NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
PIM_Group.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
15#include "main.h"
16#include "List.h"
17#include "IP.h"
18#include "PIM_SM.h"
19
20ptrPIM_GROUP pim_find_group(NETSIM_ID d, NETSIM_IPAddress addr)
21{
22 ptrPIM_GROUP gr = GET_PIM_VAR(d)->groupList;
23 while (gr)
24 {
25 if (!IP_COMPARE(gr->groupAddress, addr))
26 return gr;
27 PIM_GROUP_NEXT(gr);
28 }
29 return NULL;
30}
31
32ptrPIM_GROUP create_group(NETSIM_ID d, NETSIM_IPAddress addr, NETSIM_IPAddress RP)
33{
34 ptrPIM_VAR pim = GET_PIM_VAR(d);
35 ptrPIM_GROUP gr = PIM_GROUP_ALLOC();
36 NETSIM_ID in;
37 pim->groupCount++;
38 gr->groupId = pim->groupCount;
39 gr->groupAddress = IP_COPY(addr);
40 gr->RP = IP_COPY(RP);
41 gr->RPId = fn_NetSim_Stack_GetDeviceId_asIP(RP,&in);
42 PIM_GROUP_ADD(&pim->groupList, gr);
43 return gr;
44}
45
46
47static bool is_if_already_presen(ptrPIM_GROUP g, NETSIM_ID i)
48{
49 UINT c;
50 for (c = 0; c < g->count; c++)
51 if (g->ifid[c] == i)
52 return true;
53 return false;
54}
55
56void pim_add_interface_to_group(NETSIM_ID d, NETSIM_ID i, ptrPIM_GROUP g)
57{
58 if (is_if_already_presen(g, i))
59 return; //Already present
60
61 if (g->count)
62 g->ifid = realloc(g->ifid, (g->count + 1) * sizeof* g->ifid);
63 else
64 g->ifid = calloc(1, sizeof* g->ifid);
65
66 g->ifid[g->count] = i;
67 g->count++;
68}
69