Priyanka B
Committed by Gerrit Code Review

[ONOS-2613] Unit test the BGP Update message(LinkStateAttribute)

Change-Id: Id9545296612bed858459c8386368c66cb2159173
...@@ -34,9 +34,9 @@ public final class BgpId { ...@@ -34,9 +34,9 @@ public final class BgpId {
34 private final IpAddress ipAddress; 34 private final IpAddress ipAddress;
35 35
36 /** 36 /**
37 - * Private constructor. 37 + * Constructor to initialize ipAddress.
38 */ 38 */
39 - private BgpId(IpAddress ipAddress) { 39 + public BgpId(IpAddress ipAddress) {
40 this.ipAddress = ipAddress; 40 this.ipAddress = ipAddress;
41 } 41 }
42 42
......
...@@ -24,6 +24,7 @@ import org.onosproject.bgpio.types.As4Path; ...@@ -24,6 +24,7 @@ import org.onosproject.bgpio.types.As4Path;
24 import org.onosproject.bgpio.types.AsPath; 24 import org.onosproject.bgpio.types.AsPath;
25 import org.onosproject.bgpio.types.BgpErrorType; 25 import org.onosproject.bgpio.types.BgpErrorType;
26 import org.onosproject.bgpio.types.BgpValueType; 26 import org.onosproject.bgpio.types.BgpValueType;
27 +import org.onosproject.bgpio.types.LinkStateAttributes;
27 import org.onosproject.bgpio.types.LocalPref; 28 import org.onosproject.bgpio.types.LocalPref;
28 import org.onosproject.bgpio.types.Med; 29 import org.onosproject.bgpio.types.Med;
29 import org.onosproject.bgpio.types.NextHop; 30 import org.onosproject.bgpio.types.NextHop;
...@@ -54,7 +55,7 @@ public class BgpPathAttributes { ...@@ -54,7 +55,7 @@ public class BgpPathAttributes {
54 */ 55 */
55 protected static final Logger log = LoggerFactory.getLogger(BgpPathAttributes.class); 56 protected static final Logger log = LoggerFactory.getLogger(BgpPathAttributes.class);
56 57
57 - public static final int LINK_STATE_ATTRIBUTE_TYPE = 50; 58 + public static final int LINK_STATE_ATTRIBUTE_TYPE = 29;
58 public static final int MPREACHNLRI_TYPE = 14; 59 public static final int MPREACHNLRI_TYPE = 14;
59 public static final int MPUNREACHNLRI_TYPE = 15; 60 public static final int MPUNREACHNLRI_TYPE = 15;
60 61
...@@ -139,7 +140,7 @@ public class BgpPathAttributes { ...@@ -139,7 +140,7 @@ public class BgpPathAttributes {
139 .isMpUnReachNlriSet(); 140 .isMpUnReachNlriSet();
140 break; 141 break;
141 case LINK_STATE_ATTRIBUTE_TYPE: 142 case LINK_STATE_ATTRIBUTE_TYPE:
142 - //TODO: To be merged later 143 + pathAttribute = LinkStateAttributes.read(cb);
143 break; 144 break;
144 default: 145 default:
145 //skip bytes for unsupported attribute types 146 //skip bytes for unsupported attribute types
......
...@@ -89,7 +89,7 @@ public class LinkStateAttributes implements BgpValueType { ...@@ -89,7 +89,7 @@ public class LinkStateAttributes implements BgpValueType {
89 public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156; 89 public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156;
90 public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157; 90 public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157;
91 91
92 - public static final byte LINKSTATE_ATTRIB_TYPE = 50; 92 + public static final byte LINKSTATE_ATTRIB_TYPE = 29;
93 public static final byte TYPE_AND_LEN = 4; 93 public static final byte TYPE_AND_LEN = 4;
94 private boolean isLinkStateAttribute = false; 94 private boolean isLinkStateAttribute = false;
95 private List<BgpValueType> linkStateAttribList; 95 private List<BgpValueType> linkStateAttribList;
...@@ -139,14 +139,14 @@ public class LinkStateAttributes implements BgpValueType { ...@@ -139,14 +139,14 @@ public class LinkStateAttributes implements BgpValueType {
139 public static LinkStateAttributes read(ChannelBuffer cb) 139 public static LinkStateAttributes read(ChannelBuffer cb)
140 throws BgpParseException { 140 throws BgpParseException {
141 141
142 - ChannelBuffer tempBuf = cb; 142 + ChannelBuffer tempBuf = cb.copy();
143 Validation parseFlags = Validation.parseAttributeHeader(cb); 143 Validation parseFlags = Validation.parseAttributeHeader(cb);
144 int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN 144 int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN
145 : parseFlags.getLength() + 3; 145 : parseFlags.getLength() + 3;
146 146
147 ChannelBuffer data = tempBuf.readBytes(len); 147 ChannelBuffer data = tempBuf.readBytes(len);
148 - if (!parseFlags.getFirstBit() || parseFlags.getSecondBit() 148 + if (!parseFlags.getFirstBit() && parseFlags.getSecondBit()
149 - || parseFlags.getThirdBit()) { 149 + && parseFlags.getThirdBit()) {
150 throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, 150 throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
151 BgpErrorType.ATTRIBUTE_FLAGS_ERROR, 151 BgpErrorType.ATTRIBUTE_FLAGS_ERROR,
152 data); 152 data);
......
...@@ -56,7 +56,7 @@ public final class BgpAttrNodeFlagBitTlv implements BgpValueType { ...@@ -56,7 +56,7 @@ public final class BgpAttrNodeFlagBitTlv implements BgpValueType {
56 * @param bExternalBit External bit 56 * @param bExternalBit External bit
57 * @param bAbrBit ABR Bit 57 * @param bAbrBit ABR Bit
58 */ 58 */
59 - private BgpAttrNodeFlagBitTlv(boolean bOverloadBit, boolean bAttachedBit, 59 + public BgpAttrNodeFlagBitTlv(boolean bOverloadBit, boolean bAttachedBit,
60 boolean bExternalBit, boolean bAbrBit) { 60 boolean bExternalBit, boolean bAbrBit) {
61 this.bOverloadBit = bOverloadBit; 61 this.bOverloadBit = bOverloadBit;
62 this.bAttachedBit = bAttachedBit; 62 this.bAttachedBit = bAttachedBit;
......
...@@ -21,9 +21,8 @@ import org.jboss.netty.buffer.ChannelBuffer; ...@@ -21,9 +21,8 @@ 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.types.BgpErrorType; 22 import org.onosproject.bgpio.types.BgpErrorType;
23 import org.onosproject.bgpio.types.BgpValueType; 23 import org.onosproject.bgpio.types.BgpValueType;
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 28
...@@ -31,166 +30,103 @@ import com.google.common.base.MoreObjects; ...@@ -31,166 +30,103 @@ import com.google.common.base.MoreObjects;
31 * Implements BGP link protection type attribute. 30 * Implements BGP link protection type attribute.
32 */ 31 */
33 public final class BgpLinkAttrProtectionType implements BgpValueType { 32 public final class BgpLinkAttrProtectionType implements BgpValueType {
34 -
35 - protected static final Logger log = LoggerFactory
36 - .getLogger(BgpLinkAttrProtectionType.class);
37 -
38 public static final int ATTRLINK_PROTECTIONTYPE = 1093; 33 public static final int ATTRLINK_PROTECTIONTYPE = 1093;
39 public static final int LINK_PROTECTION_LEN = 2; 34 public static final int LINK_PROTECTION_LEN = 2;
40 35
41 - public static final int EXTRA_TRAFFIC = 0x01; 36 + private byte linkProtectionType;
42 - public static final int UNPROTECTED = 0x02;
43 - public static final int SHARED = 0x04;
44 - public static final int DEDICATED_ONE_ISTO_ONE = 0x08;
45 - public static final int DEDICATED_ONE_PLUS_ONE = 0x10;
46 - public static final int ENHANCED = 0x20;
47 -
48 - /* Link Protection type flags */
49 - private final boolean bExtraTraffic;
50 - private final boolean bUnprotected;
51 - private final boolean bShared;
52 - private final boolean bDedOneIstoOne;
53 - private final boolean bDedOnePlusOne;
54 - private final boolean bEnhanced;
55 37
56 /** 38 /**
57 - * Constructor to initialize the value. 39 + * Enum to provide Link protection types.
58 - *
59 - * @param bExtraTraffic Extra Traffic
60 - * @param bUnprotected Unprotected
61 - * @param bShared Shared
62 - * @param bDedOneIstoOne Dedicated 1:1
63 - * @param bDedOnePlusOne Dedicated 1+1
64 - * @param bEnhanced Enhanced
65 */ 40 */
66 - private BgpLinkAttrProtectionType(boolean bExtraTraffic, 41 + public enum ProtectionType {
67 - boolean bUnprotected, 42 + EXTRA_TRAFFIC(1), UNPROTECTED(2), SHARED(4), DEDICATED_ONE_ISTO_ONE(8),
68 - boolean bShared, boolean bDedOneIstoOne, 43 + DEDICATED_ONE_PLUS_ONE(0x10), ENHANCED(0x20), RESERVED(0x40);
69 - boolean bDedOnePlusOne, boolean bEnhanced) { 44 + int value;
70 - this.bExtraTraffic = bExtraTraffic;
71 - this.bUnprotected = bUnprotected;
72 - this.bShared = bShared;
73 - this.bDedOneIstoOne = bDedOneIstoOne;
74 - this.bDedOnePlusOne = bDedOnePlusOne;
75 - this.bEnhanced = bEnhanced;
76 - }
77 45
78 /** 46 /**
79 - * Returns object of this class with specified values. 47 + * Assign val with the value as the link protection type.
80 * 48 *
81 - * @param bExtraTraffic Extra Traffic 49 + * @param val link protection
82 - * @param bUnprotected Unprotected
83 - * @param bShared Shared
84 - * @param bDedOneIstoOne Dedicated 1:1
85 - * @param bDedOnePlusOne Dedicated 1+1
86 - * @param bEnhanced Enhanced
87 - * @return object of BgpLinkAttrProtectionType
88 */ 50 */
89 - public static BgpLinkAttrProtectionType of(boolean bExtraTraffic, 51 + ProtectionType(int val) {
90 - boolean bUnprotected, 52 + value = val;
91 - boolean bShared,
92 - boolean bDedOneIstoOne,
93 - boolean bDedOnePlusOne,
94 - boolean bEnhanced) {
95 - return new BgpLinkAttrProtectionType(bExtraTraffic, bUnprotected,
96 - bShared, bDedOneIstoOne,
97 - bDedOnePlusOne, bEnhanced);
98 } 53 }
99 54
100 /** 55 /**
101 - * Reads the BGP link attributes protection type. 56 + * Returns value of link protection type.
102 * 57 *
103 - * @param cb Channel buffer 58 + * @return link protection type
104 - * @return object of type BgpLinkAttrProtectionType
105 - * @throws BgpParseException while parsing BgpLinkAttrProtectionType
106 */ 59 */
107 - public static BgpLinkAttrProtectionType read(ChannelBuffer cb) 60 + public byte type() {
108 - throws BgpParseException { 61 + return (byte) value;
109 - short linkProtectionType;
110 - byte higherByte;
111 - short lsAttrLength = cb.readShort();
112 -
113 - boolean bExtraTraffic;
114 - boolean bUnprotected;
115 - boolean bShared;
116 - boolean bDedOneIstoOne;
117 - boolean bDedOnePlusOne;
118 - boolean bEnhanced;
119 -
120 - if ((lsAttrLength != LINK_PROTECTION_LEN)
121 - || (cb.readableBytes() < lsAttrLength)) {
122 - Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
123 - BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
124 - lsAttrLength);
125 } 62 }
126 -
127 - linkProtectionType = cb.readShort();
128 - higherByte = (byte) (linkProtectionType >> 8);
129 -
130 - bExtraTraffic = ((higherByte & (byte) EXTRA_TRAFFIC) == EXTRA_TRAFFIC);
131 - bUnprotected = ((higherByte & (byte) UNPROTECTED) == UNPROTECTED);
132 - bShared = ((higherByte & (byte) SHARED) == SHARED);
133 - bDedOneIstoOne = ((higherByte & (byte) DEDICATED_ONE_ISTO_ONE) == DEDICATED_ONE_ISTO_ONE);
134 - bDedOnePlusOne = ((higherByte & (byte) DEDICATED_ONE_PLUS_ONE) == DEDICATED_ONE_PLUS_ONE);
135 - bEnhanced = ((higherByte & (byte) ENHANCED) == ENHANCED);
136 -
137 - return BgpLinkAttrProtectionType.of(bExtraTraffic, bUnprotected,
138 - bShared, bDedOneIstoOne,
139 - bDedOnePlusOne, bEnhanced);
140 } 63 }
141 64
142 /** 65 /**
143 - * Returns ExtraTraffic Bit. 66 + * Constructor to initialize the value.
144 * 67 *
145 - * @return ExtraTraffic Bit 68 + * @param linkProtectionType link protection type
146 */ 69 */
147 - public boolean extraTraffic() { 70 + public BgpLinkAttrProtectionType(byte linkProtectionType) {
148 - return bExtraTraffic; 71 + this.linkProtectionType = linkProtectionType;
149 } 72 }
150 73
151 /** 74 /**
152 - * Returns Unprotected Bit. 75 + * Returns object of this class with specified values.
153 * 76 *
154 - * @return Unprotected Bit 77 + * @param linkProtectionType link protection type
78 + * @return object of BgpLinkAttrProtectionType
155 */ 79 */
156 - public boolean unprotected() { 80 + public static BgpLinkAttrProtectionType of(byte linkProtectionType) {
157 - return bUnprotected; 81 + return new BgpLinkAttrProtectionType(linkProtectionType);
158 } 82 }
159 83
160 /** 84 /**
161 - * Returns Shared Bit. 85 + * Reads the BGP link attributes protection type.
162 * 86 *
163 - * @return Shared Bit 87 + * @param cb Channel buffer
88 + * @return object of type BgpLinkAttrProtectionType
89 + * @throws BgpParseException while parsing BgpLinkAttrProtectionType
164 */ 90 */
165 - public boolean shared() { 91 + public static BgpLinkAttrProtectionType read(ChannelBuffer cb)
166 - return bShared; 92 + throws BgpParseException {
167 - } 93 + short lsAttrLength = cb.readShort();
168 94
169 - /** 95 + if ((lsAttrLength != LINK_PROTECTION_LEN) || (cb.readableBytes() < lsAttrLength)) {
170 - * Returns DedOneIstoOne Bit. 96 + Validation
171 - * 97 + .validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength);
172 - * @return DedOneIstoOne Bit
173 - */
174 - public boolean dedOneIstoOne() {
175 - return bDedOneIstoOne;
176 } 98 }
177 99
178 - /** 100 + byte linkProtectionType = cb.readByte();
179 - * Returns DedOnePlusOne Bit. 101 + byte reserved = cb.readByte();
180 - * 102 +
181 - * @return DedOnePlusOne Bit 103 + return BgpLinkAttrProtectionType.of(linkProtectionType);
182 - */
183 - public boolean dedOnePlusOne() {
184 - return bDedOnePlusOne;
185 } 104 }
186 105
187 /** 106 /**
188 - * Returns Enhanced Bit. 107 + * Returns Link Protection Type.
189 * 108 *
190 - * @return Enhanced Bit 109 + * @return Link Protection Type
191 */ 110 */
192 - public boolean enhanced() { 111 + public ProtectionType protectionType() throws BgpParseException {
193 - return bEnhanced; 112 + switch (linkProtectionType) {
113 + case Constants.EXTRA_TRAFFIC:
114 + return ProtectionType.EXTRA_TRAFFIC;
115 + case Constants.UNPROTECTED:
116 + return ProtectionType.UNPROTECTED;
117 + case Constants.SHARED:
118 + return ProtectionType.SHARED;
119 + case Constants.DEDICATED_ONE_ISTO_ONE:
120 + return ProtectionType.DEDICATED_ONE_ISTO_ONE;
121 + case Constants.DEDICATED_ONE_PLUS_ONE:
122 + return ProtectionType.DEDICATED_ONE_PLUS_ONE;
123 + case Constants.ENHANCED:
124 + return ProtectionType.ENHANCED;
125 + case Constants.RESERVED:
126 + return ProtectionType.RESERVED;
127 + default:
128 + throw new BgpParseException("Got another type " + linkProtectionType);
129 + }
194 } 130 }
195 131
196 @Override 132 @Override
...@@ -200,8 +136,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType { ...@@ -200,8 +136,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
200 136
201 @Override 137 @Override
202 public int hashCode() { 138 public int hashCode() {
203 - return Objects.hash(bExtraTraffic, bUnprotected, bShared, 139 + return Objects.hash(linkProtectionType);
204 - bDedOneIstoOne, bDedOnePlusOne, bEnhanced);
205 } 140 }
206 141
207 @Override 142 @Override
...@@ -212,12 +147,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType { ...@@ -212,12 +147,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
212 147
213 if (obj instanceof BgpLinkAttrProtectionType) { 148 if (obj instanceof BgpLinkAttrProtectionType) {
214 BgpLinkAttrProtectionType other = (BgpLinkAttrProtectionType) obj; 149 BgpLinkAttrProtectionType other = (BgpLinkAttrProtectionType) obj;
215 - return Objects.equals(bExtraTraffic, other.bExtraTraffic) 150 + return Objects.equals(linkProtectionType, other.linkProtectionType);
216 - && Objects.equals(bUnprotected, other.bUnprotected)
217 - && Objects.equals(bShared, other.bShared)
218 - && Objects.equals(bDedOneIstoOne, other.bDedOneIstoOne)
219 - && Objects.equals(bDedOnePlusOne, other.bDedOnePlusOne)
220 - && Objects.equals(bEnhanced, other.bEnhanced);
221 } 151 }
222 return false; 152 return false;
223 } 153 }
...@@ -231,11 +161,8 @@ public final class BgpLinkAttrProtectionType implements BgpValueType { ...@@ -231,11 +161,8 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
231 @Override 161 @Override
232 public String toString() { 162 public String toString() {
233 return MoreObjects.toStringHelper(getClass()) 163 return MoreObjects.toStringHelper(getClass())
234 - .add("bExtraTraffic", bExtraTraffic) 164 + .add("linkProtectionType", linkProtectionType)
235 - .add("bUnprotected", bUnprotected).add("bShared", bShared) 165 + .toString();
236 - .add("bDedOneIstoOne", bDedOneIstoOne)
237 - .add("bDedOnePlusOne", bDedOnePlusOne)
238 - .add("bEnhanced", bEnhanced).toString();
239 } 166 }
240 167
241 @Override 168 @Override
......
...@@ -33,6 +33,7 @@ import com.google.common.base.MoreObjects; ...@@ -33,6 +33,7 @@ import com.google.common.base.MoreObjects;
33 public class BgpLinkAttrSrlg implements BgpValueType { 33 public class BgpLinkAttrSrlg implements BgpValueType {
34 34
35 public static final short ATTRNODE_SRLG = 1097; 35 public static final short ATTRNODE_SRLG = 1097;
36 + public static final short SIZE = 4;
36 37
37 /* Shared Risk Link Group */ 38 /* Shared Risk Link Group */
38 private List<Integer> sRlg = new ArrayList<Integer>(); 39 private List<Integer> sRlg = new ArrayList<Integer>();
...@@ -69,7 +70,7 @@ public class BgpLinkAttrSrlg implements BgpValueType { ...@@ -69,7 +70,7 @@ public class BgpLinkAttrSrlg implements BgpValueType {
69 ArrayList<Integer> sRlg = new ArrayList<Integer>(); 70 ArrayList<Integer> sRlg = new ArrayList<Integer>();
70 71
71 short lsAttrLength = cb.readShort(); 72 short lsAttrLength = cb.readShort();
72 - int len = lsAttrLength / Integer.SIZE; // each element is of 4 octets 73 + int len = lsAttrLength / SIZE; // each element is of 4 octets
73 74
74 if (cb.readableBytes() < lsAttrLength) { 75 if (cb.readableBytes() < lsAttrLength) {
75 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, 76 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
......
...@@ -57,7 +57,7 @@ public final class BgpPrefixAttrIgpFlags implements BgpValueType { ...@@ -57,7 +57,7 @@ public final class BgpPrefixAttrIgpFlags implements BgpValueType {
57 * @param bOspfLclAddrBit OSPF local address Bit 57 * @param bOspfLclAddrBit OSPF local address Bit
58 * @param bOspfNSSABit OSPF propagate NSSA Bit 58 * @param bOspfNSSABit OSPF propagate NSSA Bit
59 */ 59 */
60 - BgpPrefixAttrIgpFlags(boolean bisisUpDownBit, 60 + public BgpPrefixAttrIgpFlags(boolean bisisUpDownBit,
61 boolean bOspfNoUnicastBit, 61 boolean bOspfNoUnicastBit,
62 boolean bOspfLclAddrBit, boolean bOspfNSSABit) { 62 boolean bOspfLclAddrBit, boolean bOspfNSSABit) {
63 this.bisisUpDownBit = bisisUpDownBit; 63 this.bisisUpDownBit = bisisUpDownBit;
......
...@@ -38,6 +38,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType { ...@@ -38,6 +38,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType {
38 .getLogger(BgpPrefixAttrRouteTag.class); 38 .getLogger(BgpPrefixAttrRouteTag.class);
39 39
40 public static final short ATTR_PREFIX_ROUTETAG = 1153; 40 public static final short ATTR_PREFIX_ROUTETAG = 1153;
41 + public static final short SIZE = 4;
41 42
42 /* Prefix Route Tag */ 43 /* Prefix Route Tag */
43 private List<Integer> pfxRouteTag = new ArrayList<Integer>(); 44 private List<Integer> pfxRouteTag = new ArrayList<Integer>();
...@@ -74,7 +75,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType { ...@@ -74,7 +75,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType {
74 ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>(); 75 ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
75 76
76 short lsAttrLength = cb.readShort(); 77 short lsAttrLength = cb.readShort();
77 - int len = lsAttrLength / Integer.SIZE; 78 + int len = lsAttrLength / SIZE;
78 79
79 if (cb.readableBytes() < lsAttrLength) { 80 if (cb.readableBytes() < lsAttrLength) {
80 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, 81 Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
......
...@@ -34,4 +34,11 @@ public final class Constants { ...@@ -34,4 +34,11 @@ public final class Constants {
34 public static final short AFI_VALUE = 16388; 34 public static final short AFI_VALUE = 16388;
35 public static final byte VPN_SAFI_VALUE = (byte) 0x80; 35 public static final byte VPN_SAFI_VALUE = (byte) 0x80;
36 public static final byte SAFI_VALUE = 71; 36 public static final byte SAFI_VALUE = 71;
37 + public static final int EXTRA_TRAFFIC = 0x01;
38 + public static final int UNPROTECTED = 0x02;
39 + public static final int SHARED = 0x04;
40 + public static final int DEDICATED_ONE_ISTO_ONE = 0x08;
41 + public static final int DEDICATED_ONE_PLUS_ONE = 0x10;
42 + public static final int ENHANCED = 0x20;
43 + public static final int RESERVED = 0x40;
37 } 44 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -20,37 +20,20 @@ import org.junit.Test; ...@@ -20,37 +20,20 @@ import org.junit.Test;
20 import com.google.common.testing.EqualsTester; 20 import com.google.common.testing.EqualsTester;
21 21
22 /** 22 /**
23 - * Test for MPLS protocol mask attribute. 23 + * Test for Protection Type attribute.
24 */ 24 */
25 public class BgpLinkAttrProtectionTypeTest { 25 public class BgpLinkAttrProtectionTypeTest {
26 - boolean bExtraTraffic = true; 26 + private final byte linkProtectionType1 = 0x04;
27 - boolean bUnprotected = true; 27 + private final byte linkProtectionType2 = 0x40;
28 - boolean bShared = true;
29 - boolean bDedOneIstoOne = true;
30 - boolean bDedOnePlusOne = true;
31 - boolean bEnhanced = true;
32 28
33 - boolean bExtraTraffic1 = false; 29 + private final BgpLinkAttrProtectionType attr1 = BgpLinkAttrProtectionType.of(linkProtectionType1);
34 - boolean bUnprotected1 = false; 30 + private final BgpLinkAttrProtectionType sameAsAttr1 = BgpLinkAttrProtectionType.of(linkProtectionType1);
35 - boolean bShared1 = false; 31 + private final BgpLinkAttrProtectionType attr2 = BgpLinkAttrProtectionType.of(linkProtectionType2);
36 - boolean bDedOneIstoOne1 = false;
37 - boolean bDedOnePlusOne1 = false;
38 - boolean bEnhanced1 = false;
39 -
40 - private final BgpLinkAttrProtectionType data = BgpLinkAttrProtectionType
41 - .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne,
42 - bDedOnePlusOne, bEnhanced);
43 - private final BgpLinkAttrProtectionType sameAsData = BgpLinkAttrProtectionType
44 - .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne,
45 - bDedOnePlusOne, bEnhanced);
46 - private final BgpLinkAttrProtectionType diffData = BgpLinkAttrProtectionType
47 - .of(bExtraTraffic1, bUnprotected1, bShared1, bDedOneIstoOne1,
48 - bDedOnePlusOne1, bEnhanced1);
49 32
50 @Test 33 @Test
51 - public void basics() { 34 + public void testEquality() {
52 - 35 + new EqualsTester().addEqualityGroup(attr1, sameAsAttr1)
53 - new EqualsTester().addEqualityGroup(data, sameAsData) 36 + .addEqualityGroup(attr2)
54 - .addEqualityGroup(diffData).testEquals(); 37 + .testEquals();
55 } 38 }
56 } 39 }
......