<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>
+++ /dev/null
-/*
- * 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();
- }
-}
--- /dev/null
+/*
+ * 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();
+ }
+}
+++ /dev/null
-<?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
+++ /dev/null
-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
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());
}
}
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