@Override protected Optional<OchPort> mapPort(Port port) { if (port instanceof OchPort) { return Optional.of((OchPort) port); } else if (port instanceof org.onosproject.net.OchPort) { // TODO remove after deprecation of old OchPort is complete // translate to new OchPort org.onosproject.net.OchPort old = (org.onosproject.net.OchPort) port; return Optional.of(new DefaultOchPort(old, old.signalType(), old.isTunable(), old.lambda())); } return OchPortHelper.asOchPort(port); }
// Creates a port description from the specified port. private PortDescription description(Port p) { switch (p.type()) { case OMS: OmsPort op = (OmsPort) p; return new OmsPortDescription( op.number(), op.isEnabled(), op.minFrequency(), op.maxFrequency(), op.grid()); case OCH: OchPort ochp = (OchPort) p; return new OchPortDescription( ochp.number(), ochp.isEnabled(), ochp.signalType(), ochp.isTunable(), ochp.lambda()); case ODUCLT: OduCltPort odup = (OduCltPort) p; return new OduCltPortDescription(odup.number(), odup.isEnabled(), odup.signalType()); default: return new DefaultPortDescription(p.number(), p.isEnabled(), p.type(), p.portSpeed()); } }
// Parses the given node with port information. private PortDescription parsePort(DeviceId deviceId, JsonNode node) { Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER")); // TL1-based ports have a name PortNumber port = null; if (node.has("name")) { for (Port p : deviceService.getPorts(deviceId)) { if (p.number().name().equals(node.get("name").asText())) { port = p.number(); break; } } } else { port = portNumber(node.path("port").asLong(0)); } if (port == null) { log.error("Cannot find port given in node {}", node); return null; } String portName = Strings.emptyToNull(port.name()); SparseAnnotations annotations = null; if (portName != null) { annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portName).build(); } switch (type) { case COPPER: return new DefaultPortDescription( port, node.path("enabled").asBoolean(true), type, node.path("speed").asLong(1_000), annotations); case FIBER: // Currently, assume OMS when FIBER. Provide sane defaults. annotations = annotations(node.get("annotations")); return new OmsPortDescription( port, node.path("enabled").asBoolean(true), CENTER, CENTER.add(TOTAL), Frequency.ofGHz(100), annotations); case ODUCLT: annotations = annotations(node.get("annotations")); OduCltPort oduCltPort = (OduCltPort) deviceService.getPort(deviceId, port); return new OduCltPortDescription( port, node.path("enabled").asBoolean(true), oduCltPort.signalType(), annotations); case OCH: annotations = annotations(node.get("annotations")); OchPort ochPort = (OchPort) deviceService.getPort(deviceId, port); return new OchPortDescription( port, node.path("enabled").asBoolean(true), ochPort.signalType(), ochPort.isTunable(), ochPort.lambda(), annotations); case OMS: annotations = annotations(node.get("annotations")); OmsPort omsPort = (OmsPort) deviceService.getPort(deviceId, port); return new OmsPortDescription( port, node.path("enabled").asBoolean(true), omsPort.minFrequency(), omsPort.maxFrequency(), omsPort.grid(), annotations); default: log.warn("{}: Unsupported Port Type"); } return new DefaultPortDescription( port, node.path("enabled").asBoolean(true), type, node.path("speed").asLong(1_000), annotations); }