Thomas Vachuska

Added a new GUI view for packet processors.

Change-Id: Ia0c6a23b389c4033b94deefdc32a2543b9c9cfa5
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 + */
16 +
17 +package org.onosproject.ui.table.cell;
18 +
19 +import java.text.DecimalFormat;
20 +import java.text.NumberFormat;
21 +
22 +/**
23 + * Formats number using the specified format string".
24 + */
25 +public final class NumberFormatter extends AbstractCellFormatter {
26 +
27 + private final NumberFormat format;
28 +
29 + /**
30 + * Creates a formatter using a default decimal format.
31 + */
32 + public NumberFormatter() {
33 + this(new DecimalFormat("#,##0.00000"));
34 + }
35 +
36 + /**
37 + * Creates a formatter using the specified format.
38 + *
39 + * @param format number format
40 + */
41 + public NumberFormatter(NumberFormat format) {
42 + this.format = format;
43 + }
44 +
45 + @Override
46 + protected String nonNullFormat(Object value) {
47 + return format.format(value);
48 + }
49 +
50 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 + */
16 +
17 +package org.onosproject.ui.impl;
18 +
19 +import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import com.google.common.collect.ImmutableSet;
21 +import org.onosproject.net.packet.PacketProcessorEntry;
22 +import org.onosproject.net.packet.PacketService;
23 +import org.onosproject.ui.RequestHandler;
24 +import org.onosproject.ui.UiMessageHandler;
25 +import org.onosproject.ui.table.TableModel;
26 +import org.onosproject.ui.table.TableRequestHandler;
27 +import org.onosproject.ui.table.cell.NumberFormatter;
28 +
29 +import java.util.Collection;
30 +
31 +import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX;
32 +import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX;
33 +
34 +/**
35 + * Message handler for packet processor view related messages.
36 + */
37 +public class ProcessorViewMessageHandler extends UiMessageHandler {
38 +
39 + private static final String PROCESSOR_DATA_REQ = "processorDataRequest";
40 + private static final String PROCESSOR_DATA_RESP = "processorDataResponse";
41 + private static final String PROCESSORS = "processors";
42 +
43 + private static final String ID = "id";
44 + private static final String TYPE = "type";
45 + private static final String PRIORITY = "priority";
46 + private static final String PROCESSOR = "processor";
47 + private static final String PACKETS = "packets";
48 + private static final String AVG_MS = "avgMillis";
49 +
50 + private static final long NANOS_IN_MS = 1_000_000;
51 +
52 + private static final String[] COL_IDS = {
53 + ID, TYPE, PRIORITY, PROCESSOR, PACKETS, AVG_MS
54 + };
55 +
56 + @Override
57 + protected Collection<RequestHandler> createRequestHandlers() {
58 + return ImmutableSet.of(new ProcessorDataRequest());
59 + }
60 +
61 + // handler for link table requests
62 + private final class ProcessorDataRequest extends TableRequestHandler {
63 + private ProcessorDataRequest() {
64 + super(PROCESSOR_DATA_REQ, PROCESSOR_DATA_RESP, PROCESSORS);
65 + }
66 +
67 + @Override
68 + protected String[] getColumnIds() {
69 + return COL_IDS;
70 + }
71 +
72 + @Override
73 + protected String defaultColumnId() {
74 + return ID;
75 + }
76 +
77 + @Override
78 + protected TableModel createTableModel() {
79 + TableModel tm = super.createTableModel();
80 + tm.setFormatter(AVG_MS, new NumberFormatter());
81 + return tm;
82 + }
83 +
84 + @Override
85 + protected void populateTable(TableModel tm, ObjectNode payload) {
86 + PacketService ps = get(PacketService.class);
87 + ps.getProcessors().forEach(entry -> populateRow(tm.addRow(), entry));
88 + }
89 +
90 + private void populateRow(TableModel.Row row, PacketProcessorEntry entry) {
91 + row.cell(ID, entry.priority())
92 + .cell(TYPE, processorType(entry.priority()))
93 + .cell(PRIORITY, processorPriority(entry.priority()))
94 + .cell(PROCESSOR, entry.processor().getClass().getName())
95 + .cell(PACKETS, entry.invocations())
96 + .cell(AVG_MS, entry.averageNanos() / NANOS_IN_MS);
97 + }
98 +
99 + private String processorType(int p) {
100 + return p > DIRECTOR_MAX ? "observer" :
101 + p > ADVISOR_MAX ? "director" : "observer";
102 + }
103 +
104 + private int processorPriority(int p) {
105 + return p > DIRECTOR_MAX ? (p - DIRECTOR_MAX - 1) :
106 + p > ADVISOR_MAX ? (p - ADVISOR_MAX - 1) : (p - 1);
107 + }
108 +
109 + }
110 +}
...@@ -77,6 +77,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { ...@@ -77,6 +77,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService {
77 new UiView(PLATFORM, "app", "Applications", "nav_apps"), 77 new UiView(PLATFORM, "app", "Applications", "nav_apps"),
78 new UiView(PLATFORM, "settings", "Settings", "nav_settings"), 78 new UiView(PLATFORM, "settings", "Settings", "nav_settings"),
79 new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"), 79 new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"),
80 + new UiView(PLATFORM, "processor", "Packet Processors", "nav_processors"),
80 new UiView(NETWORK, "topo", "Topology", "nav_topo"), 81 new UiView(NETWORK, "topo", "Topology", "nav_topo"),
81 new UiView(NETWORK, "device", "Devices", "nav_devs"), 82 new UiView(NETWORK, "device", "Devices", "nav_devs"),
82 new UiViewHidden("flow"), 83 new UiViewHidden("flow"),
...@@ -102,6 +103,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { ...@@ -102,6 +103,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService {
102 new ApplicationViewMessageHandler(), 103 new ApplicationViewMessageHandler(),
103 new SettingsViewMessageHandler(), 104 new SettingsViewMessageHandler(),
104 new ClusterViewMessageHandler(), 105 new ClusterViewMessageHandler(),
106 + new ProcessorViewMessageHandler(),
105 new TunnelViewMessageHandler() 107 new TunnelViewMessageHandler()
106 ); 108 );
107 109
......
...@@ -64,7 +64,8 @@ ...@@ -64,7 +64,8 @@
64 nav_devs: 'switch', 64 nav_devs: 'switch',
65 nav_links: 'ports', 65 nav_links: 'ports',
66 nav_hosts: 'endstation', 66 nav_hosts: 'endstation',
67 - nav_intents: 'relatedIntents' 67 + nav_intents: 'relatedIntents',
68 + nav_processors: 'allTraffic'
68 }; 69 };
69 70
70 function ensureIconLibDefs() { 71 function ensureIconLibDefs() {
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 + */
16 +
17 +/*
18 + ONOS GUI -- Processor View -- CSS file
19 + */
20 +
21 +#ov-processor h2 {
22 + display: inline-block;
23 +}
24 +
25 +#ov-processor div.ctrl-btns {
26 + width: 40px;
27 +}
28 +
29 +.light #ov-processor .current-view use {
30 + fill: white;
31 +}
32 +.dark #ov-processor .current-view use {
33 + fill: #304860;
34 +}
35 +
36 +.light #ov-processor .current-view rect {
37 + fill: deepskyblue;
38 +}
39 +.dark #ov-processor .current-view rect {
40 + fill: #eee;
41 +}
42 +
43 +#ov-processor td.number {
44 + text-align: right;
45 +}
46 +
47 +#ov-processor td.type {
48 + text-align: center;
49 +}
50 +
51 +#ov-processor tr.no-data td {
52 + text-align: center;
53 +}
1 +<!-- processor partial HTML -->
2 +<div id="ov-processor">
3 + <div class="tabular-header">
4 + <h2>
5 + Packet Processors ({{tableData.length}} Processors total)
6 + </h2>
7 + <div class="ctrl-btns">
8 + <div class="refresh" ng-class="{active: autoRefresh}"
9 + icon icon-size="36" icon-id="refresh"
10 + tooltip tt-msg="autoRefreshTip"
11 + ng-click="toggleRefresh()"></div>
12 + <!--
13 + <div class="separator"></div>
14 +
15 + <div class="current-view"
16 + icon icon-id="processorTable" icon-size="36"></div>
17 +
18 + <div class="active"
19 + icon icon-id="requestTable" icon-size="36"
20 + tooltip tt-msg="requestTip"
21 + ng-click="nav('request')"></div>
22 + -->
23 + </div>
24 + </div>
25 +
26 + <div class="summary-list" onos-table-resize>
27 + <div ng-show="loading" class="loading-wheel"
28 + icon icon-id="loading" icon-size="75"></div>
29 +
30 + <div class="table-header" onos-sortable-header>
31 + <table>
32 + <tr>
33 + <td class="type" colId="type" sortable col-width="80px">Type </td>
34 + <td class="number" colId="priority" sortable col-width="80px">Priority </td>
35 + <td colId="processor" sortable col-width="500px">Class </td>
36 + <td class="number" colId="packets" sortable col-width="100px">Packets </td>
37 + <td class="number" colId="avgMillis" sortable col-width="80px">Average (ms) </td>
38 + </tr>
39 + </table>
40 + </div>
41 +
42 + <div class="table-body">
43 + <table onos-flash-changes id-prop="id">
44 + <tr ng-if="!tableData.length" class="no-data">
45 + <td colspan="5">
46 + No Processors found
47 + </td>
48 + </tr>
49 +
50 + <tr ng-repeat="processor in tableData track by $index"
51 + ng-repeat-complete row-id="{{processor.id}}">
52 + <td class="type">{{processor.type}}</td>
53 + <td class="number">{{processor.priority}}</td>
54 + <td>{{processor.processor}}</td>
55 + <td class="number">{{processor.packets}}</td>
56 + <td class="number">{{processor.avgMillis}}</td>
57 + </tr>
58 + </table>
59 + </div>
60 +
61 + </div>
62 +
63 +</div>
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 + */
16 +
17 +/*
18 + ONOS GUI -- Packet Processor View Module
19 + */
20 +
21 +(function () {
22 + 'use strict';
23 +
24 + // injected references
25 + var $log, $scope, $location, fs, tbs, ns;
26 +
27 + angular.module('ovProcessor', [])
28 + .controller('OvProcessorCtrl',
29 + ['$log', '$scope', '$location',
30 + 'FnService', 'TableBuilderService', 'NavService',
31 +
32 + function (_$log_, _$scope_, _$location_, _fs_, _tbs_, _ns_) {
33 + var params;
34 + $log = _$log_;
35 + $scope = _$scope_;
36 + $location = _$location_;
37 + fs = _fs_;
38 + tbs = _tbs_;
39 + ns = _ns_;
40 + $scope.requestTip = 'Show packet requests';
41 +
42 + params = $location.search();
43 +
44 + tbs.buildTable({
45 + scope: $scope,
46 + tag: 'processor',
47 + query: params
48 + });
49 +
50 + $scope.nav = function (path) {
51 + if ($scope.devId) {
52 + ns.navTo(path);
53 + }
54 + };
55 +
56 + $log.log('OvProcessorCtrl has been created');
57 + }]);
58 +}());
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 <div class="table-header" onos-sortable-header> 17 <div class="table-header" onos-sortable-header>
18 <table> 18 <table>
19 <tr> 19 <tr>
20 - <td colId="component" sortable col-width="200px">Component </td> 20 + <td colId="component" sortable col-width="300px">Component </td>
21 <td colId="id" sortable>Property </td> 21 <td colId="id" sortable>Property </td>
22 <td colId="type" sortable col-width="70px">Type </td> 22 <td colId="type" sortable col-width="70px">Type </td>
23 <td colId="value" sortable>Value </td> 23 <td colId="value" sortable>Value </td>
......
...@@ -121,6 +121,7 @@ ...@@ -121,6 +121,7 @@
121 <script src="app/view/app/app.js"></script> 121 <script src="app/view/app/app.js"></script>
122 <script src="app/view/settings/settings.js"></script> 122 <script src="app/view/settings/settings.js"></script>
123 <script src="app/view/cluster/cluster.js"></script> 123 <script src="app/view/cluster/cluster.js"></script>
124 + <script src="app/view/processor/processor.js"></script>
124 <script src="app/view/tunnel/tunnel.js"></script> 125 <script src="app/view/tunnel/tunnel.js"></script>
125 126
126 <!-- This is where contributed javascript will get injected --> 127 <!-- This is where contributed javascript will get injected -->
...@@ -139,6 +140,7 @@ ...@@ -139,6 +140,7 @@
139 <link rel="stylesheet" href="app/view/app/app.css"> 140 <link rel="stylesheet" href="app/view/app/app.css">
140 <link rel="stylesheet" href="app/view/settings/settings.css"> 141 <link rel="stylesheet" href="app/view/settings/settings.css">
141 <link rel="stylesheet" href="app/view/cluster/cluster.css"> 142 <link rel="stylesheet" href="app/view/cluster/cluster.css">
143 + <link rel="stylesheet" href="app/view/processor/processor.css">
142 <link rel="stylesheet" href="app/view/tunnel/tunnel.css"> 144 <link rel="stylesheet" href="app/view/tunnel/tunnel.css">
143 145
144 <!-- This is where contributed stylesheets will get injected --> 146 <!-- This is where contributed stylesheets will get injected -->
......