使用 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.JdbcOdbc...