blob: c0d21544c42ca05a5f14c705fedac3e86c97a70a [file] [log] [blame]
Thomas Vachuska88716912015-11-13 08:15:01 -08001/*
2 * Copyright 2014-2015 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
17package org.onosproject.byon.gui;
18
19import com.fasterxml.jackson.databind.node.ArrayNode;
20import com.fasterxml.jackson.databind.node.ObjectNode;
21import com.google.common.base.Strings;
22import com.google.common.collect.ImmutableSet;
23import org.onlab.osgi.ServiceDirectory;
24import org.onos.byon.NetworkService;
25import org.onosproject.net.Device;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.Host;
28import org.onosproject.net.HostId;
29import org.onosproject.net.Link;
30import org.onosproject.net.device.DeviceService;
31import org.onosproject.net.host.HostService;
32import org.onosproject.net.link.LinkService;
33import org.onosproject.ui.RequestHandler;
34import org.onosproject.ui.UiConnection;
35import org.onosproject.ui.UiMessageHandler;
36import org.onosproject.ui.topo.DeviceHighlight;
37import org.onosproject.ui.topo.Highlights;
38import org.onosproject.ui.topo.NodeBadge;
39import org.onosproject.ui.topo.TopoJson;
40
41import java.util.Collection;
42import java.util.HashSet;
43import java.util.Set;
44import java.util.TimerTask;
45
46/**
47 * Message handler for Network topology overlay events.
48 */
49public class NetworkOverlayMessageHandler extends UiMessageHandler {
50
51 private static final String BYON_FETCH_NETWORKS_REQ = "byonFetchNetworksRequest";
52 private static final String BYON_FETCH_NETWORKS_RESP = "byonFetchNetworksResponse";
53
54 private static final String NETWORKS = "networks";
55
56 private NetworkService networkService;
57 private HostService hostService1;
58
59 @Override
60 public void init(UiConnection connection, ServiceDirectory directory) {
61 super.init(connection, directory);
62 networkService = directory.get(NetworkService.class);
63 hostService1 = get(HostService.class);
64 }
65
66 @Override
67 protected Collection<RequestHandler> createRequestHandlers() {
68 return ImmutableSet.of(
69 new FetchNetworksHandler()
70 );
71 }
72
73 // === -------------------------
74 // === Handler classes
75
76 private class FetchNetworksHandler extends RequestHandler {
77 public FetchNetworksHandler() {
78 super(BYON_FETCH_NETWORKS_REQ);
79 }
80
81 @Override
82 public void process(long sid, ObjectNode payload) {
83 ObjectNode rootNode = objectNode();
84 ArrayNode networks = arrayNode();
85 rootNode.set(NETWORKS, networks);
86
87 for (String name : networkService.getNetworks()) {
88 networks.add(networkData(name));
89 }
90 sendMessage(BYON_FETCH_NETWORKS_RESP, 0, rootNode);
91 }
92
93 private ObjectNode networkData(String name) {
94 return objectNode()
95 .put("name", name)
96 .put("hostCount", networkService.getHosts(name).size());
97 }
98
99 }
100}