@Override public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) { checkPermission(DRIVER_READ); return registry.getDrivers().stream() .filter(d -> d.hasBehaviour(withBehaviour)) .collect(Collectors.toSet()); }
.put(NAME, driver.name()) .put(MANUFACTURER, driver.manufacturer()) .put(HW_VERSION, driver.hwVersion()) .put(SW_VERSION, driver.swVersion()); if (driver.parent() != null) { result.put(PARENT, driver.parent().name()); driver.behaviours().forEach(behaviour -> { ObjectNode entry = context.mapper().createObjectNode() .put(BEHAVIORS_NAME, behaviour.getCanonicalName()) .put(BEHAVIORS_IMPLEMENTATION_NAME, driver.implementation(behaviour).getCanonicalName()); driver.properties().forEach((name, value) -> { ObjectNode entry = context.mapper().createObjectNode() .put("name", name)
private void printDriver(Driver driver, boolean first) { if (outputJson()) { json(driver); } else if (nameOnly) { print("%s", driver.name()); } else { List<Driver> parents = Optional.ofNullable(driver.parents()) .orElse(ImmutableList.of()); List<String> parentsNames = parents.stream() .map(Driver::name).collect(Collectors.toList()); if (first) { print(FMT, driver.name(), parentsNames, driver.manufacturer(), driver.hwVersion(), driver.swVersion()); } else { print(" Inherited from %s", driver.name()); } driver.behaviours().forEach(b -> printBehaviour(b, driver)); driver.properties().forEach((k, v) -> print(FMT_P, k, v)); //recursion call to print each parent parents.stream().forEach(parent -> printDriver(parent, false)); } }
private boolean matches(Driver d, String mfr, String hw, String sw) { // TODO: consider pre-compiling the expressions in the future return mfr.matches(d.manufacturer()) && hw.matches(d.hwVersion()) && sw.matches(d.swVersion()); }
@Override public void registerProvider(DriverProvider provider) { provider.getDrivers().forEach(driver -> { Driver d = addDriver(driver); driverByKey.put(key(driver.manufacturer(), driver.hwVersion(), driver.swVersion()), d); d.behaviours().forEach(b -> { Class<? extends Behaviour> implementation = d.implementation(b); classes.put(b.getName(), b); classes.put(implementation.getName(), implementation); }); post(new DriverEvent(DRIVER_ENHANCED, driver)); }); providers.add(provider); checkRequiredDrivers(); }
private DomainIntentConfigurable initDomainIntentDriver(DeviceId deviceId) { // Attempt to lookup the handler in the cache DriverHandler handler = driverHandlers.get(deviceId); if (handler == null) { try { // Otherwise create it and if it has DomainIntentConfig behaviour, cache it handler = driverService.createHandler(deviceId); if (!handler.driver().hasBehaviour(DomainIntentConfigurable.class)) { log.warn("DomainIntentConfig behaviour not supported for device {}", deviceId); return null; } } catch (ItemNotFoundException e) { log.warn("No applicable driver for device {}", deviceId); return null; } driverHandlers.put(deviceId, handler); } // Always (re)initialize the pipeline behaviour log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId); return handler.behaviour(DomainIntentConfigurable.class); } }
private Driver buildMergedDriver(PiPipeconfId pipeconfId, String baseDriverName, String newDriverName) { final Driver baseDriver = getDriver(baseDriverName); if (baseDriver == null) { log.error("Base driver {} not found, cannot build a merged one", baseDriverName); return null; } final PiPipeconf pipeconf = pipeconfs.get(pipeconfId); if (pipeconf == null) { log.error("Pipeconf {} is not registered, cannot build a merged driver", pipeconfId); return null; } // extract the behaviours from the pipipeconf. final Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = new HashMap<>(); pipeconf.behaviours().forEach( b -> behaviours.put(b, pipeconf.implementation(b).get())); final Driver piPipeconfDriver = new DefaultDriver( newDriverName, baseDriver.parents(), baseDriver.manufacturer(), baseDriver.hwVersion(), baseDriver.swVersion(), behaviours, new HashMap<>()); // take the base driver created with the behaviours of the PiPeconf and // merge it with the base driver that was assigned to the device return piPipeconfDriver.merge(baseDriver); }
.map(BasicDeviceConfig::driver) .map(driverService::getDriver) .filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)) .map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
@Override public int hashCode() { return Objects.hashCode(driver.name()); } }
private void printBehaviour(Class<? extends Behaviour> behaviour, Driver driver) { print(FMT_B, behaviour.getCanonicalName(), driver.implementation(behaviour).getCanonicalName()); }
private void setupPipelineHandler(DeviceId deviceId) { // Attempt to lookup the handler in the cache DriverHandler handler = driverHandlers.get(deviceId); if (handler == null) { try { // Otherwise create it and if it has pipeline behaviour, cache it handler = driverService.createHandler(deviceId); if (!handler.driver().hasBehaviour(Pipeliner.class)) { log.warn("Pipeline behaviour not supported for device {}", deviceId); return; } } catch (ItemNotFoundException e) { log.warn("No applicable driver for device {}", deviceId); return; } driverHandlers.put(deviceId, handler); } // Always (re)initialize the pipeline behaviour log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId); Pipeliner pipeliner = handler.behaviour(Pipeliner.class); pipeliner.init(deviceId, context); pipeliners.putIfAbsent(deviceId, pipeliner); }
private DeviceDescription getDeviceDescription(DeviceId did) { Device device = deviceService.getDevice(did); DeviceDescriptionDiscovery discovery = null; if (device == null) { // Device not yet in the core. Manually get a driver. Driver driver = driverService.getDriver(MANUFACTURER, HW_VERSION, SW_VERSION); if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) { discovery = driver.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(driver, did)), DeviceDescriptionDiscovery.class); } } else if (device.is(DeviceDescriptionDiscovery.class)) { discovery = device.as(DeviceDescriptionDiscovery.class); } if (discovery == null) { log.warn("No DeviceDescriptionDiscovery behavior for device {}", did); return null; } else { return discovery.discoverDeviceDetails(); } }
@Override public void unregisterProvider(DriverProvider provider) { provider.getDrivers().forEach(driver -> { removeDriver(driver); driverByKey.remove(key(driver.manufacturer(), driver.hwVersion(), driver.swVersion())); post(new DriverEvent(DRIVER_REDUCED, driver)); }); providers.remove(provider); checkRequiredDrivers(); }
if (!handler.driver().hasBehaviour(Pipeliner.class)) { log.debug("Pipeline behaviour not supported for device {}", deviceId); handler.driver().name(), deviceId); hTime = now(); Pipeliner pipeliner = handler.behaviour(Pipeliner.class);
if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) { Dpid did = new Dpid(dpid); DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did)))); OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(handler, OpenFlowSwitchDriver.class); ofSwitchDriver.init(did, desc, ofv); ofSwitchDriver.setAgent(agent);
private boolean isMultiplexingSupported(ConnectPoint cp) { Driver driver = driverService.getDriver(cp.deviceId()); return driver != null && driver.hasBehaviour(TributarySlotQuery.class) && staticPort(cp) == null; }
private OFAction buildExtensionAction(ExtensionTreatment i, DeviceId deviceId) { if (!driverService.isPresent()) { log.error("No driver service present"); return null; } Driver driver = driverService.get().getDriver(deviceId); if (driver.hasBehaviour(ExtensionTreatmentInterpreter.class)) { DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); ExtensionTreatmentInterpreter interpreter = handler.behaviour(ExtensionTreatmentInterpreter.class); return interpreter.mapInstruction(factory, i); } return null; } }
@Override public void event(DriverEvent event) { executor.execute(() -> attemptMergeAll(event.subject().name())); }