NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
OSPF_Area.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 "OSPF_Typedef.h"
16#include "OSPF.h"
17#include "OSPF_List.h"
18#include "OSPF_Interface.h"
19#include "OSPF_Msg.h"
20
21ptrOSPFAREA_DS OSPF_AREA_GET(ptrOSPF_PDS ospf,
22 NETSIM_ID in,
23 OSPFID areaId,
24 NETSIM_IPAddress interfaceIP)
25{
26 UINT i;
27 for (i = 0; i < ospf->areaCount; i++)
28 {
29 if (areaId && !OSPFID_COMPARE(ospf->areaDS[i]->areaId, areaId))
30 return ospf->areaDS[i];
31 UINT j;
32 for (j = 0; j < ospf->areaDS[i]->assocInterfaceCount; j++)
33 {
34 if (in && ospf->areaDS[i]->assocRouterInterfaceId[j] == in)
35 return ospf->areaDS[i];
36 if (interfaceIP && !IP_COMPARE(ospf->areaDS[i]->assocRouterInterface[j], interfaceIP))
37 return ospf->areaDS[i];
38 }
39 }
40 return NULL;
41}
42
43void OSPF_AREA_SET(ptrOSPF_PDS ospf,
44 ptrOSPFAREA_DS area)
45{
46 if (ospf->areaCount)
47 ospf->areaDS = realloc(ospf->areaDS, (ospf->areaCount + 1)*(sizeof* ospf->areaDS));
48 else
49 ospf->areaDS = calloc(1, sizeof* ospf->areaDS);
50 ospf->areaDS[ospf->areaCount] = area;
51 ospf->areaCount++;
52}
53
54static void ADDR_RN_FREE(ptrADDR_RN rn)
55{
56 free(rn);
57}
58
59static void ospf_area_addressRange_init(NETSIM_ID d,
60 ptrOSPFAREA_DS area)
61{
62 area->addressRangeList = ospf_list_init(ADDR_RN_FREE,NULL);
63 NETSIM_ID i;
64 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
65 {
66 ptrADDR_RN rn = calloc(1, sizeof* rn);
67 NetSIm_DEVICEINTERFACE* inter = DEVICE_INTERFACE(d, i + 1);
68 rn->address = IP_NETWORK_ADDRESS(inter->szAddress,
69 inter->szSubnetMask,
70 inter->prefix_len);
71 rn->mask = inter->szSubnetMask;
72 rn->status = ADDRRNSTATUS_ADVERTISE;
73 ospf_list_add_mem(area->addressRangeList, rn);
74 }
75}
76
77static void add_interface_to_area(ptrOSPFAREA_DS area,
78 NETSIM_ID d,
79 NETSIM_ID in)
80{
81 if (area->assocInterfaceCount)
82 {
83 area->assocRouterInterface = realloc(area->assocRouterInterface,
84 (area->assocInterfaceCount + 1)*
85 (sizeof* area->assocRouterInterface));
86
87 area->assocRouterInterfaceId = realloc(area->assocRouterInterfaceId,
88 (area->assocInterfaceCount + 1)*
89 (sizeof* area->assocRouterInterfaceId));
90 }
91 else
92 {
93 area->assocRouterInterface = calloc(1, sizeof* area->assocRouterInterface);
94 area->assocRouterInterfaceId = calloc(1, sizeof* area->assocRouterInterfaceId);
95 }
96 area->assocRouterInterface[area->assocInterfaceCount] = DEVICE_NWADDRESS(d, in);
97 area->assocRouterInterfaceId[area->assocInterfaceCount] = in;
98 area->assocInterfaceCount++;
99}
100
101void ospf_area_init(NETSIM_ID d, NETSIM_ID in)
102{
103 ptrOSPF_PDS pds = OSPF_PDS_GET(d);
104 ptrOSPF_IF ospf = OSPF_IF_GET(pds, in);
105 ptrOSPFAREA_DS area = OSPF_AREA_GET_ID(pds, ospf->areaId);
106 if (area)
107 {
108 add_interface_to_area(area, d, in);
109 return;
110 }
111
112 area = calloc(1, sizeof* area);
113 OSPF_AREA_SET(pds, area);
114 area->areaId = ospf->areaId;
115 add_interface_to_area(area, d, in);
116 ospf_area_addressRange_init(d, area);
117 area->extRoutingCapability = ospf->extRoutingCapability;
118
119 area->nwLSAList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
120 area->routerLSAList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
121 area->routerSummaryLSAList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
122 area->nwSummaryLSAList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
123 area->maxAgeList = ospf_list_init(OSPF_LSA_MSG_FREE, OSPF_LSA_MSG_COPY);
124}
125
126void ospf_area_handleABRTask(ptrOSPF_PDS ospf)
127{
128 ospf;
129 fnNetSimError("Implement %s after area implementation", __FUNCTION__);
130}