ns3 初探 概念及关键类

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,463评论 19 139
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,160评论 0 10
  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 9,348评论 0 5
  • 做饭是件挺有意思的事儿,我观察过身边人在做饭这件事上每个人都自己的一套价值观和方法论。我自己也一样。 生活中处处可...
    不做恶阅读 3,130评论 2 0
  • 几畦粟子十里香, 地酿美味飘四方。 洛阳牡丹虽富贵, 不敢迎风傲秋霜! (清风明月于九月二十五号)
    清风明月冯耀杰阅读 994评论 1 2