NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
SourceRoute.c
1/************************************************************************************
2 * Copyright (C) 2023 *
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*/
20int fn_NetSim_DSR_AddSourceRouteOption(NetSim_PACKET* packet,DSR_ROUTE_CACHE* cache)
21{
22// unsigned int loop;
23 unsigned int length;
24 DSR_OPTION_HEADER* option;
25 DSR_SOURCE_ROUTE_OPTION* srcRouteOption;
26 option = (DSR_OPTION_HEADER*)packet->pstruNetworkData->Packet_RoutingProtocol;
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;
35 option->nNextHeader = NO_NEXT_HEADER;
36 option->optType = optType_SourceRoute;
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;
45 packet->pstruNetworkData->Packet_RoutingProtocol = option;
46 packet->pstruNetworkData->nRoutingProtocol = NW_PROTOCOL_DSR;
47 option->nPayloadLength = DSR_SOURCEROUTE_SIZE_FIXED+length*4;
48 packet->pstruNetworkData->dOverhead = DSR_OPTION_HEADER_SIZE+option->nPayloadLength;
49 if(packet->pstruTransportData)
50 packet->pstruNetworkData->dPayload = packet->pstruTransportData->dPacketSize;
51 packet->pstruNetworkData->dPacketSize = packet->pstruNetworkData->dOverhead +
52 packet->pstruNetworkData->dPayload;
53 return 1;
54}
55/**
56This function process the data packet. it the device is the intended target,
57it adds a Transport_In_Event. Else it adds Network_Out_Event
58*/
59int fn_NetSim_DSR_ProcessSourceRouteOption(NetSim_EVENTDETAILS* pstruEventDetails)
60{
61 NetSim_PACKET* packet = pstruEventDetails->pPacket;
62 DSR_OPTION_HEADER* option;
63 DSR_SOURCE_ROUTE_OPTION* srcRouteOption;
64 option = (DSR_OPTION_HEADER*)packet->pstruNetworkData->Packet_RoutingProtocol;
65 if(!option)
66 return 0;
67 if(option->ackRequestOption)
68 DSR_PROCESS_ACK_REQUEST(packet);
69 if(option && option->optType == optType_SourceRoute)
70 {
71 //update the metrics
72 DSR_DEV_VAR(pstruEventDetails->nDeviceId)->dsrMetrics.packetReceived++;
73 srcRouteOption = option->options;
74
75 if (!IP_COMPARE(packet->pstruNetworkData->szDestIP, dsr_get_curr_ip()))
76 {
77 fn_NetSim_DSR_FreePacket(packet);
78 packet->pstruNetworkData->Packet_RoutingProtocol = NULL;
79 }
80 return 1;
81
82 }
83 return 0;
84}
85
86