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;
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.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.MessageRegistry;
32 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
33 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
34 import org.opendaylight.protocol.util.ByteArray;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.AreaIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.DomainIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Identifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv4InterfaceIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfInterfaceIdentifier;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestination;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestinationBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.NodeCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptorsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptorsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.OptionalCapabilities;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParameters;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AsPathBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpOrigin;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
92 import org.opendaylight.yangtools.yang.binding.Notification;
94 public class ParserTest {
97 * Used by other tests as well
99 private static final List<byte[]> inputBytes = new ArrayList<>();
101 private static final int COUNTER = 4;
103 private static final int MAX_SIZE = 300;
105 private static BGPUpdateMessageParser updateParser;
107 private static final int LENGTH_FIELD_LENGTH = 2;
110 public void setUp() throws Exception {
111 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext
112 .getSingletonInstance().getAttributeRegistry());
113 for (int i = 1; i <= COUNTER; i++) {
114 final String name = "/up" + i + ".bin";
115 try (final InputStream is = ParserTest.class.getResourceAsStream(name)){
117 throw new IOException("Failed to get resource " + name);
119 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
120 final byte[] data = new byte[MAX_SIZE];
122 while ((nRead = is.read(data, 0, data.length)) != -1) {
123 bis.write(data, 0, nRead);
127 inputBytes.add(bis.toByteArray());
135 public void testResource() {
136 assertNotNull(inputBytes);
140 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
142 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
143 * 00 1d <- length (29) - including header
145 * 00 00 <- withdrawn routes length
146 * 00 06 <- total path attribute length
147 * 80 <- attribute flags
148 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
149 * 03 <- attribute length
150 * 40 04 <- value (AFI 16388: LS)
151 * 47 <- value (SAFI 71)
154 public void testEORLS() throws Exception {
155 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
156 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0),
157 MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
158 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
160 final Class<? extends AddressFamily> afi = message.getAttributes()
161 .augmentation(Attributes2.class).getMpUnreachNlri().getAfi();
162 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes()
163 .augmentation(Attributes2.class).getMpUnreachNlri().getSafi();
165 assertEquals(LinkstateAddressFamily.class, afi);
166 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
168 final ByteBuf buffer = Unpooled.buffer();
169 ParserTest.updateParser.serializeMessage(message, buffer);
170 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
174 * Tests BGP Link Ipv4
176 * 00 00 <- withdrawn routes length
177 * 01 48 <- total path attribute length (328)
178 * 90 <- attribute flags
179 0e <- attribute type code (MP reach)
180 01 2c <- attribute extended length (300)
181 40 04 <- AFI (16388 - Linkstate)
182 47 <- SAFI (71 - Linkstate)
183 04 <- next hop length
184 19 19 19 01 <- nexthop (25.25.25.1)
187 00 02 <- NLRI type (2 - linkNLRI)
188 00 5d <- NLRI length (93)
189 03 <- ProtocolID - OSPF
190 00 00 00 00 00 00 00 01 <- identifier
192 01 00 <- local node descriptor type (256)
194 02 00 <- node descriptor type (member AS - 512)
196 00 00 00 64 <- value (100)
197 02 01 <- node descriptor type (bgpId - 513)
199 19 19 19 01 <- bgpId (25.25.25.1)
200 02 02 <- node descriptor type (areaId - 514)
203 02 03 <- node descriptor type (routeId - 515)
205 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
207 01 01 <- remote node descriptor type (257)
209 02 00 <- node descriptor type (member AS - 512)
211 00 00 00 64 <- value (100)
212 02 01 <- node descriptor type (bgpId - 513)
214 19 19 19 01 <- bgpId (25.25.25.1)
215 02 02 <- node descriptor type (areaId - 514)
218 02 03 <- node descriptor type (routeId - 515)
220 03 03 03 04 <- OSPF Router Id
222 01 03 <- link descriptor type (IPv4 interface address - 259)
224 0b 0b 0b 03 <- value (11.11.11.3)
226 00 02 <- NLRI type (2 - linkNLRI)
227 00 5d <- NLRI length (93)
228 03 <- ProtocolID - OSPF
229 00 00 00 00 00 00 00 01 <- identifier
231 01 00 <- local node descriptor type (256)
233 02 00 <- node descriptor type (member AS - 512)
235 00 00 00 64 <- value (100)
236 02 01 <- node descriptor type (bgpId - 513)
238 19 19 19 01 <- bgpId (25.25.25.1)
239 02 02 <- node descriptor type (areaId - 514)
242 02 03 <- node descriptor type (routeId - 515)
244 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
246 01 01 <- remote node descriptor type (257)
248 02 00 <- node descriptor type (member AS - 512)
250 00 00 00 64 <- value (100)
251 02 01 <- node descriptor type (bgpId - 513)
253 19 19 19 01 <- bgpId (25.25.25.1)
254 02 02 <- node descriptor type (areaId - 514)
257 02 03 <- node descriptor type (routeId - 515)
259 01 01 01 02 <- OSPF Router Id
261 01 03 <- link descriptor type (IPv4 interface address - 259)
263 0b 0b 0b 01 <- value (11.11.11.1)
265 00 02 <- NLRI type (2 - linkNLRI)
266 00 5d <- NLRI length (93)
267 03 <- ProtocolID - OSPF
268 00 00 00 00 00 00 00 01 <- identifier
270 01 00 <- local node descriptor type (256)
272 02 00 <- node descriptor type (member AS - 512)
274 00 00 00 64 <- value (100)
275 02 01 <- node descriptor type (bgpId - 513)
277 19 19 19 01 <- bgpId (25.25.25.1)
278 02 02 <- node descriptor type (areaId - 514)
281 02 03 <- node descriptor type (routeId - 515)
283 01 01 01 02 <- OSPF Router Id
285 01 01 <- remote node descriptor type (257)
287 02 00 <- node descriptor type (member AS - 512)
289 00 00 00 64 <- value (100)
290 02 01 <- node descriptor type (bgpId - 513)
292 19 19 19 01 <- bgpId (25.25.25.1)
293 02 02 <- node descriptor type (areaId - 514)
296 02 03 <- node descriptor type (routeId - 515)
298 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
300 01 03 <- link descriptor type (IPv4 interface address - 259)
302 0b 0b 0b 01 <- value (11.11.11.1)
304 40 <- attribute flags
305 01 <- attribute type (Origin)
306 01 <- attribute length
308 40 <- attribute flags
309 02 <- attribute type (AS Path)
311 40 <- attribute flags
312 05 <- attribute type (local pref)
315 c0 <- attribute flags
316 1D <- attribute type (Link STATE - 29)
318 04 47 <- link attribute (1095 - Metric)
323 public void testBGPLink() throws Exception {
324 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
325 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1),
326 MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
327 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
329 final UpdateBuilder builder = new UpdateBuilder();
333 assertNull(message.getWithdrawnRoutes());
335 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
336 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
338 final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder()
339 .setAsNumber(new AsNumber((long) 100)).setDomainId(
340 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
342 final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder()
343 .setAsNumber(new AsNumber((long) 100)).setDomainId(
344 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
346 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
347 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
348 clBuilder.setProtocolId(ProtocolId.Ospf);
350 final Attributes1Builder lsBuilder = new Attributes1Builder();
351 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
352 mpBuilder.setAfi(LinkstateAddressFamily.class);
353 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
354 mpBuilder.setCNextHop(nextHop);
356 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
357 final LinkCaseBuilder lCase = new LinkCaseBuilder().setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
358 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
359 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L)
360 .setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
361 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
362 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
363 .setOspfRouterId(0x03030304L).build()).build()).build());
364 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
365 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
366 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
368 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
369 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
370 .setOspfRouterId(0x01010102L).build()).build()).build());
371 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
372 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
373 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
375 lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
376 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
377 .setOspfRouterId(0x01010102L).build()).build()).build());
378 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
379 new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder()
380 .setOspfRouterId(0x03030304L)
381 .setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
382 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
384 lsBuilder.setMpReachNlri(mpBuilder.build());
386 // check path attributes
387 final Attributes attrs = message.getAttributes();
389 final AttributesBuilder paBuilder = new AttributesBuilder();
391 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
392 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
394 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
395 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
397 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
398 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
400 final MpReachNlri mp = attrs.augmentation(Attributes1.class).getMpReachNlri();
401 assertEquals(mpBuilder.getAfi(), mp.getAfi());
402 assertEquals(mpBuilder.getSafi(), mp.getSafi());
403 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
405 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
406 dBuilder.setCLinkstateDestination(linkstates);
408 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
409 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
410 lsBuilder.setMpReachNlri(mpBuilder.build());
412 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
414 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.
415 Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.
416 bgp.linkstate.rev180329.Attributes1Builder();
418 lsAttrBuilder.setLinkStateAttribute(
419 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder()
420 .setMetric(new Metric(1L)).build()).build());
421 paBuilder.addAugmentation(
422 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Attributes1.class,
423 lsAttrBuilder.build());
424 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
427 lsAttrBuilder.build(),
428 attrs.augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
429 .linkstate.rev180329.Attributes1.class));
431 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes()
432 .getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
434 assertEquals(linkstates.size(), dests.size());
436 assertEquals(linkstates, dests);
438 builder.setAttributes(paBuilder.build());
439 assertEquals(builder.build(), message);
441 final ByteBuf buffer = Unpooled.buffer();
442 ParserTest.updateParser.serializeMessage(message, buffer);
443 assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
449 * 00 00 <- withdrawn routes length
450 00 b1 <- total path attribute length (177)
451 80 <- attribute flags
452 0e <- attribute type code (MP reach)
453 a0 <- attribute length (160)
454 40 04 <- AFI (16388 - Linkstate)
455 47 <- SAFI (71 - Linkstate)
456 04 <- next hop length
457 19 19 19 01 - nexthop (25.25.25.1)
460 00 01 <- NLRI type (1 - nodeNLRI)
461 00 31 <- NLRI length (49)
462 03 <- ProtocolID - OSPF
463 00 00 00 00 00 00 00 01 <- identifier
464 01 00 <- local node descriptor type (256)
466 02 00 <- node descriptor type (member AS - 512)
468 00 00 00 64 <- value (100)
469 02 01 <- node descriptor type (bgpId - 513)
471 19 19 19 01 <- bgpId (25.25.25.1)
472 02 02 <- node descriptor type (areaId - 514)
475 02 03 <- node descriptor type (routeId - 515)
477 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
479 00 01 <- NLRI type (1 - nodeNLRI)
480 00 2d <- NLRI length (45)
481 03 <- ProtocolID - OSPF
482 00 00 00 00 00 00 00 01 <- identifier
483 01 00 <- local node descriptor type (256)
485 02 00 <- node descriptor type (member AS - 512)
487 00 00 00 64 <- value (100)
488 02 01 <- node descriptor type (bgpId - 513)
490 19 19 19 01 <- bgpId (25.25.25.1)
491 02 02 <- node descriptor type (areaId - 514)
494 02 03 <- node descriptor type (routeId - 515)
496 03 03 03 04 <- OSPF Router Id
498 00 01 <- NLRI type (1 - nodeNLRI)
499 00 2d <- NLRI length (45)
500 03 <- ProtocolID - OSPF
501 00 00 00 00 00 00 00 01 <- identifier
502 01 00 <- local node descriptor type (256)
504 02 00 <- node descriptor type (member AS - 512)
506 00 00 00 64 <- value (100)
507 02 01 <- node descriptor type (bgpId - 513)
509 19 19 19 01 <- bgpId (25.25.25.1)
510 02 02 <- node descriptor type (areaId - 514)
513 02 03 <- node descriptor type (routeId - 515)
515 01 01 01 02 <- OSPF Router Id
517 40 <- attribute flags
518 01 <- attribute type (Origin)
519 01 <- attribute length
521 40 <- attribute flags
522 02 <- attribute type (AS Path)
524 40 <- attribute flags
525 05 <- attribute type (local pref)
530 public void testBGPNode() throws Exception {
531 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
532 final int messageLength = ByteArray
533 .bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
534 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
536 final UpdateBuilder builder = new UpdateBuilder();
540 assertNull(message.getWithdrawnRoutes());
544 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
545 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
547 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
548 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
549 clBuilder.setProtocolId(ProtocolId.Ospf);
551 final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
552 n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L))
553 .setAreaId(new AreaIdentifier(0L));
555 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
556 final NodeCaseBuilder nCase = new NodeCaseBuilder();
557 nCase.setNodeDescriptors(n.setCRouterIdentifier(
558 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
559 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L)
560 .setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
561 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
563 nCase.setNodeDescriptors(n.setCRouterIdentifier(
564 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
565 .setOspfRouterId(0x03030304L).build()).build()).build());
566 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
568 nCase.setNodeDescriptors(n.setCRouterIdentifier(
569 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder()
570 .setOspfRouterId(0x01010102L).build()).build()).build());
571 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
573 final Attributes1Builder lsBuilder = new Attributes1Builder();
574 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
575 mpBuilder.setAfi(LinkstateAddressFamily.class);
576 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
577 mpBuilder.setCNextHop(nextHop);
579 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
580 dBuilder.setCLinkstateDestination(linkstates);
582 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
583 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
584 lsBuilder.setMpReachNlri(mpBuilder.build());
586 // check path attributes
587 final Attributes attrs = message.getAttributes();
589 final AttributesBuilder paBuilder = new AttributesBuilder();
591 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
592 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
594 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
595 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
597 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
598 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
600 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
601 paBuilder.setUnrecognizedAttributes(Collections.emptyList());
603 final MpReachNlri mp = attrs.augmentation(Attributes1.class).getMpReachNlri();
604 assertEquals(mpBuilder.getAfi(), mp.getAfi());
605 assertEquals(mpBuilder.getSafi(), mp.getSafi());
606 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
608 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes()
609 .getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
611 assertEquals(linkstates.size(), dests.size());
613 assertEquals(linkstates, dests);
616 builder.setAttributes(paBuilder.build());
617 assertEquals(builder.build(), message);
619 final ByteBuf buffer = Unpooled.buffer();
620 ParserTest.updateParser.serializeMessage(message, buffer);
621 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
625 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
626 * 00 3d <- length (61) - including header
629 * 00 64 <- My AS Number (AS TRANS in this case)
631 * 00 00 00 00 <- BGP Identifier
632 * 20 <- Optional Parameters Length
633 * 02 <- opt. param. type (capabilities)
635 * 01 <- capability code (MP Extensions for BGP4)
637 * 00 01 00 01 <- AFI 1, SAFI 1
638 * 02 <- opt. param. type (capabilities)
640 * 01 <- capability code (MP Extensions for BGP4)
642 * 00 02 00 01 <- AFI 2, SAFI 1
643 * 02 <- opt. param. type (capabilities)
645 * 01 <- capability code (MP Extensions for BGP4)
647 * 40 04 00 47 <- AFI 16388, SAFI 71
648 * 02 <- opt. param. type (capabilities)
650 * 41 <- capability code (AS4 octet support)
652 * 00 00 00 64 <- AS number
655 public void testOpenMessage() throws Exception {
656 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext
657 .getSingletonInstance().getMessageRegistry();
658 final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(3)), null);
659 final Open open = (Open) o;
660 final Set<BgpTableType> types = Sets.newHashSet();
661 for (final BgpParameters param : open.getBgpParameters()) {
662 for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
663 final CParameters cParam = optCapa.getCParameters();
664 if(cParam != null && cParam.augmentation(CParameters1.class) != null
665 && cParam.augmentation(CParameters1.class).getMultiprotocolCapability() != null) {
666 final MultiprotocolCapability mp = cParam.augmentation(CParameters1.class)
667 .getMultiprotocolCapability();
668 final BgpTableType type = new BgpTableTypeImpl(mp.getAfi(), mp.getSafi());
673 final Set<BgpTableType> expected = Sets.newHashSet();
674 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
675 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
676 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
677 assertEquals(expected, types);
679 final ByteBuf buffer = Unpooled.buffer();
680 msgReg.serializeMessage(o, buffer);
681 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));