Session 2. Logging과 Command Line Argument 사용법

Slides:



Advertisements
Similar presentations
Click Router: Hands on Arvind Venkatesan. Acknowledgements Thanks Hema for beautifying the slides!
Advertisements

Introduction to NS-3 Part - 1
Router Implementation Project-2
1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)
An Introduction to NS-2 * Gayatri Swamynathan CS 276 TA *some slides are from a presentation by Haobo Yu & Nader Salehi, USC/ISI.
Brief Intro to ns2: The most widely used Network Simulator COMP5416 Advanced Network Technologies Based on: Marc Greis's
Ns-2 Tutorial Exercise (1) Multimedia Networking Group, The Department of Computer Science, UVA Jianping Wang Adopted from Nicolas’s slides Jianping Wang,
How to Add a New Protocol in NS2 Xu Leiming CSCW Lab. at CS Dept., Tsinghua Univ. June 1, 2001.
Introduction to NS. Information Main website Documentation, mailing list archive, tutorial Location of Source codes –C++ files.
Session 1. NS-3 개요 ( 환경 구축 및 transport layer model) 이옥환, 신연철 Multimedia & Wireless Networking Laboratory, SNU
Ns-3 Introduction Tom Henderson (University of Washington) July 2014 Modified by Sara Mehar (university of burgundy) April 2015.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
Copyright node This presentation is a subset of the one presented by:
Introduction to Management Information Systems Chapter 5 Data Communications and Internet Technology HTM 304 Fall 07.
Project Progress Presentation GENERATION OF NS2 TRACE FILES FOR SATELLITE-WIRELESS NETWORKS CS603 - Wireless Communications & Networks Summer II 2003 Wasim.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
The Computer Communication Lab (236340) Spring 2005 Universal Plug and Play on Mobile Phone With Qualcomm - Device -
C++ fundamentals.
OMNET++. Outline Introduction Overview The NED Language Simple Modules.
NdnSIM Tutorial.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
1 Ch 3. Network Programming. 2 Network Programming (1)  Network allows arbitrary applications to communicate E.g., client-server computing such as WEB.
Wireless Networking and Systems CSE 590 ns2 tutorial.
NS-3 Tutorial Hojin Lee 한글로 만들자.
NS-3를 이용한 Proxy Mobile IPv6 Simulation
NETWORK SIMULATOR 3 Reporter: Chechieh Lin. O UTLINE Introduction NS3 vs. NS2 NS-3 Modules Key Abstractions A First ns-3 Script.
chap13 Chapter 13 Programming in the Large.
Ns-3 Training Computer and Communication Network Lab Department of Electrical Engineering National Sun Yat-Sen University 5/13/2013.
Cisco S2 C4 Router Components. Configure a Router You can configure a router from –from the console terminal (a computer connected to the router –through.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Ns-3 tutorial Katto lab Tadashi Yamazaki 8 November 2012.
Network Simulator-2 Sandeep singla 1998A2A7540. NS-2 A discrete event simulator Focused on modeling network protocols –Wired, wireless –TCP,UDP,unicast,multicast.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
1 Network Simulator Tutorial. 2 Network Simulation * Motivation: Learn fundamentals of evaluating network performance via simulation Overview: fundamentals.
Page 1 Chapter 11 CCNA2 Chapter 11 Access Control Lists : Creating ACLs, using Wildcard Mask Bits, Standard and Extended ACLs.
802.11n Sniffer Design Overview Vladislav Mordohovich Igor Shtarev Luba Brouk.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Oracle Data Integrator Agents. 8-2 Understanding Agents.
LLNL-PRES-xxxxxx This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
Dohyung Kim Computer network lab,
LonWorks Introduction Hwayoung Chae.
Introduction to Omnet++ By: Mahsa Soheil Shamaee.
Powerpoint Templates Page 1 Powerpoint Templates CS Networks Laboratory HANDLED BY, A.MAHESH PRIYA L/IT.
Jae Chung and Mark Claypool
(Modified from Polly Huang’s and last year’s original)
ns-3 Training 5/08/2017 Computer and Communication Network Lab
CSE691 Software Models and Analysis.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Simulation of Distributed Application and Protocols using TOSSIM
A quick intro to networking
Introduction to ns-2: “The” Network Simulator
Chapter 3: Using Methods, Classes, and Objects
Session 6. Wired LAN in ns-3
Session 8. LTE in ns-3 박태준 Multimedia & Wireless Networking Laboratory, SNU
Session 4. 어플리케이션 및 헤더 만들기 변성호, 이규진
Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션
Distributed Simulation with NS-3
Session 1. ns-3 기초 신연철 Multimedia & Wireless Networking Laboratory, SNU
NS3-Basic 문준영.
Ns-3 Training Emulation.
ns-3 Direct Code Execution (DCE) ns-3 Annual Meeting June 2018
ns-3 Waf build system ns-3 Annual Meeting June 2017
Ns-3 Training Session 4: Monday 3:30pm ns-3 Annual Meeting May 2014.
Ns-3 Tutorial Xin Li.
ns-3 Direct Code Execution ns-3 Annual Meeting June 2016
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Ns-3 Training Debugging support ns-3 training, June 2016.
Ns-3 Training ns-3 Objects ns-3 training, June 2016.
SPL – PS1 Introduction to C++.
Presentation transcript:

Session 2. Logging과 Command Line Argument 사용법 신연철 Multimedia & Wireless Networking Laboratory, SNU ycshin@mwnl.snu.ac.kr

First ns-3 Script

Module Includes 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” Rather than having to look up exactly what header you need, giving the ability to load a group of files Ex) ns3/core-module.h contains header files in src/core build/ns3/core-module.h

ns3 Namespace Namespace declaration using namespace ns3; ns-3 project is implemented in a C++ namespace called ns3 groups all ns-3 related declarations in a scope outside the global namespace C++ using statement introduces the ns-3 namespace into the current (global) declarative region helps the integration with other codes

Logging Logging component definition NS_LOG_COMPONENT_DEFINE (“FirstScriptExample”); Declares a logging component called FirstScriptExample Using the component name, we can enable and disable logging messages in the file

Main Function Declaration of the main function Time resolution setting int main (int argc, char *argv[]) { Time resolution setting Change the resolution exactly once Time::SetResolution (Time::NS); Logging components enabling LogComponentEnable("UdpEchoClientApplication",LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); Enabling UdpEchoClient and Server Application with info level

Creating Network Topology Using topology helpers NodeContainer List of Nodes Representative member functions void Create (uint32_t n): creates n nodes, n: # of Nodes void Add (Ptr<Node> node): append a single node Ptr<Node> Get (uint32_t i): returns i th node, i: node index uint32_t GetN (void): returns total number of nodes Ex) NodeContainer nodes; nodes.Create (2);

Creating Network Topology PointToPointHelper Helps construct a point to point link With high-level functions, NetDevice and Channel are generated and connected Representative member functions void SetDeviceAttribute (name, value) void SetChannelAttribute (name, value) 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 Ex) PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

Creating Network Topology 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 Ex) NetDeviceContainer devices; devices = pointToPoint.Install (nodes); After installation, we have two nodes, each with an installed point-to-point net device and a single point-to-point channel between them

Creating Network Topology 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 Ex) InternetStackHelper stack; stack.Install (nodes);

Creating Network Topology Ipv4AddressHelper Assigning IP address to net devices Representative member functions void SetBase (Ipv4Address network, Ipv4Mask mask, Ipv4Address base = “0.0.0.1”) Ipv4InterfaceContainer Assign (const NetDeviceContainer &c) Ex) Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); After assigning, the IP addresses of the first node and the second node are 10.1.1.1 and 10.1.1.2, respectively

Creating Applications 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 Ex) UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

Creating Applications 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 Ex) serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0));

Creating Applications 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 ) Ex) 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));

Running Simulator Stop function Run function Schedule the simulator stop event Simulator::Stop (Seconds (11.0)) Run function Running the simulator and executing scheduled events in chronological order Simulator::Run () When Start and Stop method are called, actually the corresponding events are scheduled serverApps.Start (Seconds (1.0));  server app start method is scheduled at 1s serverApps.Stop (Seconds (10.0));  server app stop method is scheduled at 10s

Running Simulator Destroy function Cleaning up the objects After it is executed, objects are destroyed and the memory is released Simulator::Destroy (); return 0; }

Simulation Example

Simulation Example (1/3) Simple point-to-point link between two nodes and echo a single packet #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" using namespace ns3; NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); int main (int argc, char *argv[]) { Time::SetResolution (Time::NS); LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

Simulation Example (2/3) NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); 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));

Simulation Example (3/3) Simulator::Run (); Simulator::Destroy (); return 0; } ../ns-3.22]$ ./waf –-run scratch/example1 Output

Tweaking Logging Modules Command Line Arguments

Logging Module Output messages from modules Useful when debugging NS_LOG environment variable NS_LOG_FUNCTION level information Verbosity level NS LOG ERROR — Log error messages; NS LOG WARN — Log warning messages; NS LOG DEBUG — Log relatively rare debugging messages; NS LOG INFO — Log informational messages about program progress; NS LOG FUNCTION — Log a message describing each function called; NS LOG LOGIC – Log messages describing logical flow within a function; NS LOG ALL — Log everything. NS LOG UNCOND – Log the associated message unconditionally.

Logging Module Example 1 Output: $ export NS_LOG=UdpEchoClientApplication=level_all $ ./waf --run scratch/example1 Output: ’build’ finished successfully (0.404s) UdpEchoClientApplication:UdpEchoClient() UdpEchoClientApplication:SetDataSize(1024) UdpEchoClientApplication:StartApplication() UdpEchoClientApplication:ScheduleTransmit() UdpEchoClientApplication:Send() Sent 1024 bytes to 10.1.1.2 Received 1024 bytes from 10.1.1.1 UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20) Received 1024 bytes from 10.1.1.2 UdpEchoClientApplication:StopApplication() UdpEchoClientApplication:DoDispose() UdpEchoClientApplication:~UdpEchoClient()

Logging Module Example 2 Output: $ export ‘NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time’ $ ./waf --run scratch/example1 Output: 0s UdpEchoClientApplication:UdpEchoClient() 0s UdpEchoClientApplication:SetDataSize(1024) 2s UdpEchoClientApplication:StartApplication() 2s UdpEchoClientApplication:ScheduleTransmit() 2s UdpEchoClientApplication:Send() 2s UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2 Received 1024 bytes from 10.1.1.1 2.00737s UdpEchoClientApplication:HandleRead(0x9aead30, 0x9aeb378) 2.00737s UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2 10s UdpEchoClientApplication:StopApplication() UdpEchoClientApplication:DoDispose() UdpEchoClientApplication:~UdpEchoClient()

Logging Module Example 3 Example 4 It prints out all of the logging $ export ‘NS_LOG=*=level_all|prefix_func|prefix_time’ $ ./waf --run scratch/example1 It prints out all of the logging ./waf –-run scratch/example1 > log.out 2>&1 2>&1 : stderr > stdout Example 4 Adding logging to your code NS_LOG_INFO (“Creating Topology”) in your source code $ export NS_LOG=FirstScriptExample=info ./waf --run scratch/example1

Command Line Arguments Change the simulation parameters using command line arguments First declare the command line parser in main function CommandLine cmd; cmd.Parse (argc, argv); Example ./waf --run "scratch/example1 –PrintHelp” ./waf –-run “scratch/example1 –PrintAttributes=ns3::PointToPointNetDevice” ./waf --run “scratch/example1 -ns3::PointToPointNetDevice::DataRate=5Mbps –ns3::PointToPointChannel::Delay=2ms”

Command Line Arguments When add your own hooks. cmd.AddValue in main function Example int main (int argc, char *argv[]) { uint32_t nPackets =1; CommandLine cmd; cmd.AddValue("nPackets", "Number of packets to echo", nPackets); Cmd.Parse (argc, argv); … echoClient.SetAttribute (“MaxPackets”, UintegerValue (nPackets)); ./waf --run “scratch/example1 –nPackets=2”

References Network Simulator NS-3 tutorial NS-3 manual http://www.nsnam.org NS-3 tutorial http://www.nsnam.org/docs/release/3.22/tutorial/singlehtml/index.html NS-3 manual http://www.nsnam.org/docs/release/3.22/manual/singlehtml/index.html

Q & A