NetSim Source Code Help
Loading...
Searching...
No Matches
DSR.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 "DSR.h"
16#include "List.h"
17int fn_NetSim_DSR_Init_F(struct stru_NetSim_Network *NETWORK_Formal,
21 int nVersion_Type,
22 void **fnPointer);
24int fn_NetSim_DSR_CopyPacket_F(const NetSim_PACKET* destPacket,const NetSim_PACKET* srcPacket);
27
28
29
30/**
31DSR Init function initializes the DSR parameters.
32*/
33_declspec(dllexport) int fn_NetSim_DSR_Init(struct stru_NetSim_Network *NETWORK_Formal,
37 int nVersion_Type,
38 void **fnPointer)
39{
41}
42/**
43This is the DSR configure function.
44*/
45_declspec(dllexport) int fn_NetSim_DSR_Configure(void** var)
46{
47 return fn_NetSim_DSR_Configure_F(var);
48}
49/**
50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51This is the DSR Run function which gets called by the IP layer for routing the data
52by the DSR Network Routing Protocol. It includes the events NETWORK_OUT_EVENT,
53NETWORK_IN_EVENT and TIMER_EVENT.
54
55NETWORK_OUT_EVENT -
56 It process the Data Packets which arrive at the NetworkOut layer to route the packet.
57NETWORK_IN_EVENT -
58 It processes Data Packets, Route Request Packets, Route Reply Packets, Route Error
59 Packets, Ack Packet
60TIMER_EVENT -
61 It Process the DSR Route Request timeout and the DSR Maintenance Buffer timeout.
62~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64*/
66{
69 return -1;
71 {
74 {
75 case 0: //Packet from upper layer or Network in
76 default:
77 {
79 {
80 NETSIM_IPAddress n1,n2;
83 if(ip->type != dest->type)
84 return 0;
88 n2=IP_NETWORK_ADDRESS(dest,
91
92 if(!IP_COMPARE(n1,n2))
94 else
95 return 0; //Other network packet
96 }
97 else
98 {
99 //DSR control packet
100 //No processing just forward
101 }
102 }
103 break;
104 }
107 else
109 break;
110 case NETWORK_IN_EVENT:
111 {
113 {
114 case 0:
115 default:
116 {
118 {
119 default://Data packet or other layer control packet
121 {
125 //pstruEventDetails->pPacket=NULL;
126 }
127 break;
131 break;
135 break;
139
140 break;
141 case ctrlPacket_ACK:
144
145 }
146 }
147 break;
151 break;
152 }
153 }
154 break;
155 case TIMER_EVENT:
156 {
158 {
161
162 break;
165 break;
166 }
167 }
168 break;
169 }
170
171 return 1;
172}
173/**
174 This function is called by NetworkStack.dll, while writing the evnt trace
175 to get the sub event as a string.
176*/
177_declspec(dllexport) char* fn_NetSim_DSR_Trace(NETSIM_ID nSubeventid)
178{
179 switch(nSubeventid)
180 {
182 return "DSR_RREQ_TIMEOUT";
184 return "DSR_MAINT_TIMEOUT";
186 return "DSR_PROCESS_RERR";
187 default:
188 return "DSR_UNKNOWN";
189 }
190}
191/**
192 This function is called by NetworkStack.dll, to copy the DSR protocol
193 from source packet to destination.
194*/
195_declspec(dllexport) int fn_NetSim_DSR_CopyPacket(const NetSim_PACKET* destPacket,const NetSim_PACKET* srcPacket)
196{
197 return fn_NetSim_DSR_CopyPacket_F(destPacket,srcPacket);
198}
199/**
200 This function is called by NetworkStack.dll, to free the TCP protocol.
201*/
203{
204 return fn_NetSim_DSR_FreePacket_F(packet);
205}
206/**
207This function call WLAN Metrics function in lib file to write the Metrics in Metrics.txt.
208*/
210{
211 return fn_NetSim_DSR_Metrics_F(filename);
212}
213/**
214 This function is called by NetworkStack.dll, once simulation end to free the
215 allocated memory for the network.
216*/
218{
219 return fn_NetSim_DSR_Finish_F();
220}
221/**
222This function will return the string to write packet trace heading.
223*/
225{
226 return "";
227}
228/**
229 This function will return the string to write packet trace.
230*/
232{
233 return "";
234}
unsigned int NETSIM_ID
Definition: Animation.h:45
char * fn_NetSim_DSR_ConfigPacketTrace()
Definition: DSR.c:224
int fn_NetSim_DSR_Configure(void **var)
Definition: DSR.c:45
int fn_NetSim_DSR_FreePacket(NetSim_PACKET *packet)
Definition: DSR.c:202
int fn_NetSim_DSR_Configure_F(void **var)
int fn_NetSim_DSR_Metrics_F(PMETRICSWRITER filename)
char * fn_NetSim_DSR_Trace(NETSIM_ID nSubeventid)
Definition: DSR.c:177
char * fn_NetSim_DSR_WritePacketTrace()
Definition: DSR.c:231
int fn_NetSim_DSR_Init(struct stru_NetSim_Network *NETWORK_Formal, NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
Definition: DSR.c:33
int fn_NetSim_DSR_Run()
Definition: DSR.c:65
int fn_NetSim_DSR_Finish()
Definition: DSR.c:217
int fn_NetSim_DSR_CopyPacket_F(const NetSim_PACKET *destPacket, const NetSim_PACKET *srcPacket)
int fn_NetSim_DSR_CopyPacket(const NetSim_PACKET *destPacket, const NetSim_PACKET *srcPacket)
Definition: DSR.c:195
int fn_NetSim_DSR_FreePacket_F(NetSim_PACKET *packet)
int fn_NetSim_DSR_Metrics(PMETRICSWRITER filename)
Definition: DSR.c:209
int fn_NetSim_DSR_Init_F(struct stru_NetSim_Network *NETWORK_Formal, NetSim_EVENTDETAILS *pstruEventDetails_Formal, char *pszAppPath_Formal, char *pszWritePath_Formal, int nVersion_Type, void **fnPointer)
#define DSR_PROCESS_SRC_ROUTE()
Definition: DSR.h:748
#define DSR_PROCESS_ACK()
Definition: DSR.h:752
#define DSR_PROCESS_RREQ()
Definition: DSR.h:740
@ subevent_MAINT_TIMEOUT
Definition: DSR.h:80
@ subevent_RREQ_TIMEOUT
Definition: DSR.h:79
@ subevent_PROCESS_RERR
Definition: DSR.h:81
#define isDSRPACKET(packet)
Definition: DSR.h:53
NETSIM_ID dsr_get_curr_if()
bool isDsrConfigured(NETSIM_ID d, NETSIM_ID in)
@ ctrlPacket_ACK
Definition: DSR.h:90
@ ctrlPacket_ROUTE_REQUEST
Definition: DSR.h:87
@ ctrlPacket_ROUTE_ERROR
Definition: DSR.h:89
@ ctrlPacket_ROUTE_REPLY
Definition: DSR.h:88
void set_dsr_curr()
#define DSR_PACKET_PROCESSING()
Definition: DSR.h:717
int fn_NetSim_DSR_Finish_F()
NETSIM_IPAddress dsr_get_curr_ip()
#define DSR_PROCESS_RERR()
Definition: DSR.h:731
#define DSR_RREQ_TIMEOUT()
Definition: DSR.h:738
#define DSR_MAINT_TIMEOUT()
Definition: DSR.h:721
#define DSR_PROCESS_RREP()
Definition: DSR.h:734
NETSIM_IPAddress IP_NETWORK_ADDRESS(NETSIM_IPAddress ip, NETSIM_IPAddress subnet, unsigned int prefix_len)
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
void * PMETRICSWRITER
Definition: MetricsWriter.h:27
NetSim_EVENTDETAILS * pstruEventDetails_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char * pszAppPath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int nVersion_Type
Definition: RIP.h:178
NetSim_EVENTDETAILS char char * pszWritePath_Formal
Definition: RIP.h:178
NetSim_EVENTDETAILS char char int void ** fnPointer
Definition: RIP.h:178
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
@ TIMER_EVENT
Definition: Stack.h:114
@ NETWORK_IN_EVENT
Definition: Stack.h:109
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define DEVICE_INTERFACE(DeviceId, InterfaceId)
Definition: Stack.h:780
EVENT_TYPE nEventType
Definition: Stack.h:747
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_ID nInterfaceId
Definition: Stack.h:751
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
unsigned int nControlDataType
Definition: Packet.h:258