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; }
@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); }
/** * Removes a port from the specified discovery helper. * @param port the port */ private void removePort(Port port) { if (port.element() instanceof Device) { Device d = (Device) port.element(); LinkDiscovery ld = discoverers.get(d.id()); if (ld != null) { ld.removePort(port.number()); } } else { log.warn("Attempted to remove non-Device port", port); } }
private DeviceEvent createPort(Device device, Port newPort, Map<PortNumber, Port> ports) { ports.put(newPort.number(), newPort); return new DeviceEvent(PORT_ADDED, device, newPort); }
private PortNumber getTunnelPort(DeviceId deviceId) { Port port = deviceService.getPorts(deviceId).stream() .filter(p -> p.annotations().value(PORT_NAME).equals( OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL)) .findAny().orElse(null); if (port == null) { log.error("No TunnelPort was created."); return null; } return port.number(); }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
private void processPortUpdated(Device device, Port port) { String portName = port.annotations().value(PORTNAME); synchronized (openstackPortInfoMap) { if (portName.startsWith(PORTNAME_PREFIX_VM)) { if (port.isEnabled()) { OpenstackSwitchingRulePopulator rulePopulator = new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, sgId -> sgRulePopulator.populateSecurityGroupRules(device.id(), sgId, vmIp, openstackPortInfoMap)); updatePortMap(device.id(), port.annotations().value(PORTNAME), openstackService.networks(), openstackService.subnets(), openstackPort); } else if (!port.isEnabled() && openstackPortInfoMap.containsKey(portName)) { log.debug("Flowrules according to the port {} were removed", port.number()); OpenstackSwitchingRulePopulator rulePopulator = new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, sgId -> sgRulePopulator.removeSecurityGroupRules(device.id(), sgId, openstackPortInfoMap.get(portName).ip(), openstackPortInfoMap, securityGroupMap)); dhcpService.removeStaticMapping(openstackPortInfoMap.get(port.annotations().value(PORTNAME)).mac()); openstackPortInfoMap.remove(port.annotations().value(PORTNAME));
/** * Returns OpenstackPort object for the Port reference given. * * @param port Port object * @return OpenstackPort reference, or null when not found */ public OpenstackPort openstackPort(Port port) { String uuid = port.annotations().value(PORT_NAME).substring(3); return openstackPortList.stream().filter(p -> p.id().startsWith(uuid)) .findAny().orElse(null); }
case PORT_ADDED: case PORT_UPDATED: if (port.isEnabled()) { updateDevice(device).ifPresent(ld -> updatePort(ld, port)); } else { log.debug("Port down {}", port); removePort(port); providerService.linksVanished(new ConnectPoint(port.element().id(), port.number())); log.debug("Port removed {}", port); removePort(port); providerService.linksVanished(new ConnectPoint(port.element().id(), port.number())); break; case DEVICE_REMOVED:
/** * Updates discovery helper state of the specified port. * * Adds a port to the discovery helper if up and discovery is enabled, * or calls {@link #removePort(Port)} otherwise. */ private void updatePort(LinkDiscovery discoverer, Port port) { if (port == null) { return; } if (port.number().isLogical()) { // silently ignore logical ports return; } if (rules.isSuppressed(port) || isBlacklisted(port)) { log.trace("LinkDiscovery from {} disabled by configuration", port); removePort(port); return; } // check if enabled and turn off discovery? if (!port.isEnabled()) { removePort(port); return; } discoverer.addPort(port); }
private String getPortStatStr(PortStatistics stat, Port port) { final String portName = port.annotations().value(AnnotationKeys.PORT_NAME); return String.format("port: %s(%s), ", stat.portNumber(), portName) + String.format("enabled: %b, ", port.isEnabled()) + String.format("pktRx: %d, ", stat.packetsReceived()) + String.format("pktTx: %d, ", stat.packetsSent()) + String.format("pktRxErr: %d, ", stat.packetsRxErrors()) + String.format("pktTxErr: %d, ", stat.packetsTxErrors()) + String.format("pktRxDrp: %d, ", stat.packetsRxDropped()) + String.format("pktTxDrp: %d", stat.packetsTxDropped()); }
public boolean isSuppressed(Port port) { Element parent = port.element(); if (parent instanceof Device) { if (isSuppressed((Device) parent)) { return true; } } final Annotations annotations = port.annotations(); if (containsSuppressionAnnotation(annotations)) { return true; } return false; }
@Override public boolean is(Port port) { return port != null && port.type() == Port.Type.OMS && super.is(port); }
/** * 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(); }
/** * Transform Port instance to Optical specific port, if it is well-formed. * * @param port Port instance to translate * @return Optical specific port instance or original {@code port}. */ public Port augment(Port port) { if (port == null) { return null; } return optdev.getUnchecked(port.element()) .map(odev -> odev.port(port)) .orElse(port); }
@Override protected List<String> choices() { DeviceId deviceId = lookForDeviceId(); if (deviceId == null) { return Collections.emptyList(); } DeviceService deviceService = getService(DeviceService.class); return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false) .map(port -> Long.toString(port.number().toLong())) .collect(Collectors.toList()); } }
private PortNumber getVxlanPortNumber(DeviceId deviceId) { Iterable<Port> ports = deviceService.getPorts(deviceId); Port vxlanPort = Sets.newHashSet(ports).stream() .filter(p ->!p.number().equals(PortNumber.LOCAL)) .filter(p ->p.annotations().value(AnnotationKeys.PORT_NAME) .startsWith(VXLANPORT_HEAD)) .findFirst().get(); return vxlanPort.number(); } }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
@Override public OpenstackPort port(Port port) { String uuid = port.annotations().value(PORT_NAME).substring(3); return getPorts().stream() .filter(p -> p.id().startsWith(uuid)) .findAny().orElse(null); }