blob: d101d60bbb36174b303eec270fceff41c091cd5d [file] [log] [blame]
Shubham Sharma47f2caf2020-02-18 12:13:40 +00001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.opencord.igmpproxy;
17
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030018import org.slf4j.Logger;
19
Shubham Sharma47f2caf2020-02-18 12:13:40 +000020import java.util.concurrent.atomic.AtomicLong;
21
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030022import static org.slf4j.LoggerFactory.getLogger;
23
Shubham Sharma47f2caf2020-02-18 12:13:40 +000024/**
Shubham Sharma47f2caf2020-02-18 12:13:40 +000025 * Records metrics for IgmpProxy application.
Shubham Sharma47f2caf2020-02-18 12:13:40 +000026 */
27public class IgmpStatistics {
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030028 private final Logger log = getLogger(getClass());
29 private static final long RESET_VALUE = 0L;
Shubham Sharma47f2caf2020-02-18 12:13:40 +000030
31 //Total number of join requests
32 private AtomicLong igmpJoinReq = new AtomicLong();
33 //Total number of successful join and rejoin requests
34 private AtomicLong igmpSuccessJoinRejoinReq = new AtomicLong();
35 //Total number of failed join requests
36 private AtomicLong igmpFailJoinReq = new AtomicLong();
37 //Total number of leaves requests
38 private AtomicLong igmpLeaveReq = new AtomicLong();
39 // Total number of disconnects
40 private AtomicLong igmpDisconnect = new AtomicLong();
41 //Count of Total number of IGMPV3_MEMBERSHIP_QUERY
42 private AtomicLong igmpv3MembershipQuery = new AtomicLong();
43 //Count of IGMPV1_MEMBERSHIP_REPORT
44 private AtomicLong igmpv1MembershipReport = new AtomicLong();
45 //Count of IGMPV3_MEMBERSHIP_REPORT
46 private AtomicLong igmpv3MembershipReport = new AtomicLong();
47 //Count of IGMPV2_MEMBERSHIP_REPORT
48 private AtomicLong igmpv2MembershipReport = new AtomicLong();
49 //Count of TYPE_IGMPV2_LEAVE_GROUP
50 private AtomicLong igmpv2LeaveGroup = new AtomicLong();
51 //Total number of messages received.
52 private AtomicLong totalMsgReceived = new AtomicLong();
53 //Total number of IGMP messages received
54 private AtomicLong igmpMsgReceived = new AtomicLong();
55 //Total number of invalid IGMP messages received
56 private AtomicLong invalidIgmpMsgReceived = new AtomicLong();
Sonal Kasliwalf11c0672020-03-18 11:11:50 +000057 //Counter for unknown igmp type
58 private AtomicLong unknownIgmpTypePacketsRxCounter = new AtomicLong();
59 // Counter for igmp report with wrong mode.
60 private AtomicLong reportsRxWithWrongModeCounter = new AtomicLong();
61 // Counter for failed join due to insufficient permission access
62 private AtomicLong failJoinReqInsuffPermissionAccessCounter = new AtomicLong();
63 // Counter for invalid group ip address i.e not a valid multicast address.
64 private AtomicLong failJoinReqUnknownMulticastIpCounter = new AtomicLong();
65 // Counter for unconfigured group
66 private AtomicLong unconfiguredGroupCounter = new AtomicLong();
67 // Counter for valid igmp packet
68 private AtomicLong validIgmpPacketCounter = new AtomicLong();
69 // Counter for current number of igmp channel joins
70 private AtomicLong igmpChannelJoinCounter = new AtomicLong();
71 // Counter for current group number
72 private AtomicLong currentGrpNumCounter = new AtomicLong();
73 // Counter for igmp Checksum
74 private AtomicLong igmpValidChecksumCounter = new AtomicLong();
75 // Counter for Invalid Igmp Length
76 private AtomicLong invalidIgmpLength = new AtomicLong();
77 //Total number of general IGMP membership query messages received
78 private AtomicLong igmpGeneralMembershipQuery = new AtomicLong();
79 //Total number of group specific IGMP membership query messages received
80 private AtomicLong igmpGrpSpecificMembershipQuery = new AtomicLong();
81 //Total number of group and source specific IGMP membership query messages received
82 private AtomicLong igmpGrpAndSrcSpecificMembershipQuery = new AtomicLong();
Shubham Sharma47f2caf2020-02-18 12:13:40 +000083
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030084 public void setStats(IgmpStatistics current) {
85 igmpJoinReq.set(current.igmpJoinReq.get());
86 igmpSuccessJoinRejoinReq.set(current.igmpSuccessJoinRejoinReq.get());
87 igmpFailJoinReq.set(current.igmpFailJoinReq.get());
88 igmpLeaveReq.set(current.igmpLeaveReq.get());
89 igmpDisconnect.set(current.igmpDisconnect.get());
90 igmpv3MembershipQuery.set(current.igmpv3MembershipQuery.get());
91 igmpv1MembershipReport.set(current.igmpv1MembershipReport.get());
92 igmpv3MembershipReport.set(current.igmpv3MembershipReport.get());
93 igmpv2MembershipReport.set(current.igmpv2MembershipReport.get());
94 igmpv2LeaveGroup.set(current.igmpv2LeaveGroup.get());
95 totalMsgReceived.set(current.totalMsgReceived.get());
96 igmpMsgReceived.set(current.igmpMsgReceived.get());
97 invalidIgmpMsgReceived.set(current.invalidIgmpMsgReceived.get());
98 unknownIgmpTypePacketsRxCounter.set(current.unknownIgmpTypePacketsRxCounter.get());
99 reportsRxWithWrongModeCounter.set(current.reportsRxWithWrongModeCounter.get());
100 failJoinReqInsuffPermissionAccessCounter.set(current.failJoinReqInsuffPermissionAccessCounter.get());
101 failJoinReqUnknownMulticastIpCounter.set(current.failJoinReqUnknownMulticastIpCounter.get());
102 unconfiguredGroupCounter.set(current.unconfiguredGroupCounter.get());
103 validIgmpPacketCounter.set(current.validIgmpPacketCounter.get());
104 igmpChannelJoinCounter.set(current.igmpChannelJoinCounter.get());
105 currentGrpNumCounter.set(current.currentGrpNumCounter.get());
106 igmpValidChecksumCounter.set(current.igmpValidChecksumCounter.get());
107 invalidIgmpLength.set(current.invalidIgmpLength.get());
108 igmpGeneralMembershipQuery.set(current.igmpGeneralMembershipQuery.get());
109 igmpGrpSpecificMembershipQuery.set(current.igmpGrpSpecificMembershipQuery.get());
110 igmpGrpAndSrcSpecificMembershipQuery.set(current.igmpGrpAndSrcSpecificMembershipQuery.get());
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000111 }
112
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +0300113 public void resetAll() {
114 igmpJoinReq.set(RESET_VALUE);
115 igmpLeaveReq.set(RESET_VALUE);
116 igmpDisconnect.set(RESET_VALUE);
117 totalMsgReceived.set(RESET_VALUE);
118 igmpv2LeaveGroup.set(RESET_VALUE);
119 invalidIgmpLength.set(RESET_VALUE);
120 igmpv3MembershipQuery.set(RESET_VALUE);
121 igmpChannelJoinCounter.set(RESET_VALUE);
122 igmpv1MembershipReport.set(RESET_VALUE);
123 igmpv2MembershipReport.set(RESET_VALUE);
124 igmpv3MembershipReport.set(RESET_VALUE);
125 invalidIgmpMsgReceived.set(RESET_VALUE);
126 validIgmpPacketCounter.set(RESET_VALUE);
127 currentGrpNumCounter.set(RESET_VALUE);
128 igmpFailJoinReq.set(RESET_VALUE);
129 unconfiguredGroupCounter.set(RESET_VALUE);
130 igmpValidChecksumCounter.set(RESET_VALUE);
131 igmpGeneralMembershipQuery.set(RESET_VALUE);
132 igmpSuccessJoinRejoinReq.set(RESET_VALUE);
133 igmpGrpSpecificMembershipQuery.set(RESET_VALUE);
134 reportsRxWithWrongModeCounter.set(RESET_VALUE);
135 unknownIgmpTypePacketsRxCounter.set(RESET_VALUE);
136 failJoinReqUnknownMulticastIpCounter.set(RESET_VALUE);
137 igmpGrpAndSrcSpecificMembershipQuery.set(RESET_VALUE);
138 failJoinReqInsuffPermissionAccessCounter.set(RESET_VALUE);
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000139 }
140
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +0300141 public void increaseStat(IgmpStatisticType type) {
142 switch (type) {
143 case IGMP_JOIN_REQ:
144 igmpJoinReq.incrementAndGet();
145 break;
146 case IGMP_LEAVE_REQ:
147 igmpLeaveReq.incrementAndGet();
148 break;
149 case IGMP_DISCONNECT:
150 igmpDisconnect.incrementAndGet();
151 break;
152 case IGMP_MSG_RECEIVED:
153 break;
154 case TOTAL_MSG_RECEIVED:
155 totalMsgReceived.incrementAndGet();
156 break;
157 case IGMP_V2_LEAVE_GROUP:
158 igmpv2LeaveGroup.incrementAndGet();
159 igmpMsgReceived.incrementAndGet();
160 break;
161 case INVALID_IGMP_LENGTH:
162 invalidIgmpLength.incrementAndGet();
163 break;
164 case IGMP_V3_MEMBERSHIP_QUERY:
165 igmpv3MembershipQuery.incrementAndGet();
166 igmpMsgReceived.incrementAndGet();
167 break;
168 case IGMP_CHANNEL_JOIN_COUNTER:
169 igmpChannelJoinCounter.incrementAndGet();
170 break;
171 case IGMP_V1_MEMBERSHIP_REPORT:
172 igmpv1MembershipReport.incrementAndGet();
173 igmpMsgReceived.incrementAndGet();
174 break;
175 case IGMP_V2_MEMBERSHIP_REPORT:
176 igmpv2MembershipReport.incrementAndGet();
177 igmpMsgReceived.incrementAndGet();
178 break;
179 case IGMP_V3_MEMBERSHIP_REPORT:
180 igmpv3MembershipReport.incrementAndGet();
181 igmpMsgReceived.incrementAndGet();
182 break;
183 case INVALID_IGMP_MSG_RECEIVED:
184 invalidIgmpMsgReceived.incrementAndGet();
185 break;
186 case VALID_IGMP_PACKET_COUNTER:
187 validIgmpPacketCounter.incrementAndGet();
188 break;
189 case CURRENT_GRP_NUMBER_COUNTER:
190 currentGrpNumCounter.incrementAndGet();
191 break;
192 case IGMP_FAIL_JOIN_REQ:
193 igmpFailJoinReq.incrementAndGet();
194 break;
195 case UNCONFIGURED_GROUP_COUNTER:
196 unconfiguredGroupCounter.incrementAndGet();
197 break;
198 case IGMP_VALID_CHECKSUM_COUNTER:
199 igmpValidChecksumCounter.incrementAndGet();
200 break;
201 case IGMP_GENERAL_MEMBERSHIP_QUERY:
202 igmpGeneralMembershipQuery.incrementAndGet();
203 break;
204 case IGMP_SUCCESS_JOIN_RE_JOIN_REQ:
205 igmpSuccessJoinRejoinReq.incrementAndGet();
206 break;
207 case IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY:
208 igmpGrpSpecificMembershipQuery.incrementAndGet();
209 break;
210 case REPORTS_RX_WITH_WRONG_MODE_COUNTER:
211 reportsRxWithWrongModeCounter.incrementAndGet();
212 break;
213 case UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER:
214 unknownIgmpTypePacketsRxCounter.incrementAndGet();
215 break;
216 case FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER:
217 failJoinReqUnknownMulticastIpCounter.incrementAndGet();
218 break;
219 case IGMP_GRP_AND_SRC_SPESIFIC_MEMBERSHIP_QUERY:
220 igmpGrpAndSrcSpecificMembershipQuery.incrementAndGet();
221 break;
222 case FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER:
223 failJoinReqInsuffPermissionAccessCounter.incrementAndGet();
224 break;
225 default:
226 log.warn("Unhandled statistic type. {}", type);
227 break;
228 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000229 }
230
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +0300231 public Long getStat(IgmpStatisticType type) {
232 Long value;
233 switch (type) {
234 case IGMP_JOIN_REQ:
235 value = igmpJoinReq.get();
236 break;
237 case IGMP_LEAVE_REQ:
238 value = igmpLeaveReq.get();
239 break;
240 case IGMP_DISCONNECT:
241 value = igmpDisconnect.get();
242 break;
243 case IGMP_MSG_RECEIVED:
244 value = igmpMsgReceived.get();
245 break;
246 case TOTAL_MSG_RECEIVED:
247 value = totalMsgReceived.get();
248 break;
249 case IGMP_V2_LEAVE_GROUP:
250 value = igmpv2LeaveGroup.get();
251 break;
252 case INVALID_IGMP_LENGTH:
253 value = invalidIgmpLength.get();
254 break;
255 case IGMP_V3_MEMBERSHIP_QUERY:
256 value = igmpv3MembershipQuery.get();
257 break;
258 case IGMP_CHANNEL_JOIN_COUNTER:
259 value = igmpChannelJoinCounter.get();
260 break;
261 case IGMP_V1_MEMBERSHIP_REPORT:
262 value = igmpv1MembershipReport.get();
263 break;
264 case IGMP_V2_MEMBERSHIP_REPORT:
265 value = igmpv2MembershipReport.get();
266 break;
267 case IGMP_V3_MEMBERSHIP_REPORT:
268 value = igmpv3MembershipReport.get();
269 break;
270 case INVALID_IGMP_MSG_RECEIVED:
271 value = invalidIgmpMsgReceived.get();
272 break;
273 case VALID_IGMP_PACKET_COUNTER:
274 value = validIgmpPacketCounter.get();
275 break;
276 case CURRENT_GRP_NUMBER_COUNTER:
277 value = currentGrpNumCounter.get();
278 break;
279 case IGMP_FAIL_JOIN_REQ:
280 value = igmpFailJoinReq.get();
281 break;
282 case UNCONFIGURED_GROUP_COUNTER:
283 value = unconfiguredGroupCounter.get();
284 break;
285 case IGMP_VALID_CHECKSUM_COUNTER:
286 value = igmpValidChecksumCounter.get();
287 break;
288 case IGMP_GENERAL_MEMBERSHIP_QUERY:
289 value = igmpGeneralMembershipQuery.get();
290 break;
291 case IGMP_SUCCESS_JOIN_RE_JOIN_REQ:
292 value = igmpSuccessJoinRejoinReq.get();
293 break;
294 case IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY:
295 value = igmpGrpSpecificMembershipQuery.get();
296 break;
297 case REPORTS_RX_WITH_WRONG_MODE_COUNTER:
298 value = reportsRxWithWrongModeCounter.get();
299 break;
300 case UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER:
301 value = unknownIgmpTypePacketsRxCounter.get();
302 break;
303 case FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER:
304 value = failJoinReqUnknownMulticastIpCounter.get();
305 break;
306 case IGMP_GRP_AND_SRC_SPESIFIC_MEMBERSHIP_QUERY:
307 value = igmpGrpAndSrcSpecificMembershipQuery.get();
308 break;
309 case FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER:
310 value = failJoinReqInsuffPermissionAccessCounter.get();
311 break;
312 default:
313 value = null;
314 log.warn("Unhandled statistic type. {}", type);
315 break;
316 }
317 return value;
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000318 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000319}