Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | |
| 17 | package org.opencord.kafka.integrations; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 22 | import org.opencord.igmpproxy.IgmpStatisticType; |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 23 | import org.osgi.service.component.annotations.Activate; |
| 24 | import org.osgi.service.component.annotations.Component; |
| 25 | import org.osgi.service.component.annotations.Deactivate; |
| 26 | import org.osgi.service.component.annotations.Reference; |
| 27 | import org.osgi.service.component.annotations.ReferenceCardinality; |
| 28 | import org.osgi.service.component.annotations.ReferencePolicy; |
| 29 | import org.opencord.kafka.EventBusService; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | import java.util.concurrent.atomic.AtomicReference; |
| 34 | |
| 35 | import org.opencord.igmpproxy.IgmpStatisticsEvent; |
| 36 | import org.opencord.igmpproxy.IgmpStatisticsEventListener; |
| 37 | import org.opencord.igmpproxy.IgmpStatisticsService; |
| 38 | |
| 39 | /** |
| 40 | * Listens for IGMP events and pushes them on a Kafka bus. |
| 41 | */ |
| 42 | |
| 43 | @Component(immediate = true) |
| 44 | public class IgmpKafkaIntegration extends AbstractKafkaIntegration { |
| 45 | |
| 46 | public Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | |
| 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 49 | protected EventBusService eventBusService; |
| 50 | |
| 51 | @Reference(cardinality = ReferenceCardinality.OPTIONAL, |
| 52 | policy = ReferencePolicy.DYNAMIC, |
| 53 | bind = "bindIgmpStatService", |
| 54 | unbind = "unbindIgmpStatService") |
| 55 | protected volatile IgmpStatisticsService ignore; |
| 56 | private final AtomicReference<IgmpStatisticsService> igmpStatServiceRef = new AtomicReference<>(); |
| 57 | |
| 58 | private final IgmpStatisticsEventListener igmpStatisticsEventListener = |
| 59 | new InternalIgmpStatisticsListener(); |
| 60 | |
| 61 | //TOPIC |
kishore | efa3db5 | 2020-03-23 16:09:26 +0530 | [diff] [blame] | 62 | protected static final String IGMP_STATISTICS_TOPIC = "onos.igmp.stats.kpis"; |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 63 | |
| 64 | // IGMP stats event params |
| 65 | private static final String IGMP_JOIN_REQ = "igmpJoinReq"; |
| 66 | private static final String IGMP_SUCCESS_JOIN_REJOIN_REQ = "igmpSuccessJoinRejoinReq"; |
| 67 | private static final String IGMP_FAIL_JOIN_REQ = "igmpFailJoinReq"; |
| 68 | private static final String IGMP_LEAVE_REQ = "igmpLeaveReq"; |
| 69 | private static final String IGMP_DISCONNECT = "igmpDisconnect"; |
| 70 | private static final String IGMP_V3_MEMBERSHIP_QUERY = "igmpv3MembbershipQuery"; |
| 71 | private static final String IGMP_V1_MEMBERSHIP_REPORT = "igmpv1MembershipReport"; |
| 72 | private static final String IGMP_V2_MEMBERSHIP_REPORT = "igmpv2MembershipReport"; |
| 73 | private static final String IGMP_V3_MEMBERSHIP_REPORT = "igmpv3MembershipReport"; |
| 74 | private static final String IGMP_V2_LEAVE_GROUP = "igmpv2LeaveGroup"; |
| 75 | private static final String TOTAL_MSG_RECEIVED = "totalMsgReceived"; |
| 76 | private static final String IGMP_MSG_RECEIVED = "igmpMsgReceived"; |
| 77 | private static final String INVALID_IGMP_MSG_RECEIVED = "invalidIgmpMsgReceived"; |
| 78 | |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 79 | private static final String UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 80 | "unknownIgmpTypePacketsRxCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 81 | private static final String REPORTS_RX_WITH_WRONG_MODE_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 82 | "reportsRxWithWrongModeCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 83 | private static final String FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 84 | "failJoinReqInsuffPermissionAccessCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 85 | private static final String FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 86 | "failJoinReqUnknownMulticastIpCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 87 | private static final String UNCONFIGURED_GROUP_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 88 | "unconfiguredGroupCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 89 | private static final String VALID_IGMP_PACKET_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 90 | "validIgmpPacketCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 91 | private static final String IGMP_CHANNEL_JOIN_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 92 | "igmpChannelJoinCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 93 | private static final String CURRENT_GRP_NUM_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 94 | "currentGrpNumCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 95 | private static final String IGMP_VALID_CHECKSUM_COUNTER = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 96 | "igmpValidChecksumCounter"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 97 | private static final String INVALID_IGMP_LENGTH = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 98 | "invalidIgmpLength"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 99 | private static final String IGMP_GENERAL_MEMBERSHIP_QUERY = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 100 | "igmpGeneralMembershipQuery"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 101 | private static final String IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 102 | "igmpGrpSpecificMembershipQuery"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 103 | private static final String IGMP_GRP_AND_SRC_SPECIFIC_MEMBERSHIP_QUERY = |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 104 | "igmpGrpAndSrcSpecificMembershipQuery"; |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 105 | |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 106 | protected void bindIgmpStatService(IgmpStatisticsService incomingService) { |
| 107 | bindAndAddListener(incomingService, igmpStatServiceRef, igmpStatisticsEventListener); |
| 108 | } |
| 109 | |
| 110 | protected void unbindIgmpStatService(IgmpStatisticsService outgoingService) { |
| 111 | unbindAndRemoveListener(outgoingService, igmpStatServiceRef, igmpStatisticsEventListener); |
| 112 | } |
| 113 | |
| 114 | @Activate |
| 115 | public void activate() { |
| 116 | log.info("Started IgmpKafkaIntegration"); |
| 117 | } |
| 118 | |
| 119 | @Deactivate |
| 120 | public void deactivate() { |
| 121 | log.info("Stopped IgmpKafkaIntegration"); |
| 122 | } |
| 123 | |
| 124 | private void handleStat(IgmpStatisticsEvent event) { |
| 125 | eventBusService.send(IGMP_STATISTICS_TOPIC, serializeStat(event)); |
Andrea Campanella | 6f0eeaf | 2020-06-25 10:33:59 +0000 | [diff] [blame] | 126 | if (log.isTraceEnabled()) { |
| 127 | log.trace("IGMPStatisticsEvent sent successfully"); |
| 128 | } |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | private JsonNode serializeStat(IgmpStatisticsEvent event) { |
| 132 | ObjectMapper mapper = new ObjectMapper(); |
| 133 | ObjectNode igmpStatEvent = mapper.createObjectNode(); |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 134 | igmpStatEvent.put(IGMP_JOIN_REQ, event.subject() |
| 135 | .getStat(IgmpStatisticType.IGMP_JOIN_REQ)); |
| 136 | igmpStatEvent.put(IGMP_SUCCESS_JOIN_REJOIN_REQ, event.subject() |
| 137 | .getStat(IgmpStatisticType.IGMP_SUCCESS_JOIN_RE_JOIN_REQ)); |
| 138 | igmpStatEvent.put(IGMP_FAIL_JOIN_REQ, event.subject() |
| 139 | .getStat(IgmpStatisticType.IGMP_FAIL_JOIN_REQ)); |
| 140 | igmpStatEvent.put(IGMP_LEAVE_REQ, event.subject() |
| 141 | .getStat(IgmpStatisticType.IGMP_LEAVE_REQ)); |
| 142 | igmpStatEvent.put(IGMP_DISCONNECT, event.subject() |
| 143 | .getStat(IgmpStatisticType.IGMP_DISCONNECT)); |
| 144 | igmpStatEvent.put(IGMP_V3_MEMBERSHIP_QUERY, event.subject() |
| 145 | .getStat(IgmpStatisticType.IGMP_V3_MEMBERSHIP_QUERY)); |
| 146 | igmpStatEvent.put(IGMP_V1_MEMBERSHIP_REPORT, event.subject() |
| 147 | .getStat(IgmpStatisticType.IGMP_V1_MEMBERSHIP_REPORT)); |
| 148 | igmpStatEvent.put(IGMP_V2_MEMBERSHIP_REPORT, event.subject() |
| 149 | .getStat(IgmpStatisticType.IGMP_V2_MEMBERSHIP_REPORT)); |
| 150 | igmpStatEvent.put(IGMP_V3_MEMBERSHIP_REPORT, event.subject() |
| 151 | .getStat(IgmpStatisticType.IGMP_V3_MEMBERSHIP_REPORT)); |
| 152 | igmpStatEvent.put(IGMP_V2_LEAVE_GROUP, event.subject() |
| 153 | .getStat(IgmpStatisticType.IGMP_V2_LEAVE_GROUP)); |
| 154 | igmpStatEvent.put(TOTAL_MSG_RECEIVED, event.subject() |
| 155 | .getStat(IgmpStatisticType.TOTAL_MSG_RECEIVED)); |
| 156 | igmpStatEvent.put(IGMP_MSG_RECEIVED, event.subject() |
| 157 | .getStat(IgmpStatisticType.IGMP_MSG_RECEIVED)); |
| 158 | igmpStatEvent.put(INVALID_IGMP_MSG_RECEIVED, event.subject() |
| 159 | .getStat(IgmpStatisticType.INVALID_IGMP_MSG_RECEIVED)); |
| 160 | igmpStatEvent.put(UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER, event.subject() |
| 161 | .getStat(IgmpStatisticType.UNKNOWN_IGMP_TYPE_PACKETS_RX_COUNTER)); |
| 162 | igmpStatEvent.put(REPORTS_RX_WITH_WRONG_MODE_COUNTER, event.subject() |
| 163 | .getStat(IgmpStatisticType.REPORTS_RX_WITH_WRONG_MODE_COUNTER)); |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 164 | igmpStatEvent.put(FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER, |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 165 | event.subject().getStat(IgmpStatisticType.FAIL_JOIN_REQ_INSUFF_PERMISSION_ACCESS_COUNTER)); |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 166 | igmpStatEvent.put(FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER, |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 167 | event.subject().getStat(IgmpStatisticType.FAIL_JOIN_REQ_UNKNOWN_MULTICAST_IP_COUNTER)); |
| 168 | igmpStatEvent.put(UNCONFIGURED_GROUP_COUNTER, event.subject() |
| 169 | .getStat(IgmpStatisticType.UNCONFIGURED_GROUP_COUNTER)); |
| 170 | igmpStatEvent.put(VALID_IGMP_PACKET_COUNTER, event.subject() |
| 171 | .getStat(IgmpStatisticType.VALID_IGMP_PACKET_COUNTER)); |
| 172 | igmpStatEvent.put(IGMP_CHANNEL_JOIN_COUNTER, event.subject() |
| 173 | .getStat(IgmpStatisticType.IGMP_CHANNEL_JOIN_COUNTER)); |
| 174 | igmpStatEvent.put(CURRENT_GRP_NUM_COUNTER, event.subject() |
| 175 | .getStat(IgmpStatisticType.CURRENT_GRP_NUMBER_COUNTER)); |
| 176 | igmpStatEvent.put(IGMP_VALID_CHECKSUM_COUNTER, event.subject() |
| 177 | .getStat(IgmpStatisticType.IGMP_VALID_CHECKSUM_COUNTER)); |
| 178 | igmpStatEvent.put(INVALID_IGMP_LENGTH, event.subject() |
| 179 | .getStat(IgmpStatisticType.INVALID_IGMP_LENGTH)); |
| 180 | igmpStatEvent.put(IGMP_GENERAL_MEMBERSHIP_QUERY, event.subject() |
| 181 | .getStat(IgmpStatisticType.IGMP_GENERAL_MEMBERSHIP_QUERY)); |
| 182 | igmpStatEvent.put(IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY, event.subject() |
| 183 | .getStat(IgmpStatisticType.IGMP_GRP_SPECIFIC_MEMBERSHIP_QUERY)); |
Sonal Kasliwal | 036c794 | 2020-03-18 12:11:20 +0000 | [diff] [blame] | 184 | igmpStatEvent.put(IGMP_GRP_AND_SRC_SPECIFIC_MEMBERSHIP_QUERY, |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 185 | event.subject().getStat(IgmpStatisticType.IGMP_GRP_AND_SRC_SPESIFIC_MEMBERSHIP_QUERY)); |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 186 | return igmpStatEvent; |
| 187 | } |
| 188 | |
| 189 | public class InternalIgmpStatisticsListener implements |
Ilayda Ozdemir | 8b96b32 | 2020-06-18 08:52:17 +0000 | [diff] [blame] | 190 | IgmpStatisticsEventListener { |
Shubham Sharma | 751e82e | 2020-03-02 06:05:41 +0000 | [diff] [blame] | 191 | |
| 192 | @Override |
| 193 | public void event(IgmpStatisticsEvent igmpStatisticsEvent) { |
| 194 | handleStat(igmpStatisticsEvent); |
| 195 | } |
| 196 | } |
| 197 | } |