Search in sources :

Example 76 with FlowRule

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

the class ForwardingObjectiveTranslatorTest method testSpecificForward.

private void testSpecificForward(PiTableId expectedTableId, TrafficSelector expectedSelector, TrafficSelector selector, Integer nextId, TrafficTreatment treatment) throws FabricPipelinerException {
    ForwardingObjective.Builder fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withTreatment(treatment).withFlag(ForwardingObjective.Flag.SPECIFIC);
    if (nextId != null) {
        fwd.nextStep(nextId);
    }
    ObjectiveTranslation actualTranslation = translator.translate(fwd.add());
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(expectedTableId).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).withTreatment(treatment).fromApp(APP_ID).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Example 77 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)

Example 78 with FlowRule

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

the class FlowRuleProtoTranslator method translate.

/**
 * Translates gRPC FlowRule to {@link FlowRule}.
 *
 * @param flowRule gRPC message
 * @return {@link FlowRule}
 */
public static FlowRule translate(FlowRuleProto flowRule) {
    if (flowRule.equals(FlowRuleProto.getDefaultInstance())) {
        return null;
    }
    DeviceId deviceId = DeviceId.deviceId(flowRule.getDeviceId());
    // TODO: to register AppId need to find a way to get CoreService
    FlowRule.FlowRemoveReason reason = FlowRuleEnumsProtoTranslator.translate(flowRule.getReason()).get();
    FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder();
    resultBuilder.forDevice(deviceId);
    resultBuilder.forTable(flowRule.getTableId());
    resultBuilder.withPriority(flowRule.getPriority());
    resultBuilder.withCookie(flowRule.getFlowId());
    resultBuilder.withReason(reason);
    if (flowRule.getPermanent()) {
        resultBuilder.makePermanent();
    } else {
        resultBuilder.makeTemporary(flowRule.getTimeout());
    }
    return resultBuilder.build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Example 79 with FlowRule

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

the class FlowTableConfig method flowtable.

public FlowTableConfig flowtable(Set<FlowRule> table) {
    JsonCodec<FlowRule> codec = codec(FlowRule.class);
    ArrayNode entries = codec.encode(table, this);
    object.set(ENTRIES, entries);
    return this;
}
Also used : FlowRule(org.onosproject.net.flow.FlowRule) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 80 with FlowRule

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

the class FlowTableConfig method flowtable.

public Set<FlowRule> flowtable() {
    JsonNode ents = object.path(ENTRIES);
    if (!ents.isArray()) {
        return ImmutableSet.of();
    }
    ArrayNode entries = (ArrayNode) ents;
    Builder<FlowRule> builder = ImmutableSet.builder();
    entries.forEach(entry -> builder.add(decode(entry, FlowRule.class)));
    return builder.build();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)351 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)226 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)207 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)207 TrafficSelector (org.onosproject.net.flow.TrafficSelector)174 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)174 Test (org.junit.Test)133 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 DeviceId (org.onosproject.net.DeviceId)87 List (java.util.List)86 Collection (java.util.Collection)68 Collectors (java.util.stream.Collectors)68 CoreService (org.onosproject.core.CoreService)66 VlanId (org.onlab.packet.VlanId)65 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 Collections (java.util.Collections)60 FlowEntry (org.onosproject.net.flow.FlowEntry)59 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)56 ArrayList (java.util.ArrayList)54