本文整理汇总了C++中Ptr::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::Bind方法的具体用法?C++ Ptr::Bind怎么用?C++ Ptr::Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ptr
的用法示例。
在下文中一共展示了Ptr::Bind方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Attach
//-----------------------------------------------------------------------------------------------------------------------------------------------------
VOID FrameBuffer::Attach( DWORD Buffer, Ptr<RenderBuffer> pRenderBuffer )
{
pRenderBuffer->Bind();
m_pContext->glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, Buffer, GL_RENDERBUFFER_EXT, pRenderBuffer->Id() );
GLenum status = m_pContext->glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
}
示例2: StartApplication
void MyApp::StartApplication (void)
{
m_running = true;
m_packetsSent = 0;
m_socket->Bind ();
m_socket->Connect (m_peer);
SendPacket ();
}
示例3: SetTexture
//-----------------------------------------------------------------------------------------------------------------------------------------------------
VOID Context::SetTexture( UINT TextureUnit, Ptr<Texture> pTexture )
{
if (m_pCurrentTexture[TextureUnit] == pTexture)
return;
m_pCurrentTexture[TextureUnit] = pTexture;
//glActiveTextureARB(GL_TEXTURE0_ARB);
pTexture->Bind();
}
示例4:
void
Ipv6FragmentationTest::StartServer (Ptr<Node> ServerNode)
{
if (m_socketServer == 0)
{
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
m_socketServer = Socket::CreateSocket (ServerNode, tid);
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address ("2001::1"), 9);
m_socketServer->Bind (local);
Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socketServer);
}
m_socketServer->SetRecvCallback (MakeCallback (&Ipv6FragmentationTest::HandleReadServer, this));
}
示例5: MakeCallback
void
Ipv6FragmentationTest::StartClient (Ptr<Node> ClientNode)
{
if (m_socketClient == 0)
{
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
m_socketClient = Socket::CreateSocket (ClientNode, tid);
m_socketClient->Bind (Inet6SocketAddress (Ipv6Address::GetAny (), 9));
m_socketClient->Connect (Inet6SocketAddress (Ipv6Address ("2001::1"), 9));
CallbackValue cbValue = MakeCallback (&Ipv6FragmentationTest::HandleReadIcmpClient, this);
m_socketClient->SetAttribute ("IcmpCallback6", cbValue);
}
m_socketClient->SetRecvCallback (MakeCallback (&Ipv6FragmentationTest::HandleReadClient, this));
}
示例6: main
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double rss = -80; // -dBm
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
double interval = 1.0; // seconds
bool verbose = false;
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
cmd.AddValue ("numPackets", "number of packets generated", numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets", interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);
// disable fragmentation for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));
NodeContainer c;
c.Create (2);
// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (0) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed regardless
// of the distance between the two stations, and the transmit power
wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
InternetStackHelper internet;
internet.Install (c);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
source->SetAllowBroadcast (true);
source->Connect (remote);
// Tracing
wifiPhy.EnablePcap ("wifi-simple-adhoc", devices);
// Output what we are doing
NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss );
Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
//.........这里部分代码省略.........
示例7: main
//.........这里部分代码省略.........
// Create net device containers
NetDeviceContainer encoderRecoderDevs = pointToPoint.Install (encoderRecoder);
NetDeviceContainer recoderDecoderDevs = pointToPoint.Install (recoderDecoder);
NetDeviceContainer devices = NetDeviceContainer (encoderRecoderDevs,
recoderDecoderDevs);
// Set IP addresses
Ipv4AddressHelper ipv4("10.1.1.0", "255.255.255.0");
ipv4.Assign (devices);
// Turn on global static routing so we can actually be routed across the hops
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Do pcap tracing on all point-to-point devices on all nodes. File naming
// convention is: multihop-[NODE_NUMBER]-[DEVICE_NUMBER].pcap
pointToPoint.EnablePcapAll ("multihop");
// Set error model for the net devices
Config::SetDefault ("ns3::RateErrorModel::ErrorUnit",
StringValue ("ERROR_UNIT_PACKET"));
Ptr<RateErrorModel> errorEncoderRecoder = CreateObject<RateErrorModel> ();
errorEncoderRecoder->SetAttribute ("ErrorRate",
DoubleValue (errorRateEncoderRecoder));
devices.Get (1)->SetAttribute ("ReceiveErrorModel",
PointerValue (errorEncoderRecoder));
Ptr<RateErrorModel> errorRecoderDecoder = CreateObject<RateErrorModel> ();
errorRecoderDecoder->SetAttribute ("ErrorRate",
DoubleValue (errorRateRecoderDecoder));
devices.Get (3)->SetAttribute ("ReceiveErrorModel",
PointerValue (errorRecoderDecoder));
errorEncoderRecoder->Enable ();
errorRecoderDecoder->Enable ();
// Creation of RLNC encoder and decoder objects
rlnc_encoder::factory encoder_factory(generationSize, packetSize);
rlnc_decoder::factory decoder_factory(generationSize, packetSize);
// The member build function creates differents instances of each object
KodoSimulation kodoSimulator(encoder_factory.build(),
decoder_factory.build(),
decoder_factory.build(),
recodingFlag);
// Setting up application sockets for recoder and decoder
uint16_t port = 80;
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
// Get node Ipv4 addresses
Ipv4Address recoderAddress = nodes.Get (1)->GetObject<Ipv4>()->
GetAddress(1,0).GetLocal();
Ipv4Address decoderAddress = nodes.Get (2)->GetObject<Ipv4>()->
GetAddress(1,0).GetLocal();
// Socket connection addresses
InetSocketAddress recoderSocketAddress = InetSocketAddress (recoderAddress,
port);
InetSocketAddress decoderSocketAddress = InetSocketAddress (decoderAddress,
port);
// Socket bind address
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny(), port);
// Encoder
Ptr<Socket> encoderSocket = Socket::CreateSocket (nodes.Get (0), tid);
encoderSocket->Connect (recoderSocketAddress);
// Recoder
Ptr<Socket> recoderSocket = Socket::CreateSocket (nodes.Get (1), tid);
recoderSocket->Bind(local);
recoderSocket->Connect (decoderSocketAddress);
recoderSocket->
SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketRecoder,
&kodoSimulator));
// Decoder
Ptr<Socket> decoderSocket = Socket::CreateSocket (nodes.Get (2), tid);
decoderSocket->Bind(local);
decoderSocket->
SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketDecoder,
&kodoSimulator));
// Simulation setup
// Schedule encoding process
Simulator::ScheduleWithContext (encoderSocket->GetNode ()->GetId (),
Seconds (1.0),
&KodoSimulation::SendPacketEncoder,
&kodoSimulator, encoderSocket,
interPacketInterval);
Simulator::ScheduleWithContext (recoderSocket->GetNode ()->GetId (),
Seconds (1.5),
&KodoSimulation::SendPacketRecoder,
&kodoSimulator, recoderSocket,
interPacketInterval);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
示例8: BooleanValue
void
SixlowpanHc1ImplTest::DoRun (void)
{
// Create topology
// Receiver Node
Ptr<Node> rxNode = CreateObject<Node> ();
AddInternetStack6 (rxNode);
Ptr<SimpleNetDevice> rxDev;
{ // first interface
rxDev = CreateObject<SimpleNetDevice> ();
rxDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
rxNode->AddDevice (rxDev);
Ptr<SixLowPanNetDevice> rxSix = CreateObject<SixLowPanNetDevice> ();
rxSix->SetAttribute ("ForceEtherType", BooleanValue (true) );
rxSix->SetAttribute ("Rfc6282", BooleanValue (false) );
rxNode->AddDevice (rxSix);
rxSix->SetNetDevice (rxDev);
Ptr<Ipv6> ipv6 = rxNode->GetObject<Ipv6> ();
ipv6->AddInterface (rxDev);
uint32_t netdev_idx = ipv6->AddInterface (rxSix);
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::1"), Ipv6Prefix (64));
ipv6->AddAddress (netdev_idx, ipv6Addr);
ipv6->SetUp (netdev_idx);
}
// Sender Node
Ptr<Node> txNode = CreateObject<Node> ();
AddInternetStack6 (txNode);
Ptr<SimpleNetDevice> txDev;
{
txDev = CreateObject<SimpleNetDevice> ();
txDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
txNode->AddDevice (txDev);
Ptr<SixLowPanNetDevice> txSix = CreateObject<SixLowPanNetDevice> ();
txSix->SetAttribute ("ForceEtherType", BooleanValue (true) );
txSix->SetAttribute ("Rfc6282", BooleanValue (false) );
txNode->AddDevice (txSix);
txSix->SetNetDevice (txDev);
Ptr<Ipv6> ipv6 = txNode->GetObject<Ipv6> ();
ipv6->AddInterface (txDev);
uint32_t netdev_idx = ipv6->AddInterface (txSix);
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::2"), Ipv6Prefix (64));
ipv6->AddAddress (netdev_idx, ipv6Addr);
ipv6->SetUp (netdev_idx);
}
// link the two nodes
Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
rxDev->SetChannel (channel1);
txDev->SetChannel (channel1);
// Create the UDP sockets
Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100::1"), 1234)), 0, "trivial");
rxSocket->SetRecvCallback (MakeCallback (&SixlowpanHc1ImplTest::ReceivePkt, this));
Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
txSocket->SetAllowBroadcast (true);
// ------ Now the tests ------------
// Unicast test
SendData (txSocket, "2001:0100::1");
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 180, "trivial");
uint8_t rxBuffer [180];
uint8_t txBuffer [180] = "\"Can you tell me where my country lies?\" \\ said the unifaun to his true love's eyes. \\ \"It lies with me!\" cried the Queen of Maybe \\ - for her merchandise, he traded in his prize.";
m_receivedPacket->CopyData (rxBuffer, 180);
NS_TEST_EXPECT_MSG_EQ (memcmp (rxBuffer, txBuffer, 180), 0, "trivial");
m_receivedPacket->RemoveAllByteTags ();
Simulator::Destroy ();
}
示例9: main
//.........这里部分代码省略.........
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));
NodeContainer c;
c.Create (numNodes);
// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (-10) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (distance),
"DeltaY", DoubleValue (distance),
"GridWidth", UintegerValue (5),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
// Enable OLSR
OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (olsr, 10);
InternetStackHelper internet;
internet.SetRoutingHelper (list); // has effect on the next Install ()
internet.Install (c);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
source->Connect (remote);
if (tracing == true)
{
AsciiTraceHelper ascii;
wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("wifi-simple-adhoc-grid.tr"));
wifiPhy.EnablePcap ("wifi-simple-adhoc-grid", devices);
// Trace routing tables
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("wifi-simple-adhoc-grid.routes", std::ios::out);
olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream);
// To do-- enable an IP-level trace that shows forwarding events only
}
// Give OLSR time to converge-- 30 seconds perhaps
Simulator::Schedule (Seconds (30.0), &GenerateTraffic,
source, packetSize, numPackets, interPacketInterval);
// Output what we are doing
NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance);
Simulator::Stop (Seconds (32.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}