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.rev150210.AreaIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfInterfaceIdentifier;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptorsBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.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.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.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.rev150210.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.rev150210.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.rev130919.Open;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPrefBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.as.path.Segments;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapability;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
92 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;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
94 import org.opendaylight.yangtools.yang.binding.Notification;
96 public class ParserTest {
99 * Used by other tests as well
101 private static final List<byte[]> inputBytes = new ArrayList<>();
103 private static final int COUNTER = 4;
105 private static final int MAX_SIZE = 300;
107 private static BGPUpdateMessageParser updateParser;
109 private static final int LENGTH_FIELD_LENGTH = 2;
112 public void setUp() throws Exception {
113 updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry());
114 for (int i = 1; i <= COUNTER; i++) {
115 final String name = "/up" + i + ".bin";
116 try (final InputStream is = ParserTest.class.getResourceAsStream(name)){
118 throw new IOException("Failed to get resource " + name);
120 final ByteArrayOutputStream bis = new ByteArrayOutputStream();
121 final byte[] data = new byte[MAX_SIZE];
123 while ((nRead = is.read(data, 0, data.length)) != -1) {
124 bis.write(data, 0, nRead);
128 inputBytes.add(bis.toByteArray());
136 public void testResource() {
137 assertNotNull(inputBytes);
141 * End of Rib for LS consists of empty MP_UNREACH_NLRI, with AFI 16388 and SAFI 71
143 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
144 * 00 1d <- length (29) - including header
146 * 00 00 <- withdrawn routes length
147 * 00 06 <- total path attribute length
148 * 80 <- attribute flags
149 * 0f <- attribute type (15 - MP_UNREACH_NLRI)
150 * 03 <- attribute length
151 * 40 04 <- value (AFI 16388: LS)
152 * 47 <- value (SAFI 71)
155 public void testEORLS() throws Exception {
156 final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
157 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), 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().getAugmentation(Attributes2.class).getMpUnreachNlri().getAfi();
161 final Class<? extends SubsequentAddressFamily> safi = message.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getSafi();
163 assertEquals(LinkstateAddressFamily.class, afi);
164 assertEquals(LinkstateSubsequentAddressFamily.class, safi);
166 final ByteBuf buffer = Unpooled.buffer();
167 ParserTest.updateParser.serializeMessage(message, buffer);
168 assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
172 * Tests BGP Link Ipv4
174 * 00 00 <- withdrawn routes length
175 * 01 48 <- total path attribute length (328)
176 * 90 <- attribute flags
177 0e <- attribute type code (MP reach)
178 01 2c <- attribute extended length (300)
179 40 04 <- AFI (16388 - Linkstate)
180 47 <- SAFI (71 - Linkstate)
181 04 <- next hop length
182 19 19 19 01 <- nexthop (25.25.25.1)
185 00 02 <- NLRI type (2 - linkNLRI)
186 00 5d <- NLRI length (93)
187 03 <- ProtocolID - OSPF
188 00 00 00 00 00 00 00 01 <- identifier
190 01 00 <- local node descriptor type (256)
192 02 00 <- node descriptor type (member AS - 512)
194 00 00 00 64 <- value (100)
195 02 01 <- node descriptor type (bgpId - 513)
197 19 19 19 01 <- bgpId (25.25.25.1)
198 02 02 <- node descriptor type (areaId - 514)
201 02 03 <- node descriptor type (routeId - 515)
203 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
205 01 01 <- remote node descriptor type (257)
207 02 00 <- node descriptor type (member AS - 512)
209 00 00 00 64 <- value (100)
210 02 01 <- node descriptor type (bgpId - 513)
212 19 19 19 01 <- bgpId (25.25.25.1)
213 02 02 <- node descriptor type (areaId - 514)
216 02 03 <- node descriptor type (routeId - 515)
218 03 03 03 04 <- OSPF Router Id
220 01 03 <- link descriptor type (IPv4 interface address - 259)
222 0b 0b 0b 03 <- value (11.11.11.3)
224 00 02 <- NLRI type (2 - linkNLRI)
225 00 5d <- NLRI length (93)
226 03 <- ProtocolID - OSPF
227 00 00 00 00 00 00 00 01 <- identifier
229 01 00 <- local node descriptor type (256)
231 02 00 <- node descriptor type (member AS - 512)
233 00 00 00 64 <- value (100)
234 02 01 <- node descriptor type (bgpId - 513)
236 19 19 19 01 <- bgpId (25.25.25.1)
237 02 02 <- node descriptor type (areaId - 514)
240 02 03 <- node descriptor type (routeId - 515)
242 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
244 01 01 <- remote node descriptor type (257)
246 02 00 <- node descriptor type (member AS - 512)
248 00 00 00 64 <- value (100)
249 02 01 <- node descriptor type (bgpId - 513)
251 19 19 19 01 <- bgpId (25.25.25.1)
252 02 02 <- node descriptor type (areaId - 514)
255 02 03 <- node descriptor type (routeId - 515)
257 01 01 01 02 <- OSPF Router Id
259 01 03 <- link descriptor type (IPv4 interface address - 259)
261 0b 0b 0b 01 <- value (11.11.11.1)
263 00 02 <- NLRI type (2 - linkNLRI)
264 00 5d <- NLRI length (93)
265 03 <- ProtocolID - OSPF
266 00 00 00 00 00 00 00 01 <- identifier
268 01 00 <- local node descriptor type (256)
270 02 00 <- node descriptor type (member AS - 512)
272 00 00 00 64 <- value (100)
273 02 01 <- node descriptor type (bgpId - 513)
275 19 19 19 01 <- bgpId (25.25.25.1)
276 02 02 <- node descriptor type (areaId - 514)
279 02 03 <- node descriptor type (routeId - 515)
281 01 01 01 02 <- OSPF Router Id
283 01 01 <- remote node descriptor type (257)
285 02 00 <- node descriptor type (member AS - 512)
287 00 00 00 64 <- value (100)
288 02 01 <- node descriptor type (bgpId - 513)
290 19 19 19 01 <- bgpId (25.25.25.1)
291 02 02 <- node descriptor type (areaId - 514)
294 02 03 <- node descriptor type (routeId - 515)
296 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
298 01 03 <- link descriptor type (IPv4 interface address - 259)
300 0b 0b 0b 01 <- value (11.11.11.1)
302 40 <- attribute flags
303 01 <- attribute type (Origin)
304 01 <- attribute length
306 40 <- attribute flags
307 02 <- attribute type (AS Path)
309 40 <- attribute flags
310 05 <- attribute type (local pref)
313 c0 <- attribute flags
314 1D <- attribute type (Link STATE - 29)
316 04 47 <- link attribute (1095 - Metric)
321 public void testBGPLink() throws Exception {
322 final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
323 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
324 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
326 final UpdateBuilder builder = new UpdateBuilder();
330 assertNull(message.getWithdrawnRoutes());
332 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
333 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
335 final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
336 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
338 final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
339 new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
341 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
342 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
343 clBuilder.setProtocolId(ProtocolId.Ospf);
345 final Attributes1Builder lsBuilder = new Attributes1Builder();
346 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
347 mpBuilder.setAfi(LinkstateAddressFamily.class);
348 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
349 mpBuilder.setCNextHop(nextHop);
351 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
352 final LinkCaseBuilder lCase = new LinkCaseBuilder().setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
353 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
354 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
355 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
356 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
357 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
358 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
359 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
361 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
362 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
363 lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
364 new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
365 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
367 lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(
368 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
369 lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(
370 new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
371 linkstates.add(clBuilder.setObjectType(lCase.build()).build());
373 lsBuilder.setMpReachNlri(mpBuilder.build());
375 // check path attributes
376 final Attributes attrs = message.getAttributes();
378 final AttributesBuilder paBuilder = new AttributesBuilder();
380 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
381 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
383 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
384 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
386 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
387 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
389 final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
390 assertEquals(mpBuilder.getAfi(), mp.getAfi());
391 assertEquals(mpBuilder.getSafi(), mp.getSafi());
392 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
394 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
395 dBuilder.setCLinkstateDestination(linkstates);
397 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
398 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
399 lsBuilder.setMpReachNlri(mpBuilder.build());
401 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
403 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1Builder();
405 lsAttrBuilder.setLinkStateAttribute(
406 new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
407 paBuilder.addAugmentation(
408 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1.class,
409 lsAttrBuilder.build());
410 paBuilder.setUnrecognizedAttributes(Collections.<UnrecognizedAttributes> emptyList());
413 lsAttrBuilder.build(),
414 attrs.getAugmentation(
415 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Attributes1.class));
417 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
419 assertEquals(linkstates.size(), dests.size());
421 assertEquals(linkstates, dests);
423 builder.setAttributes(paBuilder.build());
424 assertEquals(builder.build(), message);
426 final ByteBuf buffer = Unpooled.buffer();
427 ParserTest.updateParser.serializeMessage(message, buffer);
428 assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
434 * 00 00 <- withdrawn routes length
435 00 b1 <- total path attribute length (177)
436 80 <- attribute flags
437 0e <- attribute type code (MP reach)
438 a0 <- attribute length (160)
439 40 04 <- AFI (16388 - Linkstate)
440 47 <- SAFI (71 - Linkstate)
441 04 <- next hop length
442 19 19 19 01 - nexthop (25.25.25.1)
445 00 01 <- NLRI type (1 - nodeNLRI)
446 00 31 <- NLRI length (49)
447 03 <- ProtocolID - OSPF
448 00 00 00 00 00 00 00 01 <- identifier
449 01 00 <- local node descriptor type (256)
451 02 00 <- node descriptor type (member AS - 512)
453 00 00 00 64 <- value (100)
454 02 01 <- node descriptor type (bgpId - 513)
456 19 19 19 01 <- bgpId (25.25.25.1)
457 02 02 <- node descriptor type (areaId - 514)
460 02 03 <- node descriptor type (routeId - 515)
462 03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
464 00 01 <- NLRI type (1 - nodeNLRI)
465 00 2d <- NLRI length (45)
466 03 <- ProtocolID - OSPF
467 00 00 00 00 00 00 00 01 <- identifier
468 01 00 <- local node descriptor type (256)
470 02 00 <- node descriptor type (member AS - 512)
472 00 00 00 64 <- value (100)
473 02 01 <- node descriptor type (bgpId - 513)
475 19 19 19 01 <- bgpId (25.25.25.1)
476 02 02 <- node descriptor type (areaId - 514)
479 02 03 <- node descriptor type (routeId - 515)
481 03 03 03 04 <- OSPF Router Id
483 00 01 <- NLRI type (1 - nodeNLRI)
484 00 2d <- NLRI length (45)
485 03 <- ProtocolID - OSPF
486 00 00 00 00 00 00 00 01 <- identifier
487 01 00 <- local node descriptor type (256)
489 02 00 <- node descriptor type (member AS - 512)
491 00 00 00 64 <- value (100)
492 02 01 <- node descriptor type (bgpId - 513)
494 19 19 19 01 <- bgpId (25.25.25.1)
495 02 02 <- node descriptor type (areaId - 514)
498 02 03 <- node descriptor type (routeId - 515)
500 01 01 01 02 <- OSPF Router Id
502 40 <- attribute flags
503 01 <- attribute type (Origin)
504 01 <- attribute length
506 40 <- attribute flags
507 02 <- attribute type (AS Path)
509 40 <- attribute flags
510 05 <- attribute type (local pref)
515 public void testBGPNode() throws Exception {
516 final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
517 final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
518 final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
520 final UpdateBuilder builder = new UpdateBuilder();
524 assertNull(message.getWithdrawnRoutes());
528 final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(
529 new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
531 final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
532 clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
533 clBuilder.setProtocolId(ProtocolId.Ospf);
535 final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
536 n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
538 final List<CLinkstateDestination> linkstates = Lists.newArrayList();
539 final NodeCaseBuilder nCase = new NodeCaseBuilder();
540 nCase.setNodeDescriptors(n.setCRouterIdentifier(
541 new OspfPseudonodeCaseBuilder().setOspfPseudonode(
542 new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
543 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
545 nCase.setNodeDescriptors(n.setCRouterIdentifier(
546 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
547 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
549 nCase.setNodeDescriptors(n.setCRouterIdentifier(
550 new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
551 linkstates.add(clBuilder.setObjectType(nCase.build()).build());
553 final Attributes1Builder lsBuilder = new Attributes1Builder();
554 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
555 mpBuilder.setAfi(LinkstateAddressFamily.class);
556 mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
557 mpBuilder.setCNextHop(nextHop);
559 final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
560 dBuilder.setCLinkstateDestination(linkstates);
562 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
563 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
564 lsBuilder.setMpReachNlri(mpBuilder.build());
566 // check path attributes
567 final Attributes attrs = message.getAttributes();
569 final AttributesBuilder paBuilder = new AttributesBuilder();
571 paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
572 assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
574 paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.<Segments> emptyList()).build());
575 assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
577 paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
578 assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
580 paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
581 paBuilder.setUnrecognizedAttributes(Collections.<UnrecognizedAttributes> emptyList());
583 final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
584 assertEquals(mpBuilder.getAfi(), mp.getAfi());
585 assertEquals(mpBuilder.getSafi(), mp.getSafi());
586 assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
588 final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
590 assertEquals(linkstates.size(), dests.size());
592 assertEquals(linkstates, dests);
595 builder.setAttributes(paBuilder.build());
596 assertEquals(builder.build(), message);
598 final ByteBuf buffer = Unpooled.buffer();
599 ParserTest.updateParser.serializeMessage(message, buffer);
600 assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
604 * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
605 * 00 3d <- length (61) - including header
608 * 00 64 <- My AS Number (AS TRANS in this case)
610 * 00 00 00 00 <- BGP Identifier
611 * 20 <- Optional Parameters Length
612 * 02 <- opt. param. type (capabilities)
614 * 01 <- capability code (MP Extensions for BGP4)
616 * 00 01 00 01 <- AFI 1, SAFI 1
617 * 02 <- opt. param. type (capabilities)
619 * 01 <- capability code (MP Extensions for BGP4)
621 * 00 02 00 01 <- AFI 2, SAFI 1
622 * 02 <- opt. param. type (capabilities)
624 * 01 <- capability code (MP Extensions for BGP4)
626 * 40 04 00 47 <- AFI 16388, SAFI 71
627 * 02 <- opt. param. type (capabilities)
629 * 41 <- capability code (AS4 octet support)
631 * 00 00 00 64 <- AS number
634 public void testOpenMessage() throws Exception {
635 final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry();
636 final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(3)));
637 final Open open = (Open) o;
638 final Set<BgpTableType> types = Sets.newHashSet();
639 for (final BgpParameters param : open.getBgpParameters()) {
640 for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
641 final CParameters cParam = optCapa.getCParameters();
642 if(cParam != null && cParam.getAugmentation(CParameters1.class) != null && cParam.getAugmentation
643 (CParameters1.class).getMultiprotocolCapability() != null) {
644 final MultiprotocolCapability mp = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
645 final BgpTableType type = new BgpTableTypeImpl(mp.getAfi(), mp.getSafi());
650 final Set<BgpTableType> expected = Sets.newHashSet();
651 expected.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
652 expected.add(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
653 expected.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
654 assertEquals(expected, types);
656 final ByteBuf buffer = Unpooled.buffer();
657 msgReg.serializeMessage(o, buffer);
658 assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer));