use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class FlowRuleCodecTest method codecCriteriaFlowTest.
/**
* Checks that a rule with one of each kind of criterion decodes properly.
*
* @throws IOException if the resource cannot be processed
*/
@Test
public void codecCriteriaFlowTest() throws Exception {
FlowRule rule = getRule("criteria-flow.json");
checkCommonData(rule);
assertThat(rule.selector().criteria().size(), is(35));
rule.selector().criteria().forEach(criterion -> criteria.put(criterion.type().name(), criterion));
Criterion criterion;
criterion = getCriterion(Criterion.Type.ETH_TYPE);
assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
criterion = getCriterion(Criterion.Type.ETH_DST);
assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
criterion = getCriterion(Criterion.Type.ETH_SRC);
assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
criterion = getCriterion(Criterion.Type.IN_PORT);
assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(23)));
criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(44)));
criterion = getCriterion(Criterion.Type.VLAN_VID);
assertThat(((VlanIdCriterion) criterion).vlanId(), is(VlanId.vlanId((short) 777)));
criterion = getCriterion(Criterion.Type.VLAN_PCP);
assertThat(((VlanPcpCriterion) criterion).priority(), is(((byte) 3)));
criterion = getCriterion(Criterion.Type.IP_DSCP);
assertThat(((IPDscpCriterion) criterion).ipDscp(), is(((byte) 2)));
criterion = getCriterion(Criterion.Type.IP_ECN);
assertThat(((IPEcnCriterion) criterion).ipEcn(), is(((byte) 1)));
criterion = getCriterion(Criterion.Type.IP_PROTO);
assertThat(((IPProtocolCriterion) criterion).protocol(), is(((short) 4)));
criterion = getCriterion(Criterion.Type.IPV4_SRC);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("1.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV4_DST);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("2.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV6_SRC);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("3.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV6_DST);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("4.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.TCP_SRC);
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(80));
criterion = getCriterion(Criterion.Type.TCP_DST);
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(443));
criterion = getCriterion(Criterion.Type.UDP_SRC);
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(180));
criterion = getCriterion(Criterion.Type.UDP_DST);
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(1443));
criterion = getCriterion(Criterion.Type.SCTP_SRC);
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(280));
criterion = getCriterion(Criterion.Type.SCTP_DST);
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(2443));
criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
assertThat(((IcmpTypeCriterion) criterion).icmpType(), is((short) 24));
criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
assertThat(((IcmpCodeCriterion) criterion).icmpCode(), is((short) 16));
criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(), is((short) 14));
criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(), is((short) 6));
criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(), is(8));
criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
assertThat(((IPv6NDTargetAddressCriterion) criterion).targetAddress().toString(), is("1111:2222:3333:4444:5555:6666:7777:8888"));
criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:56")));
criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:57")));
criterion = getCriterion(Criterion.Type.MPLS_LABEL);
assertThat(((MplsCriterion) criterion).label(), is(MplsLabel.mplsLabel(123)));
criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(), is(99));
criterion = getCriterion(Criterion.Type.TUNNEL_ID);
assertThat(((TunnelIdCriterion) criterion).tunnelId(), is(100L));
criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
assertThat(((OchSignalTypeCriterion) criterion).signalType(), is(OchSignalType.FIXED_GRID));
criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
assertThat(((OduSignalTypeCriterion) criterion).signalType(), is(OduSignalType.ODU4));
criterion = getCriterion(Criterion.Type.ODU_SIGID);
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(), is(1));
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(), is(80));
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(), is(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class FlowRuleCodecTest method codecSimpleFlowTest.
/**
* Checks that a simple rule decodes properly.
*
* @throws IOException if the resource cannot be processed
*/
@Test
public void codecSimpleFlowTest() throws IOException {
FlowRule rule = getRule("simple-flow.json");
checkCommonData(rule);
assertThat(rule.selector().criteria().size(), is(1));
Criterion criterion1 = rule.selector().criteria().iterator().next();
assertThat(criterion1.type(), is(Criterion.Type.ETH_TYPE));
assertThat(((EthTypeCriterion) criterion1).ethType(), is(new EthType(2054)));
assertThat(rule.treatment().allInstructions().size(), is(1));
Instruction instruction1 = rule.treatment().allInstructions().get(0);
assertThat(instruction1.type(), is(Instruction.Type.OUTPUT));
assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.CONTROLLER));
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class InstructionsTest method testPopMplsEthertypeMethod.
/**
* Test the popMpls(EtherType) method.
*/
@Test
public void testPopMplsEthertypeMethod() {
final Instruction instruction = Instructions.popMpls(new EthType(1));
final L2ModificationInstruction.ModMplsHeaderInstruction pushHeaderInstruction = checkAndConvert(instruction, Instruction.Type.L2MODIFICATION, L2ModificationInstruction.ModMplsHeaderInstruction.class);
assertThat(pushHeaderInstruction.ethernetType().toShort(), is((short) 1));
assertThat(pushHeaderInstruction.subtype(), is(L2ModificationInstruction.L2SubType.MPLS_POP));
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class CriteriaTest method testMatchEthTypeMethod.
// EthTypeCriterion class
/**
* Test the matchEthType method.
*/
@Test
public void testMatchEthTypeMethod() {
EthType ethType = new EthType(12);
Criterion matchEthType = Criteria.matchEthType(new EthType(12));
EthTypeCriterion ethTypeCriterion = checkAndConvert(matchEthType, Criterion.Type.ETH_TYPE, EthTypeCriterion.class);
assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testEthTypeCriterion.
@Test
public void testEthTypeCriterion() throws Exception {
EthType ethType = new EthType(random.nextInt());
int bitWidth = 16;
EthTypeCriterion criterion = (EthTypeCriterion) Criteria.matchEthType(ethType);
PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is(criterion.ethType().toShort()));
}
Aggregations