2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.parser.impl;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
15 import com.google.common.collect.Lists;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import java.io.ByteArrayOutputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
28 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
29 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
30 import org.opendaylight.protocol.util.ByteArray;
31 import org.opendaylight.protocol.util.NoopReferenceCache;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Aggregator;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AggregatorBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AtomicAggregateBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Communities;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunitiesBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPrefBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.MultiExitDiscBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.SegmentsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.Nlri;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.NlriBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutesBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
66 public class BGPParserTest {
69 * Used by other tests as well
71 static final List<byte[]> inputBytes = new ArrayList<>();
73 private static int COUNTER = 7;
75 private static int MAX_SIZE = 300;
77 private static BGPUpdateMessageParser updateParser;
79 private static final int LENGTH_FIELD_LENGTH = 2;
82 public static void setUp() throws Exception {
83 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
84 for (int i = 1; i <= COUNTER; i++) {
85 final String name = "/up" + i + ".bin";
86 try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
88 throw new IOException("Failed to get resource " + name);
90 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
91 final byte[] data = new byte[MAX_SIZE];
93 while ((nRead = is.read(data, 0, data.length)) != -1) {
94 bis.write(data, 0, nRead);
98 inputBytes.add(bis.toByteArray());
106 public void testResource() {
107 assertNotNull(inputBytes);
111 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
113 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
114 * 00 54 <- length (84) - including header
116 * 00 00 <- withdrawn routes length
117 * 00 31 <- total path attribute length (49)
118 * 40 <- attribute flags
119 * 01 <- attribute type code (origin)
120 * 01 <- attribute length
121 * 00 <- Origin value (IGP)
122 * 40 <- attribute flags
123 * 02 <- attribute type code (as path)
124 * 06 <- attribute length
126 * 01 <- path segment count
127 * 00 00 fd ea <- path segment value (65002)
128 * 40 <- attribute flags
129 * 03 <- attribute type code (Next Hop)
130 * 04 <- attribute length
131 * 10 00 00 02 <- value (10.0.0.2)
132 * 80 <- attribute flags
133 * 04 <- attribute type code (multi exit disc)
134 * 04 <- attribute length
135 * 00 00 00 00 <- value
136 * 60 <- attribute flags
137 * 06 <- attribute type code (atomic aggregate)
138 * 00 <- attribute length
139 * 40 <- attribute flags
140 * 08 <- attribute type code (community)
141 * 10 <- attribute length FF FF FF
142 * 01 <- value (NO_EXPORT)
143 * FF FF FF 02 <- value (NO_ADVERTISE)
144 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
145 * FF FF FF 10 <- unknown Community
148 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
149 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
150 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
153 public void testGetUpdateMessage1() throws Exception {
155 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
156 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
157 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
161 assertNull(message.getWithdrawnRoutes());
164 final List<AsNumber> asNumbers = new ArrayList<>();
165 asNumbers.add(new AsNumber(65002L));
166 final List<Segments> asPath = Lists.newArrayList();
167 asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
169 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
170 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
172 final List<Communities> comms = Lists.newArrayList();
173 comms.add((Communities) CommunityUtil.NO_EXPORT);
174 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
175 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
176 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
178 final UpdateBuilder builder = new UpdateBuilder();
182 final List<Ipv4Prefix> prefs = Lists.newArrayList();
183 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
184 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
185 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
187 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
189 assertEquals(nlri, message.getNlri());
191 builder.setNlri(nlri);
193 // check path attributes
195 final Attributes attrs = message.getAttributes();
197 final AttributesBuilder paBuilder = new AttributesBuilder();
199 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
200 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
202 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
203 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
205 paBuilder.setCNextHop(nextHop);
206 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
208 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
209 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
211 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
212 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
214 paBuilder.setCommunities(comms);
215 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
217 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
219 builder.setAttributes(paBuilder.build());
221 assertEquals(builder.build(), message);
223 final ByteBuf buffer = Unpooled.buffer();
224 BGPParserTest.updateParser.serializeMessage(message, buffer);
225 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
229 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
231 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
232 * 00 4b <- length (75) - including header
234 * 00 00 <- withdrawn routes length
235 * 00 30 <- total path attribute length (48)
236 * 40 <- attribute flags
237 * 01 <- attribute type code (origin)
238 * 01 <- attribute length
239 * 02 <- Origin value (Incomplete)
240 * 40 <- attribute flags
241 * 02 <- attribute type code (as path)
242 * 10 <- attribute length
244 * 01 <- path segment count
245 * 00 00 00 1e <- path segment value (30)
247 * 02 <- path segment count
248 * 00 00 00 0a <- path segment value (10)
249 * 00 00 00 14 <- path segment value (20)
250 * 40 <- attribute flags
251 * 03 <- attribute type (Next hop)
252 * 04 <- attribute length
253 * 0a 00 00 09 <- value (10.0.0.9)
254 * 80 <- attribute flags
255 * 04 <- attribute type code (multi exit disc)
256 * 04 <- attribute length
257 * 00 00 00 00 <- value
258 * c0 <- attribute flags
259 * 07 <- attribute type (Aggregator)
260 * 08 <- attribute length
261 * 00 00 00 1e <- value (AS number = 30)
262 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
265 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
268 public void testGetUpdateMessage3() throws Exception {
269 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
270 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
271 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
273 final UpdateBuilder builder = new UpdateBuilder();
276 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
278 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
279 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
280 assertEquals(builder.getNlri(), message.getNlri());
283 assertNull(message.getWithdrawnRoutes());
286 final List<AsNumber> asNumbers = new ArrayList<>();
287 asNumbers.add(new AsNumber(30L));
288 final List<Segments> asPath = Lists.newArrayList();
289 asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
290 final List<AsNumber> asSet = Lists.newArrayList(new AsNumber(10L), new AsNumber(20L));
291 asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
293 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
294 new Ipv4Address("10.0.0.9")).build();
295 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
296 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
298 // check path attributes
299 final Attributes attrs = message.getAttributes();
301 final AttributesBuilder paBuilder = new AttributesBuilder();
303 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
304 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
306 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
307 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
309 paBuilder.setCNextHop(nextHop);
310 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
312 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
313 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
315 paBuilder.setAggregator(aggregator);
316 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
317 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
318 builder.setAttributes(paBuilder.build());
320 assertEquals(builder.build(), message);
322 final ByteBuf buffer = Unpooled.buffer();
323 BGPParserTest.updateParser.serializeMessage(message, buffer);
324 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
328 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
330 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
331 * 00 4A <- length (73) - including header
333 * 00 00 <- withdrawn routes length
334 * 00 27 <- total path attribute length (39)
335 * 40 <- attribute flags
336 * 01 <- attribute type code (Origin)
337 * 01 <- attribute length
338 * 01 <- Origin value (EGP)
339 * 40 <- attribute flags
340 * 02 <- attribute type code (As path)
341 * 00 <- attribute length
342 * 40 <- attribute flags
343 * 03 <- attribute type (Next hop)
344 * 04 <- attribute length
345 * 03 03 03 03 <- value (3.3.3.3)
346 * 80 <- attribute flags
347 * 04 <- attribute type code (Multi exit disc)
348 * 04 <- attribute length
349 * 00 00 00 00 <- value
350 * 40 <- attribute flags
351 * 05 <- attribute type (Local Pref)
352 * 04 <- attribute length
353 * 00 00 00 64 <- value (100)
354 * c0 <- attribute flags
355 * 10 <- attribute type (extended community)
356 * 08 <- attribute length
357 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
358 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
359 * 12 34 <- value (local adm. 4660)
362 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
363 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
364 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
367 public void testGetUpdateMessage4() throws Exception {
368 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
369 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
370 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
372 final UpdateBuilder builder = new UpdateBuilder();
375 assertNull(message.getWithdrawnRoutes());
378 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
379 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
380 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
382 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
383 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
384 assertEquals(builder.getNlri(), message.getNlri());
387 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
388 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
390 final List<ExtendedCommunities> comms = Lists.newArrayList();
391 comms.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(
392 new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
393 new RouteTargetIpv4Builder().setGlobalAdministrator(
394 new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660).build()).build()).build());
396 // check path attributes
397 final Attributes attrs = message.getAttributes();
399 final AttributesBuilder paBuilder = new AttributesBuilder();
401 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
402 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
404 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
405 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
407 paBuilder.setCNextHop(nextHop);
408 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
410 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
411 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
413 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
414 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
416 paBuilder.setExtendedCommunities(comms);
417 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
419 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
421 builder.setAttributes(paBuilder.build());
422 assertEquals(builder.build(), message);
424 final ByteBuf buffer = Unpooled.buffer();
425 BGPParserTest.updateParser.serializeMessage(message, buffer);
426 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));
430 * Tests withdrawn routes.
432 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
433 * 00 1c <- length (28) - including header
435 * 00 05 <- withdrawn routes length (5)
436 * 1e ac 10 00 04 <- route (172.16.0.4)
437 * 00 00 <- total path attribute length
440 public void testGetUpdateMessage5() throws Exception {
441 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
442 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
443 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
446 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
449 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
450 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
452 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
454 final ByteBuf buffer = Unpooled.buffer();
455 BGPParserTest.updateParser.serializeMessage(message, buffer);
456 assertArrayEquals(inputBytes.get(4), ByteArray.readAllBytes(buffer));
460 * End of Rib for Ipv4.
462 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
463 * 00 17 <- length (23) - including header
465 * 00 00 <- withdrawn routes length
466 * 00 00 <- total path attribute length
469 public void testEORIpv4() throws Exception {
470 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
471 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
472 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
474 assertEquals(new UpdateBuilder().build(), message);
476 final ByteBuf buffer = Unpooled.buffer();
477 BGPParserTest.updateParser.serializeMessage(message, buffer);
478 assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
482 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
484 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
485 * 00 1d <- length (29) - including header
487 * 00 00 <- withdrawn routes length
488 * 00 06 <- total path attribute length
489 * 80 <- attribute flags
490 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
491 * 03 <- attribute length
492 * 00 02 <- value (AFI 2: IPv6)
493 * 01 <- value (SAFI 1)
496 public void testEORIpv6() throws Exception {
497 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
498 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
499 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
501 final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
502 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
504 assertEquals(Ipv6AddressFamily.class, afi);
505 assertEquals(UnicastSubsequentAddressFamily.class, safi);
507 final ByteBuf buffer = Unpooled.buffer();
508 BGPParserTest.updateParser.serializeMessage(message, buffer);
509 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
513 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
515 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
516 * 00 1e <- length (29) - including header
518 * 00 00 <- withdrawn routes length
519 * 00 07 <- total path attribute length
520 * 90 <- attribute flags
521 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
522 * 00 03 <- attribute length
523 * 00 02 <- value (AFI 2: IPv6)
524 * 01 <- value (SAFI 1)
527 public void testEORIpv6exLength() throws Exception {
528 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
529 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
530 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
532 final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
533 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
535 assertEquals(Ipv6AddressFamily.class, afi);
536 assertEquals(UnicastSubsequentAddressFamily.class, safi);
538 final ByteBuf buffer = Unpooled.buffer();
539 BGPParserTest.updateParser.serializeMessage(message, buffer);
540 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));