Qualnet Layered Architecture - Binghamton

Transcription

Using Qualnet – Part IIAdding a Custom ProtocolQualnet’s Directory Structure QUALNET HOMEapplication– code for the application layer protocols and traffic generatorsbin– executable and configuration or input/output filesgui– the Visual Environment Toolsetinclude– common include filesmac– the code for the MAC layer protocolsmain– the basic framework designmobility– the code for the mobility modelsnetwork– the code for the network layer protocols and routing protocolsphy– the code for the physical layer modelstransport– the code for the transport layer protocols (TCP/UDP, RSVP, etc)tcplib– User models for simulating TCP applications such as FTP and Telnetverification – Sample files and outputs to verify protocol correctness2

Qualnet Layered ArchitectureThe simulation is a collection of network nodes, eachwith its own protocol stack parameters and statisticsFile addons/seq/node.hGeneral node’s infostructstruct struct node strstruct node str odeId;/*NodeAddressnodeId;/* thethe networknetwork addressaddress ofof thethe nodenode neratorunsigned short seed[3];/* seed for random number generator */*/longnumNodes;/*longnumNodes;/* numbernumber ofof nodesnodes inin thethe simulationsimulation */*/::/*/* Layer-specificLayer-specific informationinformation forfor thethe node.node. */*/PhyData*phyData[MAX NUM PHYS];//PhyData*phyData[MAX NUM PHYS];// phyphy layerlayerMacData*macData[MAX NUM INTERFACES];MacData*macData[MAX NUM INTERFACES]; //// MACMAC h*switchData;// MAC ata;// networknetwork layerlayerTransportData//TransportData transportData;transportData;// transporttransport ta;// application layerlayer::};};Layer-specific info3Messages, Packets, and TimersA message is a unit defining an interactionbetween protocols and between nodesTwo types of messages Packets – used for communication betweennodesTimers – allow protocols to schedule events ina future time4

Message-Related API FunctionsMESSAGE Alloc()Allocate a message and provide it with standardevent, layer, protocol infoMESSAGE InfoAlloc()Allocate additional user-specified space for optionalinformation about the eventMESSAGE PacketAlloc()Allocate space for the packet within the messageMESSAGE AddHeader()Add a header to the packet (usually called by eachlayer in the protocol stack)MESSAGE RemoveHeader()Remove a header from the packetMESSAGE AddVirtualPayload()Add virtual payload to a Message (increase tx delaywithout increasing array size)MESSAGE Duplicate()Copy the message, including its packet and userspecified space (info field)MESSAGE Send()Send the message as an event to the specifiedlayer and protocolMESSAGE Free()Free the message, once it has reached its finaldestination5Packet Life CycleApplicationApplicationMESSAGE Free( )MESSAGE Alloc( )MESSAGE PacketAlloc( )MESSAGE Send( )TransportTransportMESSAGE RemoveHeader()MESSAGE Send( )MESSAGE AddHeader()MESSAGE Send( )RoutingIPRoutingIPMACMACMESSAGE AddHeader()MESSAGE Send( )RadioIPMESSAGE RemoveHeader()MESSAGE Send( )MESSAGE AddHeader()MESSAGE Send( )MACMESSAGE RemoveHeader()MESSAGE Send( )RadioRadio6

Creating MessagesA pointer to the node creatingthe messageMessage*Message*MESSAGE Alloc(MESSAGE Alloc(NodeNode *node,*node,The stack layer at which this messagewill be processed nexte.g., NETWORK LAYERintint layerType,layerType,intint protocol,protocol,The specific protocol at the layerwhich will process this messagee.g., ROUTING PROTOCOL DSRintint eventType);eventType);The event that this message representse.g., MSG NETWORK FlushTables7Message ProcessingHandling functionfor tCheck eventType fieldIPnewMsgDSRAODVCheck protocolType fieldRadioMACNetworkTransportAppCheck layerType fieldmsgEvent queue8

Qualnet’s Protocol ModelingInitialization Function Allocate memory for each node’slocal variables Initialize local variables Process configuration file(s) Schedule the first eventPacket arrival ortimer expirationIdleMessage (packet or timer)processing function Modify state variables Update local statistics Generate/forward packetsFinalization Function Output statistics9Adding a Protocol to QualnetDetermine what layer your protocol willoperate atImplement four/five main functions Initialization functionPacket/event handling functionRouter function (for routing protocol)Finalization functionHook up the above functions to theprotocol dispatching functions of thecorresponding layer10

Example: Adding a New Routing ProtocolSimplified Routing Information Protocol(SRIP) Table-driven, distance vector protocolUsing periodic route update, no triggeredupdate, no split horizonWorking properly in static networks with onlya small number of nodes (no node failure)Supporting only one interface (wireless) pernode11Distributed Bellman-Ford AlgorithmWhat local information is maintained by each node?Initial routing table for ARouting TableDestinationNext hopCostDestinationNext hop:::AAB-:-Cost0 What information is exchanged between neighboringnodes?Route AdvertisementDestinationCost::How a node processes a route advertisement?A node A updates its entry for destination D only when theadvertised cost to D is lower than its current cost12

SRIP Header File (network/srip.h)#ifndef SRIP H#ifndef SRIP H#define SRIP H#define SRIP H#define SRIP INFINITY 16#define SRIP INFINITY 16typedef struct srip table entrytypedef struct srip table entry{{NodeAddress destination;NodeAddress destination;NodeAddress nextHop;NodeAddress nextHop;unsigned int distance;unsigned int distance;} SripTableEntry;} SripTableEntry;Routing table entrytypedef struct srip strtypedef struct srip al;SripTableEntry* routingTable;SripTableEntry* routingTable;Local SRIP variables per nodes/* statistic *//* statistic */unsigned int numRouteUpdatesBroadcast;unsigned int numRouteUpdatesBroadcast;} SripData;} SripData;void SripInit(Node* node, SripData** sripPtr,void SripInit(Node* node, SripData** sripPtr,const NodeInput* nodeInput, int interfaceIndex);const NodeInput* nodeInput, int interfaceIndex);Function prototypes to be recognizedvoid SripHandleProtocolEvent(Node* node, Message* msg);void SripHandleProtocolEvent(Node* node, Message* msg);void SripHandleProtocolPacket(Node* node, Message* msg,by Qualnet’s network layer (IP)void SripHandleProtocolPacket(Node* node, Message* msg,NodeAddress sourceAddress);NodeAddress sourceAddress);void SripFinalize(Node *node);void SripFinalize(Node *node);void SripRouterFunction(Node* node, Message* msg, NodeAddress destAddr,void SripRouterFunction(Node* node, Message* msg, NodeAddress destAddr,NodeAddress previousHopAddress, BOOL* packetWasRouted);NodeAddress previousHopAddress, BOOL* packetWasRouted);#endif#endif13SRIP Initialization FunctionCalled when each node is initialized by Qualnetvoid SripInit(Node*node,void pPtr,const NodeInput* nodeInput,const NodeInput* t i; BOOL retVal;int i; BOOL retVal;Message* newMsg;Message* newMsg;SripData* srip;SripData* srip;if (MAC IsWiredNetwork(node, interfaceIndex))if (MAC IsWiredNetwork(node, interfaceIndex))ERROR ReportError("SRIP supports only wireless interfaces");ERROR ReportError("SRIP supports only wireless interfaces");Make sure the node hasexactly one wireless interfaceif (node- numberInterfaces 1)if (node- numberInterfaces 1)ERROR ReportError("SRIP only supports one interface of node");ERROR ReportError("SRIP only supports one interface of node");/* allocate memory for SRIP's variables for this node *//* allocate memory for SRIP's variables for this node */(*sripPtr) (SripData*) MEM malloc(sizeof(SripData));(*sripPtr) (SripData*) MEM malloc(sizeof(SripData));srip *sripPtr;srip *sripPtr;/* read parameter from the configuration file *//* read parameter from the configuration file */IO ReadTime(node- nodeId,IO ReadTime(node- nodeId,ANY ADDRESS,ANY ,"SRIP-UPDATE-INTERVAL",&retVal,&retVal,&(srip- updateInterval));&(srip- updateInterval));if (retVal FALSE)if (retVal FALSE)ERROR ReportError("SRIP-UPDATE-INTERVAL not specified!");ERROR ReportError("SRIP-UPDATE-INTERVAL not specified!");Allocate memory for local SRIPvariables within each nodeRead SRIP parameterfrom the main config file(to be continued)14

SRIP Initialization Function(continued)/*/* allocateallocate andand initializeinitialize thethe routingrouting tabletable forfor thisthis nodenode */*//**//* Note:Note: (n 1)(n 1) entriesentries areare allocatedallocated forfor convenienceconvenience*/srip- routingTable (SripTableEntry*)srip- routingTable (SripTableEntry*)MEM malloc(sizeof(SripTableEntry)*node- numNodes 1);MEM malloc(sizeof(SripTableEntry)*node- numNodes 1);forfor (i(i 1;1; ii node- numNodes;node- numNodes; i )i ) {{srip- routingTable[i].destinationsrip- routingTable[i].destination i;i;srip- routingTable[i].nextHop INVALID ADDRESS;srip- routingTable[i].nextHopINVALID ADDRESS;srip- routingTable[i].distance SRIP INFINITY;srip- routingTable[i].distance SRIP INFINITY;}}srip- routingTable[node- nodeId].nextHopsrip- routingTable[node- nodeId].nextHop node- nodeId;node- nodeId;srip- routingTable[node- nodeId].distancesrip- routingTable[node- nodeId].distance 0;0;/*/* InitializeInitialize statisticstatistic */*/srip- numRouteUpdatesBroadcastsrip- numRouteUpdatesBroadcast 0;0;Initialize routing tableInitialize statistic/*/* TellTell IPIP toto useuse ourour functionfunction toto routeroute packetspackets unction,interfaceIndex);interfaceIndex);Register routerfunction with IPSchedule the first route}}/*/* scheduleschedule thethe veryvery firstfirst routeroute updateupdate broadcastbroadcast */*/advertisement timernewMsgnewMsg MESSAGE Alloc(node,MESSAGE Alloc(node, NETWORK LAYER,NETWORK LAYER,ROUTING PROTOCOL SRIP,MSG NETWORK RTBroadcastAlarm);ROUTING PROTOCOL SRIP, MSG NETWORK RTBroadcastAlarm);MESSAGE Send(node,MESSAGE Send(node, newMsg,newMsg, pc nrand(node- seed)%srip- updateInterval);pc nrand(node- seed)%srip- updateInterval);15SRIP Event Handling FunctionCalled when a node’s timer expiresvoid SripHandleProtocolEvent(Node* node, Message* msg)void SripHandleProtocolEvent(Node* node, Message* msg){{int i, numEntries 0, pktSize;int i, numEntries 0, pktSize;Message* newMsg;Message* newMsg;char*pktPtr;char*pktPtr;/* Obtain a pointer to the local variable space *//* Obtain a pointer to the local variable space */SripData* srip (SripData*)SripData* srip (SripData*)NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);for (i 0; i node- numNodes; i ) {for (i 0; i node- numNodes; i ) {if (srip- routingTable[i].distance SRIP INFINITY)if (srip- routingTable[i].distance SRIP INFINITY)numEntries ;numEntries ;}}Obtain pointer to localvariable spacePrepare a route advertisement packetnewMsg MESSAGE Alloc(node, 0, 0, 0);newMsg MESSAGE Alloc(node, 0, 0, 0);pktSize sizeof(unsigned int) sizeof(SripTableEntry)*numEntries;pktSize sizeof(unsigned int) sizeof(SripTableEntry)*numEntries;MESSAGE PacketAlloc(node, newMsg, pktSize, TRACE ANY PROTOCOL);MESSAGE PacketAlloc(node, newMsg, pktSize, TRACE ANY PROTOCOL);pktPtr newMsg- packet;pktPtr newMsg- packet;memcpy(pktPtr, &numEntries, sizeof(unsigned int)); /* number of entries */memcpy(pktPtr, &numEntries, sizeof(unsigned int)); /* number of entries */pktPtr sizeof(unsigned int);pktPtr sizeof(unsigned int);Count the number/* Fill the packet with the valid table entries *//* Fill the packet with the valid table entries */for (i 1; i node- numNodes; i ) {valid entriesfor (i 1; i node- numNodes; i ) {if (srip- routingTable[i].distance SRIP INFINITY) {if (srip- routingTable[i].distance SRIP INFINITY) {memcpy(pktPtr, &(srip- routingTable[i]), sizeof(SripTableEntry));memcpy(pktPtr, &(srip- routingTable[i]), sizeof(SripTableEntry));pktPtr sizeof(SripTableEntry);pktPtr sizeof(SripTableEntry);}}(to be continued)}}of16

SRIP Event Handling Function(continued)/*/* SendSend thethe routeroute updateupdate packetpacket toto MACMAC layerlayer dRawMessageToMacLayer(node,/*nodepointer*/node,/* node pointer */newMsg,/*newMsg,/* rawraw messagemessage */*/node- nodeId,/*node- nodeId,/* sourcesource addressaddress */*/ANY DEST,/*ANY DEST,/* destinationdestination addressaddress */*/CONTROL,/*CONTROL,/* prioritypriority */*/IPPROTO SRIP,/*IPProtocol*/IPPROTO SRIP,/* IP Protocol */1,/*1,/* TTLTTL */*/DEFAULT INTERFACE,/*DEFAULT INTERFACE, /* outputoutput interfaceinterface */*/ANY DEST);/*ANY DEST);/* nextnext hophop addressaddress */*//*/* updateupdate statisticstatistic */*/srip- numRouteUpdatesBroadcast ;srip- numRouteUpdatesBroadcast ;}}Ask IP to add header andsend packet to MAC layerUpdate local statistic/*/* scheduleschedule thethe nextnext routeroute updateupdate broadcastbroadcast */*/newMsgnewMsg MESSAGE Alloc(node,MESSAGE Alloc(node, NETWORK LAYER,NETWORK LAYER,Schedule the nextROUTING PROTOCOL SRIP,MSG NETWORK RTBroadcastAlarm);ROUTING PROTOCOL SRIP, MSG NETWORK RTBroadcastAlarm); broadcast eventMESSAGE Send(node,newMsg,srip- updateInterval);MESSAGE Send(node, newMsg, srip- updateInterval);17SRIP Packet Handling FunctionCalled when a node receives a route advertisementvoid SripHandleProtocolPacket(Node*node,void sage*msg,NodeAddress sourceAddress)NodeAddress sourceAddress){{SripData* srip (SripData*)SripData* srip (SripData*)NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);int i, numEntries;int i, numEntries;char *pktPtr;char *pktPtr;SripTableEntry entry;SripTableEntry entry;Obtain pointer to localvariable spacePacket format#entries 1st entry 2nd entry pktPtr msg- packet;pktPtr msg- packet;memcpy(&numEntries, pktPtr, sizeof(unsigned int));memcpy(&numEntries, pktPtr, sizeof(unsigned int));pktPtr sizeof(unsigned int);pktPtr sizeof(unsigned int);/* scan the entry list and update routing table only with entries with/* scan the entry list and update routing table only with entries with* shorter distance */* shorter distance */for (i 0; i numEntries; i )for (i 0; i numEntries; i ){{memcpy(&entry, pktPtr, sizeof(SripTableEntry));memcpy(&entry, pktPtr, sizeof(SripTableEntry));entry.distance ;entry.distance ;if (entry.distance srip- routingTable[entry.destination].distance) {if (entry.distance srip- routingTable[entry.destination].distance) {srip- routingTable[entry.destination].distance entry.distance;srip- routingTable[entry.destination].distance entry.distance;srip- routingTable[entry.destination].nextHop sourceAddress;srip- routingTable[entry.destination].nextHop sourceAddress;}}pktPtr sizeof(SripTableEntry);pktPtr sizeof(SripTableEntry);}}}MESSAGE Free(node, msg);MESSAGE Free(node, msg);}Free the message since this is itsfinal destination18

SRIP Router FunctionCalled when IP layer receives a data packet fromMAC or transportvoid SripRouterFunction(Node*node,void sg,NodeAddress destAddr,NodeAddress destAddr,NodeAddress previousHopAddress,NodeAddress tWasRouted){{IpHeaderType *ipHeader (IpHeaderType *) msg- packet;IpHeaderType *ipHeader (IpHeaderType *) msg- packet;/* Obtain a pointer to the local variable space *//* Obtain a pointer to the local variable space */SripData* srip (SripData*)SripData* srip (SripData*)NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);/* do not route any SRIP packet, or any packets destined to myself *//* do not route any SRIP packet, or any packets destined to myself */if (ipHeader- ip p IPPROTO SRIP ipHeader- ip dst node- nodeId)if (ipHeader- ip p IPPROTO SRIP ipHeader- ip dst node- nodeId)return;return;}Ignore SRIP packetsand my own packets/* route the packet only when the destination is considered reachable *//* route the packet only when the destination is considered reachable */if (srip- routingTable[ipHeader- ip dst].distance SRIP INFINITY)if (srip- routingTable[ipHeader- ip dst].distance SRIP INFINITY){{Route the packet*packetWasRouted TRUE;*packetWasRouted TRUE;NetworkIpSendPacketToMacLayer(the destination emsg,msg,DEFAULT INTERFACE,DEFAULT INTERFACE,srip- routingTable[ipHeader- ip dst].nextHop);srip- routingTable[ipHeader- ip dst].nextHop);}}}if19SRIP Finalizing FunctionCalled at each node when Qualnet isterminatingvoidvoid SripFinalize(NodeSripFinalize(Node *node)*node){{charchar buf[MAX STRING LENGTH];buf[MAX STRING LENGTH];/*/* ObtainObtain aa pointerpointer toto thethe locallocal variablevariable spacespace */*/SripData*SripData* sripsrip node,ROUTING PROTOCOL SRIP);NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP);}}sprintf(buf,sprintf(buf, "Number"Number ofof RouteRoute UpdatesUpdates BroadcastBroadcast %u",%u",srip- numRouteUpdatesBroadcast);srip- numRouteUpdatesBroadcast);IO PrintStat(node,"Network","SRIP",ANY DEST,-1,IO PrintStat(node, "Network", "SRIP", ANY DEST, -1, buf);buf);Report statistic20

Make SRIP Recognized by QualnetLet Qualnet know SRIP as a network layerprotocolIn the file include/network.h typedeftypedefenumenum{{NETWORK PROTOCOL IPNETWORK PROTOCOL IP 0,0,NETWORK PROTOCOL MOBILE IP,NETWORK PROTOCOL MOBILE IP,::::ROUTING PROTOCOL IGRP,ROUTING PROTOCOL IGRP,ROUTING PROTOCOL SRIP,ROUTING PROTOCOL SRIP,//InsertPatch ROUTING PROTOCOL TYPE//InsertPatch ROUTING PROTOCOL TYPE::ROUTING PROTOCOL ALL,ROUTING PROTOCOL ALL,ROUTING PROTOCOL NONEROUTING PROTOCOL tocolType;21Make SRIP Recognized by QualnetLet IP module know SRIP as an IP protocol In the file network/ip.h//////// IPIP protocolprotocol numbersnumbers forfor networknetwork- andand transport-layertransport-layer protocols.protocols.////#define#define IPPROTO ICMPIPPROTO ICMP#define#define IPPROTO IGMPIPPROTO IGMP::#define#define IPPROTO DVMRPIPPROTO DVMRP#define IPPROTO SRIP#define IPPROTO SRIP//InsertPatch ROUTING IPPROTO//InsertPatch ROUTING IPPROTO112220020023423422

Make SRIP Recognized by QualnetHave IP module recognize the five entryfunctions of SRIPHave network/ip.c include srip.h#include#include stdio.h stdio.h #include#include stdlib.h stdlib.h #include string.h #include string.h #include#include math.h math.h ::::#include#include "pim.h""pim.h"#include#include "access list.h""access list.h"//#define//#define DEBUG FIXDEBUG FIX#include "srip.h"#include "srip.h"//InsertPatch HEADER FILES//InsertPatch HEADER FILES::(file network/ip.pc)23Make SRIP Recognized by QualnetHave IP initialize SRIP if specified in the configuration fileIn the file network/ip.c, function NetworkIpInit()voidvoidNetworkIpInit(Node *node, const NodeInput *nodeInput)NetworkIpInit(Node *node, const NodeInput *nodeInput){{NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;::IO ReadString(IO ReadString(node- nodeId,node- nodeId,NetworkIpGetInterfaceAddress(node, i),NetworkIpGetInterfaceAddress(node, lString);if (retVal)if (retVal){{::elseelseif (strcmp(protocolString, "SRIP") 0) {if (strcmp(protocolString, "SRIP") 0) {NetworkIpAddUnicastRoutingProtocolType(node, ROUTING PROTOCOL SRIP, i);NetworkIpAddUnicastRoutingProtocolType(node, ROUTING PROTOCOL SRIP, i);if (!NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP)) {if (!NetworkIpGetRoutingProtocol(node, ROUTING PROTOCOL SRIP)) {SripInit(node,SripInit(node,(SripData **) &ip- interfaceInfo[i]- routingProtocol,(SripData **) &ip- interfaceInfo[i]- routingProtocol,nodeInput, i);nodeInput, i);}}else {else erFunction(node, ROUTING PROTOCOL SRIP, i);node, ROUTING PROTOCOL SRIP, i);}}}}//InsertPatch NETWORK INIT CODE//InsertPatch NETWORK INIT CODE::24

Make SRIP Recognized by QualnetWhen the network layer receives an event for SRIP,dispatch it to SRIP’s event handling functionIn the file, network/ip.c, function IpLayer(Node *node,*node, MessageMessage *msg)*msg){{switchswitch (msg- protocolType)(msg- protocolType){{::casecase ROUTING PROTOCOL ALL:ROUTING PROTOCOL ALL:{{ERROR Assert(FALSE,ERROR Assert(FALSE, "IP"IP eventevent s(node,//HandleSpecialMacLayerStatusEvents(node, msg);msg);break;break;}}case ROUTING PROTOCOL SRIP:case ROUTING PROTOCOL SRIP:{{SripHandleProtocolEvent(node, msg);SripHandleProtocolEvent(node, msg);break;break;}}//InsertPatch//InsertPatch NETWORK IP LAYERNETWORK IP LAYER::25Make SRIP Recognized by QualnetWhen IP receives an SRIP route advertisement packet,dispatch it to SRIP’s packet handling functionIn the file, network/ip.pc, function DeliverPacket()static void //inline//static void //inline//DeliverPacket(Node *node, Message *msg,DeliverPacket(Node *node, Message *msg,int interfaceIndex, NodeAddress previousHopAddress)int interfaceIndex, NodeAddress previousHopAddress){{NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;::ipHeader (IpHeaderType *) msg- packet;ipHeader (IpHeaderType *) msg- packet;ipProtocolNumber ipHeader- ip p;ipProtocolNumber ipHeader- ip p;if (ipHeader- ip tos & IPTOS CE) {if (ipHeader- ip tos & IPTOS CE) {aCongestionExperienced TRUE;aCongestionExperienced TRUE;}}switch (ipProtocolNumber)switch (ipProtocolNumber){{::case IPPROTO SRIP:case IPPROTO ess);break;break;}}//InsertPatch NETWORK HANDLE PACKET//InsertPatch NETWORK HANDLE PACKET::26

Make SRIP Recognized by QualnetCall SRIP’s finalizing function when IP is terminatingIn the file network/ip.pc, function NetworkIpFinalize()voidvoidNetworkIpFinalize(Node *node)NetworkIpFinalize(Node *node){{NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;NetworkDataIp *ip (NetworkDataIp *) node- networkData.networkVar;::for (i 0; i node- numberInterfaces; i )for (i 0; i node- numberInterfaces; i ){{switch (NetworkIpGetUnicastRoutingProtocolType(node, i))switch (NetworkIpGetUnicastRoutingProtocolType(node, i)){{case ROUTING PROTOCOL LAR1:case ROUTING PROTOCOL ;break;}}::case ROUTING PROTOCOL SRIP:case ROUTING PROTOCOL ;break;}}//InsertPatch FINALIZE FUNCTION//InsertPatch FINALIZE FUNCTION::27Compiling Qualnet with SRIPEdit main/Makefile-commonAdd srip.h and srip.c to SIM HDRS andSIM SRCS macros, respectivelySIM HDRSSIM HDRS \\ (ADDON HDRS) (ADDON HDRS) \\\\::./mac/aloha.h./mac/aloha.h \\\\./network/srip.h \./network/srip.h \#InsertPatch HEADER FILES#InsertPatch HEADER FILES::SIM SRCS \SIM SRCS \ (ADDON SRCS) \ (ADDON SRCS) \\\::\\./mac/aloha.c \./mac/aloha.c \\\./network/srip.c./network/srip.c \\#InsertPatch SOURCE FILES#InsertPatch SOURCE FILES28

Compiling Qualnet with SRIPRebuild the .h dependencies:cdcd QUALNET HOME/main QUALNET HOME/mainmakemake dependdependRebuild Qualnet executable:makemake29Creating a configuration file for SRIPIn QUALNET HOME/bin directory, copydefault.config into srip.config, thenmodify/add the following :ROUTING-PROTOCOLROUTING-PROTOCOL SRIPSRIPSRIP-UPDATE-INTERVALSRIP-UPDATE-INTERVAL 10S10S::30

Testing the ProtocolIn QUALNET HOME/bin directory, run qualnetwith SRIP configuration file:cdcd QUALNET HOME/bin QUALNET HOME/bin./qualnet./qualnet srip.configsrip.configCheck srip.stat file to see applications’statistics31Obtaining SRIP ExampleTwo files, srip.h and srip.c, are located in/m/buckwheat/qualnet/examplesCheck README file for instructions32

Programming TipsMESSAGE Free() must be called only once permessageRun make depend to rebuild .h dependencies wheneverdifferent header files are includedFilling data into a packet or a packet header can be trickyA field may span across a word boundary, causing ‘bus error’ insome systemsUse memcpy() instead of an assignment operation (i.e., )Use message’s info field to carry extra informationinternally (within the same node)A good way to learn Qualnet is to study the code of someprovided protocols33

Qualnet Layered Architecture The simulation is a collection of network nodes, each with its own protocol stack parameters and statistics File addons/seq/node.h struct struct_node_str {unsigned nodeIndex; NodeAddress nodeId; /* the network address of the node */: unsigned short seed[3]; /* seed for random number generator */