networks simulation with NS-3
- 格式:pdf
- 大小:369.49 KB
- 文档页数:33
一、简介1. 什么是NS-3?NS是一个离散事件驱动网络模拟器。
官方定义:(from )ns-3 is a discrete-event network simulator for Internet systems, targeted primarily for research and educational use. ns-3 is free software, licensed under the GNU GPLv2 license, and is publicly available for research, development, and use.ns-3 is intended as an eventual replacement for the popular ns-2 simulator. The project acronym “nsnam” derives historically from the concatenation of ns (network simulator) and nam (network animator).2. NS-3 vs NS-2NS-3虽然冠以一个“3”,但事实上跟它广泛流行的前任NS-2并非一脉相承,或者从使用角度上说,仅仅继承了一个名称而已。
NS-3基本上是一个新的模拟器,不支持NS-2的API。
NS-3是完全用C++编写的(也有可选的Python接口),而NS-2一部分模块使用C++而另一部分使用OTcl。
因而NS-3最大的特点就是脚本可以C++或Python语言,而在NS-2中,我们使用的是OTcl。
NS-3的功能仍旧在开发中,因此它远没有NS-2完善(当然NS-2的维护也在进行中)。
NS-3并不包含目前所有NS-2的功能,但它具有某些新的特性:正确的多网卡处理、IP寻址策略的使用、更详细的模块等等。
Latest stable release: (November 20, 2008)4. NS-3的一些名词解释POSIX:Portable Operating System Interface可移植的操作系统的接口一组操作系统API的协议/标准族,最开始为了Unix系统上的可移植性而开发的,也适用于其他操作系统。
NS-3离散事件仿真引擎实现赵问道浙江大学信息与通信工程研究所2009年11月目录一、ns-3离散事件仿真引擎的基本概念 (3)二、ns-3离散事件仿真引擎的基本原理 (4)三、基本的仿真器类:Simulator (5)四、仿真器实现类:SimulatorImpl类及其派生类 (10)五、事件调度器类:Scheduler及其派生类 (12)NS-3离散事件仿真引擎实现分析一、ns-3离散事件仿真引擎的基本概念Ns-3是一个基于事件的(event-based)仿真系统。
除了系统状态变量和系统事件发生逻辑外,基于事件仿真还包括以下组成部分:(1)时钟(Clock)仿真系统必须要保持对当前仿真时间的跟踪。
离散事件仿真与实时仿真(real time simulations)不同,在离散事件仿真中时间是跳跃的(time ‘hops’ ),因为事件是瞬时发生的– 随着仿真的进展,时钟跳跃到下一事件的开始时间。
Ns-3内部仿真时钟用一个64比特的整数表示,其单位由用户通过TimeStepPrecision::Set函数设定。
(2)事件列表(Events List)仿真系统至少要维护一个仿真事件列表,一个事件用事件发生的时刻和类型来描述,事件类型标识用于仿真事件的代码,一般事件代码都是参数化的,事件描述中还包含表示事件代码的参数。
Ns-3的事件列表由Scheduler类及其派生类实现,Simulator类提供创建具体的Scheduler对象的方法,以及插入各种事件的静态接口函数。
(3)随机数发生器(Random-Number Generators)根据系统模型,仿真系统需要产生各种类型的随机变量(random variables)。
这由一个或多个伪随机数发生器(Pseudorandom number generators)产生。
NS-3包含一个内置的伪随机数发生器,随机数由RandomVariable类及其派生类实现,可以产生具有各种分布特性的随机数,具体有UniformVariable类、ConstantVariable类、SequentialVariable类、ExponentialVariable类、ParetoVariable类、WeibullVariable类、NormalVariable类、EmpiricalVariable类、IntEmpiricalVariable类、DeterministicVariable类、LogNormalVariable类、GammaVariable类、ErlangVariable类、ZipfVariable类和TriangularVariable类等。
基于ns—3构建计算机网络教学仿真平台【摘要】计算机网络原理课程抽象、复杂,基于ns-3构建计算机网络教学仿真平台有助于提高学生的学习兴趣。
【关键词】计算机网络;网络模拟;ns-3;可视化《计算机网络原理》概念抽象、协议繁琐,传统的理论教学以板书或者PPT 进行理论讲解,枯燥乏味。
构建基于新型网络模拟器ns-3[1]构建计算机网络教学仿真平台,能提高计算机网络的教学质量[2]。
1.ns-3简介ns-3广泛汲取了现有优秀开源网络模拟器如ns-2,GTNetS,yans等的成功技术和经验,专门用于教育和研究用途的离散事件模拟器,基于GNU GPLv2许可,可以免费地获取、使用和修改[3-4]。
2.ns-3仿真流程搭建ns-3网络仿真场景和搭建实际网络类似[5-6],首先生成网络节点(Node),然后为节点安装网络设备(NetDevice)及相应的传输媒体(Channel),接下来安装网络协议,包括应用层(Application),传输层,MAC层,ns-3提供了多个应用层和传输层协议,数据包(Packets)通过协议栈(Protocol stack)向下传递给网络设备(类似于网卡,实现了MAC层和物理层协议),于是如图1所示数据包就像在真实网络中一样流动。
3.ns-3仿真实例通过仿真实例展示基于ns-3构建的计算机网络教学仿真平台的优势。
仿真场景如图2所示,网络分成两部分:基于CSAM/CD协议的有线局域网和点到点的通信链路。
其中节点0是服务器;节点1有两块网卡,一块网卡和局域在一个网段,另一块网卡和服务器在一个网段,负责局域网和服务器的通信。
3.1 仿真脚本下面我给出C++脚本的关键代码(p2p网络的部分,csma网络和其代码类似)://生成节点:NodeContainer p2pNodes;p2pNodes.Create (2);//配置网卡信道参数并安装网络设备:PointToPointHelper pointToPoint;pointToPoint.SetDeviceAttribute (“DataRate”,StringValue (“5Mbps”));pointToPoint.SetChannelAttribute (“Delay”,StringValue (“2ms”));NetDeviceContainer p2pDevices;p2pDevices = pointToPoint.Install (p2pNodes);//安装网络协议栈并配置IP地址:InternetStackHelper stack;stack.Install (p2pNodes.Get (0));Ipv4AddressHelper address;address.SetBase (“10.1.1.0”,”255.255.255.0”);Ipv4InterfaceContainer p2pInter faces;p2pInterfaces = address.Assign (p2pDevices);//安装应用程序,Node0为服务器,Node5为客户机:UdpEchoServerHelper echoServer (9);ApplicationContainer serverApps = echoServer.Install (p2pNodes.Get (0));UdpEchoClientHelper echoClient (p2pInterfaces.GetAddress (0),9);//配置路由Ipv4GlobalRoutingHelper::PopulateRoutingTables ();//利用追踪系统捕获网络数据包:pointToPoint.EnablePcapAll (“p2p_csma”);csma.EnablePcap (“p2p_csma”,csmaDevices.Get (0),true);3.2 网络仿真演示图3是ns-3可视化模块PyViz在线显示实例仿真场景的拓扑结构、网络配置及通信时的画面。
基于NS-3的海上移动场景LoRa网络性能研究作者:李凌翎朱谦任久春来源:《微型电脑应用》2019年第03期摘 要:近几年来,低功耗广域网(Low Power Wide Area Network (LPWAN ))技术以功耗低、距离远、网络部署规模大的优势在物联网应用中兴起。
LoRa 作为LPWAN 技术的热门技术之一也成为了研究和应用的重点。
目前,对LoRa 技术的研究大多数是在陆地场景,海上场景研究较少。
而在物联网中,海上移动场景也是重要的应用场景,因此研究LoRa 技术在海上移动通信的性能有其重要的意义。
使用NS-3仿真平台,通过仿真平台中的LoRaWAN 模块,建立海上通信信道模型和节点移动模型,研究LoRa 技术在海上环境移动场景下的数据包投递率、网络规模等性能,为今后实际应用提供理论基础。
关键词:LoRa;LoRaWAN;NS-3;LPWAN;IoT;海上移动通信中图分类号:TN92; TN914.42文献标志码:AAbstract:In recent years, the low power wide area network (LPWAN) technology is gaining momentum as enabling technologies for the Internet of Things with advantages of low power consumption, long distance, and large-scale network deployment. LoRa, as one of the most prominent LPWAN technologies, has become the focus of research and application. At present,most researches on LoRa are on land scenes, and there are few studies on maritime scene, which is an important scenario in the Internet of Things. Therefore, it is of great significance to study the performance of LoRa technology in maritime mobile communications. In this paper, we use the NS-3 simulation platform to evaluate the performance of LoRaWAN in maritime mobile scenario. A maritime communication channel model and a node mobility model have been established, and then combined with LoRaWAN module in NS-3 to study the LoRa network performance. The simulation results are focus on packet delivery rate and network capacity, which can provide for theoretical basis for future practical applications.Key words:LoRa; LoRaWAN; NS-3; LPWAN; IoT; Maritime mobile scenarios0 引言物聯网中节点数量多、网络规模大,需要考虑节点成本、电池寿命、数据速率、传输延迟、移动性等因素。
Simulation of the Global Routing Protocol based on NS-3Keng YeSchool of Information and Communication Engineering Beijing Information Science and Technology UniversityBeijing, Chinae-mail:**************Jinhe ZhouSchool of Information and Communication Engineering Beijing Information Science and Technology UniversityBeijing, Chinae-mail:*******************.cnAbstract—NS-3 (Network Simulator version 3) could construct a network environment to simulate protocols in computer network. The purpose of this paper is implementing global routing by using the NS-3 with modified OSPF source code. The processing of simulation had been described with C++ code. Furthermore, the result of the network simulation had been analyzed with different software tools such as gawk, gunplot. In this paper we focused on simulating the global routing of Internet by NS-3 and analyzing the related theories about the routing protocol, at last, this paper was analyzing the average delay under different rates.Keywords-routing protocol; NS-3; OSPF; simulationI.I NTRODUCTIONNS-3 not only had abandoned shortcomings of the current mainstream network simulation software such as OPNET and NS-2, but also integrated the advantages of them. NS-3 had excellence including the following aspects: (1) documenting kernel of the standard components; (2) using scripting language such as C + + or Python; (3) applying to real system (network interface, device, driver interface) perfectly; (4) software integration; (5) virtualization and test-bed integration; (6) excellent documented property system; (7) updating the model in real time.NS-3 is a kind of unique simulator which includes integrity, openness, scalability and etc, and these feathers make it superior to most of the existing mainstream network simulator software. NS-3 has extremely powerful function to simulate a variety of network, protocols at all levels.NS-3 is different from the NS-2, although NS-3 is still using the C++ language to realize the simulation node. It hadn’t supported on NS-2 API and obsoleted Otcl language to control the processing of simulation. The framework of NS-3, whose simulation process can be described by pure C++ code, is much clearer than other software [1].II.T HE P RINCIPLE OF G LOBAL R OUTING P ROTOCOLIn NS-3, a C++ object builds an OSPF (Open Shortest Path First) routing database of information about the network topology [2], and executes a Dijkstra SPF (Shortest Path First) algorithm on the topology for each node, and stores the computed routes in each node's layer 3 forwarding table by making use of the routing API(Application Program Interface). The format of the data exported harmonizes with the OSPFv2 standard. In particular, the information is exported in the form of ns3::GlobalLSA objects that semantically conform to the LSA (Link State Advertisements) of OSPF. By utilizing a standard data format for informing topology, existing OSPF route computation code can be reused, and that is what can be done by ns3::GlobalRouteManager objects.OSPF is one kind of IGP (Interior Gateway Protocol), which is used for making routing decision in a single AS (Autonomous System). OSPF is a kind of link-state routing protocol, while RIP is a kind of distance vector routing protocol. In the other words, link is called router interface, so OSPF is also known as the interface state routing protocol. The OSPF is establishing the link state database, generating the shortest path tree through the network interface state of router notice, each OSPF router using the shortest path to construct the routing table [3].The routing algorithm is the core of the OSPF routing protocol. The SPF algorithm is also called Dijkstra algorithm as shown in Fig. 1, because of the shortest path first algorithm SPF is invented by Dijkstra. The SPF algorithm utilize each router as root node to calculate the distance from root node to each destination router, according to a unified database each router will be worked out the topological structure in routing domain, which is similar to a tree called SPT( shortest path tree )in the SPF algorithm. In the OSPF routing protocol, the trunk length of SPT is the distance from the root router to other routers. Smaller Cost means that the OSPF distance between source and destination is shorter.S represents the set of nodes which have not found the shortest path to the root node.R [i]represents the node which is located in front the node i on the path from the specified source node to node i.D [i]represent the shortest distance from the specified source to the node i.Initialization of the algorithm:The set S is initialized as a set which include all nodes but the source node.D[i]: If there is a link from the source node to node v, D (v) is the Cost of the link; otherwise D (v) is infinity.R[i]: If there is a link from source node to node v, R (v) is source node; otherwise R (v) =0International Conference on Software Engineering and Computer Science (ICSECS2013)Figure 1. Pseudo code for Dijstra algorthmWhen the router is initializing or the network structure is changing (for example, increasing or decreasing in the router, link state changing), the router will generate LSA, which contains all of the routers connected to the link, and calculate the shortest path.All routers exchange data of link state with each other through a Flooding, which is that the routers sent LSA to all adjacent OSPF routers. Basing on which the routers received, they have been updating their database and forwarding link state information to the adjacent routers until a stable process When the network is re-stabilized, the convergences of OSPF routing protocol have been completed. All routers will be calculated by the respective link state database of information to generate routing table, which contains the router to another reachable one and the destination to the next router.III.T HE SIMULATION PROCESS OF GLOBAL ROUTINGIn this section, we’ll introduce some important terms that are realizing specific function in ns-3.A.NodeIn NS-3 the basic abstraction of network device is called the Node. The class Node provides methods for managing the functions of network devices in simulation. You should consider a Node as a computer or a router to which you will add functionality by yourself [1]. One adds things like topology, channel, protocol stacks and peripheral devices with their associated drivers to activate the Node to do practical function.Class NodeContainer provides a very convenient way to create, manage, and access nodes, set as follows,NodeContainer c;c.Create (7); B.TopologyClass NodeContainer can connect any two nodes, set asfollows,NodeContainer n0n4 = NodeContainer(c.Get(0), c.Get(4));C.ChannelThe class Channel provides methods for constructingcommunication subnetwork objects and connecting nodes toeach other. Channels may also be specialized by us in theobject- oriented programming method. The specializedChannel can simulate things as complicated as a wire, alarge Ethernet switch, or three-dimensional space full ofobstructions in the case of wireless networks [1].We will utilize specialized versions of the Channelcalled CsmaChannel, PointToPointChannel and WifiChannel in NS-3. This paper choosesPointToPointHelper to simulate, set as follows,PointToPointHelper p2p;DeviceIn ns-3 the abstraction of network device covers both thesoftware driver and the simulated hardware. A network device is “installed” in a Node so as to activate the Node tocommunicate with other Nodes in the simulation viaChannels. Just as in a real computer, a Node may beconnected to more than one Channel via multipleNetDevices. The abstraction of network device isrepresented in C++ by the class NetDevice. The classNetDevice provides methods for managing connections toNode and Channel objects; and may be specialized by us inthe object-oriented programming. We will utilize the severalspecialized versions of the NetDevice calledCsmaNetDevice, PointToPointNetDevice, andWifiNetDevice in NS-3[1]. This paper choosesPointToPointNetDevice to simulate, set as follows, p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));NetDeviceContainer d0d4 = p2p.Install (n0n4);E.Protocol StackUntil now, nodes, devices and channels are created, wewill use class InternetStack to add stack, set as follows, InternetStackHelper internet;internet.Install (c);F.Assignning Ipv4 AddressThis paper chooses Class Ipv4AddressHelper assign IPaddresses to the device interfaces.NS_LOG_INFO ("Assign IP Addresses.");Ipv4AddressHelper ipv4;ipv4.SetBase ("10.1.1.0", "255.255.255.0");Ipv4InterfaceContainer i0i4=ipv4.Assign (d0d4); G.Setting OSPF Cost Metrici0i4.SetMetric (0, sampleMetric04);i0i4.SetMetric (1, sampleMetric04);H.Generating Routing TableNS_LOG_INFO is recording information on the progress of the program. This paper chooses global routing protocol which is introduced in section 2.Ipv4GlobalRoutingHelper::PopulateRoutingTables ();I.Sending Traffic And Setting Data Rate , The Size OfPacketNS_LOG_INFO ("Create Applications.");uint16_t port = 80; // Discard port (RFC 863)OnOffHelper onoff ("ns3::TcpSocketFactory",InetSocketAddress (i5i6.GetAddress (1), port));onoff.SetAttribute("OnTime", RandomVariableValue (ConstantVariable (1)));onoff.SetAttribute("OffTime", RandomVariableValue (ConstantVariable (0)));onoff.SetAttribute("DataRate",StringValue("5kbps") );onoff.SetAttribute ("PacketSize", UintegerValue (50)); J.Generating And Stopping TrafficApplicationContainer apps = onoff.Install (c.Get (0));apps.Start (Seconds (1.0));apps.Stop (Seconds (100.0));K.Class Packetsink Receive The Traffic OfPacketSinkHelper sink ("ns3::TcpSocketFactory",Address (InetSocketAddress (Ipv4Address::GetAny (), port)));apps = sink.Install (c.Get (6));apps.Start (Seconds (1.0));apps.Stop (Seconds (100.0));NS_LOG_INFO ("Configure Tracing.");L.Generating Trace File To Record SimulationInformationAsciiTraceHelper ascii;Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("ospf.tr");p2p.EnableAsciiAll (stream);internet.EnableAsciiIpv4All (stream);M.Generating Routing File To Record Route Information Ipv4GlobalRoutingHelper g;Ptr<OutputStreamWrapper>routingStream=Create<OutputStreamWrapper>("ospf.routes",std::ios::out);g.PrintRoutingTableAllAt(Seconds(12), routingStream);N.Executing SimulatorNS_LOG_INFO ("Run Simulation.");Simulator::Run ();Simulator::Destroy ();NS_LOG_INFO ("Done.");IV.S IMULATION R ESULTSimulation results verify that the shortest path tree conforms to Dijkstra algorithm in OSPF protocol and count package delay to check network performance.A.Generating Shortest PathAccording to the topology in Fig. 2, in the 1st second executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, as shown in Fig. 3 the shortest path is node 0->node 4-> node 1-> node 2-> node 5-> node 6-> node 3, rather than node 0->node 4-> node 1-> node 2-> node 3 which include the least node.In 2nd second, disconnecting the link node 1 and node 2, node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, as shown in Fig.4 at the moment, the shortest path is node 0->node 4-> node 1-> node 5-> node 6 -> node 3.In 4th second, reconnecting the link node 1 and node 2, node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, the shortest path is node 0->node 4-> node 1-> node 2-> node 5-> node 6-> node 3.In 6th second, disconnecting the link node 5 and node 6,node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, at the moment, the shortest path is node 0->node 4-> node 1-> node 2-> node 3.In 8th second, disconnecting the link node 2 and node 3,node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, at the moment, the shortest path is node 0->node 4-> node 1-> node 5-> node 2 -> node 3.In 12th second, reconnecting the link node 1 and node 2, node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, at the moment, the shortest path is node 0->node 4-> node 1-> node 5-> node 6 -> node 3.In 14th second, reconnecting the link node 1 and node 2, node 0 executes a Dijkstra SPF algorithm on the topology for each node, finds the shortest path between node 0 and node 3, at the moment, the shortest path is node 0->node 4-> node 1-> node 2-> node 5-> node 6-> node 3.Figure 2. topology with cost in simulationFigure 3. shortest path in 1stsecondFigure 4. shortest path in 2ndsecondB. DelayIn Fig. 5 are shown the simulation results of delay for the communication between node 0 and node 3. Under different shortest path, delay is diverse. The network delay is very close to the case when the packets take the same path. The path of least delay is not necessarily the shortest path.The average delay is the time of all data packets arrived at destination node from the source node. The characterization means the current status of the network. As shown in Fig. 6,V.C ONCLUSIONSummary, this paper describes an effective simulation method to realize global routing protocols, evaluate network performance, and carry out a detailed analysis of delay and shortest path tree. The conclusion has certain reference value.A CKNOWLEDGMENTThis work was supported by National Natural Science Foundation of China (61271198) and Beijing Natural Science Foundation (4131003).Figure 5.the packet delayFigure 6. the average delay under different rateR EFERENCES[1] NS-3 Tutorial. /, 12 Dev 2012[2] NS-3 project NS-3 Doxygen. /,12 Dev 2012 [3] Andrew S. Tanenbaum. Computer Network Fourth Edition. Beijing:Tsinghua University Press.pp.350-366,454-459(2008) [4] WANG Jianqiang,LI Shiwei,ZENG Junwei,DOUYingying.(2011)Simulation Research of VANETs Routing Protocols Performance Based on NS -3Microcomputer Applications Vol. 32 No. 11.[5] NS-3 project NS-3 Reference Manual. /,12Dev 2012[6] Timo Bingmann.( 2009). Accuracy Enhancements of the 802.11Model and EDCA QoS Extensions in ns-3. Diploma Thesis at the Institute of Telematics[7] Learmonth, G. Holliday, J. (2011) NS3 simulation and analysis ofMCCA: Multihop Clear Channel Assessment in 802.11 DCF .Consumer Communications and Networking Conference (CCNC). IEEE[8] Henderson T R,Floyd S,Riley G F(2006) NS-3 Project Goals.Proceedings of the Workshop of Network Simulation. Pisa, Italy.[9] Vincent.S,Montavont.J(2008).Implementation of an IPv6 Stack forNS-3. Proceedings of the Workshop of Network Simulation.AthensGreece:[s. n.].。
n s-3网络仿真(总8页) --本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--NS-3网络仿真一:实验要求用NS-3仿真某个特定的网络环境,并输出相应的仿真参数(时延,抖动率,吞吐量,丢包率)。
二:软件介绍NS-3 是一款全新新的网络模拟器,NS-3并不是NS-2的扩展。
虽然二者都由C++编写的,但是NS-3并不支持NS-2的API。
NS-2的一些模块已经被移植到了NS-3。
在NS-3开发过程时,“NS-3项目”会继续维护NS-2,同时也会研究从NS-2到NS-3的过渡和整合机制。
三:实验原理及步骤NS-3是一款离散事件网络模拟驱动器,操作者能够编辑自己所需要的网络拓扑以及网络环境,来模拟一个网络的数据传输,并输出其性能参数。
软件中包含很多模块:节点模块(创造节点),移动模块(仿真WIFI,LTE可使用),随机模块(生成随机错误模型),网络模块(不同的通信协议),应用模块(创建packet 数据包以及接受packet数据包),统计模块(输出统计数据,网络性能参数)等等;首先假设一个简单的网络拓扑:两个节点之间使用点对点链路,使用TCP协议进行通信,假设随机错误率为,节点不可移动(因为不是无线网络),具体代码如下:NodeContainer nodes;(2);创建两个节点;PointToPointHelper pointToPoint;("DataRate", StringValue ("5Mbps"));("Delay", StringValue ("2ms"));设置链路的传输速率为5Mbps,时延为2ms;NetDeviceContainer devices;devices = (nodes);为每个节点添加网络设备Ptr<RateErrorModel>em=CreateObject<RateErrorModel> ();em->SetAttribute("ErrorRate",DoubleValue);(1)->SetAttribute("ReceiveErrorModel",PointerValue (em));创建一个错误模型,讲错误率设置为,仿真TCP协议的重传机制。