2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.parser.impl;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
15 import com.google.common.collect.Lists;
16 import com.google.common.collect.Sets;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.math.BigInteger;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
30 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
32 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
33 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
34 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
35 import org.opendaylight.protocol.util.ByteArray;
36 import org.opendaylight.protocol.util.NoopReferenceCache;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
61 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;
62 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;
63 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;
64 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;
65 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;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.CParameters;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregateBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ClusterIdBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDiscBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginatorIdBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.Segments;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.SegmentsBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutesBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6CaseBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv6._case.DestinationIpv6Builder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.AListCaseBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCaseBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.AListBuilder;
110 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;
111 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;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.set._case.ASetBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
114 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;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
119 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;
120 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;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
122 import org.opendaylight.yangtools.yang.binding.Notification;
124 public class BGPParserTest {
127 * Used by other tests as well
129 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
131 private static int COUNTER = 17;
133 private static int MAX_SIZE = 300;
135 private static BGPUpdateMessageParser updateParser;
137 private static final int LENGTH_FIELD_LENGTH = 2;
140 public static void setUp() throws Exception {
141 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
142 for (int i = 1; i <= COUNTER; i++) {
143 final String name = "/up" + i + ".bin";
144 try (final InputStream is = BGPParserTest.class.getResourceAsStream(name)){
146 throw new IOException("Failed to get resource " + name);
148 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
149 final byte[] data = new byte[MAX_SIZE];
151 while ((nRead = is.read(data, 0, data.length)) != -1) {
152 bis.write(data, 0, nRead);
156 inputBytes.add(bis.toByteArray());
164 public void testResource() {
165 assertNotNull(inputBytes);
169 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
171 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
172 * 00 54 <- length (84) - including header
174 * 00 00 <- withdrawn routes length
175 * 00 31 <- total path attribute length (49)
176 * 40 <- attribute flags
177 * 01 <- attribute type code (origin)
178 * 01 <- attribute length
179 * 00 <- Origin value (IGP)
180 * 40 <- attribute flags
181 * 02 <- attribute type code (as path)
182 * 06 <- attribute length
184 * 01 <- path segment count
185 * 00 00 fd ea <- path segment value (65002)
186 * 40 <- attribute flags
187 * 03 <- attribute type code (Next Hop)
188 * 04 <- attribute length
189 * 10 00 00 02 <- value (10.0.0.2)
190 * 80 <- attribute flags
191 * 04 <- attribute type code (multi exit disc)
192 * 04 <- attribute length
193 * 00 00 00 00 <- value
194 * 60 <- attribute flags
195 * 06 <- attribute type code (atomic aggregate)
196 * 00 <- attribute length
197 * 40 <- attribute flags
198 * 08 <- attribute type code (community)
199 * 10 <- attribute length FF FF FF
200 * 01 <- value (NO_EXPORT)
201 * FF FF FF 02 <- value (NO_ADVERTISE)
202 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
203 * FF FF FF 10 <- unknown Community
206 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
207 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
208 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
211 public void testGetUpdateMessage1() throws Exception {
213 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
214 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
215 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
219 assertNull(message.getWithdrawnRoutes());
223 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
224 final List<Segments> asPath = Lists.newArrayList();
225 asPath.add(new SegmentsBuilder().setCSegment(
226 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
228 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
229 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
231 final List<Communities> comms = Lists.newArrayList();
232 comms.add((Communities) CommunityUtil.NO_EXPORT);
233 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
234 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
235 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
237 final UpdateBuilder builder = new UpdateBuilder();
241 final List<Ipv4Prefix> prefs = Lists.newArrayList();
242 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
243 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
244 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
246 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
248 assertEquals(nlri, message.getNlri());
250 builder.setNlri(nlri);
252 // check path attributes
254 final PathAttributes attrs = message.getPathAttributes();
256 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
258 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
259 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
261 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
262 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
264 paBuilder.setCNextHop(nextHop);
265 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
267 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
268 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
270 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
271 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
273 paBuilder.setCommunities(comms);
274 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
276 builder.setPathAttributes(paBuilder.build());
278 assertEquals(builder.build(), message);
280 final ByteBuf buffer = Unpooled.buffer();
281 BGPParserTest.updateParser.serializeMessage(message, buffer);
282 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
286 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
288 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
289 * 00 80 <- length (128) - including header
291 * 00 00 <- withdrawn routes length
292 * 00 69 <- total path attribute length (105)
293 * 40 <- attribute flags
294 * 01 <- attribute type code (origin)
295 * 01 <- attribute length
296 * 00 <- Origin value (IGP)
297 * 40 <- attribute flags
298 * 02 <- attribute type code (as path)
299 * 06 <- attribute length
301 * 01 <- path segment count
302 * 00 00 fd e9 <- path segment value (65001)
303 * 40 <- attribute flags
304 * 03 <- attribute type code (next hop)
305 * 04 <- attribute length
306 * 0a 00 00 00 <- next hop value (10.0.0.0)
307 * 80 <- attribute flags
308 * 04 <- attribute type code (multi exit disc)
309 * 04 <- attribute length
310 * 00 00 00 00 <- value
311 * 80 <- attribute flags
312 * 09 <- attribute type code (originator id)
313 * 04 <- attribute length
314 * 7f 00 00 01 <- value (localhost ip)
315 * 80 <- attribute flags
316 * 0a <- attribute type code (cluster list)
317 * 08 <- attribute length
318 * 01 02 03 04 <- value
319 * 05 06 07 08 <- value
320 * 80 <- attribute flags
321 * 0e <- attribute type code (mp reach nlri)
322 * 40 <- attribute length
323 * 00 02 <- AFI (Ipv6)
324 * 01 <- SAFI (Unicast)
325 * 20 <- length of next hop
326 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
327 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
331 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
332 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
333 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
337 public void testGetUpdateMessage2() throws Exception {
338 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
339 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
340 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
343 assertNull(message.getWithdrawnRoutes());
345 final UpdateBuilder builder = new UpdateBuilder();
349 final List<Ipv6Prefix> prefs = Lists.newArrayList();
350 prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
351 prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
352 prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
354 assertNull(message.getNlri());
358 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
359 final List<Segments> asPath = Lists.newArrayList();
360 asPath.add(new SegmentsBuilder().setCSegment(
361 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
363 final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
364 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
366 final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
367 new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
369 // check path attributes
371 final PathAttributes attrs = message.getPathAttributes();
373 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
375 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
376 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
378 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
379 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
381 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
382 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
384 paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build());
385 assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
387 paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
388 assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
390 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
391 mpBuilder.setAfi(Ipv6AddressFamily.class);
392 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
393 mpBuilder.setCNextHop(nextHop);
394 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
395 new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
397 paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
398 assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
399 attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
403 builder.setPathAttributes(paBuilder.build());
404 assertEquals(builder.build(), message);
406 final ByteBuf buffer = Unpooled.buffer();
407 BGPParserTest.updateParser.serializeMessage(message, buffer);
408 assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
412 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
414 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
415 * 00 4b <- length (75) - including header
417 * 00 00 <- withdrawn routes length
418 * 00 30 <- total path attribute length (48)
419 * 40 <- attribute flags
420 * 01 <- attribute type code (origin)
421 * 01 <- attribute length
422 * 02 <- Origin value (Incomplete)
423 * 40 <- attribute flags
424 * 02 <- attribute type code (as path)
425 * 10 <- attribute length
427 * 01 <- path segment count
428 * 00 00 00 1e <- path segment value (30)
430 * 02 <- path segment count
431 * 00 00 00 0a <- path segment value (10)
432 * 00 00 00 14 <- path segment value (20)
433 * 40 <- attribute flags
434 * 03 <- attribute type (Next hop)
435 * 04 <- attribute length
436 * 0a 00 00 09 <- value (10.0.0.9)
437 * 80 <- attribute flags
438 * 04 <- attribute type code (multi exit disc)
439 * 04 <- attribute length
440 * 00 00 00 00 <- value
441 * c0 <- attribute flags
442 * 07 <- attribute type (Aggregator)
443 * 08 <- attribute length
444 * 00 00 00 1e <- value (AS number = 30)
445 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
448 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
451 public void testGetUpdateMessage3() throws Exception {
452 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
453 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
454 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
456 final UpdateBuilder builder = new UpdateBuilder();
459 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
461 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
462 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
463 assertEquals(builder.getNlri(), message.getNlri());
466 assertNull(message.getWithdrawnRoutes());
469 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
470 final List<Segments> asPath = Lists.newArrayList();
471 asPath.add(new SegmentsBuilder().setCSegment(
472 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
473 asPath.add(new SegmentsBuilder().setCSegment(
474 new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
476 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
477 new Ipv4Address("10.0.0.9")).build();
478 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
479 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
481 // check path attributes
482 final PathAttributes attrs = message.getPathAttributes();
484 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
486 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
487 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
489 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
490 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
492 paBuilder.setCNextHop(nextHop);
493 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
495 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
496 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
498 paBuilder.setAggregator(aggregator);
499 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
501 builder.setPathAttributes(paBuilder.build());
503 assertEquals(builder.build(), message);
505 final ByteBuf buffer = Unpooled.buffer();
506 BGPParserTest.updateParser.serializeMessage(message, buffer);
507 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
511 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
513 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
514 * 00 4A <- length (73) - including header
516 * 00 00 <- withdrawn routes length
517 * 00 27 <- total path attribute length (39)
518 * 40 <- attribute flags
519 * 01 <- attribute type code (Origin)
520 * 01 <- attribute length
521 * 01 <- Origin value (EGP)
522 * 40 <- attribute flags
523 * 02 <- attribute type code (As path)
524 * 00 <- attribute length
525 * 40 <- attribute flags
526 * 03 <- attribute type (Next hop)
527 * 04 <- attribute length
528 * 03 03 03 03 <- value (3.3.3.3)
529 * 80 <- attribute flags
530 * 04 <- attribute type code (Multi exit disc)
531 * 04 <- attribute length
532 * 00 00 00 00 <- value
533 * 40 <- attribute flags
534 * 05 <- attribute type (Local Pref)
535 * 04 <- attribute length
536 * 00 00 00 64 <- value (100)
537 * c0 <- attribute flags
538 * 10 <- attribute type (extended community)
539 * 08 <- attribute length
540 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
541 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
542 * 12 34 <- value (local adm. 4660)
545 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
546 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
547 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
550 public void testGetUpdateMessage4() throws Exception {
551 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
552 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
553 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
555 final UpdateBuilder builder = new UpdateBuilder();
558 assertNull(message.getWithdrawnRoutes());
561 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
562 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
563 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
565 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
566 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
567 assertEquals(builder.getNlri(), message.getNlri());
570 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
571 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
573 final List<ExtendedCommunities> comms = Lists.newArrayList();
574 comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setExtendedCommunity(
575 new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
576 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
577 new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
579 // check path attributes
580 final PathAttributes attrs = message.getPathAttributes();
582 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
584 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
585 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
587 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
588 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
590 paBuilder.setCNextHop(nextHop);
591 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
593 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
594 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
596 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
597 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
599 paBuilder.setExtendedCommunities(comms);
600 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
603 builder.setPathAttributes(paBuilder.build());
604 assertEquals(builder.build(), message);
606 final ByteBuf buffer = Unpooled.buffer();
607 BGPParserTest.updateParser.serializeMessage(message, buffer);
608 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));
612 * Tests withdrawn routes.
614 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
615 * 00 1c <- length (28) - including header
617 * 00 05 <- withdrawn routes length (5)
618 * 1e ac 10 00 04 <- route (172.16.0.4)
619 * 00 00 <- total path attribute length
622 public void testGetUpdateMessage5() throws Exception {
623 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
624 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
625 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
628 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
631 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
632 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
634 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
636 final ByteBuf buffer = Unpooled.buffer();
637 BGPParserTest.updateParser.serializeMessage(message, buffer);
638 assertArrayEquals(inputBytes.get(4), ByteArray.readAllBytes(buffer));
642 * End of Rib for Ipv4.
644 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
645 * 00 17 <- length (23) - including header
647 * 00 00 <- withdrawn routes length
648 * 00 00 <- total path attribute length
651 public void testEORIpv4() throws Exception {
652 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
653 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
654 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
656 assertEquals(new UpdateBuilder().build(), message);
658 final ByteBuf buffer = Unpooled.buffer();
659 BGPParserTest.updateParser.serializeMessage(message, buffer);
660 assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
664 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
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 * 00 02 <- value (AFI 2: IPv6)
675 * 01 <- value (SAFI 1)
678 public void testEORIpv6() throws Exception {
679 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
680 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
681 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
683 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
684 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
686 assertEquals(Ipv6AddressFamily.class, afi);
687 assertEquals(UnicastSubsequentAddressFamily.class, safi);
689 final ByteBuf buffer = Unpooled.buffer();
690 BGPParserTest.updateParser.serializeMessage(message, buffer);
691 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
695 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
697 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
698 * 00 1e <- length (29) - including header
700 * 00 00 <- withdrawn routes length
701 * 00 07 <- total path attribute length
702 * 90 <- attribute flags
703 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
704 * 00 03 <- attribute length
705 * 00 02 <- value (AFI 2: IPv6)
706 * 01 <- value (SAFI 1)
709 public void testEORIpv6exLength() throws Exception {
710 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
711 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
712 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
714 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
715 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
717 assertEquals(Ipv6AddressFamily.class, afi);
718 assertEquals(UnicastSubsequentAddressFamily.class, safi);
720 final ByteBuf buffer = Unpooled.buffer();
721 BGPParserTest.updateParser.serializeMessage(message, buffer);
722 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
726 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
728 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
729 * 00 1d <- length (29) - including header
731 * 00 00 <- withdrawn routes length
732 * 00 06 <- total path attribute length
733 * 80 <- attribute flags
734 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
735 * 03 <- attribute length
736 * 40 04 <- value (AFI 16388: LS)
737 * 47 <- value (SAFI 71)
740 public void testEORLS() throws Exception {
741 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
742 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
743 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
745 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
746 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
748 assertEquals(LinkstateAddressFamily.class, afi);
749 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
751 final ByteBuf buffer = Unpooled.buffer();
752 BGPParserTest.updateParser.serializeMessage(message, buffer);
753 assertArrayEquals(inputBytes.get(7), ByteArray.readAllBytes(buffer));
757 * Tests BGP Link Ipv4
759 * 00 00 <- withdrawn routes length
760 * 01 48 <- total path attribute length (328)
761 * 90 <- attribute flags
762 0e <- attribute type code (MP reach)
763 01 2c <- attribute extended length (300)
764 40 04 <- AFI (16388 - Linkstate)
765 47 <- SAFI (71 - Linkstate)
766 04 <- next hop length
767 19 19 19 01 <- nexthop (25.25.25.1)
770 00 02 <- NLRI type (2 - linkNLRI)
771 00 5d <- NLRI length (93)
772 03 <- ProtocolID - OSPF
773 00 00 00 00 00 00 00 01 <- identifier
775 01 00 <- local node descriptor type (256)
777 02 00 <- node descriptor type (member AS - 512)
779 00 00 00 64 <- value (100)
780 02 01 <- node descriptor type (bgpId - 513)
782 19 19 19 01 <- bgpId (25.25.25.1)
783 02 02 <- node descriptor type (areaId - 514)
786 02 03 <- node descriptor type (routeId - 515)
788 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
790 01 01 <- remote node descriptor type (257)
792 02 00 <- node descriptor type (member AS - 512)
794 00 00 00 64 <- value (100)
795 02 01 <- node descriptor type (bgpId - 513)
797 19 19 19 01 <- bgpId (25.25.25.1)
798 02 02 <- node descriptor type (areaId - 514)
801 02 03 <- node descriptor type (routeId - 515)
803 03 03 03 04 <- OSPF Router Id
805 01 03 <- link descriptor type (IPv4 interface address - 259)
807 0b 0b 0b 03 <- value (11.11.11.3)
809 00 02 <- NLRI type (2 - linkNLRI)
810 00 5d <- NLRI length (93)
811 03 <- ProtocolID - OSPF
812 00 00 00 00 00 00 00 01 <- identifier
814 01 00 <- local node descriptor type (256)
816 02 00 <- node descriptor type (member AS - 512)
818 00 00 00 64 <- value (100)
819 02 01 <- node descriptor type (bgpId - 513)
821 19 19 19 01 <- bgpId (25.25.25.1)
822 02 02 <- node descriptor type (areaId - 514)
825 02 03 <- node descriptor type (routeId - 515)
827 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
829 01 01 <- remote node descriptor type (257)
831 02 00 <- node descriptor type (member AS - 512)
833 00 00 00 64 <- value (100)
834 02 01 <- node descriptor type (bgpId - 513)
836 19 19 19 01 <- bgpId (25.25.25.1)
837 02 02 <- node descriptor type (areaId - 514)
840 02 03 <- node descriptor type (routeId - 515)
842 01 01 01 02 <- OSPF Router Id
844 01 03 <- link descriptor type (IPv4 interface address - 259)
846 0b 0b 0b 01 <- value (11.11.11.1)
848 00 02 <- NLRI type (2 - linkNLRI)
849 00 5d <- NLRI length (93)
850 03 <- ProtocolID - OSPF
851 00 00 00 00 00 00 00 01 <- identifier
853 01 00 <- local node descriptor type (256)
855 02 00 <- node descriptor type (member AS - 512)
857 00 00 00 64 <- value (100)
858 02 01 <- node descriptor type (bgpId - 513)
860 19 19 19 01 <- bgpId (25.25.25.1)
861 02 02 <- node descriptor type (areaId - 514)
864 02 03 <- node descriptor type (routeId - 515)
866 01 01 01 02 <- OSPF Router Id
868 01 01 <- remote node descriptor type (257)
870 02 00 <- node descriptor type (member AS - 512)
872 00 00 00 64 <- value (100)
873 02 01 <- node descriptor type (bgpId - 513)
875 19 19 19 01 <- bgpId (25.25.25.1)
876 02 02 <- node descriptor type (areaId - 514)
879 02 03 <- node descriptor type (routeId - 515)
881 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
883 01 03 <- link descriptor type (IPv4 interface address - 259)
885 0b 0b 0b 01 <- value (11.11.11.1)
887 40 <- attribute flags
888 01 <- attribute type (Origin)
889 01 <- attribute length
891 40 <- attribute flags
892 02 <- attribute type (AS Path)
894 40 <- attribute flags
895 05 <- attribute type (local pref)
898 c0 <- attribute flags
899 1D <- attribute type (Link STATE - 29)
901 04 47 <- link attribute (1095 - Metric)
906 public void testBGPLink() throws Exception {
907 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
908 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
909 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
911 final UpdateBuilder builder = new UpdateBuilder();
915 assertNull(message.getWithdrawnRoutes());
917 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
918 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
920 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
921 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
923 final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
924 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
926 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
927 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
928 clBuilder.setNlriType(NlriType.Link);
929 clBuilder.setProtocolId(ProtocolId.Ospf);
931 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
932 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
933 mpBuilder.setAfi(LinkstateAddressFamily.class);
934 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
935 mpBuilder.setCNextHop(nextHop);
937 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
938 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
939 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
940 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
941 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
942 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
943 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
944 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
945 linkstates.add(clBuilder.build());
947 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
948 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
949 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
950 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
951 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
952 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
953 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
954 linkstates.add(clBuilder.build());
956 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
957 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
958 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
959 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
960 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
961 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
962 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
963 linkstates.add(clBuilder.build());
965 lsBuilder.setMpReachNlri(mpBuilder.build());
967 // check path attributes
968 final PathAttributes attrs = message.getPathAttributes();
970 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
972 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
973 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
975 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
976 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
978 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
979 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
981 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
982 assertEquals(mpBuilder.getAfi(), mp.getAfi());
983 assertEquals(mpBuilder.getSafi(), mp.getSafi());
984 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
986 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
987 dBuilder.setCLinkstateDestination(linkstates);
989 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
990 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
991 lsBuilder.setMpReachNlri(mpBuilder.build());
993 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
995 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();
997 lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
998 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
999 paBuilder.addAugmentation(
1000 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class,
1001 lsAttrBuilder.build());
1004 lsAttrBuilder.build().getLinkstatePathAttribute(),
1005 attrs.getAugmentation(
1006 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class).getLinkstatePathAttribute());
1008 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1010 assertEquals(linkstates.size(), dests.size());
1012 assertEquals(linkstates, dests);
1013 // check API message
1014 builder.setPathAttributes(paBuilder.build());
1015 assertEquals(builder.build(), message);
1017 final ByteBuf buffer = Unpooled.buffer();
1018 BGPParserTest.updateParser.serializeMessage(message, buffer);
1019 assertArrayEquals(inputBytes.get(8), ByteArray.readAllBytes(buffer));
1025 * 00 00 <- withdrawn routes length
1026 00 b1 <- total path attribute length (177)
1027 80 <- attribute flags
1028 0e <- attribute type code (MP reach)
1029 a0 <- attribute length (160)
1030 40 04 <- AFI (16388 - Linkstate)
1031 47 <- SAFI (71 - Linkstate)
1032 04 <- next hop length
1033 19 19 19 01 - nexthop (25.25.25.1)
1036 00 01 <- NLRI type (1 - nodeNLRI)
1037 00 31 <- NLRI length (49)
1038 03 <- ProtocolID - OSPF
1039 00 00 00 00 00 00 00 01 <- identifier
1040 01 00 <- local node descriptor type (256)
1041 00 24 <- length (36)
1042 02 00 <- node descriptor type (member AS - 512)
1044 00 00 00 64 <- value (100)
1045 02 01 <- node descriptor type (bgpId - 513)
1047 19 19 19 01 <- bgpId (25.25.25.1)
1048 02 02 <- node descriptor type (areaId - 514)
1050 00 00 00 00 <- value
1051 02 03 <- node descriptor type (routeId - 515)
1053 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
1055 00 01 <- NLRI type (1 - nodeNLRI)
1056 00 2d <- NLRI length (45)
1057 03 <- ProtocolID - OSPF
1058 00 00 00 00 00 00 00 01 <- identifier
1059 01 00 <- local node descriptor type (256)
1060 00 20 <- length (32)
1061 02 00 <- node descriptor type (member AS - 512)
1063 00 00 00 64 <- value (100)
1064 02 01 <- node descriptor type (bgpId - 513)
1066 19 19 19 01 <- bgpId (25.25.25.1)
1067 02 02 <- node descriptor type (areaId - 514)
1069 00 00 00 00 <- value
1070 02 03 <- node descriptor type (routeId - 515)
1072 03 03 03 04 <- OSPF Router Id
1074 00 01 <- NLRI type (1 - nodeNLRI)
1075 00 2d <- NLRI length (45)
1076 03 <- ProtocolID - OSPF
1077 00 00 00 00 00 00 00 01 <- identifier
1078 01 00 <- local node descriptor type (256)
1079 00 20 <- length (32)
1080 02 00 <- node descriptor type (member AS - 512)
1082 00 00 00 64 <- value (100)
1083 02 01 <- node descriptor type (bgpId - 513)
1085 19 19 19 01 <- bgpId (25.25.25.1)
1086 02 02 <- node descriptor type (areaId - 514)
1088 00 00 00 00 <- value
1089 02 03 <- node descriptor type (routeId - 515)
1091 01 01 01 02 <- OSPF Router Id
1093 40 <- attribute flags
1094 01 <- attribute type (Origin)
1095 01 <- attribute length
1097 40 <- attribute flags
1098 02 <- attribute type (AS Path)
1100 40 <- attribute flags
1101 05 <- attribute type (local pref)
1103 00 00 00 64 <- value
1106 public void testBGPNode() throws Exception {
1107 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
1108 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
1109 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
1111 final UpdateBuilder builder = new UpdateBuilder();
1115 assertNull(message.getWithdrawnRoutes());
1119 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
1120 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
1122 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
1123 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
1125 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
1126 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
1127 clBuilder.setNlriType(NlriType.Node);
1128 clBuilder.setProtocolId(ProtocolId.Ospf);
1130 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
1131 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1132 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
1133 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
1134 linkstates.add(clBuilder.build());
1136 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1137 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
1138 linkstates.add(clBuilder.build());
1140 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1141 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
1142 linkstates.add(clBuilder.build());
1144 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
1145 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
1146 mpBuilder.setAfi(LinkstateAddressFamily.class);
1147 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
1148 mpBuilder.setCNextHop(nextHop);
1150 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
1151 dBuilder.setCLinkstateDestination(linkstates);
1153 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
1154 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
1155 lsBuilder.setMpReachNlri(mpBuilder.build());
1157 // check path attributes
1158 final PathAttributes attrs = message.getPathAttributes();
1160 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
1162 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
1163 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
1165 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
1166 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
1168 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
1169 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
1171 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
1173 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
1174 assertEquals(mpBuilder.getAfi(), mp.getAfi());
1175 assertEquals(mpBuilder.getSafi(), mp.getSafi());
1176 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
1178 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1180 assertEquals(linkstates.size(), dests.size());
1182 assertEquals(linkstates, dests);
1184 // check API message
1185 builder.setPathAttributes(paBuilder.build());
1186 assertEquals(builder.build(), message);
1188 final ByteBuf buffer = Unpooled.buffer();
1189 BGPParserTest.updateParser.serializeMessage(message, buffer);
1190 assertArrayEquals(inputBytes.get(9), ByteArray.readAllBytes(buffer));
1194 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1195 * 00 3d <- length (61) - including header
1196 * 01 <- message type
1198 * 00 64 <- My AS Number (AS TRANS in this case)
1199 * 00 b4 <- Hold Time
1200 * 00 00 00 00 <- BGP Identifier
1201 * 20 <- Optional Parameters Length
1202 * 02 <- opt. param. type (capabilities)
1204 * 01 <- capability code (MP Extensions for BGP4)
1206 * 00 01 00 01 <- AFI 1, SAFI 1
1207 * 02 <- opt. param. type (capabilities)
1209 * 01 <- capability code (MP Extensions for BGP4)
1211 * 00 02 00 01 <- AFI 2, SAFI 1
1212 * 02 <- opt. param. type (capabilities)
1214 * 01 <- capability code (MP Extensions for BGP4)
1216 * 40 04 00 47 <- AFI 16388, SAFI 71
1217 * 02 <- opt. param. type (capabilities)
1219 * 41 <- capability code (AS4 octet support)
1221 * 00 00 00 64 <- AS number
1224 public void testOpenMessage() throws Exception {
1225 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
1226 final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(13)));
1227 final Open open = (Open) o;
1228 final Set<BgpTableType> types = Sets.newHashSet();
1229 for (final BgpParameters param : open.getBgpParameters()) {
1230 final CParameters p = param.getCParameters();
1231 if (p instanceof MultiprotocolCase) {
1232 final BgpTableType type = new BgpTableTypeImpl(((MultiprotocolCase) p).getMultiprotocolCapability().getAfi(), ((MultiprotocolCase) p).getMultiprotocolCapability().getSafi());
1236 final Set<BgpTableType> expected = Sets.newHashSet();
1237 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1238 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1239 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1240 assertEquals(expected, types);
1242 final ByteBuf buffer = Unpooled.buffer();
1243 msgReg.serializeMessage(o, buffer);
1244 assertArrayEquals(inputBytes.get(13), ByteArray.readAllBytes(buffer));