blob: 104fa95b919df1a2ac6074b2ddff90fc2149772e [file] [log] [blame]
Thomas Vachuska7d638d32014-11-07 10:24:43 -08001/*
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 */
16package org.onlab.onos.gui;
17
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080018import com.fasterxml.jackson.databind.node.ArrayNode;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080019import com.fasterxml.jackson.databind.node.ObjectNode;
Thomas Vachuska7d638d32014-11-07 10:24:43 -080020import org.eclipse.jetty.websocket.WebSocket;
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -080021import org.onlab.onos.cluster.ClusterEvent;
22import org.onlab.onos.cluster.ClusterEventListener;
23import org.onlab.onos.cluster.ControllerNode;
Thomas Vachuska4830d392014-11-09 17:09:56 -080024import org.onlab.onos.core.ApplicationId;
25import org.onlab.onos.core.CoreService;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080026import org.onlab.onos.net.Device;
Thomas Vachuska690e5f62014-11-09 08:26:47 -080027import org.onlab.onos.net.Host;
28import org.onlab.onos.net.HostId;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080029import org.onlab.onos.net.Link;
30import org.onlab.onos.net.device.DeviceEvent;
Thomas Vachuska690e5f62014-11-09 08:26:47 -080031import org.onlab.onos.net.device.DeviceListener;
Thomas Vachuska4830d392014-11-09 17:09:56 -080032import org.onlab.onos.net.flow.DefaultTrafficSelector;
33import org.onlab.onos.net.flow.DefaultTrafficTreatment;
Thomas Vachuska690e5f62014-11-09 08:26:47 -080034import org.onlab.onos.net.host.HostEvent;
35import org.onlab.onos.net.host.HostListener;
Thomas Vachuska4830d392014-11-09 17:09:56 -080036import org.onlab.onos.net.intent.HostToHostIntent;
37import org.onlab.onos.net.intent.Intent;
38import org.onlab.onos.net.intent.IntentEvent;
Thomas Vachuska4830d392014-11-09 17:09:56 -080039import org.onlab.onos.net.intent.IntentListener;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080040import org.onlab.onos.net.link.LinkEvent;
Thomas Vachuska690e5f62014-11-09 08:26:47 -080041import org.onlab.onos.net.link.LinkListener;
Thomas Vachuska7d638d32014-11-07 10:24:43 -080042import org.onlab.osgi.ServiceDirectory;
43
44import java.io.IOException;
Thomas Vachuska29617e52014-11-20 03:17:46 -080045import java.util.HashSet;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080046import java.util.Set;
Thomas Vachuska22e34922014-11-14 00:40:55 -080047import java.util.Timer;
48import java.util.TimerTask;
Thomas Vachuska7d638d32014-11-07 10:24:43 -080049
Thomas Vachuskae7591e52014-11-13 21:31:15 -080050import static com.google.common.base.Strings.isNullOrEmpty;
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -080051import static org.onlab.onos.cluster.ClusterEvent.Type.INSTANCE_ADDED;
Thomas Vachuskad1be50d2014-11-08 16:10:20 -080052import static org.onlab.onos.net.DeviceId.deviceId;
Thomas Vachuska690e5f62014-11-09 08:26:47 -080053import static org.onlab.onos.net.HostId.hostId;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080054import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_ADDED;
Thomas Vachuska4830d392014-11-09 17:09:56 -080055import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080056import static org.onlab.onos.net.link.LinkEvent.Type.LINK_ADDED;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080057
Thomas Vachuska7d638d32014-11-07 10:24:43 -080058/**
59 * Web socket capable of interacting with the GUI topology view.
60 */
Thomas Vachuska7c27ad72014-11-14 16:20:10 -080061public class TopologyViewWebSocket
62 extends TopologyViewMessages
Thomas Vachuskaba5621e2014-11-12 01:47:19 -080063 implements WebSocket.OnTextMessage, WebSocket.OnControl {
64
65 private static final long MAX_AGE_MS = 15000;
66
67 private static final byte PING = 0x9;
68 private static final byte PONG = 0xA;
69 private static final byte[] PING_DATA = new byte[]{(byte) 0xde, (byte) 0xad};
Thomas Vachuska7d638d32014-11-07 10:24:43 -080070
Thomas Vachuska4830d392014-11-09 17:09:56 -080071 private static final String APP_ID = "org.onlab.onos.gui";
Thomas Vachuska4830d392014-11-09 17:09:56 -080072
Thomas Vachuska7c27ad72014-11-14 16:20:10 -080073 private static final long TRAFFIC_FREQUENCY_SEC = 1000;
Thomas Vachuska22e34922014-11-14 00:40:55 -080074
Thomas Vachuska4830d392014-11-09 17:09:56 -080075 private final ApplicationId appId;
Thomas Vachuskad472c6e2014-11-07 19:11:05 -080076
Thomas Vachuska7d638d32014-11-07 10:24:43 -080077 private Connection connection;
Thomas Vachuskaba5621e2014-11-12 01:47:19 -080078 private FrameConnection control;
Thomas Vachuska7d638d32014-11-07 10:24:43 -080079
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -080080 private final ClusterEventListener clusterListener = new InternalClusterListener();
Thomas Vachuska690e5f62014-11-09 08:26:47 -080081 private final DeviceListener deviceListener = new InternalDeviceListener();
82 private final LinkListener linkListener = new InternalLinkListener();
83 private final HostListener hostListener = new InternalHostListener();
Thomas Vachuska4830d392014-11-09 17:09:56 -080084 private final IntentListener intentListener = new InternalIntentListener();
Thomas Vachuska690e5f62014-11-09 08:26:47 -080085
Thomas Vachuska4830d392014-11-09 17:09:56 -080086 // Intents that are being monitored for the GUI
Thomas Vachuska22e34922014-11-14 00:40:55 -080087 private ObjectNode monitorRequest;
88 private final Timer timer = new Timer("intent-traffic-monitor");
89 private final TimerTask timerTask = new IntentTrafficMonitor();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -080090
Thomas Vachuskaba5621e2014-11-12 01:47:19 -080091 private long lastActive = System.currentTimeMillis();
Thomas Vachuskadea45ff2014-11-12 18:35:46 -080092 private boolean listenersRemoved = false;
Thomas Vachuskaba5621e2014-11-12 01:47:19 -080093
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -080094 private TopologyViewIntentFilter intentFilter;
95
Thomas Vachuska7d638d32014-11-07 10:24:43 -080096 /**
97 * Creates a new web-socket for serving data to GUI topology view.
98 *
99 * @param directory service directory
100 */
Thomas Vachuska7c27ad72014-11-14 16:20:10 -0800101 public TopologyViewWebSocket(ServiceDirectory directory) {
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800102 super(directory);
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800103
104 intentFilter = new TopologyViewIntentFilter(intentService, deviceService,
105 hostService, linkService);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800106 appId = directory.get(CoreService.class).registerApplication(APP_ID);
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800107 }
108
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800109 /**
110 * Issues a close on the connection.
111 */
112 synchronized void close() {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800113 removeListeners();
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800114 if (connection.isOpen()) {
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800115 connection.close();
116 }
117 }
118
119 /**
120 * Indicates if this connection is idle.
Thomas Vachuska3266abf2014-11-13 09:28:46 -0800121 *
122 * @return true if idle or closed
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800123 */
124 synchronized boolean isIdle() {
125 boolean idle = (System.currentTimeMillis() - lastActive) > MAX_AGE_MS;
126 if (idle || !connection.isOpen()) {
127 return true;
128 }
129 try {
130 control.sendControl(PING, PING_DATA, 0, PING_DATA.length);
131 } catch (IOException e) {
132 log.warn("Unable to send ping message due to: ", e);
133 }
134 return false;
135 }
136
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800137 @Override
138 public void onOpen(Connection connection) {
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800139 log.info("GUI client connected");
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800140 this.connection = connection;
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800141 this.control = (FrameConnection) connection;
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800142 addListeners();
Thomas Vachuska22e34922014-11-14 00:40:55 -0800143 timer.schedule(timerTask, TRAFFIC_FREQUENCY_SEC, TRAFFIC_FREQUENCY_SEC);
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800144
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800145 sendAllInstances();
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800146 sendAllDevices();
147 sendAllLinks();
Thomas Vachuska4830d392014-11-09 17:09:56 -0800148 sendAllHosts();
149 }
150
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800151 @Override
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800152 public synchronized void onClose(int closeCode, String message) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800153 removeListeners();
Thomas Vachuska22e34922014-11-14 00:40:55 -0800154 timer.cancel();
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800155 log.info("GUI client disconnected");
156 }
157
158 @Override
159 public boolean onControl(byte controlCode, byte[] data, int offset, int length) {
160 lastActive = System.currentTimeMillis();
161 return true;
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800162 }
163
164 @Override
165 public void onMessage(String data) {
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800166 lastActive = System.currentTimeMillis();
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800167 try {
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800168 processMessage((ObjectNode) mapper.reader().readTree(data));
Thomas Vachuska4830d392014-11-09 17:09:56 -0800169 } catch (Exception e) {
Thomas Vachuska0f6baee2014-11-11 15:02:32 -0800170 log.warn("Unable to parse GUI request {} due to {}", data, e);
Thomas Vachuska29617e52014-11-20 03:17:46 -0800171 log.warn("Boom!!!!", e);
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800172 }
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800173 }
174
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800175 // Processes the specified event.
176 private void processMessage(ObjectNode event) {
177 String type = string(event, "event", "unknown");
178 if (type.equals("requestDetails")) {
179 requestDetails(event);
180 } else if (type.equals("updateMeta")) {
181 updateMetaUi(event);
182 } else if (type.equals("addHostIntent")) {
183 createHostIntent(event);
184 } else if (type.equals("requestTraffic")) {
185 requestTraffic(event);
186 } else if (type.equals("requestAllTraffic")) {
187 requestAllTraffic(event);
Thomas Vachuska29617e52014-11-20 03:17:46 -0800188 } else if (type.equals("requestDeviceLinkFlows")) {
189 requestDeviceLinkFlows(event);
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800190 } else if (type.equals("cancelTraffic")) {
191 cancelTraffic(event);
192 }
193 }
194
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800195 // Sends the specified data to the client.
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800196 private synchronized void sendMessage(ObjectNode data) {
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800197 try {
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800198 if (connection.isOpen()) {
199 connection.sendMessage(data.toString());
200 }
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800201 } catch (IOException e) {
Thomas Vachuskaba5621e2014-11-12 01:47:19 -0800202 log.warn("Unable to send message {} to GUI due to {}", data, e);
Thomas Vachuskad1be50d2014-11-08 16:10:20 -0800203 }
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800204 }
205
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800206 // Sends all controller nodes to the client as node-added messages.
207 private void sendAllInstances() {
208 for (ControllerNode node : clusterService.getNodes()) {
209 sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node)));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800210 }
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800211 }
212
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800213 // Sends all devices to the client as device-added messages.
214 private void sendAllDevices() {
215 for (Device device : deviceService.getDevices()) {
216 sendMessage(deviceMessage(new DeviceEvent(DEVICE_ADDED, device)));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800217 }
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800218 }
219
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800220 // Sends all links to the client as link-added messages.
221 private void sendAllLinks() {
222 for (Link link : linkService.getLinks()) {
223 sendMessage(linkMessage(new LinkEvent(LINK_ADDED, link)));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800224 }
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800225 }
226
227 // Sends all hosts to the client as host-added messages.
228 private void sendAllHosts() {
229 for (Host host : hostService.getHosts()) {
230 sendMessage(hostMessage(new HostEvent(HOST_ADDED, host)));
231 }
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800232 }
233
234 // Sends back device or host details.
Thomas Vachuskaf1fae002014-11-11 18:22:02 -0800235 private void requestDetails(ObjectNode event) {
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800236 ObjectNode payload = payload(event);
Thomas Vachuskaf1fae002014-11-11 18:22:02 -0800237 String type = string(payload, "class", "unknown");
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800238 long sid = number(event, "sid");
239
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800240 if (type.equals("device")) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800241 sendMessage(deviceDetails(deviceId(string(payload, "id")), sid));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800242 } else if (type.equals("host")) {
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800243 sendMessage(hostDetails(hostId(string(payload, "id")), sid));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800244 }
245 }
246
Thomas Vachuska4830d392014-11-09 17:09:56 -0800247 // Creates host-to-host intent.
248 private void createHostIntent(ObjectNode event) {
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800249 ObjectNode payload = payload(event);
250 long id = number(event, "sid");
Thomas Vachuska4830d392014-11-09 17:09:56 -0800251 // TODO: add protection against device ids and non-existent hosts.
252 HostId one = hostId(string(payload, "one"));
253 HostId two = hostId(string(payload, "two"));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800254
Thomas Vachuska4830d392014-11-09 17:09:56 -0800255 HostToHostIntent hostIntent = new HostToHostIntent(appId, one, two,
256 DefaultTrafficSelector.builder().build(),
257 DefaultTrafficTreatment.builder().build());
Thomas Vachuska22e34922014-11-14 00:40:55 -0800258 monitorRequest = event;
Thomas Vachuska4830d392014-11-09 17:09:56 -0800259 intentService.submit(hostIntent);
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800260 }
261
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800262 // Subscribes for host traffic messages.
263 private synchronized void requestAllTraffic(ObjectNode event) {
264 ObjectNode payload = payload(event);
265 long sid = number(event, "sid");
266 monitorRequest = event;
267 sendMessage(trafficSummaryMessage(sid));
268 }
269
Thomas Vachuska29617e52014-11-20 03:17:46 -0800270 private void requestDeviceLinkFlows(ObjectNode event) {
271 ObjectNode payload = payload(event);
272 long sid = number(event, "sid");
273 monitorRequest = event;
274
275 // Get the set of selected hosts and their intents.
276 ArrayNode ids = (ArrayNode) payload.path("ids");
277 Set<Host> hosts = new HashSet<>();
278 Set<Device> devices = getDevices(ids);
279
280 // If there is a hover node, include it in the hosts and find intents.
281 String hover = string(payload, "hover");
282 Set<Intent> hoverIntents;
283 if (!isNullOrEmpty(hover)) {
284 addHover(hosts, devices, hover);
285 }
286 sendMessage(flowSummaryMessage(sid, devices));
287 }
288
289
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800290 // Subscribes for host traffic messages.
Thomas Vachuska22e34922014-11-14 00:40:55 -0800291 private synchronized void requestTraffic(ObjectNode event) {
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800292 ObjectNode payload = payload(event);
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800293 if (!payload.has("ids")) {
294 return;
295 }
296
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800297 long sid = number(event, "sid");
Thomas Vachuska22e34922014-11-14 00:40:55 -0800298 monitorRequest = event;
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800299
Thomas Vachuskae7591e52014-11-13 21:31:15 -0800300 // Get the set of selected hosts and their intents.
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800301 ArrayNode ids = (ArrayNode) payload.path("ids");
302 Set<Host> hosts = getHosts(ids);
303 Set<Device> devices = getDevices(ids);
304 Set<Intent> intents = intentFilter.findPathIntents(hosts, devices);
Thomas Vachuskae7591e52014-11-13 21:31:15 -0800305
306 // If there is a hover node, include it in the hosts and find intents.
307 String hover = string(payload, "hover");
308 Set<Intent> hoverIntents;
309 if (!isNullOrEmpty(hover)) {
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800310 addHover(hosts, devices, hover);
311 hoverIntents = intentFilter.findPathIntents(hosts, devices);
Thomas Vachuskae7591e52014-11-13 21:31:15 -0800312 intents.removeAll(hoverIntents);
313
314 // Send an initial message to highlight all links of all monitored intents.
315 sendMessage(trafficMessage(sid,
316 new TrafficClass("primary", hoverIntents),
317 new TrafficClass("secondary", intents)));
318
319 } else {
320 // Send an initial message to highlight all links of all monitored intents.
321 sendMessage(trafficMessage(sid, new TrafficClass("primary", intents)));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800322 }
323 }
324
325 // Cancels sending traffic messages.
326 private void cancelTraffic(ObjectNode event) {
Thomas Vachuskae7591e52014-11-13 21:31:15 -0800327 sendMessage(trafficMessage(number(event, "sid")));
Thomas Vachuska22e34922014-11-14 00:40:55 -0800328 monitorRequest = null;
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800329 }
330
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800331 // Adds all internal listeners.
332 private void addListeners() {
333 clusterService.addListener(clusterListener);
334 deviceService.addListener(deviceListener);
335 linkService.addListener(linkListener);
336 hostService.addListener(hostListener);
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800337 intentService.addListener(intentListener);
338 }
339
340 // Removes all internal listeners.
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800341 private synchronized void removeListeners() {
342 if (!listenersRemoved) {
343 listenersRemoved = true;
344 clusterService.removeListener(clusterListener);
345 deviceService.removeListener(deviceListener);
346 linkService.removeListener(linkListener);
347 hostService.removeListener(hostListener);
Thomas Vachuskadea45ff2014-11-12 18:35:46 -0800348 intentService.removeListener(intentListener);
349 }
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800350 }
351
352 // Cluster event listener.
353 private class InternalClusterListener implements ClusterEventListener {
354 @Override
355 public void event(ClusterEvent event) {
356 sendMessage(instanceMessage(event));
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800357 }
358 }
359
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800360 // Device event listener.
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800361 private class InternalDeviceListener implements DeviceListener {
362 @Override
363 public void event(DeviceEvent event) {
364 sendMessage(deviceMessage(event));
365 }
366 }
367
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800368 // Link event listener.
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800369 private class InternalLinkListener implements LinkListener {
370 @Override
371 public void event(LinkEvent event) {
372 sendMessage(linkMessage(event));
373 }
374 }
375
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800376 // Host event listener.
Thomas Vachuska690e5f62014-11-09 08:26:47 -0800377 private class InternalHostListener implements HostListener {
378 @Override
379 public void event(HostEvent event) {
380 sendMessage(hostMessage(event));
381 }
382 }
383
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800384 // Intent event listener.
Thomas Vachuska4830d392014-11-09 17:09:56 -0800385 private class InternalIntentListener implements IntentListener {
386 @Override
387 public void event(IntentEvent event) {
Thomas Vachuska22e34922014-11-14 00:40:55 -0800388 if (monitorRequest != null) {
389 requestTraffic(monitorRequest);
Thomas Vachuska4830d392014-11-09 17:09:56 -0800390 }
391 }
392 }
Thomas Vachuskaa7c3dd12014-11-11 09:10:19 -0800393
Thomas Vachuska22e34922014-11-14 00:40:55 -0800394 private class IntentTrafficMonitor extends TimerTask {
395 @Override
396 public void run() {
397 if (monitorRequest != null) {
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800398 String type = string(monitorRequest, "event", "unknown");
399 if (type.equals("requestAllTraffic")) {
400 requestAllTraffic(monitorRequest);
Thomas Vachuska29617e52014-11-20 03:17:46 -0800401 } else if (type.equals("requestDeviceLinkFlows")) {
402 requestDeviceLinkFlows(monitorRequest);
Thomas Vachuska5fedb7a2014-11-20 00:55:08 -0800403 } else {
404 requestTraffic(monitorRequest);
405 }
Thomas Vachuska22e34922014-11-14 00:40:55 -0800406 }
407 }
408 }
Thomas Vachuska7d638d32014-11-07 10:24:43 -0800409}
410