Search in sources :

Example 1 with ImmutableByteSequence

use of org.onlab.util.ImmutableByteSequence in project onos by opennetworkinglab.

the class PiExactFieldMatchTest method testConstruction.

/**
 * Checks the construction of a PiExactFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence value = copyFrom(0x0806);
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(ETH_HEADER_NAME + DOT + ETH_TYPE);
    PiExactFieldMatch piExactFieldMatch = new PiExactFieldMatch(piMatchField, value);
    assertThat(piExactFieldMatch, is(notNullValue()));
    assertThat(piExactFieldMatch.value(), is(value));
    assertThat(piExactFieldMatch.type(), is(PiMatchType.EXACT));
}
Also used : PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Example 2 with ImmutableByteSequence

use of org.onlab.util.ImmutableByteSequence in project onos by opennetworkinglab.

the class PiLpmFieldMatchTest method testConstruction.

/**
 * Checks the construction of a PiLpmFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence value = copyFrom(0x0a01010a);
    int prefix = 24;
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(IPV4_HEADER_NAME + DOT + DST_ADDR);
    PiLpmFieldMatch piLpmFieldMatch = new PiLpmFieldMatch(piMatchField, value, prefix);
    assertThat(piLpmFieldMatch, is(notNullValue()));
    assertThat(piLpmFieldMatch.value(), is(value));
    assertThat(piLpmFieldMatch.prefixLength(), is(prefix));
    assertThat(piLpmFieldMatch.type(), is(PiMatchType.LPM));
}
Also used : PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Example 3 with ImmutableByteSequence

use of org.onlab.util.ImmutableByteSequence in project onos by opennetworkinglab.

the class PiRangeFieldMatchTest method testConstruction.

/**
 * Checks the construction of a PiRangeFieldMatch object.
 */
@Test
public void testConstruction() {
    final ImmutableByteSequence high = copyFrom(0x50);
    final ImmutableByteSequence low = copyFrom(0x00);
    final PiMatchFieldId piMatchField = PiMatchFieldId.of(VLAN_HEADER_NAME + DOT + VID);
    PiRangeFieldMatch piRangeFieldMatch = new PiRangeFieldMatch(piMatchField, low, high);
    assertThat(piRangeFieldMatch, is(notNullValue()));
    assertThat(piRangeFieldMatch.lowValue(), is(low));
    assertThat(piRangeFieldMatch.highValue(), is(high));
    assertThat(piRangeFieldMatch.type(), is(PiMatchType.RANGE));
}
Also used : PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Example 4 with ImmutableByteSequence

use of org.onlab.util.ImmutableByteSequence in project onos by opennetworkinglab.

the class CriterionTranslatorHelper method translateCriterion.

/**
 * Translates a given criterion instance to a PiFieldMatch with the given id, match type, and bit-width.
 *
 * @param fieldId   PI match field identifier
 * @param criterion criterion
 * @param matchType match type
 * @param bitWidth  size of the field match in bits
 * @return a PI field match
 * @throws PiTranslationException if the criterion cannot be translated (see exception message)
 */
static PiFieldMatch translateCriterion(Criterion criterion, PiMatchFieldId fieldId, PiMatchType matchType, int bitWidth) throws PiTranslationException {
    if (!TRANSLATORS.containsKey(criterion.getClass())) {
        throw new PiTranslationException(format("Translation of criterion class %s is not implemented.", criterion.getClass().getSimpleName()));
    }
    try {
        final CriterionTranslator translator = TRANSLATORS.get(criterion.getClass()).newInstance();
        translator.init(criterion, bitWidth);
        switch(matchType) {
            case EXACT:
                return new PiExactFieldMatch(fieldId, translator.exactMatch());
            case OPTIONAL:
                return new PiOptionalFieldMatch(fieldId, translator.exactMatch());
            case TERNARY:
                final Pair<ImmutableByteSequence, ImmutableByteSequence> tp = translator.ternaryMatch();
                return new PiTernaryFieldMatch(fieldId, tp.getLeft(), tp.getRight());
            case LPM:
                final Pair<ImmutableByteSequence, Integer> lp = translator.lpmMatch();
                return new PiLpmFieldMatch(fieldId, lp.getLeft(), lp.getRight());
            default:
                throw new PiTranslationException(format("Translation of criterion %s (%s class) to match type %s is not implemented.", criterion.type().name(), criterion.getClass().getSimpleName(), matchType.name()));
        }
    } catch (ByteSequenceTrimException e) {
        throw new PiTranslationException(format("Size mismatch for criterion %s: %s", criterion.type(), e.getMessage()));
    } catch (CriterionTranslatorException e) {
        throw new PiTranslationException(format("Unable to translate criterion %s: %s", criterion.type(), e.getMessage()));
    } catch (InstantiationException | IllegalAccessException e) {
        // Was not able to instantiate the criterion translator.
        throw new IllegalStateException(e);
    }
}
Also used : IPv6NDTargetAddressCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPv6NDTargetAddressCriterionTranslator) IPEcnCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPEcnCriterionTranslator) IpCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IpCriterionTranslator) ArpPaCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.ArpPaCriterionTranslator) PbbIsidCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.PbbIsidCriterionTranslator) TcpPortCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.TcpPortCriterionTranslator) IPv6FlowLabelCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPv6FlowLabelCriterionTranslator) TunnelIdCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.TunnelIdCriterionTranslator) EthTypeCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.EthTypeCriterionTranslator) PortCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.PortCriterionTranslator) TcpFlagsCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.TcpFlagsCriterionTranslator) IPv6ExthdrFlagsCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPv6ExthdrFlagsCriterionTranslator) EthCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.EthCriterionTranslator) IPProtocolCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPProtocolCriterionTranslator) ArpOpCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.ArpOpCriterionTranslator) IPv6NDLinkLayerAddressCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPv6NDLinkLayerAddressCriterionTranslator) Icmpv6CodeCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.Icmpv6CodeCriterionTranslator) IcmpTypeCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IcmpTypeCriterionTranslator) MplsBosCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.MplsBosCriterionTranslator) MetadataCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.MetadataCriterionTranslator) VlanPcpCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.VlanPcpCriterionTranslator) UdpPortCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.UdpPortCriterionTranslator) IPDscpCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IPDscpCriterionTranslator) VlanIdCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.VlanIdCriterionTranslator) SctpPortCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.SctpPortCriterionTranslator) MplsTcCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.MplsTcCriterionTranslator) ArpHaCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.ArpHaCriterionTranslator) MplsCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.MplsCriterionTranslator) IcmpCodeCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.IcmpCodeCriterionTranslator) Icmpv6TypeCriterionTranslator(org.onosproject.net.pi.impl.CriterionTranslators.Icmpv6TypeCriterionTranslator) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) PiTranslationException(org.onosproject.net.pi.service.PiTranslationException) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) PiOptionalFieldMatch(org.onosproject.net.pi.runtime.PiOptionalFieldMatch) CriterionTranslatorException(org.onosproject.net.pi.impl.CriterionTranslator.CriterionTranslatorException) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) ByteSequenceTrimException(org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 5 with ImmutableByteSequence

use of org.onlab.util.ImmutableByteSequence in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testTernaryToLpmTranslation.

@Test
public void testTernaryToLpmTranslation() throws Exception {
    EthCriterion criterion = (EthCriterion) Criteria.matchEthDstMasked(MacAddress.ONOS, MacAddress.IPV4_MULTICAST_MASK);
    PiLpmFieldMatch lpmMatch = (PiLpmFieldMatch) translateCriterion(criterion, fieldId, LPM, MacAddress.MAC_ADDRESS_LENGTH * Byte.SIZE);
    ImmutableByteSequence expectedValue = ImmutableByteSequence.copyFrom(MacAddress.ONOS.toBytes());
    assertThat(lpmMatch.prefixLength(), is(25));
    assertThat(lpmMatch.value(), is(expectedValue));
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Aggregations

ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)17 Test (org.junit.Test)8 PiMatchFieldId (org.onosproject.net.pi.model.PiMatchFieldId)8 PiLpmFieldMatch (org.onosproject.net.pi.runtime.PiLpmFieldMatch)4 ByteString (com.google.protobuf.ByteString)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 PiAction (org.onosproject.net.pi.runtime.PiAction)3 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)3 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 String.format (java.lang.String.format)2 ByteBuffer (java.nio.ByteBuffer)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors.toList (java.util.stream.Collectors.toList)2 DeserializationException (org.onlab.packet.DeserializationException)2 Ethernet (org.onlab.packet.Ethernet)2 ByteSequenceTrimException (org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException)2