Committed by
Gerrit Code Review
BGP update message test
Change-Id: I28ae0ebf86143b99bab742b93fd3b4d0ff282ea5
Showing
2 changed files
with
1497 additions
and
1 deletions
... | @@ -131,7 +131,7 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -131,7 +131,7 @@ public class MpReachNlri implements BgpValueType { |
131 | if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE) | 131 | if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE) |
132 | && (safi == Constants.VPN_SAFI_VALUE)) { | 132 | && (safi == Constants.VPN_SAFI_VALUE)) { |
133 | byte nextHopLen = tempCb.readByte(); | 133 | byte nextHopLen = tempCb.readByte(); |
134 | - InetAddress ipAddress = Validation.toInetAddress(nextHopLen, cb); | 134 | + InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb); |
135 | if (ipAddress.isMulticastAddress()) { | 135 | if (ipAddress.isMulticastAddress()) { |
136 | throw new BgpParseException("Multicast not supported"); | 136 | throw new BgpParseException("Multicast not supported"); |
137 | } | 137 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgpio.protocol; | ||
17 | + | ||
18 | + | ||
19 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
20 | +import static org.hamcrest.Matchers.instanceOf; | ||
21 | +import static org.hamcrest.core.Is.is; | ||
22 | + | ||
23 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
24 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
25 | +import org.junit.Test; | ||
26 | +import org.onlab.packet.IpAddress; | ||
27 | +import org.onlab.packet.IpPrefix; | ||
28 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
29 | +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | ||
30 | +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; | ||
31 | +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; | ||
32 | +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType; | ||
33 | +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; | ||
34 | +import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; | ||
35 | +import org.onosproject.bgpio.types.As4Path; | ||
36 | +import org.onosproject.bgpio.types.AsPath; | ||
37 | +import org.onosproject.bgpio.types.AutonomousSystemTlv; | ||
38 | +import org.onosproject.bgpio.types.BgpHeader; | ||
39 | +import org.onosproject.bgpio.types.BgpLSIdentifierTlv; | ||
40 | +import org.onosproject.bgpio.types.BgpValueType; | ||
41 | +import org.onosproject.bgpio.types.IPReachabilityInformationTlv; | ||
42 | +import org.onosproject.bgpio.types.IsIsNonPseudonode; | ||
43 | +import org.onosproject.bgpio.types.IsIsPseudonode; | ||
44 | +import org.onosproject.bgpio.types.Med; | ||
45 | +import org.onosproject.bgpio.types.MpReachNlri; | ||
46 | +import org.onosproject.bgpio.types.MpUnReachNlri; | ||
47 | +import org.onosproject.bgpio.types.Origin; | ||
48 | +import org.onosproject.bgpio.types.NextHop; | ||
49 | +import org.onosproject.bgpio.types.LocalPref; | ||
50 | +import org.onosproject.bgpio.types.Origin.ORIGINTYPE; | ||
51 | +import org.slf4j.Logger; | ||
52 | +import org.slf4j.LoggerFactory; | ||
53 | + | ||
54 | +import java.util.LinkedList; | ||
55 | +import java.util.List; | ||
56 | +import java.util.ListIterator; | ||
57 | + | ||
58 | +/** | ||
59 | + * Test cases for BGP update Message. | ||
60 | + */ | ||
61 | +public class BgpUpdateMsgTest { | ||
62 | + protected static final Logger log = LoggerFactory.getLogger(BgpUpdateMsgTest.class); | ||
63 | + public static final byte[] MARKER = new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
64 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
65 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; | ||
66 | + public static final byte UPDATE_MSG_TYPE = 0x2; | ||
67 | + | ||
68 | + /** | ||
69 | + * This test case checks update message with no withdrawn routes | ||
70 | + * and path attributes. | ||
71 | + */ | ||
72 | + @Test | ||
73 | + public void bgpUpdateMessageTest01() throws BgpParseException { | ||
74 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
75 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
76 | + (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x02, 0x00, 0x00, 0x00, 0x00}; | ||
77 | + | ||
78 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
79 | + buffer.writeBytes(updateMsg); | ||
80 | + | ||
81 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
82 | + BgpMessage message; | ||
83 | + BgpHeader bgpHeader = new BgpHeader(); | ||
84 | + | ||
85 | + message = reader.readFrom(buffer, bgpHeader); | ||
86 | + | ||
87 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
88 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
89 | + | ||
90 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
91 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
92 | + assertThat(other.getHeader().getLength(), is((short) 23)); | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * In this test case, Marker is set as 0 in input and expecting | ||
97 | + * an exception. | ||
98 | + */ | ||
99 | + @Test(expected = BgpParseException.class) | ||
100 | + public void bgpUpdateMessageTest02() throws BgpParseException { | ||
101 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
102 | + 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
103 | + (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x02, 0x00, 0x00, 0x00, 0x00}; | ||
104 | + | ||
105 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
106 | + buffer.writeBytes(updateMsg); | ||
107 | + | ||
108 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
109 | + BgpMessage message; | ||
110 | + BgpHeader bgpHeader = new BgpHeader(); | ||
111 | + message = reader.readFrom(buffer, bgpHeader); | ||
112 | + | ||
113 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * In this test case, Invalid message length is given as input and expecting | ||
118 | + * an exception. | ||
119 | + */ | ||
120 | + @Test(expected = BgpParseException.class) | ||
121 | + public void bgpUpdateMessageTest03() throws BgpParseException { | ||
122 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
123 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
124 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x18, 0x02, 0x00, 0x00, 0x00, 0x00}; | ||
125 | + | ||
126 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
127 | + buffer.writeBytes(updateMsg); | ||
128 | + | ||
129 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
130 | + BgpMessage message; | ||
131 | + BgpHeader bgpHeader = new BgpHeader(); | ||
132 | + message = reader.readFrom(buffer, bgpHeader); | ||
133 | + | ||
134 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * In this test case, Invalid message type is given as input and expecting | ||
139 | + * an exception. | ||
140 | + */ | ||
141 | + @Test(expected = BgpParseException.class) | ||
142 | + public void bgpUpdateMessageTest04() throws BgpParseException { | ||
143 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
144 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
145 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x06, 0x00, 0x00, 0x00, 0x00}; | ||
146 | + | ||
147 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
148 | + buffer.writeBytes(updateMsg); | ||
149 | + | ||
150 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
151 | + BgpMessage message; | ||
152 | + BgpHeader bgpHeader = new BgpHeader(); | ||
153 | + message = reader.readFrom(buffer, bgpHeader); | ||
154 | + | ||
155 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * This test case checks update message with withdrawn routes. | ||
160 | + */ | ||
161 | + @Test | ||
162 | + public void bgpUpdateMessageTest05() throws BgpParseException { | ||
163 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
164 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
165 | + (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x00}; | ||
166 | + | ||
167 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
168 | + buffer.writeBytes(updateMsg); | ||
169 | + | ||
170 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
171 | + BgpMessage message; | ||
172 | + BgpHeader bgpHeader = new BgpHeader(); | ||
173 | + | ||
174 | + message = reader.readFrom(buffer, bgpHeader); | ||
175 | + | ||
176 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
177 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
178 | + | ||
179 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
180 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
181 | + assertThat(other.getHeader().getLength(), is((short) 27)); | ||
182 | + | ||
183 | + ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); | ||
184 | + byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; | ||
185 | + | ||
186 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
187 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
188 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * In this test case, Invalid withdrawn route length is given as input and expecting | ||
193 | + * an exception. | ||
194 | + */ | ||
195 | + @Test(expected = BgpParseException.class) | ||
196 | + public void bgpUpdateMessageTest06() throws BgpParseException { | ||
197 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
198 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
199 | + (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x19, 0x0a, 0x01, 0x01, 0x00, 0x00}; | ||
200 | + | ||
201 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
202 | + buffer.writeBytes(updateMsg); | ||
203 | + | ||
204 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
205 | + BgpMessage message; | ||
206 | + BgpHeader bgpHeader = new BgpHeader(); | ||
207 | + | ||
208 | + message = reader.readFrom(buffer, bgpHeader); | ||
209 | + | ||
210 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
211 | + } | ||
212 | + | ||
213 | + /** | ||
214 | + * This test case checks update message with path attributes. | ||
215 | + */ | ||
216 | + @Test | ||
217 | + public void bgpUpdateMessageTest07() throws BgpParseException { | ||
218 | + byte[] updateMsg = new byte [] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
219 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
220 | + (byte) 0xff, (byte) 0xff, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x00, 0x1c, 0x40, 0x01, 0x01, | ||
221 | + 0x00, 0x40, 0x02, 0x00, 0x40, 0x03, 0x04, 0x03, 0x03, 0x03, 0x03, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, | ||
222 | + 0x00, 0x00, 0x40, 0x05, 0x04, 0x00, 0x00, 0x00, 0x64, 0x18, 0x0a, 0x1e, 0x03, 0x18, 0x0a, 0x1e, | ||
223 | + 0x02, 0x18, 0x0a, 0x1e, 0x01}; | ||
224 | + | ||
225 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
226 | + buffer.writeBytes(updateMsg); | ||
227 | + | ||
228 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
229 | + BgpMessage message; | ||
230 | + BgpHeader bgpHeader = new BgpHeader(); | ||
231 | + | ||
232 | + message = reader.readFrom(buffer, bgpHeader); | ||
233 | + | ||
234 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
235 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
236 | + | ||
237 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
238 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
239 | + assertThat(other.getHeader().getLength(), is((short) 63)); | ||
240 | + | ||
241 | + BgpValueType testPathAttribute; | ||
242 | + Origin origin; | ||
243 | + AsPath asPath; | ||
244 | + NextHop nexthop; | ||
245 | + Med med; | ||
246 | + LocalPref localPref; | ||
247 | + | ||
248 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
249 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
250 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
251 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
252 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
253 | + | ||
254 | + testPathAttribute = listIterator.next(); | ||
255 | + origin = (Origin) testPathAttribute; | ||
256 | + assertThat(origin.origin(), is(originValue)); | ||
257 | + | ||
258 | + testPathAttribute = listIterator.next(); // AS PATH value is empty in hex dump | ||
259 | + asPath = (AsPath) testPathAttribute; | ||
260 | + List<Short> asPathValues = asPath.asPathSeq(); | ||
261 | + assertThat(asPathValues.isEmpty(), is(true)); | ||
262 | + | ||
263 | + testPathAttribute = listIterator.next(); | ||
264 | + nexthop = (NextHop) testPathAttribute; | ||
265 | + byte[] nextHopAddr = new byte[] {0x03, 0x03, 0x03, 0x03}; | ||
266 | + assertThat(nexthop.nextHop().toOctets(), is(nextHopAddr)); | ||
267 | + | ||
268 | + testPathAttribute = listIterator.next(); | ||
269 | + med = (Med) testPathAttribute; | ||
270 | + assertThat(med.med(), is(0)); | ||
271 | + | ||
272 | + testPathAttribute = listIterator.next(); | ||
273 | + localPref = (LocalPref) testPathAttribute; | ||
274 | + assertThat(localPref.localPref(), is(100)); | ||
275 | + | ||
276 | + ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator(); | ||
277 | + byte[] prefix = new byte[] {0x0a, 0x1e, 0x03, 0x00}; | ||
278 | + | ||
279 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
280 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
281 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
282 | + } | ||
283 | + | ||
284 | + /** | ||
285 | + * In this test case, Invalid ORIGIN flags is given as input and expecting | ||
286 | + * an exception. | ||
287 | + */ | ||
288 | + @Test(expected = BgpParseException.class) | ||
289 | + public void bgpUpdateMessageTest08() throws BgpParseException { | ||
290 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
291 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
292 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
293 | + 0x00, 0x49, //path attribute len | ||
294 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
295 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
296 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
297 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
298 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
299 | + 0x00, //reserved | ||
300 | + 0x00, 0x01, 0x00, | ||
301 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
302 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
303 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
304 | + | ||
305 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
306 | + buffer.writeBytes(updateMsg); | ||
307 | + | ||
308 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
309 | + BgpMessage message; | ||
310 | + BgpHeader bgpHeader = new BgpHeader(); | ||
311 | + | ||
312 | + message = reader.readFrom(buffer, bgpHeader); | ||
313 | + | ||
314 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
315 | + } | ||
316 | + | ||
317 | + /** | ||
318 | + * In this test case, Invalid ORIGIN value is given as input and expecting | ||
319 | + * an exception. | ||
320 | + */ | ||
321 | + @Test(expected = BgpParseException.class) | ||
322 | + public void bgpUpdateMessageTest09() throws BgpParseException { | ||
323 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
324 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
325 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
326 | + 0x00, 0x49, //path attribute len | ||
327 | + (byte) 0xff, 0x01, 0x04, 0x00, //origin | ||
328 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
329 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
330 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
331 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
332 | + 0x00, //reserved | ||
333 | + 0x00, 0x01, 0x00, | ||
334 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
335 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
336 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
337 | + | ||
338 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
339 | + buffer.writeBytes(updateMsg); | ||
340 | + | ||
341 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
342 | + BgpMessage message; | ||
343 | + BgpHeader bgpHeader = new BgpHeader(); | ||
344 | + | ||
345 | + message = reader.readFrom(buffer, bgpHeader); | ||
346 | + | ||
347 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
348 | + } | ||
349 | + | ||
350 | + /** | ||
351 | + * In this test case, update message without path attribute is given as input and expecting | ||
352 | + * an exception. | ||
353 | + */ | ||
354 | + @Test(expected = BgpParseException.class) | ||
355 | + public void bgpUpdateMessageTest10() throws BgpParseException { | ||
356 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
357 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
358 | + (byte) 0xff, (byte) 0xff, 0x00, 0x1a, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00}; | ||
359 | + | ||
360 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
361 | + buffer.writeBytes(updateMsg); | ||
362 | + | ||
363 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
364 | + BgpMessage message; | ||
365 | + BgpHeader bgpHeader = new BgpHeader(); | ||
366 | + | ||
367 | + message = reader.readFrom(buffer, bgpHeader); | ||
368 | + | ||
369 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
370 | + } | ||
371 | + | ||
372 | + /** | ||
373 | + * In this test case, update message with incorrect path attribute length is given as input and expecting | ||
374 | + * an exception. | ||
375 | + */ | ||
376 | + @Test(expected = BgpParseException.class) | ||
377 | + public void bgpUpdateMessageTest11() throws BgpParseException { | ||
378 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
379 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
380 | + (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x01}; | ||
381 | + | ||
382 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
383 | + buffer.writeBytes(updateMsg); | ||
384 | + | ||
385 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
386 | + BgpMessage message; | ||
387 | + BgpHeader bgpHeader = new BgpHeader(); | ||
388 | + | ||
389 | + message = reader.readFrom(buffer, bgpHeader); | ||
390 | + | ||
391 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
392 | + } | ||
393 | + | ||
394 | + /** | ||
395 | + * In this test case, Invalid MED flags is given as input and expecting | ||
396 | + * an exception. | ||
397 | + */ | ||
398 | + @Test(expected = BgpParseException.class) | ||
399 | + public void bgpUpdateMessageTest12() throws BgpParseException { | ||
400 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
401 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
402 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
403 | + 0x00, 0x49, //path attribute len | ||
404 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
405 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
406 | + (byte) 0xff, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
407 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
408 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
409 | + 0x00, //reserved | ||
410 | + 0x00, 0x01, 0x00, | ||
411 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
412 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
413 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
414 | + | ||
415 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
416 | + buffer.writeBytes(updateMsg); | ||
417 | + | ||
418 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
419 | + BgpMessage message; | ||
420 | + BgpHeader bgpHeader = new BgpHeader(); | ||
421 | + | ||
422 | + message = reader.readFrom(buffer, bgpHeader); | ||
423 | + | ||
424 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
425 | + } | ||
426 | + | ||
427 | + /** | ||
428 | + * In this test case, Invalid AS Path flags is given as input and expecting | ||
429 | + * an exception. | ||
430 | + */ | ||
431 | + @Test(expected = BgpParseException.class) | ||
432 | + public void bgpUpdateMessageTest13() throws BgpParseException { | ||
433 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
434 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
435 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
436 | + 0x00, 0x49, //path attribute len | ||
437 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
438 | + (byte) 0xff, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
439 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
440 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
441 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
442 | + 0x00, //reserved | ||
443 | + 0x00, 0x01, 0x00, | ||
444 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
445 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
446 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
447 | + | ||
448 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
449 | + buffer.writeBytes(updateMsg); | ||
450 | + | ||
451 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
452 | + BgpMessage message; | ||
453 | + BgpHeader bgpHeader = new BgpHeader(); | ||
454 | + | ||
455 | + message = reader.readFrom(buffer, bgpHeader); | ||
456 | + | ||
457 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
458 | + } | ||
459 | + | ||
460 | + /** | ||
461 | + * In this test case, Invalid MP reach flags is given as input and expecting | ||
462 | + * an exception. | ||
463 | + */ | ||
464 | + @Test(expected = BgpParseException.class) | ||
465 | + public void bgpUpdateMessageTest14() throws BgpParseException { | ||
466 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
467 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
468 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
469 | + 0x00, 0x49, //path attribute len | ||
470 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
471 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
472 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
473 | + (byte) 0xff, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
474 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
475 | + 0x00, //reserved | ||
476 | + 0x00, 0x01, 0x00, | ||
477 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
478 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
479 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
480 | + | ||
481 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
482 | + buffer.writeBytes(updateMsg); | ||
483 | + | ||
484 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
485 | + BgpMessage message; | ||
486 | + BgpHeader bgpHeader = new BgpHeader(); | ||
487 | + | ||
488 | + message = reader.readFrom(buffer, bgpHeader); | ||
489 | + | ||
490 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
491 | + } | ||
492 | + | ||
493 | + /** | ||
494 | + * In this test case, Invalid SAFI is given as input and expecting | ||
495 | + * an exception. | ||
496 | + */ | ||
497 | + @Test(expected = BgpParseException.class) | ||
498 | + public void bgpUpdateMessageTest15() throws BgpParseException { | ||
499 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
500 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
501 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
502 | + 0x00, 0x49, //path attribute len | ||
503 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
504 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
505 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
506 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x49, //mpreach with safi = 71 | ||
507 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
508 | + 0x00, //reserved | ||
509 | + 0x00, 0x01, 0x00, | ||
510 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
511 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
512 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
513 | + | ||
514 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
515 | + buffer.writeBytes(updateMsg); | ||
516 | + | ||
517 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
518 | + BgpMessage message; | ||
519 | + BgpHeader bgpHeader = new BgpHeader(); | ||
520 | + | ||
521 | + message = reader.readFrom(buffer, bgpHeader); | ||
522 | + | ||
523 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
524 | + } | ||
525 | + | ||
526 | + /** | ||
527 | + * In this test case, Invalid AFI is given as input and expecting | ||
528 | + * an exception. | ||
529 | + */ | ||
530 | + @Test(expected = BgpParseException.class) | ||
531 | + public void bgpUpdateMessageTest16() throws BgpParseException { | ||
532 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
533 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
534 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
535 | + 0x00, 0x49, //path attribute len | ||
536 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
537 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
538 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
539 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x06, 0x47, //mpreach with safi = 71 | ||
540 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
541 | + 0x00, //reserved | ||
542 | + 0x00, 0x01, 0x00, | ||
543 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
544 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
545 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
546 | + | ||
547 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
548 | + buffer.writeBytes(updateMsg); | ||
549 | + | ||
550 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
551 | + BgpMessage message; | ||
552 | + BgpHeader bgpHeader = new BgpHeader(); | ||
553 | + | ||
554 | + message = reader.readFrom(buffer, bgpHeader); | ||
555 | + | ||
556 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
557 | + } | ||
558 | + | ||
559 | + /** | ||
560 | + * In this test case, Invalid res is given as input and expecting | ||
561 | + * an exception. | ||
562 | + */ | ||
563 | + @Test(expected = BgpParseException.class) | ||
564 | + public void bgpUpdateMessageTest17() throws BgpParseException { | ||
565 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
566 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
567 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
568 | + 0x00, 0x49, //path attribute len | ||
569 | + (byte) 0xff, 0x01, 0x01, 0x00, //origin | ||
570 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
571 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
572 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
573 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
574 | + 0x01, //reserved | ||
575 | + 0x00, 0x01, 0x00, | ||
576 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
577 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
578 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; | ||
579 | + | ||
580 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
581 | + buffer.writeBytes(updateMsg); | ||
582 | + | ||
583 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
584 | + BgpMessage message; | ||
585 | + BgpHeader bgpHeader = new BgpHeader(); | ||
586 | + | ||
587 | + message = reader.readFrom(buffer, bgpHeader); | ||
588 | + | ||
589 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
590 | + } | ||
591 | + | ||
592 | + /** | ||
593 | + * This test case checks update message with node NLRI. | ||
594 | + */ | ||
595 | + @Test | ||
596 | + public void bgpUpdateMessageTest18() throws BgpParseException { | ||
597 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
598 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
599 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
600 | + 0x00, 0x49, //path attribute len | ||
601 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
602 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
603 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
604 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
605 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
606 | + 0x00, //reserved | ||
607 | + 0x00, 0x01, 0x00, | ||
608 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
609 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
610 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri | ||
611 | + | ||
612 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
613 | + buffer.writeBytes(updateMsg); | ||
614 | + | ||
615 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
616 | + BgpMessage message; | ||
617 | + BgpHeader bgpHeader = new BgpHeader(); | ||
618 | + | ||
619 | + message = reader.readFrom(buffer, bgpHeader); | ||
620 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
621 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
622 | + | ||
623 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
624 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
625 | + assertThat(other.getHeader().getLength(), is((short) 96)); | ||
626 | + | ||
627 | + BgpValueType testPathAttribute; | ||
628 | + Origin origin; | ||
629 | + AsPath asPath; | ||
630 | + Med med; | ||
631 | + MpReachNlri mpReach; | ||
632 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
633 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
634 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
635 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
636 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
637 | + | ||
638 | + testPathAttribute = listIterator.next(); | ||
639 | + origin = (Origin) testPathAttribute; | ||
640 | + assertThat(origin.origin(), is(originValue)); | ||
641 | + | ||
642 | + testPathAttribute = listIterator.next(); | ||
643 | + asPath = (AsPath) testPathAttribute; | ||
644 | + ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); | ||
645 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
646 | + | ||
647 | + testPathAttribute = listIterator.next(); | ||
648 | + med = (Med) testPathAttribute; | ||
649 | + assertThat(med.med(), is(0)); | ||
650 | + | ||
651 | + testPathAttribute = listIterator.next(); | ||
652 | + mpReach = (MpReachNlri) testPathAttribute; | ||
653 | + assertThat(mpReach.mpReachNlriLen(), is((int) 52)); | ||
654 | + assertThat(mpReach.getType(), is((short) 14)); | ||
655 | + | ||
656 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
657 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
658 | + | ||
659 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
660 | + BgpLSNlri testnlri = list1.next(); | ||
661 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE; | ||
662 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
663 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
664 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
665 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
666 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
667 | + | ||
668 | + BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri; | ||
669 | + | ||
670 | + BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors(); | ||
671 | + | ||
672 | + List<BgpValueType> testSubTlvs = new LinkedList<>(); | ||
673 | + NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors(); | ||
674 | + testSubTlvs = localNodeDescriptors.getSubTlvs(); | ||
675 | + ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); | ||
676 | + | ||
677 | + AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); | ||
678 | + assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); | ||
679 | + assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); | ||
680 | + | ||
681 | + BgpLSIdentifierTlv testBGPLSIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); | ||
682 | + assertThat(testBGPLSIdentifierTlv.getBgpLsIdentifier(), is(33686018)); | ||
683 | + assertThat(testBGPLSIdentifierTlv.getType(), is((short) 513)); | ||
684 | + | ||
685 | + IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); | ||
686 | + byte[] expISONodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; | ||
687 | + assertThat(testIsIsNonPseudonode.getISONodeID(), is(expISONodeID)); | ||
688 | + assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); | ||
689 | + | ||
690 | + } | ||
691 | + | ||
692 | + /** | ||
693 | + * This test case checks update message with prefix NLRI. | ||
694 | + */ | ||
695 | + @Test | ||
696 | + public void bgpUpdateMessageTest19() throws BgpParseException { | ||
697 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
698 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
699 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, | ||
700 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
701 | + 0x00, (byte) 0xbb, //path attribute len | ||
702 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
703 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
704 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
705 | + (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach | ||
706 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
707 | + 0x00, //reserved | ||
708 | + 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, | ||
709 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
710 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
711 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
712 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, | ||
713 | + 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
714 | + (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, | ||
715 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
716 | + 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, | ||
717 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
718 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, | ||
719 | + 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, | ||
720 | + 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, | ||
721 | + 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, | ||
722 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
723 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
724 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
725 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, | ||
726 | + 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
727 | + 0x16, 0x16, 0x16, 0x16}; // prefix nlri | ||
728 | + | ||
729 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
730 | + buffer.writeBytes(updateMsg); | ||
731 | + | ||
732 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
733 | + BgpMessage message; | ||
734 | + BgpHeader bgpHeader = new BgpHeader(); | ||
735 | + | ||
736 | + message = reader.readFrom(buffer, bgpHeader); | ||
737 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
738 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
739 | + | ||
740 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
741 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
742 | + assertThat(other.getHeader().getLength(), is((short) 214)); | ||
743 | + | ||
744 | + ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); | ||
745 | + byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; | ||
746 | + | ||
747 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
748 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
749 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
750 | + | ||
751 | + BgpValueType testPathAttribute; | ||
752 | + Origin origin; | ||
753 | + AsPath asPath; | ||
754 | + Med med; | ||
755 | + MpReachNlri mpReach; | ||
756 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
757 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
758 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
759 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
760 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
761 | + | ||
762 | + testPathAttribute = listIterator.next(); | ||
763 | + origin = (Origin) testPathAttribute; | ||
764 | + assertThat(origin.origin(), is(originValue)); | ||
765 | + | ||
766 | + testPathAttribute = listIterator.next(); | ||
767 | + asPath = (AsPath) testPathAttribute; | ||
768 | + ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); | ||
769 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
770 | + | ||
771 | + testPathAttribute = listIterator.next(); | ||
772 | + med = (Med) testPathAttribute; | ||
773 | + assertThat(med.med(), is(0)); | ||
774 | + | ||
775 | + testPathAttribute = listIterator.next(); | ||
776 | + mpReach = (MpReachNlri) testPathAttribute; | ||
777 | + assertThat(mpReach.mpReachNlriLen(), is((int) 165)); | ||
778 | + assertThat(mpReach.getType(), is((short) 14)); | ||
779 | + | ||
780 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
781 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
782 | + | ||
783 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
784 | + BgpLSNlri testnlri = list1.next(); | ||
785 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.PREFIX_IPV4; | ||
786 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
787 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
788 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
789 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
790 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
791 | + | ||
792 | + BgpPrefixLSNlri testprefixnlri = (BgpPrefixLSNlri) testnlri; | ||
793 | + | ||
794 | + NodeDescriptors testLocalNodeDescriptors = testprefixnlri.getLocalNodeDescriptors(); | ||
795 | + | ||
796 | + List<BgpValueType> testSubTlvs = new LinkedList<>(); | ||
797 | + testSubTlvs = testLocalNodeDescriptors.getSubTlvs(); | ||
798 | + ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); | ||
799 | + | ||
800 | + AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); | ||
801 | + assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); | ||
802 | + assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); | ||
803 | + | ||
804 | + BgpLSIdentifierTlv testBGPLSIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); | ||
805 | + assertThat(testBGPLSIdentifierTlv.getBgpLsIdentifier(), is(33686018)); | ||
806 | + assertThat(testBGPLSIdentifierTlv.getType(), is((short) 513)); | ||
807 | + | ||
808 | + IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); | ||
809 | + byte[] expISONodeID = new byte[] {0x19, 0x21, 0x68, 0x07, 0x70, 0x01}; | ||
810 | + assertThat(testIsIsNonPseudonode.getISONodeID(), is(expISONodeID)); | ||
811 | + assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); | ||
812 | + | ||
813 | + List<BgpValueType> testPrefixDescriptors = new LinkedList<>(); | ||
814 | + testPrefixDescriptors = testprefixnlri.getPrefixdescriptor(); | ||
815 | + ListIterator<BgpValueType> subtlvlist2 = testPrefixDescriptors.listIterator(); | ||
816 | + IPReachabilityInformationTlv testIPReachabilityInformationTlv = (IPReachabilityInformationTlv) | ||
817 | + subtlvlist2.next(); | ||
818 | + byte[] address = new byte[] {(byte) 0xc0, (byte) 0xa8, 0x4d, 0x01}; | ||
819 | + IpPrefix prefix1 = IpPrefix.valueOf(IpAddress.Version.INET, address, 32); | ||
820 | + assertThat(testIPReachabilityInformationTlv.getPrefixValue(), is(prefix1)); | ||
821 | + assertThat(testIPReachabilityInformationTlv.getPrefixLen(), is((byte) 32)); | ||
822 | + } | ||
823 | + | ||
824 | + /** | ||
825 | + * This test case checks update message with link NLRI. | ||
826 | + */ | ||
827 | + @Test | ||
828 | + public void bgpUpdateMessageTest20() throws BgpParseException { | ||
829 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
830 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
831 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x83, 0x02, 0x00, 0x04, | ||
832 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
833 | + 0x00, 0x68, //path attribute len | ||
834 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
835 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
836 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
837 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
838 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
839 | + 0x00, //reserved | ||
840 | + 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
841 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
842 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
843 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
844 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
845 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
846 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
847 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21//link nlri | ||
848 | + }; | ||
849 | + | ||
850 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
851 | + buffer.writeBytes(updateMsg); | ||
852 | + | ||
853 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
854 | + BgpMessage message = null; | ||
855 | + BgpHeader bgpHeader = new BgpHeader(); | ||
856 | + | ||
857 | + message = reader.readFrom(buffer, bgpHeader); | ||
858 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
859 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
860 | + | ||
861 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
862 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
863 | + assertThat(other.getHeader().getLength(), is((short) 131)); | ||
864 | + | ||
865 | + ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); | ||
866 | + byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; | ||
867 | + | ||
868 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
869 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
870 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
871 | + | ||
872 | + BgpValueType testPathAttribute; | ||
873 | + Origin origin; | ||
874 | + AsPath asPath; | ||
875 | + Med med; | ||
876 | + MpReachNlri mpReach; | ||
877 | + | ||
878 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
879 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
880 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
881 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
882 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
883 | + | ||
884 | + testPathAttribute = listIterator.next(); | ||
885 | + origin = (Origin) testPathAttribute; | ||
886 | + assertThat(origin.origin(), is(originValue)); | ||
887 | + | ||
888 | + testPathAttribute = listIterator.next(); | ||
889 | + asPath = (AsPath) testPathAttribute; | ||
890 | + ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); | ||
891 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
892 | + | ||
893 | + testPathAttribute = listIterator.next(); | ||
894 | + med = (Med) testPathAttribute; | ||
895 | + assertThat(med.med(), is(0)); | ||
896 | + | ||
897 | + testPathAttribute = listIterator.next(); | ||
898 | + mpReach = (MpReachNlri) testPathAttribute; | ||
899 | + assertThat(mpReach.mpReachNlriLen(), is((int) 83)); | ||
900 | + assertThat(mpReach.getType(), is((short) 14)); | ||
901 | + | ||
902 | + List<BgpLSNlri> testMpReachNlri = new LinkedList<>(); | ||
903 | + testMpReachNlri = mpReach.mpReachNlri(); | ||
904 | + | ||
905 | + ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator(); | ||
906 | + BgpLSNlri testnlri = list1.next(); | ||
907 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK; | ||
908 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
909 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
910 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
911 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
912 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
913 | + | ||
914 | + BgpLinkLsNlriVer4 testlinknlri = (BgpLinkLsNlriVer4) testnlri; | ||
915 | + | ||
916 | + NodeDescriptors testLocalNodeDescriptors = testlinknlri.localNodeDescriptors(); | ||
917 | + | ||
918 | + List<BgpValueType> testSubTlvs = new LinkedList<>(); | ||
919 | + testSubTlvs = testLocalNodeDescriptors.getSubTlvs(); | ||
920 | + ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); | ||
921 | + | ||
922 | + AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); | ||
923 | + | ||
924 | + assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); | ||
925 | + assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); | ||
926 | + | ||
927 | + BgpLSIdentifierTlv testBGPLSIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); | ||
928 | + assertThat(testBGPLSIdentifierTlv.getBgpLsIdentifier(), is(33686018)); | ||
929 | + assertThat(testBGPLSIdentifierTlv.getType(), is((short) 513)); | ||
930 | + | ||
931 | + IsIsPseudonode testIsIsPseudonode = (IsIsPseudonode) subtlvlist1.next(); | ||
932 | + assertThat(testIsIsPseudonode.getPSNIdentifier(), is((byte) 3)); | ||
933 | + assertThat(testIsIsPseudonode.getType(), is((short) 515)); | ||
934 | + | ||
935 | + NodeDescriptors testRemoteNodeDescriptors = testlinknlri.remoteNodeDescriptors(); | ||
936 | + testSubTlvs = testRemoteNodeDescriptors.getSubTlvs(); | ||
937 | + ListIterator<BgpValueType> subtlvlist2 = testSubTlvs.listIterator(); | ||
938 | + | ||
939 | + testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist2.next(); | ||
940 | + | ||
941 | + assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); | ||
942 | + assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); | ||
943 | + | ||
944 | + testBGPLSIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist2.next(); | ||
945 | + assertThat(testBGPLSIdentifierTlv.getBgpLsIdentifier(), is(33686018)); | ||
946 | + assertThat(testBGPLSIdentifierTlv.getType(), is((short) 513)); | ||
947 | + | ||
948 | + IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist2.next(); | ||
949 | + byte[] expISONodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21}; | ||
950 | + assertThat(testIsIsNonPseudonode.getISONodeID(), is(expISONodeID)); | ||
951 | + assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); | ||
952 | + } | ||
953 | + | ||
954 | + /** | ||
955 | + * In this test case, Invalid withdrawn route length is given as input and expecting | ||
956 | + * an exception. | ||
957 | + */ | ||
958 | + @Test(expected = BgpParseException.class) | ||
959 | + public void bgpUpdateMessageTest21() throws BgpParseException { | ||
960 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
961 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
962 | + (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x07, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x00}; | ||
963 | + | ||
964 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
965 | + buffer.writeBytes(updateMsg); | ||
966 | + | ||
967 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
968 | + BgpMessage message; | ||
969 | + BgpHeader bgpHeader = new BgpHeader(); | ||
970 | + | ||
971 | + message = reader.readFrom(buffer, bgpHeader); | ||
972 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
973 | + } | ||
974 | + | ||
975 | + /** | ||
976 | + * In this test case, Invalid withdrawn route length is given as input and expecting | ||
977 | + * an exception. | ||
978 | + */ | ||
979 | + @Test(expected = BgpParseException.class) | ||
980 | + public void bgpUpdateMessageTest22() throws BgpParseException { | ||
981 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
982 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
983 | + (byte) 0xff, (byte) 0xff, 0x00, 0x25, 0x02, 0x00, 0x00, //withdrawn len | ||
984 | + 0x00, 0x0e, //path attribute len | ||
985 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
986 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med | ||
987 | + | ||
988 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
989 | + buffer.writeBytes(updateMsg); | ||
990 | + | ||
991 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
992 | + BgpMessage message; | ||
993 | + BgpHeader bgpHeader = new BgpHeader(); | ||
994 | + | ||
995 | + message = reader.readFrom(buffer, bgpHeader); | ||
996 | + | ||
997 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
998 | + } | ||
999 | + | ||
1000 | + /** | ||
1001 | + * In this test case, Mandatory attributes are not given in input and expecting | ||
1002 | + * an exception. | ||
1003 | + */ | ||
1004 | + @Test(expected = BgpParseException.class) | ||
1005 | + public void bgpUpdateMessageTest23() throws BgpParseException { | ||
1006 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1007 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1008 | + (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len | ||
1009 | + 0x00, 0x12, //path attribute len | ||
1010 | + 0x0e, 0x01, 0x01, 0x00, //origin | ||
1011 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1012 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med | ||
1013 | + | ||
1014 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1015 | + buffer.writeBytes(updateMsg); | ||
1016 | + | ||
1017 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1018 | + BgpMessage message; | ||
1019 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1020 | + | ||
1021 | + message = reader.readFrom(buffer, bgpHeader); | ||
1022 | + | ||
1023 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1024 | + } | ||
1025 | + | ||
1026 | + /** | ||
1027 | + * In this test case, Invalid origin length is given as input and expecting | ||
1028 | + * an exception. | ||
1029 | + */ | ||
1030 | + @Test(expected = BgpParseException.class) | ||
1031 | + public void bgpUpdateMessageTest24() throws BgpParseException { | ||
1032 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1033 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1034 | + (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len | ||
1035 | + 0x00, 0x12, //path attribute len | ||
1036 | + 0x04, 0x01, 0x02, 0x00, //origin | ||
1037 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1038 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med | ||
1039 | + | ||
1040 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1041 | + buffer.writeBytes(updateMsg); | ||
1042 | + | ||
1043 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1044 | + BgpMessage message; | ||
1045 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1046 | + | ||
1047 | + message = reader.readFrom(buffer, bgpHeader); | ||
1048 | + | ||
1049 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1050 | + } | ||
1051 | + | ||
1052 | + /** | ||
1053 | + * In this test case, Invalid origin value is given as input and expecting | ||
1054 | + * an exception. | ||
1055 | + */ | ||
1056 | + @Test(expected = BgpParseException.class) | ||
1057 | + public void bgpUpdateMessageTest25() throws BgpParseException { | ||
1058 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1059 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1060 | + (byte) 0xff, (byte) 0xff, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len | ||
1061 | + 0x00, 0x12, //path attribute len | ||
1062 | + 0x04, 0x01, 0x01, 0x04, //origin | ||
1063 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1064 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med | ||
1065 | + | ||
1066 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1067 | + buffer.writeBytes(updateMsg); | ||
1068 | + | ||
1069 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1070 | + BgpMessage message; | ||
1071 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1072 | + | ||
1073 | + message = reader.readFrom(buffer, bgpHeader); | ||
1074 | + | ||
1075 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1076 | + } | ||
1077 | + | ||
1078 | + /** | ||
1079 | + * In this test case, Invalid descriptor type in node nlri is given as input and expecting | ||
1080 | + * an exception. | ||
1081 | + */ | ||
1082 | + @Test(expected = BgpParseException.class) | ||
1083 | + public void bgpUpdateMessageTest26() throws BgpParseException { | ||
1084 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1085 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1086 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
1087 | + 0x00, 0x49, //path attribute len | ||
1088 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1089 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1090 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1091 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
1092 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1093 | + 0x00, //reserved | ||
1094 | + 0x00, 0x01, 0x00, | ||
1095 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
1096 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
1097 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri | ||
1098 | + | ||
1099 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1100 | + buffer.writeBytes(updateMsg); | ||
1101 | + | ||
1102 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1103 | + BgpMessage message; | ||
1104 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1105 | + | ||
1106 | + message = reader.readFrom(buffer, bgpHeader); | ||
1107 | + | ||
1108 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1109 | + } | ||
1110 | + | ||
1111 | + /** | ||
1112 | + * In this test case, Invalid node nlri length field in is given as input and expecting | ||
1113 | + * an exception. | ||
1114 | + */ | ||
1115 | + @Test(expected = BgpParseException.class) | ||
1116 | + public void bgpUpdateMessageTest27() throws BgpParseException { | ||
1117 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1118 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1119 | + (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len | ||
1120 | + 0x00, 0x49, //path attribute len | ||
1121 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1122 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1123 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1124 | + (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 | ||
1125 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1126 | + 0x00, //reserved | ||
1127 | + 0x00, 0x01, 0x00, | ||
1128 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, | ||
1129 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
1130 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri | ||
1131 | + | ||
1132 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1133 | + buffer.writeBytes(updateMsg); | ||
1134 | + | ||
1135 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1136 | + BgpMessage message; | ||
1137 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1138 | + | ||
1139 | + message = reader.readFrom(buffer, bgpHeader); | ||
1140 | + | ||
1141 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1142 | + } | ||
1143 | + | ||
1144 | + /** | ||
1145 | + * In this test case, withdrawn routes with prefix length 0 is given as input and expecting | ||
1146 | + * an exception. | ||
1147 | + */ | ||
1148 | + @Test | ||
1149 | + public void bgpUpdateMessageTest28() throws BgpParseException { | ||
1150 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1151 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1152 | + (byte) 0xff, (byte) 0xff, //marker | ||
1153 | + 0x00, 0x18, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00}; | ||
1154 | + | ||
1155 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1156 | + buffer.writeBytes(updateMsg); | ||
1157 | + | ||
1158 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1159 | + BgpMessage message; | ||
1160 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1161 | + | ||
1162 | + message = reader.readFrom(buffer, bgpHeader); | ||
1163 | + | ||
1164 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1165 | + } | ||
1166 | + | ||
1167 | + /** | ||
1168 | + * In this test case, update message without total Path Attribute Length field is given as | ||
1169 | + * input and expecting an exception. | ||
1170 | + */ | ||
1171 | + @Test(expected = BgpParseException.class) | ||
1172 | + public void bgpUpdateMessageTest29() throws BgpParseException { | ||
1173 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1174 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1175 | + (byte) 0xff, (byte) 0xff, //marker | ||
1176 | + 0x00, 0x16, 0x02, 0x00, 0x01, 0x00}; | ||
1177 | + | ||
1178 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1179 | + buffer.writeBytes(updateMsg); | ||
1180 | + | ||
1181 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1182 | + BgpMessage message; | ||
1183 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1184 | + | ||
1185 | + message = reader.readFrom(buffer, bgpHeader); | ||
1186 | + | ||
1187 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1188 | + } | ||
1189 | + | ||
1190 | + /** | ||
1191 | + * This test case checks update message with as4 path attribute. | ||
1192 | + */ | ||
1193 | + @Test | ||
1194 | + public void bgpUpdateMessageTest30() throws BgpParseException { | ||
1195 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1196 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1197 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1198 | + 0x00, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x21, 0x40, 0x01, 0x01, 0x00, (byte) 0xc0, | ||
1199 | + 0x11, 0x0a, 0x02, 0x02, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x28, 0x00, 0x01, 0x40, | ||
1200 | + 0x02, 0x06, 0x02, 0x02, 0x5b, (byte) 0xa0, 0x5b, (byte) 0xa0, 0x40, 0x03, 0x04, | ||
1201 | + (byte) 0xac, 0x10, 0x03, 0x01, 0x08, 0x28}; | ||
1202 | + | ||
1203 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1204 | + buffer.writeBytes(updateMsg); | ||
1205 | + | ||
1206 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1207 | + BgpMessage message = null; | ||
1208 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1209 | + | ||
1210 | + message = reader.readFrom(buffer, bgpHeader); | ||
1211 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1212 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
1213 | + | ||
1214 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
1215 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
1216 | + assertThat(other.getHeader().getLength(), is((short) 58)); | ||
1217 | + | ||
1218 | + BgpValueType testPathAttribute; | ||
1219 | + Origin origin; | ||
1220 | + As4Path as4Path; | ||
1221 | + AsPath asPath; | ||
1222 | + NextHop nextHop; | ||
1223 | + | ||
1224 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
1225 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
1226 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
1227 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
1228 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
1229 | + | ||
1230 | + testPathAttribute = listIterator.next(); | ||
1231 | + origin = (Origin) testPathAttribute; | ||
1232 | + assertThat(origin.origin(), is(originValue)); | ||
1233 | + | ||
1234 | + testPathAttribute = listIterator.next(); | ||
1235 | + as4Path = (As4Path) testPathAttribute; | ||
1236 | + ListIterator<Integer> listIterator2 = as4Path.as4PathSEQ().listIterator(); | ||
1237 | + assertThat(listIterator2.next(), is(655361)); | ||
1238 | + | ||
1239 | + testPathAttribute = listIterator.next(); | ||
1240 | + asPath = (AsPath) testPathAttribute; | ||
1241 | + ListIterator<Short> listIterator3 = asPath.asPathSeq().listIterator(); | ||
1242 | + assertThat(listIterator3.next(), is((short) 23456)); | ||
1243 | + | ||
1244 | + testPathAttribute = listIterator.next(); | ||
1245 | + nextHop = (NextHop) testPathAttribute; | ||
1246 | + byte[] nextHopAddr = new byte[] {(byte) 0xac, 0x10, 0x03, 0x01}; | ||
1247 | + assertThat(nextHop.nextHop().toOctets(), is(nextHopAddr)); | ||
1248 | + | ||
1249 | + ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator(); | ||
1250 | + byte[] prefix = new byte[] {0x28, 0x00, 0x00, 0x00}; | ||
1251 | + | ||
1252 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
1253 | + assertThat(testPrefixValue.prefixLength(), is((int) 8)); | ||
1254 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
1255 | + } | ||
1256 | + | ||
1257 | + /** | ||
1258 | + * This test case checks update message with MPUnreach. | ||
1259 | + */ | ||
1260 | + @Test | ||
1261 | + public void bgpUpdateMessageTest31() throws BgpParseException { | ||
1262 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1263 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1264 | + (byte) 0xff, (byte) 0xff, 0x00, 0x5e, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1265 | + 0x00, 0x43, //path attribute len | ||
1266 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1267 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1268 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1269 | + (byte) 0x80, 0x0f, 0x2e, 0x40, 0x04, 0x47, //mpunreach with safi = 71 | ||
1270 | + 0x00, 0x01, 0x00, | ||
1271 | + 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, | ||
1272 | + 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | ||
1273 | + 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri | ||
1274 | + | ||
1275 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1276 | + buffer.writeBytes(updateMsg); | ||
1277 | + | ||
1278 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1279 | + BgpMessage message; | ||
1280 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1281 | + | ||
1282 | + message = reader.readFrom(buffer, bgpHeader); | ||
1283 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1284 | + BgpUpdateMsg other = (BgpUpdateMsg) message; | ||
1285 | + | ||
1286 | + assertThat(other.getHeader().getMarker(), is(MARKER)); | ||
1287 | + assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE)); | ||
1288 | + assertThat(other.getHeader().getLength(), is((short) 94)); | ||
1289 | + | ||
1290 | + ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator(); | ||
1291 | + byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00}; | ||
1292 | + | ||
1293 | + IpPrefix testPrefixValue = listIterator1.next(); | ||
1294 | + assertThat(testPrefixValue.prefixLength(), is((int) 24)); | ||
1295 | + assertThat(testPrefixValue.address().toOctets(), is(prefix)); | ||
1296 | + | ||
1297 | + BgpValueType testPathAttribute; | ||
1298 | + Origin origin; | ||
1299 | + AsPath asPath; | ||
1300 | + Med med; | ||
1301 | + MpUnReachNlri mpUnReach; | ||
1302 | + List<BgpValueType> pathAttributes = new LinkedList<>(); | ||
1303 | + BgpPathAttributes actualpathAttribute = other.bgpPathAttributes(); | ||
1304 | + pathAttributes = actualpathAttribute.pathAttributes(); | ||
1305 | + ListIterator<BgpValueType> listIterator = pathAttributes.listIterator(); | ||
1306 | + ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP; | ||
1307 | + | ||
1308 | + testPathAttribute = listIterator.next(); | ||
1309 | + origin = (Origin) testPathAttribute; | ||
1310 | + assertThat(origin.origin(), is(originValue)); | ||
1311 | + | ||
1312 | + testPathAttribute = listIterator.next(); | ||
1313 | + asPath = (AsPath) testPathAttribute; | ||
1314 | + ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator(); | ||
1315 | + assertThat(listIterator2.next(), is((short) 65001)); | ||
1316 | + | ||
1317 | + testPathAttribute = listIterator.next(); | ||
1318 | + med = (Med) testPathAttribute; | ||
1319 | + assertThat(med.med(), is(0)); | ||
1320 | + | ||
1321 | + testPathAttribute = listIterator.next(); | ||
1322 | + mpUnReach = (MpUnReachNlri) testPathAttribute; | ||
1323 | + assertThat(mpUnReach.mpUnReachNlriLen(), is((int) 46)); | ||
1324 | + assertThat(mpUnReach.getType(), is((short) 15)); | ||
1325 | + | ||
1326 | + List<BgpLSNlri> testMpUnReachNlri = new LinkedList<>(); | ||
1327 | + testMpUnReachNlri = mpUnReach.mpUnReachNlri(); | ||
1328 | + | ||
1329 | + ListIterator<BgpLSNlri> list1 = testMpUnReachNlri.listIterator(); | ||
1330 | + BgpLSNlri testnlri = list1.next(); | ||
1331 | + NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE; | ||
1332 | + ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate. | ||
1333 | + BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO; | ||
1334 | + assertThat(testnlri.getIdentifier(), is((long) 0)); | ||
1335 | + assertThat(testnlri.getNlriType(), is(nlriType)); | ||
1336 | + assertThat(testnlri.getProtocolId(), is(protocolId)); | ||
1337 | + | ||
1338 | + BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri; | ||
1339 | + | ||
1340 | + BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors(); | ||
1341 | + | ||
1342 | + List<BgpValueType> testSubTlvs = new LinkedList<>(); | ||
1343 | + NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors(); | ||
1344 | + testSubTlvs = localNodeDescriptors.getSubTlvs(); | ||
1345 | + ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator(); | ||
1346 | + | ||
1347 | + AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next(); | ||
1348 | + | ||
1349 | + assertThat(testAutonomousSystemTlv.getAsNum(), is(2222)); | ||
1350 | + assertThat(testAutonomousSystemTlv.getType(), is((short) 512)); | ||
1351 | + | ||
1352 | + BgpLSIdentifierTlv testBGPLSIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next(); | ||
1353 | + assertThat(testBGPLSIdentifierTlv.getBgpLsIdentifier(), is(33686018)); | ||
1354 | + assertThat(testBGPLSIdentifierTlv.getType(), is((short) 513)); | ||
1355 | + | ||
1356 | + IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next(); | ||
1357 | + byte[] expISONodeID = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; | ||
1358 | + assertThat(testIsIsNonPseudonode.getISONodeID(), is(expISONodeID)); | ||
1359 | + assertThat(testIsIsNonPseudonode.getType(), is((short) 515)); | ||
1360 | + } | ||
1361 | + | ||
1362 | + /** | ||
1363 | + * This test case checks update message with invalid mpreach packet. | ||
1364 | + */ | ||
1365 | + @Test(expected = BgpParseException.class) | ||
1366 | + public void bgpUpdateMessageTest32() throws BgpParseException { | ||
1367 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1368 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1369 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, | ||
1370 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1371 | + 0x00, (byte) 0xbb, //path attribute len | ||
1372 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1373 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1374 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1375 | + (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach | ||
1376 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1377 | + 0x00, //reserved | ||
1378 | + 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, | ||
1379 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, | ||
1380 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
1381 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
1382 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, | ||
1383 | + 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
1384 | + (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, | ||
1385 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1386 | + 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, | ||
1387 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1388 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, | ||
1389 | + 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, | ||
1390 | + 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, | ||
1391 | + 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, | ||
1392 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
1393 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
1394 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
1395 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, | ||
1396 | + 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
1397 | + 0x16, 0x16, 0x16, 0x16}; // prefix nlri | ||
1398 | + | ||
1399 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1400 | + buffer.writeBytes(updateMsg); | ||
1401 | + | ||
1402 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1403 | + BgpMessage message; | ||
1404 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1405 | + | ||
1406 | + message = reader.readFrom(buffer, bgpHeader); | ||
1407 | + | ||
1408 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1409 | + } | ||
1410 | + | ||
1411 | + /** | ||
1412 | + * This test case checks update message with invalid prefix nlri length in input. | ||
1413 | + */ | ||
1414 | + @Test(expected = BgpParseException.class) | ||
1415 | + public void bgpUpdateMessageTest33() throws BgpParseException { | ||
1416 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1417 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1418 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xd6, 0x02, 0x00, 0x04, | ||
1419 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1420 | + 0x00, (byte) 0xbb, //path attribute len | ||
1421 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1422 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1423 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1424 | + (byte) 0x90, 0x0e, 0x00, (byte) 0xa5, 0x40, 0x04, 0x47, //mpreach | ||
1425 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1426 | + 0x00, //reserved | ||
1427 | + 0x00, 0x03, 0x00, 0x35, 0x02, 0x00, 0x00, 0x00, | ||
1428 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
1429 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
1430 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
1431 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x21, 0x68, | ||
1432 | + 0x07, 0x70, 0x01, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
1433 | + (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01, 0x00, 0x03, 0x00, 0x30, | ||
1434 | + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1435 | + 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, | ||
1436 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1437 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, | ||
1438 | + 0x06, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x01, | ||
1439 | + 0x09, 0x00, 0x05, 0x20, 0x15, 0x15, 0x15, 0x15, | ||
1440 | + 0x00, 0x03, 0x00, 0x30, 0x02, 0x00, 0x00, 0x00, | ||
1441 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
1442 | + 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, | ||
1443 | + (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, | ||
1444 | + 0x02, 0x02, 0x03, 0x00, 0x06, 0x02, 0x20, 0x22, | ||
1445 | + 0x02, 0x20, 0x22, 0x01, 0x09, 0x00, 0x05, 0x20, | ||
1446 | + 0x16, 0x16, 0x16, 0x16}; // prefix nlri | ||
1447 | + | ||
1448 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1449 | + buffer.writeBytes(updateMsg); | ||
1450 | + | ||
1451 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1452 | + BgpMessage message; | ||
1453 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1454 | + | ||
1455 | + message = reader.readFrom(buffer, bgpHeader); | ||
1456 | + | ||
1457 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1458 | + } | ||
1459 | + | ||
1460 | + /** | ||
1461 | + * This test case checks update message with invalid link nlri length in input. | ||
1462 | + */ | ||
1463 | + @Test(expected = BgpParseException.class) | ||
1464 | + public void bgpUpdateMessageTest34() throws BgpParseException { | ||
1465 | + byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1466 | + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, | ||
1467 | + (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x83, 0x02, 0x00, 0x04, | ||
1468 | + 0x18, 0x0a, 0x01, 0x01, //withdrawn routes | ||
1469 | + 0x00, 0x68, //path attribute len | ||
1470 | + 0x04, 0x01, 0x01, 0x00, //origin | ||
1471 | + 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path | ||
1472 | + (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med | ||
1473 | + (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach | ||
1474 | + 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop | ||
1475 | + 0x00, //reserved | ||
1476 | + 0x00, 0x02, 0x00, 0x48, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1477 | + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, | ||
1478 | + 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, | ||
1479 | + 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, | ||
1480 | + (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, | ||
1481 | + 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, | ||
1482 | + 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, | ||
1483 | + 0x00, (byte) 0x95, 0x02, 0x50, 0x21}; //link nlri | ||
1484 | + | ||
1485 | + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); | ||
1486 | + buffer.writeBytes(updateMsg); | ||
1487 | + | ||
1488 | + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | ||
1489 | + BgpMessage message; | ||
1490 | + BgpHeader bgpHeader = new BgpHeader(); | ||
1491 | + | ||
1492 | + message = reader.readFrom(buffer, bgpHeader); | ||
1493 | + | ||
1494 | + assertThat(message, instanceOf(BgpUpdateMsg.class)); | ||
1495 | + } | ||
1496 | +} |
-
Please register or login to post a comment