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;
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
21 import java.io.ByteArrayOutputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.math.BigInteger;
25 import java.util.ArrayList;
26 import java.util.List;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
32 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
33 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
34 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
35 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
36 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
37 import org.opendaylight.protocol.util.ByteArray;
38 import org.opendaylight.protocol.util.NoopReferenceCache;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
63 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;
64 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;
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.DestinationLinkstateCase;
66 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;
67 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;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.CParameters;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregateBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ClusterIdBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunitiesBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDiscBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginatorIdBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.Segments;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.as.path.SegmentsBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.Nlri;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.NlriBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutesBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.DestinationIpv6CaseBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.destination.type.destination.ipv6._case.DestinationIpv6Builder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.AListCaseBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCaseBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.AListBuilder;
112 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;
113 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;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.set._case.ASetBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
116 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;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
121 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;
122 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;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
124 import org.opendaylight.yangtools.yang.binding.Notification;
126 public class BGPParserTest {
129 * Used by other tests as well
131 static final List<byte[]> inputBytes = new ArrayList<byte[]>();
133 private static int COUNTER = 17;
135 private static int MAX_SIZE = 300;
137 private static BGPUpdateMessageParser updateParser;
139 private static final int LENGTH_FIELD_LENGTH = 2;
142 public static void setUp() throws Exception {
143 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
145 for (int i = 1; i <= COUNTER; i++) {
146 final String name = "/up" + i + ".bin";
147 final InputStream is = BGPParserTest.class.getResourceAsStream(name);
149 throw new IOException("Failed to get resource " + name);
152 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
153 final byte[] data = new byte[MAX_SIZE];
155 while ((nRead = is.read(data, 0, data.length)) != -1) {
156 bis.write(data, 0, nRead);
160 inputBytes.add(bis.toByteArray());
165 public void testResource() {
166 assertNotNull(inputBytes);
170 * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
172 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
173 * 00 52 <- length (82) - including header
175 * 00 00 <- withdrawn routes length
176 * 00 2f <- total path attribute length (47)
177 * 40 <- attribute flags
178 * 01 <- attribute type code (origin)
179 * 01 <- attribute length
180 * 00 <- Origin value (IGP)
181 * 40 <- attribute flags
182 * 02 <- attribute type code (as path)
183 * 06 <- attribute length
185 * 01 <- path segment count
186 * fd ea <- path segment value (65002)
187 * 40 <- attribute flags
188 * 03 <- attribute type code (Next Hop)
189 * 04 <- attribute length
190 * 10 00 00 02 <- value (10.0.0.2)
191 * 80 <- attribute flags
192 * 04 <- attribute type code (multi exit disc)
193 * 04 <- attribute length
194 * 00 00 00 00 <- value
195 * 60 <- attribute flags
196 * 06 <- attribute type code (atomic aggregate)
197 * 00 <- attribute length
198 * 64 <- attribute flags
199 * 08 <- attribute type code (community)
200 * 10 <- attribute length FF FF FF
201 * 01 <- value (NO_EXPORT)
202 * FF FF FF 02 <- value (NO_ADVERTISE)
203 * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
204 * FF FF FF 10 <- unknown Community
207 * 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
208 * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
209 * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
212 public void testGetUpdateMessage1() throws Exception {
214 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
215 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
216 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
220 assertNull(message.getWithdrawnRoutes());
224 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
225 final List<Segments> asPath = Lists.newArrayList();
226 asPath.add(new SegmentsBuilder().setCSegment(
227 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
229 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
230 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
232 final List<Communities> comms = Lists.newArrayList();
233 comms.add((Communities) CommunityUtil.NO_EXPORT);
234 comms.add((Communities) CommunityUtil.NO_ADVERTISE);
235 comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
236 comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
238 final UpdateBuilder builder = new UpdateBuilder();
242 final List<Ipv4Prefix> prefs = Lists.newArrayList();
243 prefs.add(new Ipv4Prefix("172.17.2.0/24"));
244 prefs.add(new Ipv4Prefix("172.17.1.0/24"));
245 prefs.add(new Ipv4Prefix("172.17.0.0/24"));
247 final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
249 assertEquals(nlri, message.getNlri());
251 builder.setNlri(nlri);
253 // check path attributes
255 final PathAttributes attrs = message.getPathAttributes();
257 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
259 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
260 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
262 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
263 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
265 paBuilder.setCNextHop(nextHop);
266 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
268 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
269 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
271 paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
272 assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
274 paBuilder.setCommunities(comms);
275 assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
277 builder.setPathAttributes(paBuilder.build());
279 assertEquals(builder.build(), message);
281 final ByteBuf buffer = Unpooled.buffer();
282 BGPParserTest.updateParser.serializeMessage(message, buffer);
283 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
287 * Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
289 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
290 * 00 7e <- length (126) - including header
292 * 00 00 <- withdrawn routes length
293 * 00 67 <- total path attribute length (103)
294 * 40 <- attribute flags
295 * 01 <- attribute type code (origin)
296 * 01 <- attribute length
297 * 00 <- Origin value (IGP)
298 * 40 <- attribute flags
299 * 02 <- attribute type code (as path)
300 * 04 <- attribute length
302 * 01 <- path segment count
303 * fd e9 <- path segment value (65001)
304 * 40 <- attribute flags
305 * 03 <- attribute type code (next hop)
306 * 04 <- attribute length
307 * 0a 00 00 00 <- next hop value (10.0.0.0)
308 * 80 <- attribute flags
309 * 04 <- attribute type code (multi exit disc)
310 * 04 <- attribute length
311 * 00 00 00 00 <- value
312 * 80 <- attribute flags
313 * 09 <- attribute type code (originator id)
314 * 04 <- attribute length
315 * 7f 00 00 01 <- value (localhost ip)
316 * 80 <- attribute flags
317 * 0a <- attribute type code (cluster list)
318 * 08 <- attribute length
319 * 01 02 03 04 <- value
320 * 05 06 07 08 <- value
321 * 80 <- attribute flags
322 * 0e <- attribute type code (mp reach nlri)
323 * 40 <- attribute length
324 * 00 02 <- AFI (Ipv6)
325 * 01 <- SAFI (Unicast)
326 * 20 <- length of next hop
327 * 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
328 * fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
332 * 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
333 * 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
334 * 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
338 public void testGetUpdateMessage2() throws Exception {
339 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
340 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
341 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
344 assertNull(message.getWithdrawnRoutes());
346 final UpdateBuilder builder = new UpdateBuilder();
350 final List<Ipv6Prefix> prefs = Lists.newArrayList();
351 prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
352 prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
353 prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
355 assertNull(message.getNlri());
359 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
360 final List<Segments> asPath = Lists.newArrayList();
361 asPath.add(new SegmentsBuilder().setCSegment(
362 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
364 final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
365 new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
367 final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
368 new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
370 // check path attributes
372 final PathAttributes attrs = message.getPathAttributes();
374 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
376 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
377 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
379 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
380 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
382 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
383 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
385 paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4Address("127.0.0.1")).build());
386 assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
388 paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
389 assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
391 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
392 mpBuilder.setAfi(Ipv6AddressFamily.class);
393 mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
394 mpBuilder.setCNextHop(nextHop);
395 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
396 new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
398 paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
399 assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
400 attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
404 builder.setPathAttributes(paBuilder.build());
405 assertEquals(builder.build(), message);
407 final ByteBuf buffer = Unpooled.buffer();
408 BGPParserTest.updateParser.serializeMessage(message, buffer);
409 assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
413 * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
415 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
416 * 00 45 <- length (69) - including header
418 * 00 00 <- withdrawn routes length
419 * 00 30 <- total path attribute length (42)
420 * 40 <- attribute flags
421 * 01 <- attribute type code (origin)
422 * 01 <- attribute length
423 * 02 <- Origin value (Incomplete)
424 * 40 <- attribute flags
425 * 02 <- attribute type code (as path)
426 * 10 <- attribute length
428 * 01 <- path segment count
429 * 00 1e <- path segment value (30)
431 * 02 <- path segment count
432 * 00 0a <- path segment value (10)
433 * 00 14 <- path segment value (20)
434 * 40 <- attribute flags
435 * 03 <- attribute type (Next hop)
436 * 04 <- attribute length
437 * 0a 00 00 09 <- value (10.0.0.9)
438 * 80 <- attribute flags
439 * 04 <- attribute type code (multi exit disc)
440 * 04 <- attribute length
441 * 00 00 00 00 <- value
442 * c0 <- attribute flags
443 * 07 <- attribute type (Aggregator)
444 * 08 <- attribute length
445 * 00 00 00 1e <- value (AS number = 30)
446 * 0a 00 00 09 <- value (IP address = 10.0.0.9)
449 * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
452 public void testGetUpdateMessage3() throws Exception {
453 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
454 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
455 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
457 final UpdateBuilder builder = new UpdateBuilder();
460 final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
462 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
463 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
464 assertEquals(builder.getNlri(), message.getNlri());
467 assertNull(message.getWithdrawnRoutes());
470 final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
471 final List<Segments> asPath = Lists.newArrayList();
472 asPath.add(new SegmentsBuilder().setCSegment(
473 new AListCaseBuilder().setAList(new AListBuilder().setAsSequence(asnums).build()).build()).build());
474 asPath.add(new SegmentsBuilder().setCSegment(
475 new ASetCaseBuilder().setASet(new ASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build()).build());
477 final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
478 new Ipv4Address("10.0.0.9")).build();
479 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
480 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
482 // check path attributes
483 final PathAttributes attrs = message.getPathAttributes();
485 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
487 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
488 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
490 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
491 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
493 paBuilder.setCNextHop(nextHop);
494 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
496 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
497 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
499 paBuilder.setAggregator(aggregator);
500 assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
502 builder.setPathAttributes(paBuilder.build());
504 assertEquals(builder.build(), message);
506 final ByteBuf buffer = Unpooled.buffer();
507 BGPParserTest.updateParser.serializeMessage(message, buffer);
508 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
512 * Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
514 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
515 * 00 4A <- length (73) - including header
517 * 00 00 <- withdrawn routes length
518 * 00 27 <- total path attribute length (39)
519 * 40 <- attribute flags
520 * 01 <- attribute type code (Origin)
521 * 01 <- attribute length
522 * 01 <- Origin value (EGP)
523 * 40 <- attribute flags
524 * 02 <- attribute type code (As path)
525 * 00 <- attribute length
526 * 40 <- attribute flags
527 * 03 <- attribute type (Next hop)
528 * 04 <- attribute length
529 * 03 03 03 03 <- value (3.3.3.3)
530 * 80 <- attribute flags
531 * 04 <- attribute type code (Multi exit disc)
532 * 04 <- attribute length
533 * 00 00 00 00 <- value
534 * 40 <- attribute flags
535 * 05 <- attribute type (Local Pref)
536 * 04 <- attribute length
537 * 00 00 00 64 <- value (100)
538 * c0 <- attribute flags
539 * 10 <- attribute type (extended community)
540 * 08 <- attribute length
541 * 01 04 <- value (type - Ipv4 Address Specific Extended Community)
542 * c0 a8 01 00 <- value (global adm. 198.162.1.0)
543 * 12 34 <- value (local adm. 4660)
546 * 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
547 * 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
548 * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
551 public void testGetUpdateMessage4() throws Exception {
552 final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
553 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
554 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
556 final UpdateBuilder builder = new UpdateBuilder();
559 assertNull(message.getWithdrawnRoutes());
562 final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
563 final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
564 final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
566 final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
567 builder.setNlri(new NlriBuilder().setNlri(nlri).build());
568 assertEquals(builder.getNlri(), message.getNlri());
571 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
572 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
574 final List<ExtendedCommunities> comms = Lists.newArrayList();
575 comms.add(new ExtendedCommunitiesBuilder().setCommType((short) 1).setExtendedCommunity(
576 new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
577 new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
578 new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
580 final List<Segments> asPath = Lists.newArrayList();
582 // check path attributes
583 final PathAttributes attrs = message.getPathAttributes();
585 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
587 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
588 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
590 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
591 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
593 paBuilder.setCNextHop(nextHop);
594 assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
596 paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
597 assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
599 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
600 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
602 paBuilder.setExtendedCommunities(comms);
603 assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
606 builder.setPathAttributes(paBuilder.build());
607 assertEquals(builder.build(), message);
609 final ByteBuf buffer = Unpooled.buffer();
610 BGPParserTest.updateParser.serializeMessage(message, buffer);
611 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));
615 * Tests withdrawn routes.
617 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
618 * 00 1c <- length (28) - including header
620 * 00 05 <- withdrawn routes length (5)
621 * 1e ac 10 00 04 <- route (172.16.0.4)
622 * 00 00 <- total path attribute length
625 public void testGetUpdateMessage5() throws Exception {
626 final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
627 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
628 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
631 final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
634 final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
635 new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
637 assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
639 final ByteBuf buffer = Unpooled.buffer();
640 BGPParserTest.updateParser.serializeMessage(message, buffer);
641 assertArrayEquals(inputBytes.get(4), ByteArray.readAllBytes(buffer));
645 * End of Rib for Ipv4.
647 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
648 * 00 17 <- length (23) - including header
650 * 00 00 <- withdrawn routes length
651 * 00 00 <- total path attribute length
654 public void testEORIpv4() throws Exception {
655 final byte[] body = ByteArray.cutBytes(inputBytes.get(5), MessageUtil.COMMON_HEADER_LENGTH);
656 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
657 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
659 assertEquals(new UpdateBuilder().build(), message);
661 final ByteBuf buffer = Unpooled.buffer();
662 BGPParserTest.updateParser.serializeMessage(message, buffer);
663 assertArrayEquals(inputBytes.get(5), ByteArray.readAllBytes(buffer));
667 * End of Rib for Ipv6 consists of empty MP_UNREACH_NLRI, with AFI 2 and SAFI 1
669 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
670 * 00 1d <- length (29) - including header
672 * 00 00 <- withdrawn routes length
673 * 00 06 <- total path attribute length
674 * 80 <- attribute flags
675 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
676 * 03 <- attribute length
677 * 00 02 <- value (AFI 2: IPv6)
678 * 01 <- value (SAFI 1)
681 public void testEORIpv6() throws Exception {
682 final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
683 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
684 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
686 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
687 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
689 assertEquals(Ipv6AddressFamily.class, afi);
690 assertEquals(UnicastSubsequentAddressFamily.class, safi);
692 final ByteBuf buffer = Unpooled.buffer();
693 BGPParserTest.updateParser.serializeMessage(message, buffer);
694 assertArrayEquals(inputBytes.get(6), ByteArray.readAllBytes(buffer));
698 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
700 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
701 * 00 1d <- length (29) - including header
703 * 00 00 <- withdrawn routes length
704 * 00 06 <- total path attribute length
705 * 80 <- attribute flags
706 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
707 * 03 <- attribute length
708 * 40 04 <- value (AFI 16388: LS)
709 * 47 <- value (SAFI 71)
712 public void testEORLS() throws Exception {
713 final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
714 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
715 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
717 final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
718 final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
720 assertEquals(LinkstateAddressFamily.class, afi);
721 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
723 final ByteBuf buffer = Unpooled.buffer();
724 BGPParserTest.updateParser.serializeMessage(message, buffer);
725 assertArrayEquals(inputBytes.get(7), ByteArray.readAllBytes(buffer));
729 * Tests BGP Link Ipv4
731 * 00 00 <- withdrawn routes length
732 * 01 48 <- total path attribute length (328)
733 * 90 <- attribute flags
734 0e <- attribute type code (MP reach)
735 01 2c <- attribute extended length (300)
736 40 04 <- AFI (16388 - Linkstate)
737 47 <- SAFI (71 - Linkstate)
738 04 <- next hop length
739 19 19 19 01 <- nexthop (25.25.25.1)
742 00 02 <- NLRI type (2 - linkNLRI)
743 00 5d <- NLRI length (93)
744 03 <- ProtocolID - OSPF
745 00 00 00 00 00 00 00 01 <- identifier
747 01 00 <- local node descriptor type (256)
749 02 00 <- node descriptor type (member AS - 512)
751 00 00 00 64 <- value (100)
752 02 01 <- node descriptor type (bgpId - 513)
754 19 19 19 01 <- bgpId (25.25.25.1)
755 02 02 <- node descriptor type (areaId - 514)
758 02 03 <- node descriptor type (routeId - 515)
760 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
762 01 01 <- remote node descriptor type (257)
764 02 00 <- node descriptor type (member AS - 512)
766 00 00 00 64 <- value (100)
767 02 01 <- node descriptor type (bgpId - 513)
769 19 19 19 01 <- bgpId (25.25.25.1)
770 02 02 <- node descriptor type (areaId - 514)
773 02 03 <- node descriptor type (routeId - 515)
775 03 03 03 04 <- OSPF Router Id
777 01 03 <- link descriptor type (IPv4 interface address - 259)
779 0b 0b 0b 03 <- value (11.11.11.3)
781 00 02 <- NLRI type (2 - linkNLRI)
782 00 5d <- NLRI length (93)
783 03 <- ProtocolID - OSPF
784 00 00 00 00 00 00 00 01 <- identifier
786 01 00 <- local node descriptor type (256)
788 02 00 <- node descriptor type (member AS - 512)
790 00 00 00 64 <- value (100)
791 02 01 <- node descriptor type (bgpId - 513)
793 19 19 19 01 <- bgpId (25.25.25.1)
794 02 02 <- node descriptor type (areaId - 514)
797 02 03 <- node descriptor type (routeId - 515)
799 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
801 01 01 <- remote node descriptor type (257)
803 02 00 <- node descriptor type (member AS - 512)
805 00 00 00 64 <- value (100)
806 02 01 <- node descriptor type (bgpId - 513)
808 19 19 19 01 <- bgpId (25.25.25.1)
809 02 02 <- node descriptor type (areaId - 514)
812 02 03 <- node descriptor type (routeId - 515)
814 01 01 01 02 <- OSPF Router Id
816 01 03 <- link descriptor type (IPv4 interface address - 259)
818 0b 0b 0b 01 <- value (11.11.11.1)
820 00 02 <- NLRI type (2 - linkNLRI)
821 00 5d <- NLRI length (93)
822 03 <- ProtocolID - OSPF
823 00 00 00 00 00 00 00 01 <- identifier
825 01 00 <- local node descriptor type (256)
827 02 00 <- node descriptor type (member AS - 512)
829 00 00 00 64 <- value (100)
830 02 01 <- node descriptor type (bgpId - 513)
832 19 19 19 01 <- bgpId (25.25.25.1)
833 02 02 <- node descriptor type (areaId - 514)
836 02 03 <- node descriptor type (routeId - 515)
838 01 01 01 02 <- OSPF Router Id
840 01 01 <- remote node descriptor type (257)
842 02 00 <- node descriptor type (member AS - 512)
844 00 00 00 64 <- value (100)
845 02 01 <- node descriptor type (bgpId - 513)
847 19 19 19 01 <- bgpId (25.25.25.1)
848 02 02 <- node descriptor type (areaId - 514)
851 02 03 <- node descriptor type (routeId - 515)
853 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
855 01 03 <- link descriptor type (IPv4 interface address - 259)
857 0b 0b 0b 01 <- value (11.11.11.1)
859 40 <- attribute flags
860 01 <- attribute type (Origin)
861 01 <- attribute length
863 40 <- attribute flags
864 02 <- attribute type (AS Path)
866 40 <- attribute flags
867 05 <- attribute type (local pref)
870 c0 <- attribute flags
871 63 <- attribute type (Link STATE - 99)
873 04 47 <- link attribute (1095 - Metric)
878 public void testBGPLink() throws Exception {
879 final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
880 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
881 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
883 final UpdateBuilder builder = new UpdateBuilder();
887 assertNull(message.getWithdrawnRoutes());
889 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
890 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
892 final List<Segments> asPath = Lists.newArrayList();
894 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
895 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
897 final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
898 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
900 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
901 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
902 clBuilder.setNlriType(NlriType.Link);
903 clBuilder.setProtocolId(ProtocolId.Ospf);
905 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
906 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
907 mpBuilder.setAfi(LinkstateAddressFamily.class);
908 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
909 mpBuilder.setCNextHop(nextHop);
911 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
912 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
913 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
914 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
915 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
916 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
917 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
918 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
919 linkstates.add(clBuilder.build());
921 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
922 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
923 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
924 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
925 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
926 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
927 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
928 linkstates.add(clBuilder.build());
930 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
931 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
932 clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
933 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
934 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
935 clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
936 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
937 linkstates.add(clBuilder.build());
939 lsBuilder.setMpReachNlri(mpBuilder.build());
941 // check path attributes
942 final PathAttributes attrs = message.getPathAttributes();
944 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
946 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
947 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
949 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
950 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
952 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
953 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
955 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
956 assertEquals(mpBuilder.getAfi(), mp.getAfi());
957 assertEquals(mpBuilder.getSafi(), mp.getSafi());
958 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
960 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
961 dBuilder.setCLinkstateDestination(linkstates);
963 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
964 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
965 lsBuilder.setMpReachNlri(mpBuilder.build());
967 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
969 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();
971 lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
972 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build()).build());
973 paBuilder.addAugmentation(
974 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class,
975 lsAttrBuilder.build());
978 lsAttrBuilder.build().getLinkstatePathAttribute(),
979 attrs.getAugmentation(
980 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1.class).getLinkstatePathAttribute());
982 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
984 assertEquals(linkstates.size(), dests.size());
986 assertEquals(linkstates, dests);
988 builder.setPathAttributes(paBuilder.build());
989 assertEquals(builder.build(), message);
991 final ByteBuf buffer = Unpooled.buffer();
992 BGPParserTest.updateParser.serializeMessage(message, buffer);
993 assertArrayEquals(inputBytes.get(8), ByteArray.readAllBytes(buffer));
999 * 00 00 <- withdrawn routes length
1000 00 b1 <- total path attribute length (177)
1001 80 <- attribute flags
1002 0e <- attribute type code (MP reach)
1003 a0 <- attribute length (160)
1004 40 04 <- AFI (16388 - Linkstate)
1005 47 <- SAFI (71 - Linkstate)
1006 04 <- next hop length
1007 19 19 19 01 - nexthop (25.25.25.1)
1010 00 01 <- NLRI type (1 - nodeNLRI)
1011 00 31 <- NLRI length (49)
1012 03 <- ProtocolID - OSPF
1013 00 00 00 00 00 00 00 01 <- identifier
1014 01 00 <- local node descriptor type (256)
1015 00 24 <- length (36)
1016 02 00 <- node descriptor type (member AS - 512)
1018 00 00 00 64 <- value (100)
1019 02 01 <- node descriptor type (bgpId - 513)
1021 19 19 19 01 <- bgpId (25.25.25.1)
1022 02 02 <- node descriptor type (areaId - 514)
1024 00 00 00 00 <- value
1025 02 03 <- node descriptor type (routeId - 515)
1027 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
1029 00 01 <- NLRI type (1 - nodeNLRI)
1030 00 2d <- NLRI length (45)
1031 03 <- ProtocolID - OSPF
1032 00 00 00 00 00 00 00 01 <- identifier
1033 01 00 <- local node descriptor type (256)
1034 00 20 <- length (32)
1035 02 00 <- node descriptor type (member AS - 512)
1037 00 00 00 64 <- value (100)
1038 02 01 <- node descriptor type (bgpId - 513)
1040 19 19 19 01 <- bgpId (25.25.25.1)
1041 02 02 <- node descriptor type (areaId - 514)
1043 00 00 00 00 <- value
1044 02 03 <- node descriptor type (routeId - 515)
1046 03 03 03 04 <- OSPF Router Id
1048 00 01 <- NLRI type (1 - nodeNLRI)
1049 00 2d <- NLRI length (45)
1050 03 <- ProtocolID - OSPF
1051 00 00 00 00 00 00 00 01 <- identifier
1052 01 00 <- local node descriptor type (256)
1053 00 20 <- length (32)
1054 02 00 <- node descriptor type (member AS - 512)
1056 00 00 00 64 <- value (100)
1057 02 01 <- node descriptor type (bgpId - 513)
1059 19 19 19 01 <- bgpId (25.25.25.1)
1060 02 02 <- node descriptor type (areaId - 514)
1062 00 00 00 00 <- value
1063 02 03 <- node descriptor type (routeId - 515)
1065 01 01 01 02 <- OSPF Router Id
1067 40 <- attribute flags
1068 01 <- attribute type (Origin)
1069 01 <- attribute length
1071 40 <- attribute flags
1072 02 <- attribute type (AS Path)
1074 40 <- attribute flags
1075 05 <- attribute type (local pref)
1077 00 00 00 64 <- value
1080 public void testBGPNode() throws Exception {
1081 final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
1082 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
1083 final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
1085 final UpdateBuilder builder = new UpdateBuilder();
1089 assertNull(message.getWithdrawnRoutes());
1093 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
1094 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
1096 final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
1097 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
1099 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
1100 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
1101 clBuilder.setNlriType(NlriType.Node);
1102 clBuilder.setProtocolId(ProtocolId.Ospf);
1104 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
1105 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1106 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
1107 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
1108 linkstates.add(clBuilder.build());
1110 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1111 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
1112 linkstates.add(clBuilder.build());
1114 clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
1115 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
1116 linkstates.add(clBuilder.build());
1118 final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
1119 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
1120 mpBuilder.setAfi(LinkstateAddressFamily.class);
1121 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
1122 mpBuilder.setCNextHop(nextHop);
1124 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
1125 dBuilder.setCLinkstateDestination(linkstates);
1127 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
1128 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
1129 lsBuilder.setMpReachNlri(mpBuilder.build());
1131 final List<Segments> asPath = Lists.newArrayList();
1133 // check path attributes
1134 final PathAttributes attrs = message.getPathAttributes();
1136 final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
1138 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
1139 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
1141 paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
1142 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
1144 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
1145 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
1147 paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
1149 final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
1150 assertEquals(mpBuilder.getAfi(), mp.getAfi());
1151 assertEquals(mpBuilder.getSafi(), mp.getSafi());
1152 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
1154 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
1156 assertEquals(linkstates.size(), dests.size());
1158 assertEquals(linkstates, dests);
1160 // check API message
1161 builder.setPathAttributes(paBuilder.build());
1162 assertEquals(builder.build(), message);
1164 final ByteBuf buffer = Unpooled.buffer();
1165 BGPParserTest.updateParser.serializeMessage(message, buffer);
1166 assertArrayEquals(inputBytes.get(9), ByteArray.readAllBytes(buffer));
1170 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
1171 * 00 3d <- length (61) - including header
1172 * 01 <- message type
1174 * 00 64 <- My AS Number (AS TRANS in this case)
1175 * 00 b4 <- Hold Time
1176 * 00 00 00 00 <- BGP Identifier
1177 * 20 <- Optional Parameters Length
1178 * 02 <- opt. param. type (capabilities)
1180 * 01 <- capability code (MP Extensions for BGP4)
1182 * 00 01 00 01 <- AFI 1, SAFI 1
1183 * 02 <- opt. param. type (capabilities)
1185 * 01 <- capability code (MP Extensions for BGP4)
1187 * 00 02 00 01 <- AFI 2, SAFI 1
1188 * 02 <- opt. param. type (capabilities)
1190 * 01 <- capability code (MP Extensions for BGP4)
1192 * 40 04 00 47 <- AFI 16388, SAFI 71
1193 * 02 <- opt. param. type (capabilities)
1195 * 41 <- capability code (AS4 octet support)
1197 * 00 00 00 64 <- AS number
1200 public void testOpenMessage() throws Exception {
1201 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
1202 final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(13)));
1203 final Open open = (Open) o;
1204 final Set<BgpTableType> types = Sets.newHashSet();
1205 for (final BgpParameters param : open.getBgpParameters()) {
1206 final CParameters p = param.getCParameters();
1207 if (p instanceof MultiprotocolCase) {
1208 final BgpTableType type = new BgpTableTypeImpl(((MultiprotocolCase) p).getMultiprotocolCapability().getAfi(), ((MultiprotocolCase) p).getMultiprotocolCapability().getSafi());
1212 final Set<BgpTableType> expected = Sets.newHashSet();
1213 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
1214 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
1215 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
1216 assertEquals(expected, types);
1218 final ByteBuf buffer = Unpooled.buffer();
1219 msgReg.serializeMessage(o, buffer);
1220 assertArrayEquals(inputBytes.get(13), ByteArray.readAllBytes(buffer));