20static NETSIM_IPAddress ALL_IN_SUBNET;
21static NETSIM_IPAddress ALL_ROUTER_IN_SUBNET;
22static NETSIM_IPAddress ALL_PIM_ROUTER;
23static NETSIM_IPAddress ALL_SPF_ROUTERS;
24static NETSIM_IPAddress ALL_D_ROUTERS;
26void multicast_join_group()
28 NETSIM_IPAddress ip = pstruEventDetails->szOtherDetails;
30 IP_DEVVAR* dev = GET_IP_DEVVAR(pstruEventDetails->nDeviceId);
31 if (!dev->isIGMPConfigured)
33 fnNetSimError(
"%s is called for device %d without IGMP enable. Please enable IGMP to run multicast\n",
35 pstruEventDetails->nDeviceId);
39 igmp_host_join_group(pstruEventDetails->nDeviceId, ip);
42static bool isOSPFPacket(NetSim_PACKET* packet)
46 ALL_SPF_ROUTERS = STR_TO_IP4(
"224.0.0.5");
47 ALL_D_ROUTERS = STR_TO_IP4(
"224.0.0.6");
50 NETSIM_IPAddress ip = packet->pstruNetworkData->szDestIP;
51 if (!IP_COMPARE(ip, ALL_SPF_ROUTERS))
54 if (!IP_COMPARE(ip, ALL_D_ROUTERS))
60IP_PROTOCOL_ACTION check_ip_in_multicastgroup(NETSIM_IPAddress ip, NETSIM_ID d, NetSim_PACKET* packet)
62 if (isRouter(d) && isOSPFPacket(packet))
65 if (isIGMPPacket(packet))
68 if (isPIMPacket(packet))
77 return ACTION_REROUTE;
80 return host_is_ip_present_in_db(d, ip, packet);
81 else if (isL3Device(d))
82 return ACTION_REROUTE;
87bool is_reserved_multicast_address(NETSIM_IPAddress ip)
89 static bool init =
false;
93 ALL_PIM_ROUTER = STR_TO_IP4(
"224.0.0.13");
94 ALL_IN_SUBNET = STR_TO_IP4(
"224.0.0.1");
95 ALL_ROUTER_IN_SUBNET = STR_TO_IP4(
"224.0.0.2");
96 ALL_SPF_ROUTERS = STR_TO_IP4(
"224.0.0.5");
97 ALL_D_ROUTERS = STR_TO_IP4(
"224.0.0.6");
100 if (!IP_COMPARE(ip, ALL_IN_SUBNET ))
103 if (!IP_COMPARE(ip, ALL_PIM_ROUTER))
106 if (!IP_COMPARE(ip, ALL_ROUTER_IN_SUBNET))
109 if (!IP_COMPARE(ip, ALL_SPF_ROUTERS))
112 if (!IP_COMPARE(ip, ALL_D_ROUTERS))
118IP_ROUTINGTABLE* tab = NULL;
119static bool isCorrectRouteForSubnet(IP_ROUTINGTABLE** table, NETSIM_IPAddress dest, NETSIM_IPAddress src)
122 tab = IPROUTINGTABLE_ALLOC();
124 if (IP_COMPARE((*table)->networkDestination, dest))
127 memcpy(tab, *table,
sizeof* tab);
128 tab->interfaceCount = 0;
132 for (i = 0; i < (*table)->interfaceCount; i++)
134 if (IP_IS_IN_SAME_NETWORK_IPV4(src, (*table)->Interface[i], (*table)->netMask))
136 tab->interfaceCount++;
137 tab->Interface[k] = (*table)->Interface[i];
138 tab->nInterfaceId[k] = (*table)->nInterfaceId[i];
154bool isCorrectRoute(pptrIP_ROUTINGTABLE table, NETSIM_IPAddress dest, NETSIM_IPAddress src)
156 if (!IP_COMPARE(dest, ALL_IN_SUBNET))
157 return isCorrectRouteForSubnet(table, dest, src);
159 if (!IP_COMPARE(dest, ALL_PIM_ROUTER))