本文整理汇总了C++中Ptr::AddDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::AddDevice方法的具体用法?C++ Ptr::AddDevice怎么用?C++ Ptr::AddDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ptr
的用法示例。
在下文中一共展示了Ptr::AddDevice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddInternetStack
void
Ipv6FragmentationTest::DoRun (void)
{
// Create topology
// Receiver Node
Ptr<Node> serverNode = CreateObject<Node> ();
AddInternetStack (serverNode);
Ptr<SimpleNetDevice> serverDev;
Ptr<BinaryErrorModel> serverDevErrorModel = CreateObject<BinaryErrorModel> ();
{
serverDev = CreateObject<SimpleNetDevice> ();
serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
serverDev->SetMtu (1500);
serverDev->SetReceiveErrorModel (serverDevErrorModel);
serverDevErrorModel->Disable ();
serverNode->AddDevice (serverDev);
Ptr<Ipv6> ipv6 = serverNode->GetObject<Ipv6> ();
uint32_t netdev_idx = ipv6->AddInterface (serverDev);
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001::1"), Ipv6Prefix (32));
ipv6->AddAddress (netdev_idx, ipv6Addr);
ipv6->SetUp (netdev_idx);
}
StartServer (serverNode);
// Sender Node
Ptr<Node> clientNode = CreateObject<Node> ();
AddInternetStack (clientNode);
Ptr<SimpleNetDevice> clientDev;
Ptr<BinaryErrorModel> clientDevErrorModel = CreateObject<BinaryErrorModel> ();
{
clientDev = CreateObject<SimpleNetDevice> ();
clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
clientDev->SetMtu (1500);
clientDev->SetReceiveErrorModel (clientDevErrorModel);
clientDevErrorModel->Disable ();
clientNode->AddDevice (clientDev);
Ptr<Ipv6> ipv6 = clientNode->GetObject<Ipv6> ();
uint32_t netdev_idx = ipv6->AddInterface (clientDev);
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001::2"), Ipv6Prefix (32));
ipv6->AddAddress (netdev_idx, ipv6Addr);
ipv6->SetUp (netdev_idx);
}
StartClient (clientNode);
// link the two nodes
Ptr<ErrorChannel> channel = CreateObject<ErrorChannel> ();
serverDev->SetChannel (channel);
clientDev->SetChannel (channel);
channel->SetJumpingTime (Seconds (0.5));
// some small packets, some rather big ones
uint32_t packetSizes[5] = {2000, 2500, 5000, 10000, 65000};
// using the alphabet
uint8_t fillData[78];
for ( uint32_t k = 48; k <= 125; k++ )
{
fillData[k - 48] = k;
}
// First test: normal channel, no errors, no delays
for ( int i = 0; i < 5; i++)
{
uint32_t packetSize = packetSizes[i];
SetFill (fillData, 78, packetSize);
m_receivedPacketServer = Create<Packet> ();
Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seconds (0),
&Ipv6FragmentationTest::SendClient, this);
Simulator::Run ();
uint8_t recvBuffer[65000];
uint16_t recvSize = m_receivedPacketServer->GetSize ();
NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i],
"Packet size not correct: recvSize: " << recvSize << " packetSizes[" << i << "]: " << packetSizes[i] );
m_receivedPacketServer->CopyData (recvBuffer, 65000);
NS_TEST_EXPECT_MSG_EQ (memcmp (m_data, recvBuffer, m_receivedPacketServer->GetSize ()),
0, "Packet content differs");
}
// Second test: normal channel, no errors, delays each 2 packets.
// Each other fragment will arrive out-of-order.
// The packets should be received correctly since reassembly will reorder the fragments.
channel->SetJumpingMode (true);
for ( int i = 0; i < 5; i++)
{
uint32_t packetSize = packetSizes[i];
SetFill (fillData, 78, packetSize);
m_receivedPacketServer = Create<Packet> ();
Simulator::ScheduleWithContext (m_socketClient->GetNode ()->GetId (), Seconds (0),
&Ipv6FragmentationTest::SendClient, this);
Simulator::Run ();
//.........这里部分代码省略.........
示例2: onoff
// Test program for this 3-router scenario, using global routing
//
// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
//
void
GlobalRoutingSlash32TestCase::DoRun (void)
{
Ptr<Node> nA = CreateObject<Node> ();
Ptr<Node> nB = CreateObject<Node> ();
Ptr<Node> nC = CreateObject<Node> ();
NodeContainer c = NodeContainer (nA, nB, nC);
InternetStackHelper internet;
internet.Install (c);
// Point-to-point links
NodeContainer nAnB = NodeContainer (nA, nB);
NodeContainer nBnC = NodeContainer (nB, nC);
// We create the channels first without any IP addressing information
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer dAdB = p2p.Install (nAnB);
NetDeviceContainer dBdC = p2p.Install (nBnC);;
Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
deviceA->SetAddress (Mac48Address::Allocate ());
nA->AddDevice (deviceA);
Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
deviceC->SetAddress (Mac48Address::Allocate ());
nC->AddDevice (deviceC);
// Later, we add IP addresses.
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.252");
Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
ipv4.SetBase ("10.1.1.4", "255.255.255.252");
Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
ipv4A->AddAddress (ifIndexA, ifInAddrA);
ipv4A->SetMetric (ifIndexA, 1);
ipv4A->SetUp (ifIndexA);
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
ipv4C->AddAddress (ifIndexC, ifInAddrC);
ipv4C->SetMetric (ifIndexC, 1);
ipv4C->SetUp (ifIndexC);
// Create router nodes, initialize routing database and set up the routing
// tables in the nodes.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
uint16_t port = 9; // Discard port (RFC 863)
OnOffHelper onoff ("ns3::UdpSocketFactory",
Address (InetSocketAddress (ifInAddrC.GetLocal (), port)));
onoff.SetConstantRate (DataRate (6000));
ApplicationContainer apps = onoff.Install (nA);
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
// Create a packet sink to receive these packets
PacketSinkHelper sink ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
apps = sink.Install (nC);
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
Simulator::Run ();
// Check that we received 13 * 512 = 6656 bytes
Ptr<PacketSink> sinkPtr = DynamicCast <PacketSink> (apps.Get (0));
NS_TEST_ASSERT_MSG_EQ (sinkPtr->GetTotalRx (), 6656, "Static routing with /32 did not deliver all packets");
Simulator::Destroy ();
}
示例3: 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 ();
}