[onos-2613] - Unit testing of BgpAttrRouterIdV6

Change-Id: I46f2a821bf80237e74e4732d2315f477b1890480
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
index 06a1d73..ea63c37 100755
--- a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
@@ -31,15 +31,15 @@
 /**
  * Implements BGP attribute IPv6 router ID.
  */
-public class BgpAttrRouterIdV6 implements BGPValueType {
+public final class BgpAttrRouterIdV6 implements BGPValueType {
 
     protected static final Logger log = LoggerFactory
             .getLogger(BgpAttrRouterIdV6.class);
 
-    public short sType;
+    private final short sType;
 
     /* IPv4 Router-ID of Node */
-    private Ip6Address ip6RouterId;
+    private final Ip6Address ip6RouterId;
 
     /**
      * Constructor to initialize the value.
@@ -47,16 +47,28 @@
      * @param ip6RouterId IPV6 address of the router ID
      * @param sType TLV type
      */
-    BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) {
+    private BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) {
         this.ip6RouterId = ip6RouterId;
         this.sType = sType;
     }
 
     /**
+     * Returns object of this class with specified values.
+     *
+     * @param ip6RouterId IPV6 address of the router ID
+     * @param sType TLV type
+     * @return object of BgpAttrRouterIdV6
+     */
+    public static BgpAttrRouterIdV6 of(final Ip6Address ip6RouterId,
+                                       final short sType) {
+        return new BgpAttrRouterIdV6(ip6RouterId, sType);
+    }
+
+    /**
      * Reads the IPv6 Router-ID.
      *
      * @param cb ChannelBuffer
-     * @param sType type
+     * @param sType TLV type
      * @return object of BgpAttrRouterIdV6
      * @throws BGPParseException while parsing BgpAttrRouterIdV6
      */
@@ -67,7 +79,7 @@
 
         short lsAttrLength = cb.readShort();
 
-        if (16 != lsAttrLength) {
+        if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) {
             Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
                                    BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
                                    lsAttrLength);
@@ -76,7 +88,7 @@
         ipBytes = new byte[lsAttrLength];
         cb.readBytes(ipBytes);
         ip6RouterId = Ip6Address.valueOf(ipBytes);
-        return new BgpAttrRouterIdV6(ip6RouterId, sType);
+        return BgpAttrRouterIdV6.of(ip6RouterId, sType);
     }
 
     /**
@@ -84,7 +96,7 @@
      *
      * @return Router ID
      */
-    Ip6Address getAttrRouterId() {
+    public Ip6Address attrRouterId() {
         return ip6RouterId;
     }
 
@@ -113,7 +125,7 @@
 
     @Override
     public int write(ChannelBuffer cb) {
-        // TODO Auto-generated method stub
+        // TODO This will be implemented in the next version
         return 0;
     }
 
diff --git a/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java b/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java
new file mode 100644
index 0000000..72ca5db
--- /dev/null
+++ b/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgp;
+
+import org.junit.Test;
+import org.onlab.packet.Ip6Address;
+import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP attribute node router ID.
+ */
+public class BgpAttrRouterIdV6Test {
+
+    private final short sType = 1;
+    private final Ip6Address ip6RouterId = Ip6Address
+            .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001");
+
+    private final short sType1 = 2;
+    private final Ip6Address ip6RouterId1 = Ip6Address
+            .valueOf("2004:0db8:0a0b:12f0:0000:0000:0000:0004");
+
+    private final BgpAttrRouterIdV6 data = BgpAttrRouterIdV6.of(ip6RouterId,
+                                                                sType);
+    private final BgpAttrRouterIdV6 sameAsData = BgpAttrRouterIdV6
+            .of(ip6RouterId, sType);
+    private final BgpAttrRouterIdV6 diffData = BgpAttrRouterIdV6
+            .of(ip6RouterId1, sType1);
+
+    @Test
+    public void basics() {
+
+        new EqualsTester().addEqualityGroup(data, sameAsData)
+        .addEqualityGroup(diffData).testEquals();
+    }
+}
\ No newline at end of file