Java Code Examples for org.onosproject.net.flow.DefaultFlowRule#builder()
The following examples show how to use
org.onosproject.net.flow.DefaultFlowRule#builder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScaleTestManager.java From onos with Apache License 2.0 | 6 votes |
private void addMoreFlows(int flowsPerDevice, Device device, DeviceId id, int currentFlowCount) { int c = flowsPerDevice - currentFlowCount; log.info("Adding {} flows for device {}", c, id); List<PortNumber> ports = devicePorts(device); FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); for (int i = 0; i < c; i++) { FlowRule.Builder frb = DefaultFlowRule.builder(); frb.fromApp(appId).makePermanent().withPriority((currentFlowCount + i) % FlowRule.MAX_PRIORITY); TrafficSelector.Builder tsb = DefaultTrafficSelector.builder(); TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder(); tsb.matchEthType(Ethernet.TYPE_IPV4); tsb.matchEthDst(randomMac()); ttb.setEthDst(randomMac()).setEthSrc(randomMac()); ttb.setOutput(randomPort(ports)); frb.withSelector(tsb.build()).withTreatment(ttb.build()); ops.add(frb.forDevice(id).build()); } flowRuleService.apply(ops.build()); }
Example 2
Source File: PointToPointIntentCompiler.java From onos with Apache License 2.0 | 6 votes |
/** * Manufactures flow rule with treatment that is defined by failover * group and traffic selector determined by ingress port of the intent. * * @param intent intent which is being compiled (for appId) * @return a list of a singular flow rule with fast failover * outport traffic treatment */ private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) { List<FlowRule> flowRules = new ArrayList<>(); ConnectPoint ingress = intent.filteredIngressPoint().connectPoint(); DeviceId deviceId = ingress.deviceId(); // flow rule with failover traffic treatment TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()) .matchInPort(ingress.port()).build(); FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); flowRules.add(flowRuleBuilder.withSelector(trafficSelector) .withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))) .fromApp(intent.appId()) .makePermanent() .forDevice(deviceId) .withPriority(PRIORITY) .build()); return flowRules; }
Example 3
Source File: OvsOfdpaPipeline.java From onos with Apache License 2.0 | 4 votes |
@Override protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { List<FlowRule> rules = new ArrayList<>(); // Build filtered selector TrafficSelector selector = fwd.selector(); EthCriterion ethCriterion = (EthCriterion) selector .getCriterion(Criterion.Type.ETH_DST); VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector .getCriterion(VLAN_VID); if (vlanIdCriterion == null) { log.warn("Forwarding objective for bridging requires vlan. Not " + "installing fwd:{} in dev:{}", fwd.id(), deviceId); fail(fwd, ObjectiveError.BADPARAMS); return Collections.emptySet(); } TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder(); // Do not match MacAddress for subnet broadcast entry if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) { filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", fwd.id(), fwd.nextId(), deviceId); } else { log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " + "in dev:{} for vlan:{}", fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); } filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); TrafficSelector filteredSelector = filteredSelectorBuilder.build(); if (fwd.treatment() != null) { log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); } TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); if (fwd.nextId() != null) { NextGroup next = getGroupForNextObjective(fwd.nextId()); if (next != null) { List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); // we only need the top level group's key to point the flow to it Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); if (group != null) { treatmentBuilder.deferred().group(group.id()); } else { log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); fail(fwd, ObjectiveError.GROUPMISSING); return Collections.emptySet(); } } } treatmentBuilder.immediate().transition(ACL_TABLE); TrafficTreatment filteredTreatment = treatmentBuilder.build(); // Build bridging table entries FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); flowRuleBuilder.fromApp(fwd.appId()) .withPriority(fwd.priority()) .forDevice(deviceId) .withSelector(filteredSelector) .withTreatment(filteredTreatment) .forTable(BRIDGING_TABLE); if (fwd.permanent()) { flowRuleBuilder.makePermanent(); } else { flowRuleBuilder.makeTemporary(fwd.timeout()); } rules.add(flowRuleBuilder.build()); return rules; }
Example 4
Source File: Ofdpa2Pipeline.java From onos with Apache License 2.0 | 4 votes |
/** * Handles forwarding rules to the L2 bridging table. Flow actions are not * allowed in the bridging table - instead we use L2 Interface group or * L2 flood group * * @param fwd the forwarding objective * @return A collection of flow rules, or an empty set */ protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { List<FlowRule> rules = new ArrayList<>(); // Build filtered selector TrafficSelector selector = fwd.selector(); EthCriterion ethCriterion = (EthCriterion) selector .getCriterion(Criterion.Type.ETH_DST); VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector .getCriterion(Criterion.Type.VLAN_VID); if (vlanIdCriterion == null) { log.warn("Forwarding objective for bridging requires vlan. Not " + "installing fwd:{} in dev:{}", fwd.id(), deviceId); fail(fwd, ObjectiveError.BADPARAMS); return Collections.emptySet(); } TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder(); if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) { filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", fwd.id(), fwd.nextId(), deviceId); } else { // Use wildcard DST_MAC if the MacAddress is None or Broadcast log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " + "in dev:{} for vlan:{}", fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); } if (requireVlanExtensions()) { OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId()); filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId); } else { filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); } TrafficSelector filteredSelector = filteredSelectorBuilder.build(); if (fwd.treatment() != null) { log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); } TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); if (fwd.nextId() != null) { NextGroup next = getGroupForNextObjective(fwd.nextId()); if (next != null) { List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); // we only need the top level group's key to point the flow to it Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); if (group != null) { treatmentBuilder.deferred().group(group.id()); } else { log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); fail(fwd, ObjectiveError.GROUPMISSING); return Collections.emptySet(); } } } treatmentBuilder.immediate().transition(ACL_TABLE); TrafficTreatment filteredTreatment = treatmentBuilder.build(); // Build bridging table entries FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); flowRuleBuilder.fromApp(fwd.appId()) .withPriority(fwd.priority()) .forDevice(deviceId) .withSelector(filteredSelector) .withTreatment(filteredTreatment) .forTable(BRIDGING_TABLE); if (fwd.permanent()) { flowRuleBuilder.makePermanent(); } else { flowRuleBuilder.makeTemporary(fwd.timeout()); } rules.add(flowRuleBuilder.build()); return rules; }
Example 5
Source File: PortWaveLengthCommand.java From onos with Apache License 2.0 | 4 votes |
@Override protected void doExecute() throws Exception { if (operation.equals("edit-config")) { FlowRuleService flowService = get(FlowRuleService.class); DeviceService deviceService = get(DeviceService.class); CoreService coreService = get(CoreService.class); ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString); TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder(); FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); // an empty traffic selector TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(cp.port()).build(); OchSignal ochSignal; if (parameter.contains("/")) { ochSignal = createOchSignal(); } else if (parameter.matches("-?\\d+(\\.\\d+)?")) { ochSignal = createOchSignalFromWavelength(deviceService, cp); } else { print("Signal or wavelength %s are in uncorrect format"); return; } if (ochSignal == null) { print("Error in creating OchSignal"); return; } TrafficTreatment trafficTreatment = trafficTreatmentBuilder .add(Instructions.modL0Lambda(ochSignal)) .add(Instructions.createOutput(deviceService.getPort(cp).number())) .build(); Device device = deviceService.getDevice(cp.deviceId()); int priority = 100; ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model"); log.info(appId.name()); FlowRule addFlow = flowRuleBuilder .withPriority(priority) .fromApp(appId) .withTreatment(trafficTreatment) .withSelector(trafficSelector) .forDevice(device.id()) .makePermanent() .build(); flowService.applyFlowRules(addFlow); String msg = String.format("Setting wavelength %s", ochSignal.centralFrequency().asGHz()); print(msg); } else { print("Operation %s are not supported now.", operation); } }