Presentation is loading. Please wait.

Presentation is loading. Please wait.

NS3-Basic 2016. 11. 07 문준영.

Similar presentations


Presentation on theme: "NS3-Basic 2016. 11. 07 문준영."— Presentation transcript:

1 NS3-Basic 문준영

2 Installation

3 Installation Download ns-3 Using a Tarball Building with build.py
1 Installation Download ns-3 Using a Tarball wget tar xjf ns-allinone-3.25.tar.bz2 Building with build.py ./build.py --enable-examples --enable-tests Testing ns-3 ./test.py –c core

4 Congratulations! You are now an ns-3 user.
1 Installation Running a Script ./waf --run hello-simulator Congratulations! You are now an ns-3 user.

5 Introduction

6 Introduction 네트워크 연구를 위한 discrete-event network simulator
1 Introduction 네트워크 연구를 위한 discrete-event network simulator C++기반의 간단한 구조 유·무선 시뮬레이션의 제공 무료, 오픈 소스 소프트웨어 실제와 가까운 구현 지원 플랫폼 FreeBSD, Linux, SunOS, Solaris, Windows(Cygwin) 시그윈

7 Introduction NS-3 Tutorial NS-3 doxygen NS-3 MWNL 강의 자료
1 Introduction NS-3 Tutorial NS-3 doxygen NS-3 MWNL 강의 자료 시그윈

8 Key Abstractions

9 Key Abstractions Node Application Channel Host 혹은 end system
1 Key Abstractions Node Host 혹은 end system Basic computing device abstraction 앞으로 기능이 부여될 컴퓨터 Application 시뮬레이션 상에서 행동을 발생시키는 유저 프로그램 Node에서 동작 Ex) UdpEchoClientApplication Channel 데이터 송수신을 위한 노드 사이의 통신 매체(medium) Ex) CsmaChannel, WifiChannel

10 Key Abstractions Net device Topology helpers
1 Key Abstractions Net device NIC(Network Interface Cards)+Network Device Drivers Node에 설치되어 Channel을 통한 통신을 가능케 한다 Ex) CsmaNetDevice, WifiNetDevice Topology helpers ns-3 프로그래밍을 가능한 쉽도록 도움 Create a NetDevice add a MAC address install that net device on a Node configure the node’s protocol stack connect the NetDevice to a Channel… Ex) NodeContainer, PointToPointHelper

11 Key Abstractions Application Sockets-like API Protocol stack
1 Key Abstractions Application Protocol stack Node NetDevice Sockets-like API Channel Packet(s)‏

12 first.cc

13 1 first.cc

14 first.cc Code starts with a number of include statements
1 first.cc Code starts with a number of include statements #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h” 어떤 헤더 파일을 추가하지? 정확히 내가 필요로 하는 헤더만 찾을 것이 아니라, 파일들의 그룹을 불러오자 가장 효율적이진 않지만, 스크립트 작성이 쉬워진다 Ex) ns3/core-module.h는 src/core의 header 파일들을 포함 최적화된 방식은 아니지만, 코딩하기에 쉽다

15 first.cc Namespace declaration Logging component definition
1 first.cc Namespace declaration using namespace ns3; ns-3 프로젝트는 ns3 namespace에 구현되있다 Logging component definition NS_LOG_COMPONENT_DEFINE (“FirstScriptExample”); Component 이름을 사용하여, console message logging 사용여부를 결정할 수 있다 자세한 내용은 logging 파트에서.. Declaration of the main function int main (int argc, char *argv[]) {

16 first.cc Time resolution setting Logging components enabling
1 first.cc Time resolution setting Time::SetResolution (Time::NS); 시뮬레이션상에서의 최소 시간 단위 Default는 1 nanosecond Logging components enabling LogComponentEnable("UdpEchoClientApplication",LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); UdpEchoClient와Server Application의 info level logging message 사용 Application이 패킷을 송수신 할 때 메시지 출력 What is the logging? Info level? Logging 파트에서…

17 first.cc Creating Nodes NodeContainer NodeContainer nodes;
1 first.cc Creating Nodes NodeContainer nodes; nodes.Create (2); Create the ns-3 Node objects that will represent the computers in the simulation Node represents a computer to which we are going to add protocol stacks, applications and NIC NodeContainer Topology Helper : Provide a convenient way to create, manage and access any Node object List of Nodes Representative member functions Void Create (uint32_t n) : creates n nodes and stores pointers to nodes internally, n : # of Nodes Void Add (Ptr<Node> node) : append a single node and store pointer to node internally Ptr<Node> Get (uint32_t i) : returns i th node, i : node index Uint32_t GetN (void) : returns total number of nodes

18 first.cc Creating point to point link PointToPointHelper
1 first.cc Creating point to point link PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); Construct a point to point link using a topology helper PointToPointHelper Channel and NetDevice are intimately tied together Ex) Ethernet devices ↔ wireless channel? No! Topology Helper provides intimate coupling and therefore a single PointToPointHelper will configure and connect PointToPointNetDevice and PointToPointChannel Representative member functions void SetDeviceAttribute (name, value) void SetChannelAttribute (name, value) NetDeviceContainer Install (NodeContainer c) Ethernet device는 유선 NIC

19 first.cc Creating point to point link Set Device DataRate
1 first.cc Creating point to point link PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); Construct a point to point link using a topology helper Set Device DataRate DataRate : the number of bits per second that the device will simulate sending over the channel Use the value “5Mbps” as the “DataRate” when it creates a NetDevice object Set Channel Delay Use the value “2ms” as the “Transmission Delay” when it creates a point to point channel Ethernet device는 유선 NIC

20 first.cc Installing devices and channel NetDeviceContainer
1 first.cc Installing devices and channel NetDeviceContainer devices; devices = pointToPoint.Install (nodes); NetDeviceContainer Install (NodeContainer c) Creates p2p net devices and common channel internally, and then install the device and channel on each node in node container c After installation, we have two nodes, each with an installed point-to-point net device(5Mbps DataRate) and a single point-to-point channel(2ms Delay) between them NetDeviceContainer List of NetDevice Representative member functions void Add (Ptr<Netdevice> device): append a single device Ptr<NetDevice> Get (uint32_t i): returns I th net device uint32_t GetN (void): returns total number of net devices NodeContainer에 있는 각 노드들에게 P2PNetDevice가 설치되고 device containe에 저장됨 P2PChannel이 생성되고 Channel로 NetDevice들이 연결됨

21 first.cc Install protocol stack InternetStackHelper
1 first.cc Install protocol stack InternetStackHelper stack; stack.Install (nodes); Install internet stack on nodes using InternetStackHelper InternetStackHelper Helps construct the Internet stack Representative member functions void Install (NodeContainer c) When the install call is executed, it will install Internet stack(TCP, UDP, IP, etc.) on each node in the node container protocol stack = osi 7계층

22 first.cc Allocate IP address Ipv4AddressHelper
1 first.cc Allocate IP address Ipv4AddressHelper address; address.SetBase (" ", " "); Ipv4InterfaceContainer interfaces = address.Assign (devices); Allocate IP addresses on devices using Ipv4AddressHelper( , ) Using Ipv4InterfaceContainer for future reference of Ipv4Interface After allocation, we have a point-to-point network built, with stacks installed and IP addresses assigned Ipv4AddressHelper Assigning IP address to net devices Representative member functions void SetBase (Ipv4Address network, Ipv4Mask mask, IPv4Address base = “ ”) Ipv4InterfaceContainer Assign (const NetDeviceContainer &c)

23 first.cc Creating Applications UdpEchoServerHelper
1 first.cc Creating Applications UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); Set up a UDP echo server application on node1 using UdpEchoServerHelper UdpEchoServerHelper Upon receiving a message, echo the message Representative member functions UdpEchoServerHelper (uint16_t port) Constructor with port number ApplicationContainer Install (NodeContainer c) Creates UdpEchoServer applications and then install them on each node in node container c Each application is added in a application container

24 first.cc Creating Applications ApplicationContainer
1 first.cc Creating Applications serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); Set start and stop time for echo server application using ApplicationContainer ApplicationContainer List of Applications Representative member functions Ptr<Application> Get (uint32_t i): returns i th application Uint32_t GetN (void): returns total number of net devices void Start (Time start): all applications start at start time void Stop (Time stop): all applications stop at stop time

25 first.cc Creating Applications
1 first.cc Creating Applications UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); For the echo client, we need to set five different Attributes RemoteAddress : destination IP address RemotePort : destination port number MaxPackets : maximum number of packets we allow it to send during the simulation Interval : how long to wait between packets PacketSize : how large its packet payloads should be With this particular combination of Attributes, we are telling the client to send one 1024-byte packet

26 first.cc Creating Applications UdpEchoClientHelper
1 first.cc Creating Applications ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Set up a UDP echo client application on node0 using UdpEchoClientHelper Set start and stop time for echo server application using ApplicationContainer UdpEchoClientHelper Send UDP packets Representative member functions UdpEchoClientHelper (Address ip, uint16_t port) void Setattribute (name, value) RemoteAddress, RemotePort, MaxPackets, Interval, PacketSize ApplicationContainer Install (NodeContainer c)

27 first.cc Running Simulator Destroy function Simulator::Run ()
1 first.cc Running Simulator Simulator::Run () Running the simulator and executing scheduled events in chronological order Start server and client app, Sending packet, Packet echo, Application stop If there are no further events to process, Simulator::Run returns Destroy function Simulator::Destroy (); return 0; } Cleaning up the objects After it is executed, objects are destroyed and the memory is released

28 first.cc Building Your Script
1 first.cc Building Your Script All you have to do is to drop your script into the scratch directory and it will automatically be built if you run Waf $ cp example/tutorial/first.cc scratch/myfirst.cc $ ./waf You can now run the example $ ./waf –-run scratch/myfirst

29 1 first.cc Simulation Result

30 Thank you


Download ppt "NS3-Basic 2016. 11. 07 문준영."

Similar presentations


Ads by Google