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 java.io.ByteArrayOutputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.List;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
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.MessageRegistry;
29 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
30 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
31 import org.opendaylight.protocol.util.ByteArray;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Aggregator;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AsPathBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AtomicAggregateBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Communities;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunities;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunitiesBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.LocalPrefBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.MultiExitDiscBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.Segments;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.Nlri;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.WithdrawnRoutesBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
111 import com.google.common.collect.Lists;
112 import com.google.common.collect.Sets;
114 public class BGPParserTest {
117 * Used by other tests as well
119 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
121 private static int COUNTER = 17;
123 private static int MAX_SIZE = 300;
125 private static BGPUpdateMessageParser updateParser;
128 public static void setUp() throws Exception {
129 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
131 for (int i = 1; i <= COUNTER; i++) {
132 final String name = "/up" + i + ".bin";
133 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
135 throw new IOException("Failed to get resource " + name);
138 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
139 final byte[] data = new byte[MAX_SIZE];
141 while ((nRead = is.read(data, 0, data.length)) != -1) {
142 bis.write(data, 0, nRead);
146 inputBytes.add(bis.toByteArray());
151 public void testResource() {
152 assertNotNull(inputBytes);
156 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
158 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
159 * 00 54 <- length (84) - including header
161 * 00 00 <- withdrawn routes length
162 * 00 31 <- total path attribute length (49)
163 * 40 <- attribute flags
164 * 01 <- attribute type code (origin)
165 * 01 <- attribute length
166 * 00 <- Origin value (IGP)
167 * 40 <- attribute flags
168 * 02 <- attribute type code (as path)
169 * 06 <- attribute length
171 * 01 <- path segment count
172 * 00 00 fd ea <- path segment value (65002)
173 * 40 <- attribute flags
174 * 03 <- attribute type code (Next Hop)
175 * 04 <- attribute length
176 * 10 00 00 02 <- value (10.0.0.2)
177 * 80 <- attribute flags
178 * 04 <- attribute type code (multi exit disc)
179 * 04 <- attribute length
180 * 00 00 00 00 <- value
181 * 64 <- attribute flags
182 * 06 <- attribute type code (atomic aggregate)
183 * 00 <- attribute length
184 * 64 <- attribute flags
185 * 08 <- attribute type code (community)
186 * 10 <- attribute length FF FF FF
187 * 01 <- value (NO_EXPORT)
188 * FF FF FF 02 <- value (NO_ADVERTISE)
189 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
190 * FF FF FF 10 <- unknown Community
193 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
194 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
195 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
198 public void testGetUpdateMessage1() throws Exception {
200 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
201 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH,
202 MessageUtil.LENGTH_FIELD_LENGTH));
203 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
207 assertNull(message.getWithdrawnRoutes());
211 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
212 final List<Segments> asPath = Lists.newArrayList();
213 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
215 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
216 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
218 final List<Communities> comms = Lists.newArrayList();
219 comms.add((Communities) CommunityUtil.NO_EXPORT);
220 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
221 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
222 comms.add((Communities) CommunityUtil.create(0xFFFF, 0xFF10));
224 final UpdateBuilder builder = new UpdateBuilder();
228 final List<Ipv4Prefix> prefs = Lists.newArrayList();
229 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
230 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
231 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
233 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
235 assertEquals(nlri, message.getNlri());
237 builder.setNlri(nlri);
239 // check path attributes
241 final PathAttributes attrs = message.getPathAttributes();
243 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
245 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
246 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
248 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
249 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
251 paBuilder.setCNextHop(nextHop);
252 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
254 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
255 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
257 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
258 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
260 paBuilder.setCommunities(comms);
261 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
263 builder.setPathAttributes(paBuilder.build());
265 assertEquals(builder.build(), message);
269 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
271 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
272 * 00 80 <- length (128) - including header
274 * 00 00 <- withdrawn routes length
275 * 00 69 <- total path attribute length (105)
276 * 40 <- attribute flags
277 * 01 <- attribute type code (origin)
278 * 01 <- attribute length
279 * 00 <- Origin value (IGP)
280 * 40 <- attribute flags
281 * 02 <- attribute type code (as path)
282 * 06 <- attribute length
284 * 01 <- path segment count
285 * 00 00 fd e9 <- path segment value (65001)
286 * 80 <- attribute flags
287 * 04 <- attribute type code (multi exit disc)
288 * 04 <- attribute length
289 * 00 00 00 00 <- value
290 * 80 <- attribute flags
291 * 09 <- attribute type code (originator id)
292 * 04 <- attribute length
293 * 7f 00 00 01 <- value (localhost ip)
294 * 80 <- attribute flags
295 * 0a <- attribute type code (cluster list)
296 * 08 <- attribute length
297 * 01 02 03 04 <- value
298 * 05 06 07 08 <- value
299 * 80 <- attribute flags
300 * 0e <- attribute type code (mp reach nlri)
301 * 40 <- attribute length
302 * 00 02 <- AFI (Ipv6)
303 * 01 <- SAFI (Unicast)
304 * 20 <- length of next hop
305 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
306 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
310 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
311 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
312 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
316 public void testGetUpdateMessage2() throws Exception {
317 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
318 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
319 MessageUtil.LENGTH_FIELD_LENGTH));
320 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
323 assertNull(message.getWithdrawnRoutes());
325 final UpdateBuilder builder = new UpdateBuilder();
329 final List<Ipv6Prefix> prefs = Lists.newArrayList();
330 prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
331 prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
332 prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
334 assertNull(message.getNlri());
338 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
339 final List<Segments> asPath = Lists.newArrayList();
340 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
342 final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
343 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
345 final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
346 new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
348 // check path attributes
350 final PathAttributes attrs = message.getPathAttributes();
352 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
354 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
355 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
357 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
358 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
360 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
361 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
363 paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
364 assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
366 paBuilder.setClusterId(clusters);
367 assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
369 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
370 mpBuilder.setAfi(Ipv6AddressFamily.class);
371 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
372 mpBuilder.setCNextHop(nextHop);
373 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
374 new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build());
376 paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
377 assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
378 attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
382 builder.setPathAttributes(paBuilder.build());
383 assertEquals(builder.build(), message);
387 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
389 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
390 * 00 4b <- length (75) - including header
392 * 00 00 <- withdrawn routes length
393 * 00 30 <- total path attribute length (48)
394 * 40 <- attribute flags
395 * 01 <- attribute type code (origin)
396 * 01 <- attribute length
397 * 02 <- Origin value (Incomplete)
398 * 40 <- attribute flags
399 * 02 <- attribute type code (as path)
400 * 10 <- attribute length
402 * 01 <- path segment count
403 * 00 00 00 1e <- path segment value (30)
405 * 02 <- path segment count
406 * 00 00 00 0a <- path segment value (10)
407 * 00 00 00 14 <- path segment value (20)
408 * 40 <- attribute flags
409 * 03 <- attribute type (Next hop)
410 * 04 <- attribute length
411 * 0a 00 00 09 <- value (10.0.0.9)
412 * 80 <- attribute flags
413 * 04 <- attribute type code (multi exit disc)
414 * 04 <- attribute length
415 * 00 00 00 00 <- value
416 * c0 <- attribute flags
417 * 07 <- attribute type (Aggregator)
418 * 08 <- attribute length
419 * 00 00 00 1e <- value (AS number = 30)
420 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
423 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
426 public void testGetUpdateMessage3() throws Exception {
427 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
428 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH,
429 MessageUtil.LENGTH_FIELD_LENGTH));
430 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
432 final UpdateBuilder builder = new UpdateBuilder();
435 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
437 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
438 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
439 assertEquals(builder.getNlri(), message.getNlri());
442 assertNull(message.getWithdrawnRoutes());
445 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
446 final List<Segments> asPath = Lists.newArrayList();
447 asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
448 asPath.add(new SegmentsBuilder().setCSegment(
449 new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
451 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
452 new Ipv4Address("10.0.0.9")).build();
453 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
454 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
456 // check path attributes
457 final PathAttributes attrs = message.getPathAttributes();
459 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
461 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
462 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
464 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
465 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
467 paBuilder.setCNextHop(nextHop);
468 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
470 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
471 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
473 paBuilder.setAggregator(aggregator);
474 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
476 builder.setPathAttributes(paBuilder.build());
478 assertEquals(builder.build(), message);
482 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
484 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
485 * 00 4A <- length (73) - including header
487 * 00 00 <- withdrawn routes length
488 * 00 27 <- total path attribute length (39)
489 * 40 <- attribute flags
490 * 01 <- attribute type code (Origin)
491 * 01 <- attribute length
492 * 01 <- Origin value (EGP)
493 * 40 <- attribute flags
494 * 02 <- attribute type code (As path)
495 * 00 <- attribute length
496 * 40 <- attribute flags
497 * 03 <- attribute type (Next hop)
498 * 04 <- attribute length
499 * 03 03 03 03 <- value (3.3.3.3)
500 * 80 <- attribute flags
501 * 04 <- attribute type code (Multi exit disc)
502 * 04 <- attribute length
503 * 00 00 00 00 <- value
504 * 40 <- attribute flags
505 * 05 <- attribute type (Local Pref)
506 * 04 <- attribute length
507 * 00 00 00 64 <- value (100)
508 * 80 <- attribute flags
509 * 10 <- attribute type (extended community)
510 * 08 <- attribute length
511 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
512 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
513 * 12 34 <- value (local adm. 4660)
516 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
517 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
518 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
521 public void testGetUpdateMessage4() throws Exception {
522 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
523 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
524 MessageUtil.LENGTH_FIELD_LENGTH));
525 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
527 final UpdateBuilder builder = new UpdateBuilder();
530 assertNull(message.getWithdrawnRoutes());
533 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
534 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
535 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
537 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
538 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
539 assertEquals(builder.getNlri(), message.getNlri());
542 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
543 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
545 final List<ExtendedCommunities> comms = Lists.newArrayList();
546 comms.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(
547 new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
548 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
549 new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
551 final List<Segments> asPath = Lists.newArrayList();
553 // check path attributes
554 final PathAttributes attrs = message.getPathAttributes();
556 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
558 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
559 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
561 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
562 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
564 paBuilder.setCNextHop(nextHop);
565 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
567 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
568 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
570 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
571 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
573 paBuilder.setExtendedCommunities(comms);
574 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
577 builder.setPathAttributes(paBuilder.build());
578 assertEquals(builder.build(), message);
582 * Tests withdrawn routes.
584 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
585 * 00 1c <- length (28) - including header
587 * 00 05 <- withdrawn routes length (5)
588 * 1e ac 10 00 04 <- route (172.16.0.4)
589 * 00 00 <- total path attribute length
592 public void testGetUpdateMessage5() throws Exception {
593 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
594 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
595 MessageUtil.LENGTH_FIELD_LENGTH));
596 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
599 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
602 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
603 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
605 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
609 * End of Rib for Ipv4.
611 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
612 * 00 17 <- length (23) - including header
614 * 00 00 <- withdrawn routes length
615 * 00 00 <- total path attribute length
618 public void testEORIpv4() throws Exception {
619 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
620 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH,
621 MessageUtil.LENGTH_FIELD_LENGTH));
622 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
624 assertEquals(new UpdateBuilder().build(), message);
628 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
630 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
631 * 00 1d <- length (29) - including header
633 * 00 00 <- withdrawn routes length
634 * 00 06 <- total path attribute length
635 * 80 <- attribute flags
636 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
637 * 03 <- attribute length
638 * 00 02 <- value (AFI 2: IPv6)
639 * 01 <- value (SAFI 1)
642 public void testEORIpv6() throws Exception {
643 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
644 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
645 MessageUtil.LENGTH_FIELD_LENGTH));
646 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
648 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
649 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
651 assertEquals(Ipv6AddressFamily.class, afi);
652 assertEquals(UnicastSubsequentAddressFamily.class, safi);
656 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
658 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
659 * 00 1d <- length (29) - including header
661 * 00 00 <- withdrawn routes length
662 * 00 06 <- total path attribute length
663 * 80 <- attribute flags
664 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
665 * 03 <- attribute length
666 * 40 04 <- value (AFI 16388: LS)
667 * 47 <- value (SAFI 71)
670 public void testEORLS() throws Exception {
671 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
672 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
673 MessageUtil.LENGTH_FIELD_LENGTH));
674 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
676 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
677 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
679 assertEquals(LinkstateAddressFamily.class, afi);
680 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
684 * Tests BGP Link Ipv4
686 00 00 <- withdrawn routes length
687 01 48 <- total path attribute length (328)
688 90 <- attribute flags
689 0e <- attribute type code (MP reach)
690 01 2c <- attribute extended length (300)
691 40 04 <- AFI (16388 - Linkstate)
692 47 <- SAFI (71 - Linkstate)
693 04 <- next hop length
694 19 19 19 01 <- nexthop (25.25.25.1)
697 00 02 <- NLRI type (2 - linkNLRI)
698 00 5d <- NLRI length (93)
699 03 <- ProtocolID - OSPF
700 00 00 00 00 00 00 00 01 <- identifier
702 01 00 <- local node descriptor type (256)
704 02 00 <- node descriptor type (member AS - 512)
706 00 00 00 64 <- value (100)
707 02 01 <- node descriptor type (bgpId - 513)
709 19 19 19 01 <- bgpId (25.25.25.1)
710 02 02 <- node descriptor type (areaId - 514)
713 02 03 <- node descriptor type (routeId - 515)
715 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
717 01 01 <- remote node descriptor type (257)
719 02 00 <- node descriptor type (member AS - 512)
721 00 00 00 64 <- value (100)
722 02 01 <- node descriptor type (bgpId - 513)
724 19 19 19 01 <- bgpId (25.25.25.1)
725 02 02 <- node descriptor type (areaId - 514)
728 02 03 <- node descriptor type (routeId - 515)
730 03 03 03 04 <- OSPF Router Id
732 01 03 <- link descriptor type (IPv4 interface address - 259)
734 0b 0b 0b 03 <- value (11.11.11.3)
736 00 02 <- NLRI type (2 - linkNLRI)
737 00 5d <- NLRI length (93)
738 03 <- ProtocolID - OSPF
739 00 00 00 00 00 00 00 01 <- identifier
741 01 00 <- local node descriptor type (256)
743 02 00 <- node descriptor type (member AS - 512)
745 00 00 00 64 <- value (100)
746 02 01 <- node descriptor type (bgpId - 513)
748 19 19 19 01 <- bgpId (25.25.25.1)
749 02 02 <- node descriptor type (areaId - 514)
752 02 03 <- node descriptor type (routeId - 515)
754 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
756 01 01 <- remote node descriptor type (257)
758 02 00 <- node descriptor type (member AS - 512)
760 00 00 00 64 <- value (100)
761 02 01 <- node descriptor type (bgpId - 513)
763 19 19 19 01 <- bgpId (25.25.25.1)
764 02 02 <- node descriptor type (areaId - 514)
767 02 03 <- node descriptor type (routeId - 515)
769 01 01 01 02 <- OSPF Router Id
771 01 03 <- link descriptor type (IPv4 interface address - 259)
773 0b 0b 0b 01 <- value (11.11.11.1)
775 00 02 <- NLRI type (2 - linkNLRI)
776 00 5d <- NLRI length (93)
777 03 <- ProtocolID - OSPF
778 00 00 00 00 00 00 00 01 <- identifier
780 01 00 <- local node descriptor type (256)
782 02 00 <- node descriptor type (member AS - 512)
784 00 00 00 64 <- value (100)
785 02 01 <- node descriptor type (bgpId - 513)
787 19 19 19 01 <- bgpId (25.25.25.1)
788 02 02 <- node descriptor type (areaId - 514)
791 02 03 <- node descriptor type (routeId - 515)
793 01 01 01 02 <- OSPF Router Id
795 01 01 <- remote node descriptor type (257)
797 02 00 <- node descriptor type (member AS - 512)
799 00 00 00 64 <- value (100)
800 02 01 <- node descriptor type (bgpId - 513)
802 19 19 19 01 <- bgpId (25.25.25.1)
803 02 02 <- node descriptor type (areaId - 514)
806 02 03 <- node descriptor type (routeId - 515)
808 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
810 01 03 <- link descriptor type (IPv4 interface address - 259)
812 0b 0b 0b 01 <- value (11.11.11.1)
814 40 <- attribute flags
815 01 <- attribute type (Origin)
816 01 <- attribute length
818 40 <- attribute flags
819 02 <- attribute type (AS Path)
821 40 <- attribute flags
822 05 <- attribute type (local pref)
825 c0 <- attribute flags
826 63 <- attribute type (Link STATE - 99)
828 04 47 <- link attribute (1095 - Metric)
833 public void testBGPLink() throws Exception {
834 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
835 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
836 MessageUtil.LENGTH_FIELD_LENGTH));
837 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
839 final UpdateBuilder builder = new UpdateBuilder();
843 assertNull(message.getWithdrawnRoutes());
845 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
846 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
848 final List<Segments> asPath = Lists.newArrayList();
850 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
851 new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
852 new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
854 final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
855 new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
856 new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
858 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
859 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
860 clBuilder.setNlriType(NlriType.Link);
861 clBuilder.setProtocolId(ProtocolId.Ospf);
863 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
864 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
865 mpBuilder.setAfi(LinkstateAddressFamily.class);
866 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
867 mpBuilder.setCNextHop(nextHop);
869 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
870 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
871 new COspfPseudonodeBuilder().setOspfPseudonode(
872 new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
873 new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
874 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
875 new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
876 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
877 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
878 linkstates.add(clBuilder.build());
880 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
881 new COspfPseudonodeBuilder().setOspfPseudonode(
882 new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
883 new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
884 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
885 new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
886 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
887 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
888 linkstates.add(clBuilder.build());
890 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
891 new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
892 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
893 new COspfPseudonodeBuilder().setOspfPseudonode(
894 new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
895 new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
896 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
897 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
898 linkstates.add(clBuilder.build());
900 lsBuilder.setMpReachNlri(mpBuilder.build());
902 // check path attributes
903 final PathAttributes attrs = message.getPathAttributes();
905 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
907 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
908 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
910 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
911 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
913 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
914 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
916 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
917 assertEquals(mpBuilder.getAfi(), mp.getAfi());
918 assertEquals(mpBuilder.getSafi(), mp.getSafi());
919 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
921 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
922 dBuilder.setCLinkstateDestination(linkstates);
924 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
925 lsBuilder.setMpReachNlri(mpBuilder.build());
927 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
929 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder();
931 lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
932 new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
933 paBuilder.addAugmentation(
934 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class,
935 lsAttrBuilder.build());
938 lsAttrBuilder.build().getLinkstatePathAttribute(),
939 attrs.getAugmentation(
940 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class).getLinkstatePathAttribute());
942 final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
944 assertEquals(linkstates.size(), dests.size());
946 assertEquals(linkstates, dests);
948 builder.setPathAttributes(paBuilder.build());
949 assertEquals(builder.build(), message);
955 * 00 00 <- withdrawn routes length
956 00 b2 <- total path attribute length (178)
957 90 <- attribute flags
958 0e <- attribute type code (MP reach)
959 00 a0 <- attribute extended length (160)
960 40 04 <- AFI (16388 - Linkstate)
961 47 <- SAFI (71 - Linkstate)
962 04 <- next hop length
963 19 19 19 01 - nexthop (25.25.25.1)
966 00 01 <- NLRI type (1 - nodeNLRI)
967 00 31 <- NLRI length (49)
968 03 <- ProtocolID - OSPF
969 00 00 00 00 00 00 00 01 <- identifier
970 01 00 <- local node descriptor type (256)
972 02 00 <- node descriptor type (member AS - 512)
974 00 00 00 64 <- value (100)
975 02 01 <- node descriptor type (bgpId - 513)
977 19 19 19 01 <- bgpId (25.25.25.1)
978 02 02 <- node descriptor type (areaId - 514)
981 02 03 <- node descriptor type (routeId - 515)
983 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
985 00 01 <- NLRI type (1 - nodeNLRI)
986 00 2d <- NLRI length (45)
987 03 <- ProtocolID - OSPF
988 00 00 00 00 00 00 00 01 <- identifier
989 01 00 <- local node descriptor type (256)
991 02 00 <- node descriptor type (member AS - 512)
993 00 00 00 64 <- value (100)
994 02 01 <- node descriptor type (bgpId - 513)
996 19 19 19 01 <- bgpId (25.25.25.1)
997 02 02 <- node descriptor type (areaId - 514)
1000 02 03 <- node descriptor type (routeId - 515)
1002 03 03 03 04 <- OSPF Router Id
1004 00 01 <- NLRI type (1 - nodeNLRI)
1005 00 2d <- NLRI length (45)
1006 03 <- ProtocolID - OSPF
1007 00 00 00 00 00 00 00 01 <- identifier
1008 01 00 <- local node descriptor type (256)
1009 00 20 <- length (32)
1010 02 00 <- node descriptor type (member AS - 512)
1012 00 00 00 64 <- value (100)
1013 02 01 <- node descriptor type (bgpId - 513)
1015 19 19 19 01 <- bgpId (25.25.25.1)
1016 02 02 <- node descriptor type (areaId - 514)
1018 00 00 00 00 <- value
1019 02 03 <- node descriptor type (routeId - 515)
1021 01 01 01 02 <- OSPF Router Id
1023 40 <- attribute flags
1024 01 <- attribute type (Origin)
1025 01 <- attribute length
1027 40 <- attribute flags
1028 02 <- attribute type (AS Path)
1030 40 <- attribute flags
1031 05 <- attribute type (local pref)
1033 00 00 00 64 <- value
1036 public void testBGPNode() throws Exception {
1037 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
1038 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
1039 MessageUtil.LENGTH_FIELD_LENGTH));
1040 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
1042 final UpdateBuilder builder = new UpdateBuilder();
1046 assertNull(message.getWithdrawnRoutes());
1050 final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
1051 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
1053 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
1054 new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
1055 new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
1057 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
1058 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
1059 clBuilder.setNlriType(NlriType.Node);
1060 clBuilder.setProtocolId(ProtocolId.Ospf);
1062 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
1063 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1064 new COspfPseudonodeBuilder().setOspfPseudonode(
1065 new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
1066 new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
1067 linkstates.add(clBuilder.build());
1069 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1070 new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
1071 linkstates.add(clBuilder.build());
1073 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1074 new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
1075 linkstates.add(clBuilder.build());
1077 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
1078 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
1079 mpBuilder.setAfi(LinkstateAddressFamily.class);
1080 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
1081 mpBuilder.setCNextHop(nextHop);
1083 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
1084 dBuilder.setCLinkstateDestination(linkstates);
1086 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
1087 lsBuilder.setMpReachNlri(mpBuilder.build());
1089 final List<Segments> asPath = Lists.newArrayList();
1091 // check path attributes
1092 final PathAttributes attrs = message.getPathAttributes();
1094 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
1096 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
1097 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
1099 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
1100 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
1102 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
1103 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
1105 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
1107 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
1108 assertEquals(mpBuilder.getAfi(), mp.getAfi());
1109 assertEquals(mpBuilder.getSafi(), mp.getSafi());
1110 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
1112 final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
1114 assertEquals(linkstates.size(), dests.size());
1116 assertEquals(linkstates, dests);
1118 // check API message
1119 builder.setPathAttributes(paBuilder.build());
1120 assertEquals(builder.build(), message);
1124 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1125 * 00 98 <- length (69) - including header
1126 * 01 <- message type
1128 * 00 64 <- My AS Number (AS TRANS in this case)
1129 * 00 b4 <- Hold Time
1130 * 00 00 00 00 <- BGP Identifier
1131 * 28 <- Optional Parameters Length
1132 * 02 <- opt. param. type (capabilities)
1134 * 01 <- capability code (MP Extensions for BGP4)
1136 * 00 01 00 01 <- AFI 1, SAFI 1
1137 * 02 <- opt. param. type (capabilities)
1139 * 01 <- capability code (MP Extensions for BGP4)
1141 * 00 02 00 01 <- AFI 2, SAFI 1
1142 * 02 <- opt. param. type (capabilities)
1144 * 01 <- capability code (MP Extensions for BGP4)
1146 * 40 04 00 47 <- AFI 16388, SAFI 71
1147 * 02 <- opt. param. type (capabilities)
1149 * 80 <- capability code (private)
1151 * 02 <- opt. param. type (capabilities)
1153 * 02 <- capability code (Route refresh)
1155 * 02 <- opt. param. type (capabilities)
1157 * 41 <- capability code (AS4 octet support)
1159 * 00 00 00 64 <- AS number
1162 public void testOpenMessage() throws Exception {
1163 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
1164 final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
1165 final Set<BgpTableType> types = Sets.newHashSet();
1166 for (final BgpParameters param : open.getBgpParameters()) {
1167 final CParameters p = param.getCParameters();
1168 if (p instanceof CMultiprotocol) {
1169 final BgpTableType type = new BgpTableTypeImpl(((CMultiprotocol) p).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) p).getMultiprotocolCapability().getSafi());
1173 final Set<BgpTableType> expected = Sets.newHashSet();
1174 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1175 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1176 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1177 assertEquals(expected, types);