NetSim Source Code Help
Loading...
Searching...
No Matches
IGMP.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
20static FILE* igmp_log = NULL;
21static void init_igmp_log()
22{
23 char str[BUFSIZ];
24 sprintf(str, "%s/%s", pszIOPath, "igmp_log.txt");
25 igmp_log = fopen(str, "w");
26}
27
28static void close_igmp_log()
29{
30 fclose(igmp_log);
31}
32
33void print_igmp_log(char* format, ...)
34{
35 va_list l;
36 va_start(l, format);
37 vfprintf(igmp_log, format, l);
38 fprintf(igmp_log, "\n");
39 fflush(igmp_log);
40}
41
42//IGMP Device
43void igmp_configure(NETSIM_ID d, void* xmlNode)
44{
46 ptrIGMP_HOST host;
47 ptrIGMP_ROUTER router;
48 if (!var)
49 {
50 var = calloc(1, sizeof* var);
51 SET_IGMP_VAR(d, var);
52 }
53
54 if (isHost(d))
55 {
56 var->devType = IP_HOST;
57 host = GET_IGMP_HOST(d);
58 if (!host)
59 {
60 host = (ptrIGMP_HOST)calloc(1, sizeof* host);
61 SET_IGMP_HOST(d, host);
62 }
63 }
64 else if (isRouter(d))
65 {
66 var->devType = IP_ROUTER;
67 router = GET_IGMP_ROUTER(d);
68 if (!router)
69 {
70 router = (ptrIGMP_ROUTER)calloc(1, sizeof* router);
71 SET_IGMP_ROUTER(d, router);
72 }
73 }
74 else
75 fnNetSimError("IGMP is only for either host or router");
76
77 getXmlVar(&var->RobustnessVar, ROBUSTNESS_VARIABLE, xmlNode, 1, _UINT, IGMP);
78 getXmlVar(&var->QueryInterval, QUERY_INTERVAL, xmlNode, 1, _UINT, IGMP);
79 getXmlVar(&var->lastMemQueryInterval, LAST_MEMBER_QUERY_INTERVAL, xmlNode, 1, _DOUBLE, IGMP);
80
81 if (isIPHOST(d))
82 {
83 getXmlVar(&var->UnsolicitedReportInterval, UNSOLICITED_REPORT_INTERVAL, xmlNode, 1, _DOUBLE, IGMP);
85 }
86
87 if (isIPRouter(d))
88 {
89 getXmlVar(&var->QueryResponseInterval, QUERY_RESPONSE_INTERVAL, xmlNode, 1, _UINT, IGMP);
90 }
91}
92
94 IP_SUBEVENT sev,
96{
97 ptrIGMP_VAR igmp = GET_IGMP_VAR(d);
98 switch (sev)
99 {
101 return igmp->StartupQueryInterval*0.1*SECOND;
103 return igmp->QueryInterval*0.1*SECOND;
107 return igmp->QueryPresentInterval*0.1*SECOND;
109 {
111 double t = db->maxResponseTime*0.1*SECOND*NETSIM_RAND_01();
112 db->delayTime = t;
113 return t;
114 }
116 return igmp->GroupMembershipInterval*0.1*SECOND;
117 default:
118 fnNetSimError("Unknown subevnet %d\n", sev);
119 return 0;
120 }
121}
122
124 IP_SUBEVENT sev,
125 NETSIM_IPAddress addr,
126 double time)
127{
128 NetSim_EVENTDETAILS pevent;
129 memset(&pevent, 0, sizeof pevent);
130
131 pevent.dEventTime = time + get_subevent_delay(d, sev, addr);
132 pevent.nDeviceId = d;
133 pevent.nDeviceType = DEVICE_TYPE(d);
134 pevent.nEventType = TIMER_EVENT;
136 pevent.nSubEventType = sev;
137 pevent.szOtherDetails = addr;
138 fnpAddEvent(&pevent);
139}
140
142{
143 if(!igmp_log)
145
146 if (isIPRouter(d))
148 else if (isIPHOST(d))
150 else
151 fnNetSimError("Device %d is neither host nor router\n", d);
152
153 ptrIGMP_VAR var = GET_IGMP_VAR(d);
154
157
159 var->QueryInterval + var->QueryResponseInterval / 2;
160
162}
163
165{
167 if (!v)
168 return; //IGMP is not configured
169
170 if (isIPHOST(d))
171 host_free(d);
172 else if (isIPRouter(d))
173 router_free(d);
174
175 free(v);
176 SET_IGMP_VAR(d, NULL);
177}
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
static double get_subevent_delay(NETSIM_ID d, IP_SUBEVENT sev, NETSIM_IPAddress group)
Definition: IGMP.c:93
static FILE * igmp_log
Definition: IGMP.c:20
static void init_igmp_log()
Definition: IGMP.c:21
void igmp_configure(NETSIM_ID d, void *xmlNode)
Definition: IGMP.c:43
void print_igmp_log(char *format,...)
Definition: IGMP.c:33
void igmp_free(NETSIM_ID d)
Definition: IGMP.c:164
void igmp_init(NETSIM_ID d)
Definition: IGMP.c:141
static void close_igmp_log()
Definition: IGMP.c:28
#define SET_IGMP_HOST(d, var)
Definition: IGMP.h:176
#define isIPRouter(d)
Definition: IGMP.h:173
@ IP_HOST
Definition: IGMP.h:53
@ IP_ROUTER
Definition: IGMP.h:54
void router_free(NETSIM_ID d)
Definition: IGMP_Router.c:341
struct stru_igmp_router * ptrIGMP_ROUTER
void igmp_host_init(NETSIM_ID d)
Definition: IGMP_Host.c:58
#define GET_IGMP_HOST(d)
Definition: IGMP.h:174
#define GET_IGMP_ROUTER(d)
Definition: IGMP.h:175
void igmp_router_init(NETSIM_ID d)
Definition: IGMP_Router.c:158
void host_free(NETSIM_ID d)
Definition: IGMP_Host.c:205
#define SET_IGMP_VAR(d, var)
Definition: IGMP.h:171
#define GET_IGMP_VAR(d)
Definition: IGMP.h:170
#define SET_IGMP_ROUTER(d, var)
Definition: IGMP.h:177
ptrIGMP_HOST_DB host_get_multicast_db(NETSIM_ID d, NETSIM_IPAddress addr)
Definition: IGMP_Host.c:45
#define isIPHOST(d)
Definition: IGMP.h:172
struct stru_igmp_host * ptrIGMP_HOST
IP_SUBEVENT
Enumeration for ip sub-events.
Definition: IP.h:92
@ EVENT_IGMP_SendQuery
Definition: IP.h:100
@ EVENT_IGMP_OtherQuerierPresentTimer
Definition: IP.h:101
@ EVENT_IGMP_DelayTimer
Definition: IP.h:102
@ EVENT_IGMP_SendStartupQuery
Definition: IP.h:99
@ EVENT_IGMP_GroupMembershipTimer
Definition: IP.h:103
@ EVENT_IGMP_Unsolicited_report
Definition: IP.h:98
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
EXPORTED char * pszIOPath
Definition: Stack.h:842
#define getXmlVar(var, name, xmlNode, flag, type, protocol)
Definition: Stack.h:1046
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ _UINT
Definition: Stack.h:1037
@ _DOUBLE
Definition: Stack.h:1031
@ NW_PROTOCOL_IPV4
Definition: Stack.h:189
bool isHost(NETSIM_ID d)
#define SECOND
Definition: Stack.h:60
@ TIMER_EVENT
Definition: Stack.h:114
#define NETSIM_RAND_01()
Definition: Stack.h:860
bool isRouter(NETSIM_ID d)
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
UINT8 maxResponseTime
Definition: IGMP.h:95
double delayTime
Definition: IGMP.h:97
DEV_TYPE devType
Definition: IGMP.h:145
double GroupMembershipInterval
Definition: IGMP.h:163
UINT RobustnessVar
Definition: IGMP.h:162
UINT QueryResponseInterval
Definition: IGMP.h:156
UINT lastMemQueryCount
Definition: IGMP.h:166
UINT QueryPresentInterval
Definition: IGMP.h:164
double UnsolicitedReportInterval
Definition: IGMP.h:153
UINT StartupQueryInterval
Definition: IGMP.h:157
UINT QueryInterval
Definition: IGMP.h:161
double lastMemQueryInterval
Definition: IGMP.h:165