blob: e65a385efaf712f0b0794df9c3f2c65f7dc6a8da [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 */
chengfanb466a7e2015-08-21 09:59:29 -050016package org.onosproject.ui.impl;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import com.google.common.collect.ImmutableSet;
20import org.onosproject.incubator.net.tunnel.Tunnel;
chengfan392e8f92015-08-21 13:20:02 -050021import org.onosproject.incubator.net.tunnel.TunnelEndPointFormatter;
chengfanb466a7e2015-08-21 09:59:29 -050022import org.onosproject.incubator.net.tunnel.TunnelService;
23import org.onosproject.ui.RequestHandler;
24import org.onosproject.ui.UiMessageHandler;
25import org.onosproject.ui.table.TableModel;
26import org.onosproject.ui.table.TableRequestHandler;
27import org.onosproject.ui.table.cell.EnumFormatter;
28
29import java.util.Collection;
30
31public class TunnelViewMessageHandler extends UiMessageHandler {
32 private static final String TUNNEL_DATA_REQ = "tunnelDataRequest";
33 private static final String TUNNEL_DATA_RESP = "tunnelDataResponse";
34 private static final String TUNNELS = "tunnels";
35 private static final String ID = "id";
36 private static final String NAME = "name";
37 private static final String ONE = "one";
38 private static final String TWO = "two";
39 private static final String TYPE = "type";
40 private static final String GROUP_ID = "group_id";
41
42 private static final String BANDWIDTH = "bandwidth";
43 private static final String PATH = "path";
44
45
46 private static final String[] COL_IDS = {
47 ID, NAME, ONE, TWO, TYPE, GROUP_ID,
48 BANDWIDTH, PATH
49 };
50
51 @Override
52 protected Collection<RequestHandler> createRequestHandlers() {
53 return ImmutableSet.of(new TunnelDataRequestHandler());
54 }
55
56 private final class TunnelDataRequestHandler extends TableRequestHandler {
57
Jian Li69f66632016-01-15 12:27:42 -080058 private static final String NO_ROWS_MESSAGE = "No tunnels found";
59
chengfanb466a7e2015-08-21 09:59:29 -050060 public TunnelDataRequestHandler() {
61 super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS);
62 }
63
64 @Override
65 protected String[] getColumnIds() {
66 return COL_IDS;
67 }
68
69 @Override
Jian Li8baf4472016-01-15 15:08:09 -080070 protected String noRowsMessage(ObjectNode payload) {
Jian Li69f66632016-01-15 12:27:42 -080071 return NO_ROWS_MESSAGE;
72 }
73
74 @Override
chengfanb466a7e2015-08-21 09:59:29 -050075 protected TableModel createTableModel() {
76 TableModel tm = super.createTableModel();
77 //TODO add more formater class so that we can get a more readable table
chengfan392e8f92015-08-21 13:20:02 -050078 tm.setFormatter(ONE, TunnelEndPointFormatter.INSTANCE);
79 tm.setFormatter(TWO, TunnelEndPointFormatter.INSTANCE);
chengfanb466a7e2015-08-21 09:59:29 -050080 tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
81 return tm;
82 }
83
84 @Override
85 protected void populateTable(TableModel tm, ObjectNode payload) {
86 TunnelService ts = get(TunnelService.class);
chengfan392e8f92015-08-21 13:20:02 -050087 ts.queryAllTunnels().forEach(tunnel -> populateRow(tm.addRow(), tunnel));
chengfanb466a7e2015-08-21 09:59:29 -050088 }
89
90 }
91
92 private void populateRow(TableModel.Row row, Tunnel tunnel) {
93 row.cell(ID, tunnel.tunnelId().id())
94 .cell(NAME, tunnel.tunnelName().value())
95 .cell(ONE, tunnel.src())
96 .cell(TWO, tunnel.dst())
97 .cell(TYPE, tunnel.type())
98 .cell(GROUP_ID, tunnel.groupId().id())
99 .cell(BANDWIDTH, tunnel.annotations().value(BANDWIDTH))
100 .cell(PATH, tunnel.path());
101 }
102}