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 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(); } }
@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 ConnectPoint createConnectPoint(String devicePortString) { String[] splitted = devicePortString.split("/"); checkArgument(splitted.length == 2, "Connect point must be in \"deviceUri/portNumber\" format"); DeviceId deviceId = DeviceId.deviceId(splitted[0]); DeviceService deviceService = get(DeviceService.class); List<Port> ports = deviceService.getPorts(deviceId); for (Port port : ports) { if (splitted[1].equals(port.number().name())) { return new ConnectPoint(deviceId, port.number()); } } return null; }
@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 -> port.number().toString()) .collect(Collectors.toList()); }
/** * Add physical port to discovery process. * Send out initial LLDP and label it as slow port. * * @param port the port */ public void addPort(Port port) { boolean newPort = ports.add(port.number().toLong()); boolean isMaster = context.mastershipService().isLocalMaster(device.id()); if (newPort && isMaster) { log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id()); sendProbes(port.number().toLong()); } }
@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); } }
@Override public Map<ConnectPoint, SummaryFlowEntryWithLoad> loadSummary(Device device) { checkPermission(STATISTIC_READ); Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryLoad = new TreeMap<>(Comparators.CONNECT_POINT_COMPARATOR); if (device == null) { return summaryLoad; } List<Port> ports = new ArrayList<>(deviceService.getPorts(device.id())); for (Port port : ports) { ConnectPoint cp = new ConnectPoint(device.id(), port.number()); SummaryFlowEntryWithLoad sfe = loadSummaryPortInternal(cp); summaryLoad.put(cp, sfe); } return summaryLoad; }
private void loadAllEdgePorts() { deviceService.getAvailableDevices().forEach(d -> deviceService.getPorts(d.id()) .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number())))); }
private void unregisterPortResource(Device device, Port port) { DiscreteResource portResource = Resources.discrete(device.id(), port.number()).resource(); List<Resource> allResources = getDescendantResources(portResource); adminService.unregister(Lists.transform(allResources, Resource::id)); }
private boolean isBlacklisted(Port port) { return isBlacklisted(new ConnectPoint(port.element().id(), 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 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 printPort(Port port) { String portName = portName(port.number()); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); }
protected void printPorts(DeviceService service, Device device) { List<Port> ports = new ArrayList<>(service.getPorts(device.id())); Collections.sort(ports, Comparators.PORT_COMPARATOR); for (Port port : ports) { if (!isIncluded(port)) { continue; } String portName = port.number().toString(); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); } } }
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 void event(DeviceEvent event) { if (event.type() == DeviceEvent.Type.DEVICE_REMOVED) { removeLinks(event.subject().id()); } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) { removeLinks(new ConnectPoint(event.subject().id(), event.port().number())); } } }
private void setFlowRuleForTunnelTag(DeviceId deviceId, Port port, String vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchInPort(port.number()); tBuilder.setTunnelId(Long.parseLong(vni)); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) .withPriority(TUNNELTAG_RULE_PRIORITY) .withFlag(ForwardingObjective.Flag.SPECIFIC) .fromApp(appId) .add(); flowObjectiveService.forward(deviceId, fo); }