/** * 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); }
/** * 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); } }
@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); }
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; }
private boolean isBlacklisted(Port port) { return isBlacklisted(new ConnectPoint(port.element().id(), port.number())); }
private void printVlans(Port port) { DeviceService deviceService = get(DeviceService.class); DriverService driverService = get(DriverService.class); DeviceId deviceId = (DeviceId) port.element().id(); Device device = deviceService.getDevice(deviceId); if (!device.is(VlanQuery.class)) { // The relevant behavior is not supported by the device. print(NO_SUPPORT); return; } DriverHandler h = driverService.createHandler(deviceId); VlanQuery vlanQuery = h.behaviour(VlanQuery.class); try { Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number()); if (vlanIds.isEmpty()) { print(VLAN_NOT_AVAILABLE); } else { print(AVAIL_VLANS, getRanges(vlanIds).toString()); } } catch (Exception e) { print(FAILURE + e.getMessage()); } }
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 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; }