Search in sources :

Example 6 with MatchEntrySerializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey in project openflowplugin by opendaylight.

the class TypeKeyMakerFactoryTest method testExperimenterMatchEntriesKeyMaker.

/**
 * Tests {@link TypeKeyMakerFactory#createMatchEntriesKeyMaker(short)}.
 */
@Test
public void testExperimenterMatchEntriesKeyMaker() {
    TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null keyMaker", keyMaker);
    MatchEntryBuilder builder = new MatchEntryBuilder();
    builder.setOxmClass(ExperimenterClass.class);
    builder.setOxmMatchField(OxmMatchFieldClass.class);
    builder.setHasMask(true);
    ExperimenterIdCaseBuilder caseBuilder = new ExperimenterIdCaseBuilder();
    ExperimenterBuilder expBuilder = new ExperimenterBuilder();
    expBuilder.setExperimenter(new ExperimenterId(42L));
    caseBuilder.setExperimenter(expBuilder.build());
    builder.setMatchEntryValue(caseBuilder.build());
    MatchEntry entry = builder.build();
    MessageTypeKey<?> key = keyMaker.make(entry);
    Assert.assertNotNull("Null key", key);
    MatchEntrySerializerKey<?, ?> comparationKey = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, ExperimenterClass.class, OxmMatchFieldClass.class);
    comparationKey.setExperimenterId(42L);
    Assert.assertEquals("Wrong key", comparationKey, key);
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) ExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder) MatchEntrySerializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey) ExperimenterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId) ExperimenterIdCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder) Test(org.junit.Test)

Example 7 with MatchEntrySerializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey in project openflowplugin by opendaylight.

the class OF13SetFieldActionSerializer method serialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public void serialize(Action action, ByteBuf outBuffer) {
    Objects.requireNonNull(registry);
    final int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
    final int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    MatchEntry entry = ((SetFieldCase) action.getActionChoice()).getSetFieldAction().getMatchEntry().get(0);
    MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField());
    if (entry.getOxmClass().equals(ExperimenterClass.class)) {
        ExperimenterIdCase experimenterIdCase = (ExperimenterIdCase) entry.getMatchEntryValue();
        key.setExperimenterId(experimenterIdCase.getExperimenter().getExperimenter().getValue());
    } else {
        key.setExperimenterId(null);
    }
    OFSerializer<MatchEntry> serializer = registry.getSerializer(key);
    serializer.serialize(entry, outBuffer);
    int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
}
Also used : ExperimenterIdCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) SetFieldCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) MatchEntrySerializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with MatchEntrySerializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey in project openflowplugin by opendaylight.

the class MatchExtensionHelper method processExtension.

/**
 * Processes an extension.
 *
 * @param ofVersion openflow version
 * @param matchPath match path
 * @param matchEntry match entry
 * @return an ExtensionListBuilder
 */
private static ExtensionListBuilder processExtension(MatchEntry matchEntry, short ofVersion, MatchPath matchPath) {
    ExtensionListBuilder extListBld = null;
    // TODO: EXTENSION PROPOSAL (match, OFJava to MD-SAL)
    MatchEntrySerializerKey<? extends OxmClassBase, ? extends MatchField> key = new MatchEntrySerializerKey<>(ofVersion, matchEntry.getOxmClass(), matchEntry.getOxmMatchField());
    if (null != OFSessionUtil.getExtensionConvertorProvider()) {
        ConvertorFromOFJava<MatchEntry, MatchPath> convertor = OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
        if (convertor != null) {
            ExtensionAugment<? extends Augmentation<Extension>> extensionMatch = convertor.convert(matchEntry, matchPath);
            ExtensionBuilder extBld = new ExtensionBuilder();
            extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
            extListBld = new ExtensionListBuilder();
            extListBld.setExtension(extBld.build());
            extListBld.setExtensionKey(extensionMatch.getKey());
        }
    }
    return extListBld;
}
Also used : Extension(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension) ExtensionListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchPath(org.opendaylight.openflowplugin.extension.api.path.MatchPath) ExtensionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder) MatchEntrySerializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey)

Aggregations

MatchEntrySerializerKey (org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey)8 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)6 Test (org.junit.Test)4 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)3 MatchEntryDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey)2 ExperimenterIdCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase)2 ExperimenterIdCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder)2 ExperimenterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder)2 ExperimenterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 NiciraActionDeserializerKey (org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey)1 NiciraActionSerializerKey (org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey)1 ExperimenterActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey)1 ExperimenterActionSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey)1 ExperimenterIdDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey)1 ExperimenterIdMeterSubTypeSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey)1 ExperimenterIdSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey)1