15#include "OSPF_Typedef.h"
18#include "OSPF_Interface.h"
21ptrOSPFAREA_DS OSPF_AREA_GET(ptrOSPF_PDS ospf,
24 NETSIM_IPAddress interfaceIP)
27 for (i = 0; i < ospf->areaCount; i++)
29 if (areaId && !OSPFID_COMPARE(ospf->areaDS[i]->areaId, areaId))
30 return ospf->areaDS[i];
32 for (j = 0; j < ospf->areaDS[i]->assocInterfaceCount; j++)
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];
43void OSPF_AREA_SET(ptrOSPF_PDS ospf,
47 ospf->areaDS = realloc(ospf->areaDS, (ospf->areaCount + 1)*(
sizeof* ospf->areaDS));
49 ospf->areaDS = calloc(1,
sizeof* ospf->areaDS);
50 ospf->areaDS[ospf->areaCount] = area;
54static void ADDR_RN_FREE(ptrADDR_RN rn)
59static void ospf_area_addressRange_init(NETSIM_ID d,
62 area->addressRangeList = ospf_list_init(ADDR_RN_FREE,NULL);
64 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
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,
71 rn->mask = inter->szSubnetMask;
72 rn->status = ADDRRNSTATUS_ADVERTISE;
73 ospf_list_add_mem(area->addressRangeList, rn);
77static void add_interface_to_area(ptrOSPFAREA_DS area,
81 if (area->assocInterfaceCount)
83 area->assocRouterInterface = realloc(area->assocRouterInterface,
84 (area->assocInterfaceCount + 1)*
85 (
sizeof* area->assocRouterInterface));
87 area->assocRouterInterfaceId = realloc(area->assocRouterInterfaceId,
88 (area->assocInterfaceCount + 1)*
89 (
sizeof* area->assocRouterInterfaceId));
93 area->assocRouterInterface = calloc(1,
sizeof* area->assocRouterInterface);
94 area->assocRouterInterfaceId = calloc(1,
sizeof* area->assocRouterInterfaceId);
96 area->assocRouterInterface[area->assocInterfaceCount] = DEVICE_NWADDRESS(d, in);
97 area->assocRouterInterfaceId[area->assocInterfaceCount] = in;
98 area->assocInterfaceCount++;
101void ospf_area_init(NETSIM_ID d, NETSIM_ID in)
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);
108 add_interface_to_area(area, d, in);
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;
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);
126void ospf_area_handleABRTask(ptrOSPF_PDS ospf)
129 fnNetSimError(
"Implement %s after area implementation", __FUNCTION__);