use of org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider in project openflowplugin by opendaylight.
the class SalToOfVendorCodecCase method process.
@SuppressWarnings("unchecked")
@Nonnull
@Override
public Optional<Action> process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
final short version = data.getVersion();
final TypeVersionKey<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> key = new TypeVersionKey<>((Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>) source.getImplementedInterface(), version);
ExtensionConverterProvider extensionConverterProvider = OFSessionUtil.getExtensionConvertorProvider();
if (extensionConverterProvider == null) {
return Optional.empty();
}
final ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action> convertor = extensionConverterProvider.getConverter(key);
LOG.trace("OFP Extension action, key:{}, converter:{}", key, convertor);
return convertor != null ? Optional.of(convertor.convert(source)) : Optional.empty();
}
use of org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider in project openflowplugin by opendaylight.
the class ActionExtensionHelper method processAlienAction.
/**
* Processes an alien action.
*
* @param action openflow action
* @param ofVersion openflow version
* @param actionPath openflow action path
* @return augmentation wrapper containing augmentation depending on matchPath
*/
public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processAlienAction(final Action action, final OpenflowVersion ofVersion, final ActionPath actionPath) {
ConvertorActionFromOFJava<Action, ActionPath> convertor = null;
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action alienAction = null;
final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
if (Objects.isNull(extensionConvertorProvider)) {
return null;
}
if (action.getActionChoice() instanceof ExperimenterIdCase) {
ExperimenterIdCase actionCase = (ExperimenterIdCase) action.getActionChoice();
// TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
ExperimenterActionSerializerKey key = new ExperimenterActionSerializerKey(ofVersion.getVersion(), actionCase.getExperimenter().getExperimenter().getValue(), actionCase.getExperimenter().getSubType());
convertor = extensionConvertorProvider.getActionConverter(key);
} else if (action.getActionChoice() != null) {
ActionSerializerKey<?> key = new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID, action.getActionChoice().getImplementedInterface(), null);
convertor = extensionConvertorProvider.getActionConverter(key);
}
if (convertor != null) {
alienAction = convertor.convert(action, actionPath);
}
return alienAction;
}
use of org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider in project openflowplugin by opendaylight.
the class DeviceContextImplTest method testProcessExperimenterMessage.
@Test
public void testProcessExperimenterMessage() {
final ConvertorMessageFromOFJava mockedMessageConverter = mock(ConvertorMessageFromOFJava.class);
final ExtensionConverterProvider mockedExtensionConverterProvider = mock(ExtensionConverterProvider.class);
when(mockedExtensionConverterProvider.getMessageConverter(any(MessageTypeKey.class))).thenReturn(mockedMessageConverter);
final ExperimenterDataOfChoice mockedExperimenterDataOfChoice = mock(ExperimenterDataOfChoice.class);
final ExperimenterMessage experimenterMessage = new ExperimenterMessageBuilder().setExperimenterDataOfChoice(mockedExperimenterDataOfChoice).build();
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
((DeviceContextImpl) deviceContext).setExtensionConverterProvider(mockedExtensionConverterProvider);
deviceContext.processExperimenterMessage(experimenterMessage);
verify(mockedNotificationPublishService).offerNotification(any(ExperimenterMessageFromDev.class));
}
use of org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider in project openflowplugin by opendaylight.
the class MatchConvertor method convert.
@Override
public List<MatchEntry> convert(final Match source, final VersionConvertorData data) {
List<MatchEntry> result = new ArrayList<>();
if (source == null) {
return result;
}
final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
inPortMatch(result, source.getInPort());
inPhyPortMatch(result, source.getInPhyPort());
metadataMatch(result, source.getMetadata());
ethernetMatch(result, source.getEthernetMatch());
vlanMatch(result, source.getVlanMatch());
ipMatch(result, source.getIpMatch());
layer4Match(result, source.getLayer4Match(), getConvertorExecutor(), extensionConvertorProvider);
icmpv4Match(result, source.getIcmpv4Match());
icmpv6Match(result, source.getIcmpv6Match());
layer3Match(result, source.getLayer3Match(), getConvertorExecutor(), extensionConvertorProvider);
protocolMatchFields(result, source.getProtocolMatchFields());
tunnelMatch(result, source.getTunnel());
tcpFlagsMatch(result, source.getTcpFlagsMatch());
/*
* TODO: EXTENSION PROPOSAL (source, MD-SAL to OFJava)
* - we might need version for conversion and for key
*/
Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(source);
if (extensionListOpt.isPresent()) {
List<ExtensionList> extensionListList = extensionListOpt.get().getExtensionList();
for (ExtensionList extensionItem : extensionListList) {
// TODO: get real version
ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
ConvertorToOFJava<MatchEntry> convertor = extensionConvertorProvider.getConverter(key);
if (convertor == null) {
throw new IllegalStateException("No converter found for key: " + key.toString());
}
MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
result.add(ofMatch);
}
}
return result;
}
Aggregations