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