/** * 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); }
/** * 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(); } }
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<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<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(); } }
@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())); }
/** * 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); }
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; }
/** * 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; }
/** * 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
/** * 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 applyTunnelConfig(DriverHandler handler, IpAddress srcIp, IpAddress dstIp) { DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); } TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); TunnelDescription tunnel = new DefaultTunnelDescription( tunnelAsSrc, null, TunnelDescription.Type.VXLAN, TunnelName.tunnelName(DEFAULT_TUNNEL), optionBuilder.build()); tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), tunnel); }
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); }
@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); } }
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 (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); } }
@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); } }