微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 NS 3 Simulator20 个节点创建一个简单的 UDP 网络

如何解决使用 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?