@Override public void requestPackets(PacketRequest request) { DeviceId deviceid = request.deviceId().orElse(null); if (deviceid != null) { Device device = deviceService.getDevice(deviceid); if (device != null) { pushRule(deviceService.getDevice(deviceid), request); } } else { pushToAllDevices(request); } }
/** * Returns a completable future that completes when the device is available * for the first time. * * @param deviceId ID of the device * @return completable future */ public CompletableFuture<DeviceId> getDevice(DeviceId deviceId) { CompletableFuture<DeviceId> future = new CompletableFuture<>(); return devices.computeIfAbsent(deviceId, deviceId1 -> { if (deviceService.isAvailable(deviceId)) { future.complete(deviceId); } return future; }); }
private AsyncDeviceFetcher(DeviceService deviceService) { this.deviceService = deviceService; deviceService.addListener(listener); }
@Activate protected void activate() { executorService = newFixedThreadPool(4, groupedThreads("onos/objective-installer", "%d", log)); flowObjectiveStore.setDelegate(delegate); mastershipService.addListener(mastershipListener); deviceService.addListener(deviceListener); deviceService.getDevices().forEach(device -> setupPipelineHandler(device.id())); deviceCompositionTreeMap = Maps.newConcurrentMap(); log.info("Started"); }
private void updatePortsAndStats(DeviceId did) { Device device = deviceService.getDevice(did); if (device.is(DeviceDescriptionDiscovery.class)) { DeviceDescriptionDiscovery discovery = device.as(DeviceDescriptionDiscovery.class); List<PortDescription> portDescriptions = discovery.discoverPortDetails(); if (portDescriptions != null) { providerService.updatePorts(did, portDescriptions); } } else { log.warn("No DeviceDescriptionDiscovery behavior for device {}", did); } try { Collection<PortStatistics> portStats = getPortStatistics(controller.getAgent(did), deviceService.getPorts(did)); providerService.updatePortStatistics(did, portStats); } catch (Bmv2RuntimeException e) { log.warn("Unable to get port statistics for {}: {}", did, e.explain()); } }
void terminate() { deviceService.removeListener(deviceListener); deviceService = null; providerService = null; mastershipService = null; poller.cancel(true); executor.shutdown(); }
/** * Removes packet request flow rule from all devices. * * @param request the packet request */ private void removeFromAllDevices(PacketRequest request) { deviceService.getAvailableDevices().forEach(d -> removeRule(d, request)); }
/** * Updates ports of the specified device to the specified discovery helper. */ private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) { deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p)); }
private void loadAllEdgePorts() { deviceService.getAvailableDevices().forEach(d -> deviceService.getPorts(d.id()) .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number())))); }
private void processDeviceEvent(DeviceEvent event) { //FIXME handle the case where a device is suspended, this may or may not come up DeviceEvent.Type type = event.type(); DeviceId id = event.subject().id(); if (type == DEVICE_ADDED || type == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(id)) { // When device is added or becomes available, add all its ports deviceService.getPorts(event.subject().id()) .forEach(p -> addEdgePort(new ConnectPoint(id, p.number()))); } else if (type == DEVICE_REMOVED || type == DEVICE_AVAILABILITY_CHANGED && !deviceService.isAvailable(id)) { // When device is removed or becomes unavailable, remove all its ports. // Note: cannot rely on Device subsystem, ports may be gone. Optional.ofNullable(connectionPoints.remove(id)) .orElse(ImmutableSet.of()) .forEach(point -> post(new EdgePortEvent(EDGE_PORT_REMOVED, point))); } else if (type == DeviceEvent.Type.PORT_ADDED || type == PORT_UPDATED && event.port().isEnabled()) { addEdgePort(new ConnectPoint(id, event.port().number())); } else if (type == DeviceEvent.Type.PORT_REMOVED || type == PORT_UPDATED && !event.port().isEnabled()) { removeEdgePort(new ConnectPoint(id, event.port().number())); } }
@Override public ObjectNode encode(Device device, CodecContext context) { checkNotNull(device, "Device cannot be null"); DeviceService service = context.getService(DeviceService.class); DriverService driveService = context.getService(DriverService.class); ObjectNode result = context.mapper().createObjectNode() .put(ID, device.id().toString()) .put(TYPE, device.type().name()) .put(AVAILABLE, service.isAvailable(device.id())) .put(ROLE, service.getRole(device.id()).toString()) .put(MFR, device.manufacturer()) .put(HW, device.hwVersion()) .put(SW, device.swVersion()) .put(SERIAL, device.serialNumber()) .put(DRIVER, driveService.getDriver(device.id()).name()) .put(CHASSIS_ID, device.chassisId().toString()) .put(LAST_UPDATE, Long.toString(service.getLastUpdatedInstant(device.id()))) .put(HUMAN_READABLE_LAST_UPDATE, service.localStatus(device.id())); return annotate(result, device, context); }
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; }
/** * Prints information about the specified device. * * @param deviceService device service * @param device infrastructure device */ protected void printDevice(DeviceService deviceService, Device device) { if (device != null) { String driver = get(DriverService.class).getDriver(device.id()).name(); if (shortOnly) { print(FMT_SHORT, device.id(), deviceService.isAvailable(device.id()), deviceService.getRole(device.id()), device.type(), driver); } else { print(FMT, device.id(), deviceService.isAvailable(device.id()), deviceService.localStatus(device.id()), deviceService.getRole(device.id()), device.type(), device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId(), driver, annotations(device.annotations(), ImmutableSet.of(AnnotationKeys.DRIVER))); } } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Fetch our service and feed it's offerings to the string completer DeviceService service = AbstractShellCommand.get(DeviceService.class); // Generate the device ID/port number identifiers for (Device device : service.getDevices()) { SortedSet<String> strings = delegate.getStrings(); for (Port port : service.getPorts(device.id())) { if (!port.number().isLogical()) { strings.add(device.id().toString() + "/" + port.number()); } } } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
void terminate() { deviceService.removeListener(deviceListener); deviceService = null; meterProviderService = null; mastershipService = null; poller.cancel(true); executor.shutdown(); }
@Override public Set<DomainId> getDomainIds() { Set<DomainId> domIds = new HashSet<>(); deviceService.getAvailableDevices().forEach(dev -> domIds.add(getAnnotatedDomainId(dev))); return domIds; }
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(); }
deviceService.getAvailableDevices().forEach(d -> { if (!d.equals(device)) { deviceService.getPorts(d.id()).forEach(p -> { String pName = p.annotations().value(PORT_NAME); if (!p.equals(port) && vni.equals(getVniForPort(pName))) {
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; }
/** * Returns true if device does not accept flow rules, false otherwise. * * @param deviceId the device * @return true if device does not accept flow rule, false otherwise */ private boolean isNoFlowRule(DeviceId deviceId) { return NO_FLOWRULE_DEVICES.contains( Optional.ofNullable(deviceService.getDevice(deviceId)) .map(Device::type) .orElse(Type.OTHER)); }