Search in sources :

Example 11 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleManager method removeFlowRules.

@Override
public void removeFlowRules(FlowRule... flowRules) {
    checkPermission(FLOWRULE_WRITE);
    FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
    for (FlowRule flowRule : flowRules) {
        builder.remove(flowRule);
    }
    apply(builder.build());
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) FlowRule(org.onosproject.net.flow.FlowRule)

Example 12 with FlowRule

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

the class FabricUpfTranslatorTest method uplinkUpfTerminationNoTcToFabricEntryTest.

@Test
public void uplinkUpfTerminationNoTcToFabricEntryTest() {
    FlowRule translatedRule;
    FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_UPF_TERMINATION_NO_TC;
    try {
        translatedRule = upfTranslator.upfTerminationUplinkToFabricEntry(TestUpfConstants.UPLINK_UPF_TERMINATION_NO_TC, TestUpfConstants.DEVICE_ID, TestUpfConstants.APP_ID, TestUpfConstants.DEFAULT_PRIORITY);
    } catch (UpfProgrammableException e) {
        assertThat("Abstract uplink UPF Termination should correctly " + "translate to Fabric UPF Termination without error", false);
        return;
    }
    assertThat(translatedRule, equalTo(expectedRule));
    assertThat(translatedRule.treatment(), equalTo(expectedRule.treatment()));
}
Also used : UpfProgrammableException(org.onosproject.net.behaviour.upf.UpfProgrammableException) FlowRule(org.onosproject.net.flow.FlowRule) Test(org.junit.Test)

Example 13 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManager method getFlowRulesByGroupId.

@Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
    DeviceService deviceService = manager.get(networkId(), DeviceService.class);
    Set<FlowRule> matches = Sets.newHashSet();
    long toLookUp = ((long) appId.id() << 16) | groupId;
    for (Device d : deviceService.getDevices()) {
        for (FlowEntry flowEntry : store.getFlowEntries(networkId(), d.id())) {
            if ((flowEntry.id().value() >>> 32) == toLookUp) {
                matches.add(flowEntry);
            }
        }
    }
    return matches;
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 14 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class VirtualNetworkFlowRuleManager method applyFlowRules.

@Override
public void applyFlowRules(FlowRule... flowRules) {
    FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
    for (FlowRule flowRule : flowRules) {
        builder.add(flowRule);
    }
    apply(builder.build());
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) FlowRule(org.onosproject.net.flow.FlowRule)

Example 15 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleCodecTest method decodeInstructionsFlowTest.

/**
 * Checks that a rule with one of each instruction type decodes properly.
 *
 * @throws IOException if the resource cannot be processed
 */
@Test
public void decodeInstructionsFlowTest() throws Exception {
    FlowRule rule = getRule("instructions-flow.json");
    checkCommonData(rule);
    rule.treatment().allInstructions().forEach(instruction -> {
        String subType;
        if (instruction.type() == Instruction.Type.L0MODIFICATION) {
            subType = ((L0ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            subType = ((L2ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            subType = ((L3ModificationInstruction) instruction).subtype().name();
        } else if (instruction.type() == Instruction.Type.L4MODIFICATION) {
            subType = ((L4ModificationInstruction) instruction).subtype().name();
        } else {
            subType = "";
        }
        instructions.put(instruction.type().name() + "/" + subType, instruction);
    });
    assertThat(rule.treatment().allInstructions().size(), is(23));
    Instruction instruction;
    instruction = getInstruction(Instruction.Type.OUTPUT, "");
    assertThat(instruction.type(), is(Instruction.Type.OUTPUT));
    assertThat(((Instructions.OutputInstruction) instruction).port(), is(PortNumber.CONTROLLER));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("12:34:56:78:90:12")));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.ETH_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModEtherInstruction) instruction).mac(), is(MacAddress.valueOf("98:76:54:32:01:00")));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_ID.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModVlanIdInstruction) instruction).vlanId().toShort(), is((short) 22));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PCP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModVlanPcpInstruction) instruction).vlanPcp(), is((byte) 1));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_LABEL.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsLabelInstruction) instruction).label().toInt(), is(MplsLabel.MAX_MPLS));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.MPLS_POP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModMplsHeaderInstruction) instruction).ethernetType().toShort(), is(Ethernet.MPLS_UNICAST));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModMplsTtlInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_POP.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.VLAN_PUSH.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(instruction, instanceOf(L2ModificationInstruction.ModVlanHeaderInstruction.class));
    instruction = getInstruction(Instruction.Type.L2MODIFICATION, L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
    assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
    assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction).tunnelId(), is(100L));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.4")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV4_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.3")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.2")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPInstruction) instruction).ip(), is(IpAddress.valueOf("1.2.3.1")));
    instruction = getInstruction(Instruction.Type.L3MODIFICATION, L3ModificationInstruction.L3SubType.IPV6_FLABEL.name());
    assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
    assertThat(((L3ModificationInstruction.ModIPv6FlowLabelInstruction) instruction).flowLabel(), is(8));
    instruction = getInstruction(Instruction.Type.L0MODIFICATION, L0ModificationInstruction.L0SubType.OCH.name());
    assertThat(instruction.type(), is(Instruction.Type.L0MODIFICATION));
    L0ModificationInstruction.ModOchSignalInstruction och = (L0ModificationInstruction.ModOchSignalInstruction) instruction;
    assertThat(och.lambda().spacingMultiplier(), is(4));
    assertThat(och.lambda().slotGranularity(), is(8));
    assertThat(och.lambda().gridType(), is(GridType.DWDM));
    assertThat(och.lambda().channelSpacing(), is(ChannelSpacing.CHL_100GHZ));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40001));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.TCP_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40002));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_DST.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40003));
    instruction = getInstruction(Instruction.Type.L4MODIFICATION, L4ModificationInstruction.L4SubType.UDP_SRC.name());
    assertThat(instruction.type(), is(Instruction.Type.L4MODIFICATION));
    assertThat(((L4ModificationInstruction.ModTransportPortInstruction) instruction).port().toInt(), is(40004));
}
Also used : L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) 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