Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | package org.onlab.onos.gui; |
| 17 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 21 | import org.eclipse.jetty.websocket.WebSocket; |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 22 | import org.onlab.onos.cluster.ClusterEvent; |
| 23 | import org.onlab.onos.cluster.ClusterEventListener; |
| 24 | import org.onlab.onos.cluster.ControllerNode; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 25 | import org.onlab.onos.core.ApplicationId; |
| 26 | import org.onlab.onos.core.CoreService; |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 27 | import org.onlab.onos.event.AbstractEventAccumulator; |
| 28 | import org.onlab.onos.event.Event; |
| 29 | import org.onlab.onos.event.EventAccumulator; |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 30 | import org.onlab.onos.mastership.MastershipEvent; |
| 31 | import org.onlab.onos.mastership.MastershipListener; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 32 | import org.onlab.onos.net.ConnectPoint; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 33 | import org.onlab.onos.net.Device; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 34 | import org.onlab.onos.net.Host; |
| 35 | import org.onlab.onos.net.HostId; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 36 | import org.onlab.onos.net.HostLocation; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 37 | import org.onlab.onos.net.Link; |
| 38 | import org.onlab.onos.net.device.DeviceEvent; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 39 | import org.onlab.onos.net.device.DeviceListener; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 40 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 41 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 42 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 43 | import org.onlab.onos.net.flow.FlowRuleListener; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 44 | import org.onlab.onos.net.flow.TrafficSelector; |
| 45 | import org.onlab.onos.net.flow.TrafficTreatment; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 46 | import org.onlab.onos.net.host.HostEvent; |
| 47 | import org.onlab.onos.net.host.HostListener; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 48 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 49 | import org.onlab.onos.net.intent.Intent; |
| 50 | import org.onlab.onos.net.intent.IntentEvent; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 51 | import org.onlab.onos.net.intent.IntentListener; |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 52 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 53 | import org.onlab.onos.net.link.LinkEvent; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 54 | import org.onlab.onos.net.link.LinkListener; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 55 | import org.onlab.osgi.ServiceDirectory; |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 56 | import org.onlab.packet.Ethernet; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 57 | |
| 58 | import java.io.IOException; |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 59 | import java.util.ArrayList; |
| 60 | import java.util.Collections; |
| 61 | import java.util.Comparator; |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 62 | import java.util.HashSet; |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 63 | import java.util.List; |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 64 | import java.util.Set; |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 65 | import java.util.Timer; |
| 66 | import java.util.TimerTask; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 67 | |
Thomas Vachuska | e7591e5 | 2014-11-13 21:31:15 -0800 | [diff] [blame] | 68 | import static com.google.common.base.Strings.isNullOrEmpty; |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 69 | import static org.onlab.onos.cluster.ClusterEvent.Type.INSTANCE_ADDED; |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 70 | import static org.onlab.onos.net.DeviceId.deviceId; |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 71 | import static org.onlab.onos.net.HostId.hostId; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 72 | import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_ADDED; |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 73 | import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_UPDATED; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 74 | import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 75 | import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 76 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Web socket capable of interacting with the GUI topology view. |
| 79 | */ |
Thomas Vachuska | 7c27ad7 | 2014-11-14 16:20:10 -0800 | [diff] [blame] | 80 | public class TopologyViewWebSocket |
| 81 | extends TopologyViewMessages |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 82 | implements WebSocket.OnTextMessage, WebSocket.OnControl { |
| 83 | |
| 84 | private static final long MAX_AGE_MS = 15000; |
| 85 | |
| 86 | private static final byte PING = 0x9; |
| 87 | private static final byte PONG = 0xA; |
| 88 | private static final byte[] PING_DATA = new byte[]{(byte) 0xde, (byte) 0xad}; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 89 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 90 | private static final String APP_ID = "org.onlab.onos.gui"; |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 91 | |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 92 | private static final long TRAFFIC_FREQUENCY_SEC = 2000; |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 93 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 94 | private static final Comparator<? super ControllerNode> NODE_COMPARATOR = |
| 95 | new Comparator<ControllerNode>() { |
| 96 | @Override |
| 97 | public int compare(ControllerNode o1, ControllerNode o2) { |
| 98 | return o1.id().toString().compareTo(o2.id().toString()); |
| 99 | } |
| 100 | }; |
| 101 | |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 102 | |
| 103 | private final Timer timer = new Timer("topology-view"); |
| 104 | |
| 105 | private static final int MAX_EVENTS = 500; |
| 106 | private static final int MAX_BATCH_MS = 1000; |
| 107 | private static final int MAX_IDLE_MS = 500; |
| 108 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 109 | private final ApplicationId appId; |
Thomas Vachuska | d472c6e | 2014-11-07 19:11:05 -0800 | [diff] [blame] | 110 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 111 | private Connection connection; |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 112 | private FrameConnection control; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 113 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 114 | private final ClusterEventListener clusterListener = new InternalClusterListener(); |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 115 | private final MastershipListener mastershipListener = new InternalMastershipListener(); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 116 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 117 | private final LinkListener linkListener = new InternalLinkListener(); |
| 118 | private final HostListener hostListener = new InternalHostListener(); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 119 | private final IntentListener intentListener = new InternalIntentListener(); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 120 | private final FlowRuleListener flowListener = new InternalFlowListener(); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 121 | |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 122 | private final EventAccumulator eventAccummulator = new InternalEventAccummulator(); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 123 | |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 124 | private boolean summaryEnabled = true; |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 125 | private TimerTask trafficTask; |
| 126 | private ObjectNode trafficEvent; |
| 127 | |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 128 | private long lastActive = System.currentTimeMillis(); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 129 | private boolean listenersRemoved = false; |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 130 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 131 | private TopologyViewIntentFilter intentFilter; |
| 132 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Creates a new web-socket for serving data to GUI topology view. |
| 135 | * |
| 136 | * @param directory service directory |
| 137 | */ |
Thomas Vachuska | 7c27ad7 | 2014-11-14 16:20:10 -0800 | [diff] [blame] | 138 | public TopologyViewWebSocket(ServiceDirectory directory) { |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 139 | super(directory); |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 140 | intentFilter = new TopologyViewIntentFilter(intentService, deviceService, |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 141 | hostService, linkService); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 142 | appId = directory.get(CoreService.class).registerApplication(APP_ID); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Issues a close on the connection. |
| 147 | */ |
| 148 | synchronized void close() { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 149 | removeListeners(); |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 150 | if (connection.isOpen()) { |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 151 | connection.close(); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Indicates if this connection is idle. |
Thomas Vachuska | 3266abf | 2014-11-13 09:28:46 -0800 | [diff] [blame] | 157 | * |
| 158 | * @return true if idle or closed |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 159 | */ |
| 160 | synchronized boolean isIdle() { |
| 161 | boolean idle = (System.currentTimeMillis() - lastActive) > MAX_AGE_MS; |
| 162 | if (idle || !connection.isOpen()) { |
| 163 | return true; |
| 164 | } |
| 165 | try { |
| 166 | control.sendControl(PING, PING_DATA, 0, PING_DATA.length); |
| 167 | } catch (IOException e) { |
| 168 | log.warn("Unable to send ping message due to: ", e); |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 173 | @Override |
| 174 | public void onOpen(Connection connection) { |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 175 | log.info("GUI client connected"); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 176 | this.connection = connection; |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 177 | this.control = (FrameConnection) connection; |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 178 | addListeners(); |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 179 | |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 180 | sendAllInstances(null); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 181 | sendAllDevices(); |
| 182 | sendAllLinks(); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 183 | sendAllHosts(); |
| 184 | } |
| 185 | |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 186 | @Override |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 187 | public synchronized void onClose(int closeCode, String message) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 188 | removeListeners(); |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 189 | timer.cancel(); |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 190 | log.info("GUI client disconnected"); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public boolean onControl(byte controlCode, byte[] data, int offset, int length) { |
| 195 | lastActive = System.currentTimeMillis(); |
| 196 | return true; |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void onMessage(String data) { |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 201 | lastActive = System.currentTimeMillis(); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 202 | try { |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 203 | processMessage((ObjectNode) mapper.reader().readTree(data)); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 204 | } catch (Exception e) { |
Thomas Vachuska | 0f6baee | 2014-11-11 15:02:32 -0800 | [diff] [blame] | 205 | log.warn("Unable to parse GUI request {} due to {}", data, e); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 206 | log.warn("Boom!!!!", e); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 207 | } |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 210 | // Processes the specified event. |
| 211 | private void processMessage(ObjectNode event) { |
| 212 | String type = string(event, "event", "unknown"); |
| 213 | if (type.equals("requestDetails")) { |
| 214 | requestDetails(event); |
| 215 | } else if (type.equals("updateMeta")) { |
| 216 | updateMetaUi(event); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 217 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 218 | } else if (type.equals("addHostIntent")) { |
| 219 | createHostIntent(event); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 220 | } else if (type.equals("addMultiSourceIntent")) { |
| 221 | createMultiSourceIntent(event); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 222 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 223 | } else if (type.equals("requestTraffic")) { |
| 224 | requestTraffic(event); |
| 225 | } else if (type.equals("requestAllTraffic")) { |
| 226 | requestAllTraffic(event); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 227 | } else if (type.equals("requestDeviceLinkFlows")) { |
| 228 | requestDeviceLinkFlows(event); |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 229 | } else if (type.equals("cancelTraffic")) { |
| 230 | cancelTraffic(event); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 231 | |
| 232 | } else if (type.equals("requestSummary")) { |
| 233 | requestSummary(event); |
| 234 | } else if (type.equals("cancelSummary")) { |
| 235 | cancelSummary(event); |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 239 | // Sends the specified data to the client. |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 240 | private synchronized void sendMessage(ObjectNode data) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 241 | try { |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 242 | if (connection.isOpen()) { |
| 243 | connection.sendMessage(data.toString()); |
| 244 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 245 | } catch (IOException e) { |
Thomas Vachuska | ba5621e | 2014-11-12 01:47:19 -0800 | [diff] [blame] | 246 | log.warn("Unable to send message {} to GUI due to {}", data, e); |
Thomas Vachuska | d1be50d | 2014-11-08 16:10:20 -0800 | [diff] [blame] | 247 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 250 | // Sends all controller nodes to the client as node-added messages. |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 251 | private void sendAllInstances(String messageType) { |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 252 | List<ControllerNode> nodes = new ArrayList<>(clusterService.getNodes()); |
| 253 | Collections.sort(nodes, NODE_COMPARATOR); |
| 254 | for (ControllerNode node : nodes) { |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 255 | sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node), |
| 256 | messageType)); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 257 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 260 | // Sends all devices to the client as device-added messages. |
| 261 | private void sendAllDevices() { |
| 262 | for (Device device : deviceService.getDevices()) { |
| 263 | sendMessage(deviceMessage(new DeviceEvent(DEVICE_ADDED, device))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 264 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 267 | // Sends all links to the client as link-added messages. |
| 268 | private void sendAllLinks() { |
| 269 | for (Link link : linkService.getLinks()) { |
| 270 | sendMessage(linkMessage(new LinkEvent(LINK_ADDED, link))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 271 | } |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | // Sends all hosts to the client as host-added messages. |
| 275 | private void sendAllHosts() { |
| 276 | for (Host host : hostService.getHosts()) { |
| 277 | sendMessage(hostMessage(new HostEvent(HOST_ADDED, host))); |
| 278 | } |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // Sends back device or host details. |
Thomas Vachuska | f1fae00 | 2014-11-11 18:22:02 -0800 | [diff] [blame] | 282 | private void requestDetails(ObjectNode event) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 283 | ObjectNode payload = payload(event); |
Thomas Vachuska | f1fae00 | 2014-11-11 18:22:02 -0800 | [diff] [blame] | 284 | String type = string(payload, "class", "unknown"); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 285 | long sid = number(event, "sid"); |
| 286 | |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 287 | if (type.equals("device")) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 288 | sendMessage(deviceDetails(deviceId(string(payload, "id")), sid)); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 289 | } else if (type.equals("host")) { |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 290 | sendMessage(hostDetails(hostId(string(payload, "id")), sid)); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 294 | |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 295 | // Creates host-to-host intent. |
| 296 | private void createHostIntent(ObjectNode event) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 297 | ObjectNode payload = payload(event); |
| 298 | long id = number(event, "sid"); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 299 | // TODO: add protection against device ids and non-existent hosts. |
| 300 | HostId one = hostId(string(payload, "one")); |
| 301 | HostId two = hostId(string(payload, "two")); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 302 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 303 | HostToHostIntent intent = |
| 304 | new HostToHostIntent(appId, one, two, |
| 305 | DefaultTrafficSelector.builder().build(), |
| 306 | DefaultTrafficTreatment.builder().build()); |
| 307 | startMonitoring(event); |
| 308 | intentService.submit(intent); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 311 | // Creates multi-source-to-single-dest intent. |
| 312 | private void createMultiSourceIntent(ObjectNode event) { |
| 313 | ObjectNode payload = payload(event); |
| 314 | long id = number(event, "sid"); |
| 315 | // TODO: add protection against device ids and non-existent hosts. |
| 316 | Set<HostId> src = getHostIds((ArrayNode) payload.path("src")); |
| 317 | HostId dst = hostId(string(payload, "dst")); |
| 318 | Host dstHost = hostService.getHost(dst); |
| 319 | |
| 320 | Set<ConnectPoint> ingressPoints = getHostLocations(src); |
| 321 | |
| 322 | // FIXME: clearly, this is not enough |
| 323 | TrafficSelector selector = DefaultTrafficSelector.builder() |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 324 | .matchEthType(Ethernet.TYPE_IPV4) |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 325 | .matchEthDst(dstHost.mac()).build(); |
| 326 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 327 | |
| 328 | MultiPointToSinglePointIntent intent = |
| 329 | new MultiPointToSinglePointIntent(appId, selector, treatment, |
| 330 | ingressPoints, dstHost.location()); |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 331 | startMonitoring(event); |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 332 | intentService.submit(intent); |
| 333 | } |
| 334 | |
| 335 | private Set<ConnectPoint> getHostLocations(Set<HostId> hostIds) { |
| 336 | Set<ConnectPoint> points = new HashSet<>(); |
| 337 | for (HostId hostId : hostIds) { |
| 338 | points.add(getHostLocation(hostId)); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 339 | } |
Thomas Vachuska | 9edca30 | 2014-11-22 17:06:42 -0800 | [diff] [blame] | 340 | return points; |
| 341 | } |
| 342 | |
| 343 | private HostLocation getHostLocation(HostId hostId) { |
| 344 | return hostService.getHost(hostId).location(); |
| 345 | } |
| 346 | |
| 347 | // Produces a list of host ids from the specified JSON array. |
| 348 | private Set<HostId> getHostIds(ArrayNode ids) { |
| 349 | Set<HostId> hostIds = new HashSet<>(); |
| 350 | for (JsonNode id : ids) { |
| 351 | hostIds.add(hostId(id.asText())); |
| 352 | } |
| 353 | return hostIds; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | private synchronized long startMonitoring(ObjectNode event) { |
| 358 | if (trafficTask != null) { |
| 359 | stopMonitoring(); |
| 360 | } |
| 361 | trafficEvent = event; |
| 362 | trafficTask = new TrafficMonitor(); |
| 363 | timer.schedule(trafficTask, TRAFFIC_FREQUENCY_SEC, TRAFFIC_FREQUENCY_SEC); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 364 | return number(event, "sid"); |
| 365 | } |
| 366 | |
| 367 | private synchronized void stopMonitoring() { |
| 368 | if (trafficTask != null) { |
| 369 | trafficTask.cancel(); |
| 370 | trafficTask = null; |
| 371 | trafficEvent = null; |
| 372 | } |
| 373 | } |
| 374 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 375 | // Subscribes for host traffic messages. |
| 376 | private synchronized void requestAllTraffic(ObjectNode event) { |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 377 | long sid = startMonitoring(event); |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 378 | sendMessage(trafficSummaryMessage(sid)); |
| 379 | } |
| 380 | |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 381 | private void requestDeviceLinkFlows(ObjectNode event) { |
| 382 | ObjectNode payload = payload(event); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 383 | long sid = startMonitoring(event); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 384 | |
| 385 | // Get the set of selected hosts and their intents. |
| 386 | ArrayNode ids = (ArrayNode) payload.path("ids"); |
| 387 | Set<Host> hosts = new HashSet<>(); |
| 388 | Set<Device> devices = getDevices(ids); |
| 389 | |
| 390 | // If there is a hover node, include it in the hosts and find intents. |
| 391 | String hover = string(payload, "hover"); |
Thomas Vachuska | 29617e5 | 2014-11-20 03:17:46 -0800 | [diff] [blame] | 392 | if (!isNullOrEmpty(hover)) { |
| 393 | addHover(hosts, devices, hover); |
| 394 | } |
| 395 | sendMessage(flowSummaryMessage(sid, devices)); |
| 396 | } |
| 397 | |
| 398 | |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 399 | // Subscribes for host traffic messages. |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 400 | private synchronized void requestTraffic(ObjectNode event) { |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 401 | ObjectNode payload = payload(event); |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 402 | if (!payload.has("ids")) { |
| 403 | return; |
| 404 | } |
| 405 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 406 | long sid = startMonitoring(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 407 | |
Thomas Vachuska | e7591e5 | 2014-11-13 21:31:15 -0800 | [diff] [blame] | 408 | // Get the set of selected hosts and their intents. |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 409 | ArrayNode ids = (ArrayNode) payload.path("ids"); |
| 410 | Set<Host> hosts = getHosts(ids); |
| 411 | Set<Device> devices = getDevices(ids); |
| 412 | Set<Intent> intents = intentFilter.findPathIntents(hosts, devices); |
Thomas Vachuska | e7591e5 | 2014-11-13 21:31:15 -0800 | [diff] [blame] | 413 | |
| 414 | // If there is a hover node, include it in the hosts and find intents. |
| 415 | String hover = string(payload, "hover"); |
| 416 | Set<Intent> hoverIntents; |
| 417 | if (!isNullOrEmpty(hover)) { |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 418 | addHover(hosts, devices, hover); |
| 419 | hoverIntents = intentFilter.findPathIntents(hosts, devices); |
Thomas Vachuska | e7591e5 | 2014-11-13 21:31:15 -0800 | [diff] [blame] | 420 | intents.removeAll(hoverIntents); |
| 421 | |
| 422 | // Send an initial message to highlight all links of all monitored intents. |
| 423 | sendMessage(trafficMessage(sid, |
| 424 | new TrafficClass("primary", hoverIntents), |
| 425 | new TrafficClass("secondary", intents))); |
| 426 | |
| 427 | } else { |
| 428 | // Send an initial message to highlight all links of all monitored intents. |
| 429 | sendMessage(trafficMessage(sid, new TrafficClass("primary", intents))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | // Cancels sending traffic messages. |
| 434 | private void cancelTraffic(ObjectNode event) { |
Thomas Vachuska | e7591e5 | 2014-11-13 21:31:15 -0800 | [diff] [blame] | 435 | sendMessage(trafficMessage(number(event, "sid"))); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 436 | stopMonitoring(); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 439 | |
| 440 | // Subscribes for summary messages. |
| 441 | private synchronized void requestSummary(ObjectNode event) { |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 442 | summaryEnabled = true; |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 443 | sendMessage(summmaryMessage(number(event, "sid"))); |
| 444 | } |
| 445 | |
| 446 | // Cancels sending summary messages. |
| 447 | private synchronized void cancelSummary(ObjectNode event) { |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 448 | summaryEnabled = false; |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 452 | // Adds all internal listeners. |
| 453 | private void addListeners() { |
| 454 | clusterService.addListener(clusterListener); |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 455 | mastershipService.addListener(mastershipListener); |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 456 | deviceService.addListener(deviceListener); |
| 457 | linkService.addListener(linkListener); |
| 458 | hostService.addListener(hostListener); |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 459 | intentService.addListener(intentListener); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 460 | flowService.addListener(flowListener); |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // Removes all internal listeners. |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 464 | private synchronized void removeListeners() { |
| 465 | if (!listenersRemoved) { |
| 466 | listenersRemoved = true; |
| 467 | clusterService.removeListener(clusterListener); |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 468 | mastershipService.removeListener(mastershipListener); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 469 | deviceService.removeListener(deviceListener); |
| 470 | linkService.removeListener(linkListener); |
| 471 | hostService.removeListener(hostListener); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 472 | intentService.removeListener(intentListener); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 473 | flowService.removeListener(flowListener); |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 474 | } |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | // Cluster event listener. |
| 478 | private class InternalClusterListener implements ClusterEventListener { |
| 479 | @Override |
| 480 | public void event(ClusterEvent event) { |
Thomas Vachuska | e02e11c | 2014-11-24 16:13:52 -0800 | [diff] [blame] | 481 | sendMessage(instanceMessage(event, null)); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | // Mastership change listener |
| 486 | private class InternalMastershipListener implements MastershipListener { |
| 487 | @Override |
| 488 | public void event(MastershipEvent event) { |
| 489 | sendAllInstances("updateInstance"); |
| 490 | Device device = deviceService.getDevice(event.subject()); |
| 491 | sendMessage(deviceMessage(new DeviceEvent(DEVICE_UPDATED, device))); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 495 | // Device event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 496 | private class InternalDeviceListener implements DeviceListener { |
| 497 | @Override |
| 498 | public void event(DeviceEvent event) { |
| 499 | sendMessage(deviceMessage(event)); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 500 | eventAccummulator.add(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 504 | // Link event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 505 | private class InternalLinkListener implements LinkListener { |
| 506 | @Override |
| 507 | public void event(LinkEvent event) { |
| 508 | sendMessage(linkMessage(event)); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 509 | eventAccummulator.add(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 513 | // Host event listener. |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 514 | private class InternalHostListener implements HostListener { |
| 515 | @Override |
| 516 | public void event(HostEvent event) { |
| 517 | sendMessage(hostMessage(event)); |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 518 | eventAccummulator.add(event); |
Thomas Vachuska | 690e5f6 | 2014-11-09 08:26:47 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 522 | // Intent event listener. |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 523 | private class InternalIntentListener implements IntentListener { |
| 524 | @Override |
| 525 | public void event(IntentEvent event) { |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 526 | if (trafficEvent != null) { |
| 527 | requestTraffic(trafficEvent); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 528 | } |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 529 | eventAccummulator.add(event); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | // Intent event listener. |
| 534 | private class InternalFlowListener implements FlowRuleListener { |
| 535 | @Override |
| 536 | public void event(FlowRuleEvent event) { |
| 537 | eventAccummulator.add(event); |
Thomas Vachuska | 4830d39 | 2014-11-09 17:09:56 -0800 | [diff] [blame] | 538 | } |
| 539 | } |
Thomas Vachuska | a7c3dd1 | 2014-11-11 09:10:19 -0800 | [diff] [blame] | 540 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 541 | private class TrafficMonitor extends TimerTask { |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 542 | @Override |
| 543 | public void run() { |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 544 | try { |
| 545 | if (trafficEvent != null) { |
| 546 | String type = string(trafficEvent, "event", "unknown"); |
| 547 | if (type.equals("requestAllTraffic")) { |
| 548 | requestAllTraffic(trafficEvent); |
| 549 | } else if (type.equals("requestDeviceLinkFlows")) { |
| 550 | requestDeviceLinkFlows(trafficEvent); |
| 551 | } else { |
| 552 | requestTraffic(trafficEvent); |
| 553 | } |
Thomas Vachuska | 5fedb7a | 2014-11-20 00:55:08 -0800 | [diff] [blame] | 554 | } |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 555 | } catch (Exception e) { |
| 556 | log.warn("Unable to handle traffic request due to {}", e.getMessage()); |
Thomas Vachuska | 22e3492 | 2014-11-14 00:40:55 -0800 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | } |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 560 | |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 561 | // Accummulates events to drive methodic update of the summary pane. |
| 562 | private class InternalEventAccummulator extends AbstractEventAccumulator { |
| 563 | protected InternalEventAccummulator() { |
| 564 | super(new Timer("topo-summary"), MAX_EVENTS, MAX_BATCH_MS, MAX_IDLE_MS); |
| 565 | } |
| 566 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 567 | @Override |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 568 | public void processEvents(List<Event> events) { |
| 569 | try { |
| 570 | if (summaryEnabled) { |
| 571 | sendMessage(summmaryMessage(0)); |
| 572 | } |
| 573 | } catch (Exception e) { |
| 574 | log.warn("Unable to handle summary request due to {}", e.getMessage()); |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 575 | } |
Thomas Vachuska | 5bde31f | 2014-11-25 15:29:18 -0800 | [diff] [blame^] | 576 | |
Thomas Vachuska | 47635c6 | 2014-11-22 01:21:36 -0800 | [diff] [blame] | 577 | } |
| 578 | } |
Thomas Vachuska | 7d638d3 | 2014-11-07 10:24:43 -0800 | [diff] [blame] | 579 | } |
| 580 | |