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)));
}
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;
}
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));
}
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"));
}
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));
}
Aggregations