NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
RIP.h
1/************************************************************************************
2* Copyright (C) 2023
3*
4* TETCOS, Bangalore. India *
5
6* Tetcos owns the intellectual property rights in the Product and its content. *
7* The copying, redistribution, reselling or publication of any or all of the *
8* Product or its content without express prior written consent of Tetcos is *
9* prohibited. Ownership and / or any other right relating to the software and all *
10* intellectual property rights therein shall remain at all times with Tetcos. *
11
12* Author: Thangarasu.K *
13* ---------------------------------------------------------------------------------*/
14
15/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
16* *
17* THIS FILES CONTAIN RIP DATASTUCTURE WHICH HAS VARIABLES THAT ARE PROVIDED FOR USERS. *
18* *
19* BY MAKING USE OF THESE VARIABLES THE USER CAN CREATE THEIR OWN PROJECT IN RIP *
20* *
21* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22#ifndef _RIP_H_
23#define _RIP_H_
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define RIP_PACKET_SIZE_WITH_HEADER 512
29#define RIP_PORT 520 // Reference : RFC 2453, November 1998, Page 20
30 // RIP has a routing process that sends and receives datagrams on UDP port number 520
31#define EXPIRED_ROUTE 16 //Infinity route
32#define _RIP_Trace
33 FILE *fpRIPTrace;
34
35 //RIP
36 typedef struct stru_NetSim_Router DEVICE_ROUTER;
37 typedef struct stru_Router_Buffer BUFFER_ROUTER;
38 typedef struct stru_NetSim_RIP_Packet RIP_PACKET; //RIP Packet structure
39 typedef struct stru_Router_RIP_Routing_database RIP_ROUTING_DATABASE; // Routing database structure
40 typedef struct stru_RIP_TempRouting_database RIP_TEMPROUTING_DATABASE;
41 typedef struct stru_RIPEntry RIP_ENTRY;
42 typedef enum enum_RIP_command RIP_COMMAND;
43 typedef enum enum_RIP_Subevent_Type SUB_EVENT;
44
45
46
47 /** Enumeration for RIP Sub event Types*/
48 enum enum_RIP_Subevent_Type
49 {
50 SEND_RIP_UPDATE_PKT=APP_PROTOCOL_RIP*100+1,
51 RIP_TIMEOUT,
52 RIP_GARBAGE_COLLECTION,
53 ROUTING_TABLE_UPDATION,
54 };
55
56
57 /// This enumeration is to denote the command field in RIP packet
58 enum enum_RIP_command
59 {
60 REQUEST=1,
61 RESPONSE,
62 };
63
64
65 /** Enumeration for App Layer Packet Type*/
66 enum enum_RIP_ControlPacketType
67 {
68 RIP_Packet = APP_PROTOCOL_RIP*100+1,
69 };
70 ///Routing database structure Reference : RFC 2453, November 1998, Page 8
72
73 {
74 NETSIM_IPAddress szAddress; ///< IP address of the destination host or destination network
75 NETSIM_IPAddress szSubnetmask; ///< Subnet mask for the destination network
76 NETSIM_IPAddress szRouter; ///< The first router along the route to the destination
77 NETSIM_ID nInterface; ///< The physical network which must be used to reach the first router
78 unsigned int nMetric; ///< Distance to the destination
79 double dTimer; ///< The amount of time since the entry was last updated
80 struct stru_Router_RIP_Routing_database *pstru_Router_NextEntry;
81 };
82
83/**
84~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 RIP packet structure. RFC 2453 November 1998 Pages : 20,21
86
87 The RIP packet format is:
88
89 0 1 2 3
90 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
91 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 | command (1) | version (1) | must be zero (2) |
93 +---------------+---------------+-------------------------------+
94 | |
95 ~ RIP Entry (20) ~
96 | |
97 +---------------+---------------+---------------+---------------+
98~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99 */
101 {
102 RIP_COMMAND command; /**< The command field is used to specify the purpose of this message. <br/>
103 If it is 1-->request message, 2-->response message */
104 unsigned int nVersion:8; ///< The version field is used to specify the RIP version (version 1 or 2)
105 struct stru_RIPEntry *pstruRIPEntry;
106 };
107
108 /**
109 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 The format for the 20-octet route entry (RTE) for
111 RIP-2 is:
112
113 0 1 2 3 3
114 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
115 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116 | Address Family Identifier (2) | Route Tag (2) |
117 +-------------------------------+-------------------------------+
118 | IP Address (4) |
119 +---------------------------------------------------------------+
120 | Subnet Mask (4) |
121 +---------------------------------------------------------------+
122 | Next Hop (4) |
123 +---------------------------------------------------------------+
124 | Metric (4) |
125 +---------------------------------------------------------------+
126 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127 */
129 {
130 unsigned int nAddress_family_identifier:16; ///< This is used to identify the Address family of the IP address
131 short int RouteTag;
132 NETSIM_IPAddress szIPv4_address; ///< Destination IPv4 address
133 NETSIM_IPAddress szSubnet_Mask; ///< Destination Subnet Mask
134 NETSIM_IPAddress szNext_Hop; /**< The immediate next hop IP address to which packets to the destination.
135 specified by this route entry should be forwarded */
136 unsigned int nMetric; ///< Cost to reach the destination
137 struct stru_RIPEntry *pstru_RIP_NextEntry;
138 };
139 /** Structure to store RIP information */
140 struct stru_RIP
141 {
142 int n_Update_timer; ///< These variable values are get from configuration.xml,in RFC the update timer is mentioned as 30-second timer
143 int n_timeout_timer;
144 int n_garbage_collection_timer;
145 unsigned int n_RIP_Version:8;
146 unsigned int nRIP_Update; ///< Used to check the updates in the router
147 int nDataDropped; ///< Used to store the dropped packets
148 unsigned short int nStatus;
149
150 bool nStaticRoutingFlag;
151 char* pszFilePath; ///< Stores File path
152 char* pszFileName; ///< Stores File Name
153 };
154
155 /// This function is for forming the initial table for each router
156 int fn_NetSim_RIP_InitialTable_Creation(NETSIM_ID nDeviceId);
157
158 /// This function is used to update the database of router
159 int fn_NetSim_RIP_UpdatingEntriesinRoutingDatabase(struct stru_NetSim_Network *,int,NETSIM_IPAddress,NETSIM_IPAddress,NETSIM_IPAddress,NETSIM_ID,double,unsigned int);
160
161 /// This function is used receive the updates from neighbor routers
162 _declspec(dllexport) int fn_NetSim_RIP_ReceivingOf_RIP_Message(struct stru_NetSim_Network* ,NetSim_EVENTDETAILS* );
163
164 /// This function is used to trigger the update
165 _declspec(dllexport)int fn_NetSim_RIP_TriggeredUpdate(struct stru_NetSim_Network *,NetSim_EVENTDETAILS *);
166
167 int fn_NetSim_RIP_Run_F();
168
169 int fn_NetSim_RIPTrace(struct stru_NetSim_Network*,NETSIM_ID,int);
170
171
172
173 /****************** NetWorkStack DLL functions declarations *****************************************/
174 /** Function for configuring RIP parameters*/
175 _declspec(dllexport) int fn_NetSim_RIP_Configure_F(void** var);
176
177 /** Function for Intializing RIP protocol */
178 _declspec (dllexport) int fn_NetSim_RIP_Init(struct stru_NetSim_Network *NETWORK_Formal,NetSim_EVENTDETAILS *pstruEventDetails_Formal,char *pszAppPath_Formal,char *pszWritePath_Formal,int nVersion_Type,void **fnPointer);
179 int fn_NetSim_RIP_Init_F(struct stru_NetSim_Network * ,NetSim_EVENTDETAILS * ,char * ,char * ,int ,void **fnPointer);
180 /** Function to run RIP protocol */
181 _declspec (dllexport) int fn_NetSim_RIP_Run();
182 /// Function to free the RIP protocol variable and Unload the primitives
183 _declspec(dllexport) int fn_NetSim_RIP_Finish();
184 int fn_NetSim_RIP_Finish_F();
185 /// Return the subevent name with respect to the subevent number for writting event trace
186 _declspec (dllexport) char *fn_NetSim_RIP_Trace(int nSubEvent);
187 char *fn_NetSim_RIP_Trace_F(int nSubEvent);
188 /// Function to free the allocated memory for the RIP packet
189 _declspec(dllexport) int fn_NetSim_RIP_FreePacket(NetSim_PACKET* );
190 int fn_NetSim_RIP_FreePacket_F(NetSim_PACKET* );
191 /// Function to copy the RIP packet from source to destination
192 _declspec(dllexport) int fn_NetSim_RIP_CopyPacket(NetSim_PACKET* ,NetSim_PACKET* );
193 int fn_NetSim_RIP_CopyPacket_F(NetSim_PACKET* ,NetSim_PACKET* );
194
195 _declspec(dllexport) int fn_NetSim_RIP_Metrics(PMETRICSWRITER metricsWriter);
196 int fn_NetSim_RIP_Metrics_F(PMETRICSWRITER metricsWriter);
197
198 int fn_NetSim_RIP_DistanceVectorAlgorithm(struct stru_NetSim_Network *NETWORK,NetSim_EVENTDETAILS *pstruEventDetails);
199 int fn_NetSim_RIP_Update_Timer(struct stru_NetSim_Network *pstruNETWORK,NetSim_EVENTDETAILS *pstruEventDetails);
200 int fn_NetSim_RIP_Timeout_Timer(struct stru_NetSim_Network *pstruNETWORK,NetSim_EVENTDETAILS *pstruEventDetails);
201 int fn_NetSim_RIP_Garbage_Collection_Timer(struct stru_NetSim_Network *pstruNETWORK,NetSim_EVENTDETAILS *pstruEventDetails);
202 bool isRIPConfigured(NETSIM_ID d);
203 DEVICE_ROUTER* get_RIP_var(NETSIM_ID d);
204 void set_RIP_var(NETSIM_ID d, DEVICE_ROUTER* rip);
205#ifdef __cplusplus
206}
207#endif
208#endif /* _RIP_H_*/
RIP_COMMAND command
Definition RIP.h:102
unsigned int nVersion
The version field is used to specify the RIP version (version 1 or 2)
Definition RIP.h:104
Definition RIP.h:129
unsigned int nMetric
Cost to reach the destination.
Definition RIP.h:136
unsigned int nAddress_family_identifier
This is used to identify the Address family of the IP address.
Definition RIP.h:130
NETSIM_IPAddress szSubnet_Mask
Destination Subnet Mask.
Definition RIP.h:133
NETSIM_IPAddress szIPv4_address
Destination IPv4 address.
Definition RIP.h:132
NETSIM_IPAddress szNext_Hop
Definition RIP.h:134
char * pszFilePath
Stores File path.
Definition RIP.h:151
int n_Update_timer
These variable values are get from configuration.xml,in RFC the update timer is mentioned as 30-secon...
Definition RIP.h:142
unsigned int nRIP_Update
Used to check the updates in the router.
Definition RIP.h:146
int nDataDropped
Used to store the dropped packets.
Definition RIP.h:147
char * pszFileName
Stores File Name.
Definition RIP.h:152
Routing database structure Reference : RFC 2453, November 1998, Page 8.
Definition RIP.h:73
NETSIM_ID nInterface
The physical network which must be used to reach the first router.
Definition RIP.h:77
double dTimer
The amount of time since the entry was last updated.
Definition RIP.h:79
unsigned int nMetric
Distance to the destination.
Definition RIP.h:78
NETSIM_IPAddress szRouter
The first router along the route to the destination.
Definition RIP.h:76
NETSIM_IPAddress szAddress
IP address of the destination host or destination network.
Definition RIP.h:74
NETSIM_IPAddress szSubnetmask
Subnet mask for the destination network.
Definition RIP.h:75