NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
OLSR_routingTable.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: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "ZRP.h"
16#include "ZRP_Enum.h"
17
18int fn_NetSim_OLSR_UpdateRoutingTable()
19{
20 //Section 10
21 NODE_OLSR* olsr=GetOLSRData(pstruEventDetails->nDeviceId);
22 NETSIM_IPAddress subnet = STR_TO_IP4("255.255.255.255");
23 OLSR_NEIGHBOR_SET* neighbor;
24 OLSR_2HOP_NEIGHBOR_SET* two_hop_neighbor;
25 OLSR_TOPOLOGY_INFORMATION_BASE* topology;
26 if(!olsr->bRoutingTableUpdate)
27 {
28 return 0; //No update
29 }
30 //Condition 1
31 olsrFlushroutingTable(olsr->ipWrapper,pstruEventDetails->nDeviceId);
32 olsr->ipWrapper->table = NULL;
33
34 //Condition 2
35 neighbor=olsr->neighborSet;
36 while(neighbor)
37 {
38 if(neighbor->N_status>=SYM_NEIGH)
39 {
40 NETSIM_ID interfaceId = 1;
41 iptable_add(olsr->ipWrapper,
42 neighbor->N_neighbor_main_addr,
43 subnet,
44 0,
45 neighbor->N_neighbor_main_addr,
46 1,
47 &olsr->mainAddress,
48 &interfaceId,
49 1,
50 "OLSR");
51
52 }
53 neighbor=(OLSR_NEIGHBOR_SET*)LIST_NEXT(neighbor);
54 }
55
56 //Condition 3
57 two_hop_neighbor=olsr->twoHopNeighborSet;
58 while(two_hop_neighbor)
59 {
60 neighbor=olsrFindNeighborSet(olsr->neighborSet,two_hop_neighbor->N_2hop_addr);
61 if(!neighbor && IP_COMPARE(two_hop_neighbor->N_2hop_addr,olsr->mainAddress))
62 {
63 neighbor=olsrFindNeighborSet(olsr->neighborSet,two_hop_neighbor->N_neighbor_main_addr);
64 if(neighbor->N_willingness != WILL_NEVER && neighbor->N_status==MPR_NEIGH)
65 {
66 NETSIM_ID interfaceId = 1;
67 iptable_add(olsr->ipWrapper,
68 two_hop_neighbor->N_2hop_addr,
69 subnet,
70 0,
71 two_hop_neighbor->N_neighbor_main_addr,
72 1,
73 &olsr->mainAddress,
74 &interfaceId,
75 2,
76 "OLSR");
77 }
78 }
79 two_hop_neighbor=(OLSR_2HOP_NEIGHBOR_SET*)LIST_NEXT(two_hop_neighbor);
80 }
81
82 //Condition 3
83 topology=olsr->topologyInfoBase;
84 while(topology)
85 {
86 ptrIP_ROUTINGTABLE table=iptable_check((ptrIP_ROUTINGTABLE*)&olsr->ipWrapper->table,topology->T_dest_addr,subnet);
87 if(!table && IP_COMPARE(topology->T_dest_addr,olsr->mainAddress))
88 {
89 table=iptable_check((ptrIP_ROUTINGTABLE*)&olsr->ipWrapper->table,topology->T_last_addr,subnet);
90 if(table && table->Metric < olsr->nZoneRadius)
91 {
92 NETSIM_ID interfaceId = 1;
93 iptable_add(olsr->ipWrapper,
94 topology->T_dest_addr,
95 subnet,
96 0,
97 table->gateway,
98 1,
99 &olsr->mainAddress,
100 &interfaceId,
101 table->Metric + 1,
102 "OLSR");
103 /* topology=olsr->topologyInfoBase;
104 continue;*/
105 }
106 }
107 topology=(OLSR_TOPOLOGY_INFORMATION_BASE*)LIST_NEXT(topology);
108 }
109 olsrUpdateIptable(olsr->ipWrapper->table,pstruEventDetails->nDeviceId);
110 olsr->bRoutingTableUpdate=false;
111 if(DEVICE_NWLAYER(pstruEventDetails->nDeviceId)->nRoutingProtocolId == NW_PROTOCOL_ZRP)
112 fn_NetSim_BRP_Update(olsr->ipWrapper->table);
113 return 0;
114}
115int olsrUpdateIptable(ptrIP_ROUTINGTABLE table,NETSIM_ID nNodeId)
116{
117 while(table)
118 {
119 iptable_add(IP_WRAPPER_GET(nNodeId),
120 table->networkDestination,
121 table->netMask,
122 table->prefix_len,
123 table->gateway,
124 1,
125 table->Interface,
126 table->nInterfaceId,
127 table->Metric,
128 "OLSR");
129
130 table=(ptrIP_ROUTINGTABLE)LIST_NEXT(table);
131 }
132 return 0;
133}
134int olsrFlushroutingTable(ptrIP_WRAPPER wrapper,NETSIM_ID nNodeId)
135{
136 ptrIP_ROUTINGTABLE iptable = wrapper->table;
137 while(iptable)
138 {
139 iptable_delete(IP_WRAPPER_GET(nNodeId), iptable->networkDestination, NULL,"OLSR");
140 iptable_delete(wrapper, iptable->networkDestination, NULL,"OLSR");
141 iptable = wrapper->table;
142 }
143 return 0;
144}