use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processEgress.
/**
* In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
* egress tables.
* @param fwd the forwarding objective of type 'egress'
* @return a collection of flow rules to be sent to the switch. An empty
* collection may be returned if there is a problem in processing
* the flow rule
*/
@Override
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
List<FlowRule> rules = new ArrayList<>();
// Build selector
TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
if (vlanIdCriterion == null) {
log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst();
if (!outInstr.isPresent()) {
log.error("Egress forwarding objective:{} must include output port", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port();
sb.matchVlanId(vlanIdCriterion.vlanId());
OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
sb.extension(actsetOutput, deviceId);
// Build a flow rule for Egress VLAN Flow table
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
tb.transition(UNICAST_ROUTING_TABLE_1);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
tb.immediate().add(instr);
}
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
tb.immediate().pushVlan(ethType);
}
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
rules.add(ruleBuilder.build());
return rules;
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method sendForwards.
// Builds the batch using the accumulated flow rules
private void sendForwards(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) {
FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
log.debug("Sending {} fwd-objs", pairs.size());
List<Objective> fwdObjs = Lists.newArrayList();
// Iterates over all accumulated flow rules and then build an unique batch
pairs.forEach(pair -> {
ForwardingObjective fwd = pair.getLeft();
Collection<FlowRule> rules = pair.getRight();
switch(fwd.op()) {
case ADD:
rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::add);
log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId);
fwdObjs.add(fwd);
break;
case REMOVE:
rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::remove);
log.debug("Deleting a flow rule to sw:{}", deviceId);
fwdObjs.add(fwd);
break;
default:
fail(fwd, ObjectiveError.UNKNOWN);
log.warn("Unknown forwarding type {}", fwd.op());
}
});
// Finally applies the operations
flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
log.trace("Flow rule operations onSuccess {}", ops);
fwdObjs.forEach(OfdpaPipelineUtility::pass);
}
@Override
public void onError(FlowRuleOperations ops) {
ObjectiveError error = ObjectiveError.FLOWINSTALLATIONFAILED;
log.warn("Flow rule operations onError {}. Reason = {}", ops, error);
fwdObjs.forEach(fwdObj -> fail(fwdObj, error));
}
}));
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslatorTest method testAclDhcp.
/**
* Test versatile flag of forwarding objective with DHCP match.
*/
@Test
public void testAclDhcp() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().wipeDeferred().punt().build();
// DHCP
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpSrc(TpPort.tpPort(UDP.DHCP_CLIENT_PORT)).matchUdpDst(TpPort.tpPort(UDP.DHCP_SERVER_PORT)).build();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withTreatment(treatment).add();
ObjectiveTranslation result = translator.translate(fwd);
List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
assertEquals(1, flowRulesInstalled.size());
assertTrue(groupsInstalled.isEmpty());
FlowRule actualFlowRule = flowRulesInstalled.get(0);
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_PUNT_TO_CPU).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslatorTest method testAclNext.
/**
* Test versatile flag of forwarding objective with next step.
*/
@Test
public void testAclNext() {
// ACL 8-tuples
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).build();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).add();
ObjectiveTranslation result = translator.translate(fwd);
List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
assertEquals(1, flowRulesInstalled.size());
assertTrue(groupsInstalled.isEmpty());
FlowRule actualFlowRule = flowRulesInstalled.get(0);
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_NEXT_ID_ACL).withParameter(new PiActionParam(FabricConstants.NEXT_ID, NEXT_ID_1)).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class VirtualNetworkFlowObjectiveManagerTest method forwardingObjective.
/**
* Tests adding a forwarding objective.
*/
@Test
public void forwardingObjective() {
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
ForwardingObjective forward = DefaultForwardingObjective.builder().fromApp(NetTestTools.APP_ID).withFlag(ForwardingObjective.Flag.SPECIFIC).withSelector(selector).withTreatment(treatment).makePermanent().add(new ObjectiveContext() {
@Override
public void onSuccess(Objective objective) {
assertEquals("1 flowrule entry expected", 1, flowRuleStore.getFlowRuleCount(vnet1.id()));
assertEquals("0 flowrule entry expected", 0, flowRuleStore.getFlowRuleCount(vnet2.id()));
}
});
service1.forward(VDID1, forward);
}
Aggregations