term project zrp source code part 1
Download
Skip this Video
Download Presentation
Term Project: ZRP Source Code Part 1

Loading in 2 Seconds...

play fullscreen
1 / 23

Term Project: ZRP Source Code Part 1 - PowerPoint PPT Presentation


  • 119 Views
  • Uploaded on

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 ”

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Term Project: ZRP Source Code Part 1' - jud


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
term project zrp source code part 1

Term Project:ZRP Source CodePart 1

presented by

Ikhsan Putra Kurniawan

Sun Moon University

Spring 2012

운영체제특론(Advanced Operating System)

contents
Contents
  • routing_zrp.cpp:
    • libraries
    • routing methods

운영체제특론(Advanced Operating System)

libraries
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
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
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
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
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
“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
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
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
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
routing_zrp.cpp and its methods
  • ZrpIsEnabled
  • ZrpReturnProtocolData
  • ZrpHandleProtocolPacket
  • ZrpRouterFunction
  • enterZrpIdleState
  • ZrpInitStats
  • ZrpPrintStats
  • ZrpRunTimeStat
  • ZrpInit
  • ZrpFinalize
  • ZrpProcessEvent

운영체제특론(Advanced Operating System)

zrpisenabled
ZrpIsEnabled
  • BOOLZrpIsEnabled(Node* node) {

return (NetworkIpGetRoutingProtocol(

node,

ROUTING_PROTOCOL_ZRP) != NULL);

}

운영체제특론(Advanced Operating System)

slide14

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)

slide15

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)

slide16

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

slide20

// 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
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
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
Next: Part 2
  • IERP.
  • IARP.
  • Improvement.

운영체제특론(Advanced Operating System)

ad