创建loopback环回网卡

前提: IP协议栈已经安装到node上。

      InternetStackHelper stack;    // IPv4 is required for GlobalRouteMan
      Ipv4DceRoutingHelper ipv4RoutingHelper;
      stack.SetRoutingHelper (ipv4RoutingHelper);
      stack.Install (nodes);




创建环回网卡的代码


void SetupLoopback (Ptr   n, const char *  pcLoAddr, const char * pcLoMask)
{
  NS_LOG_FUNCTION_NOARGS ();
  Ptr device = CreateObject (); 
  Ipv4AddressHelper ipv4AddrHelper;

  n->AddDevice (device);
  ipv4AddrHelper.SetBase (pcLoAddr, pcLoMask);
  NetDeviceContainer devices;
  devices.Add(device);
  Ipv4InterfaceContainer interfaces = ipv4AddrHelper.Assign (devices);



}


你可能感兴趣的:(ns3)