Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 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 | |
| 18 | package org.onosproject.ui.impl.topo; |
| 19 | |
| 20 | import org.onosproject.ui.impl.TrafficMonitorBase; |
| 21 | import org.onosproject.ui.impl.topo.util.ServicesBundle; |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 22 | import org.onosproject.ui.impl.topo.util.TrafficLink; |
Simon Hunt | 0e16109 | 2017-05-08 17:41:38 -0700 | [diff] [blame] | 23 | import org.onosproject.ui.model.topo.UiLinkId; |
| 24 | import org.onosproject.ui.model.topo.UiSynthLink; |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 25 | import org.onosproject.ui.topo.Highlights; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
Simon Hunt | 0e16109 | 2017-05-08 17:41:38 -0700 | [diff] [blame] | 29 | import java.util.HashMap; |
| 30 | import java.util.HashSet; |
| 31 | import java.util.Map; |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 32 | import java.util.Set; |
| 33 | |
Simon Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 34 | import static org.onosproject.ui.model.topo.UiLinkId.uiLinkId; |
| 35 | |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Encapsulates the behavior of monitoring specific traffic patterns in the |
| 38 | * Topology-2 view. |
| 39 | */ |
| 40 | public class Traffic2Monitor extends TrafficMonitorBase { |
| 41 | |
| 42 | private static final Logger log = |
| 43 | LoggerFactory.getLogger(Traffic2Monitor.class); |
| 44 | |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 45 | // link back to our message handler (for outbound messages) |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 46 | private final Topo2TrafficMessageHandler msgHandler; |
| 47 | |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Constructs a traffic monitor. |
| 50 | * |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 51 | * @param trafficPeriod traffic task period in ms |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 52 | * @param servicesBundle bundle of services |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 53 | * @param msgHandler our message handler |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 54 | */ |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 55 | public Traffic2Monitor(long trafficPeriod, ServicesBundle servicesBundle, |
| 56 | Topo2TrafficMessageHandler msgHandler) { |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 57 | super(trafficPeriod, servicesBundle); |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 58 | this.msgHandler = msgHandler; |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | protected void sendAllFlowTraffic() { |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 63 | log.debug("TOPO-2-TRAFFIC: sendAllFlowTraffic"); |
Simon Hunt | 8e25811 | 2017-05-05 13:19:04 -0700 | [diff] [blame] | 64 | msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.FLOW_STATS)); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | protected void sendAllPortTrafficBits() { |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 69 | log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficBits"); |
Simon Hunt | 8e25811 | 2017-05-05 13:19:04 -0700 | [diff] [blame] | 70 | msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_STATS)); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void sendAllPortTrafficPackets() { |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 75 | log.debug("TOPO-2-TRAFFIC: sendAllPortTrafficPackets"); |
Simon Hunt | 8e25811 | 2017-05-05 13:19:04 -0700 | [diff] [blame] | 76 | msgHandler.sendHighlights(trafficSummary(TrafficLink.StatsType.PORT_PACKET_STATS)); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @Override |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 80 | protected void sendClearHighlights() { |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 81 | log.debug("TOPO-2-TRAFFIC: sendClearHighlights"); |
Simon Hunt | 8e25811 | 2017-05-05 13:19:04 -0700 | [diff] [blame] | 82 | msgHandler.sendHighlights(new Highlights()); |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Simon Hunt | 9e2413e | 2017-05-03 14:25:40 -0700 | [diff] [blame] | 85 | |
| 86 | // NOTE: currently this monitor holds no state - nothing to do for these... |
| 87 | @Override |
| 88 | protected void sendDeviceLinkFlows() { |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | protected void sendSelectedIntentTraffic() { |
| 93 | } |
| 94 | |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 95 | @Override |
| 96 | protected void clearSelection() { |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 97 | } |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 98 | |
| 99 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 100 | // -- link aggregation |
| 101 | |
| 102 | |
| 103 | @Override |
| 104 | protected Set<TrafficLink> doAggregation(Set<TrafficLink> linksWithTraffic) { |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 105 | log.debug("Need to aggregate {} links", linksWithTraffic.size()); |
| 106 | |
Simon Hunt | 0e16109 | 2017-05-08 17:41:38 -0700 | [diff] [blame] | 107 | // first, retrieve from the shared topology model those synth links that |
| 108 | // are part of the region currently being viewed by the user... |
| 109 | Map<UiLinkId, UiSynthLink> synthLinkMap = |
| 110 | msgHandler.retrieveRelevantSynthLinks(); |
| 111 | |
| 112 | // NOTE: compute Set<TrafficLink> which represents the consolidated links |
| 113 | |
| 114 | Map<UiLinkId, TrafficLink> mappedByUiLinkId = new HashMap<>(); |
| 115 | |
| 116 | for (TrafficLink tl : linksWithTraffic) { |
Simon Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 117 | UiLinkId tlid = uiLinkId(tl.key()); |
Simon Hunt | 0e16109 | 2017-05-08 17:41:38 -0700 | [diff] [blame] | 118 | UiSynthLink sl = synthLinkMap.get(tlid); |
| 119 | if (sl != null) { |
| 120 | UiLinkId aggrid = sl.link().id(); |
Simon Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 121 | TrafficLink aggregated = |
| 122 | mappedByUiLinkId.computeIfAbsent(aggrid, TrafficLink::new); |
| 123 | aggregated.mergeStats(tl); |
Simon Hunt | 0e16109 | 2017-05-08 17:41:38 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | Set<TrafficLink> result = new HashSet<>(); |
| 128 | result.addAll(mappedByUiLinkId.values()); |
| 129 | return result; |
Simon Hunt | a7aea84 | 2017-05-03 19:42:50 -0700 | [diff] [blame] | 130 | } |
Simon Hunt | 1911fe4 | 2017-05-02 18:25:58 -0700 | [diff] [blame] | 131 | } |