NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Routing.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: Thangarasu *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "Routing.h"
16/** This function is used to call the inter and intra area routing protocols */
17_declspec(dllexport) int fn_NetSim_Routing_Run()
18{
19 switch(pstruEventDetails->nProtocolId)
20 {
21 case APP_PROTOCOL_RIP:
22 fn_NetSim_RIP_Run_F();
23 break;
24 default:
25 break;
26 }
27 return 1;
28}
29/** This function is used to update the entries in routing table */
30_declspec(dllexport)int fn_NetSim_UpdateEntryinRoutingTable(struct stru_NetSim_Network *NETWORK,NetSim_EVENTDETAILS *pstruEventDetails,NETSIM_ID nDeviceId,NETSIM_ID nInterfaceId,unsigned int bgpRemoteAS,NETSIM_IPAddress szDestinationIP,NETSIM_IPAddress szNexthop,NETSIM_IPAddress szSubnetmask,unsigned int prefix_len,int nCost,int nFlag)
31{
32 DEVICE_ROUTER *pstruRouter = get_RIP_var(nDeviceId);
33 if(pstruRouter->AppIntRoutingProtocol == APP_PROTOCOL_RIP)
34 {
35 fn_NetSim_RIP_UpdatingEntriesinRoutingDatabase(NETWORK,nDeviceId,szDestinationIP,szSubnetmask,szNexthop,nInterfaceId,pstruEventDetails->dEventTime,nCost);
36 if(nFlag)
37 {
38 fn_NetSim_RIP_TriggeredUpdate(NETWORK,pstruEventDetails);
39 }
40 }
41
42 return 0;
43}
44/** This function is used to update the protocol status in the interface */
45_declspec(dllexport)int UpdateInterfaceList()
46{
47 NETSIM_ID i,j;
48 DEVICE_ROUTER *pstruRouter;
49 NETSIM_ID nDeviceCount,nInterfaceCount,nConnectedDevId,nConnectedInterId;
50 nDeviceCount = NETWORK->nDeviceCount;
51 for(i=0;i<nDeviceCount;i++)
52 {
53 //if(NETWORK->ppstruDeviceList[i]->nDeviceType == ROUTER)
54 if(fnCheckRoutingProtocol(i+1))
55 {
56 nInterfaceCount = NETWORK->ppstruDeviceList[i]->nNumOfInterface;
57 if(NETWORK->ppstruDeviceList[i]->pstruApplicationLayer)
58 {
59 pstruRouter = get_RIP_var(i + 1);
60 if(!pstruRouter->RoutingProtocol)
61 {
62 pstruRouter->RoutingProtocol = calloc(nInterfaceCount,sizeof* pstruRouter->RoutingProtocol);
63 }
64 for(j=0;j<nInterfaceCount;j++)
65 {
66 if(NETWORK->ppstruDeviceList[i]->ppstruInterfaceList[j]->nInterfaceType == INTERFACE_WAN_ROUTER)
67 {
68 fn_NetSim_Stack_GetConnectedDevice(i+1,j+1,&nConnectedDevId,&nConnectedInterId);
69 pstruRouter->RoutingProtocol[j] = APP_PROTOCOL_RIP;
70 }
71 }
72 }
73 }
74 }
75 return 0;
76}
77int fnCheckRoutingPacket()
78{
79 if(pstruEventDetails->pPacket && pstruEventDetails->pPacket->nControlDataType/100 == APP_PROTOCOL_RIP)
80 return 1;
81 return 0;
82}
83
84APPLICATION_LAYER_PROTOCOL fnCheckRoutingProtocol(NETSIM_ID deviceId)
85{
86 if(fn_NetSim_Stack_isProtocolConfigured(deviceId,APPLICATION_LAYER,APP_PROTOCOL_RIP))
87 return APP_PROTOCOL_RIP;
88 else
89 return APP_PROTOCOL_NULL;
90}