660 likes | 1.14k Views
Add new Routing Protocol to QualNet. QualNet Layered Architecture. The simulation is a collection of network nodes, each with its own protocol stack parameters and statistics accessible from the “Node” structure File include/node.h. General node ’ s info. Struct Node { :
E N D
QualNet Layered Architecture • The simulation is a collection of network nodes, each with its own protocol stack parameters and statistics accessible from the “Node” structure • File include/node.h General node’s info Struct Node { : NodeAddress nodeId; /* the user-specified node identifier */ : Int32 globalSeed; /* seed for random number generator */ Int32 numNodes; /* number of nodes in the simulation */ : /* Layer-specific information for the node. */ : MacData** macData; // MAC layer MacSwitch* switchData; // MAC switch NetworkData networkData; // network layer TransportData transportData; // transport layer AppData appData; // application layer : }; Layer-specific info
Message, Packets, and Timers • A message is a unit defining an interaction between protocols and between nodes • File include/message.h • Two types of messages • Packets (data or control) – used for communication between nodes • Timers – allow protocols to schedule events in a future time
Packet Life Cycle Application Application MESSAGE_Free(…) MESSAGE_Alloc(…) MESSAGE_PacketAlloc(…) MESSAGE_Send(…) Transport Transport MESSAGE_RemoveHeader() MESSAGE_Send(…) MESSAGE_AddHeader() MESSAGE_Send(…) Routing IP Routing IP IP MESSAGE_RemoveHeader() MESSAGE_Send(…) MESSAGE_AddHeader() MESSAGE_Send(…) MAC MAC MAC MESSAGE_AddHeader() MESSAGE_Send(…) MESSAGE_RemoveHeader() MESSAGE_Send(…) Channel Channel Channel
Creating Messages A pointer to the node creatingthe message Message* MESSAGE_Alloc( Node *node, int layerType, int protocol, int eventType); The stack layer at which this messagewill be processed next e.g., NETWORK_LAYER The specific protocol at the layer which will process this message e.g., ROUTING_PROTOCOL_DSR The event that this message represents e.g., MSG_NETWORK_FlushTables
Message Processing Handling functionfor FlushTablesevent FlushTables CheckReplied RouteTimeout Check eventType field IP DSR AODV newMsg Check protocolType field MAC Network Transport Radio App Check layerType field Event queue msg
QualNet’s Protocol Modelings • Initialization Function • Allocate memory for each node’s local variables • Initialize local variables • Process configuration file(s) • Schedule the first event Packet arrival ortimer expiration • Message (packet or timer)processing function • Modify state variables • Update local statistics • Generate/forward packets Idle • Finalization Function • Output statistics
Adding a Protocol to QualNet • Determine what layer your protocol will operate at • Implement four/five main functions • Initialization function • Packet/event handling functions • Router function (for routing protocol) • Finalization function • Hook up the above functions to the protocol dispatching functions of the corresponding layer
Introduction - AODV • What is AODV? • DSR • Source에서 destination node까지의 route를 packet header에 표기 • Node의 수에 따라 Packet header size가 결정됨 • Route cache를 이용 • Small network, low mobility에 적합 • AODV • DSR의 단점을 보강하기 위한 protocol • Hello message, routing table을 이용 • Large network, high mobility에 적합
AODV • AODV의 주요 control message • RREQ (Route Request) • RREP (Route Reply) • RERR (Route Error) • Source node가 Destination을 향해 RREQ를 flooding • Destination 혹은 Destination node까지의 path를 알고 있는 intermediate node는 RREQ를 받으면 RREP를 source node로 전송 • RREP를 전송하는 과정에서 Source쪽을 향하는 reverse path를 형성 • Destination node로 가는 route정보가 사라졌을 때 RERR을 전송해서 local repair과정을 거침
Start to transmit data packet Broadcast RREQ packet Generate RREQ packet Generate RREQ packet When need to send data. Have a route to destination? No Yes
Receive RREQ packet Receive RREQ packet Set the Reverse path Destination ? No Route Information to destination ? No Yes Yes Rebroadcast RREQ packet Reply RREP packet
Receive RREP packet Receive RREP packet Set Forward path Source node? No Update next hop information Yes Start to transmit data packet Unicast RREP via Reverse path
Detecting broken link Detecting Broken Link Generate RERR packet Precursor count = 1? No Yes Multiple unicast RERR Unicast RERR via Reverse path
Flow chart summarizes the action of an AODV Process receive event Update route to originator (if better than existing) Is Dest? Has “fresh enough” route? If not in buffer. Forward RREQ To neighbors NO NO RREQ YES YES Send RREP Check msg type Update route table, precursor & outgoing lists Is originator? RREP Send queued message YES Forward RREP to next hop NO RERR End NO Remove affected routes At least one remove? Forward RERR to precursors YES
B S A C D Route Discovery (1/10) 1. Node S needs a route to D in order to send data packets to D
B S A C D Route Discovery (2/10) 1. Node S needs a route to D in order to send data packet to D 2. Creates a Route Request (RREQ) Enters D’s IP addr, seq#, S’s IP addr, seq# hopcount (=0)
Route Discovery (3/10) 2. Creates a Route Request (RREQ) Enters D’s IP addr, seq#, S’s IP addr, seq# hopcount (=0) 3. Node S broadcasts RREQ to neighbors B RREQ S A C D
Route Discovery (4/10) 4. Node A receives RREQ • Makes reverse route entry for Sdest = S, nexthop = S, hopcnt = 1 B RREQ S A C D
Route Discovery (5/10) 4. Node A receives RREQ • Makes reverse route entry for Sdest = S, nexthop = S, hopcnt = 1 • It has no route to D, so it rebroadcasts RREQ B RREQ S A C D
Route Discovery (6/10) 5. Node C receives RREQ • Makes reverse route entry for Sdest = S, nexthop = A, hopcnt = 2 • It has a route to D, and the seq# for route for D is >=D’s seq# in RREQ B RREQ S A C D
Route Discovery (7/10) 6. Node C sends RREP • C creates a Route Reply (RREP)Enters D’s IP addr, seq #S’s IP addr, hopcount to D (=1)Lifetime • Unicasts RREP towards A B S A RREP C D
Route Discovery (8/10) 7. Node A receives RREP • Makes forward route entry to Ddest = D, nexthop = C, hopcount = 2, Lifetime • Unicasts RREP to S B RREP S A RREP C D
Route Discovery (9/10) 8. Node S receives RREP • Makes forward route entry to Ddest = D, nexthop = C, hopcount = 3, Lifetime B RREP S A C D
Route Discovery (10/10) 9. Node S sends data packets on route to D B S A C D
Route Maintenance (1/5) 1. Link between C and D breaks down • C can perform local repair for the route to D B S A RERR C D
Route Maintenance (2/5) 1. Link between C and D breaks down • C can perform local repair for the route to D 2. Node C invalidates route to D in route table B S A RERR C D
Route Maintenance (3/5) 3. Node C creates Route Error (RERR) message • C creates a Route Error (RERR)Enters DestCount (=1), D’s IP addr, seq # • Lists all destinations which are now unreachable • “DestCount” field indicates the number of unreachable destinations included in the RERR message. • Sends to upstream neighbors in precursor list B S A RERR C D
Route Maintenance (4/5) 4. Node A receives RERR • Checks whether C is its next hop on route to D • Deletes route to D or invalidates the route to D according to N flag (No delete flag) • When N flag is set, A does not send RERR to S and may reinitiate route discovery for D. • Forwards RERR to S B RERR S A RERR C D
B RERR S A C D Route Maintenance (5/5) 5. Node S receives RERR • Checks whether A is its next hop on route to D • Deletes route to D • Rediscovers route if still needed
Network Layer API • Network API • QUALNET_HOME/include/api.h : Defines the events and data structures needed to communicate between different layers of the protocol stack. • QUALNET_HOME/include/network.h : Contains definitions common to Network Layer protocols, the network data structure in the node structure, and the prototypes of functions defined in QUALNET_HOME/main/network.cpp. • QUALNET_HOME/libraries/developer/src/network_ip.h : Contains definitions of data structure and parameters used in the IP implementation and prototypes of the functions defined in QUALNET_HOME/libraries/developer/src/network_ip.cpp.
Network Layer API • Network API • QUALNET_HOME/include/mapping.h : Contains definitions of data structures and functions used for determining the network type network protocols running at a node. • QUALNET_HOME/include/mac.h : Contains definitions of API functions needed to communicate with the MAC Layer. • QUALNET_HOME/include/if_queue.h : contains definition of the class that implements queues and prototypes of functions related to queues. • QUALNET_HOME/include/if_scheduler.h : contains definition of the class that implements schedulers and prototypes of functions related to schedulers.
Network Layer API • Relevant Header Files • QUALNET_HOME/include/fileio.h : Contains prototypes of functions to read input files and create output files. • QUALNET_HOME/include/buffer.h : Contains data structures and prototypes of functions for buffer operations. • QUALNET_HOME/include/list.h : Defines a generic doubly link list structure and prototypes of functions for list operations.
Network Layer API • Folders and source files • QUALNET_HOME/libraries/developer/src, QUALNET_HOME/libraries/wireless/src • This folder contains most of the Network Layer protocols implemented in QualNet. • These include network protocols, routing protocols, queuing protocols, and schedulers. The file names are indicative of the protocol for which they provide an implementation. • QUALNET_HOME/main/network.cpp : Contains Network Layer functions, including the initialization, message processing, and finalization functions. • QUALNET_HOME/libraries/developer/src/network_ip.cpp : Contains functions that implement the IP protocol.
Network Layer API • Transport Layer Network Layer Function • NetworkIpReceivePacketFromTransportLayer : sends a packet from a Transport Layer protocol (UDP, TCP or RSVP-TE) to the IP protocol at the Network Layer • Network Layer Transport Layer Function • SendToUdp: This function sends a packet to the UDP protocol at the Transport Layer. • SendToTcp: This function sends a packet to the TCP protocol at the Transport Layer. • SendToRsvp: This function sends a packet to the RSVP-TE protocol at the Transport Layer.
Network Layer API • Network Layer MAC Layer Function • NetworkIpSendRawMessage: adds an IP header to a packet and calls function RoutePacketAndSendToMac to add routing information to the packet. • NetworkIpSendRawMessageWithDelay: adds an IP header to a packet and calls function RoutePacketAndSendToMac, after a specified delay, to add routing information to the packet. • NetworkIpSendRawMessageToMacLayer: adds an IP header to a packet and sends the packet to the MAC Layer. • NetworkIpSendRawMessageToMacLayerWithDelay: adds an IP header to a packet and sends the packet to the MAC Layer after a specified delay. • NetworkIpSendPacketToMacLayer: sends an IP packet to the MAC Layer. • NetworkIpSendPacketToMacLayerWithNewStrictSourceRoute: appends a new source route to an IP packet and sends the packet to the MAC Layer. • MAC_NetworkLayerHasPacketToSend: is used by the Network Layer to inform the MAC Layer that a packet is ready to be sent.
Network Layer API • MAC Layer Network Layer Function • NetworkIpOutputQueueIsEmpty: checks if the output queue at an interface is empty. • NetworkIpOutputQueueDequeuePacket: dequeues a packet from an output queue. • NetworkIpOutputQueueTopPacket: is used to view the top packet of a queue without dequeuing it. • NetworkIpOutputQueueDequeuePacketForAPriority: dequeues a specific priority packet from an output queue. • NETWORK_ReceivePacketFromMacLayer: is used by the MAC Layer to pass an incoming packet to the Network Layer. • NetworkIpReceiveMacAck: notifies the Network Layer that a packet has been successfully delivered by the MAC protocol. • NetworkIpNotificationOfPacketDrop: notifies the upper layer protocols when a packet is dropped at the MAC Layer.
HRP • Like AODV • Combines the merits of both proactive and reactive approach • Route discovery • Decrease routing over Head • Increase packet delivery ratio • Increase Average End-to-End Delay
HRP Header file(hrp.h) • $QUALNET_HOME\libraries\developer\src\hrp.h 참조.
HRP Initialization Function • Called when each node is initialized by QualNet • 로컬 변수 메모리 할당 • 패킷 출력을 위한 파일 포인터 생성 • 각 파라메터를 Config 파일에서 로드 • 라우팅 테이블 초기화 • 라우팅 최적화를 위한 MAC 레이어의 상태 전송 허락 • 패킷이 라우트 되기위해서 라우트함수 등록 • 타이머 등록 (to be continued)
HRP Event Handling Function • Called when a node’s timer expires • Remove an entry from the RREQ Seen Table • Remove the route that has not been used for awhile • MSG_NETWORK_DeleteRoute • Check if RREP is received after sending RREQ • MSG_NETWORK_BlacklistTimeout • MSG_NETWORK_SendHello
HRP Packet Handling Function • Called when a node receives a route advertisement • Packet Types • Route Request • Route Reply • Route Error • Route Acknowledgement
HRP Router Function • Called when IP layer receives a data packet from MAC or transport layer
HRP Finalizing Function • Called at each node when QualNet is terminating • Print Routing Tables • Write result to statistic.
Make HRP Recognized by QualNet • Copy the source files(hrpp.cpp hrpp.h) tolibraries/developer/src • Insert Source Insight Project to the files • project • synchronize files • Check the “Force” tab • Check the “Suppress” tab
Make HRP Recognized by QualNet • Let QualNet know HRP as a network layer protocol • In the file include/network.h typedef enum { NETWORK_PROTOCOL_IP = 0, : : //StartIERP ROUTING_PROTOCOL_IERP, //EndIERP ROUTING_PROTOCOL_HRP, //InsertPatch ROUTING_PROTOCOL_TYPE : ROUTING_PROTOCOL_NONE } NetworkRoutingProtocolType; include/trace.h: TraceProtocolType // start cellular TRACE_CELLULAR_PHONE, TRACE_UMTS_LAYER3, TRACE_UMTS_LAYER2, TRACE_UMTS_PHY, // end cellular TRACE_HRP, // Must be last one!!! TRACE_ANY_PROTOCOL
Make HRP Recognized by QualNet • Let IP module know HRP as an IP protocol • In the file libraries/developer/src/network_ip.h // // IP protocol numbers for network- and transport-layer protocols. // // /** // CONSTANT :: IPPROTO_IP : 0 // DESCRIPTION :: IP protocol numbers. // **/ #ifndef IPPROTO_IP #define IPPROTO_IP 0 #endif : //StartIARP #define IPPROTO_IARP 254 //EndIARP #define IPPROTO_HRP 212 //InsertPatch ROUTING_IPPROTO :