Search in sources :

Example 26 with FilteringObjective

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);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) NetworkResource(org.onosproject.net.NetworkResource) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 27 with FilteringObjective

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;
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 28 with FilteringObjective

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);
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 29 with FilteringObjective

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);
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 30 with FilteringObjective

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);
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Aggregations

FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)36 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)22 Test (org.junit.Test)21 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)15 NextObjective (org.onosproject.net.flowobjective.NextObjective)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 Objective (org.onosproject.net.flowobjective.Objective)13 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)10 FlowRule (org.onosproject.net.flow.FlowRule)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 FlowObjectiveIntent (org.onosproject.net.intent.FlowObjectiveIntent)9 Intent (org.onosproject.net.intent.Intent)9 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)7 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)7 DefaultLink (org.onosproject.net.DefaultLink)6 DeviceId (org.onosproject.net.DeviceId)6 Link (org.onosproject.net.Link)6 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)6