/** * 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); }
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 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(); } }
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 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 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 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); }
@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())); }
.filter(d -> !("ovsdb:" + ipAddress).equals(d.id().toString())) .forEach(d -> { DriverHandler handler = driverService.createHandler(d.id()); BridgeConfig bridgeConfig = handler .behaviour(BridgeConfig.class);
DriverHandler h = driverService.createHandler(deviceId); PortDiscovery portConfig = h.behaviour(PortDiscovery.class); if (portConfig != null) {
private void applyL3ArpFlows(DeviceId deviceId, VirtualPort gwPort, Objective.Operation operation) { IpAddress ip = null; Iterator<FixedIp> gwIps = gwPort.fixedIps().iterator(); if (gwIps.hasNext()) { ip = gwIps.next().ip(); } IpAddress gwIp = ip; MacAddress gwMac = gwPort.macAddress(); TenantNetwork network = tenantNetworkService .getNetwork(gwPort.networkId()); if (deviceId != null) { // Arp rules DriverHandler handler = driverService.createHandler(deviceId); arpService.programArpRules(handler, deviceId, gwIp, network.segmentationId(), gwMac, operation); } else { Iterable<Device> devices = deviceService.getAvailableDevices(); Sets.newHashSet(devices).stream() .filter(d -> Device.Type.SWITCH == d.type()).forEach(d -> { // Arp rules DriverHandler handler = driverService.createHandler(d.id()); arpService.programArpRules(handler, d.id(), gwIp, network.segmentationId(), gwMac, operation); }); } }
/** * Traffic selector builder function. * * @param deviceId device id. * @param container container need to be pushed. * @return the traffic selector builder */ public TrafficSelector.Builder packTrafficSelector(DeviceId deviceId, ExtFlowContainer container) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); DriverHandler handler = driverService.createHandler(deviceId); ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); ExtensionSelector bgpExtSelector = resolver.getExtensionSelector(EXT_MATCH_FLOW_TYPE.type()); try { bgpExtSelector.setPropertyValue("container", container); } catch (Exception e) { log.error("Failed to get extension instruction for bgp flow {}", deviceId); } selector.extension(bgpExtSelector, deviceId); return selector; }
private void printDevice(DeviceService deviceService, DriverService driverService, Device device) { super.printDevice(deviceService, device); if (!device.is(InterfaceConfig.class)) { // The relevant behavior is not supported by the device. print(ERROR_RESULT); return; } DriverHandler h = driverService.createHandler(device.id()); InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); List<DeviceInterfaceDescription> interfaces = interfaceConfig.getInterfaces(); if (interfaces == null) { print(ERROR_RESULT); } else if (interfaces.isEmpty()) { print(NO_INTERFACES); } else { interfaces.forEach(this::printInterface); } }
public void installSfcTunnelReceiveRule(DeviceId deviceId, NshServicePathId nshSpiId, Objective.Operation type) { DriverHandler handler = driverService.createHandler(deviceId); ExtensionSelectorResolver selectorResolver = handler.behaviour(ExtensionSelectorResolver.class); ExtensionSelector nshSpiSelector = selectorResolver.getExtensionSelector(NICIRA_MATCH_NSH_SPI.type()); ExtensionSelector nshSiSelector = selectorResolver.getExtensionSelector(NICIRA_MATCH_NSH_SI.type()); try { nshSpiSelector.setPropertyValue("nshSpi", nshSpiId); } catch (Exception e) { log.error("Failed to set extension selector to match Nsh Spi Id for end rule {}", e.getMessage()); } try { nshSiSelector.setPropertyValue("nshSi", NshServiceIndex.of(nshSi)); } catch (Exception e) { log.error("Failed to set extension selector to match Nsh Si Id for end rule {}", e.getMessage()); } TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); selector.extension(nshSpiSelector, deviceId); selector.extension(nshSiSelector, deviceId); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(ENCAP_OUTPUT_TABLE); sendSfcRule(selector, treatment, deviceId, type, DEFAULT_FORWARDER_PRIORITY); }
Builder builder = DefaultTrafficTreatment.builder(); DriverHandler handler = driverService.createHandler(deviceId); ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
private void printVlans(Port port) { DeviceService deviceService = get(DeviceService.class); DriverService driverService = get(DriverService.class); DeviceId deviceId = (DeviceId) port.element().id(); Device device = deviceService.getDevice(deviceId); if (!device.is(VlanQuery.class)) { // The relevant behavior is not supported by the device. print(NO_SUPPORT); return; } DriverHandler h = driverService.createHandler(deviceId); VlanQuery vlanQuery = h.behaviour(VlanQuery.class); try { Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number()); if (vlanIds.isEmpty()) { print(VLAN_NOT_AVAILABLE); } else { print(AVAIL_VLANS, getRanges(vlanIds).toString()); } } catch (Exception e) { print(FAILURE + e.getMessage()); } }
@Override protected void doExecute() { DriverService service = get(DriverService.class); DeviceId deviceId = DeviceId.deviceId(uri); DriverHandler h = service.createHandler(deviceId); InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); if (trunkMode && !accessMode && !rateLimit) { // Trunk mode for VLAN to be removed. removeTrunkModeFromIntf(interfaceConfig); } else if (accessMode && !trunkMode && !rateLimit) { // Access mode for VLAN to be removed. removeAccessModeFromIntf(interfaceConfig); } else if (rateLimit && !trunkMode && !accessMode) { // Rate limit to be removed. removeRateLimitFromIntf(interfaceConfig); } else { // Option has not been correctly set. print(ONE_ACTION_ALLOWED); } }
@Override protected void doExecute() { DriverService service = get(DriverService.class); DeviceId deviceId = DeviceId.deviceId(uri); DriverHandler h = service.createHandler(deviceId); InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); if (accessVlanString != null && trunkVlanStrings == null && limitString == null) { // Access mode to be enabled for VLAN. addAccessModeToIntf(interfaceConfig); } else if (trunkVlanStrings != null && accessVlanString == null && limitString == null) { // Trunk mode to be enabled for VLANs. addTrunkModeToIntf(interfaceConfig); } else if (limitString != null && accessVlanString == null && trunkVlanStrings == null) { // Rate limit to be set on interface. addRateLimitToIntf(interfaceConfig); } else { // Option has not been correctly set. print(ONE_ACTION_ALLOWED); } }
IpAddress localIp = IpAddress.valueOf(localIpAddress); DeviceId controllerDeviceId = controllerDevice.id(); DriverHandler handler = driverService.createHandler(controllerDeviceId); if (mastershipService.isLocalMaster(controllerDeviceId)) {
.build(); DriverHandler handler = driverService.createHandler(deviceId); ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());