/** * 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; }
/** * 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); } }
@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); }
@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); }
/** * 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); }
return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations);
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); } }