use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method createAnotherFlowObjectiveIntents.
/**
* Creates flow objective Intents with different selector.
*
* @return the flow objective Intents
*/
private List<Intent> createAnotherFlowObjectiveIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).matchInPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).addCondition(selector.getCriterion(Criterion.Type.VLAN_VID)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
List<Objective> objectives = ImmutableList.of(filt, next, fwd);
List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
return ImmutableList.of(intent);
}
use of org.onosproject.net.flowobjective.FilteringObjective 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;
}
use of org.onosproject.net.flowobjective.FilteringObjective 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.FilteringObjective in project onos by opennetworkinglab.
the class FilteringObjectiveTranslatorTest method testDenyObjective.
/**
* Test DENY objective.
*/
@Test
public void testDenyObjective() throws FabricPipelinerException {
FilteringObjective filteringObjective = DefaultFilteringObjective.builder().deny().withKey(Criteria.matchInPort(PORT_1)).addCondition(Criteria.matchVlanId(VlanId.NONE)).fromApp(APP_ID).makePermanent().withPriority(PRIORITY).add();
ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder().matchInPort(PORT_1).matchPi(buildPiCriterionVlan(null, null));
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_FILTERING_DENY).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().withPriority(PRIORITY).withSelector(selector.build()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).forDevice(DEVICE_ID).makePermanent().forTable(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN).build();
ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).build();
assertEquals(expectedTranslation, actualTranslation);
}
use of org.onosproject.net.flowobjective.FilteringObjective in project onos by opennetworkinglab.
the class FilteringObjectiveTranslatorTest method testPopVlan.
/**
* Test double VLAN pop filtering objective Creates one rule for
* ingress_port_vlan table and 3 rules for fwd_classifier table (IPv4, IPv6
* and MPLS unicast) when the condition is MAC + VLAN + INNER_VLAN.
*/
@Test
public void testPopVlan() throws FabricPipelinerException {
FilteringObjective filteringObjective = DefaultFilteringObjective.builder().withKey(Criteria.matchInPort(PORT_1)).addCondition(Criteria.matchEthDst(ROUTER_MAC)).addCondition(Criteria.matchVlanId(VLAN_100)).addCondition(Criteria.matchInnerVlanId(VLAN_200)).withPriority(PRIORITY).fromApp(APP_ID).withMeta(DefaultTrafficTreatment.builder().popVlan().writeMetadata(EDGE_PORT, 0xffffffffffffffffL).build()).permit().add();
ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
Collection<FlowRule> expectedFlowRules = Lists.newArrayList();
// Ingress port vlan rule
expectedFlowRules.add(buildExpectedVlanInPortRule(PORT_1, VLAN_100, VLAN_200, VlanId.NONE, PORT_TYPE_EDGE, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
// Forwarding classifier rules (ipv6, ipv4, mpls)
expectedFlowRules.addAll(buildExpectedFwdClassifierRule(PORT_1, ROUTER_MAC, null, Ethernet.TYPE_IPV4, FWD_IPV4_ROUTING));
expectedFlowRules.addAll(buildExpectedFwdClassifierRule(PORT_1, ROUTER_MAC, null, Ethernet.TYPE_IPV6, FWD_IPV6_ROUTING));
expectedFlowRules.addAll(buildExpectedFwdClassifierRule(PORT_1, ROUTER_MAC, null, Ethernet.MPLS_UNICAST, FWD_MPLS));
ObjectiveTranslation expectedTranslation = buildExpectedTranslation(expectedFlowRules);
assertEquals(expectedTranslation, actualTranslation);
}
Aggregations