Skip to content

Commit

Permalink
Convert openflowjava-extension-nicira to OSGi DS
Browse files Browse the repository at this point in the history
Declarative Services can easily deal with the things Blueprint is doing
for this artifact. Convert the container into two separate components.

JIRA: OPNFLWPLUG-1135
Change-Id: I80390e84458fc697e64984212998be6b4540ea11
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
  • Loading branch information
rovarga committed Feb 12, 2025
1 parent 5127f27 commit 655da87
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
14 changes: 14 additions & 0 deletions extension/openflowjava-extension-nicira/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@
<artifactId>spotbugs-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
<artifactId>javax.inject</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
<artifactId>rfc6991-ietf-inet-types</artifactId>
Expand Down Expand Up @@ -48,6 +58,10 @@
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-common-netty</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>

<dependency>
<groupId>org.opendaylight.openflowplugin.openflowjava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,44 @@
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

/**
* Implementation of NiciraExtensionCodecRegistrator.
*
* @author msunal
*/
public class NiciraExtensionCodecRegistratorImpl implements NiciraExtensionCodecRegistrator {

@Component(immediate = true)
public final class NiciraExtensionCodecRegistratorImpl implements NiciraExtensionCodecRegistrator {
// FIXME: this should not be static!
private static final Map<NiciraActionDeserializerKey, OFDeserializer<Action>> ACTION_DESERIALIZERS =
new ConcurrentHashMap<>();

private final ActionDeserializer of10ActionDeserializer = new ActionDeserializer(EncodeConstants.OF_VERSION_1_0);
private final ActionDeserializer of13ActionDeserializer = new ActionDeserializer(EncodeConstants.OF_VERSION_1_3);
private final List<SwitchConnectionProvider> providers;
private final ActionDeserializer of10ActionDeserializer;
private final ActionDeserializer of13ActionDeserializer;

@Activate
public NiciraExtensionCodecRegistratorImpl(
@Reference(target = "(type=openflow-switch-connection-provider-default-impl)")
final SwitchConnectionProvider defaultSwitchConnProvider,
@Reference(target = "(type=openflow-switch-connection-provider-legacy-impl)")
final SwitchConnectionProvider legacySwitchConnProvider) {
this(List.of(defaultSwitchConnProvider, legacySwitchConnProvider));
}

public NiciraExtensionCodecRegistratorImpl(final List<SwitchConnectionProvider> providers) {
this.providers = providers;
of10ActionDeserializer = new ActionDeserializer(EncodeConstants.OF_VERSION_1_0);
of13ActionDeserializer = new ActionDeserializer(EncodeConstants.OF_VERSION_1_3);
this.providers = List.copyOf(providers);
registerActionDeserializer(ActionDeserializer.OF10_DESERIALIZER_KEY, of10ActionDeserializer);
registerActionDeserializer(ActionDeserializer.OF13_DESERIALIZER_KEY, of13ActionDeserializer);
}

private void registerActionDeserializer(final ExperimenterActionDeserializerKey key,
final OFGeneralDeserializer deserializer) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.registerActionDeserializer(key, deserializer);
}
}
Expand All @@ -75,8 +87,7 @@ private void registerActionDeserializer(final ExperimenterActionDeserializerKey
@Override
public void registerActionDeserializer(final NiciraActionDeserializerKey key,
final OFDeserializer<Action> deserializer) {
if (deserializer instanceof DeserializerRegistryInjector) {
DeserializerRegistryInjector registryInjectable = (DeserializerRegistryInjector) deserializer;
if (deserializer instanceof DeserializerRegistryInjector registryInjectable) {
if (EncodeConstants.OF_VERSION_1_0.equals(key.getVersion())) {
registryInjectable.injectDeserializerRegistry(of10ActionDeserializer.getDeserializerRegistry());
}
Expand All @@ -88,7 +99,7 @@ public void registerActionDeserializer(final NiciraActionDeserializerKey key,
}

private void registerActionSerializer(final ActionSerializerKey<?> key, final OFGeneralSerializer serializer) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.registerActionSerializer(key, serializer);
}
}
Expand All @@ -108,13 +119,13 @@ public void registerActionSerializer(final NiciraActionSerializerKey key, final
}

private void unregisterDeserializer(final ExperimenterDeserializerKey key) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.unregisterDeserializer(key);
}
}

private void unregisterSerializer(final ExperimenterSerializerKey key) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.unregisterSerializer(key);
}
}
Expand Down Expand Up @@ -161,7 +172,7 @@ public void unregisterActionSerializer(final NiciraActionSerializerKey key) {
@Override
public void registerMatchEntryDeserializer(final MatchEntryDeserializerKey key,
final OFDeserializer<MatchEntry> deserializer) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.registerMatchEntryDeserializer(key, deserializer);
}
}
Expand Down Expand Up @@ -192,7 +203,7 @@ public void unregisterMatchEntryDeserializer(final MatchEntryDeserializerKey key
public void registerMatchEntrySerializer(
final MatchEntrySerializerKey<? extends OxmClassBase, ? extends MatchField> key,
final OFSerializer<MatchEntry> serializer) {
for (SwitchConnectionProvider provider : providers) {
for (var provider : providers) {
provider.registerMatchEntrySerializer(key, serializer);
}
}
Expand All @@ -211,6 +222,7 @@ public void unregisterMatchEntrySerializer(
unregisterSerializer(key);
}

@Deactivate
@Override
public void close() {
// TODO Auto-generated method stub
Expand All @@ -220,5 +232,4 @@ public void close() {
boolean isEmptyActionDeserializers() {
return ACTION_DESERIALIZERS.isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import static java.util.Objects.requireNonNull;

import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.openflowjava.nx.api.NiciraExtensionCodecRegistrator;
import org.opendaylight.openflowjava.nx.codec.action.ConntrackCodec;
import org.opendaylight.openflowjava.nx.codec.action.CtClearCodec;
Expand Down Expand Up @@ -67,11 +70,19 @@
import org.opendaylight.openflowjava.nx.codec.match.TunIpv4SrcCodec;
import org.opendaylight.openflowjava.nx.codec.match.UdpDstCodec;
import org.opendaylight.openflowjava.nx.codec.match.UdpSrcCodec;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

public class NiciraExtensionsRegistrator implements AutoCloseable {
@Singleton
@Component(service = { })
public final class NiciraExtensionsRegistrator implements AutoCloseable {
private final NiciraExtensionCodecRegistrator registrator;

public NiciraExtensionsRegistrator(final NiciraExtensionCodecRegistrator registrator) {
@Inject
@Activate
public NiciraExtensionsRegistrator(@Reference final NiciraExtensionCodecRegistrator registrator) {
this.registrator = requireNonNull(registrator);

registrator.registerActionDeserializer(RegLoadCodec.DESERIALIZER_KEY, NiciraActionCodecs.REG_LOAD_CODEC);
Expand Down Expand Up @@ -194,6 +205,8 @@ public NiciraExtensionsRegistrator(final NiciraExtensionCodecRegistrator registr
registrator.registerMatchEntryDeserializer(PktMarkCodec.DESERIALIZER_KEY, NiciraMatchCodecs.PKT_MARK_CODEC);
}

@Deactivate
@PreDestroy
@Override
public void close() {
registrator.unregisterActionDeserializer(RegLoadCodec.DESERIALIZER_KEY);
Expand Down

This file was deleted.

0 comments on commit 655da87

Please sign in to comment.