Priyanka B
Committed by Gerrit Code Review

[ONOS] path attribute code fix

Change-Id: I819c8105cb242dfd8f50c09edebfb3f3bbbaeaf0
...@@ -21,9 +21,8 @@ import java.util.Objects; ...@@ -21,9 +21,8 @@ import java.util.Objects;
21 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.onlab.packet.Ip4Address; 22 import org.onlab.packet.Ip4Address;
23 import org.onosproject.bgpio.exceptions.BGPParseException; 23 import org.onosproject.bgpio.exceptions.BGPParseException;
24 +import org.onosproject.bgpio.util.Constants;
24 import org.onosproject.bgpio.util.Validation; 25 import org.onosproject.bgpio.util.Validation;
25 -import org.slf4j.Logger;
26 -import org.slf4j.LoggerFactory;
27 26
28 import com.google.common.base.MoreObjects; 27 import com.google.common.base.MoreObjects;
29 import com.google.common.base.Preconditions; 28 import com.google.common.base.Preconditions;
...@@ -32,10 +31,7 @@ import com.google.common.base.Preconditions; ...@@ -32,10 +31,7 @@ import com.google.common.base.Preconditions;
32 * Implementation of NextHop BGP Path Attribute. 31 * Implementation of NextHop BGP Path Attribute.
33 */ 32 */
34 public class NextHop implements BGPValueType { 33 public class NextHop implements BGPValueType {
35 - private static final Logger log = LoggerFactory.getLogger(NextHop.class);
36 public static final byte NEXTHOP_TYPE = 3; 34 public static final byte NEXTHOP_TYPE = 3;
37 - public static final int TYPE_AND_LEN_AS_SHORT = 4;
38 - public static final int TYPE_AND_LEN_AS_BYTE = 3;
39 35
40 private boolean isNextHop = false; 36 private boolean isNextHop = false;
41 private Ip4Address nextHop; 37 private Ip4Address nextHop;
...@@ -75,15 +71,14 @@ public class NextHop implements BGPValueType { ...@@ -75,15 +71,14 @@ public class NextHop implements BGPValueType {
75 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, 71 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
76 parseFlags.getLength()); 72 parseFlags.getLength());
77 } 73 }
78 - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags 74 + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
79 - .getLength() + TYPE_AND_LEN_AS_BYTE; 75 + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
80 ChannelBuffer data = tempCb.readBytes(len); 76 ChannelBuffer data = tempCb.readBytes(len);
81 if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) { 77 if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
82 throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); 78 throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
83 } 79 }
84 80
85 - //TODO: use Validation.toInetAddress once Validation is merged 81 + InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
86 - InetAddress ipAddress = (InetAddress) cb.readBytes(parseFlags.getLength());
87 if (ipAddress.isMulticastAddress()) { 82 if (ipAddress.isMulticastAddress()) {
88 throw new BGPParseException("Multicast address is not supported"); 83 throw new BGPParseException("Multicast address is not supported");
89 } 84 }
......
...@@ -19,9 +19,8 @@ import java.util.Objects; ...@@ -19,9 +19,8 @@ import java.util.Objects;
19 19
20 import org.jboss.netty.buffer.ChannelBuffer; 20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.onosproject.bgpio.exceptions.BGPParseException; 21 import org.onosproject.bgpio.exceptions.BGPParseException;
22 +import org.onosproject.bgpio.util.Constants;
22 import org.onosproject.bgpio.util.Validation; 23 import org.onosproject.bgpio.util.Validation;
23 -import org.slf4j.Logger;
24 -import org.slf4j.LoggerFactory;
25 24
26 import com.google.common.base.MoreObjects; 25 import com.google.common.base.MoreObjects;
27 26
...@@ -29,7 +28,6 @@ import com.google.common.base.MoreObjects; ...@@ -29,7 +28,6 @@ import com.google.common.base.MoreObjects;
29 * Provides Implementation of mandatory BGP Origin path attribute. 28 * Provides Implementation of mandatory BGP Origin path attribute.
30 */ 29 */
31 public class Origin implements BGPValueType { 30 public class Origin implements BGPValueType {
32 - private static final Logger log = LoggerFactory.getLogger(Origin.class);
33 31
34 /** 32 /**
35 * Enum to provide ORIGIN types. 33 * Enum to provide ORIGIN types.
...@@ -58,8 +56,6 @@ public class Origin implements BGPValueType { ...@@ -58,8 +56,6 @@ public class Origin implements BGPValueType {
58 56
59 public static final byte ORIGIN_TYPE = 1; 57 public static final byte ORIGIN_TYPE = 1;
60 public static final byte ORIGIN_VALUE_LEN = 1; 58 public static final byte ORIGIN_VALUE_LEN = 1;
61 - public static final int TYPE_AND_LEN_AS_SHORT = 4;
62 - public static final int TYPE_AND_LEN_AS_BYTE = 3;
63 59
64 private boolean isOrigin = false; 60 private boolean isOrigin = false;
65 private byte origin; 61 private byte origin;
...@@ -109,8 +105,8 @@ public class Origin implements BGPValueType { ...@@ -109,8 +105,8 @@ public class Origin implements BGPValueType {
109 ChannelBuffer tempCb = cb.copy(); 105 ChannelBuffer tempCb = cb.copy();
110 Validation parseFlags = Validation.parseAttributeHeader(cb); 106 Validation parseFlags = Validation.parseAttributeHeader(cb);
111 107
112 - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags 108 + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
113 - .getLength() + TYPE_AND_LEN_AS_BYTE; 109 + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
114 ChannelBuffer data = tempCb.readBytes(len); 110 ChannelBuffer data = tempCb.readBytes(len);
115 if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) { 111 if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
116 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, 112 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
...@@ -122,7 +118,7 @@ public class Origin implements BGPValueType { ...@@ -122,7 +118,7 @@ public class Origin implements BGPValueType {
122 118
123 byte originValue; 119 byte originValue;
124 originValue = cb.readByte(); 120 originValue = cb.readByte();
125 - if ((originValue != ORIGINTYPE.INCOMPLETE.value) || (originValue != ORIGINTYPE.IGP.value) || 121 + if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
126 (originValue != ORIGINTYPE.EGP.value)) { 122 (originValue != ORIGINTYPE.EGP.value)) {
127 throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data); 123 throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
128 } 124 }
......