/** * 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 void invalidatePipeliner(DeviceId id) { log.info("Invalidating cached pipeline behaviour for {}", id); driverHandlers.remove(id); pipeliners.remove(id); if (deviceService.isAvailable(id)) { getAndInitDevicePipeliner(id); } }
private void updateDevice() { if (controlPlaneConnectPoint != null && deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) { DeviceId deviceId = controlPlaneConnectPoint.deviceId(); interfaceService.getInterfaces().stream() .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) .forEach(this::provisionInterface); log.info("Set up interfaces on {}", controlPlaneConnectPoint.deviceId()); } }
private void updateDevice() { if (deviceId != null && deviceService.isAvailable(deviceId)) { Set<Interface> intfs; if (interfaces.isEmpty()) { intfs = interfaceService.getInterfaces(); } else { // TODO need to fix by making interface names globally unique intfs = interfaceService.getInterfaces().stream() .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) .filter(intf -> interfaces.contains(intf.name())) .collect(Collectors.toSet()); } processIntfFilters(true, intfs); } }
@Override public void event(DeviceEvent event) { DeviceEvent.Type type = event.type(); DeviceId deviceId = event.subject().id(); if (type == PORT_STATS_UPDATED) { // Update port load updateDeviceData(deviceId); } else if (type == DEVICE_REMOVED || (type == DEVICE_AVAILABILITY_CHANGED && !deviceService.isAvailable(deviceId))) { // Clean-up all port loads pruneDeviceData(deviceId); } } }
@Override public void event(MastershipEvent event) { switch (event.type()) { case MASTER_CHANGED: log.debug("mastership changed on device {}", event.subject()); if (deviceService.isAvailable(event.subject())) { setupPipelineHandler(event.subject()); } break; case BACKUPS_CHANGED: break; default: break; } } }
@Override public boolean isRelevant(DeviceEvent event) { return event.type().equals(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) && deviceService.isAvailable(event.subject().id()); }
private void handleEvent(DeviceEvent event) { Device device = event.subject(); boolean isRelevant = mastershipService.isLocalMaster(device.id()) && deviceService.isAvailable(device.id()); if (isRelevant) { pollDeviceFlowEntries(device); } } }
@Override public void event(DeviceEvent event) { eventHandlingExecutor.execute(() -> { try { if (driverService == null) { // Event came in after the driver service shut down, nothing to be done return; } Device device = event.subject(); Driver driver = driverService.getDriver(device.id()); if (driver == null) { return; } if (!Boolean.parseBoolean(driver.getProperty(SUPPORT_PACKET_REQUEST_PROPERTY))) { return; } if (!deviceService.isAvailable(event.subject().id())) { return; } pushRulesToDevice(device); } catch (Exception e) { log.warn("Failed to process {}", event, e); } }); } }
@Override public void event(DeviceEvent event) { switch (event.type()) { case DEVICE_ADDED: case DEVICE_AVAILABILITY_CHANGED: if (deviceService.isAvailable(event.subject().id())) { DeviceId deviceId = event.subject().id(); CompletableFuture<DeviceId> future = devices.get(deviceId); if (future != null) { future.complete(deviceId); } } break; case DEVICE_UPDATED: case DEVICE_REMOVED: case DEVICE_SUSPENDED: case PORT_ADDED: case PORT_UPDATED: case PORT_REMOVED: default: break; } } }
@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 void handleEvent(DeviceEvent event) { Device device = event.subject(); boolean isRelevant = mastershipService.isLocalMaster(device.id()) && deviceService.isAvailable(device.id()); if (isRelevant) { pollDeviceGroups(device.id()); } } }
@Override public void event(DeviceEvent event) { switch (event.type()) { case DEVICE_REMOVED: case DEVICE_AVAILABILITY_CHANGED: DeviceId deviceId = event.subject().id(); if (!deviceService.isAvailable(deviceId)) { if (purgeOnDisconnection) { store.purgeFlowRule(deviceId); } } break; default: break; } } }
private void handleEvent(DeviceEvent event) { Device device = event.subject(); boolean isRelevant = mastershipService.isLocalMaster(device.id()) && deviceService.isAvailable(device.id()); if (isRelevant) { pollDeviceMeters(device.id()); } } }
private void processEventInternal(DeviceEvent event) { switch (event.type()) { case DEVICE_REMOVED: case DEVICE_AVAILABILITY_CHANGED: DeviceId deviceId = event.subject().id(); if (!deviceService.isAvailable(deviceId)) { log.debug("Device {} became unavailable for {}; clearing initial audit status", deviceId, event.type()); store.deviceInitialAuditCompleted(deviceId, false); if (purgeOnDisconnection) { store.purgeGroupEntry(deviceId); } } break; default: break; } } }
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 void event(DeviceEvent event) { final Device device = event.subject(); switch (event.type()) { case DEVICE_ADDED: case DEVICE_UPDATED: case DEVICE_AVAILABILITY_CHANGED: if (!deviceService.isAvailable(device.id())) { signalStatusUnknown(device.id()); } break; case DEVICE_REMOVED: case DEVICE_SUSPENDED: signalStatusUnknown(device.id()); break; case PORT_ADDED: case PORT_UPDATED: case PORT_REMOVED: case PORT_STATS_UPDATED: default: break; } } }
@Override public void event(DeviceEvent event) { switch (event.type()) { case DEVICE_ADDED: case DEVICE_AVAILABILITY_CHANGED: if (deviceService.isAvailable(event.subject().id())) { log.info("Device connected {}", event.subject().id()); if (event.subject().id().equals(deviceId)) { updateDevice(); } } break; // TODO other cases case DEVICE_UPDATED: case DEVICE_REMOVED: case DEVICE_SUSPENDED: case PORT_ADDED: case PORT_UPDATED: case PORT_REMOVED: default: break; } } }
/** * Pushes packet intercept flow rules to the device. * * @param device the device to push the rules to * @param request the packet request */ private void pushRule(Device device, PacketRequest request) { if (!device.type().equals(Device.Type.SWITCH)) { return; } if (!deviceService.isAvailable(device.id())) { return; } ForwardingObjective forwarding = createBuilder(request) .add(new ObjectiveContext() { @Override public void onError(Objective objective, ObjectiveError error) { log.warn("Failed to install packet request {} to {}: {}", request, device.id(), error); } }); objectiveService.forward(device.id(), forwarding); }
/** * 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))); } } } }