Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 4509c44 | 2023-01-03 14:05:28 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 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 | */ |
| 16 | package org.opencord.igmpproxy; |
| 17 | |
| 18 | import java.util.concurrent.atomic.AtomicLong; |
| 19 | |
| 20 | /** |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 21 | * Records metrics for IgmpProxy application. |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 22 | */ |
| 23 | public class IgmpStatistics { |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 24 | private static final long RESET_VALUE = 0L; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 25 | |
| 26 | //Total number of join requests |
| 27 | private AtomicLong igmpJoinReq = new AtomicLong(); |
| 28 | //Total number of successful join and rejoin requests |
| 29 | private AtomicLong igmpSuccessJoinRejoinReq = new AtomicLong(); |
| 30 | //Total number of failed join requests |
| 31 | private AtomicLong igmpFailJoinReq = new AtomicLong(); |
| 32 | //Total number of leaves requests |
| 33 | private AtomicLong igmpLeaveReq = new AtomicLong(); |
| 34 | // Total number of disconnects |
| 35 | private AtomicLong igmpDisconnect = new AtomicLong(); |
| 36 | //Count of Total number of IGMPV3_MEMBERSHIP_QUERY |
| 37 | private AtomicLong igmpv3MembershipQuery = new AtomicLong(); |
| 38 | //Count of IGMPV1_MEMBERSHIP_REPORT |
| 39 | private AtomicLong igmpv1MembershipReport = new AtomicLong(); |
| 40 | //Count of IGMPV3_MEMBERSHIP_REPORT |
| 41 | private AtomicLong igmpv3MembershipReport = new AtomicLong(); |
| 42 | //Count of IGMPV2_MEMBERSHIP_REPORT |
| 43 | private AtomicLong igmpv2MembershipReport = new AtomicLong(); |
| 44 | //Count of TYPE_IGMPV2_LEAVE_GROUP |
| 45 | private AtomicLong igmpv2LeaveGroup = new AtomicLong(); |
| 46 | //Total number of messages received. |
| 47 | private AtomicLong totalMsgReceived = new AtomicLong(); |
| 48 | //Total number of IGMP messages received |
| 49 | private AtomicLong igmpMsgReceived = new AtomicLong(); |
| 50 | //Total number of invalid IGMP messages received |
| 51 | private AtomicLong invalidIgmpMsgReceived = new AtomicLong(); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 52 | //Counter for unknown igmp type |
| 53 | private AtomicLong unknownIgmpTypePacketsRxCounter = new AtomicLong(); |
| 54 | // Counter for igmp report with wrong mode. |
| 55 | private AtomicLong reportsRxWithWrongModeCounter = new AtomicLong(); |
| 56 | // Counter for failed join due to insufficient permission access |
| 57 | private AtomicLong failJoinReqInsuffPermissionAccessCounter = new AtomicLong(); |
| 58 | // Counter for invalid group ip address i.e not a valid multicast address. |
| 59 | private AtomicLong failJoinReqUnknownMulticastIpCounter = new AtomicLong(); |
| 60 | // Counter for unconfigured group |
| 61 | private AtomicLong unconfiguredGroupCounter = new AtomicLong(); |
| 62 | // Counter for valid igmp packet |
| 63 | private AtomicLong validIgmpPacketCounter = new AtomicLong(); |
| 64 | // Counter for current number of igmp channel joins |
| 65 | private AtomicLong igmpChannelJoinCounter = new AtomicLong(); |
| 66 | // Counter for current group number |
| 67 | private AtomicLong currentGrpNumCounter = new AtomicLong(); |
| 68 | // Counter for igmp Checksum |
| 69 | private AtomicLong igmpValidChecksumCounter = new AtomicLong(); |
| 70 | // Counter for Invalid Igmp Length |
| 71 | private AtomicLong invalidIgmpLength = new AtomicLong(); |
| 72 | //Total number of general IGMP membership query messages received |
| 73 | private AtomicLong igmpGeneralMembershipQuery = new AtomicLong(); |
| 74 | //Total number of group specific IGMP membership query messages received |
| 75 | private AtomicLong igmpGrpSpecificMembershipQuery = new AtomicLong(); |
| 76 | //Total number of group and source specific IGMP membership query messages received |
Andrea Campanella | 3414fae | 2020-06-25 12:21:12 +0200 | [diff] [blame] | 77 | private AtomicLong igmpGrpAndSrcSpecificMembershipQuery = new AtomicLong(); |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 78 | |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 79 | public void setStats(IgmpStatistics current) { |
| 80 | igmpJoinReq.set(current.igmpJoinReq.get()); |
| 81 | igmpSuccessJoinRejoinReq.set(current.igmpSuccessJoinRejoinReq.get()); |
| 82 | igmpFailJoinReq.set(current.igmpFailJoinReq.get()); |
| 83 | igmpLeaveReq.set(current.igmpLeaveReq.get()); |
| 84 | igmpDisconnect.set(current.igmpDisconnect.get()); |
| 85 | igmpv3MembershipQuery.set(current.igmpv3MembershipQuery.get()); |
| 86 | igmpv1MembershipReport.set(current.igmpv1MembershipReport.get()); |
| 87 | igmpv3MembershipReport.set(current.igmpv3MembershipReport.get()); |
| 88 | igmpv2MembershipReport.set(current.igmpv2MembershipReport.get()); |
| 89 | igmpv2LeaveGroup.set(current.igmpv2LeaveGroup.get()); |
| 90 | totalMsgReceived.set(current.totalMsgReceived.get()); |
| 91 | igmpMsgReceived.set(current.igmpMsgReceived.get()); |
| 92 | invalidIgmpMsgReceived.set(current.invalidIgmpMsgReceived.get()); |
| 93 | unknownIgmpTypePacketsRxCounter.set(current.unknownIgmpTypePacketsRxCounter.get()); |
| 94 | reportsRxWithWrongModeCounter.set(current.reportsRxWithWrongModeCounter.get()); |
| 95 | failJoinReqInsuffPermissionAccessCounter.set(current.failJoinReqInsuffPermissionAccessCounter.get()); |
| 96 | failJoinReqUnknownMulticastIpCounter.set(current.failJoinReqUnknownMulticastIpCounter.get()); |
| 97 | unconfiguredGroupCounter.set(current.unconfiguredGroupCounter.get()); |
| 98 | validIgmpPacketCounter.set(current.validIgmpPacketCounter.get()); |
| 99 | igmpChannelJoinCounter.set(current.igmpChannelJoinCounter.get()); |
| 100 | currentGrpNumCounter.set(current.currentGrpNumCounter.get()); |
| 101 | igmpValidChecksumCounter.set(current.igmpValidChecksumCounter.get()); |
| 102 | invalidIgmpLength.set(current.invalidIgmpLength.get()); |
| 103 | igmpGeneralMembershipQuery.set(current.igmpGeneralMembershipQuery.get()); |
| 104 | igmpGrpSpecificMembershipQuery.set(current.igmpGrpSpecificMembershipQuery.get()); |
| 105 | igmpGrpAndSrcSpecificMembershipQuery.set(current.igmpGrpAndSrcSpecificMembershipQuery.get()); |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 108 | public void resetAll() { |
| 109 | igmpJoinReq.set(RESET_VALUE); |
| 110 | igmpLeaveReq.set(RESET_VALUE); |
| 111 | igmpDisconnect.set(RESET_VALUE); |
| 112 | totalMsgReceived.set(RESET_VALUE); |
| 113 | igmpv2LeaveGroup.set(RESET_VALUE); |
| 114 | invalidIgmpLength.set(RESET_VALUE); |
| 115 | igmpv3MembershipQuery.set(RESET_VALUE); |
| 116 | igmpChannelJoinCounter.set(RESET_VALUE); |
| 117 | igmpv1MembershipReport.set(RESET_VALUE); |
| 118 | igmpv2MembershipReport.set(RESET_VALUE); |
| 119 | igmpv3MembershipReport.set(RESET_VALUE); |
| 120 | invalidIgmpMsgReceived.set(RESET_VALUE); |
| 121 | validIgmpPacketCounter.set(RESET_VALUE); |
| 122 | currentGrpNumCounter.set(RESET_VALUE); |
| 123 | igmpFailJoinReq.set(RESET_VALUE); |
| 124 | unconfiguredGroupCounter.set(RESET_VALUE); |
| 125 | igmpValidChecksumCounter.set(RESET_VALUE); |
| 126 | igmpGeneralMembershipQuery.set(RESET_VALUE); |
| 127 | igmpSuccessJoinRejoinReq.set(RESET_VALUE); |
| 128 | igmpGrpSpecificMembershipQuery.set(RESET_VALUE); |
| 129 | reportsRxWithWrongModeCounter.set(RESET_VALUE); |
| 130 | unknownIgmpTypePacketsRxCounter.set(RESET_VALUE); |
| 131 | failJoinReqUnknownMulticastIpCounter.set(RESET_VALUE); |
| 132 | igmpGrpAndSrcSpecificMembershipQuery.set(RESET_VALUE); |
| 133 | failJoinReqInsuffPermissionAccessCounter.set(RESET_VALUE); |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 136 | public void increaseStat(IgmpStatisticType type) { |
| 137 | switch (type) { |
| 138 | case IGMP_JOIN_REQ: |
| 139 | igmpJoinReq.incrementAndGet(); |
| 140 | break; |
| 141 | case IGMP_LEAVE_REQ: |
| 142 | igmpLeaveReq.incrementAndGet(); |
| 143 | break; |
| 144 | case IGMP_DISCONNECT: |
| 145 | igmpDisconnect.incrementAndGet(); |
| 146 | break; |
| 147 | case IGMP_MSG_RECEIVED: |
| 148 | break; |
| 149 | case TOTAL_MSG_RECEIVED: |
| 150 | totalMsgReceived.incrementAndGet(); |
| 151 | break; |
| 152 | case IGMP_V2_LEAVE_GROUP: |
| 153 | igmpv2LeaveGroup.incrementAndGet(); |
| 154 | igmpMsgReceived.incrementAndGet(); |
| 155 | break; |
| 156 | case INVALID_IGMP_LENGTH: |
| 157 | invalidIgmpLength.incrementAndGet(); |
| 158 | break; |
| 159 | case IGMP_V3_MEMBERSHIP_QUERY: |
| 160 | igmpv3MembershipQuery.incrementAndGet(); |
| 161 | igmpMsgReceived.incrementAndGet(); |
| 162 | break; |
| 163 | case IGMP_CHANNEL_JOIN_COUNTER: |
| 164 | igmpChannelJoinCounter.incrementAndGet(); |
| 165 | break; |
| 166 | case IGMP_V1_MEMBERSHIP_REPORT: |
| 167 | igmpv1MembershipReport.incrementAndGet(); |
| 168 | igmpMsgReceived.incrementAndGet(); |
| 169 | break; |
| 170 | case IGMP_V2_MEMBERSHIP_REPORT: |
| 171 | igmpv2MembershipReport.incrementAndGet(); |
| 172 | igmpMsgReceived.incrementAndGet(); |
| 173 | break; |
| 174 | case IGMP_V3_MEMBERSHIP_REPORT: |
| 175 | igmpv3MembershipReport.incrementAndGet(); |
| 176 | igmpMsgReceived.incrementAndGet(); |
| 177 | break; |
| 178 | case INVALID_IGMP_MSG_RECEIVED: |
| 179 | invalidIgmpMsgReceived.incrementAndGet(); |
| 180 | break; |
| 181 | case VALID_IGMP_PACKET_COUNTER: |
| 182 | validIgmpPacketCounter.incrementAndGet(); |
| 183 | break; |
| 184 | case CURRENT_GRP_NUMBER_COUNTER: |
| 185 | currentGrpNumCounter.incrementAndGet(); |
| 186 | break; |
| 187 | case IGMP_FAIL_JOIN_REQ: |
| 188 | igmpFailJoinReq.incrementAndGet(); |
| 189 | break; |
| 190 | case UNCONFIGURED_GROUP_COUNTER: |
| 191 | unconfiguredGroupCounter.incrementAndGet(); |
| 192 | break; |
| 193 | case IGMP_VALID_CHECKSUM_COUNTER: |
| 194 | igmpValidChecksumCounter.incrementAndGet(); |
| 195 | break; |
| 196 | case IGMP_GENERAL_MEMBERSHIP_QUERY: |
| 197 | igmpGeneralMembershipQuery.incrementAndGet(); |
| 198 | break; |
| 199 | case IGMP_SUCCESS_JOIN_RE_JOIN_REQ: |
| 200 | igmpSuccessJoinRejoinReq.incrementAndGet(); |
| 201 | break; |
| 202 | case IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY: |
| 203 | igmpGrpSpecificMembershipQuery.incrementAndGet(); |
| 204 | break; |
| 205 | case REPORTS_RX_WITH_WRONG_MODE_COUNTER: |
| 206 | reportsRxWithWrongModeCounter.incrementAndGet(); |
| 207 | break; |
| 208 | case UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER: |
| 209 | unknownIgmpTypePacketsRxCounter.incrementAndGet(); |
| 210 | break; |
| 211 | case FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER: |
| 212 | failJoinReqUnknownMulticastIpCounter.incrementAndGet(); |
| 213 | break; |
| 214 | case IGMP_GRP_AND_SRC_SPESIFIC_MEMBERSHIP_QUERY: |
| 215 | igmpGrpAndSrcSpecificMembershipQuery.incrementAndGet(); |
| 216 | break; |
| 217 | case FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER: |
| 218 | failJoinReqInsuffPermissionAccessCounter.incrementAndGet(); |
| 219 | break; |
| 220 | default: |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 221 | break; |
| 222 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 225 | public Long getStat(IgmpStatisticType type) { |
| 226 | Long value; |
| 227 | switch (type) { |
| 228 | case IGMP_JOIN_REQ: |
| 229 | value = igmpJoinReq.get(); |
| 230 | break; |
| 231 | case IGMP_LEAVE_REQ: |
| 232 | value = igmpLeaveReq.get(); |
| 233 | break; |
| 234 | case IGMP_DISCONNECT: |
| 235 | value = igmpDisconnect.get(); |
| 236 | break; |
| 237 | case IGMP_MSG_RECEIVED: |
| 238 | value = igmpMsgReceived.get(); |
| 239 | break; |
| 240 | case TOTAL_MSG_RECEIVED: |
| 241 | value = totalMsgReceived.get(); |
| 242 | break; |
| 243 | case IGMP_V2_LEAVE_GROUP: |
| 244 | value = igmpv2LeaveGroup.get(); |
| 245 | break; |
| 246 | case INVALID_IGMP_LENGTH: |
| 247 | value = invalidIgmpLength.get(); |
| 248 | break; |
| 249 | case IGMP_V3_MEMBERSHIP_QUERY: |
| 250 | value = igmpv3MembershipQuery.get(); |
| 251 | break; |
| 252 | case IGMP_CHANNEL_JOIN_COUNTER: |
| 253 | value = igmpChannelJoinCounter.get(); |
| 254 | break; |
| 255 | case IGMP_V1_MEMBERSHIP_REPORT: |
| 256 | value = igmpv1MembershipReport.get(); |
| 257 | break; |
| 258 | case IGMP_V2_MEMBERSHIP_REPORT: |
| 259 | value = igmpv2MembershipReport.get(); |
| 260 | break; |
| 261 | case IGMP_V3_MEMBERSHIP_REPORT: |
| 262 | value = igmpv3MembershipReport.get(); |
| 263 | break; |
| 264 | case INVALID_IGMP_MSG_RECEIVED: |
| 265 | value = invalidIgmpMsgReceived.get(); |
| 266 | break; |
| 267 | case VALID_IGMP_PACKET_COUNTER: |
| 268 | value = validIgmpPacketCounter.get(); |
| 269 | break; |
| 270 | case CURRENT_GRP_NUMBER_COUNTER: |
| 271 | value = currentGrpNumCounter.get(); |
| 272 | break; |
| 273 | case IGMP_FAIL_JOIN_REQ: |
| 274 | value = igmpFailJoinReq.get(); |
| 275 | break; |
| 276 | case UNCONFIGURED_GROUP_COUNTER: |
| 277 | value = unconfiguredGroupCounter.get(); |
| 278 | break; |
| 279 | case IGMP_VALID_CHECKSUM_COUNTER: |
| 280 | value = igmpValidChecksumCounter.get(); |
| 281 | break; |
| 282 | case IGMP_GENERAL_MEMBERSHIP_QUERY: |
| 283 | value = igmpGeneralMembershipQuery.get(); |
| 284 | break; |
| 285 | case IGMP_SUCCESS_JOIN_RE_JOIN_REQ: |
| 286 | value = igmpSuccessJoinRejoinReq.get(); |
| 287 | break; |
| 288 | case IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY: |
| 289 | value = igmpGrpSpecificMembershipQuery.get(); |
| 290 | break; |
| 291 | case REPORTS_RX_WITH_WRONG_MODE_COUNTER: |
| 292 | value = reportsRxWithWrongModeCounter.get(); |
| 293 | break; |
| 294 | case UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER: |
| 295 | value = unknownIgmpTypePacketsRxCounter.get(); |
| 296 | break; |
| 297 | case FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER: |
| 298 | value = failJoinReqUnknownMulticastIpCounter.get(); |
| 299 | break; |
| 300 | case IGMP_GRP_AND_SRC_SPESIFIC_MEMBERSHIP_QUERY: |
| 301 | value = igmpGrpAndSrcSpecificMembershipQuery.get(); |
| 302 | break; |
| 303 | case FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER: |
| 304 | value = failJoinReqInsuffPermissionAccessCounter.get(); |
| 305 | break; |
| 306 | default: |
| 307 | value = null; |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 308 | break; |
| 309 | } |
| 310 | return value; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 311 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 312 | } |