NetSim Source Code Help
Loading...
Searching...
No Matches
PIM_Neighbor.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
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
15#include "main.h"
16#include "List.h"
17#include "IP.h"
18#include "PIM_SM.h"
19
21{
22 ptrPIM_NEIGHBOR neigh = GET_PIM_VAR(d)->neighborList;
23 while (neigh)
24 {
25 //Look for primary address
26 if (!IP_COMPARE(neigh->neighborAddr, ip))
27 return neigh;
28
29 //Look for secondary address
30 UINT i;
31 for (i = 0; i < neigh->secondary_address_count; i++)
32 if (!IP_COMPARE(ip, neigh->secondary_address_list[i]))
33 return neigh;
34
35 PIM_NEIGHBOR_NEXT(neigh);
36 }
37 return NULL;
38}
39
41{
42 GET_PIM_VAR(d)->neighCount++;
43 PIM_NEIGHBOR_ADD(&GET_PIM_VAR(d)->neighborList, neigh);
44}
45
47 NETSIM_ID ifId,
48 NETSIM_IPAddress address)
49{
51 neigh->incomingInterface = ifId;
52 neigh->neighborAddr = address;
53 add_neighbor(d, neigh);
54 return neigh;
55}
56
58 NETSIM_ID ifid,
59 UINT* c)
60{
61 UINT k = 0;
63 ptrPIM_NEIGHBOR neigh = GET_PIM_VAR(d)->neighborList;
64 while (neigh)
65 {
66 if (neigh->incomingInterface == ifid)
67 {
68 if (k)
69 n = realloc(n, (k + 1) * sizeof* n);
70 else
71 n = calloc(1, sizeof* n);
72 n[k] = neigh;
73 k++;
74 }
75 PIM_NEIGHBOR_NEXT(neigh);
76 }
77 *c = k;
78 return n;
79}
80
82{
83 if (!a->dr_priority_present || !b->dr_priority_present)
84 {
85 return a->neighborAddr->str_ip > b->neighborAddr->str_ip;
86 }
87 else
88 {
89 return ((a->dr_priority > b->dr_priority) ||
90 (a->dr_priority == b->dr_priority &&
91 a->neighborAddr->str_ip > b->neighborAddr->str_ip));
92 }
93}
94
96{
97 ptrPIM_VAR var = GET_PIM_VAR(d);
98 UINT c = 0;
100 UINT i;
101
102 PIM_NEIGHBOR me;
103 memset(&me, 0, sizeof me);
104 me.neighborAddr = DEVICE_NWADDRESS(d, ifid);
105 ptrPIM_NEIGHBOR dr = &me;
106 for (i = 0; i < c; i++)
107 {
108 if (dr_is_better(neigh[i], dr))
109 dr = neigh[i];
110 }
111 var->DR[ifid - 1] = dr->neighborAddr;
112 free(neigh);
113}
114
116{
117 UINT c = 0;
119 UINT i;
120
121 for (i = 0; i < c; i++)
122 {
123 if (neigh[i]->lan_prune_delay_present == false)
124 {
125 free(neigh);
126 return false;
127 }
128 }
129 free(neigh);
130 return true;
131}
132
134{
135 if (!lan_delay_enabled(d,I) == false)
137
138 time_interval delay = GET_PIM_VAR(d)->propagationDelay;
139 UINT c;
141 UINT i;
142
143 for (i = 0; i < c; i++)
144 {
145 if (neigh[i]->propagation_delay > delay)
146 delay = neigh[i]->propagation_delay;
147 }
148 free(neigh);
149 return delay;
150}
151
153{
154 if (!lan_delay_enabled(d, I) == false)
155 return t_override_default;
156
157 time_interval delay = GET_PIM_VAR(d)->overrideInterval;
158 UINT c;
160 UINT i;
161
162 for (i = 0; i < c; i++)
163 {
164 if (neigh[i]->override_interval > delay)
165 delay = neigh[i]->override_interval;
166 }
167 free(neigh);
168 return delay;
169}
170
172{
173 if (lan_delay_enabled(d, I) == false)
174 return true;
175
176 UINT c;
178 UINT i;
179
180 for (i = 0; i < c; i++)
181 {
182 if (neigh[i]->tracking_support == false)
183 {
184 free(neigh);
185 return true;
186 }
187 }
188 free(neigh);
189 return false;
190}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define c
#define UINT
Definition: Linux.h:38
#define realloc(p, s)
Definition: Memory.h:32
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
static struct stru_802_11_Phy_Parameters_HT a
void elect_DR(NETSIM_ID d, NETSIM_ID ifid)
Definition: PIM_Neighbor.c:95
time_interval Effective_Propagation_Delay(NETSIM_ID d, NETSIM_ID I)
Definition: PIM_Neighbor.c:133
static void add_neighbor(NETSIM_ID d, ptrPIM_NEIGHBOR neigh)
Definition: PIM_Neighbor.c:40
static bool lan_delay_enabled(NETSIM_ID d, NETSIM_ID I)
Definition: PIM_Neighbor.c:115
static bool dr_is_better(ptrPIM_NEIGHBOR a, ptrPIM_NEIGHBOR b)
Definition: PIM_Neighbor.c:81
bool Suppression_Enabled(NETSIM_ID d, NETSIM_ID I)
Definition: PIM_Neighbor.c:171
static ptrPIM_NEIGHBOR * get_all_neigh_for_interface(NETSIM_ID d, NETSIM_ID ifid, UINT *c)
Definition: PIM_Neighbor.c:57
time_interval Effective_Override_Interval(NETSIM_ID d, NETSIM_ID I)
Definition: PIM_Neighbor.c:152
ptrPIM_NEIGHBOR find_neighbor(NETSIM_ID d, NETSIM_IPAddress ip)
Definition: PIM_Neighbor.c:20
ptrPIM_NEIGHBOR create_and_add_neighbor(NETSIM_ID d, NETSIM_ID ifId, NETSIM_IPAddress address)
Definition: PIM_Neighbor.c:46
#define t_override_default
Definition: PIM_SM.h:37
#define PIM_NEIGHBOR_ADD(l, m)
Definition: PIM_SM.h:180
#define GET_PIM_VAR(d)
Definition: PIM_SM.h:226
#define Propagation_delay_default
Definition: PIM_SM.h:36
#define PIM_NEIGHBOR_ALLOC()
Definition: PIM_SM.h:178
#define time_interval
Definition: PIM_SM.h:35
#define PIM_NEIGHBOR_NEXT(neigh)
Definition: PIM_SM.h:179
#define DEVICE_NWADDRESS(DeviceId, InterfaceId)
Definition: Stack.h:805
char str_ip[_NETSIM_IP_LEN]
Definition: IP_Addressing.h:54
NETSIM_IPAddress neighborAddr
Definition: PIM_SM.h:160
UINT16 propagation_delay
Definition: PIM_SM.h:170
UINT16 override_interval
Definition: PIM_SM.h:171
NETSIM_IPAddress * secondary_address_list
Definition: PIM_SM.h:174
bool dr_priority_present
Definition: PIM_SM.h:164
NETSIM_ID incomingInterface
Definition: PIM_SM.h:161
UINT16 dr_priority
Definition: PIM_SM.h:163
UINT secondary_address_count
Definition: PIM_SM.h:173
NETSIM_IPAddress * DR
Definition: PIM_SM.h:209