Armor Network Technology

  • Increase font size
  • Default font size
  • Decrease font size

How to write simple ping protocol?

Print

HOW to write simple ping protocol?

we are going to implement simple ping protocol similar to Marc Greis protocol for NS2 (http://www.isi.edu/nsnam/ns/tutorial/nsnew.html)

this is a simple application which will show you

* Important Base classes of the simulator

* How to add new protocol to the simulator

* How to create a simple simulation scenario

* How to compile and run a simulation

* How to analyze the result of simulation

 

 

I. First step, create a folder with name related to your protocol in the GONS root folder

I will create folder ping for this purpose

 

II. Create a file README in this folder.

Document your work from the start.

we will provide separate guideline for writing useful readme file for user projects

 

II. Create a file Header.h in this folder.

create a simple text file in your new created folder and name it header.h

your project will not linked to the GONS library if you forget to create this file.

All files in this folder which have a .cpp or .h extension will be compiled and linked to the project automatically

this file will have another job too. I will describe it later in this manual.

 

III. Create project files.

I will create two file ping.h and ping.cpp for this simple application

you are free to create as many file as you may need

but BECAREFUL:

All files in this folder which have a .cpp or .h extension will be compiled and linked to the project automatically

therefore remove any unused .h or .cpp file from your project folder

 

IV. Create protocol and packet header prototypes

NOW we are going to do the real work

open the header file of you project (e.g. ping.h)

and click on this link

 

V. Create body for method functions

open the cpp file (e.g. ping.cpp)

and click on this link

 

VI. define new protocol and packet types

open the header.h file

and click on this link

 

VII. Create a simple scenario

Create another folder anywhere you want and choose name for scenario file

I will create pingtest.h for this purpose

click on this link for details

 

VIII. Recompile the Simulator & Run the simulation

Copy your new protocol folder to the GONS root folder.

You can download Simple Ping Protocol from here

Open the terminal window and cd to main GONS directory

:~$ cd gondishapur-network-simulator-0.2.0

reconfigure the package

:~$ ./reconfiguregons.sh

from now on your new protocol is integrated to the package and whenever you want to make change to it you should just issue make command.

:~$ make

Now cd to your scenario directory (e.g. ex)

run this command

:~$ gons.sh pingtest.h
Gondishapur-Network-Simulator 0.2.0
Copyright (C) 2011/01/17 by arm-net.com
For help and support please visit http://www.arm-net.com/
...
end of simulation

VIII. Analyzing results

Open the output trace file in the same directory. we have name it pingtrace.txt

Now we are going to analyze the result of simulation of simple ping scenario

in line number 1 you can see that at time 0 (t: 0) a new event (EVENT_ACTION in seventh colon ) is received (R in fifth colon) by ping protocol (PT_PING in sixth colon) at node number 0 (ip: 0).

After receiving this event the node has sent (see line 2) a ping packet (PKT_PING in colon 11) the id of this packet it 7 ( id: 7) and the ping message type is echo request (echo: 1). remember when we write this value.

In line 3 and 4 you can see the same packet is received and sent by the network protocol of the node

In line 5 and 6 you can see that the packet is received and sent by the network protocol of node number 1.

In line 7 the same packet is received to the ping protocol of node 1.

In line 8 you can see the new packet it generated with id 17 (id: 14) and message type of the packet is echo replay (echo: -1)

This packet has traveled the reverse path and in line 13 is received to ping protocol of node number 1

In line 14 ping protocol of node 0 has write a summary of pinging node 1

t: 0     ip: 0     R PT_PING    ad: 0   EVENT_ACTION New_Event_Received 
t: 0     ip: 0     S PT_PING    ad: 0   id: 7     PKT_PING   echo: 1 Packet_Sent_Down 
t: 0     ip: 0     R PT_SIPV4   ad: 0   id: 7     PKT_UDP    echo: 1 New_Packet_Received 
t: 0     ip: 0     S PT_SIPV4   ad: 0   id: 7     PKT_IPV4   echo: 1 Packet_Sent_Down 
t: 1     ip: 1     R PT_SIPV4   ad: 0   id: 7     PKT_IPV4   echo: 1 New_Packet_Received 
t: 1     ip: 1     S PT_SIPV4   ad: 0   id: 7     PKT_IPV4   echo: 1 Packet_Sent_Up 
t: 1     ip: 1     R PT_PING    ad: 0   id: 7     PKT_PING   echo: 1 New_Packet_Received 
t: 1     ip: 1     S PT_PING    ad: 0   id: 14    PKT_PING   echo: -1 Packet_Sent_Down 
t: 1     ip: 1     R PT_SIPV4   ad: 0   id: 14    PKT_UDP    echo: -1 New_Packet_Received 
t: 1     ip: 1     S PT_SIPV4   ad: 0   id: 14    PKT_IPV4   echo: -1 Packet_Sent_Down 
t: 2     ip: 0     R PT_SIPV4   ad: 0   id: 14    PKT_IPV4   echo: -1 New_Packet_Received 
t: 2     ip: 0     S PT_SIPV4   ad: 0   id: 14    PKT_IPV4   echo: -1 Packet_Sent_Up 
t: 2     ip: 0     R PT_PING    ad: 0   id: 14    PKT_PING   echo: -1 New_Packet_Received 
t: 2     ip: 0     P PT_PING    ad: 0   Send Time:0 Received Time:1 Trip Time:2 
*** end of simulation ***

 

Last Updated on Tuesday, 15 February 2011 15:42  

Login