@Override public ObjectNode encode(Port port, CodecContext context) { checkNotNull(port, "Port cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(ELEMENT, port.element().id().toString()) .put(PORT_NAME, portName(port.number())) .put(IS_ENABLED, port.isEnabled()) .put(TYPE, port.type().toString().toLowerCase()) .put(PORT_SPEED, port.portSpeed()); return annotate(result, port, context); }
/** * Query bandwidth capacity on a port. * * @param did {@link DeviceId} * @param number {@link PortNumber} * @return bandwidth capacity */ private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) { // Check and use netcfg first. ConnectPoint cp = new ConnectPoint(did, number); BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class); if (config != null) { log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number); return Optional.of(config.capacity()); } // populate bandwidth value, assuming portSpeed == bandwidth Port port = deviceService.getPort(did, number); if (port != null) { return Optional.of(Bandwidth.mbps(port.portSpeed())); } return Optional.empty(); }
private DeviceEvent updatePort(Device device, Port oldPort, Port newPort, Map<PortNumber, Port> ports) { if (oldPort.isEnabled() != newPort.isEnabled() || oldPort.type() != newPort.type() || oldPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { ports.put(oldPort.number(), newPort); return new DeviceEvent(PORT_UPDATED, device, newPort); } return null; }
/** * Produces JSON array containing ports of the specified device. * * @param service device service * @param mapper object mapper * @param device infrastructure devices * @return JSON array */ public JsonNode jsonPorts(DeviceService service, ObjectMapper mapper, Device device) { ObjectNode result = mapper.createObjectNode(); ArrayNode ports = mapper.createArrayNode(); for (Port port : service.getPorts(device.id())) { if (isIncluded(port)) { ports.add(mapper.createObjectNode() .put("port", port.number().toString()) .put("isEnabled", port.isEnabled()) .put("type", port.type().toString().toLowerCase()) .put("portSpeed", port.portSpeed()) .set("annotations", annotations(mapper, port.annotations()))); } } result.set("device", jsonForEntity(device, Device.class)); result.set("ports", ports); return result; }
private void printPort(Port port) { String portName = portName(port.number()); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); }
protected void printPorts(DeviceService service, Device device) { List<Port> ports = new ArrayList<>(service.getPorts(device.id())); Collections.sort(ports, Comparators.PORT_COMPARATOR); for (Port port : ports) { if (!isIncluded(port)) { continue; } String portName = port.number().toString(); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); } } }
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations())); break; case ODUCLT: print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations())); break; case OMS: print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations())); break; case OTU: print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations(port.annotations())); break; default: