NetSim Source Code Help
Loading...
Searching...
No Matches
IGMP_Msg.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 "IGMP.h"
19
20
22{
24}
25
26static void set_IGMP_MSG(NetSim_PACKET* packet, ptrIGMP_MSG msg)
27{
29}
30
32{
33 switch (type)
34 {
36 strcpy(stype, "IGMP_LEAVE_GROUP");
37 return PACKET_IGMP_LEAVE;
38
40 strcpy(stype, "IGMP_V2_Membership_Report");
41 return PACKET_IGMP_REPORT;
42
44 strcpy(stype, "IGMP_Membership_Query");
45 return PACKET_IGMP_QUERY;
46
47 default:
48 fnNetSimError("Unknown igmp msg type %d\n", type);
49 return 0;
50 }
51}
52
54 UINT8 maxRespTime,
56{
57 ptrIGMP_MSG msg = (ptrIGMP_MSG)calloc(1, sizeof* msg);
59 msg->Type = type;
60 msg->MaxRespTime = maxRespTime;
61
62 return msg;
63}
64
65static void free_igmp_hdr(ptrIGMP_MSG msg)
66{
67 free(msg);
68}
69
71{
72 ptrIGMP_MSG ret = (ptrIGMP_MSG)calloc(1, sizeof* msg);
73 memcpy(ret, msg, sizeof* ret);
74 return ret;
75}
76
78{
80}
82{
85 packet->pstruNetworkData->IPProtocol = 0;
86}
87
89{
90 return (UINT8)(T);
91}
92
94 NETSIM_ID ifId,
95 NETSIM_ID dest,
96 IGMPMSG_TYPE type,
98 UINT maxRespTime,
99 UINT8 ttl)
100{
101 UINT8 RespTime = make_resp_time(maxRespTime);
102 ptrIGMP_MSG msg = create_igmp_hdr(type,
103 RespTime,
104 group);
105
107
108 set_IGMP_MSG(packet, msg);
109
114 packet->nQOS = QOS_BE;
115 packet->nReceiverId = 0;
116 packet->nSourceId = src;
117 packet->nTransmitterId = src;
118 add_dest_to_packet(packet, dest);
119 packet->pstruNetworkData->nTTL = ttl;
127
128 packet->pstruNetworkData->szSourceIP = DEVICE_NWADDRESS(src, ifId);
131
132 return packet;
133}
134
136 double time,
137 NetSim_PACKET* packet)
138{
139 NetSim_EVENTDETAILS pevent;
140 memset(&pevent, 0, sizeof pevent);
141 pevent.dEventTime = time;
142 pevent.dPacketSize = packet->pstruNetworkData->dPacketSize;
143 pevent.nDeviceId = d;
144 pevent.nDeviceType = DEVICE_TYPE(d);
146 pevent.nPacketId = packet->nPacketId;
148 pevent.pPacket = packet;
149 fnpAddEvent(&pevent);
150}
151
153{
155 1,
156 0,
158 group,
159 0,
160 1);
161
163}
164
166 ptrIGMP_MSG msg,
167 NETSIM_ID d)
168{
169 if (isHost(d))
170 {
171 return host_process_report(packet, msg, d);
172 }
173
174 else if (isRouter(d))
175 {
176 return router_process_report(packet, msg, d);
177 }
178 return false;
179}
180
182 ptrIGMP_MSG msg,
183 NETSIM_ID d)
184{
185 if (isIPRouter(d))
186 return router_process_query(packet, msg, d);
187 else if (isIPHOST(d))
188 return host_process_query(packet, msg, d);
189 else
190 fnNetSimError("Device %d is neither host nor router", d);
191
192 return true;
193}
194
196{
197 bool isContinue = true;
200 ptrIGMP_MSG msg = get_IGMP_MSG(packet);
201
202 ptrIGMP_VAR igmp = GET_IGMP_VAR(d);
203 if (!igmp)
204 {
205 //IGMP is not configured
208 return;
209 }
210
211 switch (msg->Type)
212 {
214 isContinue = igmp_process_query(packet, msg, d);
215 break;
217 isContinue = igmp_process_report(packet, msg, d);
218 break;
219 default:
220 fnNetSimError("Unknown IGMP packet %d in %s.\n",
221 msg->Type,
222 __FUNCTION__);
223 break;
224 }
225
226 if (!isContinue)
227 {
230 }
231}
232
234{
235 bool isStartup = true;
236 ptrIGMP_VAR var = GET_IGMP_VAR(d);
239 group);
240
241 if (db->sentCount >= var->RobustnessVar)
242 isStartup = false;
243
244 if (db->state == RouterState_NonQuerier)
245 return;
246
247 NETSIM_ID i;
248 for (i = 0; i < DEVICE(d)->nNumOfInterface; i++)
249 {
250 if (!isBroadcastInterface(d, i + 1))
251 continue;
253 i+1,
254 0,
256 group,
258 1);
259 send_igmp_packet(d, time, packet);
260 }
261
262 db->sentCount++;
263
266 group,
267 time);
268}
unsigned int NETSIM_ID
Definition: Animation.h:45
GROUP_MOBILITY * group
Definition: GroupMobility.c:30
void igmp_start_timer(NETSIM_ID d, IP_SUBEVENT sev, NETSIM_IPAddress addr, double time)
Definition: IGMP.c:123
bool router_process_report(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Router.c:274
@ RouterState_NonQuerier
Definition: IGMP.h:113
ptrIGMP_ROUTER_DB router_get_multicast_db(NETSIM_ID d, NETSIM_IPAddress ip)
Definition: IGMP_Router.c:59
#define isIPRouter(d)
Definition: IGMP.h:173
#define IGMP_HDR_SIZE
Definition: IGMP.h:82
bool router_process_query(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Router.c:200
bool host_process_report(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Host.c:140
bool host_process_query(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Host.c:82
#define isBroadcastInterface(d, i)
Definition: IGMP.h:49
#define GET_IGMP_ROUTER(d)
Definition: IGMP.h:175
struct stru_igmp_msg * ptrIGMP_MSG
#define GET_IGMP_VAR(d)
Definition: IGMP.h:170
IGMPMSG_TYPE
Definition: IGMP.h:58
@ IGMPMSG_MembershipQuery
Definition: IGMP.h:59
@ IGMPMSG_LeaveGroup
Definition: IGMP.h:61
@ IGMPMSG_V2MembershipReport
Definition: IGMP.h:60
#define isIPHOST(d)
Definition: IGMP.h:172
static UINT8 make_resp_time(UINT T)
Definition: IGMP_Msg.c:88
static void set_IGMP_MSG(NetSim_PACKET *packet, ptrIGMP_MSG msg)
Definition: IGMP_Msg.c:26
bool igmp_process_query(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Msg.c:181
static ptrIGMP_MSG get_IGMP_MSG(NetSim_PACKET *packet)
Definition: IGMP_Msg.c:21
void send_membership_report(NETSIM_ID d, NETSIM_IPAddress group)
Definition: IGMP_Msg.c:152
void IGMP_FreePacket(NetSim_PACKET *packet)
Definition: IGMP_Msg.c:81
void process_igmp_packet()
Definition: IGMP_Msg.c:195
void send_query_msg(NETSIM_ID d, NETSIM_IPAddress group, double time)
Definition: IGMP_Msg.c:233
static void send_igmp_packet(NETSIM_ID d, double time, NetSim_PACKET *packet)
Definition: IGMP_Msg.c:135
static void free_igmp_hdr(ptrIGMP_MSG msg)
Definition: IGMP_Msg.c:65
static ptrIGMP_MSG copy_igmp_hdr(ptrIGMP_MSG msg)
Definition: IGMP_Msg.c:70
void copy_igmp_packet(NetSim_PACKET *d, NetSim_PACKET *s)
Definition: IGMP_Msg.c:77
static int get_ctrlpackettype_basedon_igmptype(IGMPMSG_TYPE type, char *stype)
Definition: IGMP_Msg.c:31
static NetSim_PACKET * create_igmp_packet(NETSIM_ID src, NETSIM_ID ifId, NETSIM_ID dest, IGMPMSG_TYPE type, NETSIM_IPAddress group, UINT maxRespTime, UINT8 ttl)
Definition: IGMP_Msg.c:93
static bool igmp_process_report(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Msg.c:165
static ptrIGMP_MSG create_igmp_hdr(IGMPMSG_TYPE type, UINT8 maxRespTime, NETSIM_IPAddress group)
Definition: IGMP_Msg.c:53
@ EVENT_IGMP_SendQuery
Definition: IP.h:100
@ EVENT_IGMP_SendStartupQuery
Definition: IP.h:99
@ PACKET_IGMP_LEAVE
Definition: IP.h:75
@ PACKET_IGMP_QUERY
Definition: IP.h:73
@ PACKET_IGMP_REPORT
Definition: IP.h:74
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define UINT8
Definition: Linux.h:31
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
@ QOS_BE
Definition: Packet.h:92
@ PacketType_Control
Definition: Packet.h:66
@ IPPROTOCOL_IGMP
Definition: Packet.h:128
void add_dest_to_packet(NetSim_PACKET *packet, NETSIM_ID dest)
@ Priority_Low
Definition: Packet.h:79
#define DEVICE(DeviceId)
Definition: Stack.h:769
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
#define DEVICE_NWADDRESS(DeviceId, InterfaceId)
Definition: Stack.h:805
@ NW_PROTOCOL_IPV4
Definition: Stack.h:189
bool isHost(NETSIM_ID d)
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
@ NETWORK_LAYER
Definition: Stack.h:96
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
bool isRouter(NETSIM_ID d)
#define fn_NetSim_Packet_CreatePacket(layer)
Definition: main.h:186
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
IP_PROTOCOL_NUMBER IPProtocol
Definition: Packet.h:203
NETWORK_LAYER_PROTOCOL nNetworkProtocol
Definition: Packet.h:204
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
NETSIM_IPAddress szSourceIP
Definition: Packet.h:198
long long int nPacketId
Definition: Packet.h:256
char szPacketType[MAX_PACKET_TYPE_LEN]
Definition: Packet.h:271
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
double dEventTime
Definition: Packet.h:262
NETSIM_ID nReceiverId
Definition: Packet.h:266
unsigned int nControlDataType
Definition: Packet.h:258
NETSIM_ID nTransmitterId
Definition: Packet.h:265
QUALITY_OF_SERVICE nQOS
Definition: Packet.h:261
PACKET_TYPE nPacketType
Definition: Packet.h:257
PACKET_PRIORITY nPacketPriority
Definition: Packet.h:260
NETSIM_ID nSourceId
Definition: Packet.h:263
IGMPMSG_TYPE Type
Definition: IGMP.h:77
UINT8 MaxRespTime
Definition: IGMP.h:78
NETSIM_IPAddress GroupAddress
Definition: IGMP.h:80
UINT RobustnessVar
Definition: IGMP.h:162
UINT QueryResponseInterval
Definition: IGMP.h:156
IGMP_ROUTER_STATE state
Definition: IGMP.h:119