Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션

Similar presentations


Presentation on theme: "Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션"— Presentation transcript:

1 Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션
구종회, 변성호 Multimedia & Wireless Networking Laboratory, SNU

2 Contents Tracing system Animator Application Exercise ASCII PCAP
UdpEcho OnOffApplication UdpClientServer Exercise

3 Tracing & Animator

4 Tracing System Tracing is a structured form of simulation output

5 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: > ) ns3::UdpHeader (length: > 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: > ) ns3::UdpHeader (length: > 9) Payload (size=1024)

6 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: > ) 08 ns3::UdpHeader ( 09 length: > 9) 10 Payload (size=1024)

7 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) IP > : UDP, length 1024 IP > : UDP, length 1024 $ tcpdump -nn -tt -r myfirst-1-0.pcap reading from file myfirst-1-0.pcap, link-type PPP (PPP) IP > : UDP, length 1024 IP > : UDP, length 1024

8 PCAP Tracing Reading output with Wireshark

9 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

10 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.

11 NetAnim How to build Summary of features
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

12 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).

13 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

14 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

15 NetAnim Start the animation

16 NetAnim Control the speed Simulation time Pause the animation

17 To show node trajectory Activated when double click a node
NetAnim To show node trajectory Activated when double click a node Node trajectory

18 “Packets” tab for packet timeline
NetAnim Packet timeline “Packets” tab for packet timeline

19 Application

20 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

21 * 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

22 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

23 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

24 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

25 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

26 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));

27 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”));

28 Attributes for OnOffApplication
DataRate: The data rate in on state. Set with class: DataRateValue Underlying type: DataRate Initial value: bps PacketSize: The size of packets sent in on state Set with class: ns3::UintegerValue Underlying type: uint32_t 1: 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.

29 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

30 Attributes for UdpClient
MaxPackets: The maximum number of packets the application will send Set with class: ns3::UintegerValue Underlying type: uint32_t 0: Initial value: 100 Interval: The time to wait between packets Set with class: ns3::TimeValue Underlying type: Time – ns: ns Initial value: ns RemoteAddress: The destination Address of the outbound packets Set with class: AddressValue Underlying type: Address Initial value: 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

31 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.

32 Simulation Example

33 Simulation Example UDP packet transmission OnOff application
Point-to-point link

34 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”

35 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

36 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

37 UdpEcho Application Example (4)
Allocate IP address Ipv4AddressHelper address; address.SetBase (" ", " "); 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

38 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

39 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);

40 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

41 OnOff Application Example (3)
InternetStackHelper internet; internet.Install (terminals.Get (0)); internet.Install (terminals.Get (1)); Ipv4AddressHelper ipv4; ipv4.SetBase (" ", " "); ipv4.Assign (p2pDevices); Install Internet stack on the nodes Allocate IP address

42 OnOff Application Example (4)
uint16_t port = 9; OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address (" "), port))); onoff.SetAttribute ("OnTime", StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”)); onoff.SetAttribute ("OffTime", StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”)); onoff.SetAttribute ("DataRate", DataRateValue( )); 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

43 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

44 Exercise

45 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

46 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

47 References Network Simulator NS-3 tutorial NS-3 manual
NS-3 tutorial NS-3 manual

48 Thank You !


Download ppt "Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션"

Similar presentations


Ads by Google