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.UnrecognizedAttributes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.SegmentsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.Nlri;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.NlriBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
65 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;
67 public class BGPParserTest {
70 * Used by other tests as well
72 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
74 private static int COUNTER = 7;
76 private static int MAX_SIZE = 300;
78 private static BGPUpdateMessageParser updateParser;
80 private static final int LENGTH_FIELD_LENGTH = 2;
83 public static void setUp() throws Exception {
84 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
85 for (int i = 1; i <= COUNTER; i++) {
86 final String name = "/up" + i + ".bin";
87 try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
89 throw new IOException("Failed to get resource " + name);
91 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
92 final byte[] data = new byte[MAX_SIZE];
94 while ((nRead = is.read(data, 0, data.length)) != -1) {
95 bis.write(data, 0, nRead);
99 inputBytes.add(bis.toByteArray());
107 public void testResource() {
108 assertNotNull(inputBytes);
112 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
114 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
115 * 00 54 <- length (84) - including header
117 * 00 00 <- withdrawn routes length
118 * 00 31 <- total path attribute length (49)
119 * 40 <- attribute flags
120 * 01 <- attribute type code (origin)
121 * 01 <- attribute length
122 * 00 <- Origin value (IGP)
123 * 40 <- attribute flags
124 * 02 <- attribute type code (as path)
125 * 06 <- attribute length
127 * 01 <- path segment count
128 * 00 00 fd ea <- path segment value (65002)
129 * 40 <- attribute flags
130 * 03 <- attribute type code (Next Hop)
131 * 04 <- attribute length
132 * 10 00 00 02 <- value (10.0.0.2)
133 * 80 <- attribute flags
134 * 04 <- attribute type code (multi exit disc)
135 * 04 <- attribute length
136 * 00 00 00 00 <- value
137 * 60 <- attribute flags
138 * 06 <- attribute type code (atomic aggregate)
139 * 00 <- attribute length
140 * 40 <- attribute flags
141 * 08 <- attribute type code (community)
142 * 10 <- attribute length FF FF FF
143 * 01 <- value (NO_EXPORT)
144 * FF FF FF 02 <- value (NO_ADVERTISE)
145 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
146 * FF FF FF 10 <- unknown Community
149 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
150 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
151 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
154 public void testGetUpdateMessage1() throws Exception {
156 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
157 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
158 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
162 assertNull(message.getWithdrawnRoutes());
165 final List<AsNumber> asNumbers = new ArrayList<AsNumber>();
166 asNumbers.add(new AsNumber(65002L));
167 final List<Segments> asPath = Lists.newArrayList();
168 asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
170 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
171 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
173 final List<Communities> comms = Lists.newArrayList();
174 comms.add((Communities) CommunityUtil.NO_EXPORT);
175 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
176 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
177 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
179 final UpdateBuilder builder = new UpdateBuilder();
183 final List<Ipv4Prefix> prefs = Lists.newArrayList();
184 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
185 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
186 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
188 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
190 assertEquals(nlri, message.getNlri());
192 builder.setNlri(nlri);
194 // check path attributes
196 final Attributes attrs = message.getAttributes();
198 final AttributesBuilder paBuilder = new AttributesBuilder();
200 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
201 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
203 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
204 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
206 paBuilder.setCNextHop(nextHop);
207 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
209 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
210 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
212 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
213 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
215 paBuilder.setCommunities(comms);
216 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
218 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
220 builder.setAttributes(paBuilder.build());
222 assertEquals(builder.build(), message);
224 final ByteBuf buffer = Unpooled.buffer();
225 BGPParserTest.updateParser.serializeMessage(message, buffer);
226 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
230 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
232 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
233 * 00 4b <- length (75) - including header
235 * 00 00 <- withdrawn routes length
236 * 00 30 <- total path attribute length (48)
237 * 40 <- attribute flags
238 * 01 <- attribute type code (origin)
239 * 01 <- attribute length
240 * 02 <- Origin value (Incomplete)
241 * 40 <- attribute flags
242 * 02 <- attribute type code (as path)
243 * 10 <- attribute length
245 * 01 <- path segment count
246 * 00 00 00 1e <- path segment value (30)
248 * 02 <- path segment count
249 * 00 00 00 0a <- path segment value (10)
250 * 00 00 00 14 <- path segment value (20)
251 * 40 <- attribute flags
252 * 03 <- attribute type (Next hop)
253 * 04 <- attribute length
254 * 0a 00 00 09 <- value (10.0.0.9)
255 * 80 <- attribute flags
256 * 04 <- attribute type code (multi exit disc)
257 * 04 <- attribute length
258 * 00 00 00 00 <- value
259 * c0 <- attribute flags
260 * 07 <- attribute type (Aggregator)
261 * 08 <- attribute length
262 * 00 00 00 1e <- value (AS number = 30)
263 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
266 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
269 public void testGetUpdateMessage3() throws Exception {
270 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
271 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
272 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
274 final UpdateBuilder builder = new UpdateBuilder();
277 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
279 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
280 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
281 assertEquals(builder.getNlri(), message.getNlri());
284 assertNull(message.getWithdrawnRoutes());
287 final List<AsNumber> asNumbers = new ArrayList<AsNumber>();
288 asNumbers.add(new AsNumber(30L));
289 final List<Segments> asPath = Lists.newArrayList();
290 asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
291 final List<AsNumber> asSet = Lists.newArrayList(new AsNumber(10L), new AsNumber(20L));
292 asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
294 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
295 new Ipv4Address("10.0.0.9")).build();
296 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
297 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
299 // check path attributes
300 final Attributes attrs = message.getAttributes();
302 final AttributesBuilder paBuilder = new AttributesBuilder();
304 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
305 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
307 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
308 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
310 paBuilder.setCNextHop(nextHop);
311 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
313 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
314 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
316 paBuilder.setAggregator(aggregator);
317 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
318 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
319 builder.setAttributes(paBuilder.build());
321 assertEquals(builder.build(), message);
323 final ByteBuf buffer = Unpooled.buffer();
324 BGPParserTest.updateParser.serializeMessage(message, buffer);
325 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
329 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
331 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
332 * 00 4A <- length (73) - including header
334 * 00 00 <- withdrawn routes length
335 * 00 27 <- total path attribute length (39)
336 * 40 <- attribute flags
337 * 01 <- attribute type code (Origin)
338 * 01 <- attribute length
339 * 01 <- Origin value (EGP)
340 * 40 <- attribute flags
341 * 02 <- attribute type code (As path)
342 * 00 <- attribute length
343 * 40 <- attribute flags
344 * 03 <- attribute type (Next hop)
345 * 04 <- attribute length
346 * 03 03 03 03 <- value (3.3.3.3)
347 * 80 <- attribute flags
348 * 04 <- attribute type code (Multi exit disc)
349 * 04 <- attribute length
350 * 00 00 00 00 <- value
351 * 40 <- attribute flags
352 * 05 <- attribute type (Local Pref)
353 * 04 <- attribute length
354 * 00 00 00 64 <- value (100)
355 * c0 <- attribute flags
356 * 10 <- attribute type (extended community)
357 * 08 <- attribute length
358 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
359 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
360 * 12 34 <- value (local adm. 4660)
363 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
364 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
365 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
368 public void testGetUpdateMessage4() throws Exception {
369 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
370 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
371 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
373 final UpdateBuilder builder = new UpdateBuilder();
376 assertNull(message.getWithdrawnRoutes());
379 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
380 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
381 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
383 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
384 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
385 assertEquals(builder.getNlri(), message.getNlri());
388 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
389 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
391 final List<ExtendedCommunities> comms = Lists.newArrayList();
392 comms.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(
393 new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
394 new RouteTargetIpv4Builder().setGlobalAdministrator(
395 new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660).build()).build()).build());
397 // check path attributes
398 final Attributes attrs = message.getAttributes();
400 final AttributesBuilder paBuilder = new AttributesBuilder();
402 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
403 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
405 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
406 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
408 paBuilder.setCNextHop(nextHop);
409 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
411 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
412 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
414 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
415 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
417 paBuilder.setExtendedCommunities(comms);
418 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
420 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
422 builder.setAttributes(paBuilder.build());
423 assertEquals(builder.build(), message);
425 final ByteBuf buffer = Unpooled.buffer();
426 BGPParserTest.updateParser.serializeMessage(message, buffer);
427 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));
431 * Tests withdrawn routes.
433 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
434 * 00 1c <- length (28) - including header
436 * 00 05 <- withdrawn routes length (5)
437 * 1e ac 10 00 04 <- route (172.16.0.4)
438 * 00 00 <- total path attribute length
441 public void testGetUpdateMessage5() throws Exception {
442 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
443 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
444 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
447 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
450 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
451 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
453 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
455 final ByteBuf buffer = Unpooled.buffer();
456 BGPParserTest.updateParser.serializeMessage(message, buffer);
457 assertArrayEquals(inputBytes.get(4), ByteArray.readAllBytes(buffer));
461 * End of Rib for Ipv4.
463 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
464 * 00 17 <- length (23) - including header
466 * 00 00 <- withdrawn routes length
467 * 00 00 <- total path attribute length
470 public void testEORIpv4() throws Exception {
471 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
472 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
473 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
475 assertEquals(new UpdateBuilder().build(), message);
477 final ByteBuf buffer = Unpooled.buffer();
478 BGPParserTest.updateParser.serializeMessage(message, buffer);
479 assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
483 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
485 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
486 * 00 1d <- length (29) - including header
488 * 00 00 <- withdrawn routes length
489 * 00 06 <- total path attribute length
490 * 80 <- attribute flags
491 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
492 * 03 <- attribute length
493 * 00 02 <- value (AFI 2: IPv6)
494 * 01 <- value (SAFI 1)
497 public void testEORIpv6() throws Exception {
498 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
499 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
500 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
502 final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
503 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
505 assertEquals(Ipv6AddressFamily.class, afi);
506 assertEquals(UnicastSubsequentAddressFamily.class, safi);
508 final ByteBuf buffer = Unpooled.buffer();
509 BGPParserTest.updateParser.serializeMessage(message, buffer);
510 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
514 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
516 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
517 * 00 1e <- length (29) - including header
519 * 00 00 <- withdrawn routes length
520 * 00 07 <- total path attribute length
521 * 90 <- attribute flags
522 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
523 * 00 03 <- attribute length
524 * 00 02 <- value (AFI 2: IPv6)
525 * 01 <- value (SAFI 1)
528 public void testEORIpv6exLength() throws Exception {
529 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
530 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
531 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
533 final Class<? extends AddressFamily> afi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
534 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
536 assertEquals(Ipv6AddressFamily.class, afi);
537 assertEquals(UnicastSubsequentAddressFamily.class, safi);
539 final ByteBuf buffer = Unpooled.buffer();
540 BGPParserTest.updateParser.serializeMessage(message, buffer);
541 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));