ns3 program running

 Three days of vacation, all tossing ns3. Ready to enter the pit ns3, I feel that it is much stronger than ns2. But there is little data. Some blogs on the Internet are mostly translations of the ns3 manual.
 Create a new folder under the example file, ns3_test. This file contains the following two files.
ns3_test.cc

#include"ns3/network-module.h"
#include"ns3/core-module.h"
#include "ns3/internet-stack-helper.h"
#include<iostream>
using namespace std;
using namespace ns3;
int main()
{
  NodeContainer n;
  n.Create (2);

  InternetStackHelper internet;
  internet.Install (n);
  Ptr<Node> node=n.Get(1);
/**
   * 以下代码用于输出一个Node节点经过install()方法的安装后,
   * 已经聚合的所有对象
   */
  Node::AggregateIterator iterator = node->GetAggregateIterator();
    while(iterator.HasNext()){
      Ptr<const Object> obj = iterator.Next();
      std::cout<<"InternetStackHelper::Install    name="<<obj->GetInstanceTypeId().GetName()<<std::endl;
    } 
}

wscript

def build(bld):
    obj = bld.create_ns3_program('ns3_test', ['csma', 'internet', 'applications'])
    obj.source = 'ns3_test.cc'

 Execute the command ./waf. Then execute the command ./waf –run ns3_test to run the program.
 Program output:

InternetStackHelper::Install    name=ns3::Ipv4L3Protocol
InternetStackHelper::Install    name=ns3::Ipv6L3Protocol
InternetStackHelper::Install    name=ns3::Node
InternetStackHelper::Install    name=ns3::ArpL3Protocol
InternetStackHelper::Install    name=ns3::Icmpv4L4Protocol
InternetStackHelper::Install    name=ns3::Ipv4RawSocketFactory
InternetStackHelper::Install    name=ns3::GlobalRouter
InternetStackHelper::Install    name=ns3::Icmpv6L4Protocol
InternetStackHelper::Install    name=ns3::Ipv6RawSocketFactory
InternetStackHelper::Install    name=ns3::Ipv6ExtensionRoutingDemux
InternetStackHelper::Install    name=ns3::Ipv6ExtensionDemux
InternetStackHelper::Install    name=ns3::Ipv6OptionDemux
InternetStackHelper::Install    name=ns3::TrafficControlLayer
InternetStackHelper::Install    name=ns3::UdpL4Protocol
InternetStackHelper::Install    name=ns3::UdpSocketFactory
InternetStackHelper::Install    name=ns3::TcpL4Protocol
InternetStackHelper::Install    name=ns3::TcpSocketFactory
InternetStackHelper::Install    name=ns3::PacketSocketFactory

 I mainly refer to [1]. This program prints out the automatically installed object classes in InternetStackHelper. After reading the source code in the past few days, I know that in the Node object, the protocol stack object will be placed, and the m_aggregates pointer in the Object will be shared with the corresponding class. This printing program, I mainly connect, in the end Node object, when is the name=ns3::UdpSocketFactory object installed.
[1] NS3 Node aggregation object description

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325445509&siteId=291194637