blob: af834ef8fb0d7615a6835528f92ca631f3ef2747 [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 */
16
17package org.opencord.igmpproxy;
18
19import org.osgi.service.component.annotations.Component;
20import org.osgi.service.component.ComponentContext;
21import org.osgi.service.component.annotations.Activate;
22import org.onlab.util.SafeRecurringTask;
23import org.onlab.util.Tools;
24import org.onosproject.cfg.ComponentConfigService;
25import org.onosproject.event.AbstractListenerManager;
26import org.osgi.service.component.annotations.Deactivate;
27import org.osgi.service.component.annotations.Modified;
28import org.osgi.service.component.annotations.Reference;
29import org.osgi.service.component.annotations.ReferenceCardinality;
30
31import static org.slf4j.LoggerFactory.getLogger;
32
33import java.util.Dictionary;
34import java.util.concurrent.Executors;
35import java.util.concurrent.ScheduledExecutorService;
36import java.util.concurrent.ScheduledFuture;
37import java.util.concurrent.TimeUnit;
38
39import org.slf4j.Logger;
40
41import com.google.common.base.Strings;
42
43import static org.opencord.igmpproxy.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD;
44import static org.opencord.igmpproxy.OsgiPropertyConstants.STATISTICS_GENERATION_PERIOD_DEFAULT;
45
46
47/**
48 *
49 * Process the stats collected in Igmp proxy application. Publish to kafka onos.
50 *
51 */
52@Component(immediate = true, property = {
53 STATISTICS_GENERATION_PERIOD + ":Integer=" + STATISTICS_GENERATION_PERIOD_DEFAULT,
54})
55public class IgmpStatisticsManager extends
56 AbstractListenerManager<IgmpStatisticsEvent, IgmpStatisticsEventListener>
57 implements IgmpStatisticsService {
58 private final Logger log = getLogger(getClass());
59 private IgmpStatistics igmpStats;
60
61 ScheduledExecutorService executorForIgmp;
62 private ScheduledFuture<?> publisherTask;
63
64 protected int statisticsGenerationPeriodInSeconds = STATISTICS_GENERATION_PERIOD_DEFAULT;
65
66 @Reference(cardinality = ReferenceCardinality.MANDATORY)
67 protected ComponentConfigService cfgService;
68
69 @Override
70 public IgmpStatistics getIgmpStats() {
71 return igmpStats;
72 }
73
74 @Activate
75 public void activate(ComponentContext context) {
76 igmpStats = new IgmpStatistics();
77
78 eventDispatcher.addSink(IgmpStatisticsEvent.class, listenerRegistry);
79 executorForIgmp = Executors.newScheduledThreadPool(1);
80 cfgService.registerProperties(getClass());
81 modified(context);
82 log.info("IgmpStatisticsManager Activated");
83 }
84
85 @Modified
86 public void modified(ComponentContext context) {
87 Dictionary<String, Object> properties = context.getProperties();
88
89 try {
90 String s = Tools.get(properties, STATISTICS_GENERATION_PERIOD);
91 statisticsGenerationPeriodInSeconds = Strings.isNullOrEmpty(s) ?
92 Integer.parseInt(STATISTICS_GENERATION_PERIOD)
93 : Integer.parseInt(s.trim());
94 } catch (NumberFormatException ne) {
95 log.error("Unable to parse configuration parameter for eventGenerationPeriodInSeconds", ne);
96 statisticsGenerationPeriodInSeconds = STATISTICS_GENERATION_PERIOD_DEFAULT;
97 }
98 if (publisherTask != null) {
99 publisherTask.cancel(true);
100 }
101 publisherTask = executorForIgmp.scheduleAtFixedRate(SafeRecurringTask.wrap(this::publishStats),
102 0, statisticsGenerationPeriodInSeconds, TimeUnit.SECONDS);
103 }
104
105 @Deactivate
106 public void deactivate() {
107 eventDispatcher.removeSink(IgmpStatisticsEvent.class);
108 publisherTask.cancel(true);
109 executorForIgmp.shutdown();
110 cfgService.unregisterProperties(getClass(), false);
111 igmpStats = null;
112 log.info("IgmpStatisticsManager Deactivated");
113 }
114
115 /**
116 * Publishes stats.
117 */
118 private void publishStats() {
119
120 if (log.isDebugEnabled()) {
121 log.debug("Notifying stats: {}", igmpStats);
122 log.debug("--IgmpDisconnect--" + igmpStats.getIgmpDisconnect());
123 log.debug("--IgmpFailJoinReq--" + igmpStats.getIgmpFailJoinReq());
124 log.debug("--IgmpJoinReq--" + igmpStats.getIgmpJoinReq());
125 log.debug("--IgmpLeaveReq--" + igmpStats.getIgmpLeaveReq());
126 log.debug("--IgmpMsgReceived--" + igmpStats.getIgmpMsgReceived());
127 log.debug("--IgmpSuccessJoinRejoinReq--" + igmpStats.getIgmpSuccessJoinRejoinReq());
128 log.debug("--Igmpv1MemershipReport--" + igmpStats.getIgmpv1MemershipReport());
129 log.debug("--Igmpv2LeaveGroup--" + igmpStats.getIgmpv2LeaveGroup());
130 log.debug("--Igmpv2MembershipReport--" + igmpStats.getIgmpv2MembershipReport());
131 log.debug("--Igmpv3MembershipQuery--" + igmpStats.getIgmpv3MembershipQuery());
132 log.debug("--Igmpv3MembershipReport--" + igmpStats.getIgmpv3MembershipReport());
133 log.debug("--InvalidIgmpMsgReceived--" + igmpStats.getInvalidIgmpMsgReceived());
134 log.debug("--TotalMsgReceived-- " + igmpStats.getTotalMsgReceived());
Sonal Kasliwalf11c0672020-03-18 11:11:50 +0000135 log.debug("--UnknownIgmpTypePacketsRx--" + igmpStats.getUnknownIgmpTypePacketsRxCounter());
136 log.debug("--ReportsRxWithWrongMode--" + igmpStats.getReportsRxWithWrongModeCounter());
137 log.debug("--FailJoinReqInsuffPermission--" + igmpStats.getFailJoinReqInsuffPermissionAccessCounter());
138 log.debug("--FailJoinReqUnknownMulticastIp--" + igmpStats.getFailJoinReqUnknownMulticastIpCounter());
139 log.debug("--UnconfiguredGroupCounter--" + igmpStats.getUnconfiguredGroupCounter());
140 log.debug("--ValidIgmpPacketCounter--" + igmpStats.getValidIgmpPacketCounter());
141 log.debug("--IgmpChannelJoinCounter--" + igmpStats.getIgmpChannelJoinCounter());
142 log.debug("--CurrentGrpNumCounter--" + igmpStats.getCurrentGrpNumCounter());
143 log.debug("--IgmpValidChecksumCounter--" + igmpStats.getIgmpValidChecksumCounter());
144 log.debug("--InvalidIgmpLength--" + igmpStats.getInvalidIgmpLength());
145 log.debug("--IgmpGeneralMembershipQuery--" + igmpStats.getIgmpGeneralMembershipQuery());
146 log.debug("--IgmpGrpSpecificMembershipQuery--" + igmpStats.getIgmpGrpSpecificMembershipQuery());
147 log.debug("--IgmpGrpAndSrcSpecificMembershipQuery--" + igmpStats.getIgmpGrpAndSrcSpecificMembershipQuery());
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000148 }
149
150 post(new IgmpStatisticsEvent(IgmpStatisticsEvent.Type.STATS_UPDATE, igmpStats));
151 }
152
153}