chengfan
Committed by Thomas Vachuska

[ONOS-2096] Let GUI support tunnel

1.add a tunnelEndPoint formatter.
2.let the tunnel page show bandwidth.
3.optimize some codes.

Change-Id: I57583f915c23e65b27b328292c9690237eba6a69
1 +package org.onosproject.incubator.net.tunnel;
2 +
3 +
4 +import org.onosproject.ui.table.CellFormatter;
5 +import org.onosproject.ui.table.cell.AbstractCellFormatter;
6 +
7 +/**
8 + * Formats a optical tunnel endpoint as "(type)/(element-id)/(port)".
9 + * Formats a ip tunnel endpoint as "ip".
10 + */
11 +public final class TunnelEndPointFormatter extends AbstractCellFormatter {
12 + //non-instantiable
13 + private TunnelEndPointFormatter() {
14 + }
15 +
16 + @Override
17 + protected String nonNullFormat(Object value) {
18 +
19 + if (value instanceof DefaultOpticalTunnelEndPoint) {
20 + DefaultOpticalTunnelEndPoint cp = (DefaultOpticalTunnelEndPoint) value;
21 + return cp.type() + "/" + cp.elementId().get() + "/" + cp.portNumber().get();
22 + } else if (value instanceof IpTunnelEndPoint) {
23 + IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
24 + return cp.ip().toString();
25 + }
26 + return "";
27 + }
28 +
29 + /**
30 + * An instance of this class.
31 + */
32 + public static final CellFormatter INSTANCE = new TunnelEndPointFormatter();
33 +}
...@@ -3,6 +3,7 @@ package org.onosproject.ui.impl; ...@@ -3,6 +3,7 @@ package org.onosproject.ui.impl;
3 import com.fasterxml.jackson.databind.node.ObjectNode; 3 import com.fasterxml.jackson.databind.node.ObjectNode;
4 import com.google.common.collect.ImmutableSet; 4 import com.google.common.collect.ImmutableSet;
5 import org.onosproject.incubator.net.tunnel.Tunnel; 5 import org.onosproject.incubator.net.tunnel.Tunnel;
6 +import org.onosproject.incubator.net.tunnel.TunnelEndPointFormatter;
6 import org.onosproject.incubator.net.tunnel.TunnelService; 7 import org.onosproject.incubator.net.tunnel.TunnelService;
7 import org.onosproject.ui.RequestHandler; 8 import org.onosproject.ui.RequestHandler;
8 import org.onosproject.ui.UiMessageHandler; 9 import org.onosproject.ui.UiMessageHandler;
...@@ -52,6 +53,8 @@ public class TunnelViewMessageHandler extends UiMessageHandler { ...@@ -52,6 +53,8 @@ public class TunnelViewMessageHandler extends UiMessageHandler {
52 protected TableModel createTableModel() { 53 protected TableModel createTableModel() {
53 TableModel tm = super.createTableModel(); 54 TableModel tm = super.createTableModel();
54 //TODO add more formater class so that we can get a more readable table 55 //TODO add more formater class so that we can get a more readable table
56 + tm.setFormatter(ONE, TunnelEndPointFormatter.INSTANCE);
57 + tm.setFormatter(TWO, TunnelEndPointFormatter.INSTANCE);
55 tm.setFormatter(TYPE, EnumFormatter.INSTANCE); 58 tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
56 return tm; 59 return tm;
57 } 60 }
...@@ -59,9 +62,7 @@ public class TunnelViewMessageHandler extends UiMessageHandler { ...@@ -59,9 +62,7 @@ public class TunnelViewMessageHandler extends UiMessageHandler {
59 @Override 62 @Override
60 protected void populateTable(TableModel tm, ObjectNode payload) { 63 protected void populateTable(TableModel tm, ObjectNode payload) {
61 TunnelService ts = get(TunnelService.class); 64 TunnelService ts = get(TunnelService.class);
62 - ts.queryAllTunnels().forEach(tunnel -> { 65 + ts.queryAllTunnels().forEach(tunnel -> populateRow(tm.addRow(), tunnel));
63 - populateRow(tm.addRow(), tunnel);
64 - });
65 } 66 }
66 67
67 } 68 }
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
61 <td>{{tunnel.two}}</td> 61 <td>{{tunnel.two}}</td>
62 <td>{{tunnel.type}}</td> 62 <td>{{tunnel.type}}</td>
63 <td>{{tunnel.group_id}}</td> 63 <td>{{tunnel.group_id}}</td>
64 + <td>{{tunnel.bandwidth}}</td>
64 <td>{{tunnel.path}}</td> 65 <td>{{tunnel.path}}</td>
65 </tr> 66 </tr>
66 </table> 67 </table>
......