1 / 23

Term Project: ZRP Source Code Part 1

Term Project: ZRP Source Code Part 1. presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012. Contents. routing_zrp.cpp: libraries routing methods. Libraries. stdlib.h stdio.h string.h “ api.h ” “ network_ip.h ” “ routing_zrp.h ” “ routing_iarp.h ”

jud
Télécharger la présentation

Term Project: ZRP Source Code Part 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Term Project:ZRP Source CodePart 1 presented by Ikhsan Putra Kurniawan Sun Moon University Spring 2012 운영체제특론(Advanced Operating System)

  2. Contents • routing_zrp.cpp: • libraries • routing methods 운영체제특론(Advanced Operating System)

  3. Libraries • stdlib.h • stdio.h • string.h • “api.h” • “network_ip.h” • “routing_zrp.h” • “routing_iarp.h” • “routing_ierp.h” 운영체제특론(Advanced Operating System)

  4. 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)

  5. 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)

  6. 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)

  7. 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)

  8. “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)

  9. 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)

  10. 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)

  11. 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)

  12. routing_zrp.cpp and its methods • ZrpIsEnabled • ZrpReturnProtocolData • ZrpHandleProtocolPacket • ZrpRouterFunction • enterZrpIdleState • ZrpInitStats • ZrpPrintStats • ZrpRunTimeStat • ZrpInit • ZrpFinalize • ZrpProcessEvent 운영체제특론(Advanced Operating System)

  13. ZrpIsEnabled • BOOLZrpIsEnabled(Node* node) { return (NetworkIpGetRoutingProtocol( node, ROUTING_PROTOCOL_ZRP) != NULL); } 운영체제특론(Advanced Operating System)

  14. 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)

  15. 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)

  16. 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)

  17. 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)

  18. 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)

  19. 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)

  20. // 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)

  21. 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)

  22. 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)

  23. Next: Part 2 • IERP. • IARP. • Improvement. 운영체제특론(Advanced Operating System)

More Related