@Override public Collection<BridgeDescription> getBridges() { DriverHandler handler = handler(); DeviceId deviceId = handler.data().deviceId(); OvsdbClientService ovsdbNode = getOvsdbNode(handler); Set<OvsdbBridge> ovsdbSet = ovsdbNode.getBridges(); Collection<BridgeDescription> bridges = Sets.newHashSet(); ovsdbSet.forEach( o -> { BridgeName bridgeName = BridgeName.bridgeName(o.bridgeName().toString()); DeviceId ownDeviceId = DeviceId.deviceId(o.datapathId().toString()); BridgeDescription description = new DefaultBridgeDescription(bridgeName, deviceId, ownDeviceId); bridges.add(description); }); return bridges; }
@Override public ExtensionCriterion read(Kryo kryo, Input input, Class<ExtensionCriterion> type) { ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); byte[] bytes = (byte[]) kryo.readClassAndObject(input); ExtensionSelector selector; try { DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); selector = resolver.getExtensionSelector(exType); selector.deserialize(bytes); } catch (ItemNotFoundException | IllegalArgumentException e) { selector = new UnresolvedExtensionSelector(bytes, exType); } return Criteria.extension(selector, deviceId); }
private void connectDevices() { RestProviderConfig cfg = cfgService.getConfig(appId, RestProviderConfig.class); try { if (cfg != null && cfg.getDevicesAddresses() != null) { // Precomputing the devices to be removed Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values()); toBeRemoved.removeAll(cfg.getDevicesAddresses()); // Adding new devices cfg.getDevicesAddresses() .stream() .filter(device -> testDeviceConnection(device)) .forEach( device -> { deviceAdded(device); }); // Removing devices not wanted anymore toBeRemoved.stream().forEach(device -> deviceRemoved(device)); } } catch (ConfigException e) { log.error("Configuration error {}", e); } log.info("REST Devices {}", controller.getDevices()); controller .getDevices() .keySet() .forEach( deviceId -> { DriverHandler h = driverService.createHandler(deviceId); PortDiscovery portConfig = h.behaviour(PortDiscovery.class); if (portConfig != null) { providerService.updatePorts(deviceId, portConfig.getPorts()); } else { log.warn("No portGetter behaviour for device {}", deviceId); } }); }
private OvsdbClientService getOvsdbNode(DriverHandler handler) { OvsdbController ovsController = handler.get(OvsdbController.class); DeviceId deviceId = handler.data().deviceId(); OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId); return ovsController.getOvsdbClient(nodeId); }