private boolean isMultiplexingSupported(ConnectPoint cp) { Driver driver = driverService.getDriver(cp.deviceId()); return driver != null && driver.hasBehaviour(TributarySlotQuery.class) && staticPort(cp) == null; }
/** * Retrieves {@link ProtectionConfigBehaviour} for the Device. * * @param did {@link DeviceId} of the Device to fetch * @return {@link ProtectionConfigBehaviour} * or throws {@link UnsupportedOperationException} on error. */ private ProtectionConfigBehaviour getBehaviour(DeviceId did) { DriverHandler handler = driverService.createHandler(did); if (!handler.hasBehaviour(ProtectionConfigBehaviour.class)) { log.error("{} does not support protection", did); throw new UnsupportedOperationException(did + " does not support protection"); } return handler.behaviour(ProtectionConfigBehaviour.class); }
@Activate protected void activate() { cfgService.registerProperties(getClass()); executorService = newFixedThreadPool(numThreads, groupedThreads(GROUP_THREAD_NAME, WORKER_PATTERN, log)); flowObjectiveStore.setDelegate(delegate); deviceService.addListener(deviceListener); driverService.addListener(driverListener); log.info("Started"); }
@Override protected void doExecute() { DriverService service = get(DriverService.class); if (driverName != null) { printDriver(service.getDriver(driverName), true); } else { if (outputJson()) { json(service.getDrivers()); } else { service.getDrivers() .stream() .sorted(Comparator.comparing(Driver::name)) .forEach(d -> printDriver(d, true)); } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); SortedSet<String> strings = delegate.getStrings(); // Fetch our service and feed it's offerings to the string completer DriverService service = AbstractShellCommand.get(DriverService.class); service.getDrivers().forEach(d -> strings.add(d.name())); // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
private DriverHandler getDriver(DeviceId devId) { Driver driver = driverService.getDriver(devId); DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId)); return handler; } }
private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) { try { DriverHandler handler = driverService.createHandler(device); if (handler == null || !handler.hasBehaviour(VlanQuery.class)) { return ImmutableSet.of(); } VlanQuery query = handler.behaviour(VlanQuery.class); if (query == null) { return ImmutableSet.of(); } return query.queryVlanIds(port); } catch (ItemNotFoundException e) { return ImmutableSet.of(); } }
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; } }
private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) { try { DriverHandler handler = driverService.createHandler(device); if (handler == null || !handler.hasBehaviour(MplsQuery.class)) { return ImmutableSet.of(); } MplsQuery query = handler.behaviour(MplsQuery.class); if (query == null) { return ImmutableSet.of(); } return query.queryMplsLabels(port); } catch (ItemNotFoundException e) { return ImmutableSet.of(); } }
/** * Pushes a packet request flow rule to all devices. * * @param request the packet request */ private void pushToAllDevices(PacketRequest request) { log.debug("Pushing packet request {} to all devices", request); for (Device device : deviceService.getDevices()) { try { Driver driver = driverService.getDriver(device.id()); if (driver != null && Boolean.parseBoolean(driver.getProperty(SUPPORT_PACKET_REQUEST_PROPERTY))) { pushRule(device, request); } } catch (ItemNotFoundException e) { log.warn("Device driver not found for {}; not processing packet request {}", device.id(), request); } } }
private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) { try { DriverHandler handler = driverService.createHandler(device); if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) { return Collections.emptySet(); } TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class); if (query != null) { return query.queryTributarySlots(port); } else { return Collections.emptySet(); } } catch (ItemNotFoundException e) { return Collections.emptySet(); } } }
private OFAction buildExtensionAction(ExtensionTreatment i) { 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; }
private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) { try { DriverHandler handler = driverService.createHandler(did); if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) { return Collections.emptySet(); } LambdaQuery query = handler.behaviour(LambdaQuery.class); if (query != null) { return query.queryLambdas(port).stream() .flatMap(ResourceDeviceListener::toResourceGrid) .collect(ImmutableSet.toImmutableSet()); } else { return Collections.emptySet(); } } catch (ItemNotFoundException e) { return Collections.emptySet(); } }
private OFOxm buildExtensionOxm(ExtensionSelector extension) { if (!driverService.isPresent()) { log.error("No driver service present"); return null; } Driver driver = driverService.get().getDriver(deviceId); if (driver.hasBehaviour(ExtensionSelectorInterpreter.class)) { DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); ExtensionSelectorInterpreter interpreter = handler.behaviour(ExtensionSelectorInterpreter.class); return interpreter.mapSelector(factory(), extension); } return null; }
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); } }
@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); } }); } }
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 DriverHandler getDriver(Dpid dpid) { DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); Driver driver = driverService.getDriver(deviceId); DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); return handler; } }
@Override protected void doExecute() { DriverService service = get(DriverService.class); deviceId = DeviceId.deviceId(uri); DriverHandler h = service.createHandler(deviceId); ControllerConfig config = h.behaviour(ControllerConfig.class); config.getControllers().forEach(c -> print(c.target())); }
@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); }