[ONOS] path attribute code fix

Change-Id: I819c8105cb242dfd8f50c09edebfb3f3bbbaeaf0
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
index 353ec3d..1d083b7 100644
--- a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
@@ -21,9 +21,8 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.onlab.packet.Ip4Address;
 import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
 import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
@@ -32,10 +31,7 @@
  * Implementation of NextHop BGP Path Attribute.
  */
 public class NextHop implements BGPValueType {
-    private static final Logger log = LoggerFactory.getLogger(NextHop.class);
     public static final byte NEXTHOP_TYPE = 3;
-    public static final int TYPE_AND_LEN_AS_SHORT = 4;
-    public static final int TYPE_AND_LEN_AS_BYTE = 3;
 
     private boolean isNextHop = false;
     private Ip4Address nextHop;
@@ -75,15 +71,14 @@
             Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
                     parseFlags.getLength());
         }
-        int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
-                .getLength() + TYPE_AND_LEN_AS_BYTE;
+        int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+                .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
         ChannelBuffer data = tempCb.readBytes(len);
         if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
             throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
         }
 
-        //TODO: use Validation.toInetAddress once Validation is merged
-        InetAddress ipAddress = (InetAddress) cb.readBytes(parseFlags.getLength());
+         InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
         if (ipAddress.isMulticastAddress()) {
             throw new BGPParseException("Multicast address is not supported");
         }
diff --git a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
index 3b2070d..2052e96 100644
--- a/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
+++ b/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
@@ -19,9 +19,8 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
 import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.MoreObjects;
 
@@ -29,7 +28,6 @@
  * Provides Implementation of mandatory BGP Origin path attribute.
  */
 public class Origin implements BGPValueType {
-    private static final Logger log = LoggerFactory.getLogger(Origin.class);
 
     /**
      * Enum to provide ORIGIN types.
@@ -58,8 +56,6 @@
 
     public static final byte ORIGIN_TYPE = 1;
     public static final byte ORIGIN_VALUE_LEN = 1;
-    public static final int TYPE_AND_LEN_AS_SHORT = 4;
-    public static final int TYPE_AND_LEN_AS_BYTE = 3;
 
     private boolean isOrigin = false;
     private byte origin;
@@ -109,8 +105,8 @@
         ChannelBuffer tempCb = cb.copy();
         Validation parseFlags = Validation.parseAttributeHeader(cb);
 
-        int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
-                .getLength() + TYPE_AND_LEN_AS_BYTE;
+        int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+                .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
         ChannelBuffer data = tempCb.readBytes(len);
         if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
             Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
@@ -122,7 +118,7 @@
 
         byte originValue;
         originValue = cb.readByte();
-        if ((originValue != ORIGINTYPE.INCOMPLETE.value) || (originValue != ORIGINTYPE.IGP.value) ||
+        if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
               (originValue != ORIGINTYPE.EGP.value)) {
             throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
         }