Convert bgp-flowspec to OSGi DS 11/93711/9
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Nov 2020 02:18:51 +0000 (03:18 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Nov 2020 14:47:31 +0000 (15:47 +0100)
As it turns out, FlowspecActivator is just a bunch of static wiring,
which we do not need to inject. Refactor SimpleFlowspecTypeRegistry
into a dedicated immutable FlowspecTypeRegistry, which has provably
static lifecycle and used only for immutable access.

This cuts a ton of complexity and fixes ServiceLoader injection,
plus makes DI conversion a breeze -- eliminating static state in
process of doing so.

JIRA: BGPCEP-941
Change-Id: I0ad4fef346131b44f7f5bca2a637826e821146d7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
29 files changed:
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java [deleted file]
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistries.java [new file with mode: 0644]
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistry.java [moved from bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java with 71% similarity]
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistryBuilder.java [new file with mode: 0644]
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/RIBActivator.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java [deleted file]
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/AbstractFlowspecL3vpnNlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4NlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6NlriParser.java
bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java
bgp/extensions/flowspec/src/main/resources/OSGI-INF/blueprint/bgp-flowspec.xml [deleted file]
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/ActivatorTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupportTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupportTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv4NlriParserTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv4RIBSupportTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6NlriParserTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6RIBSupportTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParserTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParserTest.java
bgp/extensions/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/FSExtendedCommunitiesTest.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/BGPTestTool.java

index 84752c5d0464955604fba858ffb96f8b61e4793f..7857e0e938e73a4527f234f6bfec066a6ef06a9f 100644 (file)
@@ -136,7 +136,7 @@ public abstract class AbstractFlowspecNlriParser implements NlriParser, NlriSeri
     public static final NodeIdentifier VALUE_NID
             = new NodeIdentifier(QName.create(Flowspec.QNAME.getModule(), "value"));
 
-    protected final SimpleFlowspecTypeRegistry flowspecTypeRegistry;
+    protected final FlowspecTypeRegistry flowspecTypeRegistry;
 
     /**
      * Add this constant to length value to achieve all ones in the leftmost nibble.
@@ -156,7 +156,7 @@ public abstract class AbstractFlowspecNlriParser implements NlriParser, NlriSeri
 
     private static final String FLOW_SEPARATOR = " AND ";
 
-    protected AbstractFlowspecNlriParser(final SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
+    protected AbstractFlowspecNlriParser(final FlowspecTypeRegistry flowspecTypeRegistry) {
         this.flowspecTypeRegistry = requireNonNull(flowspecTypeRegistry);
     }
 
index e6e78e4fb409b8fb83a9528da5e30c2b4be933c4..ac3d1e81c7048d126204da9147c2acbd1ba14232 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.flowspec;
 
-import static java.util.Objects.requireNonNull;
-
 import java.util.ArrayList;
 import java.util.List;
-import org.eclipse.jdt.annotation.NonNull;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.kohsuke.MetaInfServices;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsFourOctetEcHandler;
 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsTwoOctetEcHandler;
 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpNextHopEcHandler;
@@ -47,23 +47,23 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Component;
 
+@Singleton
+@Component(immediate = true, service = BGPExtensionProviderActivator.class,
+           property = "type=org.opendaylight.protocol.bgp.flowspec.BGPActivator")
 @MetaInfServices(value = BGPExtensionProviderActivator.class)
 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
     private static final int FLOWSPEC_SAFI = 133;
     private static final int FLOWSPEC_L3VPN_SAFI = 134;
 
-    private final FlowspecActivator activator;
-
-    // FIXME: this needs proper injection
-    public BGPActivator(final @NonNull FlowspecActivator activator) {
-        this.activator = requireNonNull(activator);
+    @Inject
+    public BGPActivator() {
+        // Exposed for DI
     }
 
     @Override
     protected List<Registration> startImpl(final BGPExtensionProviderContext context) {
-        final SimpleFlowspecExtensionProviderContext flowspecContext = activator.getContext();
-
         final List<Registration> regs = new ArrayList<>();
         regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
         regs.add(context.registerSubsequentAddressFamily(FlowspecL3vpnSubsequentAddressFamily.class,
@@ -72,12 +72,8 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
         final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
 
-        final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
-        final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
+        final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC);
         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
             fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class,
@@ -85,12 +81,8 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
         regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler));
         regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler));
 
-        final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
-        final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+        final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
+        final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(SAFI.FLOWSPEC_VPN);
         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
             fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java
deleted file mode 100644 (file)
index 911b49b..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.flowspec;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4DestinationPrefixHandler;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4FragmentHandler;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4SourcePrefixHandler;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6DestinationPrefixHandler;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6FragmentHandler;
-import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.DscpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.FragmentCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.PortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.FlowLabelCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase;
-import org.opendaylight.yangtools.concepts.Registration;
-
-public final class FlowspecActivator implements AutoCloseable {
-    private final SimpleFlowspecExtensionProviderContext context;
-    private List<Registration> registrations = new ArrayList<>();
-
-    public SimpleFlowspecExtensionProviderContext getContext() {
-        return this.context;
-    }
-
-    public FlowspecActivator(final @NonNull SimpleFlowspecExtensionProviderContext context) {
-        this.context = requireNonNull(context);
-
-        for (SimpleFlowspecExtensionProviderContext.SAFI safi : SimpleFlowspecExtensionProviderContext.SAFI.values()) {
-            registerCommonFlowspecTypeHandlers(
-                SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                safi
-            );
-            registerIpv4FlowspecTypeHandlers(
-                SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                safi
-            );
-
-            registerCommonFlowspecTypeHandlers(
-                SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                safi
-            );
-            registerIpv6FlowspecTypeHandlers(
-                SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                safi
-            );
-        }
-    }
-
-    /**
-     * Register the common flowspec type handlers.
-     */
-    private void registerCommonFlowspecTypeHandlers(
-        final SimpleFlowspecExtensionProviderContext.AFI afi,
-        final SimpleFlowspecExtensionProviderContext.SAFI safi
-    ) {
-        final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
-
-        final FSPortHandler portHandler = new FSPortHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSPortHandler.PORT_VALUE, portHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PortCase.class, portHandler));
-
-        final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPortCase.class,
-            destinationPortHandler));
-
-        final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE,
-            sourcePortHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePortCase.class,
-            sourcePortHandler));
-
-        final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE,
-            icmpTypeHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpTypeCase.class,
-            icmpTypeHandler));
-
-        final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE,
-            icmpCodeHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpCodeCase.class,
-            icmpCodeHandler));
-
-        final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE,
-            tcpFlagsHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(TcpFlagsCase.class,
-            tcpFlagsHandler));
-
-        final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PacketLengthCase.class,
-            packetlengthHandler));
-
-        final FSDscpHandler dscpHandler = new FSDscpHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DscpCase.class, dscpHandler));
-    }
-
-    private void registerIpv4FlowspecTypeHandlers(
-        final SimpleFlowspecExtensionProviderContext.AFI afi,
-        final SimpleFlowspecExtensionProviderContext.SAFI safi
-    ) {
-        final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
-
-        final FSIpv4DestinationPrefixHandler destinationPrefixHandler = new FSIpv4DestinationPrefixHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSIpv4DestinationPrefixHandler.DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPrefixCase.class,
-            destinationPrefixHandler));
-
-        final FSIpv4SourcePrefixHandler sourcePrefixHandler = new FSIpv4SourcePrefixHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSIpv4SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePrefixCase.class,
-            sourcePrefixHandler));
-
-        final FSIpProtocolHandler ipProtocolHandler = new FSIpProtocolHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpProtocolHandler.IP_PROTOCOL_VALUE,
-            ipProtocolHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(ProtocolIpCase.class,
-            ipProtocolHandler));
-
-        final FSIpv4FragmentHandler fragmentHandler = new FSIpv4FragmentHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4FragmentHandler.FRAGMENT_VALUE,
-            fragmentHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class,
-            fragmentHandler));
-    }
-
-    private void registerIpv6FlowspecTypeHandlers(
-        final SimpleFlowspecExtensionProviderContext.AFI afi,
-        final SimpleFlowspecExtensionProviderContext.SAFI safi
-    ) {
-        final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
-
-        final FSIpv6DestinationPrefixHandler destinationPrefixHandler = new FSIpv6DestinationPrefixHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSIpv6DestinationPrefixHandler.IPV6_DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationIpv6PrefixCase.class,
-            destinationPrefixHandler));
-
-        final FSIpv6SourcePrefixHandler sourcePrefixHandler = new FSIpv6SourcePrefixHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSIpv6SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourceIpv6PrefixCase.class,
-            sourcePrefixHandler));
-
-        final FSIpv6NextHeaderHandler nextHeaderHandler = new FSIpv6NextHeaderHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(
-            FSIpv6NextHeaderHandler.NEXT_HEADER_VALUE, nextHeaderHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(NextHeaderCase.class,
-            nextHeaderHandler));
-
-        final FSIpv6FragmentHandler fragmentHandler = new FSIpv6FragmentHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FragmentHandler.FRAGMENT_VALUE,
-            fragmentHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class,
-            fragmentHandler));
-
-        final FSIpv6FlowLabelHandler flowlabelHandler = new FSIpv6FlowLabelHandler();
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FlowLabelHandler.FLOW_LABEL_VALUE,
-            flowlabelHandler));
-        this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FlowLabelCase.class,
-            flowlabelHandler));
-    }
-
-    @Override
-    public void close() {
-        if (this.registrations != null) {
-            this.registrations.forEach(Registration::close);
-            this.registrations = null;
-        }
-    }
-}
index f864c2c7214ad3e404c442e75b7e97ec0233defe..2d8f5b62dc26b5421d5076cec83660b3187d156f 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Verify.verify;
 
 import java.util.Map;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv4.DestinationFlowspecIpv4;
@@ -31,10 +32,8 @@ public final class FlowspecIpv4RIBSupport
         FlowspecRoute,
         FlowspecRouteKey> {
     private static final FlowspecRoutes EMPTY_CONTAINER = new FlowspecRoutesBuilder().build();
-    private static FlowspecIpv4RIBSupport SINGLETON;
 
-    private FlowspecIpv4RIBSupport(final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
+    public FlowspecIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
         super(
                 mappingService,
                 FlowspecRoutesCase.class,
@@ -43,21 +42,10 @@ public final class FlowspecIpv4RIBSupport
                 Ipv4AddressFamily.class,
                 FlowspecSubsequentAddressFamily.class,
                 DestinationFlowspecIpv4.QNAME,
-                new SimpleFlowspecIpv4NlriParser(context
-                        .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
+                new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC)
         );
     }
 
-    static synchronized FlowspecIpv4RIBSupport getInstance(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
-        if (SINGLETON == null) {
-            SINGLETON = new FlowspecIpv4RIBSupport(context, mappingService);
-        }
-        return SINGLETON;
-    }
-
     @Override
     public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey key,
             final Attributes attributes) {
index d684a68f7c058b1c2c2db775259d712e52554260..a406afba0a625b14ad7b26863af2c7bf37e262cf 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Verify.verify;
 
 import java.util.Map;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6;
@@ -31,10 +32,8 @@ public final class FlowspecIpv6RIBSupport
         FlowspecRoute,
         FlowspecRouteKey> {
     private static final FlowspecIpv6Routes EMPTY_CONTAINER = new FlowspecIpv6RoutesBuilder().build();
-    private static FlowspecIpv6RIBSupport SINGLETON;
 
-    private FlowspecIpv6RIBSupport(final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
+    public FlowspecIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
         super(
                 mappingService,
                 FlowspecIpv6RoutesCase.class,
@@ -43,21 +42,10 @@ public final class FlowspecIpv6RIBSupport
                 Ipv6AddressFamily.class,
                 FlowspecSubsequentAddressFamily.class,
                 DestinationFlowspecIpv6.QNAME,
-                new SimpleFlowspecIpv6NlriParser(context
-                        .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC))
+                new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC)
         );
     }
 
-    static synchronized FlowspecIpv6RIBSupport getInstance(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
-        if (SINGLETON == null) {
-            SINGLETON = new FlowspecIpv6RIBSupport(context, mappingService);
-        }
-        return SINGLETON;
-    }
-
     @Override
     public FlowspecRoute createRoute(final FlowspecRoute route, final FlowspecRouteKey key,
             final Attributes attributes) {
diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistries.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistries.java
new file mode 100644 (file)
index 0000000..c02a9e2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.flowspec;
+
+public final class FlowspecTypeRegistries {
+    public enum AFI {
+        IPV4(),
+        IPV6(),
+    }
+
+    public enum SAFI {
+        FLOWSPEC,
+        FLOWSPEC_VPN,
+    }
+
+    private static final FlowspecTypeRegistry[][] FLOWSPEC_TYPE_REGISTRIES;
+
+    static {
+        final FlowspecTypeRegistry[][] regs = new FlowspecTypeRegistry[AFI.values().length][SAFI.values().length];
+        for (SAFI safi : SAFI.values()) {
+            regs[AFI.IPV4.ordinal()][safi.ordinal()] = new FlowspecTypeRegistryBuilder()
+                .registerIpv4FlowspecTypeHandlers().build();
+            regs[AFI.IPV6.ordinal()][safi.ordinal()] = new FlowspecTypeRegistryBuilder()
+                .registerIpv6FlowspecTypeHandlers().build();
+        }
+        FLOWSPEC_TYPE_REGISTRIES = regs;
+    }
+
+    private FlowspecTypeRegistries() {
+        // Hidden on purpose
+    }
+
+    public static FlowspecTypeRegistry getFlowspecTypeRegistry(final AFI afi, final SAFI safi) {
+        return FLOWSPEC_TYPE_REGISTRIES[afi.ordinal()][safi.ordinal()];
+    }
+}
similarity index 71%
rename from bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java
rename to bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistry.java
index ec0286b9fe91cbd5213078e276dd0e9ce6aea157..d6ed596b5dca7d897eefcb32a0b13f0e9fb5f67b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -14,19 +15,21 @@ import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.FlowspecType;
-import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
-public class SimpleFlowspecTypeRegistry {
-    private final HandlerRegistry<DataContainer, FlowspecTypeParser, FlowspecTypeSerializer> handlers =
-            new HandlerRegistry<>();
+public final class FlowspecTypeRegistry {
+    private final HandlerRegistry<DataContainer, FlowspecTypeParser, FlowspecTypeSerializer> handlers;
+
+    FlowspecTypeRegistry(final HandlerRegistry<DataContainer, FlowspecTypeParser, FlowspecTypeSerializer> handlers) {
+        this.handlers = requireNonNull(handlers);
+    }
 
     public FlowspecTypeParser getFlowspecTypeParser(final short type) {
-        return this.handlers.getParser(type);
+        return handlers.getParser(type);
     }
 
     public FlowspecTypeSerializer getFlowspecTypeSerializer(final FlowspecType fsType) {
-        return this.handlers.getSerializer(fsType.implementedInterface());
+        return handlers.getSerializer(fsType.implementedInterface());
     }
 
     public void serializeFlowspecType(final FlowspecType fsType, final ByteBuf output) {
@@ -41,13 +44,4 @@ public class SimpleFlowspecTypeRegistry {
         requireNonNull(parser, "parser for flowspec type " + type + " is not registered");
         return parser.parseType(buffer);
     }
-
-    public Registration registerFlowspecTypeParser(final int type, final FlowspecTypeParser parser) {
-        return this.handlers.registerParser(type, parser);
-    }
-
-    public Registration registerFlowspecTypeSerializer(final Class<? extends FlowspecType> typeClass,
-            final FlowspecTypeSerializer serializer) {
-        return this.handlers.registerSerializer(typeClass, serializer);
-    }
 }
diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistryBuilder.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecTypeRegistryBuilder.java
new file mode 100644 (file)
index 0000000..e90d812
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.flowspec;
+
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4DestinationPrefixHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4FragmentHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4SourcePrefixHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6DestinationPrefixHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6FragmentHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
+import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
+import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.FlowspecType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.DscpCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.FragmentCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.PortCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.FlowLabelCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+final class FlowspecTypeRegistryBuilder implements Builder<FlowspecTypeRegistry> {
+    private final HandlerRegistry<DataContainer, FlowspecTypeParser, FlowspecTypeSerializer> handlers =
+        new HandlerRegistry<>();
+
+    FlowspecTypeRegistryBuilder() {
+        final FSPortHandler portHandler = new FSPortHandler();
+        registerFlowspecTypeParser(FSPortHandler.PORT_VALUE, portHandler);
+        registerFlowspecTypeSerializer(PortCase.class, portHandler);
+
+        final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler();
+        registerFlowspecTypeParser(FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler);
+        registerFlowspecTypeSerializer(DestinationPortCase.class, destinationPortHandler);
+
+        final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler();
+        registerFlowspecTypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE, sourcePortHandler);
+        registerFlowspecTypeSerializer(SourcePortCase.class, sourcePortHandler);
+
+        final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler();
+        registerFlowspecTypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE, icmpTypeHandler);
+        registerFlowspecTypeSerializer(IcmpTypeCase.class, icmpTypeHandler);
+
+        final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler();
+        registerFlowspecTypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE, icmpCodeHandler);
+        registerFlowspecTypeSerializer(IcmpCodeCase.class, icmpCodeHandler);
+
+        final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler();
+        registerFlowspecTypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE, tcpFlagsHandler);
+        registerFlowspecTypeSerializer(TcpFlagsCase.class, tcpFlagsHandler);
+
+        final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler();
+        registerFlowspecTypeParser(FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler);
+        registerFlowspecTypeSerializer(PacketLengthCase.class, packetlengthHandler);
+
+        final FSDscpHandler dscpHandler = new FSDscpHandler();
+        registerFlowspecTypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler);
+        registerFlowspecTypeSerializer(DscpCase.class, dscpHandler);
+    }
+
+    FlowspecTypeRegistryBuilder registerIpv4FlowspecTypeHandlers() {
+        final FSIpv4DestinationPrefixHandler destinationPrefixHandler = new FSIpv4DestinationPrefixHandler();
+        registerFlowspecTypeParser(FSIpv4DestinationPrefixHandler.DESTINATION_PREFIX_VALUE, destinationPrefixHandler);
+        registerFlowspecTypeSerializer(DestinationPrefixCase.class, destinationPrefixHandler);
+
+        final FSIpv4SourcePrefixHandler sourcePrefixHandler = new FSIpv4SourcePrefixHandler();
+        registerFlowspecTypeParser(FSIpv4SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler);
+        registerFlowspecTypeSerializer(SourcePrefixCase.class, sourcePrefixHandler);
+
+        final FSIpProtocolHandler ipProtocolHandler = new FSIpProtocolHandler();
+        registerFlowspecTypeParser(FSIpProtocolHandler.IP_PROTOCOL_VALUE, ipProtocolHandler);
+        registerFlowspecTypeSerializer(ProtocolIpCase.class, ipProtocolHandler);
+
+        final FSIpv4FragmentHandler fragmentHandler = new FSIpv4FragmentHandler();
+        registerFlowspecTypeParser(FSIpv4FragmentHandler.FRAGMENT_VALUE, fragmentHandler);
+        registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler);
+        return this;
+    }
+
+    FlowspecTypeRegistryBuilder registerIpv6FlowspecTypeHandlers() {
+        final FSIpv6DestinationPrefixHandler destinationPrefixHandler = new FSIpv6DestinationPrefixHandler();
+        registerFlowspecTypeParser(FSIpv6DestinationPrefixHandler.IPV6_DESTINATION_PREFIX_VALUE,
+            destinationPrefixHandler);
+        registerFlowspecTypeSerializer(DestinationIpv6PrefixCase.class, destinationPrefixHandler);
+
+        final FSIpv6SourcePrefixHandler sourcePrefixHandler = new FSIpv6SourcePrefixHandler();
+        registerFlowspecTypeParser(FSIpv6SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler);
+        registerFlowspecTypeSerializer(SourceIpv6PrefixCase.class, sourcePrefixHandler);
+
+        final FSIpv6NextHeaderHandler nextHeaderHandler = new FSIpv6NextHeaderHandler();
+        registerFlowspecTypeParser(FSIpv6NextHeaderHandler.NEXT_HEADER_VALUE, nextHeaderHandler);
+        registerFlowspecTypeSerializer(NextHeaderCase.class, nextHeaderHandler);
+
+        final FSIpv6FragmentHandler fragmentHandler = new FSIpv6FragmentHandler();
+        registerFlowspecTypeParser(FSIpv6FragmentHandler.FRAGMENT_VALUE, fragmentHandler);
+        registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler);
+
+        final FSIpv6FlowLabelHandler flowlabelHandler = new FSIpv6FlowLabelHandler();
+        registerFlowspecTypeParser(FSIpv6FlowLabelHandler.FLOW_LABEL_VALUE, flowlabelHandler);
+        registerFlowspecTypeSerializer(FlowLabelCase.class, flowlabelHandler);
+        return this;
+    }
+
+    @Override
+    public FlowspecTypeRegistry build() {
+        return new FlowspecTypeRegistry(handlers);
+    }
+
+    private Registration registerFlowspecTypeParser(final int type, final FlowspecTypeParser parser) {
+        return handlers.registerParser(type, parser);
+    }
+
+    private Registration registerFlowspecTypeSerializer(final Class<? extends FlowspecType> typeClass,
+            final FlowspecTypeSerializer serializer) {
+        return handlers.registerSerializer(typeClass, serializer);
+    }
+}
index 3e0280492753d32e70d5dceb5e08e5305d628882..d3b2d86ea2f1cf778aec2d1097e498efffade353 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.protocol.bgp.flowspec;
 
 import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.kohsuke.MetaInfServices;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4RIBSupport;
@@ -20,14 +22,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Component;
 
+@Singleton
+@Component(immediate = true, service = RIBExtensionProviderActivator.class,
+           property = "type=org.opendaylight.protocol.bgp.flowspec.RIBActivator")
 @MetaInfServices(value = RIBExtensionProviderActivator.class)
 public final class RIBActivator extends AbstractRIBExtensionProviderActivator {
-    private final SimpleFlowspecExtensionProviderContext fsContext;
-
-    // FIXME: this requires proper injection
-    public RIBActivator(final SimpleFlowspecExtensionProviderContext context) {
-        this.fsContext = context;
+    @Inject
+    public RIBActivator() {
+        // Exposed for DI
     }
 
     @Override
@@ -35,12 +39,12 @@ public final class RIBActivator extends AbstractRIBExtensionProviderActivator {
             final BindingNormalizedNodeSerializer mappingService) {
         return List.of(
             context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
-                FlowspecIpv4RIBSupport.getInstance(this.fsContext, mappingService)),
+                new FlowspecIpv4RIBSupport(mappingService)),
             context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class,
-                FlowspecIpv6RIBSupport.getInstance(this.fsContext, mappingService)),
+                new FlowspecIpv6RIBSupport(mappingService)),
             context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
-                FlowspecL3vpnIpv4RIBSupport.getInstance(this.fsContext, mappingService)),
+                new FlowspecL3vpnIpv4RIBSupport(mappingService)),
             context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
-                FlowspecL3vpnIpv6RIBSupport.getInstance(this.fsContext, mappingService)));
+                new FlowspecL3vpnIpv6RIBSupport(mappingService)));
     }
 }
diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java
deleted file mode 100644 (file)
index 76e8edb..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.flowspec;
-
-public class SimpleFlowspecExtensionProviderContext {
-    public enum AFI {
-        IPV4(0),
-        IPV6(1);
-
-        public final int index;
-
-        AFI(int index) {
-            this.index = index;
-        }
-    }
-
-    public enum SAFI {
-        FLOWSPEC(0),
-        FLOWSPEC_VPN(1);
-
-        public final int index;
-
-        SAFI(int index) {
-            this.index = index;
-        }
-    }
-
-    private final SimpleFlowspecTypeRegistry[][] flowspecTypeRegistries = new SimpleFlowspecTypeRegistry[2][2];
-
-    public SimpleFlowspecExtensionProviderContext() {
-        for (AFI afi : AFI.values()) {
-            for (SAFI safi : SAFI.values()) {
-                this.flowspecTypeRegistries[afi.index][safi.index] = new SimpleFlowspecTypeRegistry();
-            }
-        }
-    }
-
-    public SimpleFlowspecTypeRegistry getFlowspecTypeRegistry(AFI afi, SAFI safi) {
-        return this.flowspecTypeRegistries[afi.index][safi.index];
-    }
-}
index 8c44fd4caa4b7e334665a9793d3c4e176c31427c..6eeaa891d73091f5cddf16def08a2c568ccb506d 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.protocol.bgp.flowspec;
 
 import io.netty.buffer.ByteBuf;
 import java.util.List;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.AFI;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.ipv4.FlowspecIpv4NlriParserHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
@@ -20,9 +22,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 
 public final class SimpleFlowspecIpv4NlriParser extends AbstractFlowspecNlriParser {
-
-    public SimpleFlowspecIpv4NlriParser(final SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
-        super(flowspecTypeRegistry);
+    public SimpleFlowspecIpv4NlriParser(final SAFI safi) {
+        super(FlowspecTypeRegistries.getFlowspecTypeRegistry(AFI.IPV4, safi));
     }
 
     @Override
index 997cefbddb8ade796f38d812a1f1d155cf4ba2e3..0787efab6ad86ae4843742bf75fb08b154923cac 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.protocol.bgp.flowspec;
 
 import io.netty.buffer.ByteBuf;
 import java.util.List;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.AFI;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.ipv6.FlowspecIpv6NlriParserHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
@@ -20,9 +22,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 
 public final class SimpleFlowspecIpv6NlriParser extends AbstractFlowspecNlriParser {
-
-    public SimpleFlowspecIpv6NlriParser(final SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
-        super(flowspecTypeRegistry);
+    public SimpleFlowspecIpv6NlriParser(final SAFI safi) {
+        super(FlowspecTypeRegistries.getFlowspecTypeRegistry(AFI.IPV6, safi));
     }
 
     @Override
index bea3b85bb761e5e0dcafdf895173ab3f2be99a80..3bb9e3ecfc1c09ad9156910a3dda4d6c9063a472 100644 (file)
@@ -15,7 +15,7 @@ import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecNlriParser;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
@@ -30,7 +30,7 @@ public abstract class AbstractFlowspecL3vpnNlriParser extends AbstractFlowspecNl
     public static final NodeIdentifier RD_NID = new NodeIdentifier(QName.create(Flowspec.QNAME.getModule(),
             "route-distinguisher"));
 
-    protected AbstractFlowspecL3vpnNlriParser(final SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
+    protected AbstractFlowspecL3vpnNlriParser(final FlowspecTypeRegistry flowspecTypeRegistry) {
         super(flowspecTypeRegistry);
     }
 
index 4949bbe8d9c6fee3c1cfa11f5029796e06ba24b5..a1970bef7895a4a1aec8c83d5e6290d67ad335c7 100644 (file)
@@ -9,7 +9,9 @@ package org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4;
 
 import io.netty.buffer.ByteBuf;
 import java.util.List;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.AFI;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.ipv4.FlowspecIpv4NlriParserHelper;
 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnNlriParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
@@ -28,9 +30,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
  * @author Kevin Wang
  */
 public final class FlowspecL3vpnIpv4NlriParser extends AbstractFlowspecL3vpnNlriParser {
-
-    public FlowspecL3vpnIpv4NlriParser(SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
-        super(flowspecTypeRegistry);
+    public FlowspecL3vpnIpv4NlriParser(final SAFI safi) {
+        super(FlowspecTypeRegistries.getFlowspecTypeRegistry(AFI.IPV4, safi));
     }
 
     @Override
index abb97281bef3fe1019ca6745df41559c7ae2b35e..b41cf43bddd5b9b8704dd457cc772108ebc646da 100644 (file)
@@ -11,7 +11,7 @@ import static com.google.common.base.Verify.verify;
 
 import java.util.Map;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4;
@@ -32,11 +32,8 @@ public final class FlowspecL3vpnIpv4RIBSupport
         FlowspecL3vpnRoute,
         FlowspecL3vpnRouteKey> {
     private static final FlowspecL3vpnIpv4Routes EMPTY_CONTAINER = new FlowspecL3vpnIpv4RoutesBuilder().build();
-    private static FlowspecL3vpnIpv4RIBSupport SINGLETON;
 
-    private FlowspecL3vpnIpv4RIBSupport(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
+    public FlowspecL3vpnIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
         super(
                 mappingService,
                 FlowspecL3vpnIpv4RoutesCase.class,
@@ -44,21 +41,10 @@ public final class FlowspecL3vpnIpv4RIBSupport
                 FlowspecL3vpnRoute.class,
                 DestinationFlowspecL3vpnIpv4.QNAME,
                 Ipv4AddressFamily.class,
-                new FlowspecL3vpnIpv4NlriParser(context
-                        .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
+                new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN)
         );
     }
 
-    public static synchronized FlowspecL3vpnIpv4RIBSupport getInstance(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
-        if (SINGLETON == null) {
-            SINGLETON = new FlowspecL3vpnIpv4RIBSupport(context, mappingService);
-        }
-        return SINGLETON;
-    }
-
     @Override
     public FlowspecL3vpnRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
         return new FlowspecL3vpnRouteKey(pathId, routeKey);
index 949382f053578d1237d506d7125afc1d2ba99dac..08950859ce77a6c1e48c5e9a2fe0da6c48eb9b54 100644 (file)
@@ -9,7 +9,9 @@ package org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6;
 
 import io.netty.buffer.ByteBuf;
 import java.util.List;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.AFI;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.ipv6.FlowspecIpv6NlriParserHelper;
 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnNlriParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
@@ -28,9 +30,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
  * @author Kevin Wang
  */
 public final class FlowspecL3vpnIpv6NlriParser extends AbstractFlowspecL3vpnNlriParser {
-
-    public FlowspecL3vpnIpv6NlriParser(SimpleFlowspecTypeRegistry flowspecTypeRegistry) {
-        super(flowspecTypeRegistry);
+    public FlowspecL3vpnIpv6NlriParser(final SAFI safi) {
+        super(FlowspecTypeRegistries.getFlowspecTypeRegistry(AFI.IPV6, safi));
     }
 
     @Override
index 7a4adbf3f040cbdd15b97bda91d438f9f26c0021..ef469018b6a38a0d602695331e2bc4b1a6326fc1 100644 (file)
@@ -11,7 +11,7 @@ import static com.google.common.base.Verify.verify;
 
 import java.util.Map;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6;
@@ -32,11 +32,8 @@ public final class FlowspecL3vpnIpv6RIBSupport
         FlowspecL3vpnRoute,
         FlowspecL3vpnRouteKey> {
     private static final FlowspecL3vpnIpv6Routes EMPTY_CONTAINER = new FlowspecL3vpnIpv6RoutesBuilder().build();
-    private static FlowspecL3vpnIpv6RIBSupport SINGLETON;
 
-    private FlowspecL3vpnIpv6RIBSupport(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
+    public FlowspecL3vpnIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
         super(
                 mappingService,
                 FlowspecL3vpnIpv6RoutesCase.class,
@@ -44,21 +41,10 @@ public final class FlowspecL3vpnIpv6RIBSupport
                 FlowspecL3vpnRoute.class,
                 DestinationFlowspecL3vpnIpv6.QNAME,
                 Ipv6AddressFamily.class,
-                new FlowspecL3vpnIpv6NlriParser(context
-                        .getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-                                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN))
+                new FlowspecL3vpnIpv6NlriParser(SAFI.FLOWSPEC_VPN)
         );
     }
 
-    public static synchronized FlowspecL3vpnIpv6RIBSupport getInstance(
-            final SimpleFlowspecExtensionProviderContext context,
-            final BindingNormalizedNodeSerializer mappingService) {
-        if (SINGLETON == null) {
-            SINGLETON = new FlowspecL3vpnIpv6RIBSupport(context, mappingService);
-        }
-        return SINGLETON;
-    }
-
     @Override
     public FlowspecL3vpnRouteKey createRouteListKey(final PathId pathId, final String routeKey) {
         return new FlowspecL3vpnRouteKey(pathId, routeKey);
diff --git a/bgp/extensions/flowspec/src/main/resources/OSGI-INF/blueprint/bgp-flowspec.xml b/bgp/extensions/flowspec/src/main/resources/OSGI-INF/blueprint/bgp-flowspec.xml
deleted file mode 100644 (file)
index 4f1c465..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
-
-  This program and the accompanying materials are made available under the
-  terms of the Eclipse Public License v1.0 which accompanies this distribution,
-  and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
-
-  <bean id="flowSpecExtensionContext" class="org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext"/>
-
-  <bean id="flowSpecActivator" class="org.opendaylight.protocol.bgp.flowspec.FlowspecActivator">
-    <argument ref="flowSpecExtensionContext"/>
-  </bean>
-
-  <bean id="BGPActivator" class="org.opendaylight.protocol.bgp.flowspec.BGPActivator">
-    <argument ref="flowSpecActivator"/>
-  </bean>
-
-  <bean id="RIBActivator" class="org.opendaylight.protocol.bgp.flowspec.RIBActivator">
-    <argument ref="flowSpecExtensionContext"/>
-  </bean>
-
-  <service ref="BGPActivator" interface="org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator"
-          odl:type="org.opendaylight.protocol.bgp.flowspec.BGPActivator"/>
-
-  <service ref="RIBActivator" interface="org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator"
-          odl:type="org.opendaylight.protocol.bgp.flowspec.RIBActivator"/>
-</blueprint>
index 1859a4efa72d67d91e530c8b85d7ef8d0441573a..b9f40444a0df88ccd5e6324119472a3782d9466e 100644 (file)
@@ -22,9 +22,7 @@ public class ActivatorTest {
 
     @Test
     public void testActivator() throws Exception {
-        final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
-        final FlowspecActivator activator = new FlowspecActivator(fsContext);
-        final BGPActivator act = new BGPActivator(activator);
+        final BGPActivator act = new BGPActivator();
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(FLOWSPEC_SAFI));
         assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(FLOWSPEC_VPN_SAFI));
index bf039ffd87be7f4bf49e0b950fe5c482f9627fbc..449af5d77da12d53273504f454712f290d90e98d 100644 (file)
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
@@ -77,16 +78,12 @@ public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest<FlowspecR
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
-        final FlowspecActivator activator = new FlowspecActivator(fsContext);
-        final BGPActivator act = new BGPActivator(activator);
+        final BGPActivator act = new BGPActivator();
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         act.start(context);
-        this.ribSupport = FlowspecIpv4RIBSupport.getInstance(fsContext, this.adapter.currentSerializer());
+        this.ribSupport = new FlowspecIpv4RIBSupport(this.adapter.currentSerializer());
 
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-                fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                        SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
         this.route = new FlowspecRouteBuilder().withKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
index c69bf10883ffce1f3b18407f3deea28a42e82f88..f8943854ef117869d1b51951ce59557240e4d844 100644 (file)
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
@@ -76,20 +77,16 @@ public class FlowspecIpv6RIBSupportTest extends AbstractRIBSupportTest<FlowspecI
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
-        final FlowspecActivator activator = new FlowspecActivator(fsContext);
-        final BGPActivator act = new BGPActivator(activator);
+        final BGPActivator act = new BGPActivator();
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         act.start(context);
 
-        final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser(
-                fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                        SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC);
         this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST));
         this.route = new FlowspecRouteBuilder().withKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST)
                 .setAttributes(new AttributesBuilder().build()).build();
         this.routes = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Map.of(this.route.key(), this.route)).build();
-        this.ribSupport = FlowspecIpv6RIBSupport.getInstance(fsContext, this.adapter.currentSerializer());
+        this.ribSupport = new FlowspecIpv6RIBSupport(this.adapter.currentSerializer());
         setUpTestCustomizer(this.ribSupport);
     }
 
index c3b64688839acb656a885417115b755cd73cdebc..e29adac1f3710df77d12be1e94483383eb7d56f2 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
@@ -166,11 +167,7 @@ public class FlowspecL3vpnIpv4NlriParserTest {
         0x0c, (byte) 0x81, (byte) 0x0e
     };
 
-    private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
-    private final FlowspecActivator fsa = new FlowspecActivator(this.flowspecContext);
-    private final FlowspecL3vpnIpv4NlriParser fsParser = new FlowspecL3vpnIpv4NlriParser(
-        this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-            SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+    private final FlowspecL3vpnIpv4NlriParser fsParser = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
 
     @Before
     public void setUp() {
@@ -209,9 +206,7 @@ public class FlowspecL3vpnIpv4NlriParserTest {
         builder.setFlowspecType(sps);
         fs.add(builder.build());
 
-        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
 
         final MpReachNlriBuilder result = new MpReachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -326,9 +321,7 @@ public class FlowspecL3vpnIpv4NlriParserTest {
         builder.setFlowspecType(sps);
         fs.add(builder.build());
 
-        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
 
         final MpReachNlriBuilder result = new MpReachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -415,9 +408,7 @@ public class FlowspecL3vpnIpv4NlriParserTest {
         builder.setFlowspecType(fragment);
         fs.add(builder.build());
 
-        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
 
         final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -549,9 +540,7 @@ public class FlowspecL3vpnIpv4NlriParserTest {
         builder.setFlowspecType(fragment);
         fs.add(builder.build());
 
-        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
+        final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
 
         final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
index e74f115293101d14c6d5137c5e450ba0c925ffeb..3821c9ab11d5240b14838e9d05b55ac3cf15cc39 100644 (file)
@@ -85,8 +85,7 @@ public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest<Flow
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        this.ribSupport = FlowspecL3vpnIpv4RIBSupport
-                .getInstance(new SimpleFlowspecExtensionProviderContext(), this.adapter.currentSerializer());
+        this.ribSupport = new FlowspecL3vpnIpv4RIBSupport(this.adapter.currentSerializer());
         setUpTestCustomizer(this.ribSupport);
     }
 
index 4af5209def664e0b7486013140384ab8d02c1f30..fd1d0a11466194161d073db2922425ba278bbeaa 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
@@ -86,11 +87,7 @@ public class FlowspecL3vpnIpv6NlriParserTest {
     private PeerSpecificParserConstraint constraint;
     @Mock
     private MultiPathSupport muliPathSupport;
-    private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
-    private final FlowspecActivator fsa = new FlowspecActivator(this.flowspecContext);
-    private final FlowspecL3vpnIpv6NlriParser fsParser = new FlowspecL3vpnIpv6NlriParser(
-        this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-            SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+    private final FlowspecL3vpnIpv6NlriParser fsParser = new FlowspecL3vpnIpv6NlriParser(SAFI.FLOWSPEC);
 
     private static final byte[] REACHED_NLRI = new byte[]{
         0x1B,   // NLRI length: 19+8=27
index f5d0974c0e172b46c9509fb5658c0a627d6fbe4e..283cc211f0be487ec97e1c05aee0e05bdd6a5027 100644 (file)
@@ -85,8 +85,7 @@ public class FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest<Flow
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        this.ribSupport = FlowspecL3vpnIpv6RIBSupport
-                .getInstance(new SimpleFlowspecExtensionProviderContext(), this.adapter.currentSerializer());
+        this.ribSupport = new FlowspecL3vpnIpv6RIBSupport(this.adapter.currentSerializer());
         setUpTestCustomizer(this.ribSupport);
     }
 
index 6093ad338dc6b0a1af5d5f4ec6e883588f7dae96..442015918085a6a6463ae4781588b5f55ba8ff7e 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
@@ -159,11 +160,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
         0x0c, (byte) 0x81, (byte) 0x0e
     };
 
-    private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
-    private final FlowspecActivator fsa = new FlowspecActivator(this.flowspecContext);
-    private final SimpleFlowspecIpv4NlriParser fsParser = new SimpleFlowspecIpv4NlriParser(
-        flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-            SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+    private final SimpleFlowspecIpv4NlriParser fsParser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
     @Before
     public void setUp() {
@@ -208,9 +205,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
             .setDestinationFlowspecIpv4(new DestinationFlowspecIpv4Builder().setFlowspec(fs).build())
             .build()).build());
 
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         final MpReachNlriBuilder result = new MpReachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -312,9 +307,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
             ).build()
         );
 
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         final MpReachNlriBuilder result = new MpReachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -395,9 +388,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
             ).build()
         );
 
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -530,9 +521,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
             ).build()
         );
 
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
@@ -944,9 +933,7 @@ public class SimpleFlowspecIpv4NlriParserTest {
 
     @Test
     public void testBatchedFlowspecNlri() throws Exception {
-        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(
-            flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
-                SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+        final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
 
         final MpReachNlriBuilder result = new MpReachNlriBuilder();
         result.setAfi(Ipv4AddressFamily.class);
index 6e33f8b43adbad2d4638944374da61ae53866ee0..077c593a3d1d99887ac0a6c85d268a05ec9539c2 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
@@ -82,11 +83,7 @@ public class SimpleFlowspecIpv6NlriParserTest {
     private PeerSpecificParserConstraint constraint;
     @Mock
     private MultiPathSupport muliPathSupport;
-    private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
-    private final FlowspecActivator fsa = new FlowspecActivator(this.flowspecContext);
-    private final SimpleFlowspecIpv6NlriParser fsParser = new SimpleFlowspecIpv6NlriParser(
-        this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
-            SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
+    private final SimpleFlowspecIpv6NlriParser fsParser = new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC);
 
     private static final byte[] REACHED_NLRI = new byte[] {
         0x13,
index 23bb040d1fc2f47b72a8a35a9e459dcf4ae26fa4..d149e2bc98795ba0e92d31d3a9835ee3b8c3d684 100644 (file)
@@ -15,8 +15,6 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.flowspec.BGPActivator;
-import org.opendaylight.protocol.bgp.flowspec.FlowspecActivator;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
@@ -84,10 +82,7 @@ public class FSExtendedCommunitiesTest {
 
     @Before
     public void setUp() throws Exception {
-        final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
-        final FlowspecActivator activator = new FlowspecActivator(fsContext);
-
-        this.act = new BGPActivator(activator);
+        this.act = new BGPActivator();
         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
         this.act.start(context);
         this.registry = context.getExtendedCommunityRegistry();
index 021245458e2ff1bde1909bf1ad6c4834caca1952..4b7fdf8f159ca8668465496a10c492d6cc280fbc 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.testtool;
 
 import static org.opendaylight.protocol.bgp.testtool.BGPPeerBuilder.createPeer;
@@ -19,8 +18,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import org.opendaylight.protocol.bgp.flowspec.FlowspecActivator;
-import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
@@ -102,10 +99,8 @@ final class BGPTestTool {
                 .evpn.impl.BGPActivator();
         evpnActivator.start(ctx);
 
-        final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
-        final FlowspecActivator flowspecActivator = new FlowspecActivator(fsContext);
         final org.opendaylight.protocol.bgp.flowspec.BGPActivator flowspecBGPActivator
-                = new org.opendaylight.protocol.bgp.flowspec.BGPActivator(flowspecActivator);
+                = new org.opendaylight.protocol.bgp.flowspec.BGPActivator();
         flowspecBGPActivator.start(ctx);
 
         final org.opendaylight.protocol.bgp.labeled.unicast.BGPActivator labeledActivator