ns 3でloopbackインタフェースはいつ作成されますか?

2453 ワード

参照先:
Breakpoint 3, ns3::Node::GetNDevices (this=0x6617f0) at ../src/network/model/node.cc:146 146      return m_devices.size (); (gdb) bt #0  ns3::Node::GetNDevices (this=0x6617f0) at ../src/network/model/node.cc:146 #1  0x00007ffff6cb8c7c in ns3::Ipv4L3Protocol::SetupLoopback (this=0x662cf0) at ../src/internet/model/ipv4-l3-protocol.cc:265 #2  0x00007ffff6cb7a24 in ns3::Ipv4L3Protocol::SetNode (this=0x662cf0, node=...) at ../src/internet/model/ipv4-l3-protocol.cc:156 #3  0x00007ffff6cb8077 in ns3::Ipv4L3Protocol::NotifyNewAggregate (this=0x662cf0) at ../src/internet/model/ipv4-l3-protocol.cc:197 #4  0x00007ffff73714e3 in ns3::Object::AggregateObject (this=0x6617f0, o=...) at ../src/core/model/object.cc:306 #5  0x00007ffff6ee4784 in ns3::InternetStackHelper::CreateAndAggregateObjectFromTypeId (node=..., typeId=...) at ../src/internet/helper/internet-stack-helper.cc:419 #6  0x00007ffff6ee49f9 in ns3::InternetStackHelper::Install (this=0x7fffffffd320, node=...) at ../src/internet/helper/internet-stack-helper.cc:435 #7  0x00007ffff6ee4632 in ns3::InternetStackHelper::Install (this=0x7fffffffd320, c=...) at ../src/internet/helper/internet-stack-helper.cc:403 #8  0x000000000040f43c in main (argc=1, argv=0x7fffffffdc98) at ../myscripts/ns-3-dce-quagga/example/dce-quagga-isisd.cc:98 (gdb) p m_devices.size() $3 = 1 (gdb) 
兆候を探して見つけたloインタフェースを作成する場所は以下の通りです.
  // First check whether an existing LoopbackNetDevice exists on the node
  for (uint32_t i = 0; i < m_node->GetNDevices (); i++)
    {
      if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
        {
          break;
        }
    }
  if (device == 0)
    {
      device = CreateObject<LoopbackNetDevice> (); 
      m_node->AddDevice (device);
    }

一般的に作成される方法は、
      Ipv4AddressHelper ipv4AddrHelper;
      // Internet stack install
      InternetStackHelper stack;    // IPv4 is required for GlobalRouteMan
      Ipv4DceRoutingHelper ipv4RoutingHelper;
      stack.SetRoutingHelper (ipv4RoutingHelper);
      stack.Install (nodes);

ここでのroutingHelperは、必ずしもdceではなく、別のroutingHelperであってもよい.
stack.Install(nodes)呼び出しの順序は、インタフェースifIndexの値に影響します.
ノードifIndexを計算する方法は、累積
  uint32_t index = m_devices.size ();
  m_devices.push_back (device);
  device->SetNode (this);
  device->SetIfIndex (index);