Armor Network Technology

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

How to create a simple simulation scenario

Print

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

Trace::SetTraceLevel(TRACE_DEBUG); 

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

 
Trace::SetTraceLayer(Protocol::Trace(PT_PING)|Protocol::Trace(PT_SIPV4)); 

this is the name of your trace file. all output will written to this file at your working directory

char outputFileName[128]="pingtrace.txt"; 
 

here I have used a temporary variable for number of nodes

const int numNode = 2;


set NumberOfPhyMedium from Simulator class to number of nodes
Simulator::NumberOfPhyMedium()=numNode;


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

Simulator::SetDomainBoundary(0,0,100,100); 
 

now we instantiate an object of class Simulator

Simulator sim; 
 

then we set the trace file to the name we already choosed

sim.SetTraceFile(outputFileName);


now we instantiate two Mobile Node object

MobileNode n[numNode]; 
 

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

WirelessMedium space(PT_WIRELESS,PT_IFACE,numNode); 
 

now we set the position of our two node SetPosition(x,y)

n[0].SetPosition(0,0); 
n[1].SetPosition(100,100); 
 

for (int i=0;i<numNode;i++){ 
 // SetNodeStructure methods set the Structure of the node. what this means? 
 // Node structure is defined according to the 4 layer IP structure.  
 // you can define other type of nodes according to 7 layer OSI or what ever you want 
 // but for this 4 layer structure we should tell the simulator type of protocol that should be used at each layer 
 // we have created very flexible structure here you can have multi-interface, multi-protocol and multi-application nodes and we will tell you how to create such nodes in more advanced manuals. 
 // Node and MobileNode which are defined here are 4-layer multi-interface, multi-application, but you will have just IP protocol at Network layer 
 // in SetNodeStructure method first parameter determines type of Network Protocol 
 // second parameter determines type of MAC protocol 
 // third parameter determines type of physical protocol 
 // the last parameter which is an integer is determines number of different interface in the node 
 // if you set this integer greater than other interface will be created but all will have the same physical and MAC protocol.  
 // we will discuss commands to set every protocol independently in more advanced manuals 
 n[i].SetNodeStructure(PT_SIPV4,PT_MAC_802_11,PT_IFACE,1); 
 
 // here we set the MAC protocol bandwidth (in Bytes/ms) and propagation delay (ms) 
 n[i].PhyMediumProtocol(0,0,1)->SetParameters(256,1); 
 
 // this command is actually determines number of applications we want to have at each node  
 // each application should be assigned to a port number later 
 n[i].SetNumberOfAgents(1); 
 
 // this command connect each node we have created to our Wireless Medium which we choose a name space for it 
 // first parameter is the address of node 
 // second parameter is the address of Wireless Medium (space)  
 // third parameter is the physical address of interface on the node which will be bound to wireless medium 
 // forth parameter is the physical address of interface on wireless medium which will be bound to this node 
 // its clear that for each node we should have a physical interface on the wireless medium 
 // and when we connect the nodes this address should be increased one by one  
 sim.Connect(&n[i],&space,0,i); 
} 
 

OK now we create an object of our new protocol

PingProtocol *ping1;

BECAREFUL you MUST always use Create method to create new object from any type of protocol

ping1=(PingProtocol*)Protocol::Create(PT_PING);


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

ping1->Start(0); 
 

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

n[0].AttachAgent(ping1,PT_UDP,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  

  
PingProtocol *ping2; 
ping2=(PingProtocol*)Protocol::Create(PT_PING); 
//ping->Start(0); 
n[1].AttachAgent(ping2,PT_UDP,USER_PORT_START); 
 

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

sim.Connect(ping1,ping2); 
 

this command will set the simulation time in milliseconds. after this time the simulation will ends

sim.Finish(1000); 
 

OK this last command will start the simulation

sim.Run();

Back to: How to write simple ping protocol

 

 

 

 

Last Updated on Tuesday, 08 February 2011 02:53  

Login