Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션 구종회, 변성호 Multimedia & Wireless Networking Laboratory, SNU jhkoo@mwnl.snu.ac.kr shbyeon@mwnl.snu.ac.kr
Contents Tracing system Animator Application Exercise ASCII PCAP UdpEcho OnOffApplication UdpClientServer Exercise
Tracing & Animator
Tracing System Tracing is a structured form of simulation output
ASCII Tracing AsciiTraceHelper ascii; ASCII Tracing Trace file similar to that of NS-2 AsciiTraceHelper ascii; pointToPoint.EnableAsciiAll (ascii.CreateFileStream(“myfirst.tr”)); Simulator::Run (); Simulator::Destroy (); return 0; Output (myfirst.tr) + 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024) - 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024) …
ASCII Tracing Trace file format 00 + 01 2 02 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue 03 ns3::PppHeader ( 04 Point-to-Point Protocol: IP (0x0021)) 05 ns3::Ipv4Header ( 06 tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] 07 length: 1052 10.1.1.1 > 10.1.1.2) 08 ns3::UdpHeader ( 09 length: 1032 49153 > 9) 10 Payload (size=1024)
PCAP Tracing PCAP Tracing .pcap file format Traffic trace analyze pointToPoint.EnablePcapAll (“myfirst”); Reading output with tcpdump $ tcpdump -nn -tt -r myfirst-0-0.pcap reading from file myfirst-0-0.pcap, link-type PPP (PPP) 2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024 $ tcpdump -nn -tt -r myfirst-1-0.pcap reading from file myfirst-1-0.pcap, link-type PPP (PPP) 2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024 2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024
PCAP Tracing Reading output with Wireshark http://www.wireshark.org/download.html
Tracing system Simple tracing system Use trace source and trace sink ASCII tracing PCAP tracing Used to generate output for checking the operation and measure the system performance Use trace source and trace sink Study the advanced tracing system in Session 5
NetAnim Newest version 3.105 An offline animator based on the Qt 4 toolkit. It animates the simulation using an XML trace file collected during simulation.
NetAnim How to build Summary of features http://www.nsnam.org/wiki/NetAnim_3.105 Summary of features Animate packets over wired-links and wireless-links Limited support for LTE traces. No support for IPv6 Packet timeline on packet meta-data. Node position statistics with node trajectory plotting Path of a mobile node Print brief packet-meta data on packets Use custom icons for nodes Parse flow-monitor XML files and display statistics for each flow Show IP and MAC information Including peer IP and MAC for point-to-point links. Step through a simulation one event at a time and pause the simulation at a given time Print the routing table
NetAnim Update the name of the node Update the size of the node AnimationInterface::UpdateNodeDescription (uint32_t nodeId, string name); Update the size of the node AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height) Update the color of the node AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) Update the image of the node AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId).
NetAnim Example (src/netanim/examples/wireless-animation.cc) // include netanim header - mandatory #include “ns3/netanim-module.h” // xml generation - mandatory AnimationInterface anim (“wireless-animation.xml”); // for stationary nodes anim.SetConstantPosition(n,100,200); // ‘n’ is a node pointer
NetAnim Example (src/netanim/examples/wireless-animation.cc) for (uint32_t i = 0; i < wifiStaNodes.GetN (); ++i) { anim.UpdateNodeDescription (wifiStaNodes.Get (i), "STA"); // Optional anim.UpdateNodeColor (wifiStaNodes.Get (i), 255, 0, 0); // Optional } for (uint32_t i = 0; i < wifiApNode.GetN (); ++i) anim.UpdateNodeDescription (wifiApNode.Get (i), "AP"); // Optional anim.UpdateNodeColor (wifiApNode.Get (i), 0, 255, 0); // Optional for (uint32_t i = 0; i < csmaNodes.GetN (); ++i) anim.UpdateNodeDescription (csmaNodes.Get (i), "CSMA"); // Optional anim.UpdateNodeColor (csmaNodes.Get (i), 0, 0, 255); // Optional anim.EnablePacketMetadata (); // Optional
NetAnim Start the animation
NetAnim Control the speed Simulation time Pause the animation
To show node trajectory Activated when double click a node NetAnim To show node trajectory Activated when double click a node Node trajectory
“Packets” tab for packet timeline NetAnim Packet timeline “Packets” tab for packet timeline
Application
Applications in NS-3 An Application generates packets Applications are associated with individual nodes Class ns3::Application can be used as a base class for ns3 applications Various application modules are provided by ns3 Application helper Can make it easy to install application to node With “Install” method
* CBR: constant bit rate Applications in NS-3 UdpEcho: A client sends packets to a server and the server returns packets OnOffApplication: During the “On” state, CBR traffic generated UdpClientServer: A UDP client and server BulkSendApplication: Send data up to MaxBytes or until the application is stopped (if MaxBytes is zero) PacketSink: Receive and consume packets V4Ping: Send one ICMP ECHO request, waits for a REPLY, and calculate RTT Ping6: Send ping with IPv6 address Radvd: Router advertisement daemon * CBR: constant bit rate
Application void Application::SetStartTime(Time time); Specifies when the application should be started The application subclasses should override the private StartApplication method, which is called at the time specified, to cause the application to begin void ApplicationContainer::Start(Time start); Call Application::SetStartTime method for all of applications in the application container
Applications in NS-3 void Application::SetStopTime(Time time); Specifies when an application is to stop The application subclasses should override the private StopApplication method, to be notified when that time has come void ApplicationContainer::Stop(Time stop); Call Application::SetStopTime method for all of applications in the application container
Applications in NS-3 virtual void Application::StartApplication(void); The StartApplication method is called at the start time specified by SetStartTime This method should be overridden by all or most application subclasses virtual void Application::StopApplication(void); The StopApplication method is called at the stop time specified by SetStopTime
UdpEcho server/client the port the server will wait on for incoming packets UdpEchoServerHelper UdpEchoServerHelper::UdpEchoServerHelper (uint16_t port2 ) ApplicationContainer UdpEchoServerHelper::Install (Ptr<Node> echoserver) UdpEchoClientHelper UdpEchoClientHelper::UdpEchoClientHelper (Address IP2, uint16_t port2) void UdpEchoClientHelper::Setattribute ( name, value ) ApplicationContainer UdpEchoClientHelper::Install (Ptr<Node> echoclient ) - Ptr<Node> node - std:string nodeName - NodeContainer c IP address and port number of the remote udp echo server
UdpEcho server/client Example UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0));
OnOffApplication Class ns::OnOffApplication Example Generate traffic to a single destination according to an OnOff pattern After Application::StartApplication is called, “On” and “Off” states alternate onTime and offTime variables duration of each state “Off” state: no traffic is generated, “On” state: CBR traffic is generated The attributes, data rate and packet size, characterize CBR traffic Example Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); onoff.SetAttribute (“DataRate”, StringValue (“14kb/s”));
Attributes for OnOffApplication DataRate: The data rate in on state. Set with class: DataRateValue Underlying type: DataRate Initial value: 500000bps PacketSize: The size of packets sent in on state Set with class: ns3::UintegerValue Underlying type: uint32_t 1:4294967295 Initial value: 512 OnTime: A RandomVariable used to pick the duration of the 'On' state. Set with class: RandomVariableValue Underlying type: RandomVariable Initial value: Constant:1 OffTime: A RandomVariable used to pick the duration of the 'Off' state.
UdpClientServer A UDP client sends UDP packets and a UDP server receives UDP packets Classes PacketLossCounter: count the number of lost packets SeqTsHeader: Packet header for UDP client/server application sequence number, time stamp UdpClient/UdpServer: A UDP client/server UdpClientHelper/UdpServerHelper Create a client/server application UdpTraceClient UdpTraceClientHelper
Attributes for UdpClient MaxPackets: The maximum number of packets the application will send Set with class: ns3::UintegerValue Underlying type: uint32_t 0:4294967295 Initial value: 100 Interval: The time to wait between packets Set with class: ns3::TimeValue Underlying type: Time –9223372036854775808.0ns:+9223372036854775807.0ns Initial value: +1000000000.0ns RemoteAddress: The destination Address of the outbound packets Set with class: AddressValue Underlying type: Address Initial value: 00-00-00 RemotePort: The destination port of the outbound packets Underlying type: uint16_t 0:65535 PacketSize: Size of packets generated. The minimum packet size is 12 bytes which is the size of the header carrying the sequence number and the time stamp. Underlying type: uint32_t 12:1500 Initial value: 1024
Attributes for UdpServer Port: Port on which we listen for incoming packets. Set with class: ns3::UintegerValue Underlying type: uint16_t 0:65535 Initial value: 100 PacketWindowSize: The size of the window used to compute the packet loss. This value should be a multiple of 8. Underlying type: uint16_t 8:256 Initial value: 32 Private Attributes PacketLossCounter m_lossCounter Lost packet counter uint16_t m_port Port on which we listen for incoming packets. uint32_t m_received Number of received packets.
Simulation Example
Simulation Example UDP packet transmission OnOff application Point-to-point link
UdpEcho Application Example (1) #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 (“OnOffExample"); int main (int argc, char *argv[]) { bool verbose = true; CommandLine cmd; cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); cmd.Parse (argc,argv); To determine whether the logging components are enabled or not command line argument for variable “verbose”
UdpEcho Application Example (2) if (verbose) { LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); } NodeContainer p2pNodes; // create the nodecontainer, “p2pNodes” p2pNodes.Create (2); // If verbose = 1, log components are enable Create a node container and 2 nodes for p2p link
UdpEcho Application Example (3) PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer p2pDevices; p2pDevices = pointToPoint.Install (p2pNodes); InternetStackHelper stack; stack.Install (p2pNodes.Get (0)); stack.Install (p2pNodes.Get (1)); p2p link generation and install on the p2p nodes Install Internet stack on the nodes
UdpEcho Application Example (4) Allocate IP address Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer p2pInterfaces; p2pInterfaces = address.Assign (p2pDevices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (p2pNodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); UdpEchoClientHelper echoClient (p2pInterfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (100)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); Setup echoServer and Install it on node1 Setup echoClient Attributes of echoClient
UdpEcho Application Example (5) ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); pointToPoint.EnablePcapAll ("second"); Simulator::Run (); Simulator::Destroy (); return 0; } Install echoClient on node0 enable pcap tracing
OnOff Application Example (1) #include <iostream> #include <fstream> #include "ns3/point-to-point-module.h" #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/applications-module.h" #include "ns3/internet-module.h" using namespace ns3; int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv);
OnOff Application Example (2) NodeContainer terminals; terminals.Create (2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer p2pDevices; p2pDevices = pointToPoint.Install (terminals); Create a node container and 2 nodes for p2p link Create a netdevice container and p2p link
OnOff Application Example (3) InternetStackHelper internet; internet.Install (terminals.Get (0)); internet.Install (terminals.Get (1)); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); ipv4.Assign (p2pDevices); Install Internet stack on the nodes Allocate IP address
OnOff Application Example (4) uint16_t port = 9; OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); onoff.SetAttribute ("OnTime", StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”)); onoff.SetAttribute ("OffTime", StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”)); onoff.SetAttribute ("DataRate", DataRateValue(5000000)); ApplicationContainer app = onoff.Install (terminals.Get (0)); app.Start (Seconds (1.0)); app.Stop (Seconds (10.0)); Setup OnOff application Install OnOff application sender on a node
OnOff Application Example (5) PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); app = sink.Install (terminals.Get (1)); app.Start (Seconds (1.0)); Simulator::Stop(Seconds (15)); Simulator::Run (); Simulator::Destroy (); } Create a packet sink to receive packets and install it on a node Running simulator
Exercise
Exercise UDP Udpclientserver application p2p link: DataRate 5 Mbps, Delay 10 us Application & flow Udpclientserver Application UDP flow: node0 node1, UDP 5 Mbps, 1 – 10s
Exercise 2. (Optional) use NetAnim Check and verify all the output system of onoff application example print out all of the logging into .out file use AsciiTraceHelper use PCAP trace and … Check .pcap file both TCPDUMP and Wireshark 2. (Optional) use NetAnim
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
Thank You !