blob: 1c0fb81af312f4646eb430c3b83cda0a6a962e10 [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 Hunt1911fe42017-05-02 18:25:58 -070051 * @param servicesBundle bundle of services
Simon Hunt9e2413e2017-05-03 14:25:40 -070052 * @param msgHandler our message handler
Simon Hunt1911fe42017-05-02 18:25:58 -070053 */
Thomas Vachuskaa5e986d2021-04-06 11:14:09 -070054 public Traffic2Monitor(ServicesBundle servicesBundle,
Simon Hunt9e2413e2017-05-03 14:25:40 -070055 Topo2TrafficMessageHandler msgHandler) {
Thomas Vachuskaa5e986d2021-04-06 11:14:09 -070056 super(servicesBundle, msgHandler);
Simon Hunt9e2413e2017-05-03 14:25:40 -070057 this.msgHandler = msgHandler;
Simon Hunt1911fe42017-05-02 18:25:58 -070058 }
59
60 @Override
61 protected void sendAllFlowTraffic() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070062 log.debug("TOPO-2-TRAFFIC: sendAllFlowTraffic");
Simon Hunt8e258112017-05-05 13:19:04 -070063 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.FLOW_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070064 }
65
66 @Override
Thomas Vachuska2b4de872021-03-30 16:31:34 -070067 protected void sendCustomTraffic() {
68 }
69
70 @Override
Simon Hunt1911fe42017-05-02 18:25:58 -070071 protected void sendAllPortTrafficBits() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070072 log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficBits");
Simon Hunt8e258112017-05-05 13:19:04 -070073 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070074 }
75
76 @Override
77 protected void sendAllPortTrafficPackets() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070078 log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficPackets");
Simon Hunt8e258112017-05-05 13:19:04 -070079 msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_PACKET_STATS));
Simon Hunt1911fe42017-05-02 18:25:58 -070080 }
81
82 @Override
Simon Hunt1911fe42017-05-02 18:25:58 -070083 protected void sendClearHighlights() {
Simon Hunt9e2413e2017-05-03 14:25:40 -070084 log.debug("TOPO-2-TRAFFIC: sendClearHighlights");
Simon Hunt8e258112017-05-05 13:19:04 -070085 msgHandler.sendHighlights(new Highlights());
Simon Hunt1911fe42017-05-02 18:25:58 -070086 }
87
Simon Hunt9e2413e2017-05-03 14:25:40 -070088
89 // NOTE: currently this monitor holds no state - nothing to do for these...
90 @Override
91 protected void sendDeviceLinkFlows() {
92 }
93
94 @Override
95 protected void sendSelectedIntentTraffic() {
Sean Condonadeb7162019-04-13 20:56:14 +010096 log.debug("sendSelectedIntentTraffic: {}", selectedIntents);
97 msgHandler.sendHighlights(intentTraffic());
Simon Hunt9e2413e2017-05-03 14:25:40 -070098 }
99
Simon Hunt1911fe42017-05-02 18:25:58 -0700100 @Override
101 protected void clearSelection() {
Sean Condonf9ff66a2020-03-23 08:40:55 +0000102 selectedNodes = null;
103 selectedIntents = null;
Simon Hunt1911fe42017-05-02 18:25:58 -0700104 }
Simon Hunta7aea842017-05-03 19:42:50 -0700105
106 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107 // -- link aggregation
108
109
110 @Override
111 protected Set<TrafficLink> doAggregation(Set<TrafficLink> linksWithTraffic) {
Simon Hunta7aea842017-05-03 19:42:50 -0700112 log.debug("Need to aggregate {} links", linksWithTraffic.size());
113
Simon Hunt0e161092017-05-08 17:41:38 -0700114 // first, retrieve from the shared topology model those synth links that
115 // are part of the region currently being viewed by the user...
116 Map<UiLinkId, UiSynthLink> synthLinkMap =
117 msgHandler.retrieveRelevantSynthLinks();
118
119 // NOTE: compute Set<TrafficLink> which represents the consolidated links
120
121 Map<UiLinkId, TrafficLink> mappedByUiLinkId = new HashMap<>();
122
123 for (TrafficLink tl : linksWithTraffic) {
Simon Hunt05eba352017-05-11 20:17:08 -0700124 UiLinkId tlid = uiLinkId(tl.key());
Simon Hunt0e161092017-05-08 17:41:38 -0700125 UiSynthLink sl = synthLinkMap.get(tlid);
126 if (sl != null) {
127 UiLinkId aggrid = sl.link().id();
Simon Hunt05eba352017-05-11 20:17:08 -0700128 TrafficLink aggregated =
129 mappedByUiLinkId.computeIfAbsent(aggrid, TrafficLink::new);
130 aggregated.mergeStats(tl);
Simon Hunt0e161092017-05-08 17:41:38 -0700131 }
132 }
133
134 Set<TrafficLink> result = new HashSet<>();
135 result.addAll(mappedByUiLinkId.values());
136 return result;
Simon Hunta7aea842017-05-03 19:42:50 -0700137 }
Simon Hunt1911fe42017-05-02 18:25:58 -0700138}