NetSim Source Code Help
Loading...
Searching...
No Matches
IGMP_Host.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
21{
22 ptrIGMP_HOST_DB r = GET_IGMP_HOST(d)->database;
23
24 while (r)
25 {
26 if (!IP_COMPARE(r->group, group))
27 return r;
28 r = LIST_NEXT(r);
29 }
30
32 r->group = IP_COPY(group);
34
35 IGMP_HOST_DB_ADD(d, r);
36
37 return r;
38}
39
41{
43}
44
46{
47 ptrIGMP_HOST_DB r = GET_IGMP_HOST(d)->database;
48
49 while (r)
50 {
51 if (!IP_COMPARE(r->group, addr))
52 return r;
53 r = LIST_NEXT(r);
54 }
55 return NULL;
56}
57
59{
61
62 print_igmp_log("\nHost %d, Time 0: joining multicast group %s.",
63 d,
64 "224.0.0.1");
65
67}
68
70{
71 IP_DEVVAR* dip = GET_IP_DEVVAR(d);
72 ptrIGMP_HOST_DB db = dip->isIGMPConfigured ? GET_IGMP_HOST(d)->database : NULL;
73 while (db)
74 {
75 if (!IP_COMPARE(db->group, ip))
76 return ACTION_MOVEUP;
77 db = LIST_NEXT(db);
78 }
79 return ACTION_DROP;
80}
81
83 ptrIGMP_MSG msg,
84 NETSIM_ID d)
85{
86 bool isTimerReqd = false;
88
89 print_igmp_log("\nHost %d, Time %0.0lf: Query received for group address %s.",
90 d,
92 msg->GroupAddress->str_ip);
93
94 if (!db->isReportreqd ||
96 db->queryRecvTime -
97 db->delayTime >=
98 msg->MaxRespTime*0.1*SECOND)
99 isTimerReqd = true;
100
101 db->maxResponseTime = msg->MaxRespTime;
103
104 if (isTimerReqd)
105 {
106 print_igmp_log("Starting Delay timer.");
109 msg->GroupAddress,
111 db->isReportreqd = true;
112 print_igmp_log("Changing host state to delaying member");
114 }
115
116 return false;
117}
118
120{
123 g);
124
125 if (db->isReportreqd)
126 {
127 print_igmp_log("\nHost %d, Time %0.0lf: Sending report for group address %s.",
130 g->str_ip);
131
133 g);
134 db->isReportreqd = false;
135 print_igmp_log("Changing host state to idle member");
137 }
138}
139
141 ptrIGMP_MSG msg,
142 NETSIM_ID d)
143{
145 if (db)
146 {
147 print_igmp_log("\nHost %d, Time %0.0lf: report received for group address %s.",
148 d,
150 msg->GroupAddress->str_ip);
151 print_igmp_log("Report is not required.");
152 db->isReportreqd = false;
153 print_igmp_log("Changing host state to Idle member");
155 }
156 return false;
157}
158
160{
161 if (!isHost(d))
162 fnNetSimError("%s is called for Non-Host device %d.\n", __FUNCTION__, d);
163
164 print_igmp_log("\nHost %d, Time %0.0lf: Joining multicast group %s.",
165 d,
167 group->str_ip);
168 print_igmp_log("Sending membership report.");
169
171
173 db->reportSentCount++;
174 print_igmp_log("Changing host state to delaying member");
176 print_igmp_log("Starting Unsolicited report timer");
179 group,
181}
182
184{
187
189
190 if (db->reportSentCount < 2 && db->isReportreqd)
191 {
192 print_igmp_log("\nHost %d, Time %0.0lf: Unsolicited report timer triggered. Sending membership report.");
194 db->reportSentCount++;
195 print_igmp_log("Changing host state to delaying member");
197 print_igmp_log("Starting Unsolicited report timer");
200 group,
202 }
203}
204
206{
209 while (db)
210 {
211 LIST_FREE(&db, db);
212 }
213 free(h);
214 SET_IGMP_HOST(d, NULL);
215}
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
void print_igmp_log(char *format,...)
Definition: IGMP.c:33
@ HostState_IdleMember
Definition: IGMP.h:87
@ HostState_DelayingMember
Definition: IGMP.h:88
#define IGMP_HOST_DB_ALLOC()
Definition: IGMP.h:102
#define SET_IGMP_HOST(d, var)
Definition: IGMP.h:176
void send_membership_report(NETSIM_ID d, NETSIM_IPAddress group)
Definition: IGMP_Msg.c:152
#define GET_IGMP_HOST(d)
Definition: IGMP.h:174
#define IGMP_HOST_DB_ADD(d, db)
Definition: IGMP.h:103
struct stru_host_database * ptrIGMP_HOST_DB
void host_send_report()
Definition: IGMP_Host.c:119
void igmp_host_join_group(NETSIM_ID d, NETSIM_IPAddress group)
Definition: IGMP_Host.c:159
bool host_process_report(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Host.c:140
static void host_join_multicast_group(NETSIM_ID d, NETSIM_IPAddress group)
Definition: IGMP_Host.c:40
bool host_process_query(NetSim_PACKET *packet, ptrIGMP_MSG msg, NETSIM_ID d)
Definition: IGMP_Host.c:82
void igmp_host_init(NETSIM_ID d)
Definition: IGMP_Host.c:58
void host_free(NETSIM_ID d)
Definition: IGMP_Host.c:205
IP_PROTOCOL_ACTION host_is_ip_present_in_db(NETSIM_ID d, NETSIM_IPAddress ip, NetSim_PACKET *packet)
Definition: IGMP_Host.c:69
ptrIGMP_HOST_DB host_get_multicast_db(NETSIM_ID d, NETSIM_IPAddress addr)
Definition: IGMP_Host.c:45
void host_handle_unsolicited_report_timer()
Definition: IGMP_Host.c:183
static ptrIGMP_HOST_DB find_or_alloc_multicast_db_host(NETSIM_ID d, NETSIM_IPAddress group)
Definition: IGMP_Host.c:20
IP_PROTOCOL_ACTION
Definition: IP.h:138
@ ACTION_DROP
Definition: IP.h:139
@ ACTION_MOVEUP
Definition: IP.h:140
#define GET_IP_DEVVAR(d)
Definition: IP.h:49
@ EVENT_IGMP_DelayTimer
Definition: IP.h:102
@ EVENT_IGMP_Unsolicited_report
Definition: IP.h:98
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define STR_TO_IP4(ipstr)
Definition: IP_Addressing.h:94
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define LIST_NEXT(ls)
Definition: List.h:29
#define LIST_FREE(ls, mem)
Definition: List.h:32
#define free(p)
Definition: Memory.h:31
bool isHost(NETSIM_ID d)
#define SECOND
Definition: Stack.h:60
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
Structure to store the device ip details.
Definition: IP.h:226
bool isIGMPConfigured
Definition: IP.h:270
NETSIM_ID nDeviceId
Definition: Stack.h:750
UINT8 maxResponseTime
Definition: IGMP.h:95
double queryRecvTime
Definition: IGMP.h:96
NETSIM_IPAddress group
Definition: IGMP.h:93
double delayTime
Definition: IGMP.h:97
bool isReportreqd
Definition: IGMP.h:98
UINT reportSentCount
Definition: IGMP.h:99
IGMP_HOST_STATE state
Definition: IGMP.h:94
ptrIGMP_HOST_DB database
Definition: IGMP.h:107
UINT8 MaxRespTime
Definition: IGMP.h:78
NETSIM_IPAddress GroupAddress
Definition: IGMP.h:80
char str_ip[_NETSIM_IP_LEN]
Definition: IP_Addressing.h:54