Add uint24.yang 98/86698/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 4 Jan 2020 10:40:52 +0000 (11:40 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 4 Jan 2020 14:24:46 +0000 (15:24 +0100)
uint24 is used in a variety of binary protocols (rsvp,lisp,bgp),
this adds a common definition of this type and the corresponding
netty utilities.

JIRA: MDSAL-507
Change-Id: I5170c2bb9ed65d25bada3a85aca6c22f9ba4696b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 28d302faed8b6f57263991257163414ac073a37f)

14 files changed:
artifacts/pom.xml
common/mdsal-uint24-netty/pom.xml [new file with mode: 0644]
common/mdsal-uint24-netty/src/main/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtils.java [new file with mode: 0644]
common/mdsal-uint24-netty/src/test/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtilsTest.java [new file with mode: 0644]
common/pom.xml
docs/pom.xml
features/features-mdsal/pom.xml
features/odl-mdsal-model-odl-uint24/pom.xml [new file with mode: 0644]
features/odl-mdsal-uint24-netty/pom.xml [new file with mode: 0644]
features/odl-mdsal-uint24-netty/src/main/feature/feature.xml [new file with mode: 0644]
features/pom.xml
model/odl-uint24/pom.xml [new file with mode: 0644]
model/odl-uint24/src/main/yang/uint24.yang [new file with mode: 0644]
model/pom.xml

index bb1e923b977133a117551ece8bcdd168f8c4bbd5..365ff0516302836a34144f2036f38c83a0ef7dd2 100644 (file)
                 <type>xml</type>
             </dependency>
 
+            <!-- uint24 support -->
+            <dependency>
+                <groupId>org.opendaylight.mdsal.model</groupId>
+                <artifactId>odl-uint24</artifactId>
+                <version>5.0.7-SNAPSHOT</version>
+            </dependency>
+            <dependency>
+                <groupId>org.opendaylight.mdsal</groupId>
+                <artifactId>mdsal-uint24-netty</artifactId>
+                <version>5.0.7-SNAPSHOT</version>
+            </dependency>
+
             <!-- MODELS -->
             <dependency>
                 <groupId>org.opendaylight.mdsal.model</groupId>
                 <classifier>features</classifier>
                 <type>xml</type>
             </dependency>
+            <dependency>
+                <groupId>org.opendaylight.mdsal.model</groupId>
+                <artifactId>odl-mdsal-model-odl-uint24</artifactId>
+                <version>5.0.7-SNAPSHOT</version>
+                <classifier>features</classifier>
+                <type>xml</type>
+            </dependency>
+            <dependency>
+                <groupId>org.opendaylight.mdsal</groupId>
+                <artifactId>odl-mdsal-uint24-netty</artifactId>
+                <version>5.0.7-SNAPSHOT</version>
+                <classifier>features</classifier>
+                <type>xml</type>
+            </dependency>
 
             <!-- Documentation -->
             <dependency>
diff --git a/common/mdsal-uint24-netty/pom.xml b/common/mdsal-uint24-netty/pom.xml
new file mode 100644 (file)
index 0000000..2ec4ac4
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2019 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
+-->
+<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>
+
+    <parent>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>dom-parent</artifactId>
+        <version>5.0.7-SNAPSHOT</version>
+        <relativePath>../../dom/dom-parent</relativePath>
+    </parent>
+
+    <artifactId>mdsal-uint24-netty</artifactId>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common-netty</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>yang-binding</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>odl-uint24</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>mockito-configuration</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Automatic-Module-Name>org.opendaylight.mdsal.uint24.netty</Automatic-Module-Name>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <scm>
+        <connection>scm:git:http://git.opendaylight.org/gerrit/mdsal.git</connection>
+        <developerConnection>scm:git:ssh://git.opendaylight.org:29418/mdsal.git</developerConnection>
+        <tag>HEAD</tag>
+        <url>https://wiki.opendaylight.org/view/MD-SAL:Main</url>
+    </scm>
+</project>
diff --git a/common/mdsal-uint24-netty/src/main/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtils.java b/common/mdsal-uint24-netty/src/main/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtils.java
new file mode 100644 (file)
index 0000000..d7bf5e8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2019 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.mdsal.uint24.netty;
+
+import com.google.common.annotations.Beta;
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.uint24.rev200104.Uint24;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+@Beta
+public final class Uint24ByteBufUtils {
+    private Uint24ByteBufUtils() {
+        // Hidden on purpose
+    }
+
+    /**
+     * Read a {@link Uint24} from specified buffer.
+     *
+     * @param buf buffer
+     * @return A {@link Uint24}
+     * @throws NullPointerException if {@code buf} is null
+     * @throws IndexOutOfBoundsException if {@code buf} does not have enough data
+     */
+    public static @NonNull Uint24 readUint24(final ByteBuf buf) {
+        return new Uint24(Uint32.fromIntBits(buf.readMedium()));
+    }
+
+    /**
+     * Write a {@link Uint24} to specified buffer.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint24}
+     * @throws NullPointerException if any argument is null
+     */
+    public static void writeUint24(final ByteBuf buf, final Uint24 value) {
+        buf.writeMedium(value.getValue().intValue());
+    }
+
+    /**
+     * Write a {@link Uint24} property to specified buffer. If the {@code value} is known to be non-null, prefer to use
+     * {@link #writeUint24(ByteBuf, Uint24)} instead of this method.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint24}
+     * @param name Property name for error reporting purposes
+     * @throws NullPointerException if {@code buf} is null
+     * @throws IllegalArgumentException if {@code value} is null
+     */
+    public static void writeMandatoryUint24(final ByteBuf buf, final Uint24 value, final String name) {
+        if (value == null) {
+            throw new IllegalArgumentException(name + " is mandatory");
+        }
+        writeUint24(buf, value);
+    }
+
+    /**
+     * Write a {@link Uint24} value to specified buffer if it is not null.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint24}
+     * @throws NullPointerException if {@code buf} is null
+     */
+    public static void writeOptionalUint24(final ByteBuf buf, final @Nullable Uint24 value) {
+        if (value != null) {
+            writeUint24(buf, value);
+        }
+    }
+
+    /**
+     * Write a {@link Uint24} value to specified buffer if it is not null, otherwise write three zero bytes.
+     *
+     * @param buf buffer
+     * @param value A {@link Uint24}
+     * @throws NullPointerException if {@code buf} is null
+     */
+    public static void writeUint24OrZero(final ByteBuf buf, final @Nullable Uint24 value) {
+        buf.writeMedium(value != null ? value.getValue().intValue() : 0);
+    }
+}
diff --git a/common/mdsal-uint24-netty/src/test/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtilsTest.java b/common/mdsal-uint24-netty/src/test/java/org/opendaylight/mdsal/uint24/netty/Uint24ByteBufUtilsTest.java
new file mode 100644 (file)
index 0000000..bcaf6f2
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2019 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.mdsal.uint24.netty;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.uint24.rev200104.Uint24;
+import org.opendaylight.yangtools.yang.common.Uint32;
+
+public class Uint24ByteBufUtilsTest {
+    private static final Uint24 ONE_TWO_THREE = new Uint24(Uint32.valueOf(0x010203));
+
+    @Test
+    public void testRead() {
+        final ByteBuf buf = Unpooled.buffer().writeMedium(0x010203);
+        assertEquals(ONE_TWO_THREE, Uint24ByteBufUtils.readUint24(buf));
+        assertEquals(0, buf.readableBytes());
+    }
+
+    @Test
+    public void testWrite() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeUint24(buf, ONE_TWO_THREE);
+        assertMedium(buf);
+    }
+
+    @Test
+    public void testWriteMandatory() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeMandatoryUint24(buf, ONE_TWO_THREE, "foo");
+        assertMedium(buf);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testWriteMandatoryNull() {
+        Uint24ByteBufUtils.writeMandatoryUint24(Unpooled.buffer(), null, "foo");
+    }
+
+    @Test
+    public void testWriteOptional() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeOptionalUint24(buf, ONE_TWO_THREE);
+        assertMedium(buf);
+    }
+
+    @Test
+    public void testWriteOptionalNull() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeOptionalUint24(buf, null);
+        assertEquals(0, buf.readableBytes());
+    }
+
+    @Test
+    public void testWriteOrZero() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeUint24OrZero(buf, ONE_TWO_THREE);
+        assertMedium(buf);
+    }
+
+    @Test
+    public void testWriteOrZeroNull() {
+        final ByteBuf buf = Unpooled.buffer();
+        Uint24ByteBufUtils.writeUint24OrZero(buf, null);
+        assertMedium(buf, 0);
+    }
+
+    private static void assertMedium(final ByteBuf buf) {
+        assertMedium(buf, 0x010203);
+    }
+
+    private static void assertMedium(final ByteBuf buf, final int value) {
+        assertEquals(3, buf.readableBytes());
+        assertEquals(value, buf.readMedium());
+    }
+}
index 4aba02d171912b514c571ed56f9d8b18d30b7e3f..40dad8ed8065960642234f7e7d7bd5db2c1c9cd5 100644 (file)
@@ -27,6 +27,7 @@
     <modules>
         <module>mdsal-common-api</module>
         <module>mdsal-common-util</module>
+        <module>mdsal-uint24-netty</module>
     </modules>
 
     <properties>
index 01e21ba672e1aeb8291999d32eeb787183de77fd..e2b6e1db0c17510428831455a4a5b4a00e10ef98 100644 (file)
             <artifactId>mdsal-yanglib-rfc8525</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>odl-uint24</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>mdsal-uint24-netty</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.opendaylight.mdsal.model</groupId>
             <artifactId>opendaylight-l2-types</artifactId>
index 483dbe5f136b7d09ef77b8d461643d2e1bd4d429..842b4ad5a4cf0b4d555c20649005b95cd9de5b8b 100644 (file)
             <type>xml</type>
         </dependency>
 
+        <!-- uint24 support -->
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>odl-mdsal-model-odl-uint24</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>odl-mdsal-uint24-netty</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+
         <!-- Models -->
         <dependency>
             <groupId>org.opendaylight.mdsal.model</groupId>
diff --git a/features/odl-mdsal-model-odl-uint24/pom.xml b/features/odl-mdsal-model-odl-uint24/pom.xml
new file mode 100644 (file)
index 0000000..4433772
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright © 2019 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
+ -->
+<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>
+    <parent>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>feature-parent</artifactId>
+        <version>5.0.7-SNAPSHOT</version>
+        <relativePath>../feature-parent</relativePath>
+    </parent>
+
+    <groupId>org.opendaylight.mdsal.model</groupId>
+    <artifactId>odl-mdsal-model-odl-uint24</artifactId>
+    <version>5.0.7-SNAPSHOT</version>
+    <packaging>feature</packaging>
+    <name>OpenDaylight :: MD-SAL :: Model :: OpenDaylight uint24 type</name>
+    <description>OpenDaylight-specific model of uint24</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>odl-mdsal-binding-base</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>odl-uint24</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/features/odl-mdsal-uint24-netty/pom.xml b/features/odl-mdsal-uint24-netty/pom.xml
new file mode 100644 (file)
index 0000000..c7e8661
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright © 2019 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
+ -->
+<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>
+    <parent>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>feature-parent</artifactId>
+        <version>5.0.7-SNAPSHOT</version>
+        <relativePath>../feature-parent</relativePath>
+    </parent>
+
+    <artifactId>odl-mdsal-uint24-netty</artifactId>
+    <packaging>feature</packaging>
+    <name>OpenDaylight :: MD-SAL :: uint24 :: Netty</name>
+    <description>Netty support for uint24</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>odl-yangtools-netty</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal.model</groupId>
+            <artifactId>odl-mdsal-model-odl-uint24</artifactId>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>mdsal-uint24-netty</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/features/odl-mdsal-uint24-netty/src/main/feature/feature.xml b/features/odl-mdsal-uint24-netty/src/main/feature/feature.xml
new file mode 100644 (file)
index 0000000..542c2e6
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-mdsal-uint24-netty">
+    <feature name="odl-mdsal-uint24-netty">
+        <feature version="[4,5)">odl-yangtools-netty</feature>
+    </feature>
+</features>
index 62a97b7ede14925768bf36ca760bd36a8f488606..65c6472785e9acc99b9b13b0d0223483a0b2e4a8 100644 (file)
         <module>odl-mdsal-exp-yanglib-rfc7895</module>
         <module>odl-mdsal-exp-yanglib-rfc8525</module>
 
+        <!-- uint24 support -->
+        <module>odl-mdsal-model-odl-uint24</module>
+        <module>odl-mdsal-uint24-netty</module>
+
         <!-- Models -->
         <!-- Standards -->
         <module>odl-mdsal-model-rfc6991</module>
diff --git a/model/odl-uint24/pom.xml b/model/odl-uint24/pom.xml
new file mode 100644 (file)
index 0000000..a8e245a
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2019 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
+-->
+<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">
+
+    <parent>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>5.0.7-SNAPSHOT</version>
+        <relativePath>../../binding/binding-parent</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.opendaylight.mdsal.model</groupId>
+    <artifactId>odl-uint24</artifactId>
+    <packaging>bundle</packaging>
+</project>
diff --git a/model/odl-uint24/src/main/yang/uint24.yang b/model/odl-uint24/src/main/yang/uint24.yang
new file mode 100644 (file)
index 0000000..24cf836
--- /dev/null
@@ -0,0 +1,30 @@
+module odl-uint24 {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:uint24";
+    prefix "uint24";
+
+    organization "OpenDaylight";
+    contact "Robert Varga <robert.varga@pantheon.tech>";
+
+    description
+        "This module contains the definition of uint24, an uint32 restricted
+         to 24 bits.
+
+         Copyright (c)2019 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";
+
+    revision "2020-01-04" {
+        description "Initial revision.";
+    }
+
+    typedef uint24 {
+        type uint32 {
+            range "0..16777215";
+        }
+        description "24-bit unsigned integer.";
+    }
+}
index ef850fa86ca17095ef42f39545d5c40079578baa..e39996e5876f8759342da2ac97077b2816bf9e6e 100644 (file)
@@ -30,6 +30,7 @@
         <module>ietf</module>
         <module>l2-types</module>
         <module>general-entity</module>
+        <module>odl-uint24</module>
     </modules>
 
     <properties>