NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
UpdateTimer.c
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#include "main.h"
15#include "Routing.h"
16/**
17~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 Every 30 seconds, the RIP process is awakened to send an unsolicited response message
19 containing the complete routing table to every neighboring router.
20
21 1. Create the RIP packet
22 2. Add the RIP packets in the WAN ports of the current router
23 3. Add the packet in the socket buffer for transmitting the RIP packet
24~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25*/
26int fn_NetSim_RIP_Update_Timer(struct stru_NetSim_Network *pstruNETWORK,NetSim_EVENTDETAILS *pstruEventDetails)
27{
28 int nLoop1=0,nLink_Id=0;
29 NETSIM_ID nConnectedDevId=0,nDeviceid;
30 NETSIM_ID nConnectedInterfaceId=0;
31 NETSIM_ID nInterfaceId,nLoop=0;
32 NETSIM_ID nInterfaceCount;
33 DEVICE_ROUTER *pstruRouter;
34 bool bWanPort=false;
35 RIP_PACKET *pstruRIPPacket = NULL;
36 NetSim_PACKET* pstruControlPacket=NULL;
37 RIP_ROUTING_DATABASE *pstrudatabase;
38 RIP_ENTRY *pstruRIPNewEntry,*pstruRIPCurrentEntry;
39 NETWORK=pstruNETWORK;
40 nDeviceid=pstruEventDetails->nDeviceId;
41 nInterfaceCount=NETWORK->ppstruDeviceList[nDeviceid-1]->nNumOfInterface;
42 for(nLoop=0;nLoop<nInterfaceCount;nLoop++)
43 {
44 if(NETWORK->ppstruDeviceList[nDeviceid-1]->ppstruInterfaceList[nLoop]->szAddress &&
45 NETWORK->ppstruDeviceList[nDeviceid-1]->ppstruInterfaceList[nLoop]->nInterfaceType==INTERFACE_WAN_ROUTER)
46 {
47 nLink_Id = fn_NetSim_Stack_GetConnectedDevice(nDeviceid,nLoop+1,&nConnectedDevId,&nConnectedInterfaceId);
48 if(!nLink_Id)
49 continue;
50 pstruRouter = get_RIP_var(nDeviceid);
51 if(pstruRouter && pstruRouter->RoutingProtocol[nLoop] == APP_PROTOCOL_RIP)
52 {
53 //Get the Interface type
54 bWanPort=true;
55 //Creating the RIP packet
56 pstruRIPPacket=calloc(1,sizeof(RIP_PACKET));
57 //Assign the Version type
58 pstruRIPPacket->nVersion=pstruRouter->uniInteriorRouting.struRIP.n_RIP_Version;
59 pstrudatabase=pstruRouter->pstruRoutingTables->pstruRIP_RoutingTable;
60 //Add all the entries in routing database to RIP packet
61 while(pstrudatabase!=NULL)
62 {
63 pstruRIPNewEntry=calloc(1,sizeof(struct stru_RIPEntry));
64 pstruRIPNewEntry->szIPv4_address=IP_COPY(pstrudatabase->szAddress);
65 pstruRIPNewEntry->szNext_Hop=IP_COPY(pstrudatabase->szRouter);
66 pstruRIPNewEntry->nAddress_family_identifier=2; // The Address family identifier value is 2 for IP
67 pstruRIPNewEntry->szSubnet_Mask=IP_COPY(pstrudatabase->szSubnetmask);
68 pstruRIPNewEntry->nMetric=pstrudatabase->nMetric;
69 if(pstruRIPPacket->pstruRIPEntry)
70 {
71 pstruRIPCurrentEntry = pstruRIPPacket->pstruRIPEntry;
72 while(pstruRIPCurrentEntry->pstru_RIP_NextEntry != NULL)
73 pstruRIPCurrentEntry = pstruRIPCurrentEntry->pstru_RIP_NextEntry;
74 pstruRIPCurrentEntry->pstru_RIP_NextEntry = pstruRIPNewEntry;
75 }
76 else
77 pstruRIPPacket->pstruRIPEntry = pstruRIPNewEntry;
78 pstrudatabase=pstrudatabase->pstru_Router_NextEntry;
79 }
80 nInterfaceId=nLoop+1;
81 //Create the Application layer packet to carry the RIP packet
82 pstruControlPacket=fn_NetSim_Packet_CreatePacket(APPLICATION_LAYER);
83 pstruControlPacket->nControlDataType=RIP_Packet;
84 pstruControlPacket->nPacketId=0;
85 pstruControlPacket->nPacketType=PacketType_Control;
86 pstruControlPacket->nSourceId=nDeviceid;
87 add_dest_to_packet(pstruControlPacket, nConnectedDevId);
88 pstruControlPacket->nTransmitterId=nDeviceid;
89 pstruControlPacket->nReceiverId=nConnectedDevId;
90 //Assign the Application layer details of the packet
91 pstruControlPacket->pstruAppData->dArrivalTime=pstruEventDetails->dEventTime;
92 pstruControlPacket->pstruAppData->dEndTime=pstruEventDetails->dEventTime;
93 pstruControlPacket->pstruAppData->dStartTime=pstruEventDetails->dEventTime;
94 pstruControlPacket->pstruAppData->dPayload=RIP_PACKET_SIZE_WITH_HEADER;
95 pstruControlPacket->pstruAppData->dOverhead=0;
96 pstruControlPacket->pstruAppData->dPacketSize=pstruControlPacket->pstruAppData->dPayload+pstruControlPacket->pstruAppData->dOverhead;
97 pstruControlPacket->pstruAppData->nApplicationProtocol=APP_PROTOCOL_RIP;
98 pstruControlPacket->pstruAppData->Packet_AppProtocol=pstruRIPPacket;
99 //Assign the Network layer details of the packet
100 pstruControlPacket->pstruNetworkData->nNetworkProtocol=NW_PROTOCOL_IPV4;
101 pstruControlPacket->pstruNetworkData->nTTL = 1;
102 pstruControlPacket->pstruNetworkData->szSourceIP=IP_COPY(fn_NetSim_Stack_GetIPAddressAsId(nDeviceid,nInterfaceId));
103 pstruControlPacket->pstruNetworkData->szDestIP=IP_COPY(fn_NetSim_Stack_GetIPAddressAsId(nConnectedDevId,nConnectedInterfaceId));
104 if(!pstruControlPacket->pstruNetworkData->szDestIP)
105 {
106 char str[5000];
107 sprintf(str,"Unable to get the connected device IP address for Router %d Interface %d",nDeviceid,nInterfaceId);
108 fnNetSimError(str);
109 }
110 //Assign the Transport layer details of the packet
111 pstruControlPacket->pstruTransportData->nSourcePort=RIP_PORT+1;
112 pstruControlPacket->pstruTransportData->nDestinationPort=RIP_PORT;
113 if(NETWORK->ppstruDeviceList[nDeviceid-1]->pstruTransportLayer->isUDP)
114 pstruControlPacket->pstruTransportData->nTransportProtocol=TX_PROTOCOL_UDP;
115 else if(NETWORK->ppstruDeviceList[nDeviceid-1]->pstruTransportLayer->isTCP)
116 pstruControlPacket->pstruTransportData->nTransportProtocol=TX_PROTOCOL_TCP;
117 else
118 pstruControlPacket->pstruTransportData->nTransportProtocol=0;
119 //Add the packets to the socket buffer
120 if(!fn_NetSim_Socket_GetBufferStatus(pstruRouter->sock))
121 {
122 fn_NetSim_Socket_PassPacketToInterface(nDeviceid, pstruControlPacket, pstruRouter->sock);
123 pstruEventDetails->dEventTime=pstruEventDetails->dEventTime;
124 pstruEventDetails->dPacketSize=pstruControlPacket->pstruAppData->dPacketSize;
125 pstruEventDetails->nApplicationId=0;
126 pstruEventDetails->nProtocolId=pstruControlPacket->pstruTransportData->nTransportProtocol;
127 pstruEventDetails->nDeviceId=nDeviceid;
128 pstruEventDetails->nInterfaceId=0;
129 pstruEventDetails->nEventType=TRANSPORT_OUT_EVENT;
130 pstruEventDetails->nSubEventType=0;
131 pstruEventDetails->pPacket=NULL;
132 pstruEventDetails->szOtherDetails = pstruRouter->sock;
133 fnpAddEvent(pstruEventDetails);
134 }
135 else
136 {
137 fn_NetSim_Socket_PassPacketToInterface(nDeviceid, pstruControlPacket, pstruRouter->sock);
138 }
139 }
140 }
141 }
142 //To add the next update event
143 if(bWanPort)
144 {
145 pstruEventDetails->nPacketId=0;
146 pstruEventDetails->nApplicationId= 0;
147 pstruEventDetails->nEventType=TIMER_EVENT;
148 pstruEventDetails->nSubEventType=SEND_RIP_UPDATE_PKT;
149 pstruEventDetails->nProtocolId=APP_PROTOCOL_RIP;
150 pstruEventDetails->dEventTime=pstruEventDetails->dEventTime+get_RIP_var(nDeviceid)->uniInteriorRouting.struRIP.n_Update_timer;
151 pstruEventDetails->pPacket = NULL;
152 fnpAddEvent(pstruEventDetails);
153 }
154 return 0;
155}
156
157
158
159
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
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