Added a new GUI view for packet processors.
Change-Id: Ia0c6a23b389c4033b94deefdc32a2543b9c9cfa5
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/NumberFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/NumberFormatter.java
new file mode 100644
index 0000000..76f4246
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/NumberFormatter.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.ui.table.cell;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+/**
+ * Formats number using the specified format string".
+ */
+public final class NumberFormatter extends AbstractCellFormatter {
+
+ private final NumberFormat format;
+
+ /**
+ * Creates a formatter using a default decimal format.
+ */
+ public NumberFormatter() {
+ this(new DecimalFormat("#,##0.00000"));
+ }
+
+ /**
+ * Creates a formatter using the specified format.
+ *
+ * @param format number format
+ */
+ public NumberFormatter(NumberFormat format) {
+ this.format = format;
+ }
+
+ @Override
+ protected String nonNullFormat(Object value) {
+ return format.format(value);
+ }
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java
new file mode 100644
index 0000000..652116c
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.ui.impl;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.packet.PacketProcessorEntry;
+import org.onosproject.net.packet.PacketService;
+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.NumberFormatter;
+
+import java.util.Collection;
+
+import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX;
+import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX;
+
+/**
+ * Message handler for packet processor view related messages.
+ */
+public class ProcessorViewMessageHandler extends UiMessageHandler {
+
+ private static final String PROCESSOR_DATA_REQ = "processorDataRequest";
+ private static final String PROCESSOR_DATA_RESP = "processorDataResponse";
+ private static final String PROCESSORS = "processors";
+
+ private static final String ID = "id";
+ private static final String TYPE = "type";
+ private static final String PRIORITY = "priority";
+ private static final String PROCESSOR = "processor";
+ private static final String PACKETS = "packets";
+ private static final String AVG_MS = "avgMillis";
+
+ private static final long NANOS_IN_MS = 1_000_000;
+
+ private static final String[] COL_IDS = {
+ ID, TYPE, PRIORITY, PROCESSOR, PACKETS, AVG_MS
+ };
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(new ProcessorDataRequest());
+ }
+
+ // handler for link table requests
+ private final class ProcessorDataRequest extends TableRequestHandler {
+ private ProcessorDataRequest() {
+ super(PROCESSOR_DATA_REQ, PROCESSOR_DATA_RESP, PROCESSORS);
+ }
+
+ @Override
+ protected String[] getColumnIds() {
+ return COL_IDS;
+ }
+
+ @Override
+ protected String defaultColumnId() {
+ return ID;
+ }
+
+ @Override
+ protected TableModel createTableModel() {
+ TableModel tm = super.createTableModel();
+ tm.setFormatter(AVG_MS, new NumberFormatter());
+ return tm;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ PacketService ps = get(PacketService.class);
+ ps.getProcessors().forEach(entry -> populateRow(tm.addRow(), entry));
+ }
+
+ private void populateRow(TableModel.Row row, PacketProcessorEntry entry) {
+ row.cell(ID, entry.priority())
+ .cell(TYPE, processorType(entry.priority()))
+ .cell(PRIORITY, processorPriority(entry.priority()))
+ .cell(PROCESSOR, entry.processor().getClass().getName())
+ .cell(PACKETS, entry.invocations())
+ .cell(AVG_MS, entry.averageNanos() / NANOS_IN_MS);
+ }
+
+ private String processorType(int p) {
+ return p > DIRECTOR_MAX ? "observer" :
+ p > ADVISOR_MAX ? "director" : "observer";
+ }
+
+ private int processorPriority(int p) {
+ return p > DIRECTOR_MAX ? (p - DIRECTOR_MAX - 1) :
+ p > ADVISOR_MAX ? (p - ADVISOR_MAX - 1) : (p - 1);
+ }
+
+ }
+}
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 2bd0bb6..86cf038 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
@@ -77,6 +77,7 @@
new UiView(PLATFORM, "app", "Applications", "nav_apps"),
new UiView(PLATFORM, "settings", "Settings", "nav_settings"),
new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"),
+ new UiView(PLATFORM, "processor", "Packet Processors", "nav_processors"),
new UiView(NETWORK, "topo", "Topology", "nav_topo"),
new UiView(NETWORK, "device", "Devices", "nav_devs"),
new UiViewHidden("flow"),
@@ -102,6 +103,7 @@
new ApplicationViewMessageHandler(),
new SettingsViewMessageHandler(),
new ClusterViewMessageHandler(),
+ new ProcessorViewMessageHandler(),
new TunnelViewMessageHandler()
);
diff --git a/web/gui/src/main/webapp/app/fw/svg/icon.js b/web/gui/src/main/webapp/app/fw/svg/icon.js
index ba79431..dec0334 100644
--- a/web/gui/src/main/webapp/app/fw/svg/icon.js
+++ b/web/gui/src/main/webapp/app/fw/svg/icon.js
@@ -64,7 +64,8 @@
nav_devs: 'switch',
nav_links: 'ports',
nav_hosts: 'endstation',
- nav_intents: 'relatedIntents'
+ nav_intents: 'relatedIntents',
+ nav_processors: 'allTraffic'
};
function ensureIconLibDefs() {
diff --git a/web/gui/src/main/webapp/app/view/processor/processor.css b/web/gui/src/main/webapp/app/view/processor/processor.css
new file mode 100644
index 0000000..f4c22aa
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/processor/processor.css
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+/*
+ ONOS GUI -- Processor View -- CSS file
+ */
+
+#ov-processor h2 {
+ display: inline-block;
+}
+
+#ov-processor div.ctrl-btns {
+ width: 40px;
+}
+
+.light #ov-processor .current-view use {
+ fill: white;
+}
+.dark #ov-processor .current-view use {
+ fill: #304860;
+}
+
+.light #ov-processor .current-view rect {
+ fill: deepskyblue;
+}
+.dark #ov-processor .current-view rect {
+ fill: #eee;
+}
+
+#ov-processor td.number {
+ text-align: right;
+}
+
+#ov-processor td.type {
+ text-align: center;
+}
+
+#ov-processor tr.no-data td {
+ text-align: center;
+}
diff --git a/web/gui/src/main/webapp/app/view/processor/processor.html b/web/gui/src/main/webapp/app/view/processor/processor.html
new file mode 100644
index 0000000..24e126e
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/processor/processor.html
@@ -0,0 +1,63 @@
+<!-- processor partial HTML -->
+<div id="ov-processor">
+ <div class="tabular-header">
+ <h2>
+ Packet Processors ({{tableData.length}} Processors 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="current-view"
+ icon icon-id="processorTable" icon-size="36"></div>
+
+ <div class="active"
+ icon icon-id="requestTable" icon-size="36"
+ tooltip tt-msg="requestTip"
+ ng-click="nav('request')"></div>
+ -->
+ </div>
+ </div>
+
+ <div class="summary-list" onos-table-resize>
+ <div ng-show="loading" class="loading-wheel"
+ icon icon-id="loading" icon-size="75"></div>
+
+ <div class="table-header" onos-sortable-header>
+ <table>
+ <tr>
+ <td class="type" colId="type" sortable col-width="80px">Type </td>
+ <td class="number" colId="priority" sortable col-width="80px">Priority </td>
+ <td colId="processor" sortable col-width="500px">Class </td>
+ <td class="number" colId="packets" sortable col-width="100px">Packets </td>
+ <td class="number" colId="avgMillis" sortable col-width="80px">Average (ms) </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 Processors found
+ </td>
+ </tr>
+
+ <tr ng-repeat="processor in tableData track by $index"
+ ng-repeat-complete row-id="{{processor.id}}">
+ <td class="type">{{processor.type}}</td>
+ <td class="number">{{processor.priority}}</td>
+ <td>{{processor.processor}}</td>
+ <td class="number">{{processor.packets}}</td>
+ <td class="number">{{processor.avgMillis}}</td>
+ </tr>
+ </table>
+ </div>
+
+ </div>
+
+</div>
diff --git a/web/gui/src/main/webapp/app/view/processor/processor.js b/web/gui/src/main/webapp/app/view/processor/processor.js
new file mode 100644
index 0000000..89d717b
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/processor/processor.js
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+/*
+ ONOS GUI -- Packet Processor View Module
+ */
+
+(function () {
+ 'use strict';
+
+ // injected references
+ var $log, $scope, $location, fs, tbs, ns;
+
+ angular.module('ovProcessor', [])
+ .controller('OvProcessorCtrl',
+ ['$log', '$scope', '$location',
+ 'FnService', 'TableBuilderService', 'NavService',
+
+ function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_) {
+ var params;
+ $log = _$log_;
+ $scope = _$scope_;
+ $location = _$location_;
+ fs = _fs_;
+ tbs = _tbs_;
+ ns = _ns_;
+ $scope.requestTip = 'Show packet requests';
+
+ params = $location.search();
+
+ tbs.buildTable({
+ scope: $scope,
+ tag: 'processor',
+ query: params
+ });
+
+ $scope.nav = function (path) {
+ if ($scope.devId) {
+ ns.navTo(path);
+ }
+ };
+
+ $log.log('OvProcessorCtrl has been created');
+ }]);
+}());
diff --git a/web/gui/src/main/webapp/app/view/settings/settings.html b/web/gui/src/main/webapp/app/view/settings/settings.html
index ee069d3..6108101 100644
--- a/web/gui/src/main/webapp/app/view/settings/settings.html
+++ b/web/gui/src/main/webapp/app/view/settings/settings.html
@@ -17,7 +17,7 @@
<div class="table-header" onos-sortable-header>
<table>
<tr>
- <td colId="component" sortable col-width="200px">Component </td>
+ <td colId="component" sortable col-width="300px">Component </td>
<td colId="id" sortable>Property </td>
<td colId="type" sortable col-width="70px">Type </td>
<td colId="value" sortable>Value </td>
diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html
index 154f941..5df3c66 100644
--- a/web/gui/src/main/webapp/index.html
+++ b/web/gui/src/main/webapp/index.html
@@ -121,6 +121,7 @@
<script src="app/view/app/app.js"></script>
<script src="app/view/settings/settings.js"></script>
<script src="app/view/cluster/cluster.js"></script>
+ <script src="app/view/processor/processor.js"></script>
<script src="app/view/tunnel/tunnel.js"></script>
<!-- This is where contributed javascript will get injected -->
@@ -139,6 +140,7 @@
<link rel="stylesheet" href="app/view/app/app.css">
<link rel="stylesheet" href="app/view/settings/settings.css">
<link rel="stylesheet" href="app/view/cluster/cluster.css">
+ <link rel="stylesheet" href="app/view/processor/processor.css">
<link rel="stylesheet" href="app/view/tunnel/tunnel.css">
<!-- This is where contributed stylesheets will get injected -->