Session 4. 어플리케이션 및 헤더 만들기 변성호, 이규진

Slides:



Advertisements
Similar presentations
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Advertisements

Introduction 1.  A Simulator  Modular (Component-based)  Open-architecture  For Discrete Event Networks.
1 ns-2 Tutorial, part 2 Dave Anderson, Xiaowei Yang (Modified from Polly Huang’s slides)
How to Add a New Protocol in NS2 Xu Leiming CSCW Lab. at CS Dept., Tsinghua Univ. June 1, 2001.
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
ECE Department: University of Massachusetts, Amherst ECE 354 Lab 3: Transmitting and Receiving Ethernet Packets.
UDP & TCP Where would we be without them!. UDP User Datagram Protocol.
Networks I Transmission Control Protocol Instituto Tecnológico y de Estudios Superiores de Monterrey Campus Estado de México Prof. MSc. Ivan A. Escobar.
Transmission Control Protocol (TCP) Basics
Copyright node This presentation is a subset of the one presented by:
Students:Gilad Goldman Lior Kamran Supervisor:Mony Orbach Mid-Semester Presentation Spring 2005 Network Sniffer.
TCP. Learning objectives Reliable Transport in TCP TCP flow and Congestion Control.
John Degenhart Joseph Allen.  What is FTP?  Communication over Control connection  Communication over Data Connection  File Type  Data Structure.
QualNet 2014/05/ 尉遲仲涵. Outline Directory Structure QualNet Basic Message & Event QualNet simulation architecture Protocol Model Programming.
Penetration Testing Security Analysis and Advanced Tools: Snort.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
1 Ch 3. Network Programming. 2 Network Programming (1)  Network allows arbitrary applications to communicate E.g., client-server computing such as WEB.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
LWIP TCP/IP Stack 김백규.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
1 CS4550 Computer Networks II TCP/UDP Ref: Feit Chap 9 Tanenbaum Chap 6.
1 The Internet and Networked Multimedia. 2 Layering  Internet protocols are designed to work in layers, with each layer building on the facilities provided.
© Jörg Liebeherr (modified by M. Veeraraghavan) 1 ICMP: A helper protocol to IP The Internet Control Message Protocol (ICMP) is the protocol used for error.
Transmission Control Protocol
Wireless Software R&D Group, IITP RAS Kirill Andreev, Aleksey Kovalenko, Dmitriy Lakontsev Realization of IEEE802.11s draft standard in NS-3.3 Institute.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2000 Transmission Control Protocol (TCP)
Chapter 2 Applications and Layered Architectures Sockets.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Network Programming Chapter 5: Raw Socket Programming.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
CS433/533 Assignment 4 Overview. Fishnet Network protocol simulator & emulator Read fishnet-intro.pdf Get started Network topology (.topo) for emulator.
GPRS functionality overview in Horner OCS. GPRS functionality – Peer to Peer communication over GPRS – CSCAPE connectivity over GPRS – Data exchange using.
Today’s topic: UDP Reliable communication over UDP.
Protocol Layering Chapter 11.
Voice Over Internet Protocol (VoIP) Copyright © 2006 Heathkit Company, Inc. All Rights Reserved Presentation 5 – VoIP and the OSI Model.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
LonWorks Introduction Hwayoung Chae.
1 Network Communications A Brief Introduction. 2 Network Communications.
Introduction to Omnet++ By: Mahsa Soheil Shamaee.
Introductions of SDN in NS-3
The Data Link Layer RIS 251 Dr. ir. S.S. Msanjila.
SOCKET PROGRAMMING Presented By : Divya Sharma.
ns-3 Training 5/08/2017 Computer and Communication Network Lab
Chapter 9: Transport Layer
Instructor Materials Chapter 9: Transport Layer
A quick intro to networking
Transport Layer.
CS 1652 Jack Lange University of Pittsburgh
Process-to-Process Delivery, TCP and UDP protocols
Layered Architectures
Session 3. Pcap 출력, animator 사용법 및 ns-3 기본 제공 어플리케이션
Session 2. Logging과 Command Line Argument 사용법
Communication Networks NETW 501 Tutorial 3
Session 1. ns-3 기초 신연철 Multimedia & Wireless Networking Laboratory, SNU
UNIX Sockets Outline Homework #1 posted by end of day
ns-3 Waf build system ns-3 Annual Meeting June 2017
Dr. John P. Abraham Professor UTPA
TRANSMISSION CONTROL PROTOCOL
Dr. John P. Abraham Professor UTPA
Ns-3 Tutorial Xin Li.
Active Tests and Traffic Simulation: Module Objectives
Active Tests and Traffic Simulation: Module Objectives
Ns-3 Training: Packets ns-3 Annual meeting June 2016.
Anant Mudambi, U. Virginia
ns-3 training Tom Henderson ns-3 annual meeting 2019
Transport Layer 9/22/2019.
Exceptions and networking
Presentation transcript:

Session 4. 어플리케이션 및 헤더 만들기 변성호, 이규진 Multimedia & Wireless Networking Laboratory, SNU shbyeon@mwnl.snu.ac.kr gjlee@mwnl.snu.ac.kr

Contents Application in NS-3 Application Example Header in NS-3 Header Example Exercise

Application in NS-3

Application Class ns3::Application can be used as a base class for ns3 applications Applications are associated with individual nodes Each node holds a list of references (smart pointers) to its applications The main purpose of the base class application public API is to provide a uniform way to start and stop applications Conceptually, an application has zero or more ns3::Socket objects associated with it, that are created using the Socket API of the Kernel capability

Application Helper Application helper can make it easy to install application to node Using application helper, simulation script can become more simpler Only “Install” method

Application void Application::SetStartTime(Time time); This method specifies when the application should be started The application subclasses should override the private "StartApplication" method defined below, 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

Application 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

Application void Application::SetStopTime(Time time); The Stop method 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

Application virtual void Application::StopApplication(void); The StopApplication method is called at the stop time specified by SetStopTime This method should be overridden by all or most application subclasses

Application Example

Overview Creating new application called “NewApp” UDP traffic generator Sender mode / Receiver mode # of packets, data rate can be prescribed

Interface Using UDP socket

Source codes

wscript All ns-3 modules depend on the core module and usually on other modules. This dependency is specified in the wscript file. The new files are added to the wscript file found in each directory

Module dependency Modify “wscript” file in src/applications folder def build(bld): module = bld.create_ns3_module('applications', ['internet', 'config-store', 'tools']) module.source = [ … 'model/new-app.cc', 'helper/new-app-helper.cc', ] headers.source = [ 'model/new-app.h', 'helper/new-app-helper.h',

NewApp Class definition (new-app.h) class NewApp : public Application { public: static TypeId GetTypeId (void); NewApp (); virtual ~NewApp (); private: virtual void StartApplication (void); virtual void StopApplication (void); void ScheduleTx (void); void SendPacket (void); void HandleRead (Ptr<Socket> socket); Functions to handle packet transmission and reception

NewApp Class definition (new-app.h) bool m_mode; // Tx: true, Rx: false Address m_address; uint32_t m_nPackets; DataRate m_dataRate; Ptr<Socket> m_socket; uint32_t m_packetSize; uint32_t m_packetsSent; EventId m_sendEvent; bool m_running; TracedCallback<Ptr<const Packet> > m_txTrace; TracedCallback<Ptr<const Packet> > m_rxTrace; };

NewApp Constructor (new-app.cc) Packet size = 1000 NewApp::NewApp () : m_socket (0), m_packetSize (1000), m_packetsSent (0), m_running (false) { NS_LOG_FUNCTION (this); } Packet size = 1000

GetTypeId TypeId Application::GetTypeId (void) Get the TypeId TypeId ns3::TypeId::SetParent (TypeId tid) Record in this TypeId which TypeId is the TypeId of the base class of the subclass. TypeId ns3::TypeId::AddConstructor (void) Record in this TypeId the fact that the default constructor is accessible TypeId ns3::TypeId::AddAttribute ( … ) Record in this TypeId the fact that a new attribute exists TypeId ns3::TypeId::AddTraceSource ( … ) Record in this TypeId the fact that a new trace source exists

GetTypeId TypeId NewApp::GetTypeId (void) (new-app.cc) Name Help text static TypeId tid = TypeId ("ns3::NewApp") .SetParent<Application> () .AddConstructor<NewApp> () .AddAttribute ("Mode", "The mode : Sender(true), Receiver(false)", BooleanValue (false), MakeBooleanAccessor (&NewApp::m_mode), MakeBooleanChecker ()) .AddAttribute ("Address", "The address", AddressValue (), MakeAddressAccessor (&NewApp::m_address), MakeAddressChecker ()) Name Help text Intial value Associated value

GetTypeId TypeId NewApp::GetTypeId (void) (new-app.cc) Name Help text .AddAttribute ("NPackets", "The total number of packets to send", UintegerValue (10000), MakeUintegerAccessor (&NewApp::m_nPackets), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("DataRate", "The data rate", DataRateValue (DataRate ("500kb/s")), MakeDataRateAccessor (&NewApp::m_dataRate), MakeDataRateChecker ()) .AddTraceSource("Tx", "A new packet is created and is sent", MakeTraceSourceAccessor(&NewApp::m_txTrace)) .AddTraceSource("Rx", "A packet has been received", MakeTraceSourceAccessor (&NewApp::m_rxTrace)) ; return tid; } Name Help text Trace source

StartApplication virtual void Application::StartApplication (void) (new-app.cc) void NewApp::StartApplication (void) { NS_LOG_FUNCTION (this); if(m_mode == true) if(!m_socket){ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socket = Socket::CreateSocket(GetNode(), tid); m_socket->Bind(); m_socket->Connect(m_address); } m_running = true; SendPacket(); Sender Mode Create UDP socket & Connect to receiver Packet transmission

StartApplication virtual void Application::StartApplication (void) (new-app.cc) else { if(!m_socket){ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); m_socket = Socket::CreateSocket(GetNode(), tid); m_socket->Bind(m_address); m_socket->Listen(); m_socket->ShutdownSend(); m_socket->SetRecvCallback (MakeCallback (&NewApp::HandleRead, this)); } Receiver Mode Create UDP socket & Prepare to receive Register callback function for packet reception

Packet Transmission void NewApp::SendPacket () (new-app.cc) void NewApp::SendPacket (void) { NS_LOG_FUNCTION (this); Ptr<Packet> packet = Create<Packet> (m_packetSize); m_txTrace(packet); m_socket->Send(packet); if(++m_packetsSent < m_nPackets) ScheduleTx(); } Create a packet Tracing Send a packet Schedule next packet transmission

Packet Transmission void NewApp::ScheduleTx () (new-app.cc) void NewApp::ScheduleTx (void) { if(m_running) Time tNext ( Seconds (m_packetSize*8/static_cast<double>(m_dataRate.GetBitRate()))); m_sendEvent = Simulator::Schedule(tNext, &NewApp::SendPacket, this); } Calculate next packet transmission time & Schedule transmission event

Packet Reception void NewApp::HandleRead (Ptr<Socket> socket) (new-app.cc) void NewApp::HandleRead (Ptr<Socket> socket) { Ptr<Packet> packet; Address from; while ((packet = m_socket->RecvFrom(from))) if(packet->GetSize() > 0) m_rxTrace(packet); } Receive a packet Tracing

StopApplication virtual void Application::StopApplication(void) (new-app.cc) void NewApp::StopApplication () { NS_LOG_FUNCTION (this); m_running = false; if(m_sendEvent.IsRunning()) Simulator::Cancel (m_sendEvent); } if(m_socket) m_socket->Close(); Cancel next packet transmission Close a socket

NewAppHelper Class definition (new-app-helper.h) class NewAppHelper { public: NewAppHelper (bool mode, Address address); void SetAttribute (std::string name, const AttributeValue &value); ApplicationContainer Install (Ptr<Node> node) const; ApplicationContainer Install (std::string nodeName) const; ApplicationContainer Install (NodeContainer c) const; private: Ptr<Application> InstallPriv (Ptr<Node> node) const; ObjectFactory m_factory; };

NewAppHelper Helper functions (new-app-helper.cc) NewAppHelper::NewAppHelper (bool mode, Address address) { m_factory.SetTypeId ("ns3::NewApp"); m_factory.Set ("Mode", BooleanValue (mode)); m_factory.Set ("Address", AddressValue (address)); } void NewAppHelper::SetAttribute (std::string name, const AttributeValue &value) { m_factory.Set (name, value); ApplicationContainer NewAppHelper::Install (Ptr<Node> node) const { return ApplicationContainer (InstallPriv (node)); Set “Mode” and “Address” attribute for NewApp Set attribute for NewApp Install NewApp (omit details)

Simulation Script Sender part Setup destination address int main (int argc, char *argv[]) { … uint16_t port = 8080; Address destination (InetSocketAddress (interfaces.GetAddress (1), port)); NewAppHelper sender (true, destination); sender.SetAttribute("NPackets", UintegerValue(10)); sender.SetAttribute("DataRate", DataRateValue(DataRate("8Mb/s"))); ApplicationContainer senderApp = sender.Install(nodes.Get(0)); senderApp.Start (Seconds(1.0)); senderApp.Stop (Seconds(5.0)); } Setup destination address Make a NewAppHelper, Set Attribute for NewApp, Install NewApp to a node Setup time to start and stop

Simulation Script Receiver part Setup address to receive int main (int argc, char *argv[]) { … Address any (InetSocketAddress (Ipv4Address::GetAny(), port)); NewAppHelper receiver (false, any); ApplicationContainer receiverApp = receiver.Install(nodes.Get(1)); receiverApp.Start (Seconds(0.5)); receiverApp.Stop (Seconds(7.0)); } Setup address to receive Make a NewAppHelper, Install NewApp to a node Setup time to start and stop

Simulation Script Connect trace sources to callback function int main (int argc, char *argv[]) { … senderApp.Get(0)->TraceConnectWithoutContext("Tx", MakeCallback (&PacketTx)); receiverApp.Get(0)->TraceConnectWithoutContext("Rx", MakeCallback (&PacketRx)); }

Simulation Script Callback functions Print tx time Print rx time static void PacketTx (Ptr<const Packet> p) { NS_LOG_UNCOND (Simulator::Now().GetSeconds() << "\t“ << "A new packet is sent at Node 0"); } static void PacketRx (Ptr<const Packet> p) NS_LOG_UNCOND (Simulator::Now().GetSeconds() << "\t" << "A packet is received at Node 1"); Print tx time Print rx time

Header in NS-3

Packet Structure A packet has two types of fields Header Payload Header fields & Payload field Header Supplemental data placed at the beginning of a payload Payload A block of data being transmitted

Packet Structure Example Headers Payload PHY Header MAC Header LLC Header IP Header TCP Header

Header Class Using Header class Base class for every protocol headers Define pure virtual methods Serialization, Deserialization, Print, etc. Each protocol header class implement this methods Used in tandem with the Packet class Attach header: AddHeader method Detach header: RemoveHeader method

Function of Header Class TypeId Header::GetTypeId(void) Get the type ID virtual void Header::Serialize(Buffer::Iterator start) const Used by Packet::AddHeader to store a header into the byte buffer of a packet start: an iterator which points to where the header should be written Convert value into byte stream Using Buffer Iterator functions WriteU8, WriteHtonU32, WriteHtonU64, etc.

Function of Header Class virtual uint32_t Header::GetSerializedSize(void) const Used by Packet::AddHeader to store a header into the byte buffer of a packet Return the expected size of the header by Serialize

Function of Header Class virtual uint32_t Header::Deserialize(Buffer::Iterator start) Used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet start: an iterator which points to where the header should read from Return the number of bytes read Convert byte stream into values Using Buffer Iterator functions ReadU8, ReadNtohU32, ReadNtohU64, etc.

Function of Header Class virtual void Header::Print(std::ostream& os) const Used by Packet::Print to print the content of a trailer as ascii data to a c++ output stream os: output stream to print

Header Example

Other headers(IP, UDP, etc) Overview Creating a new header called “NewHeader” Application header Attach current time(ms) before payload It can be used to measure end-to-end delay Other headers(IP, UDP, etc) NewHeader Payload Time(ms) 8bytes

Overview Creating a new header called “NewHeader” Used in NewApp

Source codes

Module dependency Modify “wscript” file in src/internet folder def build(bld): obj = bld.create_ns3_module('internet', ['bridge', 'mpi', 'network', 'core']) obj.source = [ … 'model/new-header.cc', ] headers.source = [ 'model/new-header.h',

NewHeader Class definition (new-header.h) class NewHeader : public Header { public: static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; virtual void Print (std::ostream &os) const; virtual uint32_t GetSerializedSize (void) const; virtual void Serialize (Buffer::Iterator start) const; virtual uint32_t Deserialize (Buffer::Iterator start); void SetTime (void); uint64_t GetTime (void) const; private: uint64_t m_time; };

NewHeader GetTypeId & GetInstanceTypeId TypeId NewHeader::GetTypeId (void) { static TypeId tid = TypeId ("ns3::NewHeader") .SetParent<Header> () .AddConstructor<NewHeader> () ; return tid; } TypeId NewHeader::GetInstanceTypeId (void) const return GetTypeId();

NewHeader SetTime & GetTime Set current time (ms) void NewHeader::SetTime (void) { m_time = Simulator::Now().GetMicroSeconds(); } uint64_t NewHeader::GetTime (void) const return m_time; Set current time (ms)

NewHeader Serialize & GetSerializedSize Record time (64bits = 8bytes) void NewHeader::Serialize (Buffer::Iterator start) const { start.WriteHtonU64(m_time); } uint32_t NewHeader::GetSerializedSize (void) const return 8; Record time (64bits = 8bytes) Header size (64bits = 8bytes)

NewHeader Deserialize & Print Get time from header (64bits = 8bytes) uint32_t NewHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; m_time = i.ReadNtohU64(); return i.GetDistanceFrom(start); } void NewHeader::Print (std::ostream &os) const os << “m_time = " << m_time << "\n"; Get time from header (64bits = 8bytes) Distance = 8bytes Print time

NewHeader in NewApp void NewApp::SendPacket () (new-app.cc) void NewApp::SendPacket (void) { … Ptr<Packet> packet = Create<Packet> (m_packetSize); m_txTrace(packet); NewHeader hdr; hdr.SetTime(); hdr.Print(std::cout); packet->AddHeader(hdr); m_socket->Send(packet); } Make a NewHeader, Set time & Print, Attach header into packet

NewHeader in NewApp void NewApp::HandleRead (Ptr<Socket> socket) (new-app.cc) void NewApp::HandleRead (Ptr<Socket> socket) { … while ((packet = m_socket->RecvFrom(from))) NewHeader hdr; packet->RemoveHeader(hdr); uint64_t hdr_time = hdr.GetTime(); NS_LOG_INFO("header time at rx = " << hdr_time); m_rxTrace(packet); } Make a NewHeader, Detach header into packet Get time & Print

Header Example Result 8byte header, 0xf4240 = 1,000,000

Exercise

Other headers(IP, UDP, etc) Exercise Add sequence field into NewHeader Sequence field: Packet sequence Initial value = 0, Increase 1 for every packet Other headers(IP, UDP, etc) NewHeader Payload Sequence Time(ms) 2byte 8byte

Exercise Check packet sequence Print packet sequences Add trace value for sequence error Seq=1 Seq=2 Seq=3 time Sequence error!

References NS-3 Tutorial NS-3 Manual NS-3 Doxygen http://www.nsnam.org/docs/release/3.22/tutorial/ns-3-tutorial.pdf NS-3 Manual http://www.nsnam.org/docs/release/3.22/manual/ns-3-manual.pdf NS-3 Doxygen http://www.nsnam.org/docs/release/3.22/doxygen/index.html

Thank You !