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.impl.nlri.LinkNlriParser;
24 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser;
25 import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser;
26 import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
27 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
28 import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry;
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[] {
97 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
98 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
99 (byte) 0x23, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
100 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
101 (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x29, (byte) 0x29,
102 (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x00,
103 (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
105 private final byte[] linkNlri = new byte[] {
106 (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
107 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
109 // local node descriptors
110 (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2a,
111 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
112 (byte) 0x02, (byte) 0x01,
113 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
114 (byte) 0x00, (byte) 0x06,
115 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
116 2, 4, 0, 4, 1, 1, 1, 1,
117 2, 5, 0, 4, 0, 0, 1, 2,
118 // remote node descriptors
119 (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x28,
120 (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
121 (byte) 0x02, (byte) 0x01,
122 (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03,
123 (byte) 0x00, (byte) 0x04,
124 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40,
125 2, 4, 0, 4, 1, 1, 1, 2,
126 2, 5, 0, 4, 0, 0, 1, 3,
128 1, 2, 0, 8, 1, 2, 3, 4, 0x0a,
129 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
131 (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
134 private final byte[] prefixNlri = new byte[] {
135 (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00,
136 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
137 (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00,
138 (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28,
139 (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
140 (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00,
141 (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09,
142 (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF
145 private final byte[] teLspNlri = new byte[] {
146 (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4
147 (byte) 0x00, (byte) 0x15, // length
148 (byte) 0x08, //Protocol-ID
150 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
151 (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address
152 (byte) 0x00, (byte) 0x01, //Tunnel ID
153 (byte) 0x00, (byte) 0x01, //LSP ID
154 (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 }; // IPv4 Tunnel End-point Address
156 private CLinkstateDestination dest;
157 private SimpleNlriTypeRegistry registry;
159 private void setUp(final byte[] data) throws BGPParsingException {
160 final LinkstateNlriParser parser = new LinkstateNlriParser();
161 final MpReachNlriBuilder builder = new MpReachNlriBuilder();
162 this.registry = SimpleNlriTypeRegistry.getInstance();
163 final BGPActivator act = new BGPActivator(true,
164 ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry());
165 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
168 parser.parseNlri(Unpooled.copiedBuffer(data), builder, null);
170 final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType())
171 .getDestinationLinkstate();
172 assertEquals(1, ls.getCLinkstateDestination().size());
174 this.dest = ls.getCLinkstateDestination().get(0);
178 public void testNodeNlri() throws BGPParsingException {
179 setUp(this.nodeNlri);
182 assertNull(this.dest.getRouteDistinguisher());
183 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
184 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
185 final NodeCase nCase = (NodeCase) this.dest.getObjectType();
187 final NodeDescriptors nodeD = nCase.getNodeDescriptors();
188 assertEquals(new AsNumber(72L), nodeD.getAsNumber());
189 assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId());
190 assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
191 new IsisPseudonodeBuilder().setPsn((short) 5).setIsIsRouterIdentifier(
192 new IsIsRouterIdentifierBuilder().setIsoSystemId(
193 new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(),
194 nodeD.getCRouterIdentifier());
196 final ByteBuf buffer = Unpooled.buffer();
197 this.registry.serializeNlriType(this.dest, buffer);
198 assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
201 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
202 ImmutableUnkeyedListEntryNodeBuilder.create();
203 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
205 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
206 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
207 protocolId.withValue("isis-level2");
208 linkstateBI.addChild(protocolId.build());
210 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
211 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
212 identifier.withValue(BigInteger.ONE);
213 linkstateBI.addChild(identifier.build());
215 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
216 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
218 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
219 nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
221 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
222 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
223 asNumber.withValue(72L);
224 nodeDescriptors.addChild(asNumber.build());
226 final ImmutableLeafNodeBuilder<Long> areaID = new ImmutableLeafNodeBuilder<>();
227 areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
228 areaID.withValue(2697513L);
229 nodeDescriptors.addChild(areaID.build());
231 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
232 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
233 domainID.withValue(0x28282828L);
234 nodeDescriptors.addChild(domainID.build());
236 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
237 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
239 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
240 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
242 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
243 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
244 isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});
246 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter =
247 Builders.containerBuilder();
248 isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
249 isisPseudoRouter.addChild(isoSystemID.build());
251 isisNode.addChild(isisPseudoRouter.build());
252 isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5)
254 crouterId.addChild(isisNode.build());
256 nodeDescriptors.addChild(crouterId.build());
257 objectType.addChild(nodeDescriptors.build());
258 linkstateBI.addChild(objectType.build());
260 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
264 public void testLinkNlri() throws BGPParsingException {
265 setUp(this.linkNlri);
268 assertNull(this.dest.getRouteDistinguisher());
269 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
270 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
272 final LinkCase lCase = (LinkCase) this.dest.getObjectType();
274 final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
275 assertEquals(new AsNumber(72L), local.getAsNumber());
276 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
278 new IsisNodeCaseBuilder().setIsisNode(
279 new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] {
280 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(),
281 local.getCRouterIdentifier());
282 assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
283 assertEquals(new AsNumber(258L), local.getMemberAsn());
285 final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
286 assertEquals(new AsNumber(72L), remote.getAsNumber());
287 assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
288 assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build())
290 remote.getCRouterIdentifier());
291 assertEquals(new AsNumber(259L), remote.getMemberAsn());
292 assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());
294 final LinkDescriptors ld = lCase.getLinkDescriptors();
295 assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
296 assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
298 final ByteBuf buffer = Unpooled.buffer();
299 this.registry.serializeNlriType(this.dest, buffer);
300 assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
303 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
304 ImmutableUnkeyedListEntryNodeBuilder.create();
305 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
307 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
308 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
309 protocolId.withValue("isis-level2");
310 linkstateBI.addChild(protocolId.build());
312 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
313 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
314 identifier.withValue(BigInteger.ONE);
315 linkstateBI.addChild(identifier.build());
317 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
318 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
320 // local node descriptors
321 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors =
322 Builders.containerBuilder();
323 localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
325 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
326 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
327 asNumber.withValue(72L);
328 localNodeDescriptors.addChild(asNumber.build());
330 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
331 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
332 domainID.withValue(0x28282828L);
333 localNodeDescriptors.addChild(domainID.build());
335 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
336 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
338 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
339 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
341 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
342 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
343 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
345 isisNode.addChild(isoSystemID.build());
346 crouterId.addChild(isisNode.build());
347 localNodeDescriptors.addChild(crouterId.build());
349 final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
350 bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
351 bgpRouterId.withValue("1.1.1.1");
353 final ImmutableLeafNodeBuilder<Long> memberAsn = new ImmutableLeafNodeBuilder<>();
354 memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
355 memberAsn.withValue(258L);
357 localNodeDescriptors.addChild(bgpRouterId.build());
358 localNodeDescriptors.addChild(memberAsn.build());
360 // remote descriptors
361 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors =
362 Builders.containerBuilder();
363 remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
364 remoteNodeDescriptors.addChild(asNumber.build());
365 remoteNodeDescriptors.addChild(domainID.build());
367 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
368 crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
370 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
371 ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
373 final ImmutableLeafNodeBuilder<Long> ospfRouterId = new ImmutableLeafNodeBuilder<>();
374 ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
375 ospfRouterId.withValue(0x00000040L);
376 ospfNode.addChild(ospfRouterId.build());
377 crouterId2.addChild(ospfNode.build());
378 remoteNodeDescriptors.addChild(crouterId2.build());
379 final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
380 bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
381 bgpRouterIdRemote.withValue("1.1.1.2");
382 remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
384 final ImmutableLeafNodeBuilder<Long> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
385 memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
386 memberAsnRemote.withValue(259L);
387 remoteNodeDescriptors.addChild(memberAsnRemote.build());
390 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
391 linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
393 final ImmutableLeafNodeBuilder<Long> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
394 linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
395 linkLocalIdentifier.withValue(16909060L);
397 final ImmutableLeafNodeBuilder<Long> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
398 linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
399 linkRemoteIdentifier.withValue(168496141L);
401 final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
402 ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
403 ipv4InterfaceAddress.withValue("197.20.160.42");
405 final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
406 ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
407 ipv4NeighborAddress.withValue("197.20.160.40");
409 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
410 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
411 multiTopologyId.withValue(3);
413 linkDescriptors.addChild(linkLocalIdentifier.build());
414 linkDescriptors.addChild(linkRemoteIdentifier.build());
415 linkDescriptors.addChild(ipv4InterfaceAddress.build());
416 linkDescriptors.addChild(ipv4NeighborAddress.build());
417 linkDescriptors.addChild(multiTopologyId.build());
419 objectType.addChild(localNodeDescriptors.build());
420 objectType.addChild(remoteNodeDescriptors.build());
421 objectType.addChild(linkDescriptors.build());
423 linkstateBI.addChild(objectType.build());
424 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
428 public void testPrefixNlri() throws BGPParsingException {
429 setUp(this.prefixNlri);
432 assertNull(this.dest.getRouteDistinguisher());
433 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
434 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
436 final PrefixCase pCase = (PrefixCase) this.dest.getObjectType();
438 final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
439 assertEquals(new AsNumber(72L), local.getAsNumber());
440 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
442 new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(
443 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
444 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
446 final PrefixDescriptors pd = pCase.getPrefixDescriptors();
447 assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
448 assertEquals(new TopologyIdentifier(15), pd.getMultiTopologyId());
449 assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
451 final ByteBuf buffer = Unpooled.buffer();
452 this.registry.serializeNlriType(this.dest, buffer);
453 assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
456 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
457 ImmutableUnkeyedListEntryNodeBuilder.create();
458 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
460 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
461 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
462 protocolId.withValue("isis-level2");
463 linkstateBI.addChild(protocolId.build());
465 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
466 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
467 identifier.withValue(BigInteger.ONE);
468 linkstateBI.addChild(identifier.build());
470 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
471 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
473 // advertising node descriptors
474 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors =
475 Builders.containerBuilder();
476 advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
478 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
479 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
480 asNumber.withValue(72L);
481 advertisingNodeDescriptors.addChild(asNumber.build());
483 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
484 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
485 domainID.withValue(673720360L);
486 advertisingNodeDescriptors.addChild(domainID.build());
488 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
489 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
491 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
492 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
494 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
495 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
496 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
498 isisNode.addChild(isoSystemID.build());
499 crouterId.addChild(isisNode.build());
500 advertisingNodeDescriptors.addChild(crouterId.build());
502 // prefix descriptors
503 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> prefixDescriptors =
504 Builders.containerBuilder();
505 prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
506 prefixDescriptors.addChild(asNumber.build());
507 prefixDescriptors.addChild(domainID.build());
509 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
510 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
511 multiTopologyId.withValue(15);
513 prefixDescriptors.addChild(multiTopologyId.build());
515 final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
516 ipReachabilityInformation.withNodeIdentifier(IP_REACH_NID);
517 ipReachabilityInformation.withValue("255.255.0.0/16");
519 prefixDescriptors.addChild(ipReachabilityInformation.build());
521 final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
522 ospfRouteType.withNodeIdentifier(OSPF_ROUTE_NID);
523 ospfRouteType.withValue("external1");
525 prefixDescriptors.addChild(ospfRouteType.build());
527 objectType.addChild(advertisingNodeDescriptors.build());
528 objectType.addChild(prefixDescriptors.build());
530 linkstateBI.addChild(objectType.build());
531 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
535 public void testTELspNlri() throws BGPParsingException {
536 setUp(this.teLspNlri);
538 assertNull(this.dest.getRouteDistinguisher());
539 assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
540 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
541 final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
543 assertEquals(new LspId(1L), teCase.getLspId());
544 assertEquals(new TunnelId(1), teCase.getTunnelId());
545 assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
546 assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
549 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
550 ImmutableUnkeyedListEntryNodeBuilder.create();
551 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
553 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
554 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
555 protocolId.withValue("rsvp-te");
556 linkstateBI.addChild(protocolId.build());
558 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
559 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
560 identifier.withValue(BigInteger.ONE);
561 linkstateBI.addChild(identifier.build());
563 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
564 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
566 final ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
567 lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
570 final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
571 tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
572 tunnelId.withValue(1);
574 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
575 addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
577 final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
578 ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
579 ipv4TunnelSenderAddress.withValue("1.2.3.4");
581 final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
582 ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
583 ipv4TunnelEndPointAddress.withValue("4.3.2.1");
585 addressFamily.addChild(ipv4TunnelSenderAddress.build());
586 addressFamily.addChild(ipv4TunnelEndPointAddress.build());
588 objectType.addChild(lspId.build());
589 objectType.addChild(tunnelId.build());
590 objectType.addChild(addressFamily.build());
592 linkstateBI.addChild(objectType.build());
593 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
597 public void testSerializeAttribute() throws BGPParsingException {
598 final LinkstateNlriParser parser = new LinkstateNlriParser();
599 setUp(this.prefixNlri);
600 final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
601 final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
602 new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
603 final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
604 final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder()
605 .setAdvertizedRoutes(aroutes).build()).build();
607 Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).build();
609 ByteBuf result = Unpooled.buffer();
610 parser.serializeAttribute(pa, result);
611 assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));
613 setUp(this.nodeNlri);
614 final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
615 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
616 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU =
617 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
618 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder()
619 .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
620 .linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
621 .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU)
623 final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build();
624 final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder()
625 .setWithdrawnRoutes(wroutes).build()).build();
627 pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build();
629 result = Unpooled.buffer();
630 parser.serializeAttribute(pa, result);
631 assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));