[ONOS-2096] Let GUI support tunnel
1. add a TunnelViewMesageHandler to handle message from the client.
2. add a tunnel view to show tunnel information on the GUI
Change-Id: I1d9a73c0e4e8ed1a55cdbef09426995989c4e76a
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TunnelViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/TunnelViewMessageHandler.java
new file mode 100644
index 0000000..c0a2725
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TunnelViewMessageHandler.java
@@ -0,0 +1,79 @@
+package org.onosproject.ui.impl;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.table.TableModel;
+import org.onosproject.ui.table.TableRequestHandler;
+import org.onosproject.ui.table.cell.EnumFormatter;
+
+import java.util.Collection;
+
+public class TunnelViewMessageHandler extends UiMessageHandler {
+ private static final String TUNNEL_DATA_REQ = "tunnelDataRequest";
+ private static final String TUNNEL_DATA_RESP = "tunnelDataResponse";
+ private static final String TUNNELS = "tunnels";
+ private static final String ID = "id";
+ private static final String NAME = "name";
+ private static final String ONE = "one";
+ private static final String TWO = "two";
+ private static final String TYPE = "type";
+ private static final String GROUP_ID = "group_id";
+
+ private static final String BANDWIDTH = "bandwidth";
+ private static final String PATH = "path";
+
+
+ private static final String[] COL_IDS = {
+ ID, NAME, ONE, TWO, TYPE, GROUP_ID,
+ BANDWIDTH, PATH
+ };
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(new TunnelDataRequestHandler());
+ }
+
+ private final class TunnelDataRequestHandler extends TableRequestHandler {
+
+ public TunnelDataRequestHandler() {
+ super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS);
+ }
+
+ @Override
+ protected String[] getColumnIds() {
+ return COL_IDS;
+ }
+
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ //TODO add more formater class so that we can get a more readable table
+ tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
+ return tm;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ TunnelService ts = get(TunnelService.class);
+ ts.queryAllTunnels().forEach(tunnel -> {
+ populateRow(tm.addRow(), tunnel);
+ });
+ }
+
+ }
+
+ private void populateRow(TableModel.Row row, Tunnel tunnel) {
+ row.cell(ID, tunnel.tunnelId().id())
+ .cell(NAME, tunnel.tunnelName().value())
+ .cell(ONE, tunnel.src())
+ .cell(TWO, tunnel.dst())
+ .cell(TYPE, tunnel.type())
+ .cell(GROUP_ID, tunnel.groupId().id())
+ .cell(BANDWIDTH, tunnel.annotations().value(BANDWIDTH))
+ .cell(PATH, tunnel.path());
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 84e9995..2bd0bb6 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -84,7 +84,9 @@
new UiViewHidden("group"),
new UiView(NETWORK, "link", "Links", "nav_links"),
new UiView(NETWORK, "host", "Hosts", "nav_hosts"),
- new UiView(NETWORK, "intent", "Intents", "nav_intents")
+ new UiView(NETWORK, "intent", "Intents", "nav_intents"),
+ //TODO add a new type of icon for tunnel
+ new UiView(NETWORK, "tunnel", "Tunnels", "nav_links")
);
UiMessageHandlerFactory messageHandlerFactory =
@@ -99,7 +101,8 @@
new IntentViewMessageHandler(),
new ApplicationViewMessageHandler(),
new SettingsViewMessageHandler(),
- new ClusterViewMessageHandler()
+ new ClusterViewMessageHandler(),
+ new TunnelViewMessageHandler()
);
UiTopoOverlayFactory topoOverlayFactory =