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.rev131125.AreaIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.CParameters;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregateBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDiscBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.Segments;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.SegmentsBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutesBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6CaseBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv6._case.DestinationIpv6Builder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.AListCaseBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCaseBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.AListBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequence;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequenceBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.set._case.ASetBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
112 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;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
116 import com.google.common.collect.Lists;
117 import com.google.common.collect.Sets;
119 public class BGPParserTest {
122 * Used by other tests as well
124 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
126 private static int COUNTER = 17;
128 private static int MAX_SIZE = 300;
130 private static BGPUpdateMessageParser updateParser;
133 public static void setUp() throws Exception {
134 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
136 for (int i = 1; i <= COUNTER; i++) {
137 final String name = "/up" + i + ".bin";
138 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
140 throw new IOException("Failed to get resource " + name);
143 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
144 final byte[] data = new byte[MAX_SIZE];
146 while ((nRead = is.read(data, 0, data.length)) != -1) {
147 bis.write(data, 0, nRead);
151 inputBytes.add(bis.toByteArray());
156 public void testResource() {
157 assertNotNull(inputBytes);
161 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
163 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
164 * 00 54 <- length (84) - including header
166 * 00 00 <- withdrawn routes length
167 * 00 31 <- total path attribute length (49)
168 * 40 <- attribute flags
169 * 01 <- attribute type code (origin)
170 * 01 <- attribute length
171 * 00 <- Origin value (IGP)
172 * 40 <- attribute flags
173 * 02 <- attribute type code (as path)
174 * 06 <- attribute length
176 * 01 <- path segment count
177 * 00 00 fd ea <- path segment value (65002)
178 * 40 <- attribute flags
179 * 03 <- attribute type code (Next Hop)
180 * 04 <- attribute length
181 * 10 00 00 02 <- value (10.0.0.2)
182 * 80 <- attribute flags
183 * 04 <- attribute type code (multi exit disc)
184 * 04 <- attribute length
185 * 00 00 00 00 <- value
186 * 64 <- attribute flags
187 * 06 <- attribute type code (atomic aggregate)
188 * 00 <- attribute length
189 * 64 <- attribute flags
190 * 08 <- attribute type code (community)
191 * 10 <- attribute length FF FF FF
192 * 01 <- value (NO_EXPORT)
193 * FF FF FF 02 <- value (NO_ADVERTISE)
194 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
195 * FF FF FF 10 <- unknown Community
198 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
199 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
200 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
203 public void testGetUpdateMessage1() throws Exception {
205 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
206 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH,
207 MessageUtil.LENGTH_FIELD_LENGTH));
208 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
212 assertNull(message.getWithdrawnRoutes());
216 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
217 final List<Segments> asPath = Lists.newArrayList();
218 asPath.add(new SegmentsBuilder().setCSegment(
219 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
221 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
222 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
224 final List<Communities> comms = Lists.newArrayList();
225 comms.add((Communities) CommunityUtil.NO_EXPORT);
226 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
227 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
228 comms.add((Communities) CommunityUtil.create(0xFFFF, 0xFF10));
230 final UpdateBuilder builder = new UpdateBuilder();
234 final List<Ipv4Prefix> prefs = Lists.newArrayList();
235 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
236 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
237 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
239 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
241 assertEquals(nlri, message.getNlri());
243 builder.setNlri(nlri);
245 // check path attributes
247 final PathAttributes attrs = message.getPathAttributes();
249 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
251 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
252 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
254 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
255 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
257 paBuilder.setCNextHop(nextHop);
258 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
260 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
261 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
263 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
264 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
266 paBuilder.setCommunities(comms);
267 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
269 builder.setPathAttributes(paBuilder.build());
271 assertEquals(builder.build(), message);
275 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
277 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
278 * 00 80 <- length (128) - including header
280 * 00 00 <- withdrawn routes length
281 * 00 69 <- total path attribute length (105)
282 * 40 <- attribute flags
283 * 01 <- attribute type code (origin)
284 * 01 <- attribute length
285 * 00 <- Origin value (IGP)
286 * 40 <- attribute flags
287 * 02 <- attribute type code (as path)
288 * 06 <- attribute length
290 * 01 <- path segment count
291 * 00 00 fd e9 <- path segment value (65001)
292 * 80 <- attribute flags
293 * 04 <- attribute type code (multi exit disc)
294 * 04 <- attribute length
295 * 00 00 00 00 <- value
296 * 80 <- attribute flags
297 * 09 <- attribute type code (originator id)
298 * 04 <- attribute length
299 * 7f 00 00 01 <- value (localhost ip)
300 * 80 <- attribute flags
301 * 0a <- attribute type code (cluster list)
302 * 08 <- attribute length
303 * 01 02 03 04 <- value
304 * 05 06 07 08 <- value
305 * 80 <- attribute flags
306 * 0e <- attribute type code (mp reach nlri)
307 * 40 <- attribute length
308 * 00 02 <- AFI (Ipv6)
309 * 01 <- SAFI (Unicast)
310 * 20 <- length of next hop
311 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
312 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
316 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
317 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
318 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
322 public void testGetUpdateMessage2() throws Exception {
323 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
324 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
325 MessageUtil.LENGTH_FIELD_LENGTH));
326 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
329 assertNull(message.getWithdrawnRoutes());
331 final UpdateBuilder builder = new UpdateBuilder();
335 final List<Ipv6Prefix> prefs = Lists.newArrayList();
336 prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
337 prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
338 prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
340 assertNull(message.getNlri());
344 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
345 final List<Segments> asPath = Lists.newArrayList();
346 asPath.add(new SegmentsBuilder().setCSegment(
347 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
349 final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
350 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
352 final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
353 new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
355 // check path attributes
357 final PathAttributes attrs = message.getPathAttributes();
359 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
361 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
362 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
364 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
365 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
367 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
368 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
370 paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
371 assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
373 paBuilder.setClusterId(clusters);
374 assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
376 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
377 mpBuilder.setAfi(Ipv6AddressFamily.class);
378 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
379 mpBuilder.setCNextHop(nextHop);
380 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
381 new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
383 paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
384 assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
385 attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
389 builder.setPathAttributes(paBuilder.build());
390 assertEquals(builder.build(), message);
394 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
396 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
397 * 00 4b <- length (75) - including header
399 * 00 00 <- withdrawn routes length
400 * 00 30 <- total path attribute length (48)
401 * 40 <- attribute flags
402 * 01 <- attribute type code (origin)
403 * 01 <- attribute length
404 * 02 <- Origin value (Incomplete)
405 * 40 <- attribute flags
406 * 02 <- attribute type code (as path)
407 * 10 <- attribute length
409 * 01 <- path segment count
410 * 00 00 00 1e <- path segment value (30)
412 * 02 <- path segment count
413 * 00 00 00 0a <- path segment value (10)
414 * 00 00 00 14 <- path segment value (20)
415 * 40 <- attribute flags
416 * 03 <- attribute type (Next hop)
417 * 04 <- attribute length
418 * 0a 00 00 09 <- value (10.0.0.9)
419 * 80 <- attribute flags
420 * 04 <- attribute type code (multi exit disc)
421 * 04 <- attribute length
422 * 00 00 00 00 <- value
423 * c0 <- attribute flags
424 * 07 <- attribute type (Aggregator)
425 * 08 <- attribute length
426 * 00 00 00 1e <- value (AS number = 30)
427 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
430 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
433 public void testGetUpdateMessage3() throws Exception {
434 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
435 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH,
436 MessageUtil.LENGTH_FIELD_LENGTH));
437 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
439 final UpdateBuilder builder = new UpdateBuilder();
442 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
444 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
445 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
446 assertEquals(builder.getNlri(), message.getNlri());
449 assertNull(message.getWithdrawnRoutes());
452 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
453 final List<Segments> asPath = Lists.newArrayList();
454 asPath.add(new SegmentsBuilder().setCSegment(
455 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
456 asPath.add(new SegmentsBuilder().setCSegment(
457 new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
459 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
460 new Ipv4Address("10.0.0.9")).build();
461 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
462 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
464 // check path attributes
465 final PathAttributes attrs = message.getPathAttributes();
467 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
469 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
470 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
472 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
473 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
475 paBuilder.setCNextHop(nextHop);
476 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
478 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
479 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
481 paBuilder.setAggregator(aggregator);
482 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
484 builder.setPathAttributes(paBuilder.build());
486 assertEquals(builder.build(), message);
490 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
492 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
493 * 00 4A <- length (73) - including header
495 * 00 00 <- withdrawn routes length
496 * 00 27 <- total path attribute length (39)
497 * 40 <- attribute flags
498 * 01 <- attribute type code (Origin)
499 * 01 <- attribute length
500 * 01 <- Origin value (EGP)
501 * 40 <- attribute flags
502 * 02 <- attribute type code (As path)
503 * 00 <- attribute length
504 * 40 <- attribute flags
505 * 03 <- attribute type (Next hop)
506 * 04 <- attribute length
507 * 03 03 03 03 <- value (3.3.3.3)
508 * 80 <- attribute flags
509 * 04 <- attribute type code (Multi exit disc)
510 * 04 <- attribute length
511 * 00 00 00 00 <- value
512 * 40 <- attribute flags
513 * 05 <- attribute type (Local Pref)
514 * 04 <- attribute length
515 * 00 00 00 64 <- value (100)
516 * 80 <- attribute flags
517 * 10 <- attribute type (extended community)
518 * 08 <- attribute length
519 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
520 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
521 * 12 34 <- value (local adm. 4660)
524 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
525 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
526 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
529 public void testGetUpdateMessage4() throws Exception {
530 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
531 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
532 MessageUtil.LENGTH_FIELD_LENGTH));
533 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
535 final UpdateBuilder builder = new UpdateBuilder();
538 assertNull(message.getWithdrawnRoutes());
541 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
542 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
543 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
545 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
546 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
547 assertEquals(builder.getNlri(), message.getNlri());
550 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
551 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
553 final List<ExtendedCommunities> comms = Lists.newArrayList();
554 comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setExtendedCommunity(
555 new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
556 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
557 new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
559 final List<Segments> asPath = Lists.newArrayList();
561 // check path attributes
562 final PathAttributes attrs = message.getPathAttributes();
564 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
566 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
567 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
569 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
570 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
572 paBuilder.setCNextHop(nextHop);
573 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
575 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
576 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
578 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
579 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
581 paBuilder.setExtendedCommunities(comms);
582 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
585 builder.setPathAttributes(paBuilder.build());
586 assertEquals(builder.build(), message);
590 * Tests withdrawn routes.
592 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
593 * 00 1c <- length (28) - including header
595 * 00 05 <- withdrawn routes length (5)
596 * 1e ac 10 00 04 <- route (172.16.0.4)
597 * 00 00 <- total path attribute length
600 public void testGetUpdateMessage5() throws Exception {
601 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
602 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
603 MessageUtil.LENGTH_FIELD_LENGTH));
604 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
607 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
610 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
611 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
613 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
617 * End of Rib for Ipv4.
619 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
620 * 00 17 <- length (23) - including header
622 * 00 00 <- withdrawn routes length
623 * 00 00 <- total path attribute length
626 public void testEORIpv4() throws Exception {
627 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
628 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH,
629 MessageUtil.LENGTH_FIELD_LENGTH));
630 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
632 assertEquals(new UpdateBuilder().build(), message);
636 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
638 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
639 * 00 1d <- length (29) - including header
641 * 00 00 <- withdrawn routes length
642 * 00 06 <- total path attribute length
643 * 80 <- attribute flags
644 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
645 * 03 <- attribute length
646 * 00 02 <- value (AFI 2: IPv6)
647 * 01 <- value (SAFI 1)
650 public void testEORIpv6() throws Exception {
651 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
652 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
653 MessageUtil.LENGTH_FIELD_LENGTH));
654 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
656 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
657 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
659 assertEquals(Ipv6AddressFamily.class, afi);
660 assertEquals(UnicastSubsequentAddressFamily.class, safi);
664 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
666 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
667 * 00 1d <- length (29) - including header
669 * 00 00 <- withdrawn routes length
670 * 00 06 <- total path attribute length
671 * 80 <- attribute flags
672 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
673 * 03 <- attribute length
674 * 40 04 <- value (AFI 16388: LS)
675 * 47 <- value (SAFI 71)
678 public void testEORLS() throws Exception {
679 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
680 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
681 MessageUtil.LENGTH_FIELD_LENGTH));
682 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
684 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
685 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
687 assertEquals(LinkstateAddressFamily.class, afi);
688 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
692 * Tests BGP Link Ipv4
694 00 00 <- withdrawn routes length
695 01 48 <- total path attribute length (328)
696 90 <- attribute flags
697 0e <- attribute type code (MP reach)
698 01 2c <- attribute extended length (300)
699 40 04 <- AFI (16388 - Linkstate)
700 47 <- SAFI (71 - Linkstate)
701 04 <- next hop length
702 19 19 19 01 <- nexthop (25.25.25.1)
705 00 02 <- NLRI type (2 - linkNLRI)
706 00 5d <- NLRI length (93)
707 03 <- ProtocolID - OSPF
708 00 00 00 00 00 00 00 01 <- identifier
710 01 00 <- local node descriptor type (256)
712 02 00 <- node descriptor type (member AS - 512)
714 00 00 00 64 <- value (100)
715 02 01 <- node descriptor type (bgpId - 513)
717 19 19 19 01 <- bgpId (25.25.25.1)
718 02 02 <- node descriptor type (areaId - 514)
721 02 03 <- node descriptor type (routeId - 515)
723 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
725 01 01 <- remote node descriptor type (257)
727 02 00 <- node descriptor type (member AS - 512)
729 00 00 00 64 <- value (100)
730 02 01 <- node descriptor type (bgpId - 513)
732 19 19 19 01 <- bgpId (25.25.25.1)
733 02 02 <- node descriptor type (areaId - 514)
736 02 03 <- node descriptor type (routeId - 515)
738 03 03 03 04 <- OSPF Router Id
740 01 03 <- link descriptor type (IPv4 interface address - 259)
742 0b 0b 0b 03 <- value (11.11.11.3)
744 00 02 <- NLRI type (2 - linkNLRI)
745 00 5d <- NLRI length (93)
746 03 <- ProtocolID - OSPF
747 00 00 00 00 00 00 00 01 <- identifier
749 01 00 <- local node descriptor type (256)
751 02 00 <- node descriptor type (member AS - 512)
753 00 00 00 64 <- value (100)
754 02 01 <- node descriptor type (bgpId - 513)
756 19 19 19 01 <- bgpId (25.25.25.1)
757 02 02 <- node descriptor type (areaId - 514)
760 02 03 <- node descriptor type (routeId - 515)
762 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
764 01 01 <- remote node descriptor type (257)
766 02 00 <- node descriptor type (member AS - 512)
768 00 00 00 64 <- value (100)
769 02 01 <- node descriptor type (bgpId - 513)
771 19 19 19 01 <- bgpId (25.25.25.1)
772 02 02 <- node descriptor type (areaId - 514)
775 02 03 <- node descriptor type (routeId - 515)
777 01 01 01 02 <- OSPF Router Id
779 01 03 <- link descriptor type (IPv4 interface address - 259)
781 0b 0b 0b 01 <- value (11.11.11.1)
783 00 02 <- NLRI type (2 - linkNLRI)
784 00 5d <- NLRI length (93)
785 03 <- ProtocolID - OSPF
786 00 00 00 00 00 00 00 01 <- identifier
788 01 00 <- local node descriptor type (256)
790 02 00 <- node descriptor type (member AS - 512)
792 00 00 00 64 <- value (100)
793 02 01 <- node descriptor type (bgpId - 513)
795 19 19 19 01 <- bgpId (25.25.25.1)
796 02 02 <- node descriptor type (areaId - 514)
799 02 03 <- node descriptor type (routeId - 515)
801 01 01 01 02 <- OSPF Router Id
803 01 01 <- remote node descriptor type (257)
805 02 00 <- node descriptor type (member AS - 512)
807 00 00 00 64 <- value (100)
808 02 01 <- node descriptor type (bgpId - 513)
810 19 19 19 01 <- bgpId (25.25.25.1)
811 02 02 <- node descriptor type (areaId - 514)
814 02 03 <- node descriptor type (routeId - 515)
816 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
818 01 03 <- link descriptor type (IPv4 interface address - 259)
820 0b 0b 0b 01 <- value (11.11.11.1)
822 40 <- attribute flags
823 01 <- attribute type (Origin)
824 01 <- attribute length
826 40 <- attribute flags
827 02 <- attribute type (AS Path)
829 40 <- attribute flags
830 05 <- attribute type (local pref)
833 c0 <- attribute flags
834 63 <- attribute type (Link STATE - 99)
836 04 47 <- link attribute (1095 - Metric)
841 public void testBGPLink() throws Exception {
842 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
843 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
844 MessageUtil.LENGTH_FIELD_LENGTH));
845 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
847 final UpdateBuilder builder = new UpdateBuilder();
851 assertNull(message.getWithdrawnRoutes());
853 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
854 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
856 final List<Segments> asPath = Lists.newArrayList();
858 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
859 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
861 final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
862 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
864 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
865 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
866 clBuilder.setNlriType(NlriType.Link);
867 clBuilder.setProtocolId(ProtocolId.Ospf);
869 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
870 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
871 mpBuilder.setAfi(LinkstateAddressFamily.class);
872 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
873 mpBuilder.setCNextHop(nextHop);
875 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
876 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
877 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
878 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
879 new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
880 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
881 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
882 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
883 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
884 linkstates.add(clBuilder.build());
886 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
887 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
888 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
889 new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
890 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
891 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
892 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
893 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
894 linkstates.add(clBuilder.build());
896 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
897 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
898 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
899 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
900 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
901 new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
902 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
903 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
904 linkstates.add(clBuilder.build());
906 lsBuilder.setMpReachNlri(mpBuilder.build());
908 // check path attributes
909 final PathAttributes attrs = message.getPathAttributes();
911 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
913 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
914 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
916 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
917 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
919 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
920 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
922 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
923 assertEquals(mpBuilder.getAfi(), mp.getAfi());
924 assertEquals(mpBuilder.getSafi(), mp.getSafi());
925 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
927 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
928 dBuilder.setCLinkstateDestination(linkstates);
930 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
931 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
932 lsBuilder.setMpReachNlri(mpBuilder.build());
934 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
936 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder();
938 lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
939 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
940 paBuilder.addAugmentation(
941 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class,
942 lsAttrBuilder.build());
945 lsAttrBuilder.build().getLinkstatePathAttribute(),
946 attrs.getAugmentation(
947 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class).getLinkstatePathAttribute());
949 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
951 assertEquals(linkstates.size(), dests.size());
953 assertEquals(linkstates, dests);
955 builder.setPathAttributes(paBuilder.build());
956 assertEquals(builder.build(), message);
962 * 00 00 <- withdrawn routes length
963 00 b2 <- total path attribute length (178)
964 90 <- attribute flags
965 0e <- attribute type code (MP reach)
966 00 a0 <- attribute extended length (160)
967 40 04 <- AFI (16388 - Linkstate)
968 47 <- SAFI (71 - Linkstate)
969 04 <- next hop length
970 19 19 19 01 - nexthop (25.25.25.1)
973 00 01 <- NLRI type (1 - nodeNLRI)
974 00 31 <- NLRI length (49)
975 03 <- ProtocolID - OSPF
976 00 00 00 00 00 00 00 01 <- identifier
977 01 00 <- local node descriptor type (256)
979 02 00 <- node descriptor type (member AS - 512)
981 00 00 00 64 <- value (100)
982 02 01 <- node descriptor type (bgpId - 513)
984 19 19 19 01 <- bgpId (25.25.25.1)
985 02 02 <- node descriptor type (areaId - 514)
988 02 03 <- node descriptor type (routeId - 515)
990 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
992 00 01 <- NLRI type (1 - nodeNLRI)
993 00 2d <- NLRI length (45)
994 03 <- ProtocolID - OSPF
995 00 00 00 00 00 00 00 01 <- identifier
996 01 00 <- local node descriptor type (256)
998 02 00 <- node descriptor type (member AS - 512)
1000 00 00 00 64 <- value (100)
1001 02 01 <- node descriptor type (bgpId - 513)
1003 19 19 19 01 <- bgpId (25.25.25.1)
1004 02 02 <- node descriptor type (areaId - 514)
1006 00 00 00 00 <- value
1007 02 03 <- node descriptor type (routeId - 515)
1009 03 03 03 04 <- OSPF Router Id
1011 00 01 <- NLRI type (1 - nodeNLRI)
1012 00 2d <- NLRI length (45)
1013 03 <- ProtocolID - OSPF
1014 00 00 00 00 00 00 00 01 <- identifier
1015 01 00 <- local node descriptor type (256)
1016 00 20 <- length (32)
1017 02 00 <- node descriptor type (member AS - 512)
1019 00 00 00 64 <- value (100)
1020 02 01 <- node descriptor type (bgpId - 513)
1022 19 19 19 01 <- bgpId (25.25.25.1)
1023 02 02 <- node descriptor type (areaId - 514)
1025 00 00 00 00 <- value
1026 02 03 <- node descriptor type (routeId - 515)
1028 01 01 01 02 <- OSPF Router Id
1030 40 <- attribute flags
1031 01 <- attribute type (Origin)
1032 01 <- attribute length
1034 40 <- attribute flags
1035 02 <- attribute type (AS Path)
1037 40 <- attribute flags
1038 05 <- attribute type (local pref)
1040 00 00 00 64 <- value
1043 public void testBGPNode() throws Exception {
1044 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
1045 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
1046 MessageUtil.LENGTH_FIELD_LENGTH));
1047 final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
1049 final UpdateBuilder builder = new UpdateBuilder();
1053 assertNull(message.getWithdrawnRoutes());
1057 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
1058 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
1060 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
1061 new DomainIdentifier(0x19191901L)).setAreaId(
1062 new AreaIdentifier(0L));
1064 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
1065 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
1066 clBuilder.setNlriType(NlriType.Node);
1067 clBuilder.setProtocolId(ProtocolId.Ospf);
1069 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
1070 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1071 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
1072 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
1073 new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
1074 linkstates.add(clBuilder.build());
1076 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1077 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
1078 linkstates.add(clBuilder.build());
1080 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1081 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
1082 linkstates.add(clBuilder.build());
1084 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
1085 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
1086 mpBuilder.setAfi(LinkstateAddressFamily.class);
1087 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
1088 mpBuilder.setCNextHop(nextHop);
1090 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
1091 dBuilder.setCLinkstateDestination(linkstates);
1093 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
1094 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
1095 lsBuilder.setMpReachNlri(mpBuilder.build());
1097 final List<Segments> asPath = Lists.newArrayList();
1099 // check path attributes
1100 final PathAttributes attrs = message.getPathAttributes();
1102 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
1104 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
1105 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
1107 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
1108 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
1110 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
1111 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
1113 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
1115 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
1116 assertEquals(mpBuilder.getAfi(), mp.getAfi());
1117 assertEquals(mpBuilder.getSafi(), mp.getSafi());
1118 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
1120 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1122 assertEquals(linkstates.size(), dests.size());
1124 assertEquals(linkstates, dests);
1126 // check API message
1127 builder.setPathAttributes(paBuilder.build());
1128 assertEquals(builder.build(), message);
1132 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1133 * 00 98 <- length (69) - including header
1134 * 01 <- message type
1136 * 00 64 <- My AS Number (AS TRANS in this case)
1137 * 00 b4 <- Hold Time
1138 * 00 00 00 00 <- BGP Identifier
1139 * 28 <- Optional Parameters Length
1140 * 02 <- opt. param. type (capabilities)
1142 * 01 <- capability code (MP Extensions for BGP4)
1144 * 00 01 00 01 <- AFI 1, SAFI 1
1145 * 02 <- opt. param. type (capabilities)
1147 * 01 <- capability code (MP Extensions for BGP4)
1149 * 00 02 00 01 <- AFI 2, SAFI 1
1150 * 02 <- opt. param. type (capabilities)
1152 * 01 <- capability code (MP Extensions for BGP4)
1154 * 40 04 00 47 <- AFI 16388, SAFI 71
1155 * 02 <- opt. param. type (capabilities)
1157 * 80 <- capability code (private)
1159 * 02 <- opt. param. type (capabilities)
1161 * 02 <- capability code (Route refresh)
1163 * 02 <- opt. param. type (capabilities)
1165 * 41 <- capability code (AS4 octet support)
1167 * 00 00 00 64 <- AS number
1170 public void testOpenMessage() throws Exception {
1171 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
1172 final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
1173 final Set<BgpTableType> types = Sets.newHashSet();
1174 for (final BgpParameters param : open.getBgpParameters()) {
1175 final CParameters p = param.getCParameters();
1176 if (p instanceof MultiprotocolCase) {
1177 final BgpTableType type = new BgpTableTypeImpl(((MultiprotocolCase) p).getMultiprotocolCapability().getAfi(), ((MultiprotocolCase) p).getMultiprotocolCapability().getSafi());
1181 final Set<BgpTableType> expected = Sets.newHashSet();
1182 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1183 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1184 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1185 assertEquals(expected, types);