NetSim Source Code Help
Loading...
Searching...
No Matches
RIP.h
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020
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
34
35 //RIP
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;
44
45
46
47 /** Enumeration for RIP Sub event Types*/
49 {
54 };
55
56
57 /// This enumeration is to denote the command field in RIP packet
59 {
62 };
63
64
65 /** Enumeration for App Layer Packet Type*/
67 {
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
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)
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
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
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
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
157
158 /// This function is used to update the database of router
160
161 /// This function is used receive the updates from neighbor routers
163
164 /// This function is used to trigger the update
166
168
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 */
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();
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
191 /// Function to copy the RIP packet from source to destination
194
195 _declspec(dllexport) int fn_NetSim_RIP_Metrics(PMETRICSWRITER metricsWriter);
197
205#ifdef __cplusplus
206}
207#endif
208#endif /* _RIP_H_*/
unsigned int NETSIM_ID
Definition: Animation.h:45
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
void * PMETRICSWRITER
Definition: MetricsWriter.h:27
int fn_NetSim_RIP_CopyPacket(NetSim_PACKET *pstruDestPacket, NetSim_PACKET *pstruSrcPacket)
Definition: RIP.c:64
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)
Definition: RIP.c:28
int fn_NetSim_RIP_Run()
Definition: RIP.c:95
int fn_NetSim_RIP_Finish()
Definition: RIP.c:40
char * fn_NetSim_RIP_Trace(int nSubEvent)
Definition: RIP.c:49
int fn_NetSim_RIP_TriggeredUpdate(struct stru_NetSim_Network *pstruNETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: RIP.c:102
int fn_NetSim_RIP_Metrics(PMETRICSWRITER metricsWriter)
Definition: RIP.c:71
int fn_NetSim_RIP_FreePacket(NetSim_PACKET *pstruPacket)
Definition: RIP.c:56
enum_RIP_Subevent_Type
Definition: RIP.h:49
@ RIP_TIMEOUT
Definition: RIP.h:51
@ SEND_RIP_UPDATE_PKT
Definition: RIP.h:50
@ RIP_GARBAGE_COLLECTION
Definition: RIP.h:52
@ ROUTING_TABLE_UPDATION
Definition: RIP.h:53
enum_RIP_command
This enumeration is to denote the command field in RIP packet.
Definition: RIP.h:59
@ REQUEST
Definition: RIP.h:60
@ RESPONSE
Definition: RIP.h:61
NetSim_PACKET *int fn_NetSim_RIP_CopyPacket_F(NetSim_PACKET *, NetSim_PACKET *)
NetSim_EVENTDETAILS NetSim_EVENTDETAILS *int fn_NetSim_RIP_Run_F()
Definition: RIP.c:223
int fn_NetSim_RIP_DistanceVectorAlgorithm(struct stru_NetSim_Network *NETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
int fn_NetSim_RIP_Finish_F()
FILE * fpRIPTrace
Definition: RIP.h:33
void set_RIP_var(NETSIM_ID d, DEVICE_ROUTER *rip)
int fn_NetSim_RIP_InitialTable_Creation(NETSIM_ID nDeviceId)
This function is for forming the initial table for each router
enum enum_RIP_Subevent_Type SUB_EVENT
Definition: RIP.h:43
int fn_NetSim_RIP_Timeout_Timer(struct stru_NetSim_Network *pstruNETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: TimeoutTimer.c:25
int fn_NetSim_RIP_Garbage_Collection_Timer(struct stru_NetSim_Network *pstruNETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
NetSim_EVENTDETAILS * pstruEventDetails_Formal
Definition: RIP.h:178
enum_RIP_ControlPacketType
Definition: RIP.h:67
@ RIP_Packet
Definition: RIP.h:68
struct stru_RIP_TempRouting_database RIP_TEMPROUTING_DATABASE
Definition: RIP.h:40
int fn_NetSim_RIP_Update_Timer(struct stru_NetSim_Network *pstruNETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: UpdateTimer.c:26
int fn_NetSim_RIP_Init_F(struct stru_NetSim_Network *, NetSim_EVENTDETAILS *, char *, char *, int, void **fnPointer)
enum enum_RIP_command RIP_COMMAND
Definition: RIP.h:42
NetSim_EVENTDETAILS char * pszAppPath_Formal
Definition: RIP.h:178
int fn_NetSim_RIP_Metrics_F(PMETRICSWRITER metricsWriter)
int fn_NetSim_RIP_UpdatingEntriesinRoutingDatabase(struct stru_NetSim_Network *, int, NETSIM_IPAddress, NETSIM_IPAddress, NETSIM_IPAddress, NETSIM_ID, double, unsigned int)
This function is used to update the database of router.
NetSim_EVENTDETAILS char char int nVersion_Type
Definition: RIP.h:178
char * fn_NetSim_RIP_Trace_F(int nSubEvent)
bool isRIPConfigured(NETSIM_ID d)
int fn_NetSim_RIPTrace(struct stru_NetSim_Network *, NETSIM_ID, int)
NetSim_EVENTDETAILS char char * pszWritePath_Formal
Definition: RIP.h:178
DEVICE_ROUTER * get_RIP_var(NETSIM_ID d)
int fn_NetSim_RIP_FreePacket_F(NetSim_PACKET *)
NetSim_EVENTDETAILS char char int void ** fnPointer
Definition: RIP.h:178
int fn_NetSim_RIP_ReceivingOf_RIP_Message(struct stru_NetSim_Network *pstruNETWORK, NetSim_EVENTDETAILS *pstruEventDetails)
Definition: ReceivingRIP.c:23
@ APP_PROTOCOL_RIP
Definition: Stack.h:154
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
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
struct stru_RIPEntry * pstruRIPEntry
Definition: RIP.h:105
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
short int RouteTag
Definition: RIP.h:131
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
struct stru_RIPEntry * pstru_RIP_NextEntry
Definition: RIP.h:137
Definition: RIP.h:141
int n_garbage_collection_timer
Definition: RIP.h:144
char * pszFilePath
Stores File path
Definition: RIP.h:151
unsigned short int nStatus
Definition: RIP.h:148
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 n_timeout_timer
Definition: RIP.h:143
int nDataDropped
Used to store the dropped packets
Definition: RIP.h:147
bool nStaticRoutingFlag
Definition: RIP.h:150
char * pszFileName
Stores File Name
Definition: RIP.h:152
unsigned int n_RIP_Version
Definition: RIP.h:145
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
struct stru_Router_RIP_Routing_database * pstru_Router_NextEntry
Definition: RIP.h:80
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