use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslatorTest method testAclDrop.
/**
* Test versatile flag of forwarding objective with acl drop.
*/
@Test
public void testAclDrop() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().wipeDeferred().build();
// ACL 8-tuples like
TrafficSelector selector = DefaultTrafficSelector.builder().matchIPDst(IPV4_UNICAST_ADDR).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_DROP).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 testAclArp.
/**
* Test versatile flag of forwarding objective with ARP match.
*/
@Test
public void testAclArp() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
// ARP
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).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());
assertEquals(1, groupsInstalled.size());
FlowRule actualFlowRule = flowRulesInstalled.get(0);
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_CLONE_SESSION_ID).withParameter(new PiActionParam(FabricConstants.CLONE_ID, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID)).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();
GroupDescription actualCloneGroup = groupsInstalled.get(0);
TrafficTreatment cloneGroupTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build();
List<GroupBucket> cloneBuckets = ImmutableList.of(DefaultGroupBucket.createCloneGroupBucket(cloneGroupTreatment));
GroupBuckets cloneGroupBuckets = new GroupBuckets(cloneBuckets);
GroupKey cloneGroupKey = new DefaultGroupKey(FabricPipeliner.KRYO.serialize(ForwardingObjectiveTranslator.CLONE_TO_CPU_ID));
GroupDescription expectedCloneGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.CLONE, cloneGroupBuckets, cloneGroupKey, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID, APP_ID);
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
assertTrue(expectedCloneGroup.equals(actualCloneGroup));
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslatorTest method testAclNextWithPortType.
/**
* Test versatile flag of forwarding objective with next step and port type.
*/
@Test
public void testAclNextWithPortType() {
// ACL 8-tuples
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).build();
TrafficSelector metaSelector = DefaultTrafficSelector.builder().matchMetadata(EDGE_PORT).build();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).withMeta(metaSelector).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();
TrafficSelector expectedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, PORT_TYPE_EDGE, PORT_TYPE_MASK).build()).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
metaSelector = DefaultTrafficSelector.builder().matchMetadata(INFRA_PORT).build();
fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).withMeta(metaSelector).add();
result = translator.translate(fwd);
flowRulesInstalled = (List<FlowRule>) result.flowRules();
groupsInstalled = (List<GroupDescription>) result.groups();
assertEquals(1, flowRulesInstalled.size());
assertTrue(groupsInstalled.isEmpty());
actualFlowRule = flowRulesInstalled.get(0);
expectedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, PORT_TYPE_INFRA, PORT_TYPE_MASK).build()).build();
expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).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 FabricUtils method isValidSrMetadata.
/**
* Check metadata passed from SegmentRouting app.
*
* @param obj the objective containing the metadata
* @return true if the objective contains valid metadata, false otherwise
*/
public static boolean isValidSrMetadata(Objective obj) {
long meta = 0;
if (obj instanceof FilteringObjective) {
FilteringObjective filtObj = (FilteringObjective) obj;
if (filtObj.meta() == null) {
return true;
}
Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
if (metaIns == null) {
return true;
}
meta = metaIns.metadata() & metaIns.metadataMask();
} else if (obj instanceof ForwardingObjective) {
ForwardingObjective fwdObj = (ForwardingObjective) obj;
if (fwdObj.meta() == null) {
return true;
}
MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
if (metaCrit == null) {
return true;
}
meta = metaCrit.metadata();
}
return meta != 0 && ((meta ^ METADATA_MASK) <= METADATA_MASK);
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project onos by opennetworkinglab.
the class FabricUtils method isSrMetadataSet.
/**
* Verify if a given flag has been set into the metadata.
*
* @param obj the objective containing the metadata
* @param flag the flag to verify
* @return true if the flag is set, false otherwise
*/
public static boolean isSrMetadataSet(Objective obj, long flag) {
long meta = 0;
if (obj instanceof FilteringObjective) {
FilteringObjective filtObj = (FilteringObjective) obj;
if (filtObj.meta() == null) {
return false;
}
Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
if (metaIns == null) {
return false;
}
meta = metaIns.metadata() & metaIns.metadataMask();
} else if (obj instanceof ForwardingObjective) {
ForwardingObjective fwdObj = (ForwardingObjective) obj;
if (fwdObj.meta() == null) {
return false;
}
MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
if (metaCrit == null) {
return false;
}
meta = metaCrit.metadata();
}
return (meta & flag) == flag;
}
Aggregations