440 likes | 556 Views
Term Project: ZRP Source Code Part 1 & Part 2. presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012. General Overview. Existing Protocols ------------------ IP Internet Protocol ICMP Internet Control Message Protocol ZRP Entities ------------
E N D
Term Project:ZRP Source CodePart 1 & Part 2 presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012 운영체제특론(Advanced Operating System)
General Overview Existing Protocols ------------------ IP Internet Protocol ICMP Internet Control Message Protocol ZRP Entities ------------ IARP Routing Protocol IERP Routing Protocol BRP Resolution Protocol Additional Protocols -------------------- NDP Discovery Protocol 운영체제특론(Advanced Operating System)
Term Project:ZRP Source CodePart 1 presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012 운영체제특론(Advanced Operating System)
Contents • routing_zrp.cpp: • libraries • routing methods 운영체제특론(Advanced Operating System)
Libraries • stdlib.h • stdio.h • string.h • “api.h” • “network_ip.h” • “routing_zrp.h” • “routing_iarp.h” • “routing_ierp.h” 운영체제특론(Advanced Operating System)
stdlib.h • Standard general utilities library • String conversion • Eg:atoi, convert string to int, etc, • dynamic memory management • Eg: malloc, memory allocation, etc, • Environment • Eg: exit, terminate process, etc, • Searching and sorting • Eg: qsort, sort elements of array, etc, • integer arithmethics • Eg: abs, absolute value, etc • Etc. 운영체제특론(Advanced Operating System)
stdio.h • Library to perform input/output operations • Operation on files • remove, remove file, etc • File access • Fclose, close file, etc. • Formatted i/o • printf, print data to stdout, etc. • Character i/o • getchar, get character from stdin, etc. • Etc. 운영체제특론(Advanced Operating System)
string.h • Several functions to manipulate C strings and arrays. • Copying • strcpy, copy string, etc. • Concatenation • strcat, concatenate strings, etc. • Comparison • strcmp, compare two strings, etc. • Etc. 운영체제특론(Advanced Operating System)
Libraries cont. • stdlib.h • stdio.h • string.h • “api.h” • “network_ip.h” • “routing_zrp.h” • “routing_iarp.h” • “routing_ierp.h” 운영체제특론(Advanced Operating System)
“api.h” • In qualnet • It enumerates the basic message/eventsexchanged during the simulation process and the various layer functions (initialize, finalize, and event handling functions) and other miscellaneous routines and data structure definitions. • Enum • MSG_SPECIAL_Timer = 0, • MSG_WEATHER_MobilityTimerExpired = 50, • MSG_PROP_SignalArrival = 100, • MSG_PROP_SAMPLE_PATHLOSS = 103, • Etc. • Routines • void CHANNEL_Initialize(Node *node, constNodeInput *nodeInput); • Channel initialization • void PHY_Init(Node *node, constNodeInput *nodeInput); • Physical layer initiation • Etc. 운영체제특론(Advanced Operating System)
network_ip.h • In qualnet • It contains data structures and prototypes of functions used by IP. • Define • #define IPVERSION4 4 • #define FORWARDING_TABLE_ROW_START_SIZE 8 • Etc. • Struct type • structIpHeaderType {……} • Etc. • Routines • static void IpHeaderSetVersion(UInt32 *ip_v_hl_tos_len, unsigned int version) • Etc. 운영체제특론(Advanced Operating System)
routing_zrp.h • In qualnet • Define • #define _ZRP_NETWORK_H_ • Struct • typedefstructstruct_zrp_strZrpData; • Etc. • Routines • Void ZrpInit(Node* node, ZrpData** dataPtr, constNodeInput* nodeInput, intinterfaceIndex); • Etc. • Enum • enum { ZRP_RECEIVE_PACKET_FROM_NETWORK, ZRP_ROUTE_PACKET, ZRP_IDLE_STATE, ZRP_INITIAL_STATE, ZRP_FINAL_STATE, ZRP_DEFAULT_STATE }; • Etc. • End define 운영체제특론(Advanced Operating System)
routing_iarp.h & routing_ierp.h • #define _IARP_NETWORK_H_ • Struct • Enum • routine • End define • #define _IERP_NETWORK_H_ • Struct • Enum • routine • End define 운영체제특론(Advanced Operating System)
routing_zrp.cpp and its methods • ZrpIsEnabled • ZrpReturnProtocolData • ZrpHandleProtocolPacket • ZrpRouterFunction • enterZrpIdleState • ZrpInitStats • ZrpPrintStats • ZrpRunTimeStat • ZrpInit • ZrpFinalize • ZrpProcessEvent 운영체제특론(Advanced Operating System)
ZrpIsEnabled • BOOLZrpIsEnabled(Node* node) { return (NetworkIpGetRoutingProtocol( node, ROUTING_PROTOCOL_ZRP) != NULL); } 운영체제특론(Advanced Operating System)
Returning pointer to protocol data structure. Parameters: node (node which is returning protocol data), routingProtocolType (the routing Protocol Type). • void* ZrpReturnProtocolData(Node* node,NetworkRoutingProtocolTyperoutingProtocolType) { ZrpData* dataPtr = (ZrpData*) NetworkIpGetRoutingProtocol (node, ROUTING_PROTOCOL_ZRP); if (dataPtr == NULL) { ERROR_Assert(FALSE, "ZRP not found in this node"); abort(); } switch (routingProtocolType) { case ROUTING_PROTOCOL_IERP: { return dataPtr->ierpProtocolStruct; } case ROUTING_PROTOCOL_IARP: { return dataPtr->iarpProtocolStruct; } default: { return NULL; } } • } 운영체제특론(Advanced Operating System)
void ZrpHandleProtocolPacket(Node* node,Message* msg, NodeAddresssourceAddr,NodeAddressdestAddr, intinterfaceIndex, unsigned ttl) { //UserCodeStartReceivePacketFromNetwork // NO operation. // Control of code MUST NOT come here. ZrpData *dataPtr = (ZrpData*) NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_ZRP); ERROR_Assert(FALSE, "Control Must not reach Here"); //UserCodeEndReceivePacketFromNetwork dataPtr->state = ZRP_IDLE_STATE; enterZrpIdleState(node, dataPtr, msg); • } 운영체제특론(Advanced Operating System)
void ZrpRouterFunction(Node* node, Message* msg, NodeAddressdestAddr, NodeAddresspreviousHopAddr, BOOL* packetWasRouted) { //UserCodeStartRoutePacket ZrpData*dataPtr = (ZrpData*) NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_ZRP); // call iarp router function first // if IARP is unable to route call IERP to route dataPtr->iarpRouterFunction( node, msg, destAddr, previousHopAddr, packetWasRouted); if (*packetWasRouted == FALSE) { // call ierp router function dataPtr->ierpRouterFunction( node, msg, destAddr, previousHopAddr, packetWasRouted); } // Set the message pointer to NULL. This will not effect // the original pointer passed to this function, but it will prevent // the message from being freed at the idle state. msg = NULL; //UserCodeEndRoutePacket dataPtr->state = ZRP_IDLE_STATE; enterZrpIdleState(node, dataPtr, msg); } 운영체제특론(Advanced Operating System)
enterZrpIdleState • static void enterZrpIdleState(Node* node, ZrpData* dataPtr, Message *msg) { //UserCodeStartIdleState // Free the message if it is null. if (msg != NULL) { MESSAGE_Free(node, msg); } //UserCodeEndIdleState • } 운영체제특론(Advanced Operating System)
ZrpInitStats, ZrpPrintStats, ZrpRunTimeStat • //Statistic Function Definitions static void ZrpInitStats(Node* node, ZrpStatsType *stats) { if (node->guiOption) { } } • void ZrpPrintStats(Node* node) { } • void ZrpRunTimeStat(Node* node, ZrpData* dataPtr) { } 운영체제특론(Advanced Operating System)
ZrpInit • void ZrpInit(Node* node, ZrpData** dataPtr, constNodeInput* nodeInput, intinterfaceIndex) { Message *msg = NULL; //UserCodeStartInit // The following line of code should be executed only // for the *first* initialization of an interface that // shares this data structure. // Initialize ZrpProtocol data structure (*dataPtr) = (ZrpData*) MEM_malloc(sizeof(ZrpData)); memset((*dataPtr), 0, sizeof(ZrpData)); (*dataPtr)->printStats = TRUE; // The routing protocols IARP and IERP will be Initialized // from ZRP. So first check that if IARP or IER is already // initialized or not. If they are initialized before flash // an error message and the abort execution. if (NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_IERP) || NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_IARP)) { ERROR_ReportError("IERP or IARP was initialized before \n" "disable IARP or IERP first\n"); abort(); } // Register ZRP with IARP protocol IarpRegisterZrp( node, (IarpData**) &((*dataPtr)->iarpProtocolStruct), nodeInput, interfaceIndex, &((*dataPtr)->iarpRouterFunction)); 운영체제특론(Advanced Operating System)
// Register ZRP with IERP protocol IerpRegisterZrp( node, (IerpData**) &((*dataPtr)->ierpProtocolStruct), nodeInput, interfaceIndex, &((*dataPtr)->ierpRouterFunction), &((*dataPtr)->macStatusHandlar)); NetworkIpSetRouterFunction( node, ZrpRouterFunction, interfaceIndex); NetworkIpSetMacLayerStatusEventHandlerFunction( node, (*dataPtr)->macStatusHandlar, interfaceIndex); IarpSetIerpUpdeteFuncPtr(node, IerpReturnRouteTableUpdateFunction(node)); if ((*dataPtr)->initStats) { ZrpInitStats(node, &((*dataPtr)->stats)); } //UserCodeEndInit if ((*dataPtr)->initStats) { ZrpInitStats(node, &((*dataPtr)->stats)); } (*dataPtr)->state = ZRP_IDLE_STATE; enterZrpIdleState(node, *dataPtr, msg); } 운영체제특론(Advanced Operating System)
ZrpFinalize • void ZrpFinalize(Node* node) { ZrpData *dataPtr = (ZrpData*) NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_ZRP); //UserCodeStartFinalize IarpFinalize(node); IerpFinalize(node); //UserCodeEndFinalize if (dataPtr->statsPrinted) { return; } if (dataPtr->printStats) { dataPtr->statsPrinted = TRUE; ZrpPrintStats(node); } } 운영체제특론(Advanced Operating System)
ZrpProcessEvent • void ZrpProcessEvent(Node* node, Message* msg) { ZrpData* dataPtr = (ZrpData*) NetworkIpGetRoutingProtocol(node, ROUTING_PROTOCOL_ZRP); switch (dataPtr->state) { case ZRP_IDLE_STATE: assert(FALSE); break; default: ERROR_ReportError("Illegal transition"); break; } } 운영체제특론(Advanced Operating System)
Next: Part 2 • IARP. • IERP. • BRP. 운영체제특론(Advanced Operating System)
Term Project:ZRP Source CodePart 2 presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012 운영체제특론(Advanced Operating System)
Content • IARP. • Routing_iarp.cpp • Routing_iarp.h • IERP. • Routing_ierp.cpp • Routing_ierp.h • BRP • Routing_brp.cpp • Routing_brp.h 운영체제특론(Advanced Operating System)
IARP & IERP • Routing_iarp.cpp • Libraries. • Define. • Routing Methods. • Routing_ierp.cpp • Libraries. • Define. • Routing Methods. • Routing_brp.cpp • Libraries. • Define. • Routing Methods. 운영체제특론(Advanced Operating System)
Routing_iarp.cpp • Libraries. • stdlib.h, stdio.h, string.h, <limits.h> • "api.h“, "network_ip.h“, "routing_iarp.h" • Define. • IARP_DEFAULT_ZONE_RADIUS, IARP_DEFAULT_BROADCAST_TIMER, IARP_DEFAULT_ROUTE_REFRSH_TIMER • Etc. • Routing Methods. • Statistic Functions • Utility Functions • State Declarations 운영체제특론(Advanced Operating System)
Libraries • stdlib.h, stdio.h, string.h, <limits.h> • Standard and basic libraries. • "api.h“ • basic message/events, functions, data structure. • "network_ip.h“, • data structures and prototypes of functions used by IP. • "routing_iarp.h“ • Definition, struct, enum, interface of functions. 운영체제특론(Advanced Operating System)
Define. • #define IARP_DEFAULT_ZONE_RADIUS 2 • #define IARP_DEFAULT_BROADCAST_TIMER (10 * SECOND) • #define IARP_DEFAULT_ROUTE_REFRSH_TIMER (20 * SECOND) • #define IARP_LINK_STATE_TIMER (40 * SECOND) • #define IARP_STARTUP_DELAY (10 * MILLI_SECOND) • #define IARP_HEADER_SIZE 12 • #define IARP_NEIGHBOR_INFO_SIZE 12 • #define IARP_INITIAL_SEQ_NUM 1 • #define MAX_NODE_ENTRY 1024 • #define NO_NEXT_HOP -1 • #define IARP_DEBUG_UPDATE 0 • #define IARP_DEBUG_LINK_STATE_TABLE 0 • #define IARP_DEBUG_NDP 0 • #define IARP_DEBUG_TABLE 0 • #define IARP_DEBUG_FORWARD 0 • #define IARP_DEBUG_PERIODIC 0 • #define IARP_DEBUG_SHORTEST_PATH 0 • #define NetworkIpGetRoutingProtocol(N,P) IarpGetRoutingProtocol(N,P) • #define IARP_INITIAL_ROUTE_TABLE_ENTRY 8 운영체제특론(Advanced Operating System)
Routing Methods. • Statistic Functions • IarpInitStats(Node* node, IarpStatsType *stats) • IarpPrintStats(Node* node) • Utility Functions • IarpUpdateIerpRoutingTable • IarpReceiveNdpUpdate • IarpInitializeRoutingTable • IarpScheduleBroadcastTimer • IarpDeleteRouteFromRoutingTable • IarpReadZoneRadiusFromConfigurationFile • IarpInitializePrivateDataStructures • IarpProcessNdpOrIarpUpdatePacket • IarpReadStatisticsOptionFromConfigurationFile • IarpCheckForInZoneNode • IarpUpdateIarpRouteTable • IarpInitializeLinkStateTable • IarpAddLinkSourceToLinkStateTable • IarpAddLinkStateInfo 운영체제특론(Advanced Operating System)
IarpPrintLinkStateTable • IarpPrintRoutingTable • IarpBuildUpdatePacket • IarpAdvancePacketPtr • IarpIncrementLinkStateSeqNum • IarpBuildHeader • IarpIncludeLinkStateInformationInPacket • IarpEncapsulatePacketInTheMessage • IarpReadHeaderInformation • IarpScheduleRefreshTimer • IarpReBroadcastUpdatePacket • IarpFindShortestPathBFS • IarpFlushRoutingTable • SearchLinkSourceInSeqTable • InsertIntoSeqTable • State Declarations • enterIarpIdle • enterIarpProcessAgedOutRoutes • enterIarpProcessBroadcastTimerExpired 운영체제특론(Advanced Operating System)
Routing_ierp.cpp • Libraries. • stdlib.h, stdio.h, string.h • "api.h“, "network_ip.h“, "routing_ierp.h" • <limits.h>, “routing_brp.h” • Define. • IERP_INITIAL_ROUTE_TABLE_SIZE, IERP_HEADER_SIZE, IERP_INITIAL_QUERY_PACKET_SIZE • Routing Methods. • Statistic Functions • Utility Functions • State Declarations • Routing_brp.cpp • Libraries. • Define. • Routing Methods. 운영체제특론(Advanced Operating System)
Libraries • stdlib.h, stdio.h, string.h, <limits.h>, "api.h“, "network_ip.h“. • "routing_ierp.h“ • Definition, struct, enum, interface of functions • “routing_brp.h” • Definition, struct, enum, interface of functions 운영체제특론(Advanced Operating System)
Define. • #define IERP_INITIAL_ROUTE_TABLE_SIZE 8 • #define IERP_HEADER_SIZE 8 • #define IERP_INITIAL_QUERY_PACKET_SIZE 8 • #define IERP_INITIAL_QUERY_ID 0 • #define IERP_DEFAULT_ROUTE_REQ_TIMER (30 * SECOND) • #define IERP_DEFAULT_ROUTE_AGE_OUT_TIME (2 * MINUTE) • #define IERP_DEBUG_QUERY 0 • #define IERP_DEBUG_REPLY 0 • #define NetworkIpGetRoutingProtocol(n,p) IerpGetRoutingProtocol(n,p) • #define IERP_DEFAULT_MAX_MESSAGE_BUFFER_SIZE 100 운영체제특론(Advanced Operating System)
Routing Methods. • Statistic Functions • IerpInitStats • IerpPrintStats • Utility Functions • IerpPrintQueryPacket • IerpScheduleRouteQueryTimer • IerpInitializeRoutingTable • IerpScheduleRouteFlushOutTimer • IerpAddRouteToRoutingTable • IerpDeleteRouteFromRoutingTable • IerpSearchRouteInRoutingTable • IerpRegisterIarpUpdate • IerpSearchLinkSourceInSeqTable • IerpInsertIntoSeqTable • IerpIncrementQueryId • IerpAdvancePacketPtr • IerpEncapsulatePacketInTheMessage • IerpBuildHeader 운영체제특론(Advanced Operating System)
IerpBuildHeader • IerpBuildInitialQueryPacket • IerpCreateRouteRequestPacket • IerpSendRouteQueryPacket • IerpGetDestinationQueried • IerpForwardQueryPacket • ExtractPreviousHopAddress • IerpGenerateReplyPacket • IerpForwardReplyPacket • IerpReturnPathAndPathLengthAndPreviousHop • IerpReadHeaderInformation • IerpHandlePacketDrop • IerpReadZoneRadiusFromConfigurationFile • IerpInsertBuffer • IerpGetBufferedPacket • State Functions • enterIerpProcessIerpQueryTimerExpired • enterIerpSendQueryPacket • enterIerpRoutePacket • enterIerpIdleState • enterIerpProcessReplyPacket • enterIerpProcessQueryPacket • enterIerpProcessFlushTimerExpired 운영체제특론(Advanced Operating System)
BRP Review • provides bordercasting packet delivery service to support network querying applications. • uses existing map from IARP. • is used to guide route requests of IERP. • employs special query control mechanisms to steer route requests away from areas of network that have been covered by query. • better than flooding network with query. 운영체제특론(Advanced Operating System)
Routing_brp.cpp • Libraries. • <stdlib.h>, <stdio.h>, <string.h>, "api.h“, "network_ip.h“, "routing_iarp.h“, "routing_ierp.h“, • "routing_brp.h“ • Define. • #define DEBUG_BRP 0 • Routing Methods. • BrpDeleteRoutesFromTable • BrpConstructPrevBordercasterRoutingTable • BrpExtractPacket • BrpBordercastQueryPacket • BrpLoadPacket • BrpGetQueryCoverageEntryByCacheId • BrpScheduleDelete • BrpDeleteQueryCoverageEntryByCacheId • BrpAddNewQueryCoverageEntry • BrpNewNetGraph • BrpIsCovered • BrpMarkCovered • BrpSend • BrpCheckIfIntendedReceiver • BrpCheckQueryCoverageEntry • BrpDeliver • BrpInit • BrpProcessEvent • BrpPrintStats • BrpFinalize 운영체제특론(Advanced Operating System)
Libraries & Define • stdlib.h, stdio.h, string.h, <limits.h>, "api.h“, "network_ip.h“, "routing_iarp.h“, “routing_brp.h” • Definition, struct, enum, interface of functions • Routing_brp.h • In qualnet • Define • IERP is going to send another request after 30 seconds. So previous query information should be deleted before that. • #define BRP_DEFAULT_REQUEST_TIMEOUT (30 * SECOND) • #define BRP_INITIAL_PERIPHERAL_ENTRY_SIZE 10 • Etc. • Struct • brp_hdr_struct • Etc. • Routines • BrpDeliver, BrpSend, BrpInit, BrpPrintStats, BrpProcessEvent, BrpFinalize • Etc. • End define 운영체제특론(Advanced Operating System)
Routing Methods • BrpDeleteRoutesFromTable • Free memory of Previous bordercast node's ARP Routing table which is temporary created. • BrpConstructPrevBordercasterRoutingTable • Create Previous bordercast node's ARP Routing table for temporary. • BrpExtractPacket • Extract the BRP packet • BrpBordercastQueryPacket • Bordercasting query package. • BrpLoadPacket • Bordercasting query package. • BrpGetQueryCoverageEntryByCacheId • search the Query coverage for BRP Cache ID. • BrpScheduleDelete • Schedule timer for Deletion of the Query Coverage Entry • BrpDeleteQueryCoverageEntryByCacheId • Delete the Query Coverage Entry as per BRP Cache ID • BrpAddNewQueryCoverageEntry • Add a new Query Coverage Entry. • BrpNewNetGraph • Add a new Connecting graph. 운영체제특론(Advanced Operating System)
BrpIsCovered • Whether this node is already covered or not. • BrpMarkCovered • Mark the node as it is covered by query message. • BrpSend • used by IERP to request packet transmission • BrpCheckIfIntendedReceiver • Wheteher this node is intended receiver • BrpCheckQueryCoverageEntry • Get the Query Coverage Entry by Query ID ans Source • BrpDeliver • used by IP to deliver packet to BRP • BrpInit • BRP Initialization • BrpProcessEvent • BRP Process Event • BrpPrintStats • Printing BRP Status • BrpFinalize 운영체제특론(Advanced Operating System)
References • http://www.olsr.org/docs/report_html/node18.html • http://rainbow.sunmoon.ac.kr/~yypark/advancedOS/zrp.pptx • http://tools.ietf.org/id/draft-ietf-manet-zone-zrp-04.txt • http://tools.ietf.org/id/draft-ietf-manet-zone-brp-02.txt 운영체제특론(Advanced Operating System)