Jian Li
Committed by Gerrit Code Review

[ONOS-3642] Add GUI Meter View

This implements the web GUI meter view.
Current implementation uses the group table icon for meter,
and the revised meter icon will be updated in following commit.
See ONOS-3645 for detail.

Change-Id: Iaa2e673ef83024135d757a2aaec1c31a87263217
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.DeviceId;
import org.onosproject.net.meter.Band;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.table.CellFormatter;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import java.util.Collection;
/**
* Message handler for meter view related messages.
*/
public class MeterViewMessageHandler extends UiMessageHandler {
private static final String METER_DATA_REQ = "meterDataRequest";
private static final String METER_DATA_RESP = "meterDataResponse";
private static final String METERS = "meters";
private static final String ID = "id";
private static final String APP_ID = "app_id";
private static final String STATE = "state";
private static final String PACKETS = "packets";
private static final String BYTES = "bytes";
private static final String BANDS = "bands";
private static final String[] COL_IDS = {
ID, APP_ID, STATE, PACKETS, BYTES, BANDS
};
@Override
protected Collection<RequestHandler> createRequestHandlers() {
return ImmutableSet.of(new MeterDataRequest());
}
// handler for meter table requests
private final class MeterDataRequest extends TableRequestHandler {
private MeterDataRequest() {
super(METER_DATA_REQ, METER_DATA_RESP, METERS);
}
@Override
protected String[] getColumnIds() {
return COL_IDS;
}
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setFormatter(BANDS, new BandFormatter());
return tm;
}
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
String uri = string(payload, "devId");
if (!Strings.isNullOrEmpty(uri)) {
DeviceId deviceId = DeviceId.deviceId(uri);
MeterService ms = get(MeterService.class);
for (Meter meter : ms.getMeters(deviceId)) {
populateRow(tm.addRow(), meter);
}
}
}
private void populateRow(TableModel.Row row, Meter m) {
row.cell(ID, m.id().id())
.cell(APP_ID, m.appId().name())
.cell(STATE, m.state())
.cell(PACKETS, m.packetsSeen())
.cell(BYTES, m.bytesSeen())
.cell(BANDS, m.bands());
}
private final class BandFormatter implements CellFormatter {
private static final String BREAK = "<br>";
@Override
public String format(Object value) {
StringBuilder sb = new StringBuilder();
Collection<Band> bands = (Collection<Band>) value;
if (bands.isEmpty()) {
return "(No bands for this meter)";
}
// TODO: re-arrange band properties based on band type
for (Band b : bands) {
sb.append("Bytes: ")
.append(b.bytes())
.append(" Packets: ")
.append(b.packets())
.append(" Type: ")
.append(b.type())
.append(BREAK);
}
return sb.toString();
}
}
}
}
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -83,6 +83,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService {
new UiViewHidden("flow"),
new UiViewHidden("port"),
new UiViewHidden("group"),
new UiViewHidden("meter"),
new UiView(NETWORK, "link", "Links", "nav_links"),
new UiView(NETWORK, "host", "Hosts", "nav_hosts"),
new UiView(NETWORK, "intent", "Intents", "nav_intents"),
......@@ -99,6 +100,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService {
new FlowViewMessageHandler(),
new PortViewMessageHandler(),
new GroupViewMessageHandler(),
new MeterViewMessageHandler(),
new IntentViewMessageHandler(),
new ApplicationViewMessageHandler(),
new SettingsViewMessageHandler(),
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -230,6 +230,28 @@
'-6.3,0.9-8.9,2.5c3.7,3.8,6.1,8.9,6.2,14.6c6.1,3.1,10.6,8.9,11.7,' +
'15.8C81.5,65.6,85,60,85,53.5C85,43.8,77.1,35.8,67.3,35.8z',
meterTable: 'M16,19.1H8v-13h8V19.1z M90.6,6.1H75.7v13h14.9V6.1z ' +
'M71.9,6.1H57v13h14.9V6.1z M53.3,6.1H38.4v13h14.9V6.1z M34.6,6.1' +
'H19.7v13h14.9V6.1z M102.3,6.1h-8v13h8V6.1z M45.7,52.7c0.2-5.6,' +
'2.6-10.7,6.2-14.4c-2.6-1.5-5.7-2.5-8.9-2.5c-9.8,0-17.7,7.9-17.7,' +
'17.7c0,6.3,3.3,11.9,8.3,15C34.8,61.5,39.4,55.6,45.7,52.7z M51.9,' +
'68.8c-3.1-3.1-5.2-7.2-6-11.7c-4.7,2.8-7.9,7.6-8.6,13.2c1.8,0.6,' +
'3.6,0.9,5.6,0.9C46.2,71.2,49.3,70.3,51.9,68.8z M55.2,71.5c-3.5,' +
'2.4-7.7,3.7-12.2,3.7c-1.9,0-3.8-0.3-5.6-0.7C38.5,83.2,45.9,90,' +
'54.9,90c9,0,16.4-6.7,17.5-15.4c-1.6,0.4-3.4,0.6-5.1,0.6C62.8,' +
'75.2,58.6,73.8,55.2,71.5z M54.9,50.6c1.9,0,3.8,0.3,5.6,0.7c-0.5' +
'-4.1-2.5-7.9-5.4-10.6c-2.9,2.7-4.8,6.4-5.3,10.5C51.5,50.8,53.2,' +
'50.6,54.9,50.6z M49.7,55.4c0.5,4.3,2.4,8.1,5.4,10.9c2.9-2.8,4.9' +
'-6.6,5.4-10.8c-1.8-0.6-3.6-0.9-5.6-0.9C53.1,54.6,51.4,54.9,49.7,' +
'55.4z M102.3,23.6v78.5H8V23.6H102.3z M89,53.5c0-12-9.7-21.7-' +
'21.7-21.7c-4.5,0-8.7,1.4-12.2,3.7c-3.5-2.4-7.7-3.7-12.2-3.7c-12,' +
'0-21.7,9.7-21.7,21.7c0,8.5,4.9,15.9,12,19.4C33.6,84.6,43.2,94,' +
'54.9,94c11.7,0,21.2-9.3,21.7-20.9C84,69.7,89,62.2,89,53.5z M' +
'64.3,57.3c-0.8,4.4-2.9,8.4-5.9,11.5c2.6,1.5,5.7,2.5,8.9,2.5c1.8,' +
'0,3.6-0.3,5.2-0.8C72,64.9,68.8,60.1,64.3,57.3z M67.3,35.8c-3.3,0' +
'-6.3,0.9-8.9,2.5c3.7,3.8,6.1,8.9,6.2,14.6c6.1,3.1,10.6,8.9,11.7,' +
'15.8C81.5,65.6,85,60,85,53.5C85,43.8,77.1,35.8,67.3,35.8z',
// --- Topology toolbar specific glyphs ----------------------
summary: "M95.8,9.2H14.2c-2.8,0-5,2.2-5,5v81.5c0,2.8,2.2,5,5," +
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -53,6 +53,7 @@
flowTable: 'flowTable',
portTable: 'portTable',
groupTable: 'groupTable',
meterTable: 'meterTable',
hostIcon_endstation: 'endstation',
hostIcon_router: 'router',
......
......@@ -26,6 +26,11 @@
icon icon-id="groupTable" icon-size="36"
tooltip tt-msg="groupTip"
ng-click="nav('group')"></div>
<div ng-class="{active: !!selId}"
icon icon-id="meterTable" icon-size="36"
tooltip tt-msg="meterTip"
ng-click="nav('meter')"></div>
</div>
</div>
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -294,6 +294,7 @@
$scope.flowTip = 'Show flow view for selected device';
$scope.portTip = 'Show port view for selected device';
$scope.groupTip = 'Show group view for selected device';
$scope.meterTip = 'Show meter view for selected device';
// details panel handlers
handlers[detailsResp] = respDetailsCb;
......
......@@ -30,6 +30,11 @@
icon icon-id="groupTable" icon-size="36"
tooltip tt-msg="groupTip"
ng-click="nav('group')"></div>
<div class="active"
icon icon-id="meterTable" icon-size="36"
tooltip tt-msg="meterTip"
ng-click="nav('meter')"></div>
</div>
</div>
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -40,6 +40,7 @@
$scope.deviceTip = 'Show device table';
$scope.portTip = 'Show port view for this device';
$scope.groupTip = 'Show group view for this device';
$scope.meterTip = 'Show meter view for selected device';
params = $location.search();
if (params.hasOwnProperty('devId')) {
......
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- Group partial HTML -->
<div id="ov-group">
<div class="tabular-header">
......@@ -46,6 +30,11 @@
<div class="current-view"
icon icon-id="groupTable" icon-size="36"></div>
<div class="active"
icon icon-id="meterTable" icon-size="36"
tooltip tt-msg="meterTip"
ng-click="nav('meter')"></div>
</div>
</div>
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -40,6 +40,7 @@
$scope.deviceTip = 'Show device table';
$scope.flowTip = 'Show flow view for this device';
$scope.portTip = 'Show port view for this device';
$scope.meterTip = 'Show meter view for selected device';
params = $location.search();
if (params.hasOwnProperty('devId')) {
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Meter View -- CSS file
*/
#ov-meter h2 {
display: inline-block;
}
#ov-meter div.ctrl-btns {
}
.light #ov-meter .current-view use {
fill: white;
}
.dark #ov-meter .current-view use {
fill: #304860;
}
.light #ov-meter .current-view rect {
fill: deepskyblue;
}
.dark #ov-meter .current-view rect {
fill: #eee;
}
.light #ov-meter tr:nth-child(4n + 1),
.light #ov-meter tr:nth-child(4n + 2) {
background-color: #eee;
}
.light #ov-meter tr:nth-child(4n + 3),
.light #ov-meter tr:nth-child(4n) {
background-color: #ddd;
}
.dark #ov-meter tr:nth-child(4n + 1),
.dark #ov-meter tr:nth-child(4n + 2) {
background-color: #444;
}
.dark #ov-meter tr:nth-child(4n + 3),
.dark #ov-meter tr:nth-child(4n) {
background-color: #333;
}
/* highlighted color */
.light #ov-meter tr:nth-child(4n + 1).data-change,
.light #ov-meter tr:nth-child(4n + 2).data-change,
.light #ov-meter tr:nth-child(4n + 3).data-change,
.light #ov-meter tr:nth-child(4n).data-change {
background-color: #FDFFDC;
}
.dark #ov-meter tr:nth-child(4n + 1).data-change,
.dark #ov-meter tr:nth-child(4n + 2).data-change,
.dark #ov-meter tr:nth-child(4n + 3).data-change,
.dark #ov-meter tr:nth-child(4n).data-change {
background-color: #5A5600;
}
#ov-meter td.bands {
padding-left: 36px;
opacity: 0.65;
}
\ No newline at end of file
<!-- Meter partial HTML -->
<div id="ov-meter">
<div class="tabular-header">
<h2>
Meters for Device {{devId || "(No device selected)"}}
({{tableData.length}} total)
</h2>
<div class="ctrl-btns">
<div class="refresh" ng-class="{active: autoRefresh}"
icon icon-size="36" icon-id="refresh"
tooltip tt-msg="autoRefreshTip"
ng-click="toggleRefresh()"></div>
<div class="separator"></div>
<div class="active"
icon icon-id="deviceTable" icon-size="36"
tooltip tt-msg="deviceTip"
ng-click="nav('device')"></div>
<div class="active"
icon icon-id="flowTable" icon-size="36"
tooltip tt-msg="flowTip"
ng-click="nav('flow')"></div>
<div class="active"
icon icon-id="portTable" icon-size="36"
tooltip tt-msg="portTip"
ng-click="nav('port')"></div>
<div class="active"
icon icon-id="groupTable" icon-size="36"
tooltip tt-msg="groupTip"
ng-click="nav('group')"></div>
<div class="current-view"
icon icon-id="meterTable" icon-size="36"></div>
</div>
</div>
<div class="summary-list" onos-table-resize>
<div class="table-header" onos-sortable-header>
<table>
<tr>
<td colId="id" sortable>Meter ID </td>
<td colId="app_id" sortable>App ID </td>
<td colId="state" sortable>State </td>
<td colId="packets" sortable>Packets </td>
<td colId="bytes" sortable>Bytes </td>
</tr>
</table>
</div>
<div class="table-body">
<table onos-flash-changes id-prop="id">
<tr ng-if="!tableData.length" class="no-data">
<td colspan="5">
No Meters found
</td>
</tr>
<tr ng-repeat-start="meter in tableData track by $index"
ng-repeat-complete row-id="{{meter.id}}">
<td>{{meter.id}}</td>
<td>{{meter.app_id}}</td>
<td>{{meter.state}}</td>
<td>{{meter.packets}}</td>
<td>{{meter.bytes}}</td>
</tr>
<tr row-id="{{meter.id}}" ng-repeat-end>
<td class="bands" colspan="5"
ng-bind-html="meter.bands"></td>
</tr>
</table>
</div>
</div>
</div>
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
ONOS GUI -- Meter View Module
*/
(function () {
'use strict';
// injected references
var $log, $scope, $location, fs, tbs, ns;
angular.module('ovMeter', [])
.controller('OvMeterCtrl',
['$log', '$scope', '$location', '$sce',
'FnService', 'TableBuilderService', 'NavService',
function (_$log_, _$scope_, _$location_, $sce, _fs_, _tbs_, _ns_) {
var params;
$log = _$log_;
$scope = _$scope_;
$location = _$location_;
fs = _fs_;
tbs = _tbs_;
ns = _ns_;
$scope.deviceTip = 'Show device table';
$scope.flowTip = 'Show flow view for this device';
$scope.portTip = 'Show port view for this device';
$scope.groupTip = 'Show group view for this device';
params = $location.search();
if (params.hasOwnProperty('devId')) {
$scope.devId = params['devId'];
}
tbs.buildTable({
scope: $scope,
tag: 'meter',
query: params
});
$scope.$watch('tableData', function () {
if (!fs.isEmptyObject($scope.tableData)) {
$scope.tableData.forEach(function (meter) {
meter.bands = $sce.trustAsHtml(meter.bands);
});
}
});
$scope.nav = function (path) {
if ($scope.devId) {
ns.navTo(path, { devId: $scope.devId });
}
};
$log.log('OvMeterCtrl has been created');
}]);
}());
\ No newline at end of file
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!-- Port partial HTML -->
<div id="ov-port">
<div class="tabular-header">
......@@ -46,6 +30,11 @@
icon icon-id="groupTable" icon-size="36"
tooltip tt-msg="groupTip"
ng-click="nav('group')"></div>
<div class="active"
icon icon-id="meterTable" icon-size="36"
tooltip tt-msg="meterTip"
ng-click="nav('meter')"></div>
</div>
</div>
......
/*
* Copyright 2015 Open Networking Laboratory
* Copyright 2015,2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -40,6 +40,7 @@
$scope.deviceTip = 'Show device table';
$scope.flowTip = 'Show flow view for this device';
$scope.groupTip = 'Show group view for this device';
$scope.meterTip = 'Show meter view for selected device';
params = $location.search();
if (params.hasOwnProperty('devId')) {
......
<!DOCTYPE html>
<!--
~ Copyright 2014,2015 Open Networking Laboratory
~ Copyright 2014-2016 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
......@@ -118,6 +118,7 @@
<script src="app/view/flow/flow.js"></script>
<script src="app/view/port/port.js"></script>
<script src="app/view/group/group.js"></script>
<script src="app/view/meter/meter.js"></script>
<script src="app/view/link/link.js"></script>
<script src="app/view/host/host.js"></script>
<script src="app/view/intent/intent.js"></script>
......@@ -137,6 +138,7 @@
<link rel="stylesheet" href="app/view/flow/flow.css">
<link rel="stylesheet" href="app/view/port/port.css">
<link rel="stylesheet" href="app/view/group/group.css">
<link rel="stylesheet" href="app/view/meter/meter.css">
<link rel="stylesheet" href="app/view/link/link.css">
<link rel="stylesheet" href="app/view/host/host.css">
<link rel="stylesheet" href="app/view/intent/intent.css">
......
/*
* Copyright 2014,2015 Open Networking Laboratory
* Copyright 2014-2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -41,6 +41,7 @@
'flow',
'port',
'group',
'meter',
'host',
'app',
'intent',
......