Convert pcep-auto-bandwidth-extension to OSGi DS 48/104048/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 16 Jan 2023 20:59:49 +0000 (21:59 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 16 Jan 2023 22:36:18 +0000 (23:36 +0100)
This is an experimenter option, this patch brings persistence out of the
picture and shifts configuration to OSGi DS (or whatever else external).

JIRA: BGPCEP-1018
Change-Id: I122d5a9c41c78b5ac8523bc4a1d5ed54d7b166b3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/auto-bandwidth-extension/pom.xml
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/Activator.java [deleted file]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/AutoBandwidthActivator.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/resources/OSGI-INF/blueprint/pcep-auto-bandwidth.xml [deleted file]
pcep/auto-bandwidth-extension/src/main/yang/pcep-auto-bandwidth-app-config.yang [deleted file]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/AutoBandwidthActivatorTest.java [moved from pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/ActivatorTest.java with 80% similarity]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodecTest.java

index 99d0ca4f3c44d9c1f4d52c817715f3c65d69bb30..db94adfd93f4388bf961b905ce2533920aa6e21b 100644 (file)
             <groupId>${project.groupId}</groupId>
             <artifactId>pcep-ietf-stateful</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-buffer</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-common</artifactId>
             <artifactId>rfc6991-ietf-inet-types</artifactId>
         </dependency>
         <dependency>
-            <groupId>io.netty</groupId>
-            <artifactId>netty-buffer</artifactId>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
         </dependency>
         <dependency>
             <groupId>org.kohsuke.metainf-services</groupId>
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/Activator.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/Activator.java
deleted file mode 100644 (file)
index 1afbe94..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2016 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.pcep.auto.bandwidth.extension;
-
-import com.google.common.base.MoreObjects;
-import java.util.List;
-import org.kohsuke.MetaInfServices;
-import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
-import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Pcrpt;
-import org.opendaylight.yangtools.concepts.Registration;
-
-@MetaInfServices
-public class Activator implements PCEPExtensionProviderActivator {
-    private final int bandwidthUsageObjectType;
-
-    public Activator() {
-        this(5);
-    }
-
-    public Activator(final int bandwidthUsageObjectType) {
-        this.bandwidthUsageObjectType = bandwidthUsageObjectType;
-    }
-
-    @Override
-    public List<Registration> start(final PCEPExtensionProviderContext context) {
-        final BandwidthUsageObjectCodec bandwidthUsageObjectCodec =
-                new BandwidthUsageObjectCodec(bandwidthUsageObjectType);
-        final PcRptMessageCodec pcRptMessageCodec = new PcRptMessageCodec(context.getObjectHandlerRegistry());
-
-        return List.of(
-            context.registerObjectParser(bandwidthUsageObjectCodec),
-            context.registerObjectSerializer(BandwidthUsage.class, bandwidthUsageObjectCodec),
-            context.registerMessageParser(PcRptMessageCodec.TYPE, pcRptMessageCodec),
-            context.registerMessageSerializer(Pcrpt.class, pcRptMessageCodec));
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this).add("bandwithUsage", bandwidthUsageObjectType).toString();
-    }
-}
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/AutoBandwidthActivator.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/AutoBandwidthActivator.java
new file mode 100644 (file)
index 0000000..c99b29e
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2016 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.pcep.auto.bandwidth.extension;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.base.MoreObjects;
+import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.kohsuke.MetaInfServices;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Pcrpt;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@Singleton
+@MetaInfServices
+@Component(immediate = true)
+@Designate(ocd = AutoBandwidthActivator.Configuration.class)
+public class AutoBandwidthActivator implements PCEPExtensionProviderActivator {
+    /**
+     * This implementation is bound to
+     * <a href="https://datatracker.ietf.org/doc/html/draft-dhody-pce-stateful-pce-auto-bandwidth-06#section-8.4">
+     * draft-dhody-pce-stateful-pce-auto-bandwidth-06</a>. Since there may be varying success with experimenting with
+     * compatibility, the type we bind to is configurable via {@link #bandwidthObjectClass()}.
+     */
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition(min = "3", max = "15", description = "Object Class Value as per RFC5440")
+        byte bandwidthObjectClass() default DEFAULT_BANDWIDTH_OBJECT_TYPE;
+    }
+
+    /**
+     * {@code BANDWITH object} as per {@code draft-dhody-pce-stateful-pce-auto-bandwidth-06 section 8.4}.
+     */
+    private static final byte DEFAULT_BANDWIDTH_OBJECT_TYPE = 5;
+
+    private final int bandwidthObjectClass;
+
+    @Inject
+    public AutoBandwidthActivator() {
+        this(DEFAULT_BANDWIDTH_OBJECT_TYPE);
+    }
+
+    @Activate
+    public AutoBandwidthActivator(final Configuration config) {
+        this(config.bandwidthObjectClass());
+    }
+
+    public AutoBandwidthActivator(final byte bandwidthObjectType) {
+        checkArgument(bandwidthObjectType >= 3 && bandwidthObjectType <= 15,
+            "Object type %s is not in range [[3..15]]", bandwidthObjectType);
+        bandwidthObjectClass = bandwidthObjectType;
+    }
+
+    @Override
+    public List<Registration> start(final PCEPExtensionProviderContext context) {
+        final var bandwidthUsageObjectCodec = new BandwidthUsageObjectCodec(bandwidthObjectClass);
+        final var pcRptMessageCodec = new PcRptMessageCodec(context.getObjectHandlerRegistry());
+
+        return List.of(
+            context.registerObjectParser(bandwidthUsageObjectCodec),
+            context.registerObjectSerializer(BandwidthUsage.class, bandwidthUsageObjectCodec),
+            context.registerMessageParser(PcRptMessageCodec.TYPE, pcRptMessageCodec),
+            context.registerMessageSerializer(Pcrpt.class, pcRptMessageCodec));
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this).add("bandwithUsage", bandwidthObjectClass).toString();
+    }
+}
diff --git a/pcep/auto-bandwidth-extension/src/main/resources/OSGI-INF/blueprint/pcep-auto-bandwidth.xml b/pcep/auto-bandwidth-extension/src/main/resources/OSGI-INF/blueprint/pcep-auto-bandwidth.xml
deleted file mode 100644 (file)
index 198a481..0000000
+++ /dev/null
@@ -1,23 +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">
-
-  <odl:clustered-app-config id="autoBandwidthAppConfig"
-      binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.app.config.rev160707.PcepAutoBandwidthAppConfig"/>
-
-  <bean id="autoBandwidthActivator" class="org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator">
-    <argument>
-      <bean factory-ref="autoBandwidthAppConfig" factory-method="getBandwidthUsageObjectType"/>
-    </argument>
-  </bean>
-
-  <service ref="autoBandwidthActivator" interface="org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator"
-          odl:type="org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator"/>
-</blueprint>
\ No newline at end of file
diff --git a/pcep/auto-bandwidth-extension/src/main/yang/pcep-auto-bandwidth-app-config.yang b/pcep/auto-bandwidth-extension/src/main/yang/pcep-auto-bandwidth-app-config.yang
deleted file mode 100644 (file)
index f15c0dc..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-module pcep-auto-bandwidth-app-config {
-    yang-version 1;
-    namespace "urn:opendaylight:params:xml:ns:yang:controller:pcep:auto-bandwidth-app-config";
-    prefix "pcep-auto-bandwidth-app-config";
-
-    description
-      "Configuration for the PCEP auto bandwidth extension.";
-
-    revision "2016-07-07" {
-        description
-            "Initial revision.
-
-            Copyright (c) 2016 Brocade Communications Systems, Inc. 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";
-    }
-
-    container pcep-auto-bandwidth-app-config {
-        leaf bandwidth-usage-object-type {
-            type uint16 {
-                range "3..15";
-            }
-
-            default 5;
-        }
-    }
-}
\ No newline at end of file
@@ -9,14 +9,13 @@ package org.opendaylight.protocol.pcep.auto.bandwidth.extension;
 
 import static org.junit.Assert.assertEquals;
 
-import java.util.List;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
 
-public class ActivatorTest {
+public class AutoBandwidthActivatorTest {
     @Test
     public void testStartImplPCEPExtensionProviderContext() {
-        final List<?> registrations = new Activator().start(new SimplePCEPExtensionProviderContext());
+        final var registrations = new AutoBandwidthActivator().start(new SimplePCEPExtensionProviderContext());
         assertEquals(4, registrations.size());
     }
 }
index 178f1465315808762689535a0a3db4353ef8e735..e6e878030761805c91b65327ba7148dc881ceac6 100644 (file)
@@ -61,7 +61,7 @@ public class PcRptMessageCodecTest {
     public void setUp() {
         new BaseParserExtensionActivator().start(ctx);
         new StatefulActivator().start(ctx);
-        new org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator().start(ctx);
+        new org.opendaylight.protocol.pcep.auto.bandwidth.extension.AutoBandwidthActivator().start(ctx);
     }
 
     @Test