【问题标题】:ns3 How to create a custom point to point topologyns3 如何创建自定义点对点拓扑
【发布时间】:2020-12-20 10:45:07
【问题描述】:

创建点对点拓扑涉及两个节点,生成此类拓扑的代码如下:

// 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 个节点的点对点拓扑,如下图:

【问题讨论】:

    标签: c++ simulation ns-3


    【解决方案1】:

    several layout helpers for 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
    

    【讨论】:

    • @Zahra 这能回答你的问题吗?
    • 这不在您的问题范围内,但您只需创建单独的 NetDeviceContainers 并将pointToPoint.Install(...) 返回的设备添加到您想要的 NetDeviceContainer 中。同样,您可以创建单独的 NodeContainer。
    • @Zahra 你应该在这里接受这个问题,因为它回答了原始问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 2020-10-23
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 2023-03-18
    • 2016-09-05
    相关资源
    最近更新 更多