/** * Builds port description. * * @param deviceId device ID for the port * @param portNumber port number of the link * @return list of port description */ private List<PortDescription> buildPortDescriptions(DeviceId deviceId, PortNumber portNumber) { List<PortDescription> portList; if (portMap.containsKey(deviceId)) { portList = portMap.get(deviceId); } else { portList = new ArrayList<>(); } if (portNumber != null) { PortDescription portDescriptions = new DefaultPortDescription(portNumber, true); portList.add(portDescriptions); } portMap.put(deviceId, portList); return portList; }
private PortDescription ensurePortEnabledState(PortDescription desc, boolean enabled) { if (desc.isEnabled() != enabled) { return DefaultPortDescription.builder(desc) .isEnabled(enabled) .build(); } return desc; }
/** * Puts PortDescription, merging annotations as necessary. * * @param newDesc new PortDescription * @return previous PortDescription */ public synchronized PortDescription putPortDesc(PortDescription newDesc) { PortDescription oldOne = portDescs.get(newDesc.portNumber()); PortDescription newOne = newDesc; if (oldOne != null) { SparseAnnotations merged = union(oldOne.annotations(), newDesc.annotations()); newOne = new DefaultPortDescription(newOne, merged); } return portDescs.put(newOne.portNumber(), newOne); } }
DefaultPortDescription.Builder builder = DefaultPortDescription.builder() .withPortNumber(portNumber); if (portNode.has(ENABLED)) {
@Override public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) { log.debug("Delete link {}", ospfRouter.routerIp().toString()); if (linkProviderService == null) { return; } LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed); //Updating ports of the link List<PortDescription> srcPortDescriptions = new LinkedList<>(); srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true)); deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions); List<PortDescription> dstPortDescriptions = new LinkedList<>(); dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true)); deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions); linkProviderService.linkVanished(linkDes); }
portDescs.add(DefaultPortDescription.builder().withPortNumber(number) .isEnabled(isEnabled).build());
@Override public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) { log.debug("Addlink {}", ospfRouter.routerIp()); LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed); //If already link exists, return if (linkService.getLink(linkDes.src(), linkDes.dst()) != null || linkProviderService == null) { return; } //Updating ports of the link List<PortDescription> srcPortDescriptions = new LinkedList<>(); srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true)); deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions); List<PortDescription> dstPortDescriptions = new LinkedList<>(); dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true)); deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions); linkProviderService.linkDetected(linkDes); }
@Override public void deletePort(DeviceId deviceId, PortDescription basePortDescription) { checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(basePortDescription, PORT_DESCRIPTION_NULL); checkValidity(); if (!mastershipService.isLocalMaster(deviceId)) { // Never been a master for this device // any update will be ignored. log.trace("Ignoring {} port update on standby node. {}", deviceId, basePortDescription); return; } Device device = getDevice(deviceId); if (device == null) { log.trace("Device not found: {}", deviceId); } PortDescription newPortDescription = DefaultPortDescription.builder(basePortDescription) .isRemoved(true) .build(); final DeviceEvent event = store.updatePortStatus(this.provider().id(), deviceId, newPortDescription); if (event != null) { log.info("Device {} port {} status changed", deviceId, event.port().number()); post(event); } }
/** * Build a portDescription from a given Ethernet port description. * * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFPortDesc port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, enabled, type, portSpeed(port), annotations); }
/** * Updates {@link PortDescription} using specified number and annotations. * * @param port {@link PortNumber} to use in updated description * @param sa annotations to use in updated description * @param descr base {@link PortDescription} * @return updated {@link PortDescription} */ private static PortDescription updateDescription(PortNumber port, SparseAnnotations sa, PortDescription descr) { if (port.exactlyEquals(descr.portNumber()) && sa.equals(descr.annotations())) { // result is no-op return descr; } return DefaultPortDescription.builder(descr) .withPortNumber(port) .annotations(sa) .build(); }
return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations);
@Override public PortDescription combine(ConnectPoint cp, PortDescription descr) { PortAnnotationConfig cfg = lookupConfig(cp); if (cfg == null) { return descr; } Map<String, String> annotations = cfg.annotations(); if (annotations.isEmpty()) { return descr; } Builder builder = DefaultAnnotations.builder(); builder.putAll(descr.annotations()); builder.putAll(annotations); return DefaultPortDescription.builder(descr) .annotations(builder.build()) .build(); }
private PortDescription buildPortDescription(OFPortStatus status) { OFPortDesc port = status.getDesc(); if (status.getReason() != OFPortReason.DELETE) { return buildPortDescription(port); } else { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, false, type, portSpeed(port), annotations); } }
return DefaultPortDescription.builder() .withPortNumber(number) .isEnabled(isEnabled)
/** * Creates OCh port DefaultPortDescription based on the supplied information. * * @param number port number * @param isEnabled port enabled state * @param signalType ODU signal type * @param isTunable tunable wavelength capability * @param lambda OCh signal * @param annotationsIn key/value annotations map * @return OCh port DefaultPortDescription with OCh annotations */ public static PortDescription ochPortDescription(PortNumber number, boolean isEnabled, OduSignalType signalType, boolean isTunable, OchSignal lambda, SparseAnnotations annotationsIn) { Builder builder = DefaultAnnotations.builder(); builder.putAll(annotationsIn); builder.set(TUNABLE, String.valueOf(isTunable)); builder.set(LAMBDA, OchSignalCodec.encode(lambda).toString()); builder.set(SIGNAL_TYPE, signalType.toString()); DefaultAnnotations annotations = builder.build(); long portSpeed = signalType.bitRate(); return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled) .type(Port.Type.OCH).portSpeed(portSpeed).annotations(annotations) .build(); }
/** * Creates OTU port description based on the supplied information. * * @param number port number * @param isEnabled port enabled state * @param signalType OTU client signal type * @param annotations key/value annotations map * @return port description */ public static PortDescription otuPortDescription(PortNumber number, boolean isEnabled, OtuSignalType signalType, SparseAnnotations annotations) { Builder builder = DefaultAnnotations.builder(); builder.putAll(annotations); builder.set(SIGNAL_TYPE, signalType.toString()); long portSpeed = 0; // TODO specify appropriate value? return DefaultPortDescription.builder() .withPortNumber(number) .isEnabled(isEnabled) .type(Port.Type.OTU) .portSpeed(portSpeed) .annotations(builder.build()) .build(); }
/** * Creates ODU client port description based on the supplied information. * * @param number port number * @param isEnabled port enabled state * @param signalType ODU client signal type * @param annotations key/value annotations map * @return port description */ public static PortDescription oduCltPortDescription(PortNumber number, boolean isEnabled, CltSignalType signalType, SparseAnnotations annotations) { Builder builder = DefaultAnnotations.builder(); builder.putAll(annotations); builder.set(SIGNAL_TYPE, signalType.toString()); long portSpeed = signalType.bitRate(); return DefaultPortDescription.builder() .withPortNumber(number) .isEnabled(isEnabled) .type(Port.Type.ODUCLT) .portSpeed(portSpeed) .annotations(builder.build()) .build(); }