In this document we teach how to create simple simulation scenario
we will use ping application we have created as an application protocol
*** Simple ping application with 2 nodes wireless network ****
we set the trace level of the code first
when your code is ready and you are going to produce final results
to keep the trace file as small as possible set it to TRACE_ON; in this case you can only see PACKET traces
When you are developing your protocol set it to TRACE_DEBUG or TRACE_DEBUG2 to be able to trace every step of the code
by default none of the protocols write their trace to the output
to enable each protocol you should add it to TraceLayer by following command, use OR (|) operator between each protocol you want to add as shown here
currently available protocols are PT_CBR, PT_UDP, PT_SIPV4, PT_MAC_802_11,PT_IFACE and PT_WIRELESS
also our new defined protocol PT_PING, play with this options and check the trace file to get the idea
this is the name of your trace file. all output will written to this file at your working directory
here I have used a temporary variable for number of nodes
set NumberOfPhyMedium from Simulator class to number of nodes
if you are going to simulate a mobile wireless network you should set the boundary of the domain to keep the nodes from going outside of it
now we instantiate an object of class Simulator
then we set the trace file to the name we already choosed
now we instantiate two Mobile Node object
here we create an object of class WirelessMedium,
we postpone the description of it for more advanced manual
but for the moment the last parameter should always set to number of wireless nodes
now we set the position of our two node SetPosition(x,y)
OK now we create an object of our new protocol
BECAREFUL you MUST always use Create method to create new object from any type of protocol
after creating our protocol we set the start time equal to 0. it means at time 0 this protocol will send an echo request to destination
following command will attach created protocol to node zero
first parameter is pointer to the created application protocol
second argument determine transport protocol type
and the third parameter determine which port number this application will listening to
you can choose any port number greater than USER_PORT_START
for the second node we should repeat the exact scenario but we will do not want to send a ping from this node therefore we do not start this application
we have another Connect function here.
this method function will connect our two application protocol to each other
when we do this ping1 will be aware of IP address and port number of ping2 and vice versa
this command will set the simulation time in milliseconds. after this time the simulation will ends
OK this last command will start the simulation
Back to: How to write simple ping protocol




