/** * Gets ports in the controller device. * * @param handler DriverHandler * @return set of port numbers */ public static Set<PortNumber> getPortNumbers(DriverHandler handler) { BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); return bridgeConfig.getPortNumbers(); }
/** * 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); }
/** * Discovers the device details using the device discovery behaviour of * the supplied driver handler context for interacting with a specific * device. * * @param handler driver handler context */ protected void discoverDevice(DriverHandler handler) { DeviceId deviceId = handler.data().deviceId(); DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class); DeviceDescription description = discovery.discoverDeviceDetails(); if (description != null) { providerService.deviceConnected(deviceId, description); } else { log.info("No other description given for device {}", deviceId); } providerService.updatePorts(deviceId, discovery.discoverPortDetails()); } // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns
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(DriverEvent event) { String driverName = event.subject().name(); driverHandlers.entrySet().stream() .filter(e -> driverName.equals(e.getValue().driver().name())) .map(Map.Entry::getKey) .distinct() .forEach(FlowObjectiveManager.this::invalidatePipeliner); } }
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 void invalidatePipelinerIfNecessary(Device device) { DriverHandler handler = driverHandlers.get(device.id()); if (handler != null && !Objects.equals(handler.driver().name(), device.annotations().value(DRIVER))) { invalidatePipeliner(device.id()); } }
/** * Creates or update bridge in the controller device. * * @param handler DriverHandler * @param dpid datapath id * @param exPortName external port name */ public static void applyBridgeConfig(DriverHandler handler, String dpid, String exPortName) { BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), dpid, exPortName); }
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(); } }
@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())); }
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(); } }
DriverHandler handler = driverService.createHandler(d.id()); BridgeConfig bridgeConfig = handler .behaviour(BridgeConfig.class); Collection<BridgeDescription> bridgeDescriptions = bridgeConfig .getBridges();
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(); } } }
addedDevices.forEach(deviceId -> { DriverHandler h = driverService.createHandler(deviceId); PortDiscovery portConfig = h.behaviour(PortDiscovery.class); if (portConfig != null) { providerService.updatePorts(deviceId, portConfig.getPorts());
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(); } }
/** * Creates or update tunnel in the controller device. * * @param handler DriverHandler * @param srcIp the ipAddress of the local controller device * @param dstIp the ipAddress of the remote controller device */ public static void removeTunnelConfig(DriverHandler handler, IpAddress srcIp, IpAddress dstIp) { TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); TunnelDescription tunnel = new DefaultTunnelDescription( tunnelAsSrc, tunnelAsDst, TunnelDescription.Type.VXLAN, null); tunnelConfig.removeTunnel(tunnel); }
DeviceId deviceId) { ExtensionTreatmentInterpreter treatmentInterpreter; if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); } else { treatmentInterpreter = null;
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; }
DeviceId deviceId) { ExtensionTreatmentInterpreter interpreter; if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); } else { interpreter = null;