Search in sources :

Example 86 with Instruction

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

the class GroupCodecTest method codecDecodeTest.

@Test
public void codecDecodeTest() throws IOException {
    Group group = getGroup("simple-group.json");
    checkCommonData(group);
    assertThat(group.buckets().buckets().size(), is(1));
    GroupBucket groupBucket = group.buckets().buckets().get(0);
    assertThat(groupBucket.type().toString(), is("ALL"));
    assertThat(groupBucket.treatment().allInstructions().size(), is(1));
    Instruction instruction1 = groupBucket.treatment().allInstructions().get(0);
    assertThat(instruction1.type(), is(Instruction.Type.OUTPUT));
    assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.portNumber(2)));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupJsonMatcher.matchesGroup(org.onosproject.codec.impl.GroupJsonMatcher.matchesGroup) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) Test(org.junit.Test)

Example 87 with Instruction

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

the class InstructionCodecTest method getInstruction.

/**
 * Reads in an instruction from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded instruction
 * @throws IOException if processing the resource fails
 */
private Instruction getInstruction(String resourceName) throws IOException {
    InputStream jsonStream = InstructionCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    Instruction instruction = instructionCodec.decode((ObjectNode) json, context);
    Assert.assertThat(instruction, notNullValue());
    return instruction;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) InstructionJsonMatcher.matchesInstruction(org.onosproject.codec.impl.InstructionJsonMatcher.matchesInstruction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction)

Example 88 with Instruction

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

the class InstructionCodecTest method piInstructionDecodingTest.

/**
 * Tests the decoding of protocol-independent instructions.
 */
@Test
public void piInstructionDecodingTest() throws IOException {
    Instruction actionInstruction = getInstruction("PiActionInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction action = ((PiInstruction) actionInstruction).action();
    Assert.assertThat(action.type(), is(PiTableAction.Type.ACTION));
    Assert.assertThat(((PiAction) action).id().id(), is("set_egress_port"));
    Assert.assertThat(((PiAction) action).parameters().size(), is(1));
    Collection<PiActionParam> actionParams = ((PiAction) action).parameters();
    PiActionParam actionParam = actionParams.iterator().next();
    Assert.assertThat(actionParam.id().id(), is("port"));
    Assert.assertThat(actionParam.value(), is(copyFrom((byte) 0x1)));
    Instruction actionGroupIdInstruction = getInstruction("PiActionProfileGroupIdInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction actionGroupId = ((PiInstruction) actionGroupIdInstruction).action();
    Assert.assertThat(actionGroupId.type(), is(PiTableAction.Type.ACTION_PROFILE_GROUP_ID));
    Assert.assertThat(((PiActionProfileGroupId) actionGroupId).id(), is(100));
    Instruction actionMemberIdInstruction = getInstruction("PiActionProfileMemberIdInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction actionMemberId = ((PiInstruction) actionMemberIdInstruction).action();
    Assert.assertThat(actionMemberId.type(), is(PiTableAction.Type.ACTION_PROFILE_MEMBER_ID));
    Assert.assertThat(((PiActionProfileMemberId) actionMemberId).id(), is(100));
}
Also used : PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) InstructionJsonMatcher.matchesInstruction(org.onosproject.codec.impl.InstructionJsonMatcher.matchesInstruction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 89 with Instruction

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

the class IntentCodecTest method decodePointToPointIntent.

/**
 * Tests the point to point intent JSON codec.
 *
 * @throws IOException if JSON processing fails
 */
@Test
public void decodePointToPointIntent() throws IOException {
    JsonCodec<Intent> intentCodec = context.codec(Intent.class);
    assertThat(intentCodec, notNullValue());
    Intent intent = getIntent("PointToPointIntent.json", intentCodec);
    assertThat(intent, notNullValue());
    assertThat(intent, instanceOf(PointToPointIntent.class));
    PointToPointIntent pointIntent = (PointToPointIntent) intent;
    assertThat(pointIntent.priority(), is(55));
    assertThat(pointIntent.filteredIngressPoint().connectPoint().deviceId(), is(did("0000000000000001")));
    assertThat(pointIntent.filteredIngressPoint().connectPoint().port(), is(PortNumber.portNumber(1)));
    assertThat(pointIntent.filteredEgressPoint().connectPoint().deviceId(), is(did("0000000000000007")));
    assertThat(pointIntent.filteredEgressPoint().connectPoint().port(), is(PortNumber.portNumber(2)));
    assertThat(pointIntent.constraints(), hasSize(1));
    assertThat(pointIntent.selector(), notNullValue());
    assertThat(pointIntent.selector().criteria(), hasSize(1));
    Criterion criterion1 = pointIntent.selector().criteria().iterator().next();
    assertThat(criterion1, instanceOf(EthCriterion.class));
    EthCriterion ethCriterion = (EthCriterion) criterion1;
    assertThat(ethCriterion.mac().toString(), is("11:22:33:44:55:66"));
    assertThat(ethCriterion.type().name(), is("ETH_DST"));
    assertThat(pointIntent.treatment(), notNullValue());
    assertThat(pointIntent.treatment().allInstructions(), hasSize(1));
    Instruction instruction1 = pointIntent.treatment().allInstructions().iterator().next();
    assertThat(instruction1, instanceOf(ModEtherInstruction.class));
    ModEtherInstruction ethInstruction = (ModEtherInstruction) instruction1;
    assertThat(ethInstruction.mac().toString(), is("22:33:44:55:66:77"));
    assertThat(ethInstruction.type().toString(), is("L2MODIFICATION"));
    assertThat(ethInstruction.subtype().toString(), is("ETH_SRC"));
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) IntentJsonMatcher.matchesIntent(org.onosproject.codec.impl.IntentJsonMatcher.matchesIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 90 with Instruction

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

the class TrafficTreatmentCodecTest method testTrafficTreatmentDecode.

/**
 * Tests decoding of a traffic treatment JSON object.
 */
@Test
public void testTrafficTreatmentDecode() throws IOException {
    TrafficTreatment treatment = getTreatment("TrafficTreatment.json");
    List<Instruction> insts = treatment.immediate();
    assertThat(insts.size(), is(2));
    ImmutableSet<String> types = ImmutableSet.of("OUTPUT", "L2MODIFICATION");
    assertThat(types.contains(insts.get(0).type().name()), is(true));
    assertThat(types.contains(insts.get(1).type().name()), is(true));
}
Also used : TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) Test(org.junit.Test)

Aggregations

Instruction (org.onosproject.net.flow.instructions.Instruction)104 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)59 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)44 Criterion (org.onosproject.net.flow.criteria.Criterion)42 TrafficSelector (org.onosproject.net.flow.TrafficSelector)34 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)33 Instructions (org.onosproject.net.flow.instructions.Instructions)33 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)32 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)32 PortNumber (org.onosproject.net.PortNumber)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)27 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)26 VlanId (org.onlab.packet.VlanId)25 DeviceId (org.onosproject.net.DeviceId)25 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)25 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)25 FlowRule (org.onosproject.net.flow.FlowRule)24 Group (org.onosproject.net.group.Group)23