diff options
Diffstat (limited to 'framework/src/onos/web/gui/src/main/java/org/onosproject/ui')
3 files changed, 175 insertions, 12 deletions
diff --git a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java index fb83cdd7..53b16a65 100644 --- a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java +++ b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/DeviceViewMessageHandler.java @@ -25,12 +25,16 @@ import org.onosproject.net.Device; import org.onosproject.net.DeviceId; import org.onosproject.net.Link; import org.onosproject.net.Port; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.net.config.basics.BasicDeviceConfig; import org.onosproject.net.device.DeviceService; import org.onosproject.net.link.LinkService; import org.onosproject.ui.RequestHandler; import org.onosproject.ui.UiMessageHandler; import org.onosproject.ui.table.TableModel; import org.onosproject.ui.table.TableRequestHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; @@ -38,7 +42,10 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import static com.google.common.base.Strings.emptyToNull; +import static com.google.common.base.Strings.isNullOrEmpty; import static org.apache.commons.lang.WordUtils.capitalizeFully; +import static org.onosproject.net.DeviceId.deviceId; /** * Message handler for device view related messages. @@ -53,6 +60,11 @@ public class DeviceViewMessageHandler extends UiMessageHandler { private static final String DEV_DETAILS_RESP = "deviceDetailsResponse"; private static final String DETAILS = "details"; + private static final String DEV_NAME_CHANGE_REQ = "deviceNameChangeRequest"; + private static final String DEV_NAME_CHANGE_RESP = "deviceNameChangeResponse"; + + private static final String ZERO_URI = "of:0000000000000000"; + private static final String ID = "id"; private static final String TYPE = "type"; private static final String AVAILABLE = "available"; @@ -72,25 +84,41 @@ public class DeviceViewMessageHandler extends UiMessageHandler { private static final String ENABLED = "enabled"; private static final String SPEED = "speed"; private static final String NAME = "name"; + private static final String WARN = "warn"; private static final String[] COL_IDS = { - AVAILABLE, AVAILABLE_IID, TYPE_IID, ID, - NUM_PORTS, MASTER_ID, MFR, HW, SW, + AVAILABLE, AVAILABLE_IID, TYPE_IID, + NAME, ID, MASTER_ID, NUM_PORTS, MFR, HW, SW, PROTOCOL, CHASSIS_ID, SERIAL }; private static final String ICON_ID_ONLINE = "active"; private static final String ICON_ID_OFFLINE = "inactive"; + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Override protected Collection<RequestHandler> createRequestHandlers() { return ImmutableSet.of( new DataRequestHandler(), + new NameChangeHandler(), new DetailRequestHandler() ); } + // Get friendly name of the device from the annotations + private static String deviceName(Device device) { + String name = device.annotations().value(AnnotationKeys.NAME); + return isNullOrEmpty(name) ? device.id().toString() : name; + } + + private static String deviceProtocol(Device device) { + String protocol = device.annotations().value(PROTOCOL); + return protocol != null ? protocol : ""; + } + private static String getTypeIconId(Device d) { return DEV_ICON_PREFIX + d.type().toString(); } @@ -121,16 +149,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler { boolean available = ds.isAvailable(id); String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; - String protocol = dev.annotations().value(PROTOCOL); - row.cell(ID, id) + .cell(NAME, deviceName(dev)) .cell(AVAILABLE, available) .cell(AVAILABLE_IID, iconId) .cell(TYPE_IID, getTypeIconId(dev)) .cell(MFR, dev.manufacturer()) .cell(HW, dev.hwVersion()) .cell(SW, dev.swVersion()) - .cell(PROTOCOL, protocol != null ? protocol : "") + .cell(PROTOCOL, deviceProtocol(dev)) .cell(NUM_PORTS, ds.getPorts(id).size()) .cell(MASTER_ID, ms.getMasterFor(id)); } @@ -144,15 +171,16 @@ public class DeviceViewMessageHandler extends UiMessageHandler { @Override public void process(long sid, ObjectNode payload) { - String id = string(payload, "id", "of:0000000000000000"); + String id = string(payload, ID, ZERO_URI); - DeviceId deviceId = DeviceId.deviceId(id); + DeviceId deviceId = deviceId(id); DeviceService service = get(DeviceService.class); MastershipService ms = get(MastershipService.class); Device device = service.getDevice(deviceId); - ObjectNode data = MAPPER.createObjectNode(); + ObjectNode data = objectNode(); data.put(ID, deviceId.toString()); + data.put(NAME, deviceName(device)); data.put(TYPE, capitalizeFully(device.type().toString())); data.put(TYPE_IID, getTypeIconId(device)); data.put(MFR, device.manufacturer()); @@ -161,9 +189,9 @@ public class DeviceViewMessageHandler extends UiMessageHandler { data.put(SERIAL, device.serialNumber()); data.put(CHASSIS_ID, device.chassisId().toString()); data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); - data.put(PROTOCOL, device.annotations().value(PROTOCOL)); + data.put(PROTOCOL, deviceProtocol(device)); - ArrayNode ports = MAPPER.createArrayNode(); + ArrayNode ports = arrayNode(); List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); Collections.sort(portList, (p1, p2) -> { @@ -176,13 +204,13 @@ public class DeviceViewMessageHandler extends UiMessageHandler { } data.set(PORTS, ports); - ObjectNode rootNode = MAPPER.createObjectNode(); + ObjectNode rootNode = objectNode(); rootNode.set(DETAILS, data); sendMessage(DEV_DETAILS_RESP, 0, rootNode); } private ObjectNode portData(Port p, DeviceId id) { - ObjectNode port = MAPPER.createObjectNode(); + ObjectNode port = objectNode(); LinkService ls = get(LinkService.class); String name = p.annotations().value(AnnotationKeys.PORT_NAME); @@ -206,4 +234,29 @@ public class DeviceViewMessageHandler extends UiMessageHandler { return port; } } + + + // handler for changing device friendly name + private final class NameChangeHandler extends RequestHandler { + private NameChangeHandler() { + super(DEV_NAME_CHANGE_REQ); + } + + @Override + public void process(long sid, ObjectNode payload) { + DeviceId deviceId = deviceId(string(payload, ID, ZERO_URI)); + String name = emptyToNull(string(payload, NAME, null)); + log.debug("Name change request: {} -- '{}'", deviceId, name); + + NetworkConfigService service = get(NetworkConfigService.class); + BasicDeviceConfig cfg = + service.addConfig(deviceId, BasicDeviceConfig.class); + + // Name attribute missing from the payload (or empty string) + // means that the friendly name should be unset. + cfg.name(name); + cfg.apply(); + sendMessage(DEV_NAME_CHANGE_RESP, 0, payload); + } + } } diff --git a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java new file mode 100644 index 00000000..5d97504e --- /dev/null +++ b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/ProcessorViewMessageHandler.java @@ -0,0 +1,108 @@ +/* + * 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 OBSERVER = "observer"; + private static final String DIRECTOR = "director"; + private static final String ADVISOR = "advisor"; + + 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 packet processor 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 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, (double) entry.averageNanos() / NANOS_IN_MS); + } + + private String processorType(int p) { + return p > DIRECTOR_MAX ? OBSERVER : p > ADVISOR_MAX ? DIRECTOR : ADVISOR; + } + + 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/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java index 2bd0bb61..86cf038b 100644 --- a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java +++ b/framework/src/onos/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() ); |