@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)); } } }
private boolean isMultiplexingSupported(ConnectPoint cp) { Driver driver = driverService.getDriver(cp.deviceId()); return driver != null && driver.hasBehaviour(TributarySlotQuery.class) && staticPort(cp) == null; }
private DriverHandler getDriver(DeviceId devId) { Driver driver = driverService.getDriver(devId); DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId)); return handler; } }
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; } }
/** * 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 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 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; }
@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 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 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; } }
private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) { Driver driver = driverService.getDriver(id); DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id)); ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class); ExtensionTreatment extensionInstruction = resolver.getExtensionInstruction( ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type()); try { extensionInstruction.setPropertyValue(TUNNEL_DST, hostIp); } catch (ExtensionPropertyException e) { log.error("Error setting Nicira extension setting {}", e); } return extensionInstruction; }
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 write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) { kryo.writeClassAndObject(output, object.extensionInstruction().type()); kryo.writeClassAndObject(output, object.deviceId()); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); // It raises ItemNotFoundException if it failed to find driver Driver driver = driverService.getDriver(object.deviceId()); kryo.writeClassAndObject(output, driver.name()); kryo.writeClassAndObject(output, object.extensionInstruction().serialize()); }
@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); } }
@Override public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, Class<Instructions.ExtensionInstructionWrapper> type) { ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); String driverName = (String) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); byte[] bytes = (byte[]) kryo.readClassAndObject(input); ExtensionTreatment instruction; try { DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(driverName), deviceId)); ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); instruction = resolver.getExtensionInstruction(exType); instruction.deserialize(bytes); } catch (ItemNotFoundException | IllegalArgumentException e) { instruction = new UnresolvedExtensionTreatment(bytes, exType); } return Instructions.extension(instruction, deviceId); } }
/** * 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))); } } } }