[英]ns3 How to create a custom point to point topology
創建點對點拓撲涉及兩個節點,生成此類拓撲的代碼如下所示:
// Default Network Topology
//
// 10.1.1.0
// n0 -------------- n1
// point-to-point
//
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
{
CommandLine cmd (__FILE__);
cmd.Parse (argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
此代碼僅創建兩個點對點節點。 但是我們如何創建一個具有超過 2 個節點的點對點拓撲,如下圖所示:
PointToPointNetDevices 有幾個布局助手,但沒有一個完全適合您想要做的事情。
實現所需拓撲的最直接方法是創建節點,然后手動安裝 PointToPointNetDevices。 類似的東西
NodeContainer nodes(7);
PointToPointHelper pointToPoint;
NetDeviceContainer devices;
devices.Add(pointToPoint.Install(nodes.Get(0), nodes.Get(1)));
devices.Add(pointToPoint.Install(nodes.Get(0), nodes.Get(2)));
devices.Add(pointToPoint.Install(nodes.Get(1), nodes.Get(3)));
devices.Add(pointToPoint.Install(nodes.Get(2), nodes.Get(3)));
devices.Add(pointToPoint.Install(nodes.Get(2), nodes.Get(4)));
devices.Add(pointToPoint.Install(nodes.Get(2), nodes.Get(6)));
devices.Add(pointToPoint.Install(nodes.Get(4), nodes.Get(6)));
devices.Add(pointToPoint.Install(nodes.Get(5), nodes.Get(5)));
// the rest of your script
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.