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