Thejaswi N K
Committed by Gerrit Code Review

[onos-2613] - Unit testing of BgpAttrRouterIdV4

Change-Id: I0a6a57301f7dd0e9ca588d407d230c910798fd55
...@@ -31,15 +31,15 @@ import com.google.common.base.MoreObjects; ...@@ -31,15 +31,15 @@ import com.google.common.base.MoreObjects;
31 /** 31 /**
32 * Implements BGP attribute node router ID. 32 * Implements BGP attribute node router ID.
33 */ 33 */
34 -public class BgpAttrRouterIdV4 implements BGPValueType { 34 +public final class BgpAttrRouterIdV4 implements BGPValueType {
35 35
36 protected static final Logger log = LoggerFactory 36 protected static final Logger log = LoggerFactory
37 .getLogger(BgpAttrRouterIdV4.class); 37 .getLogger(BgpAttrRouterIdV4.class);
38 38
39 - public short sType; 39 + private final short sType;
40 40
41 /* IPv4 Router-ID of Node */ 41 /* IPv4 Router-ID of Node */
42 - private Ip4Address ip4RouterId; 42 + private final Ip4Address ip4RouterId;
43 43
44 /** 44 /**
45 * Constructor to initialize the value. 45 * Constructor to initialize the value.
...@@ -47,36 +47,45 @@ public class BgpAttrRouterIdV4 implements BGPValueType { ...@@ -47,36 +47,45 @@ public class BgpAttrRouterIdV4 implements BGPValueType {
47 * @param ip4RouterId IPV4 address of router 47 * @param ip4RouterId IPV4 address of router
48 * @param sType TLV type 48 * @param sType TLV type
49 */ 49 */
50 - BgpAttrRouterIdV4(Ip4Address ip4RouterId, short sType) { 50 + private BgpAttrRouterIdV4(Ip4Address ip4RouterId, short sType) {
51 this.ip4RouterId = ip4RouterId; 51 this.ip4RouterId = ip4RouterId;
52 this.sType = sType; 52 this.sType = sType;
53 } 53 }
54 54
55 /** 55 /**
56 + * Returns object of this class with specified values.
57 + *
58 + * @param ip4RouterId IPv4 address
59 + * @param sType Type of this TLV
60 + * @return object of BgpAttrRouterIdV4
61 + */
62 + public static BgpAttrRouterIdV4 of(final Ip4Address ip4RouterId,
63 + final short sType) {
64 + return new BgpAttrRouterIdV4(ip4RouterId, sType);
65 + }
66 +
67 + /**
56 * Reads the IPv4 Router-ID. 68 * Reads the IPv4 Router-ID.
57 * 69 *
58 * @param cb ChannelBuffer 70 * @param cb ChannelBuffer
59 - * @param sType type 71 + * @param sType tag type
60 * @return object of BgpAttrRouterIdV4 72 * @return object of BgpAttrRouterIdV4
61 - * @throws BGPParseException while parsing BgpAttrNodeRouterId 73 + * @throws BGPParseException while parsing BgpAttrRouterIdV4
62 */ 74 */
63 public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType) 75 public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType)
64 throws BGPParseException { 76 throws BGPParseException {
65 - byte[] ipBytes;
66 - Ip4Address ip4RouterId;
67 -
68 short lsAttrLength = cb.readShort(); 77 short lsAttrLength = cb.readShort();
69 78
70 - if (4 != lsAttrLength) { 79 + if ((lsAttrLength != 4) || (cb.readableBytes() < lsAttrLength)) {
71 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, 80 Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
72 BGPErrorType.ATTRIBUTE_LENGTH_ERROR, 81 BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
73 lsAttrLength); 82 lsAttrLength);
74 } 83 }
75 84
76 - ipBytes = new byte[lsAttrLength]; 85 + byte[] ipBytes = new byte[lsAttrLength];
77 - cb.readBytes(ipBytes); 86 + cb.readBytes(ipBytes, 0, lsAttrLength);
78 - ip4RouterId = Ip4Address.valueOf(ipBytes); 87 + Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
79 - return new BgpAttrRouterIdV4(ip4RouterId, sType); 88 + return BgpAttrRouterIdV4.of(ip4RouterId, sType);
80 } 89 }
81 90
82 /** 91 /**
...@@ -84,7 +93,7 @@ public class BgpAttrRouterIdV4 implements BGPValueType { ...@@ -84,7 +93,7 @@ public class BgpAttrRouterIdV4 implements BGPValueType {
84 * 93 *
85 * @return Router ID 94 * @return Router ID
86 */ 95 */
87 - Ip4Address getAttrRouterId() { 96 + public Ip4Address attrRouterId() {
88 return ip4RouterId; 97 return ip4RouterId;
89 } 98 }
90 99
...@@ -113,7 +122,7 @@ public class BgpAttrRouterIdV4 implements BGPValueType { ...@@ -113,7 +122,7 @@ public class BgpAttrRouterIdV4 implements BGPValueType {
113 122
114 @Override 123 @Override
115 public int write(ChannelBuffer cb) { 124 public int write(ChannelBuffer cb) {
116 - // TODO Auto-generated method stub 125 + // TODO This will be implemented in the next version
117 return 0; 126 return 0;
118 } 127 }
119 128
......