Committed by
Gerrit Code Review
[ONOS-2613] Unit test the BGP Update message(LinkStateAttribute)
Change-Id: Id9545296612bed858459c8386368c66cb2159173
Showing
12 changed files
with
2570 additions
and
175 deletions
... | @@ -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); | ... | ... |
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
100755 → 100644
... | @@ -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 | ... | ... |
protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpUpdateLinkStateAttrTest.java
0 → 100644
This diff could not be displayed because it is too large.
protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpUpdateMsgTest.java
100755 → 100644
... | @@ -23,6 +23,7 @@ import static org.hamcrest.core.Is.is; | ... | @@ -23,6 +23,7 @@ import static org.hamcrest.core.Is.is; |
23 | import org.jboss.netty.buffer.ChannelBuffer; | 23 | import org.jboss.netty.buffer.ChannelBuffer; |
24 | import org.jboss.netty.buffer.ChannelBuffers; | 24 | import org.jboss.netty.buffer.ChannelBuffers; |
25 | import org.junit.Test; | 25 | import org.junit.Test; |
26 | +import org.onlab.packet.Ip4Address; | ||
26 | import org.onlab.packet.IpAddress; | 27 | import org.onlab.packet.IpAddress; |
27 | import org.onlab.packet.IpPrefix; | 28 | import org.onlab.packet.IpPrefix; |
28 | import org.onosproject.bgpio.exceptions.BgpParseException; | 29 | import org.onosproject.bgpio.exceptions.BgpParseException; |
... | @@ -41,6 +42,7 @@ import org.onosproject.bgpio.types.BgpValueType; | ... | @@ -41,6 +42,7 @@ import org.onosproject.bgpio.types.BgpValueType; |
41 | import org.onosproject.bgpio.types.IPReachabilityInformationTlv; | 42 | import org.onosproject.bgpio.types.IPReachabilityInformationTlv; |
42 | import org.onosproject.bgpio.types.IsIsNonPseudonode; | 43 | import org.onosproject.bgpio.types.IsIsNonPseudonode; |
43 | import org.onosproject.bgpio.types.IsIsPseudonode; | 44 | import org.onosproject.bgpio.types.IsIsPseudonode; |
45 | +import org.onosproject.bgpio.types.LinkStateAttributes; | ||
44 | import org.onosproject.bgpio.types.Med; | 46 | import org.onosproject.bgpio.types.Med; |
45 | import org.onosproject.bgpio.types.MpReachNlri; | 47 | import org.onosproject.bgpio.types.MpReachNlri; |
46 | import org.onosproject.bgpio.types.MpUnReachNlri; | 48 | import org.onosproject.bgpio.types.MpUnReachNlri; |
... | @@ -48,6 +50,10 @@ import org.onosproject.bgpio.types.Origin; | ... | @@ -48,6 +50,10 @@ import org.onosproject.bgpio.types.Origin; |
48 | import org.onosproject.bgpio.types.NextHop; | 50 | import org.onosproject.bgpio.types.NextHop; |
49 | import org.onosproject.bgpio.types.LocalPref; | 51 | import org.onosproject.bgpio.types.LocalPref; |
50 | import org.onosproject.bgpio.types.Origin.ORIGINTYPE; | 52 | import org.onosproject.bgpio.types.Origin.ORIGINTYPE; |
53 | +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4; | ||
54 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrName; | ||
55 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag; | ||
56 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags; | ||
51 | import org.slf4j.Logger; | 57 | import org.slf4j.Logger; |
52 | import org.slf4j.LoggerFactory; | 58 | import org.slf4j.LoggerFactory; |
53 | 59 | ||
... | @@ -1493,4 +1499,498 @@ public class BgpUpdateMsgTest { | ... | @@ -1493,4 +1499,498 @@ public class BgpUpdateMsgTest { |
1493 | 1499 | ||
1494 | assertThat(message, instanceOf(BgpUpdateMsg.class)); | 1500 | assertThat(message, instanceOf(BgpUpdateMsg.class)); |
1495 | } | 1501 | } |
1502 | + | ||
1503 | + //Negative scenarios | ||
1504 | + /** | ||
1505 | + * Wrong length BgpAttrRouterIdV4. | ||
1506 | + */ | ||
1507 | + @Test(expected = BgpParseException.class) | ||
1508 | + public void bgpUpdateMessageTest35() throws BgpParseException { | ||
1509 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1510 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1511 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95, | ||
1512 | + 0x02, 0x00, 0x04, | ||
1513 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1514 | + 0x00, 0x7A, //path attribute len | ||
1515 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1516 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1517 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1518 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1519 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1520 | + 0x00, //reserved | ||
1521 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1522 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1523 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1524 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1525 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1526 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1527 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1528 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1529 | + (byte) 0x80, 0x1d, 0x0f, //linkstate attr | ||
1530 | + 0x04, 0x04, 0x00, 0x06, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4 | ||
1531 | + 0x04, 0x47, 0x00, 0x03, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric | ||
1532 | + | ||
1533 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1534 | + buffer.writeBytes(updateMsg); | ||
1535 | + | ||
1536 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1537 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1538 | + reader.readFrom(buffer, bgpHeader); | ||
1539 | + } | ||
1540 | + | ||
1541 | + /** | ||
1542 | + * Wrong length BgpLinkAttrIGPMetric. | ||
1543 | + */ | ||
1544 | + @Test(expected = BgpParseException.class) | ||
1545 | + public void bgpUpdateMessageTest36() throws BgpParseException { | ||
1546 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1547 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1548 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95, | ||
1549 | + 0x02, 0x00, 0x04, | ||
1550 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1551 | + 0x00, 0x7A, //path attribute len | ||
1552 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1553 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1554 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1555 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1556 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1557 | + 0x00, //reserved | ||
1558 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1559 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1560 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1561 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1562 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1563 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1564 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1565 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1566 | + (byte) 0x80, 0x1d, 0x0f, //linkstate attr | ||
1567 | + 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4 | ||
1568 | + 0x04, 0x47, 0x00, 0x02, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric | ||
1569 | + | ||
1570 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1571 | + buffer.writeBytes(updateMsg); | ||
1572 | + | ||
1573 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1574 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1575 | + reader.readFrom(buffer, bgpHeader); | ||
1576 | + } | ||
1577 | + | ||
1578 | + /** | ||
1579 | + * Wrong length BgpPrefixAttrMetric. | ||
1580 | + */ | ||
1581 | + @Test(expected = BgpParseException.class) | ||
1582 | + public void bgpUpdateMessageTest37() throws BgpParseException { | ||
1583 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1584 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1585 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, | ||
1586 | + 0x02, 0x00, 0x04, | ||
1587 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1588 | + 0x00, 0x7b, //path attribute len | ||
1589 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1590 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1591 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1592 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1593 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1594 | + 0x00, //reserved | ||
1595 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1596 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1597 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1598 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1599 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1600 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1601 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1602 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1603 | + (byte) 0x80, 0x1d, 0x10, //linkstate attr | ||
1604 | + 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 | ||
1605 | + 0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric | ||
1606 | + | ||
1607 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1608 | + buffer.writeBytes(updateMsg); | ||
1609 | + | ||
1610 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1611 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1612 | + reader.readFrom(buffer, bgpHeader); | ||
1613 | + } | ||
1614 | + | ||
1615 | + /** | ||
1616 | + * Wrong length BgpPrefixAttrMetric. | ||
1617 | + */ | ||
1618 | + @Test(expected = BgpParseException.class) | ||
1619 | + public void bgpUpdateMessageTest38() throws BgpParseException { | ||
1620 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1621 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1622 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, | ||
1623 | + 0x02, 0x00, 0x04, | ||
1624 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1625 | + 0x00, 0x7b, //path attribute len | ||
1626 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1627 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1628 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1629 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1630 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1631 | + 0x00, //reserved | ||
1632 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1633 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1634 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1635 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1636 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1637 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1638 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1639 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1640 | + (byte) 0x80, 0x1d, 0x10, //linkstate attr | ||
1641 | + 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 | ||
1642 | + 0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric | ||
1643 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1644 | + buffer.writeBytes(updateMsg); | ||
1645 | + | ||
1646 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1647 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1648 | + reader.readFrom(buffer, bgpHeader); | ||
1649 | + } | ||
1650 | + | ||
1651 | + /** | ||
1652 | + * Wrong length BgpPrefixAttrOpaqueData. | ||
1653 | + */ | ||
1654 | + @Test(expected = BgpParseException.class) | ||
1655 | + public void bgpUpdateMessageTest39() throws BgpParseException { | ||
1656 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1657 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1658 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, | ||
1659 | + 0x02, 0x00, 0x04, | ||
1660 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1661 | + 0x00, 0x7B, //path attribute len | ||
1662 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1663 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1664 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1665 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1666 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1667 | + 0x00, //reserved | ||
1668 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1669 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1670 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1671 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1672 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1673 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1674 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1675 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1676 | + (byte) 0x80, 0x1d, 0x10, //linkstate attr | ||
1677 | + 0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 | ||
1678 | + 0x04, (byte) 0x85, 0x00, 0x06, 0x0a, 0x0a, 0x0a, 0x0a}; //BgpPrefixAttrOpaqueData | ||
1679 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1680 | + buffer.writeBytes(updateMsg); | ||
1681 | + | ||
1682 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1683 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1684 | + reader.readFrom(buffer, bgpHeader); | ||
1685 | + } | ||
1686 | + | ||
1687 | + /** | ||
1688 | + * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName. | ||
1689 | + * | ||
1690 | + * @throws BgpParseException while parsing update message | ||
1691 | + */ | ||
1692 | + @Test | ||
1693 | + public void bgpUpdateMessageTest40() throws BgpParseException { | ||
1694 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1695 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1696 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A, | ||
1697 | + 0x02, 0x00, 0x04, | ||
1698 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1699 | + 0x00, 0x7F, //path attribute len | ||
1700 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1701 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1702 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1703 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1704 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1705 | + 0x00, //reserved | ||
1706 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1707 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1708 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1709 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1710 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1711 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1712 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1713 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1714 | + (byte) 0x80, 0x1d, 0x14, //linkstate attr | ||
1715 | + 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 | ||
1716 | + 0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b}; //BgpLinkAttrName | ||
1717 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1718 | + buffer.writeBytes(updateMsg); | ||
1719 | + | ||
1720 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1721 | + BgpMessage message = null; | ||
1722 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1723 | + | ||
1724 | + message = reader.readFrom(buffer, bgpHeader); | ||
1725 | + | ||
1726 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1727 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
1728 | + | ||
1729 | + byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1730 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1731 | + (byte) 0xff, (byte) 0xff, (byte) 0xff }; | ||
1732 | + | ||
1733 | + assertThat(other.getHeader().getMarker(), is(marker)); | ||
1734 | + assertThat(other.getHeader().getType(), is((byte) 2)); | ||
1735 | + assertThat(other.getHeader().getLength(), is((short) 154)); | ||
1736 | + | ||
1737 | + ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); | ||
1738 | + byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; | ||
1739 | + | ||
1740 | + while (listIterator1.hasNext()) { | ||
1741 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
1742 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
1743 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
1744 | + } | ||
1745 | + | ||
1746 | + BgpValueType testPathAttribute = null; | ||
1747 | + Origin origin; | ||
1748 | + AsPath aspath; | ||
1749 | + Med med; | ||
1750 | + MpReachNlri mpReach; | ||
1751 | + LinkStateAttributes linkStateAttr; | ||
1752 | + List<BgpValueType> pathAttributeList = new LinkedList<>(); | ||
1753 | + BgpPathAttributes pathAttribute = other.bgpPathAttributes(); | ||
1754 | + pathAttributeList = pathAttribute.pathAttributes(); | ||
1755 | + ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); | ||
1756 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
1757 | + | ||
1758 | + testPathAttribute = listIterator.next(); | ||
1759 | + origin = (Origin) testPathAttribute; | ||
1760 | + assertThat(origin.origin(), is(originValue)); | ||
1761 | + | ||
1762 | + testPathAttribute = listIterator.next(); | ||
1763 | + aspath = (AsPath) testPathAttribute; | ||
1764 | + ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); | ||
1765 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
1766 | + | ||
1767 | + testPathAttribute = listIterator.next(); | ||
1768 | + med = (Med) testPathAttribute; | ||
1769 | + assertThat(med.med(), is(0)); | ||
1770 | + | ||
1771 | + testPathAttribute = listIterator.next(); | ||
1772 | + mpReach = (MpReachNlri) testPathAttribute; | ||
1773 | + assertThat(mpReach.mpReachNlriLen(), is((int) 83)); | ||
1774 | + assertThat(mpReach.getType(), is((short) 14)); | ||
1775 | + | ||
1776 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
1777 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
1778 | + | ||
1779 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
1780 | + BgpLSNlri testnlri = list1.next(); | ||
1781 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; | ||
1782 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
1783 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
1784 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
1785 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
1786 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
1787 | + | ||
1788 | + testPathAttribute = listIterator.next(); | ||
1789 | + linkStateAttr = (LinkStateAttributes) testPathAttribute; | ||
1790 | + | ||
1791 | + assertThat(linkStateAttr.getType(), is((short) 29)); | ||
1792 | + ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); | ||
1793 | + byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; | ||
1794 | + Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); | ||
1795 | + assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); | ||
1796 | + byte[] linkName = new byte[] {0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b }; | ||
1797 | + assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName)); | ||
1798 | + } | ||
1799 | + | ||
1800 | + /** | ||
1801 | + * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrIGPFlags. | ||
1802 | + * | ||
1803 | + * @throws BgpParseException while parsing update message | ||
1804 | + */ | ||
1805 | + @Test | ||
1806 | + public void bgpUpdateMessageTest41() throws BgpParseException { | ||
1807 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1808 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1809 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93, | ||
1810 | + 0x02, 0x00, 0x04, | ||
1811 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1812 | + 0x00, 0x78, //path attribute len | ||
1813 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1814 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1815 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1816 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1817 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1818 | + 0x00, //reserved | ||
1819 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1820 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1821 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1822 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1823 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1824 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1825 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1826 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri | ||
1827 | + (byte) 0x80, 0x1d, 0x0D, //linkstate attr | ||
1828 | + 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4 | ||
1829 | + 0x04, (byte) 0x80, 0x00, 0x01, (byte) 0xA0}; //BgpPrefixAttrIGPFlags | ||
1830 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1831 | + buffer.writeBytes(updateMsg); | ||
1832 | + | ||
1833 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1834 | + BgpMessage message = null; | ||
1835 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1836 | + | ||
1837 | + message = reader.readFrom(buffer, bgpHeader); | ||
1838 | + | ||
1839 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1840 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
1841 | + | ||
1842 | + byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1843 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1844 | + (byte) 0xff, (byte) 0xff, (byte) 0xff }; | ||
1845 | + | ||
1846 | + assertThat(other.getHeader().getMarker(), is(marker)); | ||
1847 | + assertThat(other.getHeader().getType(), is((byte) 2)); | ||
1848 | + assertThat(other.getHeader().getLength(), is((short) 147)); | ||
1849 | + | ||
1850 | + BgpValueType testPathAttribute = null; | ||
1851 | + Origin origin; | ||
1852 | + AsPath aspath; | ||
1853 | + Med med; | ||
1854 | + MpReachNlri mpReach; | ||
1855 | + LinkStateAttributes linkStateAttr; | ||
1856 | + List<BgpValueType> pathAttributeList = new LinkedList<>(); | ||
1857 | + BgpPathAttributes pathAttribute = other.bgpPathAttributes(); | ||
1858 | + pathAttributeList = pathAttribute.pathAttributes(); | ||
1859 | + ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); | ||
1860 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
1861 | + | ||
1862 | + testPathAttribute = listIterator.next(); | ||
1863 | + origin = (Origin) testPathAttribute; | ||
1864 | + assertThat(origin.origin(), is(originValue)); | ||
1865 | + | ||
1866 | + testPathAttribute = listIterator.next(); | ||
1867 | + aspath = (AsPath) testPathAttribute; | ||
1868 | + ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); | ||
1869 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
1870 | + | ||
1871 | + testPathAttribute = listIterator.next(); | ||
1872 | + med = (Med) testPathAttribute; | ||
1873 | + assertThat(med.med(), is(0)); | ||
1874 | + | ||
1875 | + testPathAttribute = listIterator.next(); | ||
1876 | + mpReach = (MpReachNlri) testPathAttribute; | ||
1877 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
1878 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
1879 | + | ||
1880 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
1881 | + BgpLSNlri testnlri = list1.next(); | ||
1882 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; | ||
1883 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
1884 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
1885 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
1886 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
1887 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
1888 | + | ||
1889 | + testPathAttribute = listIterator.next(); | ||
1890 | + linkStateAttr = (LinkStateAttributes) testPathAttribute; | ||
1891 | + | ||
1892 | + assertThat(linkStateAttr.getType(), is((short) 29)); | ||
1893 | + ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); | ||
1894 | + byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; | ||
1895 | + Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); | ||
1896 | + assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); | ||
1897 | + BgpPrefixAttrIgpFlags obj = new BgpPrefixAttrIgpFlags(true, false, true, false); | ||
1898 | + assertThat(((BgpPrefixAttrIgpFlags) list.next()).equals(obj), is(true)); | ||
1899 | + } | ||
1900 | + | ||
1901 | + /** | ||
1902 | + * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrExtRouteTag. | ||
1903 | + * | ||
1904 | + * @throws BgpParseException while parsing update message | ||
1905 | + */ | ||
1906 | + @Test | ||
1907 | + public void bgpUpdateMessageTest42() throws BgpParseException { | ||
1908 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1909 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1910 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xA2, 0x02, 0x00, 0x04, | ||
1911 | + 0x18, 0x0a, 0x01, 0x01, 0x00, (byte) 0x87, 0x04, 0x01, 0x01, 0x00, //origin | ||
1912 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1913 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1914 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1915 | + 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved | ||
1916 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1917 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1918 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1919 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1920 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1921 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1922 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1923 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21, (byte) 0x80, 0x1d, 0x1C, //linkstate attr | ||
1924 | + 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId | ||
1925 | + 0x04, (byte) 0x82, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, (byte) 0xBB, (byte) 0xE9, 0x0B, | ||
1926 | + 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0x6E, 0x1B}; //BgpPrefixAttrExtRouteTag | ||
1927 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1928 | + buffer.writeBytes(updateMsg); | ||
1929 | + | ||
1930 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1931 | + BgpMessage message = null; | ||
1932 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1933 | + | ||
1934 | + message = reader.readFrom(buffer, bgpHeader); | ||
1935 | + | ||
1936 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1937 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
1938 | + | ||
1939 | + byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1940 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1941 | + (byte) 0xff, (byte) 0xff, (byte) 0xff }; | ||
1942 | + | ||
1943 | + assertThat(other.getHeader().getMarker(), is(marker)); | ||
1944 | + assertThat(other.getHeader().getType(), is((byte) 2)); | ||
1945 | + assertThat(other.getHeader().getLength(), is((short) 162)); | ||
1946 | + | ||
1947 | + BgpValueType testPathAttribute = null; | ||
1948 | + Origin origin; | ||
1949 | + AsPath aspath; | ||
1950 | + Med med; | ||
1951 | + MpReachNlri mpReach; | ||
1952 | + LinkStateAttributes linkStateAttr; | ||
1953 | + List<BgpValueType> pathAttributeList = new LinkedList<>(); | ||
1954 | + BgpPathAttributes pathAttribute = other.bgpPathAttributes(); | ||
1955 | + pathAttributeList = pathAttribute.pathAttributes(); | ||
1956 | + ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator(); | ||
1957 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
1958 | + | ||
1959 | + testPathAttribute = listIterator.next(); | ||
1960 | + origin = (Origin) testPathAttribute; | ||
1961 | + assertThat(origin.origin(), is(originValue)); | ||
1962 | + | ||
1963 | + testPathAttribute = listIterator.next(); | ||
1964 | + aspath = (AsPath) testPathAttribute; | ||
1965 | + ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator(); | ||
1966 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
1967 | + | ||
1968 | + testPathAttribute = listIterator.next(); | ||
1969 | + med = (Med) testPathAttribute; | ||
1970 | + assertThat(med.med(), is(0)); | ||
1971 | + | ||
1972 | + testPathAttribute = listIterator.next(); | ||
1973 | + mpReach = (MpReachNlri) testPathAttribute; | ||
1974 | + | ||
1975 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
1976 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
1977 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
1978 | + BgpLSNlri testnlri = list1.next(); | ||
1979 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
1980 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
1981 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
1982 | + | ||
1983 | + testPathAttribute = listIterator.next(); | ||
1984 | + linkStateAttr = (LinkStateAttributes) testPathAttribute; | ||
1985 | + | ||
1986 | + assertThat(linkStateAttr.getType(), is((short) 29)); | ||
1987 | + ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator(); | ||
1988 | + byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 }; | ||
1989 | + Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes); | ||
1990 | + assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId)); | ||
1991 | + List<Long> extRouteTag = new LinkedList<>(); | ||
1992 | + extRouteTag.add(45869323L); | ||
1993 | + extRouteTag.add(52456987L); | ||
1994 | + assertThat(((BgpPrefixAttrExtRouteTag) list.next()).pfxExtRouteTag(), is(extRouteTag)); | ||
1995 | + } | ||
1496 | } | 1996 | } | ... | ... |
... | @@ -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 | } | ... | ... |
-
Please register or login to post a comment