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.assertNull;
13 import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.OspfRouteTlvParser.OSPF_ROUTE_NID;
14 import static org.opendaylight.protocol.bgp.linkstate.impl.tlvs.ReachTlvParser.IP_REACH_NID;
16 import com.google.common.collect.Lists;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.math.BigInteger;
20 import java.util.List;
21 import org.junit.Test;
22 import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator;
23 import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
24 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkNlriParser;
25 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
26 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser;
27 import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
28 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
29 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
30 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
31 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
32 import org.opendaylight.protocol.rsvp.parser.spi.pojo.ServiceLoaderRSVPExtensionProviderContext;
33 import org.opendaylight.protocol.util.ByteArray;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.DomainIdentifier;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfRouteType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifierBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestination;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.NodeCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.PrefixCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.TeLspCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LocalNodeDescriptors;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.RemoteNodeDescriptors;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv4Case;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.CRouterIdentifier;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
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.DestinationLinkstateCase;
62 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;
63 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.DestinationLinkstate;
64 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;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
80 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
81 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
82 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
83 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
84 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
85 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
86 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
87 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
88 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
89 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
91 public class LinkstateNlriParserTest {
93 private static final NodeIdentifier C_LINKSTATE_NID = new NodeIdentifier(CLinkstateDestination.QNAME);
94 private static final NodeIdentifier C_ROUTER_ID_NID = new NodeIdentifier(CRouterIdentifier.QNAME);
96 private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00,
97 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x23,
98 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
99 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04,
100 (byte) 0x00, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00,
101 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
103 private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00,
104 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
105 // local node descriptors
106 (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2a,
107 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
108 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06,
109 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
110 2, 4, 0, 4, 1, 1, 1, 1,
111 2, 5, 0, 4, 0, 0, 1, 2,
112 // remote node descriptors
113 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x28,
114 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
115 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x04,
116 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40,
117 2, 4, 0, 4, 1, 1, 1, 2,
118 2, 5, 0, 4, 0, 0, 1, 3,
120 1, 2, 0, 8, 1, 2, 3, 4, 0x0a,
121 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x2a,
122 (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
125 private final byte[] prefixNlri = new byte[] { (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00,
126 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
127 (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02,
128 (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00,
129 (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00,
130 (byte) 0x02, (byte) 0x00, (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09,
131 (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF };
133 private final byte[] teLspNlri = new byte[] { (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4
134 (byte) 0x00, (byte) 0x15, // length
135 (byte) 0x08, //Protocol-ID
136 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // Identifier
137 (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address
138 (byte) 0x00, (byte) 0x01, //Tunnel ID
139 (byte) 0x00, (byte) 0x01, //LSP ID
140 (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 }; // IPv4 Tunnel End-point Address
142 private CLinkstateDestination dest;
143 private SimpleNlriTypeRegistry registry;
145 private void setUp(final byte[] data) throws BGPParsingException {
146 final LinkstateNlriParser parser = new LinkstateNlriParser();
147 final MpReachNlriBuilder builder = new MpReachNlriBuilder();
148 this.registry = SimpleNlriTypeRegistry.getInstance();
149 final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
150 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
153 parser.parseNlri(Unpooled.copiedBuffer(data), builder, null);
155 final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
156 assertEquals(1, ls.getCLinkstateDestination().size());
158 this.dest = ls.getCLinkstateDestination().get(0);
162 public void testNodeNlri() throws BGPParsingException {
163 setUp(this.nodeNlri);
166 assertNull(this.dest.getRouteDistinguisher());
167 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
168 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
169 final NodeCase nCase = ((NodeCase) this.dest.getObjectType());
171 final NodeDescriptors nodeD = nCase.getNodeDescriptors();
172 assertEquals(new AsNumber(72L), nodeD.getAsNumber());
173 assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId());
174 assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
175 new IsisPseudonodeBuilder().setPsn((short) 5).setIsIsRouterIdentifier(
176 new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), nodeD.getCRouterIdentifier());
178 final ByteBuf buffer = Unpooled.buffer();
179 this.registry.serializeNlriType(this.dest, buffer);
180 assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
183 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder
185 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
187 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
188 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
189 protocolId.withValue("isis-level2");
190 linkstateBI.addChild(protocolId.build());
192 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
193 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
194 identifier.withValue(BigInteger.ONE);
195 linkstateBI.addChild(identifier.build());
197 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
198 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
200 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
201 nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
203 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
204 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
205 asNumber.withValue(72L);
206 nodeDescriptors.addChild(asNumber.build());
208 final ImmutableLeafNodeBuilder<Long> areaID = new ImmutableLeafNodeBuilder<>();
209 areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
210 areaID.withValue(2697513L); nodeDescriptors.addChild(areaID.build());
212 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
213 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
214 domainID.withValue(0x28282828L);
215 nodeDescriptors.addChild(domainID.build());
217 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
218 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
220 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
221 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
223 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
224 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
225 isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});
227 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter = Builders.containerBuilder();
228 isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
229 isisPseudoRouter.addChild(isoSystemID.build());
231 isisNode.addChild(isisPseudoRouter.build());
232 isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5).build());
233 crouterId.addChild(isisNode.build());
235 nodeDescriptors.addChild(crouterId.build());
236 objectType.addChild(nodeDescriptors.build());
237 linkstateBI.addChild(objectType.build());
239 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
243 public void testLinkNlri() throws BGPParsingException {
244 setUp(this.linkNlri);
247 assertNull(this.dest.getRouteDistinguisher());
248 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
249 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
251 final LinkCase lCase = ((LinkCase) this.dest.getObjectType());
253 final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
254 assertEquals(new AsNumber(72L), local.getAsNumber());
255 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
257 new IsisNodeCaseBuilder().setIsisNode(
258 new IsisNodeBuilder().setIsoSystemId(
259 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
260 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
261 assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
262 assertEquals(new AsNumber(258L), local.getMemberAsn());
264 final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
265 assertEquals(new AsNumber(72L), remote.getAsNumber());
266 assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
267 assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build()).build(),
268 remote.getCRouterIdentifier());
269 assertEquals(new AsNumber(259L), remote.getMemberAsn());
270 assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());
272 final LinkDescriptors ld = lCase.getLinkDescriptors();
273 assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
274 assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
276 final ByteBuf buffer = Unpooled.buffer();
277 this.registry.serializeNlriType(this.dest, buffer);
278 assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
281 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
282 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
284 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
285 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
286 protocolId.withValue("isis-level2");
287 linkstateBI.addChild(protocolId.build());
289 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
290 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
291 identifier.withValue(BigInteger.ONE);
292 linkstateBI.addChild(identifier.build());
294 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
295 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
297 // local node descriptors
298 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors = Builders.containerBuilder();
299 localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
301 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
302 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
303 asNumber.withValue(72L);
304 localNodeDescriptors.addChild(asNumber.build());
306 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
307 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
308 domainID.withValue(0x28282828L);
309 localNodeDescriptors.addChild(domainID.build());
311 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
312 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
314 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
315 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
317 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
318 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
319 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
321 isisNode.addChild(isoSystemID.build());
322 crouterId.addChild(isisNode.build());
323 localNodeDescriptors.addChild(crouterId.build());
325 final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
326 bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
327 bgpRouterId.withValue("1.1.1.1");
329 final ImmutableLeafNodeBuilder<Long> memberAsn = new ImmutableLeafNodeBuilder<>();
330 memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
331 memberAsn.withValue(258L);
333 localNodeDescriptors.addChild(bgpRouterId.build());
334 localNodeDescriptors.addChild(memberAsn.build());
336 // remote descriptors
337 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors = Builders.containerBuilder();
338 remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
339 remoteNodeDescriptors.addChild(asNumber.build());
340 remoteNodeDescriptors.addChild(domainID.build());
342 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
343 crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
345 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
346 ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
348 final ImmutableLeafNodeBuilder<Long> ospfRouterId = new ImmutableLeafNodeBuilder<>();
349 ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
350 ospfRouterId.withValue(0x00000040L);
351 ospfNode.addChild(ospfRouterId.build());
352 crouterId2.addChild(ospfNode.build());
353 remoteNodeDescriptors.addChild(crouterId2.build());
354 final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
355 bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
356 bgpRouterIdRemote.withValue("1.1.1.2");
357 remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
359 final ImmutableLeafNodeBuilder<Long> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
360 memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
361 memberAsnRemote.withValue(259L);
362 remoteNodeDescriptors.addChild(memberAsnRemote.build());
365 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
366 linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
368 final ImmutableLeafNodeBuilder<Long> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
369 linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
370 linkLocalIdentifier.withValue(16909060L);
372 final ImmutableLeafNodeBuilder<Long> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
373 linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
374 linkRemoteIdentifier.withValue(168496141L);
376 final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
377 ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
378 ipv4InterfaceAddress.withValue("197.20.160.42");
380 final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
381 ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
382 ipv4NeighborAddress.withValue("197.20.160.40");
384 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
385 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
386 multiTopologyId.withValue(3);
388 linkDescriptors.addChild(linkLocalIdentifier.build());
389 linkDescriptors.addChild(linkRemoteIdentifier.build());
390 linkDescriptors.addChild(ipv4InterfaceAddress.build());
391 linkDescriptors.addChild(ipv4NeighborAddress.build());
392 linkDescriptors.addChild(multiTopologyId.build());
394 objectType.addChild(localNodeDescriptors.build());
395 objectType.addChild(remoteNodeDescriptors.build());
396 objectType.addChild(linkDescriptors.build());
398 linkstateBI.addChild(objectType.build());
399 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
403 public void testPrefixNlri() throws BGPParsingException {
404 setUp(this.prefixNlri);
407 assertNull(this.dest.getRouteDistinguisher());
408 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
409 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
411 final PrefixCase pCase = ((PrefixCase) this.dest.getObjectType());
413 final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
414 assertEquals(new AsNumber(72L), local.getAsNumber());
415 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
417 new IsisNodeCaseBuilder().setIsisNode(
418 new IsisNodeBuilder().setIsoSystemId(
419 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
420 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
422 final PrefixDescriptors pd = pCase.getPrefixDescriptors();
423 assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
424 assertEquals(new TopologyIdentifier(15), pd.getMultiTopologyId());
425 assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
427 final ByteBuf buffer = Unpooled.buffer();
428 this.registry.serializeNlriType(this.dest, buffer);
429 assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
432 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
433 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
435 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
436 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
437 protocolId.withValue("isis-level2");
438 linkstateBI.addChild(protocolId.build());
440 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
441 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
442 identifier.withValue(BigInteger.ONE);
443 linkstateBI.addChild(identifier.build());
445 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
446 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
448 // advertising node descriptors
449 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors = Builders.containerBuilder();
450 advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
452 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
453 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
454 asNumber.withValue(72L);
455 advertisingNodeDescriptors.addChild(asNumber.build());
457 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
458 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
459 domainID.withValue(673720360L);
460 advertisingNodeDescriptors.addChild(domainID.build());
462 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
463 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
465 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
466 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
468 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
469 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
470 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
472 isisNode.addChild(isoSystemID.build());
473 crouterId.addChild(isisNode.build());
474 advertisingNodeDescriptors.addChild(crouterId.build());
476 // prefix descriptors
477 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> prefixDescriptors = Builders.containerBuilder();
478 prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
479 prefixDescriptors.addChild(asNumber.build());
480 prefixDescriptors.addChild(domainID.build());
482 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
483 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
484 multiTopologyId.withValue(15);
486 prefixDescriptors.addChild(multiTopologyId.build());
488 final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
489 ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
490 ipReachabilityInformation.withValue("255.255.0.0/16");
492 prefixDescriptors.addChild(ipReachabilityInformation.build());
494 final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
495 ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
496 ospfRouteType.withValue("external1");
498 prefixDescriptors.addChild(ospfRouteType.build());
500 objectType.addChild(advertisingNodeDescriptors.build());
501 objectType.addChild(prefixDescriptors.build());
503 linkstateBI.addChild(objectType.build());
504 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
508 public void testTELspNlri() throws BGPParsingException {
509 setUp(this.teLspNlri);
511 assertNull(this.dest.getRouteDistinguisher());
512 assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
513 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
514 final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
516 assertEquals(new LspId(1L), teCase.getLspId());
517 assertEquals(new TunnelId(1), teCase.getTunnelId());
518 assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
519 assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
522 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
523 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
525 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
526 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
527 protocolId.withValue("rsvp-te");
528 linkstateBI.addChild(protocolId.build());
530 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
531 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
532 identifier.withValue(BigInteger.ONE);
533 linkstateBI.addChild(identifier.build());
535 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
536 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
538 final ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
539 lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
542 final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
543 tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
544 tunnelId.withValue(1);
546 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
547 addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
549 final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
550 ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
551 ipv4TunnelSenderAddress.withValue("1.2.3.4");
553 final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
554 ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
555 ipv4TunnelEndPointAddress.withValue("4.3.2.1");
557 addressFamily.addChild(ipv4TunnelSenderAddress.build());
558 addressFamily.addChild(ipv4TunnelEndPointAddress.build());
560 objectType.addChild(lspId.build());
561 objectType.addChild(tunnelId.build());
562 objectType.addChild(addressFamily.build());
564 linkstateBI.addChild(objectType.build());
565 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
568 public void testSerializeAttribute() throws BGPParsingException {
569 final LinkstateNlriParser parser = new LinkstateNlriParser();
570 setUp(this.prefixNlri);
571 final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
572 final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
573 final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
574 final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAdvertizedRoutes(aroutes).build()).build();
576 Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).build();
578 ByteBuf result = Unpooled.buffer();
579 parser.serializeAttribute(pa, result);
580 assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));
582 setUp(this.nodeNlri);
583 final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
584 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU =
585 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
586 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU).build()).build();
587 final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build();
588 final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder().setWithdrawnRoutes(wroutes).build()).build();
590 pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build();
592 result = Unpooled.buffer();
593 parser.serializeAttribute(pa, result);
594 assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));