美文网首页ns3
ns3 初探 概念及关键类

ns3 初探 概念及关键类

作者: epeeian | 来源:发表于2017-05-24 11:24 被阅读0次

    1.概念

    • 节点 基本计算设备被抽象为节点。用C++中node类描述。可想象成计算机,我们要为它添加应用程序,协议栈,外设卡及驱动等。
    • 应用程序 C++A中Application类描述。
    • 信道 用C++中Channel类。管理通信子网对象和节点连接至它们的方法。
    • 网络设备 相当于硬件设备和软件驱动的总和。安装在节点上。一个几点可以通过多个网络设备同时连接到多条信道上。由C++中NetDevice描述。提供管理连接其他节点和信道对象的方法。
    • 拓扑生成器 把网络设备连接到节点,信道,配置ip地址等等。

    2.关键类

    2.1拓扑生成器关键类

    • NodeContainer类 创建,管理和使用节点。

    NodeContainer nodes;
    nodes.Create(2);

    • PointToPointHelper类
      网络设备,信道。配置和连接PointToPointNetDevice和PointToPointChannel对象。例如设置5M传输速率和2ms的点到点传输时延。

    • NetDeviceContainer类
      存放所有被创建的NetDevice对象列表

    NetDeviceContainer devices;
    devices=pointToPoint.Install(nodes);

    调用后会有两个节点,每一个节点安装了点到点网络设备,之间有点到点信道。两设备会被配置在一个2ms传输实验的信道上以5M比特每秒速率传输

    • InternetStackHelper类
      安装协议栈,为每一个节点容器中的节点安装一个网络协议栈(TCP, UDP, IP等)
      InternetStackHelper stack;
      stack.Install(nodes);

    • Ipv4AddressHelper类
      Ipv4AddressHelper address;
      address.SetBase(''10.1.1.0'',''255.255.255.0'');
      Ipv4InterfaceContainer interfaces=address.Assingn(devices);//完成真正地址分配
      第一个10.1.1.1,后面10.1.1.2等

    2.2Application 类

    UdpEchoServerApplication 和 UdpEchoClientApplication两个核心类。在这里我们使用生成器对象。

    • UdpEchoServerHelper类
      在节点上设置一个UDP回显服务应用。

    UdpEchoServerHelper echoServer (9);
    ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
    serverApps.Start (Seconds (1.0));
    serverApps.Stop (Seconds (10.0));

    这里有一个C++隐式转换,(nodes.Get (1)作为输入,作为一个未命名的NodeContainer的构造函数的参数,送入Install方法。echoServer.Install会在管理节点的NodeContainer容器索引号为1的机节点安装一个UdpEchoServerApplication 。安装会返回一个容器,包含了指向所有被生成器创建的应用指针。

    serverApps.Start (Seconds (1.0));
    serverApps.Stop (Seconds (10.0));

    These times are set using the ApplicationContainer methods Start and Stop.

    • UdpEchoClientrHelper类
      与回显服务器类似,用来管理UdpEchoClientApplication

    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));

    The “MaxPackets” Attribute tells the client the maximum number of packets we allow it to send during the simula-
    tion. The “Interval” Attribute tells the client how long to wait between packets, and the “PacketSize” Attribute
    tells the client how large its packet payloads should be. With this particular combination of Attributes, we are
    telling the client to send one 1024-byte packet.

    2.3 Simulator类

    用全局函数Simulator::Run.
    When we previously called the methods,

    serverApps.Start (Seconds (1.0));
    serverApps.Stop (Seconds (10.0));
    ...
    clientApps.Start (Seconds (2.0));
    clientApps.Stop (Seconds (10.0));

    we actually scheduled events in the simulator at 1.0 seconds, 2.0 seconds and two events at 10.0 seconds. When
    Simulator::Run is called, the system will begin looking through the list of scheduled events and executing them. The remaining lines of our first ns-3 script, first.cc, do just that:

    Simulator::Destroy ();
    return 0;
    }

    相关文章

      网友评论

        本文标题:ns3 初探 概念及关键类

        本文链接:https://www.haomeiwen.com/subject/qfvnxxtx.html