c++ - ns3 如何创建自定义点对点拓扑
问题描述
创建点对点拓扑涉及两个节点,生成此类拓扑的代码如下所示:
// 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
推荐阅读
- websocket - ActiveMQ Artemis - 踩在 websocket 上 - 框架类型
- elasticsearch - 在 Elasticsearch 中检索最新文档需要很长时间
- c# - 调用 POST api 将用户添加到数据库表时出现错误 500
- node.js - “systemctl start pm2-user-name”给出错误
- sql - 即使数据条目似乎正确,也无法在核心 2.2 中输出外键对象
- java - 如何禁用 oData API 的 HTTP POST 请求?
- python - 使用 python 请求模块获取验证码图像的问题
- php - 是否可以通过设置时间戳重用 datetime 对象?
- javascript - 在 node-ftp 模块中捕获未捕获的异常错误
- oracle - 按下按钮时触发器引发未处理的异常 ora-01401