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;
14 import com.google.common.collect.Lists;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import java.math.BigInteger;
18 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser;
21 import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
22 import org.opendaylight.protocol.bgp.linkstate.nlri.NodeNlriParser;
23 import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv4NlriParser;
24 import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixIpv6NlriParser;
25 import org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriSerializer;
26 import org.opendaylight.protocol.bgp.linkstate.nlri.SimpleNlriTypeRegistry;
27 import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv4NlriParser;
28 import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspIpv6NlriParser;
29 import org.opendaylight.protocol.bgp.linkstate.nlri.TeLspNlriSerializer;
30 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
31 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
32 import org.opendaylight.protocol.util.ByteArray;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NlriType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.OspfRouteType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifierBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.TeLspCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptors;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptors;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptors;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptors;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.te.lsp._case.address.family.Ipv4Case;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.CRouterIdentifier;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
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.DestinationLinkstateCase;
62 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;
63 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.DestinationLinkstate;
64 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;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.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) 0x12, // 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;
144 private void setUp(final byte[] data) throws BGPParsingException {
145 final LinkstateNlriParser parser = new LinkstateNlriParser(false);
146 final MpReachNlriBuilder builder = new MpReachNlriBuilder();
147 final SimpleNlriTypeRegistry testreg = SimpleNlriTypeRegistry.getInstance();
149 final NodeNlriParser nodeParser = new NodeNlriParser();
150 testreg.registerNlriTypeParser(NlriType.Node, nodeParser);
151 testreg.registerNlriTypeSerializer(NodeCase.class, nodeParser);
153 final LinkNlriParser linkParser = new LinkNlriParser();
154 testreg.registerNlriTypeParser(NlriType.Link, linkParser);
155 testreg.registerNlriTypeSerializer(LinkCase.class, linkParser);
157 final PrefixIpv4NlriParser ipv4PrefParser = new PrefixIpv4NlriParser();
158 testreg.registerNlriTypeParser(NlriType.Ipv4Prefix, ipv4PrefParser);
160 final PrefixIpv6NlriParser ipv6PrefParser = new PrefixIpv6NlriParser();
161 testreg.registerNlriTypeParser(NlriType.Ipv6Prefix, ipv6PrefParser);
163 final TeLspIpv4NlriParser telSPipv4Parser = new TeLspIpv4NlriParser();
164 testreg.registerNlriTypeParser(NlriType.Ipv4TeLsp, telSPipv4Parser);
166 final TeLspIpv6NlriParser telSPipv6Parser = new TeLspIpv6NlriParser();
167 testreg.registerNlriTypeParser(NlriType.Ipv6TeLsp, telSPipv6Parser);
169 final PrefixNlriSerializer prefixSerializer = new PrefixNlriSerializer();
170 testreg.registerNlriTypeSerializer(PrefixCase.class, prefixSerializer);
172 final TeLspNlriSerializer telSpSerializer = new TeLspNlriSerializer();
173 testreg.registerNlriTypeSerializer(TeLspCase.class, telSpSerializer);
175 parser.parseNlri(Unpooled.copiedBuffer(data), builder);
177 final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
178 assertEquals(1, ls.getCLinkstateDestination().size());
180 this.dest = ls.getCLinkstateDestination().get(0);
184 public void testNodeNlri() throws BGPParsingException {
185 setUp(this.nodeNlri);
188 assertNull(this.dest.getDistinguisher());
189 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
190 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
191 final NodeCase nCase = ((NodeCase) this.dest.getObjectType());
193 final NodeDescriptors nodeD = nCase.getNodeDescriptors();
194 assertEquals(new AsNumber(72L), nodeD.getAsNumber());
195 assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId());
196 assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
197 new IsisPseudonodeBuilder().setPsn((short) 5).setIsIsRouterIdentifier(
198 new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), nodeD.getCRouterIdentifier());
200 final ByteBuf buffer = Unpooled.buffer();
201 LinkstateNlriParser.serializeNlri(this.dest, buffer);
202 assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));
205 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder
207 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
209 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
210 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
211 protocolId.withValue("isis-level2");
212 linkstateBI.addChild(protocolId.build());
214 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
215 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
216 identifier.withValue(BigInteger.ONE);
217 linkstateBI.addChild(identifier.build());
219 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
220 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
222 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
223 nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);
225 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
226 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
227 asNumber.withValue(72L);
228 nodeDescriptors.addChild(asNumber.build());
230 final ImmutableLeafNodeBuilder<Long> areaID = new ImmutableLeafNodeBuilder<>();
231 areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
232 areaID.withValue(2697513L); nodeDescriptors.addChild(areaID.build());
234 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
235 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
236 domainID.withValue(0x28282828L);
237 nodeDescriptors.addChild(domainID.build());
239 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
240 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
242 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
243 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);
245 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
246 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
247 isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});
249 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter = Builders.containerBuilder();
250 isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
251 isisPseudoRouter.addChild(isoSystemID.build());
253 isisNode.addChild(isisPseudoRouter.build());
254 isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5).build());
255 crouterId.addChild(isisNode.build());
257 nodeDescriptors.addChild(crouterId.build());
258 objectType.addChild(nodeDescriptors.build());
259 linkstateBI.addChild(objectType.build());
261 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
265 public void testLinkNlri() throws BGPParsingException {
266 setUp(this.linkNlri);
269 assertNull(this.dest.getDistinguisher());
270 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
271 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
273 final LinkCase lCase = ((LinkCase) this.dest.getObjectType());
275 final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
276 assertEquals(new AsNumber(72L), local.getAsNumber());
277 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
279 new IsisNodeCaseBuilder().setIsisNode(
280 new IsisNodeBuilder().setIsoSystemId(
281 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
282 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
283 assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
284 assertEquals(new AsNumber(258L), local.getMemberAsn());
286 final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
287 assertEquals(new AsNumber(72L), remote.getAsNumber());
288 assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
289 assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build()).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 LinkstateNlriParser.serializeNlri(this.dest, buffer);
300 assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
303 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
304 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
306 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
307 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
308 protocolId.withValue("isis-level2");
309 linkstateBI.addChild(protocolId.build());
311 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
312 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
313 identifier.withValue(BigInteger.ONE);
314 linkstateBI.addChild(identifier.build());
316 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
317 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
319 // local node descriptors
320 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors = Builders.containerBuilder();
321 localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
323 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
324 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
325 asNumber.withValue(72L);
326 localNodeDescriptors.addChild(asNumber.build());
328 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
329 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
330 domainID.withValue(0x28282828L);
331 localNodeDescriptors.addChild(domainID.build());
333 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
334 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
336 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
337 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
339 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
340 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
341 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
343 isisNode.addChild(isoSystemID.build());
344 crouterId.addChild(isisNode.build());
345 localNodeDescriptors.addChild(crouterId.build());
347 final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
348 bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
349 bgpRouterId.withValue("1.1.1.1");
351 final ImmutableLeafNodeBuilder<Long> memberAsn = new ImmutableLeafNodeBuilder<>();
352 memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
353 memberAsn.withValue(258L);
355 localNodeDescriptors.addChild(bgpRouterId.build());
356 localNodeDescriptors.addChild(memberAsn.build());
358 // remote descriptors
359 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors = Builders.containerBuilder();
360 remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
361 remoteNodeDescriptors.addChild(asNumber.build());
362 remoteNodeDescriptors.addChild(domainID.build());
364 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
365 crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
367 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
368 ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
370 final ImmutableLeafNodeBuilder<Long> ospfRouterId = new ImmutableLeafNodeBuilder<>();
371 ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
372 ospfRouterId.withValue(0x00000040L);
373 ospfNode.addChild(ospfRouterId.build());
374 crouterId2.addChild(ospfNode.build());
375 remoteNodeDescriptors.addChild(crouterId2.build());
376 final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
377 bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
378 bgpRouterIdRemote.withValue("1.1.1.2");
379 remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
381 final ImmutableLeafNodeBuilder<Long> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
382 memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
383 memberAsnRemote.withValue(259L);
384 remoteNodeDescriptors.addChild(memberAsnRemote.build());
387 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
388 linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
390 final ImmutableLeafNodeBuilder<Long> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
391 linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
392 linkLocalIdentifier.withValue(16909060L);
394 final ImmutableLeafNodeBuilder<Long> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
395 linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
396 linkRemoteIdentifier.withValue(168496141L);
398 final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
399 ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
400 ipv4InterfaceAddress.withValue("197.20.160.42");
402 final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
403 ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
404 ipv4NeighborAddress.withValue("197.20.160.40");
406 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
407 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
408 multiTopologyId.withValue(3);
410 linkDescriptors.addChild(linkLocalIdentifier.build());
411 linkDescriptors.addChild(linkRemoteIdentifier.build());
412 linkDescriptors.addChild(ipv4InterfaceAddress.build());
413 linkDescriptors.addChild(ipv4NeighborAddress.build());
414 linkDescriptors.addChild(multiTopologyId.build());
416 objectType.addChild(localNodeDescriptors.build());
417 objectType.addChild(remoteNodeDescriptors.build());
418 objectType.addChild(linkDescriptors.build());
420 linkstateBI.addChild(objectType.build());
421 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
425 public void testPrefixNlri() throws BGPParsingException {
426 setUp(this.prefixNlri);
429 assertNull(this.dest.getDistinguisher());
430 assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
431 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
433 final PrefixCase pCase = ((PrefixCase) this.dest.getObjectType());
435 final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors();
436 assertEquals(new AsNumber(72L), local.getAsNumber());
437 assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
439 new IsisNodeCaseBuilder().setIsisNode(
440 new IsisNodeBuilder().setIsoSystemId(
441 new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
442 (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
444 final PrefixDescriptors pd = pCase.getPrefixDescriptors();
445 assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
446 assertEquals(new TopologyIdentifier(15), pd.getMultiTopologyId());
447 assertEquals(new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());
449 final ByteBuf buffer = Unpooled.buffer();
450 LinkstateNlriParser.serializeNlri(this.dest, buffer);
451 assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));
454 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
455 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
457 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
458 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
459 protocolId.withValue("isis-level2");
460 linkstateBI.addChild(protocolId.build());
462 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
463 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
464 identifier.withValue(BigInteger.ONE);
465 linkstateBI.addChild(identifier.build());
467 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
468 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
470 // advertising node descriptors
471 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors = Builders.containerBuilder();
472 advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);
474 final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
475 asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
476 asNumber.withValue(72L);
477 advertisingNodeDescriptors.addChild(asNumber.build());
479 final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
480 domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
481 domainID.withValue(673720360L);
482 advertisingNodeDescriptors.addChild(domainID.build());
484 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
485 crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
487 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
488 isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
490 final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
491 isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
492 isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
494 isisNode.addChild(isoSystemID.build());
495 crouterId.addChild(isisNode.build());
496 advertisingNodeDescriptors.addChild(crouterId.build());
498 // prefix descriptors
499 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> prefixDescriptors = Builders.containerBuilder();
500 prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
501 prefixDescriptors.addChild(asNumber.build());
502 prefixDescriptors.addChild(domainID.build());
504 final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
505 multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
506 multiTopologyId.withValue(15);
508 prefixDescriptors.addChild(multiTopologyId.build());
510 final ImmutableLeafNodeBuilder<String> ipReachabilityInformation = new ImmutableLeafNodeBuilder<>();
511 ipReachabilityInformation.withNodeIdentifier(PrefixIpv4NlriParser.IP_REACH_NID);
512 ipReachabilityInformation.withValue("255.255.0.0/16");
514 prefixDescriptors.addChild(ipReachabilityInformation.build());
516 final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
517 ospfRouteType.withNodeIdentifier(PrefixIpv4NlriParser.OSPF_ROUTE_NID);
518 ospfRouteType.withValue("external1");
520 prefixDescriptors.addChild(ospfRouteType.build());
522 objectType.addChild(advertisingNodeDescriptors.build());
523 objectType.addChild(prefixDescriptors.build());
525 linkstateBI.addChild(objectType.build());
526 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
530 public void testTELspNlri() throws BGPParsingException {
531 setUp(this.teLspNlri);
533 assertNull(this.dest.getDistinguisher());
534 assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
535 assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
536 final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
538 assertEquals(new LspId(1L), teCase.getLspId());
539 assertEquals(new TunnelId(1), teCase.getTunnelId());
540 assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
541 assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
544 final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
545 linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
547 final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
548 protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
549 protocolId.withValue("rsvp-te");
550 linkstateBI.addChild(protocolId.build());
552 final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
553 identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
554 identifier.withValue(BigInteger.ONE);
555 linkstateBI.addChild(identifier.build());
557 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
558 objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
560 final ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
561 lspId.withNodeIdentifier(TeLspNlriSerializer.LSP_ID);
564 final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
565 tunnelId.withNodeIdentifier(TeLspNlriSerializer.TUNNEL_ID);
566 tunnelId.withValue(1);
568 final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
569 addressFamily.withNodeIdentifier(TeLspNlriSerializer.ADDRESS_FAMILY);
571 final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
572 ipv4TunnelSenderAddress.withNodeIdentifier(TeLspNlriSerializer.IPV4_TUNNEL_SENDER_ADDRESS);
573 ipv4TunnelSenderAddress.withValue("1.2.3.4");
575 final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
576 ipv4TunnelEndPointAddress.withNodeIdentifier(TeLspNlriSerializer.IPV4_TUNNEL_ENDPOINT_ADDRESS);
577 ipv4TunnelEndPointAddress.withValue("4.3.2.1");
579 addressFamily.addChild(ipv4TunnelSenderAddress.build());
580 addressFamily.addChild(ipv4TunnelEndPointAddress.build());
582 objectType.addChild(lspId.build());
583 objectType.addChild(tunnelId.build());
584 objectType.addChild(addressFamily.build());
586 linkstateBI.addChild(objectType.build());
587 assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
590 public void testSerializeAttribute() throws BGPParsingException {
591 final LinkstateNlriParser parser = new LinkstateNlriParser(true);
592 setUp(this.prefixNlri);
593 final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
594 final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
595 final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
596 final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAdvertizedRoutes(aroutes).build()).build();
598 Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).build();
600 ByteBuf result = Unpooled.buffer();
601 parser.serializeAttribute(pa, result);
602 assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));
604 setUp(this.nodeNlri);
605 final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
606 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU =
607 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
608 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU).build()).build();
609 final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build();
610 final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder().setWithdrawnRoutes(wroutes).build()).build();
612 pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build();
614 result = Unpooled.buffer();
615 parser.serializeAttribute(pa, result);
616 assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));