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.linkstate;
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;
14 import static org.mockito.Mockito.mock;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import java.io.ByteArrayOutputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.ArrayList;
22 import java.util.HashSet;
23 import java.util.List;
25 import java.util.ServiceLoader;
27 import org.junit.Before;
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.spi.BGPExtensionConsumerContext;
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.NlriRegistry;
35 import org.opendaylight.protocol.util.ByteArray;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AreaIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.DomainIdentifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Identifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4InterfaceIdentifier;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateSubsequentAddressFamily;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.OspfInterfaceIdentifier;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.destination.CLinkstateDestination;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.destination.CLinkstateDestinationBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.LinkCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LinkDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.node._case.NodeDescriptorsBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReachBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
93 import org.opendaylight.yangtools.yang.binding.Notification;
94 import org.opendaylight.yangtools.yang.common.Uint32;
95 import org.opendaylight.yangtools.yang.common.Uint64;
97 public class ParserTest {
99 // Used by other tests as well
100 private static final List<byte[]> INPUT_BYTES = new ArrayList<>();
102 private static final int COUNTER = 4;
104 private static final int MAX_SIZE = 300;
106 private static BGPUpdateMessageParser updateParser;
108 private static final int LENGTH_FIELD_LENGTH = 2;
110 private MessageRegistry msgReg;
113 public void setUp() throws Exception {
114 final BGPExtensionConsumerContext context = ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst()
117 msgReg = context.getMessageRegistry();
118 updateParser = new BGPUpdateMessageParser(context.getAttributeRegistry(), mock(NlriRegistry.class));
119 for (int i = 1; i <= COUNTER; i++) {
120 final String name = "/up" + i + ".bin";
121 try (InputStream is = ParserTest.class.getResourceAsStream(name)) {
123 throw new IOException("Failed to get resource " + name);
125 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
126 final byte[] data = new byte[MAX_SIZE];
128 while ((numRead = is.read(data, 0, data.length)) != -1) {
129 bis.write(data, 0, numRead);
133 INPUT_BYTES.add(bis.toByteArray());
141 public void testResource() {
142 assertNotNull(INPUT_BYTES);
146 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
148 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
149 * 00 1d <- length (29) - including header
151 * 00 00 <- withdrawn routes length
152 * 00 06 <- total path attribute length
153 * 80 <- attribute flags
154 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
155 * 03 <- attribute length
156 * 40 04 <- value (AFI 16388: LS)
157 * 47 <- value (SAFI 71)
160 public void testEORLS() throws Exception {
161 final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(0), MessageUtil.COMMON_HEADER_LENGTH);
162 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(0),
163 MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
164 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength,
167 final AddressFamily afi = message.getAttributes()
168 .augmentation(AttributesUnreach.class).getMpUnreachNlri().getAfi();
169 final SubsequentAddressFamily safi = message.getAttributes()
170 .augmentation(AttributesUnreach.class).getMpUnreachNlri().getSafi();
172 assertEquals(LinkstateAddressFamily.VALUE, afi);
173 assertEquals(LinkstateSubsequentAddressFamily.VALUE, safi);
175 final ByteBuf buffer = Unpooled.buffer();
176 ParserTest.updateParser.serializeMessage(message, buffer);
177 assertArrayEquals(INPUT_BYTES.get(0), ByteArray.readAllBytes(buffer));
181 * Tests BGP Link Ipv4
183 * 00 00 <- withdrawn routes length
184 * 01 48 <- total path attribute length (328)
185 * 90 <- attribute flags
186 0e <- attribute type code (MP reach)
187 01 2c <- attribute extended length (300)
188 40 04 <- AFI (16388 - Linkstate)
189 47 <- SAFI (71 - Linkstate)
190 04 <- next hop length
191 19 19 19 01 <- nexthop (25.25.25.1)
194 00 02 <- NLRI type (2 - linkNLRI)
195 00 5d <- NLRI length (93)
196 03 <- ProtocolID - OSPF
197 00 00 00 00 00 00 00 01 <- identifier
199 01 00 <- local node descriptor type (256)
201 02 00 <- node descriptor type (member AS - 512)
203 00 00 00 64 <- value (100)
204 02 01 <- node descriptor type (bgpId - 513)
206 19 19 19 01 <- bgpId (25.25.25.1)
207 02 02 <- node descriptor type (areaId - 514)
210 02 03 <- node descriptor type (routeId - 515)
212 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
214 01 01 <- remote node descriptor type (257)
216 02 00 <- node descriptor type (member AS - 512)
218 00 00 00 64 <- value (100)
219 02 01 <- node descriptor type (bgpId - 513)
221 19 19 19 01 <- bgpId (25.25.25.1)
222 02 02 <- node descriptor type (areaId - 514)
225 02 03 <- node descriptor type (routeId - 515)
227 03 03 03 04 <- OSPF Router Id
229 01 03 <- link descriptor type (IPv4 interface address - 259)
231 0b 0b 0b 03 <- value (11.11.11.3)
233 00 02 <- NLRI type (2 - linkNLRI)
234 00 5d <- NLRI length (93)
235 03 <- ProtocolID - OSPF
236 00 00 00 00 00 00 00 01 <- identifier
238 01 00 <- local node descriptor type (256)
240 02 00 <- node descriptor type (member AS - 512)
242 00 00 00 64 <- value (100)
243 02 01 <- node descriptor type (bgpId - 513)
245 19 19 19 01 <- bgpId (25.25.25.1)
246 02 02 <- node descriptor type (areaId - 514)
249 02 03 <- node descriptor type (routeId - 515)
251 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
253 01 01 <- remote node descriptor type (257)
255 02 00 <- node descriptor type (member AS - 512)
257 00 00 00 64 <- value (100)
258 02 01 <- node descriptor type (bgpId - 513)
260 19 19 19 01 <- bgpId (25.25.25.1)
261 02 02 <- node descriptor type (areaId - 514)
264 02 03 <- node descriptor type (routeId - 515)
266 01 01 01 02 <- OSPF Router Id
268 01 03 <- link descriptor type (IPv4 interface address - 259)
270 0b 0b 0b 01 <- value (11.11.11.1)
272 00 02 <- NLRI type (2 - linkNLRI)
273 00 5d <- NLRI length (93)
274 03 <- ProtocolID - OSPF
275 00 00 00 00 00 00 00 01 <- identifier
277 01 00 <- local node descriptor type (256)
279 02 00 <- node descriptor type (member AS - 512)
281 00 00 00 64 <- value (100)
282 02 01 <- node descriptor type (bgpId - 513)
284 19 19 19 01 <- bgpId (25.25.25.1)
285 02 02 <- node descriptor type (areaId - 514)
288 02 03 <- node descriptor type (routeId - 515)
290 01 01 01 02 <- OSPF Router Id
292 01 01 <- remote node descriptor type (257)
294 02 00 <- node descriptor type (member AS - 512)
296 00 00 00 64 <- value (100)
297 02 01 <- node descriptor type (bgpId - 513)
299 19 19 19 01 <- bgpId (25.25.25.1)
300 02 02 <- node descriptor type (areaId - 514)
303 02 03 <- node descriptor type (routeId - 515)
305 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
307 01 03 <- link descriptor type (IPv4 interface address - 259)
309 0b 0b 0b 01 <- value (11.11.11.1)
311 40 <- attribute flags
312 01 <- attribute type (Origin)
313 01 <- attribute length
315 40 <- attribute flags
316 02 <- attribute type (AS Path)
318 40 <- attribute flags
319 05 <- attribute type (local pref)
322 c0 <- attribute flags
323 1D <- attribute type (Link STATE - 29)
325 04 47 <- link attribute (1095 - Metric)
330 public void testBGPLink() throws Exception {
331 final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(1), MessageUtil.COMMON_HEADER_LENGTH);
332 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(1),
333 MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
334 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength,
337 final UpdateBuilder builder = new UpdateBuilder();
341 assertNull(message.getWithdrawnRoutes());
343 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
344 new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("25.25.25.1")).build()).build();
346 final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder()
347 .setAsNumber(new AsNumber(Uint32.valueOf(100))).setDomainId(
348 new DomainIdentifier(Uint32.valueOf(0x19191901L))).setAreaId(new AreaIdentifier(Uint32.ZERO));
350 final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder()
351 .setAsNumber(new AsNumber(Uint32.valueOf(100))).setDomainId(
352 new DomainIdentifier(Uint32.valueOf(0x19191901L))).setAreaId(new AreaIdentifier(Uint32.ZERO));
354 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
355 clBuilder.setIdentifier(new Identifier(Uint64.ONE));
356 clBuilder.setProtocolId(ProtocolId.Ospf);
358 final AttributesReachBuilder lsBuilder = new AttributesReachBuilder();
359 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder()
360 .setAfi(LinkstateAddressFamily.VALUE)
361 .setSafi(LinkstateSubsequentAddressFamily.VALUE)
362 .setCNextHop(nextHop);
364 final List<CLinkstateDestination> linkstates = new ArrayList<>();
365 final LinkCaseBuilder lCase = new LinkCaseBuilder()
366 .setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(new OspfPseudonodeCaseBuilder()
367 .setOspfPseudonode(new OspfPseudonodeBuilder()
368 .setOspfRouterId(Uint32.valueOf(0x03030304L))
369 .setLanInterface(new OspfInterfaceIdentifier(Uint32.valueOf(0x0b0b0b03L)))
370 .build()).build()).build());
371 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
372 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
373 .setOspfRouterId(Uint32.valueOf(0x03030304L)).build()).build()).build());
374 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
375 new Ipv4InterfaceIdentifier(new Ipv4AddressNoZone("11.11.11.3"))).build());
376 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
378 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
379 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
380 .setOspfRouterId(Uint32.valueOf(0x01010102L)).build()).build()).build());
381 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
382 new Ipv4InterfaceIdentifier(new Ipv4AddressNoZone("11.11.11.1"))).build());
383 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
385 lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
386 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
387 .setOspfRouterId(Uint32.valueOf(0x01010102L)).build()).build()).build());
388 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
389 new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder()
390 .setOspfRouterId(Uint32.valueOf(0x03030304L))
391 .setLanInterface(new OspfInterfaceIdentifier(Uint32.valueOf(0x0b0b0b03L))).build()).build()).build());
392 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
394 lsBuilder.setMpReachNlri(mpBuilder.build());
396 // check path attributes
397 final Attributes attrs = message.getAttributes();
399 final AttributesBuilder paBuilder = new AttributesBuilder();
401 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
402 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
404 paBuilder.setAsPath(new AsPathBuilder().setSegments(List.of()).build());
405 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
407 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build());
408 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
410 final MpReachNlri mp = attrs.augmentation(AttributesReach.class).getMpReachNlri();
411 assertEquals(mpBuilder.getAfi(), mp.getAfi());
412 assertEquals(mpBuilder.getSafi(), mp.getSafi());
413 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
415 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
416 dBuilder.setCLinkstateDestination(linkstates);
418 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
419 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
420 lsBuilder.setMpReachNlri(mpBuilder.build());
422 paBuilder.addAugmentation(lsBuilder.build());
424 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120
425 .Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
426 .bgp.linkstate.rev200120.Attributes1Builder();
428 lsAttrBuilder.setLinkStateAttribute(
429 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder()
430 .setMetric(new Metric(Uint32.ONE)).build()).build());
431 paBuilder.addAugmentation(lsAttrBuilder.build());
432 paBuilder.setUnrecognizedAttributes(Map.of());
435 lsAttrBuilder.build(),
436 attrs.augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120
437 .Attributes1.class));
439 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes()
440 .getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
442 assertEquals(linkstates.size(), dests.size());
444 assertEquals(linkstates, dests);
446 builder.setAttributes(paBuilder.build());
447 assertEquals(builder.build(), message);
449 final ByteBuf buffer = Unpooled.buffer();
450 ParserTest.updateParser.serializeMessage(message, buffer);
451 assertArrayEquals(INPUT_BYTES.get(1), ByteArray.readAllBytes(buffer));
457 * 00 00 <- withdrawn routes length
458 00 b1 <- total path attribute length (177)
459 80 <- attribute flags
460 0e <- attribute type code (MP reach)
461 a0 <- attribute length (160)
462 40 04 <- AFI (16388 - Linkstate)
463 47 <- SAFI (71 - Linkstate)
464 04 <- next hop length
465 19 19 19 01 - nexthop (25.25.25.1)
468 00 01 <- NLRI type (1 - nodeNLRI)
469 00 31 <- NLRI length (49)
470 03 <- ProtocolID - OSPF
471 00 00 00 00 00 00 00 01 <- identifier
472 01 00 <- local node descriptor type (256)
474 02 00 <- node descriptor type (member AS - 512)
476 00 00 00 64 <- value (100)
477 02 01 <- node descriptor type (bgpId - 513)
479 19 19 19 01 <- bgpId (25.25.25.1)
480 02 02 <- node descriptor type (areaId - 514)
483 02 03 <- node descriptor type (routeId - 515)
485 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
487 00 01 <- NLRI type (1 - nodeNLRI)
488 00 2d <- NLRI length (45)
489 03 <- ProtocolID - OSPF
490 00 00 00 00 00 00 00 01 <- identifier
491 01 00 <- local node descriptor type (256)
493 02 00 <- node descriptor type (member AS - 512)
495 00 00 00 64 <- value (100)
496 02 01 <- node descriptor type (bgpId - 513)
498 19 19 19 01 <- bgpId (25.25.25.1)
499 02 02 <- node descriptor type (areaId - 514)
502 02 03 <- node descriptor type (routeId - 515)
504 03 03 03 04 <- OSPF Router Id
506 00 01 <- NLRI type (1 - nodeNLRI)
507 00 2d <- NLRI length (45)
508 03 <- ProtocolID - OSPF
509 00 00 00 00 00 00 00 01 <- identifier
510 01 00 <- local node descriptor type (256)
512 02 00 <- node descriptor type (member AS - 512)
514 00 00 00 64 <- value (100)
515 02 01 <- node descriptor type (bgpId - 513)
517 19 19 19 01 <- bgpId (25.25.25.1)
518 02 02 <- node descriptor type (areaId - 514)
521 02 03 <- node descriptor type (routeId - 515)
523 01 01 01 02 <- OSPF Router Id
525 40 <- attribute flags
526 01 <- attribute type (Origin)
527 01 <- attribute length
529 40 <- attribute flags
530 02 <- attribute type (AS Path)
532 40 <- attribute flags
533 05 <- attribute type (local pref)
538 public void testBGPNode() throws Exception {
539 final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(2), MessageUtil.COMMON_HEADER_LENGTH);
540 final int messageLength = ByteArray
541 .bytesToInt(ByteArray.subByte(INPUT_BYTES.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
542 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength,
545 final UpdateBuilder builder = new UpdateBuilder();
549 assertNull(message.getWithdrawnRoutes());
553 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
554 new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("25.25.25.1")).build()).build();
556 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
557 clBuilder.setIdentifier(new Identifier(Uint64.ONE));
558 clBuilder.setProtocolId(ProtocolId.Ospf);
560 final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder()
561 .setAsNumber(new AsNumber(Uint32.valueOf(100)))
562 .setDomainId(new DomainIdentifier(Uint32.valueOf(0x19191901L)))
563 .setAreaId(new AreaIdentifier(Uint32.ZERO));
565 final List<CLinkstateDestination> linkstates = new ArrayList<>();
566 final NodeCaseBuilder nCase = new NodeCaseBuilder()
567 .setNodeDescriptors(n.setCRouterIdentifier(new OspfPseudonodeCaseBuilder()
568 .setOspfPseudonode(new OspfPseudonodeBuilder()
569 .setOspfRouterId(Uint32.valueOf(0x03030304L))
570 .setLanInterface(new OspfInterfaceIdentifier(Uint32.valueOf(0x0b0b0b03L)))
573 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
575 nCase.setNodeDescriptors(n.setCRouterIdentifier(
576 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
577 .setOspfRouterId(Uint32.valueOf(0x03030304L)).build()).build()).build());
578 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
580 nCase.setNodeDescriptors(n.setCRouterIdentifier(
581 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
582 .setOspfRouterId(Uint32.valueOf(0x01010102L)).build()).build()).build());
583 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
585 final AttributesReachBuilder lsBuilder = new AttributesReachBuilder();
586 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder()
587 .setAfi(LinkstateAddressFamily.VALUE)
588 .setSafi(LinkstateSubsequentAddressFamily.VALUE)
589 .setCNextHop(nextHop);
591 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
592 dBuilder.setCLinkstateDestination(linkstates);
594 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
595 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
596 lsBuilder.setMpReachNlri(mpBuilder.build());
598 // check path attributes
599 final Attributes attrs = message.getAttributes();
601 final AttributesBuilder paBuilder = new AttributesBuilder();
603 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
604 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
606 paBuilder.setAsPath(new AsPathBuilder().setSegments(List.of()).build());
607 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
609 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build());
610 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
612 paBuilder.addAugmentation(lsBuilder.build());
613 paBuilder.setUnrecognizedAttributes(Map.of());
615 final MpReachNlri mp = attrs.augmentation(AttributesReach.class).getMpReachNlri();
616 assertEquals(mpBuilder.getAfi(), mp.getAfi());
617 assertEquals(mpBuilder.getSafi(), mp.getSafi());
618 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
620 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes()
621 .getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
623 assertEquals(linkstates.size(), dests.size());
625 assertEquals(linkstates, dests);
628 builder.setAttributes(paBuilder.build());
629 assertEquals(builder.build(), message);
631 final ByteBuf buffer = Unpooled.buffer();
632 ParserTest.updateParser.serializeMessage(message, buffer);
633 assertArrayEquals(INPUT_BYTES.get(2), ByteArray.readAllBytes(buffer));
637 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
638 * 00 3d <- length (61) - including header
641 * 00 64 <- My AS Number (AS TRANS in this case)
643 * 00 00 00 00 <- BGP Identifier
644 * 20 <- Optional Parameters Length
645 * 02 <- opt. param. type (capabilities)
647 * 01 <- capability code (MP Extensions for BGP4)
649 * 00 01 00 01 <- AFI 1, SAFI 1
650 * 02 <- opt. param. type (capabilities)
652 * 01 <- capability code (MP Extensions for BGP4)
654 * 00 02 00 01 <- AFI 2, SAFI 1
655 * 02 <- opt. param. type (capabilities)
657 * 01 <- capability code (MP Extensions for BGP4)
659 * 40 04 00 47 <- AFI 16388, SAFI 71
660 * 02 <- opt. param. type (capabilities)
662 * 41 <- capability code (AS4 octet support)
664 * 00 00 00 64 <- AS number
667 public void testOpenMessage() throws Exception {
668 final Notification<?> o = msgReg.parseMessage(Unpooled.copiedBuffer(INPUT_BYTES.get(3)), null);
669 final Open open = (Open) o;
670 final Set<BgpTableType> types = new HashSet<>();
671 for (final BgpParameters param : open.getBgpParameters()) {
672 for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
673 final CParameters cParam = optCapa.getCParameters();
674 if (cParam != null && cParam.augmentation(CParameters1.class) != null
675 && cParam.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
676 final MultiprotocolCapability mp = cParam.augmentation(CParameters1.class)
677 .getMultiprotocolCapability();
678 final BgpTableType type = new BgpTableTypeImpl(mp.getAfi(), mp.getSafi());
683 final Set<BgpTableType> expected = new HashSet<>();
684 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE));
685 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE));
686 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.VALUE, LinkstateSubsequentAddressFamily.VALUE));
687 assertEquals(expected, types);
689 final ByteBuf buffer = Unpooled.buffer();
690 msgReg.serializeMessage(o, buffer);
691 assertArrayEquals(INPUT_BYTES.get(3), ByteArray.readAllBytes(buffer));