Search in sources :

Example 1 with TranslatorLibrary

use of org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorUtil method translate.

public static Optional<? extends MultipartReplyBody> translate(final OfHeader message, final DeviceInfo deviceInfo, @Nullable final ConvertorExecutor convertorExecutor, @Nullable final TranslatorLibrary translatorLibrary) {
    if (message instanceof MultipartReply) {
        final Optional<ConvertorExecutor> convertor = Optional.ofNullable(convertorExecutor);
        final Optional<TranslatorLibrary> translator = Optional.ofNullable(translatorLibrary);
        final MultipartReply msg = MultipartReply.class.cast(message);
        final OpenflowVersion ofVersion = OpenflowVersion.get(deviceInfo.getVersion());
        final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(deviceInfo.getVersion());
        data.setDatapathId(deviceInfo.getDatapathId());
        switch(msg.getType()) {
            case OFPMPFLOW:
                return convertor.flatMap(c -> Optional.of(translateFlow(msg, data, c)));
            case OFPMPAGGREGATE:
                return Optional.of(translateAggregate(msg));
            case OFPMPPORTSTATS:
                return Optional.of(translatePortStats(msg, ofVersion, deviceInfo.getDatapathId()));
            case OFPMPGROUP:
                return convertor.flatMap(c -> Optional.of(translateGroup(msg, data, c)));
            case OFPMPGROUPDESC:
                return convertor.flatMap(c -> Optional.of(translateGroupDesc(msg, data, c)));
            case OFPMPGROUPFEATURES:
                return Optional.of(translateGroupFeatures(msg));
            case OFPMPMETER:
                return convertor.flatMap(c -> Optional.of(translateMeter(msg, data, c)));
            case OFPMPMETERCONFIG:
                return convertor.flatMap(c -> Optional.of(translateMeterConfig(msg, data, c)));
            case OFPMPMETERFEATURES:
                return Optional.of(translateMeterFeatures(msg));
            case OFPMPTABLE:
                return Optional.of(translateTable(msg));
            case OFPMPQUEUE:
                return Optional.of(translateQueue(msg, ofVersion, deviceInfo.getDatapathId()));
            case OFPMPDESC:
                return Optional.of(translateDesc(msg));
            case OFPMPTABLEFEATURES:
                return convertor.flatMap(c -> Optional.of(translateTableFeatures(msg, deviceInfo.getVersion(), c)));
            case OFPMPPORTDESC:
                return translator.flatMap(t -> Optional.of(translatePortDesc(msg, deviceInfo, t)));
            default:
        }
    } else if (message instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) {
        return Optional.of(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply.class.cast(message).getMultipartReplyBody());
    }
    LOG.debug("Failed to translate {} for node {}.", message.getImplementedInterface(), deviceInfo);
    return Optional.empty();
}
Also used : VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)

Example 2 with TranslatorLibrary

use of org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary in project openflowplugin by opendaylight.

the class DeviceContextImplTest method testTranslatorLibrary.

@Test
public void testTranslatorLibrary() {
    final TranslatorLibrary pickedTranslatorLibrary = deviceContext.oook();
    assertEquals(translatorLibrary, pickedTranslatorLibrary);
}
Also used : TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) Test(org.junit.Test)

Example 3 with TranslatorLibrary

use of org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary in project openflowplugin by opendaylight.

the class TranslatorLibraryUtil method injectBasicTranslatorLibrary.

public static void injectBasicTranslatorLibrary(final TranslatorLibrarian librarian, final ConvertorExecutor convertorExecutor) {
    final TranslatorLibrary basicTranslatorLibrary = new TranslatorLibraryBuilder().addTranslator(OF_13_TRANSLATOR_KEY_FACTORY.createTranslatorKey(PacketIn.class), new PacketReceivedTranslator(convertorExecutor)).addTranslator(OF_13_TRANSLATOR_KEY_FACTORY.createTranslatorKey(PortGrouping.class), new PortUpdateTranslator()).addTranslator(OF_13_TRANSLATOR_KEY_FACTORY.createTranslatorKey(MultipartReplyAggregateCase.class), new AggregatedFlowStatisticsTranslator()).addTranslator(OF_13_TRANSLATOR_KEY_FACTORY.createTranslatorKey(FlowRemoved.class), new FlowRemovedTranslator(convertorExecutor)).addTranslator(OF_10_TRANSLATOR_KEY_FACTORY.createTranslatorKey(PacketIn.class), new PacketReceivedTranslator(convertorExecutor)).addTranslator(OF_10_TRANSLATOR_KEY_FACTORY.createTranslatorKey(PortGrouping.class), new PortUpdateTranslator()).addTranslator(OF_10_TRANSLATOR_KEY_FACTORY.createTranslatorKey(MultipartReplyAggregateCase.class), new AggregatedFlowStatisticsTranslator()).addTranslator(OF_10_TRANSLATOR_KEY_FACTORY.createTranslatorKey(FlowRemoved.class), new FlowRemovedV10Translator(convertorExecutor)).build();
    librarian.setTranslatorLibrary(basicTranslatorLibrary);
}
Also used : TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) PacketIn(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn) MultipartReplyAggregateCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase) PortUpdateTranslator(org.opendaylight.openflowplugin.impl.translator.PortUpdateTranslator) FlowRemovedV10Translator(org.opendaylight.openflowplugin.impl.translator.FlowRemovedV10Translator) TranslatorLibraryBuilder(org.opendaylight.openflowplugin.impl.translator.TranslatorLibraryBuilder) PacketReceivedTranslator(org.opendaylight.openflowplugin.impl.translator.PacketReceivedTranslator) FlowRemovedTranslator(org.opendaylight.openflowplugin.impl.translator.FlowRemovedTranslator) AggregatedFlowStatisticsTranslator(org.opendaylight.openflowplugin.impl.translator.AggregatedFlowStatisticsTranslator)

Example 4 with TranslatorLibrary

use of org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorUtilTest method setUp.

@Before
public void setUp() throws Exception {
    when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    translatorLibrarian = new TranslatorLibrarian() {

        private TranslatorLibrary translatorLibrary;

        @Override
        public TranslatorLibrary oook() {
            return translatorLibrary;
        }

        @Override
        public void setTranslatorLibrary(final TranslatorLibrary translatorLibrary) {
            this.translatorLibrary = translatorLibrary;
        }
    };
    TranslatorLibraryUtil.injectBasicTranslatorLibrary(translatorLibrarian, convertorExecutor);
}
Also used : TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) TranslatorLibrarian(org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian) Before(org.junit.Before)

Example 5 with TranslatorLibrary

use of org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary in project openflowplugin by opendaylight.

the class TranslatorLibratyUtilTest method setBasicTranslatorLibraryTest.

@Test
public void setBasicTranslatorLibraryTest() {
    final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
    TranslatorLibraryUtil.injectBasicTranslatorLibrary(translatorLibrarian, convertorManager);
    TranslatorLibrary translatorLibrary = translatorLibrarian.oook();
    TranslatorKeyFactory of13TranslatorKeyFactory = new TranslatorKeyFactory(OFP_VERSION_1_3);
    MessageTranslator<Object, Object> translator;
    translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory.createTranslatorKey(PacketIn.class));
    assertNotNull(translator);
    translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory.createTranslatorKey(PortGrouping.class));
    assertNotNull(translator);
    translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory.createTranslatorKey(MultipartReplyAggregateCase.class));
    assertNotNull(translator);
    TranslatorKeyFactory of10TranslatorKeyFactory = new TranslatorKeyFactory(OFP_VERSION_1_0);
    translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(PacketIn.class));
    assertNotNull(translator);
    translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(PortGrouping.class));
    assertNotNull(translator);
    translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(MultipartReplyAggregateCase.class));
    assertNotNull(translator);
}
Also used : TranslatorLibrary(org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary) TranslatorKeyFactory(org.opendaylight.openflowplugin.impl.translator.TranslatorKeyFactory) ConvertorManager(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager) Test(org.junit.Test)

Aggregations

TranslatorLibrary (org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary)5 Test (org.junit.Test)2 Before (org.junit.Before)1 OpenflowVersion (org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)1 TranslatorLibrarian (org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian)1 AggregatedFlowStatisticsTranslator (org.opendaylight.openflowplugin.impl.translator.AggregatedFlowStatisticsTranslator)1 FlowRemovedTranslator (org.opendaylight.openflowplugin.impl.translator.FlowRemovedTranslator)1 FlowRemovedV10Translator (org.opendaylight.openflowplugin.impl.translator.FlowRemovedV10Translator)1 PacketReceivedTranslator (org.opendaylight.openflowplugin.impl.translator.PacketReceivedTranslator)1 PortUpdateTranslator (org.opendaylight.openflowplugin.impl.translator.PortUpdateTranslator)1 TranslatorKeyFactory (org.opendaylight.openflowplugin.impl.translator.TranslatorKeyFactory)1 TranslatorLibraryBuilder (org.opendaylight.openflowplugin.impl.translator.TranslatorLibraryBuilder)1 ConvertorExecutor (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)1 ConvertorManager (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager)1 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)1 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)1 PacketIn (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn)1 MultipartReplyAggregateCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase)1