Bug 4921 - Support Bandwidth Usage object 00/33100/2
authorMilos Fabian <milfabia@cisco.com>
Mon, 11 Jan 2016 01:10:52 +0000 (02:10 +0100)
committerMilos Fabian <milfabia@cisco.com>
Wed, 20 Jan 2016 14:20:34 +0000 (14:20 +0000)
Support Bandwidth-Usage object as defined in
https://tools.ietf.org/html/draft-dhody-pce-stateful-pce-auto-bandwidth-06#section-5.3.2
The object is used in PcRpt message report the real-time
bandwidth usage of a TE LSP.
Make object-type configurable, since no codepoint is assigned by IANA.
By default object-type=5.

Change-Id: I8aacf86cee3f647ad47a0dc01a861b16f89a62c5
Signed-off-by: Milos Fabian <milfabia@cisco.com>
(cherry picked from commit 5bd37a2832c88475435300ffe46836cb895309c4)

18 files changed:
artifacts/pom.xml
features/pcep/pom.xml
features/pcep/src/main/features/features.xml
pcep/auto-bandwidth-extension/pom.xml [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModule.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleFactory.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/Activator.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/BandwidthUsageObjectCodec.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodec.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth-cfg.yang [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth.yang [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleTest.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/ActivatorTest.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PCEPBandwidthUsageObjectCodecTest.java [new file with mode: 0644]
pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodecTest.java [new file with mode: 0644]
pcep/controller-config/pom.xml
pcep/controller-config/src/main/resources/initial/34-pcep-auto-bandwidth.xml [new file with mode: 0644]
pcep/pom.xml

index e019affe82f915bc235f19af8f12bfb762a43591..e28878d0dfd7efb03e3c5f790877a9571c701581 100644 (file)
                 <artifactId>pcep-tunnel-provider</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>pcep-auto-bandwidth-extension</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>pcep-controller-config</artifactId>
                 <type>xml</type>
                 <classifier>config-segment</classifier>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>pcep-controller-config</artifactId>
+                <version>${project.version}</version>
+                <type>xml</type>
+                <classifier>config-auto-bw</classifier>
+            </dependency>
 
             <dependency>
                 <groupId>${project.groupId}</groupId>
index 8dd6cb7b8bc42033638982dc25f52748af2511ba..c0ef6adf65932087e0f2510ffa37443bb5eb7a03 100644 (file)
           <type>xml</type>
           <classifier>config-segment</classifier>
       </dependency>
+      <dependency>
+          <groupId>${project.groupId}</groupId>
+          <artifactId>pcep-controller-config</artifactId>
+          <type>xml</type>
+          <classifier>config-auto-bw</classifier>
+      </dependency>
       <dependency>
           <groupId>${project.groupId}</groupId>
           <artifactId>pcep-controller-config</artifactId>
           <groupId>${project.groupId}</groupId>
           <artifactId>pcep-tunnel-provider</artifactId>
       </dependency>
+      <dependency>
+          <groupId>${project.groupId}</groupId>
+          <artifactId>pcep-auto-bandwidth-extension</artifactId>
+      </dependency>
       <dependency>
           <groupId>${project.groupId}</groupId>
           <artifactId>programming-api</artifactId>
index 426fa1c74246fafc9b20223b5256c054ffe8cb0b..490115f3f5713620e14b58b9e39dcd8596bdc5ef 100644 (file)
@@ -29,6 +29,7 @@
         <feature version='${project.version}'>odl-bgpcep-pcep-impl</feature>
         <feature version='${project.version}'>odl-bgpcep-pcep-stateful07</feature>
         <feature version='${project.version}'>odl-bgpcep-pcep-segment-routing</feature>
+        <feature version='${project.version}'>odl-bgpcep-pcep-auto-bandwidth</feature>
         <feature version='${project.version}'>odl-bgpcep-pcep-topology</feature>
         <feature version='${project.version}'>odl-bgpcep-pcep-topology-provider</feature>
         <feature version='${project.version}'>odl-bgpcep-pcep-tunnel-provider</feature>
         <bundle>mvn:org.opendaylight.bgpcep/pcep-segment-routing/{{VERSION}}</bundle>
         <configfile finalname="etc/opendaylight/karaf/33-pcep-segment-routing.xml">mvn:org.opendaylight.bgpcep/pcep-controller-config/{{VERSION}}/xml/config-segment</configfile>
     </feature>
+
+    <feature name='odl-bgpcep-pcep-auto-bandwidth' version='${project.version}'>
+        <feature version='${project.version}'>odl-bgpcep-pcep-stateful07</feature>
+        <bundle>mvn:org.opendaylight.bgpcep/pcep-auto-bandwidth-extension/{{VERSION}}</bundle>
+        <configfile finalname="etc/opendaylight/karaf/34-pcep-auto-bandwidth.xml">mvn:org.opendaylight.bgpcep/pcep-controller-config/{{VERSION}}/xml/config-auto-bw</configfile>
+    </feature>
 </features>
diff --git a/pcep/auto-bandwidth-extension/pom.xml b/pcep/auto-bandwidth-extension/pom.xml
new file mode 100644 (file)
index 0000000..c0ca9fb
--- /dev/null
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <scm>
+        <connection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</connection>
+        <developerConnection>scm:git:ssh://git.opendaylight.org:29418/bgpcep.git</developerConnection>
+        <url>https://wiki.opendaylight.org/view/BGP_LS_PCEP:Main</url>
+        <tag>HEAD</tag>
+    </scm>
+    <parent>
+        <groupId>org.opendaylight.bgpcep</groupId>
+        <artifactId>pcep-parent</artifactId>
+        <version>0.5.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>pcep-auto-bandwidth-extension</artifactId>
+    <description>PCE Auto Bandwidth Extension</description>
+    <packaging>bundle</packaging>
+    <name>${project.artifactId}</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>util</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>config-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>pcep-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>pcep-spi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>pcep-topology-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>pcep-impl</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>pcep-ietf-stateful07</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>ietf-topology</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-buffer</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+         <!--test dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModule.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModule.java
new file mode 100644 (file)
index 0000000..c320f73
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.controller.config.yang.pcep.auto.bandwidth.cfg;
+
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator;
+
+public class AutoBandwidthPCEPParserModule extends AbstractAutoBandwidthPCEPParserModule {
+
+    private static final int BW_TYPE_RANGE_LOW = 3;
+    private static final int BW_TYPE_RANGE_UP = 15;
+
+    public AutoBandwidthPCEPParserModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public AutoBandwidthPCEPParserModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver, final AutoBandwidthPCEPParserModule oldModule, final AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        //values 3-15 are unassigned - http://www.iana.org/assignments/pcep/pcep.xhtml#pcep-objects
+        JmxAttributeValidationException.checkCondition(getBandwidthUsageObjectType() >= BW_TYPE_RANGE_LOW &&
+                getBandwidthUsageObjectType() <= BW_TYPE_RANGE_UP, "out of range 3..15", bandwidthUsageObjectTypeJmxAttribute);
+    }
+
+    @Override
+    public AutoCloseable createInstance() {
+        return new Activator(getBandwidthUsageObjectType());
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleFactory.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleFactory.java
new file mode 100644 (file)
index 0000000..94d4ec5
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * 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.controller.config.yang.pcep.auto.bandwidth.cfg;
+
+public class AutoBandwidthPCEPParserModuleFactory extends AbstractAutoBandwidthPCEPParserModuleFactory {
+
+}
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
new file mode 100644 (file)
index 0000000..7123f30
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
+
+public class Activator extends AbstractPCEPExtensionProviderActivator {
+
+    private final int bandwidthUsageObjectType;
+
+    public Activator(final int bandwidthUsageObjectType) {
+        this.bandwidthUsageObjectType = bandwidthUsageObjectType;
+    }
+
+    @Override
+    protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
+        final List<AutoCloseable> regs = new ArrayList<>();
+
+        final BandwidthUsageObjectCodec bandwidthUsageObjectCodec = new BandwidthUsageObjectCodec(this.bandwidthUsageObjectType);
+        regs.add(context.registerObjectParser(BandwidthUsageObjectCodec.CLASS, bandwidthUsageObjectCodec.getType(), bandwidthUsageObjectCodec));
+        regs.add(context.registerObjectSerializer(BandwidthUsage.class, bandwidthUsageObjectCodec));
+
+        final PcRptMessageCodec pcRptMessageCodec = new PcRptMessageCodec(context.getObjectHandlerRegistry());
+        regs.add(context.registerMessageParser(PcRptMessageCodec.TYPE, pcRptMessageCodec));
+        regs.add(context.registerMessageSerializer(Pcrpt.class, pcRptMessageCodec));
+
+        return regs;
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/BandwidthUsageObjectCodec.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/BandwidthUsageObjectCodec.java
new file mode 100644 (file)
index 0000000..6adafad
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+
+public class BandwidthUsageObjectCodec implements ObjectParser, ObjectSerializer {
+
+    public static final int CLASS = 5;
+
+    private static final int BW_LENGTH = 4;
+
+    private final int type;
+
+    public BandwidthUsageObjectCodec(final int type) {
+        this.type = type;
+    }
+
+    @Override
+    public BandwidthUsage parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
+        Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+        if (bytes.readableBytes() % BW_LENGTH != 0) {
+            throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected multiple of "
+                    + BW_LENGTH + ".");
+        }
+        final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
+        builder.setIgnore(header.isIgnore());
+        builder.setProcessingRule(header.isProcessingRule());
+        final List<Bandwidth> bwSamples = new ArrayList<>(bytes.readableBytes() / BW_LENGTH);
+        while (bytes.isReadable()) {
+            bwSamples.add(new Bandwidth(ByteArray.readBytes(bytes, BW_LENGTH)));
+        }
+        builder.setBwSample(bwSamples);
+        return builder.build();
+    }
+
+    @Override
+    public void serializeObject(final Object object, final ByteBuf buffer) {
+        Preconditions.checkArgument(object instanceof BandwidthUsage, "Wrong instance of PCEPObject. Passed %s. Needed BandwidthUsage.", object.getClass());
+        final List<Bandwidth> bwSample = ((BandwidthUsage) object).getBwSample();
+        final ByteBuf body = Unpooled.buffer(bwSample.size() * BW_LENGTH);
+        for (final Bandwidth bw : bwSample) {
+            writeFloat32(bw, body);
+        }
+        ObjectUtil.formatSubobject(getType(), CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+    }
+
+    public int getType() {
+        return this.type;
+    }
+}
diff --git a/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodec.java b/pcep/auto-bandwidth-extension/src/main/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodec.java
new file mode 100644 (file)
index 0000000..d6f2044
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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.Optional;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+import io.netty.buffer.ByteBuf;
+import java.util.List;
+import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07PCReportMessageParser;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.Bandwidth1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.Bandwidth1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.ReportsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.Path;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
+
+public class PcRptMessageCodec extends Stateful07PCReportMessageParser {
+
+    public PcRptMessageCodec(final ObjectRegistry registry) {
+        super(registry);
+    }
+
+    @Override
+    protected Reports getValidReports(final List<Object> objects, final List<Message> errors) {
+        final Reports validReports = super.getValidReports(objects, errors);
+        final Optional<Object> find = Iterables.tryFind(objects, Predicates.instanceOf(BandwidthUsage.class));
+        final Path path = validReports.getPath();
+        if (find.isPresent() && path != null) {
+            final Object object = find.get();
+            objects.remove(object);
+            return new ReportsBuilder(validReports).setPath(new PathBuilder(path).setBandwidth(
+                    setBandwidthUsage(path.getBandwidth(), (BandwidthUsage) object)).build()).build();
+        }
+        return validReports;
+    }
+
+    @Override
+    protected void serializeObject(final Object object, final ByteBuf buffer) {
+        super.serializeObject(object, buffer);
+        if (object instanceof Bandwidth) {
+            final Bandwidth1 bw = ((Bandwidth) object).getAugmentation(Bandwidth1.class);
+            if (bw != null) {
+                super.serializeObject(new BandwidthUsageBuilder().setBwSample(bw.getBwSample()).build(), buffer);
+            }
+
+        }
+    }
+
+    private static Bandwidth setBandwidthUsage(final Bandwidth bandwidth, final BandwidthUsage bwUsage) {
+        final BandwidthBuilder bandwidthBuilder;
+        if (bandwidth != null) {
+            bandwidthBuilder = new BandwidthBuilder(bandwidth);
+        } else {
+            bandwidthBuilder = new BandwidthBuilder();
+        }
+        bandwidthBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(bwUsage.getBwSample()).build()).build();
+        return bandwidthBuilder.build();
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth-cfg.yang b/pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth-cfg.yang
new file mode 100644 (file)
index 0000000..c92bb09
--- /dev/null
@@ -0,0 +1,45 @@
+module odl-pcep-auto-bandwidth-cfg {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:pcep:auto:bandwidth:cfg";
+    prefix "auto-bw-cfg";
+
+    import config { prefix config; revision-date 2013-04-05; }
+    import odl-pcep-api-cfg { prefix pcep; revision-date 2013-04-09; }
+    import odl-pcep-spi-cfg { prefix spi; revision-date 2013-11-15; }
+
+    organization "Cisco Systems, Inc.";
+
+    contact "Milos Fabian <milfabia@cisco.com>";
+
+    description
+        "This module contains the base YANG definitions for
+         draft-ietf-pce-stateful-pce-07 extensions configuration.
+
+        Copyright (c)2016 Cisco 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";
+
+    revision 2016-01-09 {
+        description "Initial revision";
+    }
+
+    identity pcep-parser-auto-bandwidth {
+        base config:module-type;
+        config:provided-service spi:extension;
+        config:java-name-prefix AutoBandwidthPCEPParser;
+    }
+
+    augment "/config:modules/config:module/config:configuration" {
+        case pcep-parser-auto-bandwidth {
+            when "/config:modules/config:module/config:type = 'pcep-parser-auto-bandwidth'";
+            leaf bandwidth-usage-object-type {
+                type uint8;
+                default 5;
+            }
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth.yang b/pcep/auto-bandwidth-extension/src/main/yang/odl-pcep-auto-bandwidth.yang
new file mode 100644 (file)
index 0000000..76ebbe8
--- /dev/null
@@ -0,0 +1,55 @@
+module odl-pcep-auto-bandwidth {
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:pcep:auto:bandwidth";
+    prefix "auto-bw";
+
+    import pcep-types { prefix pcep; revision-date 2013-10-05; }
+    import pcep-message { prefix msg; revision-date 2013-10-07; }
+    import network-topology { prefix nt; revision-date 2013-10-21; }
+    import network-topology-pcep { prefix topo; revision-date 2013-10-24; }
+    import odl-pcep-ietf-stateful07 { prefix stateful; revision-date 2013-12-22; }
+    import network-concepts { prefix netc; revision-date 2013-11-25; }
+
+    organization "Cisco Systems, Inc.";
+    contact "Milos Fabian <milfabia@cisco.com>";
+
+    description
+        "This module contains the data model of PCEP extensions defined
+        in draft-dhody-pce-stateful-pce-auto-bandwidth-06.
+
+        Copyright (c)2016 Cisco 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";
+
+    revision 2016-01-09 {
+        description "Initial revision";
+        reference "https://tools.ietf.org/html/draft-dhody-pce-stateful-pce-auto-bandwidth-06";
+    }
+
+    grouping bw-samples {
+        leaf-list bw-sample {
+            type netc:bandwidth;
+            ordered-by user;
+        }
+    }
+
+    grouping bandwidth-usage-object {
+        description "Bandwidth-Usage Report Object";
+        reference "https://tools.ietf.org/html/draft-dhody-pce-stateful-pce-auto-bandwidth-06#section-8.4";
+        container bandwidth-usage {
+            uses pcep:object;
+            uses bw-samples;
+        }
+    }
+
+    augment "/stateful:pcrpt/stateful:pcrpt-message/stateful:reports/stateful:path/stateful:bandwidth" {
+        uses bw-samples;
+    }
+
+    augment "/nt:network-topology/nt:topology/nt:node/topo:path-computation-client/topo:reported-lsp/topo:path/topo:bandwidth" {
+        uses bw-samples;
+    }
+
+}
\ No newline at end of file
diff --git a/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleTest.java b/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/controller/config/yang/pcep/auto/bandwidth/cfg/AutoBandwidthPCEPParserModuleTest.java
new file mode 100644 (file)
index 0000000..045f22f
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.controller.config.yang.pcep.auto.bandwidth.cfg;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.protocol.pcep.auto.bandwidth.extension.Activator;
+
+public class AutoBandwidthPCEPParserModuleTest {
+
+    private static final AutoBandwidthPCEPParserModuleFactory FACTORY = new AutoBandwidthPCEPParserModuleFactory();
+
+    private AutoBandwidthPCEPParserModule module;
+
+    @Before
+    public void setUp() {
+        final DependencyResolver dependencyResolver = Mockito.mock(DependencyResolver.class);
+        this.module = (AutoBandwidthPCEPParserModule) FACTORY.createModule("instance", dependencyResolver, null);
+    }
+
+    @Test
+    public void testCreateInsatnce() {
+        final AutoCloseable instance = module.createInstance();
+        Assert.assertTrue(instance instanceof Activator);
+    }
+
+    @Test
+    public void testCustomValidationLowerBound() {
+        try  {
+            this.module.setBandwidthUsageObjectType((short) 3);
+            this.module.customValidation();
+        } catch (final JmxAttributeValidationException e) {
+            Assert.fail(e.getMessage());
+        }
+
+        try {
+            this.module.setBandwidthUsageObjectType((short) 2);
+            this.module.customValidation();
+            Assert.fail();
+        } catch (final JmxAttributeValidationException e) {
+            Assert.assertTrue(e.getMessage().startsWith("BandwidthUsageObjectType out of range"));
+        }
+
+    }
+
+    @Test
+    public void testCustomValidationUpperBound() {
+        try  {
+            this.module.setBandwidthUsageObjectType((short) 15);
+            this.module.customValidation();
+        } catch (final JmxAttributeValidationException e) {
+            Assert.fail(e.getMessage());
+        }
+
+        try {
+            this.module.setBandwidthUsageObjectType((short) 16);
+            this.module.customValidation();
+            Assert.fail();
+        } catch (final JmxAttributeValidationException e) {
+            Assert.assertTrue(e.getMessage().startsWith("BandwidthUsageObjectType out of range"));
+        }
+
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/ActivatorTest.java b/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/ActivatorTest.java
new file mode 100644 (file)
index 0000000..8e87289
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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 java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+
+public class ActivatorTest {
+
+    @Test
+    public void testStartImplPCEPExtensionProviderContext() throws PCEPDeserializerException {
+        final Activator activator = new Activator(1);
+        final PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.create();
+        final List<AutoCloseable> registrations = activator.startImpl(ctx);
+        Assert.assertEquals(4, registrations.size());
+        activator.close();
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PCEPBandwidthUsageObjectCodecTest.java b/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PCEPBandwidthUsageObjectCodecTest.java
new file mode 100644 (file)
index 0000000..d8d5ba1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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 org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+
+public class PCEPBandwidthUsageObjectCodecTest {
+
+    private static final byte[] BW_BYTES = new byte[] { 0x05, 0x50, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x40, 0x00};
+
+    @Test
+    public void testCodec() throws PCEPDeserializerException {
+        final BandwidthUsageObjectCodec codec = new BandwidthUsageObjectCodec(5);
+        assertEquals(5, codec.getType());
+
+        final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
+        builder.setBwSample(Lists.newArrayList(new Bandwidth(new byte [] {0x00, 0x00, 0x10, 0x00}), new Bandwidth(new byte[] {0x00, 0x00, 0x40, 0x00})));
+        builder.setIgnore(false);
+        builder.setProcessingRule(false);
+        final BandwidthUsage parsedObject = codec.parseObject(new ObjectHeaderImpl(false, false), Unpooled.wrappedBuffer(BW_BYTES, 4, BW_BYTES.length - 4));
+        assertEquals(builder.build(), parsedObject);
+
+        final ByteBuf buffer = Unpooled.buffer(BW_BYTES.length);
+        codec.serializeObject(builder.build(), buffer);
+        assertArrayEquals(BW_BYTES, ByteArray.getAllBytes(buffer));
+    }
+
+}
diff --git a/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodecTest.java b/pcep/auto-bandwidth-extension/src/test/java/org/opendaylight/protocol/pcep/auto/bandwidth/extension/PcRptMessageCodecTest.java
new file mode 100644 (file)
index 0000000..157dd91
--- /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 org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.Collections;
+import java.util.List;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
+import org.opendaylight.protocol.pcep.impl.Activator;
+import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.Bandwidth1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.Bandwidth1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev160109.bandwidth.usage.object.BandwidthUsageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
+
+public class PcRptMessageCodecTest {
+
+    private SimplePCEPExtensionProviderContext ctx;
+    private Activator act;
+    private StatefulActivator statefulAct;
+
+    @Before
+    public void setUp() {
+        this.ctx = new SimplePCEPExtensionProviderContext();
+        this.act = new Activator();
+        this.act.start(this.ctx);
+        this.statefulAct = new StatefulActivator();
+        this.statefulAct.start(this.ctx);
+    }
+
+    @After
+    public void tearDown() {
+        this.act.stop();
+        this.statefulAct.stop();
+    }
+
+    @Test
+    public void testGetValidReportsPositive() {
+        final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
+        final BandwidthUsage bw = new BandwidthUsageBuilder().setBwSample(Lists.newArrayList(new Bandwidth(new byte[] {0, 0, 0, 1}))).build();
+        final Lsp lsp = new LspBuilder().build();
+        final Ero ero = new EroBuilder().build();
+        final List<Object> objects = Lists.<Object>newArrayList(lsp, ero, bw);
+        final Reports validReports = codec.getValidReports(objects, Collections.<Message>emptyList());
+        assertNotNull(validReports.getPath().getBandwidth().getAugmentation(Bandwidth1.class));
+        assertTrue(objects.isEmpty());
+    }
+
+    @Test
+    public void testserializeObject() {
+        final PcRptMessageCodec codec = new PcRptMessageCodec(this.ctx.getObjectHandlerRegistry());
+        final BandwidthBuilder bwBuilder = new BandwidthBuilder();
+        bwBuilder.addAugmentation(Bandwidth1.class, new Bandwidth1Builder().setBwSample(
+                Lists.newArrayList(new Bandwidth(new byte[] {0, 0, 0, 1}))).build());
+        final ByteBuf buffer = Unpooled.buffer();
+        codec.serializeObject(bwBuilder.build(), buffer);
+        Assert.assertTrue(buffer.readableBytes() > 0);
+    }
+
+}
index 974916847beb768bbc859bb4421344ab250ca6e1..f564a29be65315a23aaadbf47d0cc1e76c8e17e9 100644 (file)
                                     <type>xml</type>
                                     <classifier>config-segment</classifier>
                                 </artifact>
+                                <artifact>
+                                    <file>${project.build.directory}/classes/initial/34-pcep-auto-bandwidth.xml</file>
+                                    <type>xml</type>
+                                    <classifier>config-auto-bw</classifier>
+                                </artifact>
                                 <artifact>
                                     <file>${project.build.directory}/classes/initial/39-pcep-provider.xml</file>
                                     <type>xml</type>
diff --git a/pcep/controller-config/src/main/resources/initial/34-pcep-auto-bandwidth.xml b/pcep/controller-config/src/main/resources/initial/34-pcep-auto-bandwidth.xml
new file mode 100644 (file)
index 0000000..5fa5ad8
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<snapshot>
+    <required-capabilities>
+        <capability>urn:opendaylight:params:xml:ns:yang:controller:pcep:impl?module=odl-pcep-impl-cfg&amp;revision=2013-06-27</capability>
+        <capability>urn:opendaylight:params:xml:ns:yang:controller:pcep:spi?module=odl-pcep-spi-cfg&amp;revision=2013-11-15</capability>
+        <capability>urn:opendaylight:params:xml:ns:yang:controller:pcep:auto:bandwidth:cfg?module=odl-pcep-auto-bandwidth-cfg&amp;revision=2016-01-09</capability>
+    </required-capabilities>
+    <configuration>
+        <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+            <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+                <module>
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:pcep:spi">prefix:pcep-extensions-impl</type>
+                    <name>global-pcep-extensions</name>
+                    <extension>
+                        <type xmlns:pcepspi="urn:opendaylight:params:xml:ns:yang:controller:pcep:spi">pcepspi:extension</type>
+                        <name>pcep-parser-auto-bandwidth</name>
+                    </extension>
+                </module>
+                <module>
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:pcep:auto:bandwidth:cfg">prefix:pcep-parser-auto-bandwidth</type>
+                    <name>pcep-parser-auto-bandwidth</name>
+                    <!--<bandwidth-usage-object-type>5</bandwidth-usage-object-type>-->
+                </module>
+            </modules>
+            <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+                <service>
+                    <type xmlns:pcepspi="urn:opendaylight:params:xml:ns:yang:controller:pcep:spi">pcepspi:extension</type>
+                    <instance>
+                        <name>pcep-parser-auto-bandwidth</name>
+                        <provider>/config/modules/module[name='pcep-parser-auto-bandwidth']/instance[name='pcep-parser-auto-bandwidth']</provider>
+                    </instance>
+                </service>
+           </services>
+        </data>
+    </configuration>
+</snapshot>
\ No newline at end of file
index 9f58b23462580ed9285ac9f82cba070956674864..64a5044d6a9b1d66dd31f0765b94406ae57e1cb1 100644 (file)
@@ -44,5 +44,6 @@
         <module>controller-config</module>
         <module>segment-routing</module>
         <module>pcc-mock</module>
+        <module>auto-bandwidth-extension</module>
     </modules>
 </project>