NetSim Source Code Help
Loading...
Searching...
No Matches
SourceRoute.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "List.h"
16#include "DSR.h"
17/**
18This function adds the source route option
19*/
21{
22// unsigned int loop;
23 unsigned int length;
24 DSR_OPTION_HEADER* option;
25 DSR_SOURCE_ROUTE_OPTION* srcRouteOption;
27 if(option && option->optType == optType_SourceRoute)
28 {
29 //Already added and processed
30 return 1;
31 }
32 option = calloc(1,sizeof* option);
33 srcRouteOption=calloc(1,sizeof* srcRouteOption);
34 option->options = srcRouteOption;
37 srcRouteOption->F = cache->F;
38 srcRouteOption->L = cache->L;
39 srcRouteOption->nSalvage = 0;
40 srcRouteOption->nOptionType = optType_SourceRoute;
41 srcRouteOption->nReserved = 0;
42 length = fn_NetSim_DSR_FillAddress(srcRouteOption,cache,dsr_get_curr_ip(),packet->pstruNetworkData->szDestIP);
43 srcRouteOption->nSegsLeft = length;
44 srcRouteOption->nOptDataLen = length*4+2;
52 return 1;
53}
54/**
55This function process the data packet. it the device is the intended target,
56it adds a Transport_In_Event. Else it adds Network_Out_Event
57*/
59{
61 DSR_OPTION_HEADER* option;
62 DSR_SOURCE_ROUTE_OPTION* srcRouteOption;
64 if(!option)
65 return 0;
66 if(option->ackRequestOption)
68 if(option && option->optType == optType_SourceRoute)
69 {
70 //update the metrics
71 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.packetReceived++;
72 srcRouteOption = option->options;
73
75 {
78 }
79 return 1;
80
81 }
82 return 0;
83}
84
85
int fn_NetSim_DSR_FreePacket(NetSim_PACKET *packet)
Definition: DSR.c:202
#define DSR_SOURCEROUTE_SIZE_FIXED
Definition: DSR.h:34
unsigned int fn_NetSim_DSR_FillAddress(DSR_SOURCE_ROUTE_OPTION *srcOption, DSR_ROUTE_CACHE *cache, NETSIM_IPAddress src, NETSIM_IPAddress dest)
#define DSR_PROCESS_ACK_REQUEST(packet)
Definition: DSR.h:751
#define DSR_DEV_VAR(dev)
Definition: DSR.h:772
#define DSR_OPTION_HEADER_SIZE
Definition: DSR.h:30
#define NO_NEXT_HEADER
Definition: DSR.h:45
NETSIM_IPAddress dsr_get_curr_ip()
@ optType_SourceRoute
Definition: DSR.h:100
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define calloc(c, s)
Definition: Memory.h:29
int fn_NetSim_DSR_AddSourceRouteOption(NetSim_PACKET *packet, DSR_ROUTE_CACHE *cache)
Definition: SourceRoute.c:20
int fn_NetSim_DSR_ProcessSourceRouteOption(NetSim_EVENTDETAILS *pstruEventDetails)
Definition: SourceRoute.c:58
@ NW_PROTOCOL_DSR
Definition: Stack.h:196
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
unsigned int nPayloadLength
Definition: DSR.h:557
DSR_ACK_REQ_OPTION * ackRequestOption
Definition: DSR.h:566
void * options
Definition: DSR.h:565
unsigned int nNextHeader
Definition: DSR.h:536
DSR_OPTION_TYPE optType
Definition: DSR.h:558
unsigned int F
Definition: DSR.h:580
unsigned int L
Definition: DSR.h:581
DSR_OPTION_TYPE nOptionType
Definition: DSR.h:129
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETWORK_LAYER_PROTOCOL nRoutingProtocol
Definition: Packet.h:205
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
struct stru_NetSim_Packet_TransportLayer * pstruTransportData
Definition: Packet.h:274