blob: 3195d21c87fc0c9cfc022cc8675828e46530f44d [file] [log] [blame]
Priyanka B0ab34b92015-12-03 21:13:52 +05301/*
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 */
16package org.onosproject.bgpio.protocol;
17
18
19import static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.Matchers.instanceOf;
21import static org.hamcrest.core.Is.is;
22
23import org.jboss.netty.buffer.ChannelBuffer;
24import org.jboss.netty.buffer.ChannelBuffers;
25import org.junit.Test;
26import org.onlab.packet.Ip4Address;
27import org.onlab.packet.IpPrefix;
28import org.onosproject.bgpio.exceptions.BgpParseException;
29import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
30import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes;
31import org.onosproject.bgpio.types.AsPath;
32import org.onosproject.bgpio.types.BgpHeader;
33import org.onosproject.bgpio.types.BgpValueType;
34import org.onosproject.bgpio.types.LinkStateAttributes;
35import org.onosproject.bgpio.types.Med;
36import org.onosproject.bgpio.types.MpReachNlri;
37import org.onosproject.bgpio.types.Origin;
Jonathan Hart51539b82015-10-29 09:53:04 -070038import org.onosproject.bgpio.types.Origin.OriginType;
Priyanka B0ab34b92015-12-03 21:13:52 +053039import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv;
40import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId;
41import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
42import org.onosproject.bgpio.types.attr.BgpAttrNodeName;
43import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
44import org.onosproject.bgpio.types.attr.BgpAttrOpaqueNode;
45import org.onosproject.bgpio.types.attr.BgpLinkAttrIsIsAdminstGrp;
46import org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask;
47import org.onosproject.bgpio.types.attr.BgpLinkAttrOpaqLnkAttrib;
48import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType.ProtectionType;
49import org.onosproject.bgpio.types.attr.BgpLinkAttrSrlg;
50import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
51import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData;
52import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType;
53import org.onosproject.bgpio.types.attr.BgpPrefixAttrRouteTag;
54
55import java.util.ArrayList;
56import java.util.LinkedList;
57import java.util.List;
58import java.util.ListIterator;
59
60/**
61 * UT for Update Message (Link State Attribute and all its TLVs).
62 */
63public class BgpUpdateLinkStateAttrTest {
64
65 /**
66 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrIGPMetric.
67 *
68 * @throws BgpParseException while parsing update message
69 */
70 @Test
71 public void bgpUpdateMessageTest1() throws BgpParseException {
72 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
73 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
74 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95,
75 0x02, 0x00, 0x04,
76 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
77 0x00, 0x7A, //path attribute len
78 0x04, 0x01, 0x01, 0x00, //origin
79 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
80 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
81 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
82 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
83 0x00, //reserved
84 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
86 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
87 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
88 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
89 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
90 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
91 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
92 (byte) 0x80, 0x1d, 0x0f, //linkstate attr
93 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrNodeRouterId
94 0x04, 0x47, 0x00, 0x03, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric
95
96 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
97 buffer.writeBytes(updateMsg);
98
99 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
100 BgpMessage message = null;
101 BgpHeader bgpHeader = new BgpHeader();
102
103 message = reader.readFrom(buffer, bgpHeader);
104
105 assertThat(message, instanceOf(BgpUpdateMsg.class));
106 BgpUpdateMsg other = (BgpUpdateMsg) message;
107
108 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
109 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
110 (byte) 0xff, (byte) 0xff, (byte) 0xff };
111
112 assertThat(other.getHeader().getMarker(), is(marker));
113 assertThat(other.getHeader().getType(), is((byte) 2));
114 assertThat(other.getHeader().getLength(), is((short) 149));
115
116 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
117 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
118
119 while (listIterator1.hasNext()) {
120 IpPrefix testPrefixValue = listIterator1.next();
121 assertThat(testPrefixValue.prefixLength(), is((int) 24));
122 assertThat(testPrefixValue.address().toOctets(), is(prefix));
123 }
124
125 BgpValueType testPathAttribute = null;
126 Origin origin;
127 AsPath aspath;
128 Med med;
129 MpReachNlri mpReach;
130 LinkStateAttributes linkStateAttr;
131 List<BgpValueType> pathAttributeList = new LinkedList<>();
132 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
133 pathAttributeList = pathAttribute.pathAttributes();
134 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700135 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530136
137 //compare Origin
138 testPathAttribute = listIterator.next();
139 origin = (Origin) testPathAttribute;
140 assertThat(origin.origin(), is(originValue));
141
142 //compare Aspath
143 testPathAttribute = listIterator.next();
144 aspath = (AsPath) testPathAttribute;
145 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
146 assertThat(listIterator2.next(), is((short) 65001));
147
148 //compare MED
149 testPathAttribute = listIterator.next();
150 med = (Med) testPathAttribute;
151 assertThat(med.med(), is(0));
152
153 //compare Mpreach
154 testPathAttribute = listIterator.next();
155 mpReach = (MpReachNlri) testPathAttribute;
156 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
157 assertThat(mpReach.getType(), is((short) 14));
158
159 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
160 testMpReachNlri = mpReach.mpReachNlri();
161
162 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
163 BgpLSNlri testnlri = list1.next();
164 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
165 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
166 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
167 assertThat(testnlri.getIdentifier(), is((long) 0));
168 assertThat(testnlri.getNlriType(), is(nlriType));
169 assertThat(testnlri.getProtocolId(), is(protocolId));
170
171 //compare LinkStateAttributes
172 testPathAttribute = listIterator.next();
173 linkStateAttr = (LinkStateAttributes) testPathAttribute;
174 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x0f, 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c,
175 0x62, 0x04, 0x47, 0x00, 0x03, 0x00, 0x00, 0x0a };
176 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
177 cb.writeBytes(linkAttrbs);
178 LinkStateAttributes obj = LinkStateAttributes.read(cb);
179
180 assertThat(linkStateAttr.linkStateAttributes(), is(obj.linkStateAttributes()));
181 assertThat(linkStateAttr.getType(), is((short) 29));
182 }
183
184 /**
185 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeRouterId.
186 *
187 * @throws BgpParseException while parsing update message
188 */
189 @Test
190 public void bgpUpdateMessageTest2() throws BgpParseException {
191 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
192 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
193 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
194 0x02, 0x00, 0x04,
195 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
196 0x00, 0x7b, //path attribute len
197 0x04, 0x01, 0x01, 0x00, //origin
198 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
199 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
200 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
201 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
202 0x00, //reserved
203 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
205 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
206 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
207 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
208 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
209 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
210 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
211 (byte) 0x80, 0x1d, 0x10, //linkstate attr
212 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
213 0x04, 0x06, 0x00, 0x04, 0x16, 0x16, 0x16, 0x16}; //BgpAttrNodeRouterId
214 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
215 buffer.writeBytes(updateMsg);
216
217 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
218 BgpMessage message = null;
219 BgpHeader bgpHeader = new BgpHeader();
220
221 message = reader.readFrom(buffer, bgpHeader);
222
223 assertThat(message, instanceOf(BgpUpdateMsg.class));
224 BgpUpdateMsg other = (BgpUpdateMsg) message;
225
226 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
227 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
228 (byte) 0xff, (byte) 0xff, (byte) 0xff };
229
230 assertThat(other.getHeader().getMarker(), is(marker));
231 assertThat(other.getHeader().getType(), is((byte) 2));
232 assertThat(other.getHeader().getLength(), is((short) 150));
233
234 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
235 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
236
237 while (listIterator1.hasNext()) {
238 IpPrefix testPrefixValue = listIterator1.next();
239 assertThat(testPrefixValue.prefixLength(), is((int) 24));
240 assertThat(testPrefixValue.address().toOctets(), is(prefix));
241 }
242
243 BgpValueType testPathAttribute = null;
244 Origin origin;
245 AsPath asPath;
246 Med med;
247 MpReachNlri mpReach;
248 LinkStateAttributes linkStateAttr;
249 List<BgpValueType> pathAttributeList = new LinkedList<>();
250 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
251 pathAttributeList = pathAttribute.pathAttributes();
252 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700253 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530254
255 testPathAttribute = listIterator.next();
256 origin = (Origin) testPathAttribute;
257 assertThat(origin.origin(), is(originValue));
258
259 testPathAttribute = listIterator.next();
260 asPath = (AsPath) testPathAttribute;
261 ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator();
262 assertThat(listIterator2.next(), is((short) 65001));
263
264 testPathAttribute = listIterator.next();
265 med = (Med) testPathAttribute;
266 assertThat(med.med(), is(0));
267
268 testPathAttribute = listIterator.next();
269 mpReach = (MpReachNlri) testPathAttribute;
270 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
271 assertThat(mpReach.getType(), is((short) 14));
272
273 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
274 testMpReachNlri = mpReach.mpReachNlri();
275
276 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
277 BgpLSNlri testnlri = list1.next();
278 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
279 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
280 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
281 assertThat(testnlri.getIdentifier(), is((long) 0));
282 assertThat(testnlri.getNlriType(), is(nlriType));
283 assertThat(testnlri.getProtocolId(), is(protocolId));
284
285 testPathAttribute = listIterator.next();
286 linkStateAttr = (LinkStateAttributes) testPathAttribute;
287 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x10, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
288 0x15, 0x04, 0x06, 0x00, 0x04, 0x16, 0x16, 0x16, 0x16 };
289 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
290 cb.writeBytes(linkAttrbs);
291 LinkStateAttributes obj = LinkStateAttributes.read(cb);
292
293 assertThat(linkStateAttr.linkStateAttributes(), is(obj.linkStateAttributes()));
294 assertThat(linkStateAttr.getType(), is((short) 29));
295 }
296
297 /**
298 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrMetric.
299 *
300 * @throws BgpParseException while parsing update message
301 */
302 @Test
303 public void bgpUpdateMessageTest3() throws BgpParseException {
304 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
305 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
306 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
307 0x02, 0x00, 0x04,
308 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
309 0x00, 0x7b, //path attribute len
310 0x04, 0x01, 0x01, 0x00, //origin
311 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
312 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
313 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
314 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
315 0x00, //reserved
316 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
318 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
319 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
320 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
321 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
322 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
323 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
324 (byte) 0x80, 0x1d, 0x10, //linkstate attr
325 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
326 0x04, (byte) 0x83, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric
327 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
328 buffer.writeBytes(updateMsg);
329
330 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
331 BgpMessage message = null;
332 BgpHeader bgpHeader = new BgpHeader();
333
334 message = reader.readFrom(buffer, bgpHeader);
335
336 assertThat(message, instanceOf(BgpUpdateMsg.class));
337 BgpUpdateMsg other = (BgpUpdateMsg) message;
338
339 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
340 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
341 (byte) 0xff, (byte) 0xff, (byte) 0xff };
342
343 assertThat(other.getHeader().getMarker(), is(marker));
344 assertThat(other.getHeader().getType(), is((byte) 2));
345 assertThat(other.getHeader().getLength(), is((short) 150));
346
347 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
348 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
349
350 while (listIterator1.hasNext()) {
351 IpPrefix testPrefixValue = listIterator1.next();
352 assertThat(testPrefixValue.prefixLength(), is((int) 24));
353 assertThat(testPrefixValue.address().toOctets(), is(prefix));
354 }
355
356 BgpValueType testPathAttribute = null;
357 Origin origin;
358 AsPath aspath;
359 Med med;
360 MpReachNlri mpReach;
361 LinkStateAttributes linkStateAttr;
362 List<BgpValueType> pathAttributeList = new LinkedList<>();
363 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
364 pathAttributeList = pathAttribute.pathAttributes();
365 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700366 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530367
368 testPathAttribute = listIterator.next();
369 origin = (Origin) testPathAttribute;
370 assertThat(origin.origin(), is(originValue));
371
372 testPathAttribute = listIterator.next();
373 aspath = (AsPath) testPathAttribute;
374 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
375 assertThat(listIterator2.next(), is((short) 65001));
376
377 testPathAttribute = listIterator.next();
378 med = (Med) testPathAttribute;
379 assertThat(med.med(), is(0));
380
381 testPathAttribute = listIterator.next();
382 mpReach = (MpReachNlri) testPathAttribute;
383 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
384 assertThat(mpReach.getType(), is((short) 14));
385
386 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
387 testMpReachNlri = mpReach.mpReachNlri();
388
389 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
390 BgpLSNlri testnlri = list1.next();
391 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
392 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
393 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
394 assertThat(testnlri.getIdentifier(), is((long) 0));
395 assertThat(testnlri.getNlriType(), is(nlriType));
396 assertThat(testnlri.getProtocolId(), is(protocolId));
397
398 testPathAttribute = listIterator.next();
399 linkStateAttr = (LinkStateAttributes) testPathAttribute;
400 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x10, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
401 0x15, 0x04, (byte) 0x83, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 };
402 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
403 cb.writeBytes(linkAttrbs);
404 LinkStateAttributes obj = LinkStateAttributes.read(cb);
405
406 assertThat(linkStateAttr.linkStateAttributes(), is(obj.linkStateAttributes()));
407 assertThat(linkStateAttr.getType(), is((short) 29));
408 }
409
410 /**
411 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeName.
412 *
413 * @throws BgpParseException while parsing update message
414 */
415 @Test
416 public void bgpUpdateMessageTest4() throws BgpParseException {
417 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
418 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
419 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x98,
420 0x02, 0x00, 0x04,
421 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
422 0x00, 0x7d, //path attribute len
423 0x04, 0x01, 0x01, 0x00, //origin
424 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
425 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
426 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
427 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
428 0x00, //reserved
429 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
431 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
432 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
433 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
434 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
435 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
436 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
437 (byte) 0x80, 0x1d, 0x12, //linkstate attr
438 0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
439 0x04, 0x02, 0x00, 0x06, 0x37, 0x37, 0x35, 0x30, 0x2d, 0x31 }; //BgpAttrNodeName
440
441 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
442 buffer.writeBytes(updateMsg);
443
444 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
445 BgpMessage message = null;
446 BgpHeader bgpHeader = new BgpHeader();
447
448 message = reader.readFrom(buffer, bgpHeader);
449
450 assertThat(message, instanceOf(BgpUpdateMsg.class));
451 BgpUpdateMsg other = (BgpUpdateMsg) message;
452
453 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
454 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
455 (byte) 0xff, (byte) 0xff, (byte) 0xff };
456
457 assertThat(other.getHeader().getMarker(), is(marker));
458 assertThat(other.getHeader().getType(), is((byte) 2));
459 assertThat(other.getHeader().getLength(), is((short) 152));
460
461 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
462 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
463
464 while (listIterator1.hasNext()) {
465 IpPrefix testPrefixValue = listIterator1.next();
466 assertThat(testPrefixValue.prefixLength(), is((int) 24));
467 assertThat(testPrefixValue.address().toOctets(), is(prefix));
468 }
469
470 BgpValueType testPathAttribute = null;
471 Origin origin;
472 AsPath aspath;
473 Med med;
474 MpReachNlri mpReach;
475 LinkStateAttributes linkStateAttr;
476 List<BgpValueType> pathAttributeList = new LinkedList<>();
477 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
478 pathAttributeList = pathAttribute.pathAttributes();
479 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700480 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530481
482 testPathAttribute = listIterator.next();
483 origin = (Origin) testPathAttribute;
484 assertThat(origin.origin(), is(originValue));
485
486 testPathAttribute = listIterator.next();
487 aspath = (AsPath) testPathAttribute;
488 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
489 assertThat(listIterator2.next(), is((short) 65001));
490
491 testPathAttribute = listIterator.next();
492 med = (Med) testPathAttribute;
493 assertThat(med.med(), is(0));
494
495 testPathAttribute = listIterator.next();
496 mpReach = (MpReachNlri) testPathAttribute;
497 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
498 assertThat(mpReach.getType(), is((short) 14));
499
500 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
501 testMpReachNlri = mpReach.mpReachNlri();
502
503 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
504 BgpLSNlri testnlri = list1.next();
505 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
506 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
507 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
508 assertThat(testnlri.getIdentifier(), is((long) 0));
509 assertThat(testnlri.getNlriType(), is(nlriType));
510 assertThat(testnlri.getProtocolId(), is(protocolId));
511
512 testPathAttribute = listIterator.next();
513 linkStateAttr = (LinkStateAttributes) testPathAttribute;
514 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x12, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
515 0x15, 0x04, 0x02, 0x00, 0x06, 0x37, 0x37, 0x35, 0x30, 0x2d, 0x31 };
516 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
517 cb.writeBytes(linkAttrbs);
518 LinkStateAttributes obj = LinkStateAttributes.read(cb);
519
520 ListIterator<BgpValueType> list = obj.linkStateAttributes().listIterator();
521 ListIterator<BgpValueType> list2 = linkStateAttr.linkStateAttributes().listIterator();
522 assertThat(list.next(), is(list2.next()));
523 assertThat(((BgpAttrNodeName) list2.next()).attrNodeName(), is(((BgpAttrNodeName) list.next()).attrNodeName()));
524 assertThat(linkStateAttr.getType(), is((short) 29));
525 }
526
527 /**
528 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeIsIsAreaId.
529 *
530 * @throws BgpParseException while parsing update message
531 */
532 @Test
533 public void bgpUpdateMessageTest5() throws BgpParseException {
534 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
535 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
536 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95,
537 0x02, 0x00, 0x04,
538 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
539 0x00, 0x7A, //path attribute len
540 0x04, 0x01, 0x01, 0x00, //origin
541 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
542 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
543 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
544 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
545 0x00, //reserved
546 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
547 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
548 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
549 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
550 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
551 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
552 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
553 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
554 (byte) 0x80, 0x1d, 0x0f, //linkstate attr
555 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrNodeRouterId
556 0x04, 0x03, 0x00, 0x03, 0x40, 0x01, 0x00}; //BgpAttrNodeIsIsAreaId
557
558 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
559 buffer.writeBytes(updateMsg);
560
561 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
562 BgpMessage message = null;
563 BgpHeader bgpHeader = new BgpHeader();
564
565 message = reader.readFrom(buffer, bgpHeader);
566
567 assertThat(message, instanceOf(BgpUpdateMsg.class));
568 BgpUpdateMsg other = (BgpUpdateMsg) message;
569
570 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
571 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
572 (byte) 0xff, (byte) 0xff, (byte) 0xff };
573
574 assertThat(other.getHeader().getMarker(), is(marker));
575 assertThat(other.getHeader().getType(), is((byte) 2));
576 assertThat(other.getHeader().getLength(), is((short) 149));
577
578 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
579 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
580
581 while (listIterator1.hasNext()) {
582 IpPrefix testPrefixValue = listIterator1.next();
583 assertThat(testPrefixValue.prefixLength(), is((int) 24));
584 assertThat(testPrefixValue.address().toOctets(), is(prefix));
585 }
586
587 BgpValueType testPathAttribute = null;
588 Origin origin;
589 AsPath aspath;
590 Med med;
591 MpReachNlri mpReach;
592 LinkStateAttributes linkStateAttr;
593 List<BgpValueType> pathAttributeList = new LinkedList<>();
594 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
595 pathAttributeList = pathAttribute.pathAttributes();
596 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700597 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530598
599 testPathAttribute = listIterator.next();
600 origin = (Origin) testPathAttribute;
601 assertThat(origin.origin(), is(originValue));
602
603 testPathAttribute = listIterator.next();
604 aspath = (AsPath) testPathAttribute;
605 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
606 assertThat(listIterator2.next(), is((short) 65001));
607
608 testPathAttribute = listIterator.next();
609 med = (Med) testPathAttribute;
610 assertThat(med.med(), is(0));
611
612 testPathAttribute = listIterator.next();
613 mpReach = (MpReachNlri) testPathAttribute;
614 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
615 assertThat(mpReach.getType(), is((short) 14));
616
617 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
618 testMpReachNlri = mpReach.mpReachNlri();
619
620 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
621 BgpLSNlri testnlri = list1.next();
622 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
623 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
624 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
625 assertThat(testnlri.getIdentifier(), is((long) 0));
626 assertThat(testnlri.getNlriType(), is(nlriType));
627 assertThat(testnlri.getProtocolId(), is(protocolId));
628
629 testPathAttribute = listIterator.next();
630 linkStateAttr = (LinkStateAttributes) testPathAttribute;
631 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x0f, 0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c,
632 0x62, 0x04, 0x03, 0x00, 0x03, 0x40, 0x01, 0x00 };
633 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
634 cb.writeBytes(linkAttrbs);
635 LinkStateAttributes obj = LinkStateAttributes.read(cb);
636
637 ListIterator<BgpValueType> list = obj.linkStateAttributes().listIterator();
638 ListIterator<BgpValueType> list2 = linkStateAttr.linkStateAttributes().listIterator();
639 assertThat(list.next(), is(list2.next()));
640 assertThat(((BgpAttrNodeIsIsAreaId) list2.next()).attrNodeIsIsAreaId(),
641 is(((BgpAttrNodeIsIsAreaId) list.next()).attrNodeIsIsAreaId()));
642 assertThat(linkStateAttr.getType(), is((short) 29));
643 }
644
645 /**
646 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrRouterIdV6.
647 *
648 * @throws BgpParseException while parsing update message
649 */
650 @Test
651 public void bgpUpdateMessageTest6() throws BgpParseException {
652 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
653 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
654 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xA2,
655 0x02, 0x00, 0x04,
656 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
657 0x00, (byte) 0x87, //path attribute len
658 0x04, 0x01, 0x01, 0x00, //origin
659 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
660 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
661 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
662 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
663 0x00, //reserved
664 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
665 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
666 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
667 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
668 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
669 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
670 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
671 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
672 (byte) 0x80, 0x1d, 0x1C, //linkstate attr
673 0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
674 0x04, 0x05, 0x00, 0x10, 0x01, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675 0x00, 0x00, 0x00, 0x01}; //BgpAttrRouterIdV6
676 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
677 buffer.writeBytes(updateMsg);
678
679 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
680 BgpMessage message = null;
681 BgpHeader bgpHeader = new BgpHeader();
682
683 message = reader.readFrom(buffer, bgpHeader);
684
685 assertThat(message, instanceOf(BgpUpdateMsg.class));
686 BgpUpdateMsg other = (BgpUpdateMsg) message;
687
688 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
689 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
690 (byte) 0xff, (byte) 0xff, (byte) 0xff };
691
692 assertThat(other.getHeader().getMarker(), is(marker));
693 assertThat(other.getHeader().getType(), is((byte) 2));
694 assertThat(other.getHeader().getLength(), is((short) 162));
695
696 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
697 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
698
699 while (listIterator1.hasNext()) {
700 IpPrefix testPrefixValue = listIterator1.next();
701 assertThat(testPrefixValue.prefixLength(), is((int) 24));
702 assertThat(testPrefixValue.address().toOctets(), is(prefix));
703 }
704
705 BgpValueType testPathAttribute = null;
706 Origin origin;
707 AsPath aspath;
708 Med med;
709 MpReachNlri mpReach;
710 LinkStateAttributes linkStateAttr;
711 List<BgpValueType> pathAttributeList = new LinkedList<>();
712 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
713 pathAttributeList = pathAttribute.pathAttributes();
714 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
715
Jonathan Hart51539b82015-10-29 09:53:04 -0700716 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530717
718 testPathAttribute = listIterator.next();
719 origin = (Origin) testPathAttribute;
720 assertThat(origin.origin(), is(originValue));
721
722 testPathAttribute = listIterator.next();
723 aspath = (AsPath) testPathAttribute;
724 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
725 assertThat(listIterator2.next(), is((short) 65001));
726
727 testPathAttribute = listIterator.next();
728 med = (Med) testPathAttribute;
729 assertThat(med.med(), is(0));
730
731 testPathAttribute = listIterator.next();
732 mpReach = (MpReachNlri) testPathAttribute;
733 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
734 assertThat(mpReach.getType(), is((short) 14));
735
736 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
737 testMpReachNlri = mpReach.mpReachNlri();
738
739 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
740 BgpLSNlri testnlri = list1.next();
741 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
742 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
743 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
744 assertThat(testnlri.getIdentifier(), is((long) 0));
745 assertThat(testnlri.getNlriType(), is(nlriType));
746 assertThat(testnlri.getProtocolId(), is(protocolId));
747
748 testPathAttribute = listIterator.next();
749 linkStateAttr = (LinkStateAttributes) testPathAttribute;
750 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x1C, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
751 0x15, 0x04, 0x05, 0x00, 0x10, 0x01, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
752 0x00, 0x00, 0x00, 0x01 };
753 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
754 cb.writeBytes(linkAttrbs);
755 LinkStateAttributes obj = LinkStateAttributes.read(cb);
756
757 assertThat(linkStateAttr.linkStateAttributes(), is(obj.linkStateAttributes()));
758 assertThat(linkStateAttr.getType(), is((short) 29));
759 }
760
761 /**
762 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeMultiTopologyId.
763 *
764 * @throws BgpParseException while parsing update message
765 */
766 @Test
767 public void bgpUpdateMessageTest7() throws BgpParseException {
768 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
769 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
770 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
771 0x02, 0x00, 0x04,
772 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
773 0x00, 0x7b, //path attribute len
774 0x04, 0x01, 0x01, 0x00, //origin
775 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
776 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
777 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
778 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
779 0x00, //reserved
780 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
781 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
782 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
783 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
784 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
785 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
786 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
787 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
788 (byte) 0x80, 0x1d, 0x10, //linkstate attr
789 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
790 0x01, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02}; //BgpAttrNodeMultiTopologyId
791 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
792 buffer.writeBytes(updateMsg);
793
794 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
795 BgpMessage message = null;
796 BgpHeader bgpHeader = new BgpHeader();
797
798 message = reader.readFrom(buffer, bgpHeader);
799
800 assertThat(message, instanceOf(BgpUpdateMsg.class));
801 BgpUpdateMsg other = (BgpUpdateMsg) message;
802
803 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
804 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
805 (byte) 0xff, (byte) 0xff, (byte) 0xff };
806
807 assertThat(other.getHeader().getMarker(), is(marker));
808 assertThat(other.getHeader().getType(), is((byte) 2));
809 assertThat(other.getHeader().getLength(), is((short) 150));
810
811 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
812 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
813
814 while (listIterator1.hasNext()) {
815 IpPrefix testPrefixValue = listIterator1.next();
816 assertThat(testPrefixValue.prefixLength(), is((int) 24));
817 assertThat(testPrefixValue.address().toOctets(), is(prefix));
818 }
819
820 BgpValueType testPathAttribute = null;
821 Origin origin;
822 AsPath aspath;
823 Med med;
824 MpReachNlri mpReach;
825 LinkStateAttributes linkStateAttr;
826 List<BgpValueType> pathAttributeList = new LinkedList<>();
827 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
828 pathAttributeList = pathAttribute.pathAttributes();
829 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700830 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530831
832 testPathAttribute = listIterator.next();
833 origin = (Origin) testPathAttribute;
834 assertThat(origin.origin(), is(originValue));
835
836 testPathAttribute = listIterator.next();
837 aspath = (AsPath) testPathAttribute;
838 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
839 assertThat(listIterator2.next(), is((short) 65001));
840
841 testPathAttribute = listIterator.next();
842 med = (Med) testPathAttribute;
843 assertThat(med.med(), is(0));
844
845 testPathAttribute = listIterator.next();
846 mpReach = (MpReachNlri) testPathAttribute;
847 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
848 assertThat(mpReach.getType(), is((short) 14));
849
850 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
851 testMpReachNlri = mpReach.mpReachNlri();
852
853 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
854 BgpLSNlri testnlri = list1.next();
855 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
856 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
857 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
858 assertThat(testnlri.getIdentifier(), is((long) 0));
859 assertThat(testnlri.getNlriType(), is(nlriType));
860 assertThat(testnlri.getProtocolId(), is(protocolId));
861
862 testPathAttribute = listIterator.next();
863 linkStateAttr = (LinkStateAttributes) testPathAttribute;
864 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x10, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
865 0x15, 0x01, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02 };
866 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
867 cb.writeBytes(linkAttrbs);
868 LinkStateAttributes obj = LinkStateAttributes.read(cb);
869
870 ListIterator<BgpValueType> list = obj.linkStateAttributes().listIterator();
871 ListIterator<BgpValueType> list2 = linkStateAttr.linkStateAttributes().listIterator();
872 assertThat(list.next(), is(list2.next()));
873 assertThat(((BgpAttrNodeMultiTopologyId) list2.next()).attrMultiTopologyId(),
874 is(((BgpAttrNodeMultiTopologyId) list.next()).attrMultiTopologyId()));
875
876 assertThat(linkStateAttr.getType(), is((short) 29));
877 }
878
879 /**
880 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrRouteTag.
881 *
882 * @throws BgpParseException while parsing update message
883 */
884 @Test
885 public void bgpUpdateMessageTest8() throws BgpParseException {
886 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
887 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
888 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
889 0x02, 0x00, 0x04,
890 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
891 0x00, 0x7b, //path attribute len
892 0x04, 0x01, 0x01, 0x00, //origin
893 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
894 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
895 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
896 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
897 0x00, //reserved
898 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
899 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
900 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
901 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
902 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
903 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
904 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
905 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
906 (byte) 0x80, 0x1d, 0x10, //linkstate attr
907 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
908 0x04, (byte) 0x81, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01}; //BgpPrefixAttrRouteTag
909 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
910 buffer.writeBytes(updateMsg);
911
912 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
913 BgpMessage message = null;
914 BgpHeader bgpHeader = new BgpHeader();
915
916 message = reader.readFrom(buffer, bgpHeader);
917
918 assertThat(message, instanceOf(BgpUpdateMsg.class));
919 BgpUpdateMsg other = (BgpUpdateMsg) message;
920
921 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
922 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
923 (byte) 0xff, (byte) 0xff, (byte) 0xff };
924
925 assertThat(other.getHeader().getMarker(), is(marker));
926 assertThat(other.getHeader().getType(), is((byte) 2));
927 assertThat(other.getHeader().getLength(), is((short) 150));
928
929 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
930 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
931
932 while (listIterator1.hasNext()) {
933 IpPrefix testPrefixValue = listIterator1.next();
934 assertThat(testPrefixValue.prefixLength(), is((int) 24));
935 assertThat(testPrefixValue.address().toOctets(), is(prefix));
936 }
937
938 BgpValueType testPathAttribute = null;
939 Origin origin;
940 AsPath aspath;
941 Med med;
942 MpReachNlri mpReach;
943 LinkStateAttributes linkStateAttr;
944 List<BgpValueType> pathAttributeList = new LinkedList<>();
945 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
946 pathAttributeList = pathAttribute.pathAttributes();
947 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -0700948 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +0530949
950 testPathAttribute = listIterator.next();
951 origin = (Origin) testPathAttribute;
952 assertThat(origin.origin(), is(originValue));
953
954 testPathAttribute = listIterator.next();
955 aspath = (AsPath) testPathAttribute;
956 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
957 assertThat(listIterator2.next(), is((short) 65001));
958
959 testPathAttribute = listIterator.next();
960 med = (Med) testPathAttribute;
961 assertThat(med.med(), is(0));
962
963 testPathAttribute = listIterator.next();
964 mpReach = (MpReachNlri) testPathAttribute;
965 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
966 assertThat(mpReach.getType(), is((short) 14));
967
968 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
969 testMpReachNlri = mpReach.mpReachNlri();
970
971 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
972 BgpLSNlri testnlri = list1.next();
973 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
974 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
975 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
976 assertThat(testnlri.getIdentifier(), is((long) 0));
977 assertThat(testnlri.getNlriType(), is(nlriType));
978 assertThat(testnlri.getProtocolId(), is(protocolId));
979
980 testPathAttribute = listIterator.next();
981 linkStateAttr = (LinkStateAttributes) testPathAttribute;
982 byte[] linkAttrbs = new byte[] {(byte) 0x80, 0x1d, 0x10, 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15,
983 0x15, 0x04, (byte) 0x81, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01 };
984 ChannelBuffer cb = ChannelBuffers.dynamicBuffer();
985 cb.writeBytes(linkAttrbs);
986 LinkStateAttributes obj = LinkStateAttributes.read(cb);
987
988 ListIterator<BgpValueType> list = obj.linkStateAttributes().listIterator();
989 ListIterator<BgpValueType> list2 = linkStateAttr.linkStateAttributes().listIterator();
990 assertThat(list.next(), is(list2.next()));
991 assertThat(((BgpPrefixAttrRouteTag) list2.next()).getPfxRouteTag(),
992 is(((BgpPrefixAttrRouteTag) list.next()).getPfxRouteTag()));
993
994 assertThat(linkStateAttr.getType(), is((short) 29));
995 }
996
997 /**
998 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrIsIsAdminstGrp.
999 *
1000 * @throws BgpParseException while parsing update message
1001 */
1002 @Test
1003 public void bgpUpdateMessageTest9() throws BgpParseException {
1004 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1005 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1006 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
1007 0x02, 0x00, 0x04,
1008 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1009 0x00, 0x7b, //path attribute len
1010 0x04, 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 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1014 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1015 0x00, //reserved
1016 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1017 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1018 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1019 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1020 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1021 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1022 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1023 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1024 (byte) 0x80, 0x1d, 0x10, //linkstate attr
1025 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
1026 0x04, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //BgpLinkAttrIsIsAdminstGrp
1027 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1028 buffer.writeBytes(updateMsg);
1029
1030 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1031 BgpMessage message = null;
1032 BgpHeader bgpHeader = new BgpHeader();
1033
1034 message = reader.readFrom(buffer, bgpHeader);
1035
1036 assertThat(message, instanceOf(BgpUpdateMsg.class));
1037 BgpUpdateMsg other = (BgpUpdateMsg) message;
1038
1039 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1040 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1041 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1042
1043 assertThat(other.getHeader().getMarker(), is(marker));
1044 assertThat(other.getHeader().getType(), is((byte) 2));
1045 assertThat(other.getHeader().getLength(), is((short) 150));
1046
1047 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1048 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1049
1050 while (listIterator1.hasNext()) {
1051 IpPrefix testPrefixValue = listIterator1.next();
1052 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1053 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1054 }
1055
1056 BgpValueType testPathAttribute = null;
1057 Origin origin;
1058 AsPath aspath;
1059 Med med;
1060 MpReachNlri mpReach;
1061 LinkStateAttributes linkStateAttr;
1062 List<BgpValueType> pathAttributeList = new LinkedList<>();
1063 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1064 pathAttributeList = pathAttribute.pathAttributes();
1065 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001066 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301067
1068 testPathAttribute = listIterator.next();
1069 origin = (Origin) testPathAttribute;
1070 assertThat(origin.origin(), is(originValue));
1071
1072 testPathAttribute = listIterator.next();
1073 aspath = (AsPath) testPathAttribute;
1074 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1075 assertThat(listIterator2.next(), is((short) 65001));
1076
1077 testPathAttribute = listIterator.next();
1078 med = (Med) testPathAttribute;
1079 assertThat(med.med(), is(0));
1080
1081 testPathAttribute = listIterator.next();
1082 mpReach = (MpReachNlri) testPathAttribute;
1083 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1084 assertThat(mpReach.getType(), is((short) 14));
1085
1086 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1087 testMpReachNlri = mpReach.mpReachNlri();
1088
1089 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1090 BgpLSNlri testnlri = list1.next();
1091 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1092 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1093 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1094 assertThat(testnlri.getIdentifier(), is((long) 0));
1095 assertThat(testnlri.getNlriType(), is(nlriType));
1096 assertThat(testnlri.getProtocolId(), is(protocolId));
1097
1098 testPathAttribute = listIterator.next();
1099 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1100
1101 assertThat(linkStateAttr.getType(), is((short) 29));
1102 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1103 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1104 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1105 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1106 assertThat(((BgpLinkAttrIsIsAdminstGrp) list.next()).linkAttrIsIsAdminGrp(), is((long) 0));
1107 }
1108
1109 /**
1110 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeFlagBitTlv.
1111 *
1112 * @throws BgpParseException while parsing update message
1113 */
1114 @Test
1115 public void bgpUpdateMessageTest10() throws BgpParseException {
1116 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1117 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1118 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93,
1119 0x02, 0x00, 0x04,
1120 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1121 0x00, 0x78, //path attribute len
1122 0x04, 0x01, 0x01, 0x00, //origin
1123 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1124 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1125 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1126 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1127 0x00, //reserved
1128 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1129 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1130 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1131 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1132 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1133 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1134 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1135 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1136 (byte) 0x80, 0x1d, 0x0D, //linkstate attr
1137 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
1138 0x04, 0x00, 0x00, 0x01, 0x20}; //BgpAttrNodeFlagBitTlv
1139 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1140 buffer.writeBytes(updateMsg);
1141
1142 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1143 BgpMessage message = null;
1144 BgpHeader bgpHeader = new BgpHeader();
1145
1146 message = reader.readFrom(buffer, bgpHeader);
1147
1148 assertThat(message, instanceOf(BgpUpdateMsg.class));
1149 BgpUpdateMsg other = (BgpUpdateMsg) message;
1150
1151 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1152 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1153 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1154
1155 assertThat(other.getHeader().getMarker(), is(marker));
1156 assertThat(other.getHeader().getType(), is((byte) 2));
1157 assertThat(other.getHeader().getLength(), is((short) 147));
1158
1159 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1160 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1161
1162 while (listIterator1.hasNext()) {
1163 IpPrefix testPrefixValue = listIterator1.next();
1164 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1165 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1166 }
1167
1168 BgpValueType testPathAttribute = null;
1169 Origin origin;
1170 AsPath aspath;
1171 Med med;
1172 MpReachNlri mpReach;
1173 LinkStateAttributes linkStateAttr;
1174 List<BgpValueType> pathAttributeList = new LinkedList<>();
1175 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1176 pathAttributeList = pathAttribute.pathAttributes();
1177 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001178 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301179
1180 testPathAttribute = listIterator.next();
1181 origin = (Origin) testPathAttribute;
1182 assertThat(origin.origin(), is(originValue));
1183
1184 testPathAttribute = listIterator.next();
1185 aspath = (AsPath) testPathAttribute;
1186 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1187 assertThat(listIterator2.next(), is((short) 65001));
1188
1189 testPathAttribute = listIterator.next();
1190 med = (Med) testPathAttribute;
1191 assertThat(med.med(), is(0));
1192
1193 testPathAttribute = listIterator.next();
1194 mpReach = (MpReachNlri) testPathAttribute;
1195 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1196 assertThat(mpReach.getType(), is((short) 14));
1197
1198 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1199 testMpReachNlri = mpReach.mpReachNlri();
1200
1201 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1202 BgpLSNlri testnlri = list1.next();
1203 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1204 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1205 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1206 assertThat(testnlri.getIdentifier(), is((long) 0));
1207 assertThat(testnlri.getNlriType(), is(nlriType));
1208 assertThat(testnlri.getProtocolId(), is(protocolId));
1209
1210 testPathAttribute = listIterator.next();
1211 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1212
1213 assertThat(linkStateAttr.getType(), is((short) 29));
1214 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1215 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1216 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1217 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1218 BgpAttrNodeFlagBitTlv obj = new BgpAttrNodeFlagBitTlv(false, false, true, false);
1219 assertThat(((BgpAttrNodeFlagBitTlv) list.next()).equals(obj), is(true));
1220 }
1221
1222 /**
1223 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrTeDefaultMetric.
1224 *
1225 * @throws BgpParseException while parsing update message
1226 */
1227 @Test
1228 public void bgpUpdateMessageTest11() throws BgpParseException {
1229 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1230 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1231 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
1232 0x02, 0x00, 0x04,
1233 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1234 0x00, 0x7B, //path attribute len
1235 0x04, 0x01, 0x01, 0x00, //origin
1236 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1237 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1238 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1239 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1240 0x00, //reserved
1241 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1242 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1243 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1244 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1245 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1246 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1247 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1248 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1249 (byte) 0x80, 0x1d, 0x10, //linkstate attr
1250 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
1251 0x04, 0x44, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a}; //BgpLinkAttrTeDefaultMetric
1252 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1253 buffer.writeBytes(updateMsg);
1254
1255 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1256 BgpMessage message = null;
1257 BgpHeader bgpHeader = new BgpHeader();
1258
1259 message = reader.readFrom(buffer, bgpHeader);
1260
1261 assertThat(message, instanceOf(BgpUpdateMsg.class));
1262 BgpUpdateMsg other = (BgpUpdateMsg) message;
1263
1264 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1265 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1266 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1267
1268 assertThat(other.getHeader().getMarker(), is(marker));
1269 assertThat(other.getHeader().getType(), is((byte) 2));
1270 assertThat(other.getHeader().getLength(), is((short) 150));
1271
1272 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1273 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1274
1275 while (listIterator1.hasNext()) {
1276 IpPrefix testPrefixValue = listIterator1.next();
1277 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1278 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1279 }
1280
1281 BgpValueType testPathAttribute = null;
1282 Origin origin;
1283 AsPath aspath;
1284 Med med;
1285 MpReachNlri mpReach;
1286 LinkStateAttributes linkStateAttr;
1287 List<BgpValueType> pathAttributeList = new LinkedList<>();
1288 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1289 pathAttributeList = pathAttribute.pathAttributes();
1290 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001291 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301292
1293 testPathAttribute = listIterator.next();
1294 origin = (Origin) testPathAttribute;
1295 assertThat(origin.origin(), is(originValue));
1296
1297 testPathAttribute = listIterator.next();
1298 aspath = (AsPath) testPathAttribute;
1299 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1300 assertThat(listIterator2.next(), is((short) 65001));
1301
1302 testPathAttribute = listIterator.next();
1303 med = (Med) testPathAttribute;
1304 assertThat(med.med(), is(0));
1305
1306 testPathAttribute = listIterator.next();
1307 mpReach = (MpReachNlri) testPathAttribute;
1308 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1309 assertThat(mpReach.getType(), is((short) 14));
1310
1311 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1312 testMpReachNlri = mpReach.mpReachNlri();
1313
1314 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1315 BgpLSNlri testnlri = list1.next();
1316 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1317 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1318 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1319 assertThat(testnlri.getIdentifier(), is((long) 0));
1320 assertThat(testnlri.getNlriType(), is(nlriType));
1321 assertThat(testnlri.getProtocolId(), is(protocolId));
1322
1323 testPathAttribute = listIterator.next();
1324 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1325
1326 assertThat(linkStateAttr.getType(), is((short) 29));
1327 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1328 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1329 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1330 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1331 assertThat(((BgpLinkAttrTeDefaultMetric) list.next()).attrLinkDefTeMetric(), is(10));
1332 }
1333
1334 /**
1335 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrOpaqueNode.
1336 *
1337 * @throws BgpParseException while parsing update message
1338 */
1339 @Test
1340 public void bgpUpdateMessageTest12() throws BgpParseException {
1341 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1342 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1343 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
1344 0x02, 0x00, 0x04,
1345 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1346 0x00, 0x7B, //path attribute len
1347 0x04, 0x01, 0x01, 0x00, //origin
1348 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1349 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1350 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1351 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1352 0x00, //reserved
1353 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1354 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1355 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1356 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1357 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1358 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1359 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1360 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1361 (byte) 0x80, 0x1d, 0x10, //linkstate attr
1362 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1363 0x04, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a}; //BgpAttrOpaqueNode
1364 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1365 buffer.writeBytes(updateMsg);
1366
1367 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1368 BgpMessage message = null;
1369 BgpHeader bgpHeader = new BgpHeader();
1370
1371 message = reader.readFrom(buffer, bgpHeader);
1372
1373 assertThat(message, instanceOf(BgpUpdateMsg.class));
1374 BgpUpdateMsg other = (BgpUpdateMsg) message;
1375
1376 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1377 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1378 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1379
1380 assertThat(other.getHeader().getMarker(), is(marker));
1381 assertThat(other.getHeader().getType(), is((byte) 2));
1382 assertThat(other.getHeader().getLength(), is((short) 150));
1383
1384 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1385 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1386
1387 while (listIterator1.hasNext()) {
1388 IpPrefix testPrefixValue = listIterator1.next();
1389 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1390 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1391 }
1392
1393 BgpValueType testPathAttribute = null;
1394 Origin origin;
1395 AsPath aspath;
1396 Med med;
1397 MpReachNlri mpReach;
1398 LinkStateAttributes linkStateAttr;
1399 List<BgpValueType> pathAttributeList = new LinkedList<>();
1400 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1401 pathAttributeList = pathAttribute.pathAttributes();
1402 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001403 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301404
1405 testPathAttribute = listIterator.next();
1406 origin = (Origin) testPathAttribute;
1407 assertThat(origin.origin(), is(originValue));
1408
1409 testPathAttribute = listIterator.next();
1410 aspath = (AsPath) testPathAttribute;
1411 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1412 assertThat(listIterator2.next(), is((short) 65001));
1413
1414 testPathAttribute = listIterator.next();
1415 med = (Med) testPathAttribute;
1416 assertThat(med.med(), is(0));
1417
1418 testPathAttribute = listIterator.next();
1419 mpReach = (MpReachNlri) testPathAttribute;
1420 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1421 assertThat(mpReach.getType(), is((short) 14));
1422
1423 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1424 testMpReachNlri = mpReach.mpReachNlri();
1425
1426 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1427 BgpLSNlri testnlri = list1.next();
1428 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1429 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1430 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1431 assertThat(testnlri.getIdentifier(), is((long) 0));
1432 assertThat(testnlri.getNlriType(), is(nlriType));
1433 assertThat(testnlri.getProtocolId(), is(protocolId));
1434
1435 testPathAttribute = listIterator.next();
1436 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1437
1438 assertThat(linkStateAttr.getType(), is((short) 29));
1439 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1440 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1441 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1442 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1443 byte[] opaqueNode = new byte[] {0x00, 0x00, 0x00, 0x0a };
1444 assertThat(((BgpAttrOpaqueNode) list.next()).attrOpaqueNode(), is(opaqueNode));
1445 }
1446
1447 /**
1448 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrProtectionType.
1449 *
1450 * @throws BgpParseException while parsing update message
1451 */
1452 @Test
1453 public void bgpUpdateMessageTest13() throws BgpParseException {
1454 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1455 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1456 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x94,
1457 0x02, 0x00, 0x04,
1458 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1459 0x00, 0x79, //path attribute len
1460 0x04, 0x01, 0x01, 0x00, //origin
1461 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1462 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1463 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1464 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1465 0x00, //reserved
1466 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1467 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1468 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1469 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1470 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1471 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1472 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1473 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1474 (byte) 0x80, 0x1d, 0x0E, //linkstate attr
1475 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1476 0x04, 0x45, 0x00, 0x02, 0x10, 0x00}; //BgpLinkAttrProtectionType
1477 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1478 buffer.writeBytes(updateMsg);
1479
1480 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1481 BgpMessage message = null;
1482 BgpHeader bgpHeader = new BgpHeader();
1483
1484 message = reader.readFrom(buffer, bgpHeader);
1485
1486 assertThat(message, instanceOf(BgpUpdateMsg.class));
1487 BgpUpdateMsg other = (BgpUpdateMsg) message;
1488
1489 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1490 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1491 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1492
1493 assertThat(other.getHeader().getMarker(), is(marker));
1494 assertThat(other.getHeader().getType(), is((byte) 2));
1495 assertThat(other.getHeader().getLength(), is((short) 148));
1496
1497 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1498 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1499
1500 while (listIterator1.hasNext()) {
1501 IpPrefix testPrefixValue = listIterator1.next();
1502 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1503 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1504 }
1505
1506 BgpValueType testPathAttribute = null;
1507 Origin origin;
1508 AsPath aspath;
1509 Med med;
1510 MpReachNlri mpReach;
1511 LinkStateAttributes linkStateAttr;
1512 List<BgpValueType> pathAttributeList = new LinkedList<>();
1513 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1514 pathAttributeList = pathAttribute.pathAttributes();
1515 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001516 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301517
1518 testPathAttribute = listIterator.next();
1519 origin = (Origin) testPathAttribute;
1520 assertThat(origin.origin(), is(originValue));
1521
1522 testPathAttribute = listIterator.next();
1523 aspath = (AsPath) testPathAttribute;
1524 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1525 assertThat(listIterator2.next(), is((short) 65001));
1526
1527 testPathAttribute = listIterator.next();
1528 med = (Med) testPathAttribute;
1529 assertThat(med.med(), is(0));
1530
1531 testPathAttribute = listIterator.next();
1532 mpReach = (MpReachNlri) testPathAttribute;
1533 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1534 assertThat(mpReach.getType(), is((short) 14));
1535
1536 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1537 testMpReachNlri = mpReach.mpReachNlri();
1538
1539 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1540 BgpLSNlri testnlri = list1.next();
1541 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1542 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1543 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1544 assertThat(testnlri.getIdentifier(), is((long) 0));
1545 assertThat(testnlri.getNlriType(), is(nlriType));
1546 assertThat(testnlri.getProtocolId(), is(protocolId));
1547
1548 testPathAttribute = listIterator.next();
1549 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1550
1551 assertThat(linkStateAttr.getType(), is((short) 29));
1552 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1553 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1554 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1555 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1556 assertThat(((BgpLinkAttrProtectionType) list.next()).protectionType(),
1557 is(ProtectionType.DEDICATED_ONE_PLUS_ONE));
1558 }
1559
1560 /**
1561 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrMplsProtocolMask.
1562 *
1563 * @throws BgpParseException while parsing update message
1564 */
1565 @Test
1566 public void bgpUpdateMessageTest14() throws BgpParseException {
1567 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1568 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1569 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93,
1570 0x02, 0x00, 0x04,
1571 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1572 0x00, 0x78, //path attribute len
1573 0x04, 0x01, 0x01, 0x00, //origin
1574 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1575 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1576 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1577 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1578 0x00, //reserved
1579 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1580 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1581 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1582 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1583 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1584 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1585 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1586 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1587 (byte) 0x80, 0x1d, 0x0D, //linkstate attr
1588 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1589 0x04, 0x46, 0x00, 0x01, (byte) 0xC0}; //BgpLinkAttrMplsProtocolMask
1590 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1591 buffer.writeBytes(updateMsg);
1592
1593 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1594 BgpMessage message = null;
1595 BgpHeader bgpHeader = new BgpHeader();
1596
1597 message = reader.readFrom(buffer, bgpHeader);
1598
1599 assertThat(message, instanceOf(BgpUpdateMsg.class));
1600 BgpUpdateMsg other = (BgpUpdateMsg) message;
1601
1602 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1603 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1604 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1605
1606 assertThat(other.getHeader().getMarker(), is(marker));
1607 assertThat(other.getHeader().getType(), is((byte) 2));
1608 assertThat(other.getHeader().getLength(), is((short) 147));
1609
1610 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1611 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1612
1613 while (listIterator1.hasNext()) {
1614 IpPrefix testPrefixValue = listIterator1.next();
1615 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1616 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1617 }
1618
1619 BgpValueType testPathAttribute = null;
1620 Origin origin;
1621 AsPath aspath;
1622 Med med;
1623 MpReachNlri mpReach;
1624 LinkStateAttributes linkStateAttr;
1625 List<BgpValueType> pathAttributeList = new LinkedList<>();
1626 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1627 pathAttributeList = pathAttribute.pathAttributes();
1628 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001629 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301630
1631 testPathAttribute = listIterator.next();
1632 origin = (Origin) testPathAttribute;
1633 assertThat(origin.origin(), is(originValue));
1634
1635 testPathAttribute = listIterator.next();
1636 aspath = (AsPath) testPathAttribute;
1637 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1638 assertThat(listIterator2.next(), is((short) 65001));
1639
1640 testPathAttribute = listIterator.next();
1641 med = (Med) testPathAttribute;
1642 assertThat(med.med(), is(0));
1643
1644 testPathAttribute = listIterator.next();
1645 mpReach = (MpReachNlri) testPathAttribute;
1646 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1647 assertThat(mpReach.getType(), is((short) 14));
1648
1649 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1650 testMpReachNlri = mpReach.mpReachNlri();
1651
1652 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1653 BgpLSNlri testnlri = list1.next();
1654 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1655 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1656 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1657 assertThat(testnlri.getIdentifier(), is((long) 0));
1658 assertThat(testnlri.getNlriType(), is(nlriType));
1659 assertThat(testnlri.getProtocolId(), is(protocolId));
1660
1661 testPathAttribute = listIterator.next();
1662 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1663
1664 assertThat(linkStateAttr.getType(), is((short) 29));
1665 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1666 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1667 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1668 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1669 BgpLinkAttrMplsProtocolMask obj = new BgpLinkAttrMplsProtocolMask(true, true);
1670 assertThat(((BgpLinkAttrMplsProtocolMask) list.next()).equals(obj), is(true));
1671 }
1672
1673 /**
1674 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrSRLG.
1675 *
1676 * @throws BgpParseException while parsing update message
1677 */
1678 @Test
1679 public void bgpUpdateMessageTest15() throws BgpParseException {
1680 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1681 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1682 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A,
1683 0x02, 0x00, 0x04,
1684 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1685 0x00, 0x7F, //path attribute len
1686 0x04, 0x01, 0x01, 0x00, //origin
1687 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1688 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1689 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1690 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
1691 0x00, //reserved
1692 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1693 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1694 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1695 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1696 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1697 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1698 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1699 0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
1700 (byte) 0x80, 0x1d, 0x14, //linkstate attr
1701 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1702 0x04, 0x48, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b}; //BgpLinkAttrSRLG
1703 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1704 buffer.writeBytes(updateMsg);
1705
1706 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1707 BgpMessage message = null;
1708 BgpHeader bgpHeader = new BgpHeader();
1709
1710 message = reader.readFrom(buffer, bgpHeader);
1711
1712 assertThat(message, instanceOf(BgpUpdateMsg.class));
1713 BgpUpdateMsg other = (BgpUpdateMsg) message;
1714
1715 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1716 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1717 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1718
1719 assertThat(other.getHeader().getMarker(), is(marker));
1720 assertThat(other.getHeader().getType(), is((byte) 2));
1721 assertThat(other.getHeader().getLength(), is((short) 154));
1722
1723 ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
1724 byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
1725
1726 while (listIterator1.hasNext()) {
1727 IpPrefix testPrefixValue = listIterator1.next();
1728 assertThat(testPrefixValue.prefixLength(), is((int) 24));
1729 assertThat(testPrefixValue.address().toOctets(), is(prefix));
1730 }
1731
1732 BgpValueType testPathAttribute = null;
1733 Origin origin;
1734 AsPath aspath;
1735 Med med;
1736 MpReachNlri mpReach;
1737 LinkStateAttributes linkStateAttr;
1738 List<BgpValueType> pathAttributeList = new LinkedList<>();
1739 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1740 pathAttributeList = pathAttribute.pathAttributes();
1741 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001742 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301743
1744 testPathAttribute = listIterator.next();
1745 origin = (Origin) testPathAttribute;
1746 assertThat(origin.origin(), is(originValue));
1747
1748 testPathAttribute = listIterator.next();
1749 aspath = (AsPath) testPathAttribute;
1750 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1751 assertThat(listIterator2.next(), is((short) 65001));
1752
1753 testPathAttribute = listIterator.next();
1754 med = (Med) testPathAttribute;
1755 assertThat(med.med(), is(0));
1756
1757 testPathAttribute = listIterator.next();
1758 mpReach = (MpReachNlri) testPathAttribute;
1759 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1760 assertThat(mpReach.getType(), is((short) 14));
1761
1762 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1763 testMpReachNlri = mpReach.mpReachNlri();
1764
1765 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1766 BgpLSNlri testnlri = list1.next();
1767 NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
1768 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1769 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1770 assertThat(testnlri.getIdentifier(), is((long) 0));
1771 assertThat(testnlri.getNlriType(), is(nlriType));
1772 assertThat(testnlri.getProtocolId(), is(protocolId));
1773
1774 testPathAttribute = listIterator.next();
1775 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1776
1777 assertThat(linkStateAttr.getType(), is((short) 29));
1778 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1779 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1780 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1781 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1782 List<Integer> attrSrlg = new ArrayList<Integer>();
1783 attrSrlg.add(10);
1784 attrSrlg.add(11);
1785 assertThat(((BgpLinkAttrSrlg) list.next()).attrSrlg(), is(attrSrlg));
1786 }
1787
1788 /**
1789 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrOpaqLnkAttrib.
1790 *
1791 * @throws BgpParseException while parsing update message
1792 */
1793 @Test
1794 public void bgpUpdateMessageTest16() throws BgpParseException {
1795 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1796 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1797 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A,
1798 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, //withdrawn routes
1799 0x00, 0x7F, 0x04, 0x01, 0x01, 0x00, //origin
1800 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1801 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1802 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,
1803 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1804 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1805 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1806 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1807 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1808 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1809 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1810 0x00, (byte) 0x95, 0x02, 0x50, 0x21, (byte) 0x80, 0x1d, 0x14, //linkstate attr
1811 0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1812 0x04, 0x49, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b}; //BgpLinkAttrOpaqLnkAttrib
1813 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1814 buffer.writeBytes(updateMsg);
1815
1816 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1817 BgpMessage message = null;
1818 BgpHeader bgpHeader = new BgpHeader();
1819
1820 message = reader.readFrom(buffer, bgpHeader);
1821
1822 assertThat(message, instanceOf(BgpUpdateMsg.class));
1823 BgpUpdateMsg other = (BgpUpdateMsg) message;
1824
1825 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1826 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1827 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1828
1829 assertThat(other.getHeader().getMarker(), is(marker));
1830 assertThat(other.getHeader().getType(), is((byte) 2));
1831 assertThat(other.getHeader().getLength(), is((short) 154));
1832
1833 BgpValueType testPathAttribute = null;
1834 Origin origin;
1835 AsPath aspath;
1836 Med med;
1837 MpReachNlri mpReach;
1838 LinkStateAttributes linkStateAttr;
1839 List<BgpValueType> pathAttributeList = new LinkedList<>();
1840 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1841 pathAttributeList = pathAttribute.pathAttributes();
1842 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001843 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301844
1845 testPathAttribute = listIterator.next();
1846 origin = (Origin) testPathAttribute;
1847 assertThat(origin.origin(), is(originValue));
1848
1849 testPathAttribute = listIterator.next();
1850 aspath = (AsPath) testPathAttribute;
1851 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1852 assertThat(listIterator2.next(), is((short) 65001));
1853
1854 testPathAttribute = listIterator.next();
1855 med = (Med) testPathAttribute;
1856 assertThat(med.med(), is(0));
1857
1858 testPathAttribute = listIterator.next();
1859 mpReach = (MpReachNlri) testPathAttribute;
1860 assertThat(mpReach.mpReachNlriLen(), is((int) 83));
1861 assertThat(mpReach.getType(), is((short) 14));
1862
1863 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1864 testMpReachNlri = mpReach.mpReachNlri();
1865
1866 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1867 BgpLSNlri testnlri = list1.next();
1868 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1869 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1870 assertThat(testnlri.getProtocolId(), is(protocolId));
1871
1872 testPathAttribute = listIterator.next();
1873 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1874
1875 assertThat(linkStateAttr.getType(), is((short) 29));
1876 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1877 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1878 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1879 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1880 byte[] attrOpaqLnkAttrib = new byte[] {0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
1881 assertThat(((BgpLinkAttrOpaqLnkAttrib) list.next()).attrOpaqueLnk(), is(attrOpaqLnkAttrib));
1882 }
1883
1884 /**
1885 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrOpaqueData.
1886 *
1887 * @throws BgpParseException while parsing update message
1888 */
1889 @Test
1890 public void bgpUpdateMessageTest17() throws BgpParseException {
1891 byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1892 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1893 (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96, 0x02, 0x00, 0x04,
1894 0x18, 0x0a, 0x01, 0x01, 0x00, 0x7B, //path attribute len
1895 0x04, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
1896 (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
1897 (byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
1898 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved
1899 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1900 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
1901 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
1902 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
1903 (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
1904 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
1905 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
1906 0x00, (byte) 0x95, 0x02, 0x50, 0x21, (byte) 0x80, 0x1d, 0x10, //linkstate attr
1907 0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
1908 0x04, (byte) 0x85, 0x00, 0x04, 0x0a, 0x0a, 0x0a, 0x0a}; //BgpPrefixAttrOpaqueData
1909 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
1910 buffer.writeBytes(updateMsg);
1911
1912 BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
1913 BgpMessage message = null;
1914 BgpHeader bgpHeader = new BgpHeader();
1915
1916 message = reader.readFrom(buffer, bgpHeader);
1917
1918 assertThat(message, instanceOf(BgpUpdateMsg.class));
1919 BgpUpdateMsg other = (BgpUpdateMsg) message;
1920
1921 byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1922 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
1923 (byte) 0xff, (byte) 0xff, (byte) 0xff };
1924
1925 assertThat(other.getHeader().getMarker(), is(marker));
1926 assertThat(other.getHeader().getType(), is((byte) 2));
1927 assertThat(other.getHeader().getLength(), is((short) 150));
1928 BgpValueType testPathAttribute = null;
1929 Origin origin;
1930 AsPath aspath;
1931 Med med;
1932 MpReachNlri mpReach;
1933 LinkStateAttributes linkStateAttr;
1934 List<BgpValueType> pathAttributeList = new LinkedList<>();
1935 BgpPathAttributes pathAttribute = other.bgpPathAttributes();
1936 pathAttributeList = pathAttribute.pathAttributes();
1937 ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
Jonathan Hart51539b82015-10-29 09:53:04 -07001938 OriginType originValue = OriginType.IGP;
Priyanka B0ab34b92015-12-03 21:13:52 +05301939
1940 testPathAttribute = listIterator.next();
1941 origin = (Origin) testPathAttribute;
1942 assertThat(origin.origin(), is(originValue));
1943
1944 testPathAttribute = listIterator.next();
1945 aspath = (AsPath) testPathAttribute;
1946 ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
1947 assertThat(listIterator2.next(), is((short) 65001));
1948
1949 testPathAttribute = listIterator.next();
1950 med = (Med) testPathAttribute;
1951 assertThat(med.med(), is(0));
1952
1953 testPathAttribute = listIterator.next();
1954 mpReach = (MpReachNlri) testPathAttribute;
1955 List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
1956 testMpReachNlri = mpReach.mpReachNlri();
1957
1958 ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
1959 BgpLSNlri testnlri = list1.next();
1960 ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
1961 BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
1962 assertThat(testnlri.getProtocolId(), is(protocolId));
1963
1964 testPathAttribute = listIterator.next();
1965 linkStateAttr = (LinkStateAttributes) testPathAttribute;
1966
1967 assertThat(linkStateAttr.getType(), is((short) 29));
1968 ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
1969 byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
1970 Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
1971 assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
1972 byte[] opaquePrefixAttr = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
1973 assertThat(((BgpPrefixAttrOpaqueData) list.next()).getOpaquePrefixAttribute(), is(opaquePrefixAttr));
1974 }
1975}