blob: 6a41cf23586a8ecc62fbcfa04de4f4edda4d9a9b [file] [log] [blame]
Simon Hunt1911fe42017-05-02 18:25:58 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Simon Hunt1911fe42017-05-02 18:25:58 -07003 *
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
18package org.onosproject.ui.impl.topo;
19
20import org.onosproject.ui.impl.TrafficMonitorBase;
21import org.onosproject.ui.impl.topo.util.ServicesBundle;
Simon Hunta7aea842017-05-03 19:42:50 -070022import org.onosproject.ui.impl.topo.util.TrafficLink;
Simon Hunt0e161092017-05-08 17:41:38 -070023import org.onosproject.ui.model.topo.UiLinkId;
24import org.onosproject.ui.model.topo.UiSynthLink;
Simon Hunta7aea842017-05-03 19:42:50 -070025import org.onosproject.ui.topo.Highlights;
Simon Hunt1911fe42017-05-02 18:25:58 -070026import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
Simon Hunt0e161092017-05-08 17:41:38 -070029import java.util.HashMap;
30import java.util.HashSet;
31import java.util.Map;
Simon Hunta7aea842017-05-03 19:42:50 -070032import java.util.Set;
33
Simon Hunt05eba352017-05-11 20:17:08 -070034import static org.onosproject.ui.model.topo.UiLinkId.uiLinkId;
35
Simon Hunt1911fe42017-05-02 18:25:58 -070036/**
37 * Encapsulates the behavior of monitoring specific traffic patterns in the
38 * Topology-2 view.
39 */
40public class Traffic2Monitor extends TrafficMonitorBase {
41
42 private static final Logger log =
43 LoggerFactory.getLogger(Traffic2Monitor.class);
44
Simon Hunta7aea842017-05-03 19:42:50 -070045 // link back to our message handler (for outbound messages)
Simon Hunt9e2413e2017-05-03 14:25:40 -070046 private final Topo2TrafficMessageHandler msgHandler;
47
Simon Hunt1911fe42017-05-02 18:25:58 -070048 /**
49 * Constructs a traffic monitor.
50 *
Simon Hunt9e2413e2017-05-03 14:25:40 -070051 * @param trafficPeriod traffic task period in ms
Simon Hunt1911fe42017-05-02 18:25:58 -070052 * @param servicesBundle bundle of services
Simon Hunt9e2413e2017-05-03 14:25:40 -070053 * @param msgHandler our message handler
Simon Hunt1911fe42017-05-02 18:25:58 -070054 */
Simon Hunt9e2413e2017-05-03 14:25:40 -070055 public Traffic2Monitor(long trafficPeriod, ServicesBundle servicesBundle,
56 Topo2TrafficMessageHandler msgHandler) {
Sean Condonadeb7162019-04-13 20:56:14 +010057 super(trafficPeriod, servicesBundle, msgHandler);
Simon Hunt9e2413e2017-05-03 14:25:40 -070058 this.msgHandler = msgHandler;
Simon Hunt1911fe42017-05-02 18:25:58 -070059 }
60
61 @Override
62 protected void sendAllFlowTraffic() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070063 log.debug("TOPO-2-TRAFFIC: sendAllFlowTraffic");
Simon Hunt8e258112017-05-05 13:19:04 -070064 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.FLOW_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070065 }
66
67 @Override
Thomas Vachuska2b4de872021-03-30 16:31:34 -070068 protected void sendCustomTraffic() {
69 }
70
71 @Override
Simon Hunt1911fe42017-05-02 18:25:58 -070072 protected void sendAllPortTrafficBits() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070073 log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficBits");
Simon Hunt8e258112017-05-05 13:19:04 -070074 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070075 }
76
77 @Override
78 protected void sendAllPortTrafficPackets() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070079 log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficPackets");
Simon Hunt8e258112017-05-05 13:19:04 -070080 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_PACKET_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070081 }
82
83 @Override
Simon Hunt1911fe42017-05-02 18:25:58 -070084 protected void sendClearHighlights() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070085 log.debug("TOPO-2-TRAFFIC: sendClearHighlights");
Simon Hunt8e258112017-05-05 13:19:04 -070086 msgHandler.sendHighlights(new Highlights());
Simon Hunt1911fe42017-05-02 18:25:58 -070087 }
88
Simon Hunt9e2413e2017-05-03 14:25:40 -070089
90 // NOTE: currently this monitor holds no state - nothing to do for these...
91 @Override
92 protected void sendDeviceLinkFlows() {
93 }
94
95 @Override
96 protected void sendSelectedIntentTraffic() {
Sean Condonadeb7162019-04-13 20:56:14 +010097 log.debug("sendSelectedIntentTraffic: {}", selectedIntents);
98 msgHandler.sendHighlights(intentTraffic());
Simon Hunt9e2413e2017-05-03 14:25:40 -070099 }
100
Simon Hunt1911fe42017-05-02 18:25:58 -0700101 @Override
102 protected void clearSelection() {
Sean Condonf9ff66a2020-03-23 08:40:55 +0000103 selectedNodes = null;
104 selectedIntents = null;
Simon Hunt1911fe42017-05-02 18:25:58 -0700105 }
Simon Hunta7aea842017-05-03 19:42:50 -0700106
107 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 // -- link aggregation
109
110
111 @Override
112 protected Set<TrafficLink> doAggregation(Set<TrafficLink> linksWithTraffic) {
Simon Hunta7aea842017-05-03 19:42:50 -0700113 log.debug("Need to aggregate {} links", linksWithTraffic.size());
114
Simon Hunt0e161092017-05-08 17:41:38 -0700115 // first, retrieve from the shared topology model those synth links that
116 // are part of the region currently being viewed by the user...
117 Map<UiLinkId, UiSynthLink> synthLinkMap =
118 msgHandler.retrieveRelevantSynthLinks();
119
120 // NOTE: compute Set<TrafficLink> which represents the consolidated links
121
122 Map<UiLinkId, TrafficLink> mappedByUiLinkId = new HashMap<>();
123
124 for (TrafficLink tl : linksWithTraffic) {
Simon Hunt05eba352017-05-11 20:17:08 -0700125 UiLinkId tlid = uiLinkId(tl.key());
Simon Hunt0e161092017-05-08 17:41:38 -0700126 UiSynthLink sl = synthLinkMap.get(tlid);
127 if (sl != null) {
128 UiLinkId aggrid = sl.link().id();
Simon Hunt05eba352017-05-11 20:17:08 -0700129 TrafficLink aggregated =
130 mappedByUiLinkId.computeIfAbsent(aggrid, TrafficLink::new);
131 aggregated.mergeStats(tl);
Simon Hunt0e161092017-05-08 17:41:38 -0700132 }
133 }
134
135 Set<TrafficLink> result = new HashSet<>();
136 result.addAll(mappedByUiLinkId.values());
137 return result;
Simon Hunta7aea842017-05-03 19:42:50 -0700138 }
Simon Hunt1911fe42017-05-02 18:25:58 -0700139}