diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java new file mode 100644 index 0000000000..7060e8220a --- /dev/null +++ b/core/api/src/main/java/org/onosproject/ui/table/cell/EnumFormatter.java @@ -0,0 +1,37 @@ +/* + * 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 org.onosproject.ui.table.CellFormatter; + +import static org.apache.commons.lang.WordUtils.capitalizeFully; + +/** + * Formats enum types to be readable strings. + */ +public class EnumFormatter extends AbstractCellFormatter { + + @Override + protected String nonNullFormat(Object value) { + return capitalizeFully(value.toString().replace("_", " ")); + } + + /** + * An instance of this class. + */ + public static final CellFormatter INSTANCE = new EnumFormatter(); +} diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java new file mode 100644 index 0000000000..b61c1b73d9 --- /dev/null +++ b/web/gui/src/main/java/org/onosproject/ui/impl/GroupViewMessageHandler.java @@ -0,0 +1,145 @@ +/* + * 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.base.Strings; +import com.google.common.collect.ImmutableSet; +import org.onosproject.net.DeviceId; +import org.onosproject.net.group.Group; +import org.onosproject.net.group.GroupBucket; +import org.onosproject.net.group.GroupService; +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 org.onosproject.ui.table.cell.EnumFormatter; +import org.onosproject.ui.table.cell.IntComparator; +import org.onosproject.ui.table.cell.LongComparator; + +import java.util.Collection; +import java.util.List; + + +/** + * Message handler for group view related messages. + */ +public class GroupViewMessageHandler extends UiMessageHandler { + + private static final String GROUP_DATA_REQ = "groupDataRequest"; + private static final String GROUP_DATA_RESP = "groupDataResponse"; + private static final String GROUPS = "groups"; + + private static final String ID = "id"; + private static final String APP_ID = "app_id"; + private static final String STATE = "state"; + private static final String TYPE = "type"; + private static final String PACKETS = "packets"; + private static final String BYTES = "bytes"; + private static final String BUCKETS = "buckets"; + + private static final String[] COL_IDS = { + ID, APP_ID, STATE, TYPE, PACKETS, BYTES, BUCKETS + }; + + @Override + protected Collection getHandlers() { + return ImmutableSet.of(new GroupDataRequest()); + } + + // handler for group table requests + private final class GroupDataRequest extends TableRequestHandler { + + private GroupDataRequest() { + super(GROUP_DATA_REQ, GROUP_DATA_RESP, GROUPS); + } + + @Override + protected String[] getColumnIds() { + return COL_IDS; + } + + @Override + protected TableModel createTableModel() { + TableModel tm = super.createTableModel(); + + tm.setComparator(ID, IntComparator.INSTANCE); + tm.setComparator(PACKETS, LongComparator.INSTANCE); + tm.setComparator(BYTES, LongComparator.INSTANCE); + + tm.setFormatter(TYPE, EnumFormatter.INSTANCE); + tm.setFormatter(BUCKETS, new BucketFormatter()); + return tm; + } + + @Override + protected void populateTable(TableModel tm, ObjectNode payload) { + String uri = string(payload, "devId"); + if (!Strings.isNullOrEmpty(uri)) { + DeviceId deviceId = DeviceId.deviceId(uri); + GroupService gs = get(GroupService.class); + for (Group group : gs.getGroups(deviceId)) { + populateRow(tm.addRow(), group); + } + } + } + + private void populateRow(TableModel.Row row, Group g) { + row.cell(ID, g.id().id()) + .cell(APP_ID, g.appId().name()) + .cell(STATE, g.state()) + .cell(TYPE, g.type()) + .cell(PACKETS, g.packets()) + .cell(BYTES, g.bytes()) + .cell(BUCKETS, g.buckets().buckets()); + } + + private final class BucketFormatter implements CellFormatter { + private static final String COMMA = ", "; + + @Override + public String format(Object value) { + StringBuilder sb = new StringBuilder(); + List buckets = (List) value; + + if (buckets.isEmpty()) { + return "(No buckets for this group)"; + } + + for (GroupBucket b : buckets) { + sb.append("Bytes: ") + .append(Long.toString(b.bytes())) + .append(" Packets: ") + .append(Long.toString(b.packets())) + .append(" Actions: ") + .append(b.treatment().allInstructions()) + .append(COMMA); + } + removeTrailingComma(sb); + + return sb.toString(); + } + + private StringBuilder removeTrailingComma(StringBuilder sb) { + int pos = sb.lastIndexOf(COMMA); + sb.delete(pos, sb.length()); + return sb; + } + } + } +} 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 92ac04db4b..a09ae58ef2 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 @@ -69,6 +69,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { new UiView(NETWORK, "device", "Devices", "nav_devs"), new UiViewHidden("flow"), new UiViewHidden("port"), + new UiViewHidden("group"), new UiView(NETWORK, "link", "Links", "nav_links"), new UiView(NETWORK, "host", "Hosts", "nav_hosts"), new UiView(NETWORK, "intent", "Intents", "nav_intents") @@ -82,6 +83,7 @@ public class UiExtensionManager implements UiExtensionService, SpriteService { new HostViewMessageHandler(), new FlowViewMessageHandler(), new PortViewMessageHandler(), + new GroupViewMessageHandler(), new IntentViewMessageHandler(), new ApplicationViewMessageHandler(), new ClusterViewMessageHandler() diff --git a/web/gui/src/main/webapp/app/view/group/group.css b/web/gui/src/main/webapp/app/view/group/group.css new file mode 100644 index 0000000000..8553ddc361 --- /dev/null +++ b/web/gui/src/main/webapp/app/view/group/group.css @@ -0,0 +1,49 @@ +/* + * 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 -- Group View -- CSS file + */ + +#ov-group h2 { + display: inline-block; +} + +#ov-group div.ctrl-btns { + width: 45px; +} + +.light #ov-group tr:nth-child(4n + 2), +.light #ov-group tr:nth-child(4n + 3) { + background-color: #eee; +} +.light #ov-group tr:nth-child(4n + 4), +.light #ov-group tr:nth-child(4n + 1) { + background-color: #ddd; +} +.dark #ov-group tr:nth-child(4n + 2), +.dark #ov-group tr:nth-child(4n + 3) { + background-color: #444; +} +.dark #ov-group tr:nth-child(4n + 4), +.dark #ov-group tr:nth-child(4n + 1) { + background-color: #333; +} + +#ov-group td.buckets { + padding-left: 36px; + opacity: 0.65; +} diff --git a/web/gui/src/main/webapp/app/view/group/group.html b/web/gui/src/main/webapp/app/view/group/group.html new file mode 100644 index 0000000000..ad1e8a1a6d --- /dev/null +++ b/web/gui/src/main/webapp/app/view/group/group.html @@ -0,0 +1,72 @@ + + + +
+
+

+ Groups for Device {{devId || "(No device selected)"}} + ({{tableData.length}} total) +

+
+
+
+
+ +
+ +
+ + + + + + + + + +
Group ID App ID State Type Packets Bytes
+
+ +
+ + + + + + + + + + + + + + + + +
+ No Groups found +
{{group.id}}{{group.app_id}}{{group.state}}{{group.type}}{{group.packets}}{{group.bytes}}
{{group.buckets}}
+
+ +
+ +
diff --git a/web/gui/src/main/webapp/app/view/group/group.js b/web/gui/src/main/webapp/app/view/group/group.js new file mode 100644 index 0000000000..1602da128d --- /dev/null +++ b/web/gui/src/main/webapp/app/view/group/group.js @@ -0,0 +1,60 @@ +/* + * 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 -- Group View Module + */ + +(function () { + 'use strict'; + + // injected references + var $log, $scope, $location, fs, ts, tbs; + + angular.module('ovGroup', []) + .controller('OvGroupCtrl', + ['$log', '$scope', '$location', + 'FnService', 'TableService', 'TableBuilderService', + + function (_$log_, _$scope_, _$location_, _fs_, _ts_, _tbs_) { + var params; + $log = _$log_; + $scope = _$scope_; + $location = _$location_; + fs = _fs_; + ts = _ts_; + tbs = _tbs_; + + params = $location.search(); + if (params.hasOwnProperty('devId')) { + $scope.devId = params['devId']; + } + + tbs.buildTable({ + scope: $scope, + tag: 'group', + query: params + }); + + $scope.refresh = function () { + $log.debug('Refreshing groups page'); + ts.resetSortIcons(); + $scope.sortCallback(); + }; + + $log.log('OvGroupCtrl has been created'); + }]); +}()); diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html index caa8b269b3..7dd2f42e47 100644 --- a/web/gui/src/main/webapp/index.html +++ b/web/gui/src/main/webapp/index.html @@ -112,6 +112,7 @@ + @@ -127,6 +128,7 @@ + diff --git a/web/gui/src/main/webapp/onos.js b/web/gui/src/main/webapp/onos.js index 3af48bcac1..d49d2c02d2 100644 --- a/web/gui/src/main/webapp/onos.js +++ b/web/gui/src/main/webapp/onos.js @@ -40,6 +40,7 @@ 'device', 'flow', 'port', + 'group', 'host', 'app', 'intent',