如何解决使用 NS 3 Simulator20 个节点创建一个简单的 UDP 网络
我正在尝试在 NS 3 Simulator 中使用 UDP 连接创建一个大约 20 个节点的简单网络。目的是生成一个包含一些恶意节点的网络。但我发现很难生成超过 3 个节点的网络。此外,我还想捕获每个节点的数据。那么,执行此过程的适当方式或方法是什么? (我使用 P2P 作为节点通道)(代码:C++)
代码: `NodeContainer 节点; 节点.创建(3);
InternetStackHelper stack;
stack.Install (nodes);
PointToPointHelper pointToPoint1;
pointToPoint1.SetDeviceAttribute ("Datarate",StringValue ("5Mbps"));
pointToPoint1.SetChannelAttribute ("Delay",StringValue ("1ms"));
PointToPointHelper pointToPoint2;
pointToPoint2.SetDeviceAttribute ("Datarate",StringValue ("10Mbps"));
pointToPoint2.SetChannelAttribute ("Delay",StringValue ("5ms"));
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0","255.255.255.0");
NetDeviceContainer devices;
devices = pointToPoint1.Install (nodes.Get(0),nodes.Get(1));
Ipv4InterfaceContainer interfaces = address.Assign (devices);
devices = pointToPoint2.Install (nodes.Get(1),nodes.Get(2));
address.SetBase ("10.1.2.0","255.255.255.0");
interfaces = address.Assign (devices);
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
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));
pointToPoint1.EnablePcapAll("p2p1");
pointToPoint2.EnablePcapAll("p2p2");
printf("Animation");
printf("\n");
std::string animFile = "MyExample1.xml";
AnimationInterface anim (animFile);
anim.SetConstantPosition(nodes.Get(0),0.0,0.0);
anim.SetConstantPosition(nodes.Get(1),2.0,2.0);
anim.SetConstantPosition(nodes.Get(2),3.0,3.0);
printf("Animation");
printf("\n");'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。