From 3ece373c812d892e8bad0c09d450cd5347c49249 Mon Sep 17 00:00:00 2001 From: Thomas Vachuska Date: Tue, 22 Sep 2015 23:58:50 -0700 Subject: [PATCH] Added a new GUI view for packet processors. Change-Id: Ia0c6a23b389c4033b94deefdc32a2543b9c9cfa5 --- .../ui/table/cell/NumberFormatter.java | 50 ++++++++ .../ui/impl/ProcessorViewMessageHandler.java | 110 ++++++++++++++++++ .../ui/impl/UiExtensionManager.java | 2 + web/gui/src/main/webapp/app/fw/svg/icon.js | 3 +- .../webapp/app/view/processor/processor.css | 53 +++++++++ .../webapp/app/view/processor/processor.html | 63 ++++++++++ .../webapp/app/view/processor/processor.js | 58 +++++++++ .../webapp/app/view/settings/settings.html | 2 +- web/gui/src/main/webapp/index.html | 2 + 9 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 core/api/src/main/java/org/onosproject/ui/table/cell/NumberFormatter.java create mode 100644 web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java create mode 100644 web/gui/src/main/webapp/app/view/processor/processor.css create mode 100644 web/gui/src/main/webapp/app/view/processor/processor.html create mode 100644 web/gui/src/main/webapp/app/view/processor/processor.js 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 0000000000..76f4246606 --- /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 0000000000..652116ce23 --- /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 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 2bd0bb61ed..86cf038bc3 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 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { 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 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { 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 ba79431315..dec0334fd6 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 0000000000..f4c22aafdb --- /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 0000000000..24e126e7a4 --- /dev/null +++ b/web/gui/src/main/webapp/app/view/processor/processor.html @@ -0,0 +1,63 @@ + +
+
+

+ Packet Processors ({{tableData.length}} Processors total) +

+
+
+ +
+
+ +
+
+ +
+ + + + + + + + +
Type Priority Class Packets Average (ms)
+
+ +
+ + + + + + + + + + + + +
+ No Processors found +
{{processor.type}}{{processor.priority}}{{processor.processor}}{{processor.packets}}{{processor.avgMillis}}
+
+ +
+ +
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 0000000000..89d717b649 --- /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 ee069d3738..610810176e 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 @@
- + diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html index 154f941699..5df3c66418 100644 --- a/web/gui/src/main/webapp/index.html +++ b/web/gui/src/main/webapp/index.html @@ -121,6 +121,7 @@ + @@ -139,6 +140,7 @@ +
Component Component Property Type Value