Search in sources :

Example 1 with MessageTypeKey

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

the class MultipartReplyExperimenterDeserializer method deserialize.

@Override
@SuppressWarnings("unchecked")
public MultipartReplyBody deserialize(ByteBuf message) {
    final MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder();
    final long expId = message.readUnsignedInt();
    final long expType = message.readUnsignedInt();
    try {
        final OFDeserializer<ExperimenterMessageOfChoice> deserializer = registry.getDeserializer(new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, expType, ExperimenterMessageOfChoice.class));
        builder.setExperimenterMessageOfChoice(deserializer.deserialize(message));
    } catch (ClassCastException | IllegalStateException es) {
        final OFDeserializer<ExperimenterDataOfChoice> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, expType));
        final ExperimenterDataOfChoice data = deserializer.deserialize(message);
        final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, (Class<? extends ExperimenterDataOfChoice>) data.getImplementedInterface());
        final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> convertor = OFSessionUtil.getExtensionConvertorProvider().getMessageConverter(key);
        try {
            builder.setExperimenterMessageOfChoice(convertor.convert(data, MessagePath.MPMESSAGE_RPC_OUTPUT));
        } catch (ConversionException ce) {
            LOG.debug("Failed to deserialize multipart reply experimenter for key: {}", key);
        }
    }
    return builder.build();
}
Also used : OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ConvertorMessageFromOFJava(org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava) MultipartReplyExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) ExperimenterIdTypeDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)

Example 2 with MessageTypeKey

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

the class OF10MatchSerializerTest method startUp.

/**
 * Initializes serializer table and stores correct factory in field.
 */
@Before
public void startUp() {
    registry = new SerializerRegistryImpl();
    registry.init();
    matchSerializer = registry.getSerializer(new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, MatchV10.class));
}
Also used : SerializerRegistryImpl(org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) Before(org.junit.Before)

Example 3 with MessageTypeKey

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

the class OF13MatchSerializerTest method startUp.

/**
 * Initializes serializer table and stores correct factory in field.
 */
@Before
public void startUp() {
    registry = new SerializerRegistryImpl();
    registry.init();
    matchSerializer = registry.getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Match.class));
}
Also used : SerializerRegistryImpl(org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) Before(org.junit.Before)

Example 4 with MessageTypeKey

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

the class DeviceContextImpl method processExperimenterMessage.

@Override
public void processExperimenterMessage(final ExperimenterMessage notification) {
    if (isMasterOfDevice()) {
        // lookup converter
        final ExperimenterDataOfChoice vendorData = notification.getExperimenterDataOfChoice();
        final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(getDeviceInfo().getVersion(), (Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
        final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
        if (messageConverter == null) {
            LOG.warn("custom converter for {}[OF:{}] not found", notification.getExperimenterDataOfChoice().getImplementedInterface(), getDeviceInfo().getVersion());
            return;
        }
        // build notification
        final ExperimenterMessageOfChoice messageOfChoice;
        try {
            messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
            final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder().setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier())).setExperimenterMessageOfChoice(messageOfChoice);
            // publish
            notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
        } catch (final ConversionException e) {
            LOG.error("Conversion of experimenter notification failed", e);
        }
    } else {
        LOG.debug("Controller is not owner of the device {}, skipping experimenter message", deviceInfo.getLOGValue());
    }
}
Also used : ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ExperimenterMessageFromDevBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)

Example 5 with MessageTypeKey

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

the class SwitchConnectionProviderImpl02Test method testUnregisterExistingKeys.

/**
 * Test register and unregister method.
 */
@Test
public void testUnregisterExistingKeys() throws UnknownHostException {
    startUp(TransportProtocol.TCP);
    // -- registerActionSerializer
    final ExperimenterActionSerializerKey key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
    provider.registerActionSerializer(key1, serializer);
    Assert.assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
    Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key", provider.unregisterSerializer(key1));
    // -- registerActionDeserializer
    final ExperimenterActionDeserializerKey key2 = new ExperimenterActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
    provider.registerActionDeserializer(key2, deserializer);
    Assert.assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
    Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key", provider.unregisterDeserializer(key2));
    // -- registerInstructionSerializer
    final ExperimenterInstructionSerializerKey key3 = new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
    provider.registerInstructionSerializer(key3, serializer);
    Assert.assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
    Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key", provider.unregisterSerializer(key3));
    // -- registerInstructionDeserializer
    final ExperimenterInstructionDeserializerKey key4 = new ExperimenterInstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
    provider.registerInstructionDeserializer(key4, deserializer);
    Assert.assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
    Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key", provider.unregisterDeserializer(key4));
    // -- registerMatchEntryDeserializer
    final MatchEntryDeserializerKey key5 = new MatchEntryDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0x8000, 42);
    provider.registerMatchEntryDeserializer(key5, deserializer);
    Assert.assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
    Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key", provider.unregisterDeserializer(key5));
    // -- registerErrorDeserializer
    final ExperimenterIdDeserializerKey key6 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ErrorMessage.class);
    provider.registerErrorDeserializer(key6, deserializerError);
    Assert.assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
    Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key", provider.unregisterDeserializer(key6));
    // -- registerExperimenterMessageDeserializer
    final ExperimenterIdDeserializerKey key7 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class);
    provider.registerExperimenterMessageDeserializer(key7, deserializerExpMsg);
    Assert.assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
    Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key", provider.unregisterDeserializer(key7));
    // -- registerMultipartReplyMessageDeserializer
    final ExperimenterIdDeserializerKey key8 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
    provider.registerMultipartReplyMessageDeserializer(key8, deserializerMultipartRplMsg);
    Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer", provider.unregisterDeserializer(key8));
    Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key", provider.unregisterDeserializer(key8));
    // -- registerMultipartReplyTFDeserializer
    final ExperimenterIdDeserializerKey key9 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
    provider.registerMultipartReplyTFDeserializer(key9, deserializer);
    Assert.assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
    Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key", provider.unregisterDeserializer(key9));
    // -- registerQueuePropertyDeserializer
    final ExperimenterIdDeserializerKey key10 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, QueueProperty.class);
    provider.registerQueuePropertyDeserializer(key10, deserializerQueueProperty);
    Assert.assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
    Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key", provider.unregisterDeserializer(key10));
    // -- registerMeterBandDeserializer
    final ExperimenterIdDeserializerKey key11 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MeterBandExperimenterCase.class);
    provider.registerMeterBandDeserializer(key11, deserializerMeterBandExpCase);
    Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
    Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key", provider.unregisterDeserializer(key11));
    // -- registerExperimenterMessageSerializer
    ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key12 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class);
    provider.registerExperimenterMessageSerializer(key12, serializerExperimenterInput);
    Assert.assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
    Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key", provider.unregisterSerializer(key12));
    // registerMultipartRequestSerializer
    ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key13 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class);
    provider.registerMultipartRequestSerializer(key13, serializerMultipartRequestExpCase);
    Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
    Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key", provider.unregisterSerializer(key13));
    // -- registerMultipartRequestTFSerializer
    final ExperimenterIdSerializerKey<TableFeatureProperties> key14 = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, TableFeatureProperties.class);
    provider.registerMultipartRequestTFSerializer(key14, serializer);
    Assert.assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
    Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key", provider.unregisterSerializer(key14));
    // -- registerMeterBandSerializer
    final ExperimenterIdMeterSubTypeSerializerKey<MeterBandExperimenterCase> key15 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, MeterBandExperimenterCase.class, null);
    provider.registerMeterBandSerializer(key15, serializerMeterBandExpCase);
    Assert.assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
    Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key", provider.unregisterSerializer(key15));
    // -- registerMatchEntrySerializer
    final MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
    provider.registerMatchEntrySerializer(key16, serializer);
    Assert.assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
    Assert.assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key", provider.unregisterSerializer(key15));
    // -- registerSerializer
    final MessageTypeKey key17 = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TestSubType.class);
    provider.registerSerializer(key17, serializer);
    // -- registerDeserializer
    final MessageCodeKey key18 = new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 42, TestSubType.class);
    provider.registerDeserializer(key18, deserializer);
}
Also used : ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) InPort(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey) TableFeatureProperties(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties) OpenflowBasicClass(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass) ExperimenterIdMeterSubTypeSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey) ExperimenterInstructionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey) ExperimenterIdDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) ExperimenterInstructionSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ExperimenterActionSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) MatchEntrySerializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) ExperimenterIdSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey) Test(org.junit.Test)

Aggregations

MessageTypeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)60 Before (org.junit.Before)55 SerializerRegistryImpl (org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl)55 SerializerRegistry (org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry)21 ExperimenterDataOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)4 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)3 ExperimenterMessageOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice)3 Test (org.junit.Test)2 MessagePath (org.opendaylight.openflowplugin.extension.api.path.MessagePath)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)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 ExperimenterIdTypeDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey)1