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