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.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15 import com.google.common.collect.Lists;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import java.lang.reflect.Constructor;
19 import java.lang.reflect.InvocationTargetException;
20 import java.util.Arrays;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkAttributesParser;
24 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser;
25 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.NodeAttributesParser;
26 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.PrefixAttributesParser;
27 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
28 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
29 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
30 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
31 import org.opendaylight.protocol.util.ByteArray;
32 import org.opendaylight.protocol.util.Ipv4Util;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Attributes1;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkProtectionType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestinationBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.LinkCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.NodeCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.PrefixCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.TeLspCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.te.lsp.attributes._case.TeLspAttributes;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.IgpBits;
58 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;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2Builder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlriBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.adj.flags.flags.IsisAdjFlagsCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.LocalLabelCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
77 public class LinkstateAttributeParserTest {
79 private static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, lenght, value
80 0x00, (byte) 0x20, (byte) 0x0c, 0x02, // Lenght, Class, Ctype
81 0x00, 0x00, 0x00, 0x07,
82 0x01, 0x00, 0x00, 0x06,
83 (byte) 0x7f, 0x00, 0x00, 0x05,
84 0x00, 0x00, 0x00, 0x01, //Token Bucket Rate
85 0x00, 0x00, 0x00, 0x02, //Token Bucket Size
86 0x00, 0x00, 0x00, 0x03, //Peak Data Rate
87 0x00, 0x00, 0x00, 0x04, //Minimum Policed Unit
88 0x00, 0x00, 0x00, 0x05, //Maximum Packet Size
89 0x00, (byte) 0x08, (byte) 0xc7, 0x01, // Lenght, Class, Ctype
90 0x00, 0x01, 0x00, 0x02,
91 0x01, 0x02, 0x03, 0x04,};
93 private static final byte[] LINK_ATTR = {0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b,
94 0x04, 0x40, 0, 0x04, 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04,
95 0x46, 0x43, 0x50, 0, 0x04, 0x43, 0, 0x20, 0x46, 0x43, 0x50, 0, 0x46, 0x43, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x44, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x45, 0, 0x02, 0, 0x08, 0x04, 0x46, 0, 0x01,
97 (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a,
98 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32,
99 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj
100 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj
101 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj
102 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-lan-adj
103 0x04, 0x4d, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, // peer-node-sid
104 0x04, 0x4e, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0f, // peer-adj-sid
105 0x04, 0x4f, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0e, // peer-set-sid
106 0x04, (byte) 0x88, 0, 0x01, 0x0a };
108 private static final byte[] NODE_ATTR = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0,
109 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04,
110 0x29, 0x29, 0x29, 0x29, 0x04, (byte) 0x88, 0, 0x01, 0x0a,
111 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
112 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
115 private static final byte[] NODE_ATTR_S = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0,
116 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04,
117 0x29, 0x29, 0x29, 0x29,
118 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
119 4, 0x0b, 0, 2, 0, 1 // sr-algorythms
122 private static final byte[] P4_ATTR = { 0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
123 0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70,
124 0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b,
125 4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv
126 4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv
127 4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv
130 private RSVPExtensionProviderContext context;
131 private RSVPActivator rsvpActivator;
132 private LinkstateAttributeParser parser;
135 public final void setUp() {
136 this.context = new SimpleRSVPExtensionProviderContext();
137 this.rsvpActivator = new RSVPActivator();
138 this.rsvpActivator.start(this.context);
139 this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry());
141 private static AttributesBuilder createBuilder(final ObjectType type) {
142 return new AttributesBuilder().addAugmentation(
143 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1.class,
144 new Attributes1Builder().setMpReachNlri(
145 new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
146 new AdvertizedRoutesBuilder().setDestinationType(
147 new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
148 new DestinationLinkstateBuilder().setCLinkstateDestination(
149 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build());
152 private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
153 return new AttributesBuilder().addAugmentation(
154 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2.class,
155 new Attributes2Builder().setMpUnreachNlri(
156 new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setWithdrawnRoutes(
157 new WithdrawnRoutesBuilder().setDestinationType(
158 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(
159 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(
160 Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build());
164 public void testGetNlriType() throws BGPParsingException {
165 final ByteBuf b = Unpooled.buffer();
166 AttributesBuilder builder = new AttributesBuilder();
167 this.parser.parseAttribute(b, builder);
168 assertEquals(0, b.readableBytes());
169 builder = new AttributesBuilder();
171 final Attributes1Builder builder1 = new Attributes1Builder();
172 builder.addAugmentation(Attributes1.class, builder1.build());
173 this.parser.parseAttribute(b, builder);
174 assertEquals(0, b.readableBytes());
175 builder = new AttributesBuilder();
177 builder.addAugmentation(Attributes1.class, builder1.setMpReachNlri(
178 new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().build()).build()).build()).build());
179 this.parser.parseAttribute(b, builder);
180 assertEquals(0, b.readableBytes());
181 builder = new AttributesBuilder();
183 final Attributes2Builder builder2 = new Attributes2Builder();
184 builder.addAugmentation(Attributes2.class, builder2.build());
185 this.parser.parseAttribute(b, builder);
186 assertEquals(0, b.readableBytes());
187 builder = new AttributesBuilder();
189 builder.addAugmentation(Attributes2.class, builder2.setMpUnreachNlri(
190 new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().build()).build()).build()).build());
191 this.parser.parseAttribute(b, builder);
192 assertEquals(0, b.readableBytes());
196 public void testPositiveLinks() throws BGPParsingException {
197 final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
198 this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder);
199 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
200 final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
203 assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
204 assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
205 assertEquals(Long.valueOf(0L), ls.getAdminGroup().getValue());
206 assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
207 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
208 assertNotNull(ls.getUnreservedBandwidth());
209 assertEquals(8, ls.getUnreservedBandwidth().size());
210 assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
211 assertTrue(ls.getMplsProtocol().isLdp());
212 assertTrue(ls.getMplsProtocol().isRsvpte());
213 assertEquals(new Long(10), ls.getMetric().getValue());
214 assertEquals(2, ls.getSharedRiskLinkGroups().size());
215 assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
216 assertEquals("12K-2", ls.getLinkName());
217 final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder().setAddressFamily(Boolean.TRUE).setBackup(Boolean.FALSE).setSet(Boolean.FALSE).build();
218 assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
219 assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
220 assertEquals(new Long(1048575L), ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
221 assertEquals(new Long(1048559L), ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
222 assertEquals(new Long(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
223 assertEquals(new Short("5"), ls.getPeerNodeSid().getWeight().getValue());
224 assertEquals(new Long(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
225 assertEquals(new Short("5"), ls.getPeerSetSids().get(0).getWeight().getValue());
226 assertEquals(new Long(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
227 assertEquals(new Short("5"), ls.getPeerAdjSid().getWeight().getValue());
230 final ByteBuf buff = Unpooled.buffer();
231 this.parser.serializeAttribute(builder.build(), buff);
233 // there is unresolved TLV at the end, that needs to be cut off
235 assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length -5), ByteArray.getAllBytes(buff));
239 public void testPositiveNodes() throws BGPParsingException {
240 final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
241 this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder);
243 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
244 final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
247 assertEquals(2, ls.getTopologyIdentifier().size());
248 assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
249 assertTrue(ls.getNodeFlags().isOverload());
250 assertFalse(ls.getNodeFlags().isAttached());
251 assertTrue(ls.getNodeFlags().isExternal());
252 assertTrue(ls.getNodeFlags().isAbr());
253 assertTrue(ls.getNodeFlags().isRouter());
254 assertTrue(ls.getNodeFlags().isV6());
256 assertEquals("12K-2", ls.getDynamicHostname());
257 assertEquals(2, ls.getIsisAreaId().size());
258 assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
261 final ByteBuf buff = Unpooled.buffer();
262 this.parser.serializeAttribute(builder.build(), buff);
264 assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
268 public void testPositiveV4Prefixes() throws BGPParsingException {
269 final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
270 new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build());
271 this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
273 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
274 final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
277 assertNotNull(ls.getSrRange());
278 assertFalse(ls.getSrRange().isInterArea());
279 assertEquals(1, ls.getSrRange().getSubTlvs().size());
280 assertNotNull(ls.getSrBindingSidLabels());
281 final IgpBits ispBits = ls.getIgpBits();
282 assertTrue(ispBits.getUpDown().isUpDown());
283 assertTrue(ispBits.isIsIsUpDown());
284 assertTrue(ispBits.isOspfNoUnicast());
285 assertTrue(ispBits.isOspfLocalAddress());
286 assertTrue(ispBits.isOspfPropagateNssa());
287 assertEquals(2, ls.getRouteTags().size());
288 assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0).getValue());
289 assertEquals(1, ls.getExtendedTags().size());
290 assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50,
291 (byte) 0x70 }, ls.getExtendedTags().get(0).getValue());
292 assertEquals(10, ls.getPrefixMetric().getValue().intValue());
293 assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue());
296 final ByteBuf buff = Unpooled.buffer();
297 this.parser.serializeAttribute(builder.build(), buff);
299 // there is unresolved TLV at the end, that needs to be cut off
300 assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
304 public void testPositiveTELspAttribute() throws BGPParsingException {
305 final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
306 this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder);
308 final Attributes1 attrs = builder.getAugmentation(Attributes1.class);
309 final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute()).getTeLspAttributes();
310 assertNotNull(teLspAttributes);
311 final TspecObject tSpec = teLspAttributes.getTspecObject();
312 assertNotNull(tSpec);
313 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}), tSpec.getTokenBucketRate());
314 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}), teLspAttributes.getTspecObject().getTokenBucketSize());
315 assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}), tSpec.getPeakDataRate());
316 assertEquals(new Long("4"), tSpec.getMinimumPolicedUnit());
317 assertEquals(new Long("5"), tSpec.getMaximumPacketSize());
319 final AssociationObject associationObject = teLspAttributes.getAssociationObject();
320 assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
321 final IpAddress ipv4 = new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.copiedBuffer(new byte[]{0x01, 0x02, 0x03, 0x04})));
322 assertEquals(ipv4, associationObject.getIpAddress());
323 final short associationId = 2;
324 assertEquals(associationId, associationObject.getAssociationId().shortValue());
327 final ByteBuf buff = Unpooled.buffer();
328 this.parser.serializeAttribute(builder.build(), buff);
329 assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
330 assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
333 @Test(expected=UnsupportedOperationException.class)
334 public void testLinkAttributesPrivateConstructor() throws Throwable {
335 final Constructor<LinkAttributesParser> c = LinkAttributesParser.class.getDeclaredConstructor();
336 c.setAccessible(true);
339 } catch (final InvocationTargetException e) {
344 @Test(expected=UnsupportedOperationException.class)
345 public void testNodeAttributesPrivateConstructor() throws Throwable {
346 final Constructor<NodeAttributesParser> c = NodeAttributesParser.class.getDeclaredConstructor();
347 c.setAccessible(true);
350 } catch (final InvocationTargetException e) {
355 @Test(expected=UnsupportedOperationException.class)
356 public void testPrefixAttributesPrivateConstructor() throws Throwable {
357 final Constructor<PrefixAttributesParser> c = PrefixAttributesParser.class.getDeclaredConstructor();
358 c.setAccessible(true);
361 } catch (final InvocationTargetException e) {