Search in sources :

Example 21 with FlowRule

use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.

the class FabricUpfProgrammable method addInterface.

private void addInterface(UpfInterface upfInterface) throws UpfProgrammableException {
    assertSliceId(upfInterface.sliceId());
    FlowRule flowRule = upfTranslator.interfaceToFabricEntry(upfInterface, deviceId, appId, DEFAULT_PRIORITY);
    log.info("Installing {}", upfInterface);
    flowRuleService.applyFlowRules(flowRule);
    log.debug("Interface added with flowID {}", flowRule.id().value());
    // TODO: allow enabling/disabling UE-to-UE via netcfg or other API.
    if (upfInterface.isCore()) {
        applyUplinkRecirculation(upfInterface.prefix(), false);
    }
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Example 22 with FlowRule

use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.

the class FabricUpfProgrammable method applyUplinkRecirculation.

private void applyUplinkRecirculation(Ip4Prefix subnet, boolean remove) {
    log.warn("{} uplink recirculation rules on {} for subnet {}", remove ? "Removing" : "Installing", deviceId, subnet);
    // By default deny all uplink traffic with IP dst on the given UE subnet
    FlowRule denyRule = upfTranslator.buildFabricUplinkRecircEntry(deviceId, appId, null, subnet, false, DEFAULT_PRIORITY);
    // Allow recirculation only for packets with source on the same UE subnet
    FlowRule allowRule = upfTranslator.buildFabricUplinkRecircEntry(deviceId, appId, subnet, subnet, true, DEFAULT_PRIORITY + 10);
    if (!remove) {
        flowRuleService.applyFlowRules(denyRule, allowRule);
    } else {
        flowRuleService.removeFlowRules(denyRule, allowRule);
    }
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Example 23 with FlowRule

use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.

the class FabricPipelinerTest method testInitializePipeline.

@Test
public void testInitializePipeline() {
    final Capture<FlowRule> capturedSwitchInfoRule = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedCpuIgVlanRule = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedCpuFwdClsRule = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedIgPortVlanRule = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedEgVlanRule = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedFwdClsIpRules = newCapture(CaptureType.ALL);
    final Capture<FlowRule> capturedFwdClsMplsRules = newCapture(CaptureType.ALL);
    final Capture<GroupDescription> capturedCloneGroup = newCapture(CaptureType.FIRST);
    final List<FlowRule> expectedIgPortVlanRules = Lists.newArrayList();
    final List<FlowRule> expectedEgVlanRules = Lists.newArrayList();
    final List<FlowRule> expectedFwdClsIpRules = Lists.newArrayList();
    final List<FlowRule> expectedFwdClsMplsRules = Lists.newArrayList();
    final FlowRule expectedSwitchInfoRule = switchInfoRule();
    final FlowRule expectedCpuIgVlanRule = buildIngressVlanRule(CPU_PORT);
    final FlowRule expectedCpuFwdClsRule = buildFwdClsRule(CPU_PORT, null, Ethernet.TYPE_IPV4, FWD_IPV4_ROUTING, DEFAULT_FLOW_PRIORITY);
    final GroupDescription expectedPacketInCloneGroup = buildPacketInCloneGroup();
    final List<Long> recircPorts = this.isArchV1model ? V1MODEL_RECIRC_PORT : RECIRC_PORTS;
    flowRuleService.applyFlowRules(capture(capturedSwitchInfoRule), capture(capturedCpuIgVlanRule), capture(capturedCpuFwdClsRule));
    groupService.addGroup(capture(capturedCloneGroup));
    expectLastCall().once();
    recircPorts.forEach(port -> {
        expectedIgPortVlanRules.add(buildIngressVlanRule(port));
        expectedEgVlanRules.add(buildEgressVlanRule(port));
        expectedFwdClsIpRules.add(buildFwdClsRule(port, null, Ethernet.TYPE_IPV4, FWD_IPV4_ROUTING, DEFAULT_FLOW_PRIORITY));
        expectedFwdClsMplsRules.add(buildFwdClsRule(port, Ethernet.MPLS_UNICAST, Ethernet.TYPE_IPV4, FWD_MPLS, DEFAULT_FLOW_PRIORITY + 10));
        flowRuleService.applyFlowRules(capture(capturedIgPortVlanRule), capture(capturedEgVlanRule), capture(capturedFwdClsIpRules), capture(capturedFwdClsMplsRules));
    });
    replay(flowRuleService);
    replay(groupService);
    pipeliner.initializePipeline();
    assertTrue(expectedSwitchInfoRule.exactMatch(capturedSwitchInfoRule.getValue()));
    assertTrue(expectedCpuIgVlanRule.exactMatch(capturedCpuIgVlanRule.getValue()));
    assertTrue(expectedCpuFwdClsRule.exactMatch(capturedCpuFwdClsRule.getValue()));
    assertEquals(expectedPacketInCloneGroup, capturedCloneGroup.getValue());
    for (int i = 0; i < recircPorts.size(); i++) {
        FlowRule expectIgPortVlanRule = expectedIgPortVlanRules.get(i);
        FlowRule actualIgPortVlanRule = capturedIgPortVlanRule.getValues().get(i);
        FlowRule expectEgVlanRule = expectedEgVlanRules.get(i);
        FlowRule actualEgVlanRule = capturedEgVlanRule.getValues().get(i);
        FlowRule expectedFwdClsIpRule = expectedFwdClsIpRules.get(i);
        FlowRule actualFwdClsIpRule = capturedFwdClsIpRules.getValues().get(i);
        FlowRule expectedFwdClsMplsRule = expectedFwdClsMplsRules.get(i);
        FlowRule actualFwdClsMplsRule = capturedFwdClsMplsRules.getValues().get(i);
        assertTrue(expectIgPortVlanRule.exactMatch(actualIgPortVlanRule));
        assertEquals(expectEgVlanRule, actualEgVlanRule);
        assertTrue(expectEgVlanRule.exactMatch(actualEgVlanRule));
        assertTrue(expectedFwdClsIpRule.exactMatch(actualFwdClsIpRule));
        assertTrue(expectedFwdClsMplsRule.exactMatch(actualFwdClsMplsRule));
    }
    verify(flowRuleService);
    reset(flowRuleService);
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 24 with FlowRule

use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.

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, P4InfoConstants.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));
    // DSCP rewriter clear
    expectedFlowRules.add(buildExpectedEgressDscpRewriter(PORT_1, true));
    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)

Example 25 with FlowRule

use of org.onosproject.net.flow.FlowRule in project fabric-tna by stratum.

the class FilteringObjectiveTranslatorTest method testIsPortUpdate.

/**
 * Test port update scenarios for filtering objective. Creates only one rule for
 * ingress_port_vlan table.
 */
@Test
public void testIsPortUpdate() throws FabricPipelinerException {
    // Tagged port scenario
    FilteringObjective filteringObjective = DefaultFilteringObjective.builder().withKey(Criteria.matchInPort(PORT_1)).addCondition(Criteria.matchEthDst(ROUTER_MAC)).addCondition(Criteria.matchVlanId(VLAN_100)).withPriority(PRIORITY).fromApp(APP_ID).withMeta(DefaultTrafficTreatment.builder().writeMetadata(10, 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, null, VlanId.NONE, PORT_TYPE_EDGE, P4InfoConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
    // DSCP rewriter clear
    expectedFlowRules.add(buildExpectedEgressDscpRewriter(PORT_1, true));
    ObjectiveTranslation expectedTranslation = buildExpectedTranslation(expectedFlowRules);
    assertEquals(expectedTranslation, actualTranslation);
    // Untagged port scenario
    filteringObjective = DefaultFilteringObjective.builder().withKey(Criteria.matchInPort(PORT_1)).addCondition(Criteria.matchEthDst(ROUTER_MAC)).addCondition(Criteria.matchVlanId(VlanId.NONE)).withPriority(PRIORITY).fromApp(APP_ID).withMeta(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VLAN_200).writeMetadata(10, 0xffffffffffffffffL).build()).permit().add();
    actualTranslation = translator.translate(filteringObjective);
    expectedFlowRules = Lists.newArrayList();
    // Ingress port vlan rule
    expectedFlowRules.add(buildExpectedVlanInPortRule(PORT_1, VlanId.NONE, null, VLAN_200, PORT_TYPE_EDGE, P4InfoConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
    // DSCP rewriter clear
    expectedFlowRules.add(buildExpectedEgressDscpRewriter(PORT_1, true));
    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

FlowRule (org.onosproject.net.flow.FlowRule)432 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)279 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)226 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)225 TrafficSelector (org.onosproject.net.flow.TrafficSelector)193 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)189 Test (org.junit.Test)173 List (java.util.List)101 DeviceId (org.onosproject.net.DeviceId)101 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 Collection (java.util.Collection)75 Collectors (java.util.stream.Collectors)75 CoreService (org.onosproject.core.CoreService)72 Collections (java.util.Collections)70 VlanId (org.onlab.packet.VlanId)65 FlowEntry (org.onosproject.net.flow.FlowEntry)63 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 PortNumber (org.onosproject.net.PortNumber)57 ArrayList (java.util.ArrayList)56