Cleanup deprecation warnings in bgp/extensions/linkstate
[bgpcep.git] / bgp / extensions / linkstate / src / test / java / org / opendaylight / protocol / bgp / linkstate / LinkstateAttributeParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.linkstate;
9
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
16 import com.google.common.collect.Lists;
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import java.util.Arrays;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser;
23 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
24 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
25 import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator;
26 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
27 import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
28 import org.opendaylight.protocol.util.ByteArray;
29 import org.opendaylight.protocol.util.Ipv4Util;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
33 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;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkProtectionType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkstateSubsequentAddressFamily;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.ObjectType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.destination.CLinkstateDestinationBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.LinkCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.NodeCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.PrefixCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.TeLspCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.TeLspAttributesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.te.lsp.attributes._case.TeLspAttributes;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.IgpBits;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.IsisAdjFlagsCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.IsisAdjFlagsCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.adj.flags.flags.isis.adj.flags._case.IsisAdjFlagsBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.LocalLabelCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AssociationType;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.association.object.AssociationObject;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.tspec.object.TspecObject;
73 import org.opendaylight.yangtools.yang.common.Uint32;
74 import org.opendaylight.yangtools.yang.common.Uint8;
75
76 public class LinkstateAttributeParserTest {
77
78     private static final byte[] TE_LSP_ATTR = {
79         0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value
80         0x00, (byte) 0x20, (byte) 0x0c, 0x02,  // Length, 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,  // Length, Class, Ctype
90         0x00, 0x01, 0x00, 0x02,
91         0x01, 0x02, 0x03, 0x04
92     };
93
94     private static final byte[] LINK_ATTR = {
95         0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, 0x04, 0x40, 0, 0x04,
96         0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, 0x46, 0x43,
97         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,
98         0, 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,
99         0x04, 0x46, 0, 0x01, (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
100         0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32,
101         0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj
102         0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj
103         0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj
104         0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-lan-adj
105         0x04, 0x4d, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, // peer-node-sid
106         0x04, 0x4e, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0f, // peer-adj-sid
107         0x04, 0x4f, 0, 0x08, 0, 0x05, 0, 0, 0x0a, 0x0b, 0x0c, 0x0e, // peer-set-sid
108         // Performace Metrics
109         0x04, 0x5a, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay
110         0x04, 0x5b, 0, 0x08, 0, 0, 0x13, (byte)0x88, 0, 0, 0x4e, 0x20, // Link Min-Max Delay
111         0x04, 0x5c, 0, 0x04, 0, 0, 0x27, 0x10, // Link Delay Variation
112         0x04, 0x5d, 0, 0x04, 0, 0, 0, 0, // Link Loss
113         0x04, 0x5e, 0, 0x04, 0x46, 0x43, 0x50, 0, // Residual Bandwidth
114         0x04, 0x5f, 0, 0x04, 0x46, 0x43, 0x50, 0, // Available Bandwidth
115         0x04, 0x60, 0, 0x04, 0, 0, 0, 0,  // Utilized Bandwidth
116         0x04, (byte) 0x88, 0, 0x01, 0x0a
117     };
118
119     private static final byte[] NODE_ATTR = {
120         0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
121         0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
122         0x04, (byte) 0x88, 0, 0x01, 0x0a,
123         4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
124         4, 0x0b, 0, 2, 0, 1 // sr-algorythms
125     };
126
127     private static final byte[] NODE_ATTR_S = {
128         0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b,
129         0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29,
130         4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps
131         4, 0x0b, 0, 2, 0, 1 // sr-algorythms
132     };
133
134     private static final byte[] P4_ATTR = {
135         0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78,
136         0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70,
137         0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b,
138         4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv
139         4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv
140         4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv
141     };
142
143     private RSVPExtensionProviderContext context;
144     private RSVPActivator rsvpActivator;
145     private LinkstateAttributeParser parser;
146
147     @Before
148     public final void setUp() {
149         this.context = new SimpleRSVPExtensionProviderContext();
150         this.rsvpActivator = new RSVPActivator();
151         this.rsvpActivator.start(this.context);
152         this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry());
153     }
154
155     private static AttributesBuilder createBuilder(final ObjectType type) {
156         return new AttributesBuilder().addAugmentation(new Attributes1Builder()
157             .setMpReachNlri(new MpReachNlriBuilder()
158                 .setAfi(LinkstateAddressFamily.class)
159                 .setSafi(LinkstateSubsequentAddressFamily.class)
160                 .setAdvertizedRoutes(new AdvertizedRoutesBuilder()
161                     .setDestinationType(new DestinationLinkstateCaseBuilder()
162                         .setDestinationLinkstate(new DestinationLinkstateBuilder()
163                             .setCLinkstateDestination(Lists.newArrayList(new CLinkstateDestinationBuilder()
164                                 .setObjectType(type)
165                                 .setProtocolId(ProtocolId.IsisLevel1)
166                                 .build()))
167                             .build())
168                         .build())
169                     .build())
170                 .build())
171             .build());
172     }
173
174     private static AttributesBuilder createUnreachBuilder(final ObjectType type) {
175         return new AttributesBuilder().addAugmentation(new Attributes2Builder()
176             .setMpUnreachNlri(new MpUnreachNlriBuilder()
177                 .setAfi(LinkstateAddressFamily.class)
178                 .setSafi(LinkstateSubsequentAddressFamily.class)
179                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder()
180                     .setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
181                         .linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
182                         .DestinationLinkstateCaseBuilder()
183                             .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns
184                                 .yang.bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes
185                                 .destination.type.destination.linkstate._case.DestinationLinkstateBuilder()
186                                     .setCLinkstateDestination(Lists.newArrayList(new CLinkstateDestinationBuilder()
187                                         .setObjectType(type)
188                                         .setProtocolId(ProtocolId.IsisLevel1)
189                                         .build()))
190                                     .build())
191                             .build())
192                     .build())
193                 .build())
194             .build());
195     }
196
197     @Test
198     public void testGetNlriType() throws BGPParsingException, BGPDocumentedException {
199         final ByteBuf b = Unpooled.buffer();
200         AttributesBuilder builder = new AttributesBuilder();
201         this.parser.parseAttribute(b, builder, null);
202         assertEquals(0, b.readableBytes());
203         builder = new AttributesBuilder();
204
205         final Attributes1Builder builder1 = new Attributes1Builder();
206         builder.addAugmentation(builder1.build());
207         this.parser.parseAttribute(b, builder, null);
208         assertEquals(0, b.readableBytes());
209         builder = new AttributesBuilder();
210
211         builder.addAugmentation(builder1
212             .setMpReachNlri(new MpReachNlriBuilder()
213                 .setAdvertizedRoutes(new AdvertizedRoutesBuilder()
214                     .setDestinationType(new DestinationIpv4CaseBuilder().build())
215                     .build())
216                 .build())
217             .build());
218         this.parser.parseAttribute(b, builder, null);
219         assertEquals(0, b.readableBytes());
220         builder = new AttributesBuilder();
221
222         final Attributes2Builder builder2 = new Attributes2Builder();
223         builder.addAugmentation(builder2.build());
224         this.parser.parseAttribute(b, builder, null);
225         assertEquals(0, b.readableBytes());
226         builder = new AttributesBuilder();
227
228         builder.addAugmentation(builder2
229             .setMpUnreachNlri(new MpUnreachNlriBuilder()
230                 .setWithdrawnRoutes(new WithdrawnRoutesBuilder()
231                     .setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
232                         .rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
233                         .DestinationIpv6CaseBuilder().build())
234                     .build())
235                 .build())
236             .build());
237         this.parser.parseAttribute(b, builder, null);
238         assertEquals(0, b.readableBytes());
239     }
240
241     @Test
242     public void testPositiveLinks() throws BGPParsingException, BGPDocumentedException {
243         final AttributesBuilder builder = createBuilder(new LinkCaseBuilder().build());
244         this.parser.parseAttribute(Unpooled.copiedBuffer(LINK_ATTR), builder, null);
245         final Attributes1 attrs = builder.augmentation(Attributes1.class);
246         final LinkAttributes ls = ((LinkAttributesCase) attrs.getLinkStateAttribute()).getLinkAttributes();
247         assertNotNull(ls);
248
249         assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
250         assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
251         assertEquals(Uint32.ZERO, ls.getAdminGroup().getValue());
252         assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
253             ls.getMaxLinkBandwidth().getValue());
254         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
255             ls.getMaxReservableBandwidth().getValue());
256         assertNotNull(ls.getUnreservedBandwidth());
257         assertEquals(8, ls.getUnreservedBandwidth().size());
258         assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection());
259         assertTrue(ls.getMplsProtocol().isLdp());
260         assertTrue(ls.getMplsProtocol().isRsvpte());
261         assertEquals(Uint32.TEN, ls.getMetric().getValue());
262         assertEquals(2, ls.getSharedRiskLinkGroups().size());
263         assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue());
264         assertEquals("12K-2", ls.getLinkName());
265         final IsisAdjFlagsCase flags = new IsisAdjFlagsCaseBuilder()
266                 .setIsisAdjFlags(new IsisAdjFlagsBuilder()
267                     .setAddressFamily(Boolean.TRUE)
268                     .setBackup(Boolean.FALSE)
269                     .setSet(Boolean.FALSE)
270                     .build())
271                 .build();
272         assertEquals(flags, ls.getSrAdjIds().get(0).getFlags());
273         assertEquals(flags, ls.getSrAdjIds().get(1).getFlags());
274         assertEquals(Uint32.valueOf(1048575L),
275             ((LocalLabelCase)ls.getSrAdjIds().get(0).getSidLabelIndex()).getLocalLabel().getValue());
276         assertEquals(Uint32.valueOf(1048559L),
277             ((LocalLabelCase)ls.getSrAdjIds().get(1).getSidLabelIndex()).getLocalLabel().getValue());
278         assertEquals(Uint32.valueOf(168496141L), ((SidCase) ls.getPeerNodeSid().getSidLabelIndex()).getSid());
279         assertEquals(Uint8.valueOf(5), ls.getPeerNodeSid().getWeight().getValue());
280         assertEquals(Uint32.valueOf(168496142L), ((SidCase) ls.getPeerSetSids().get(0).getSidLabelIndex()).getSid());
281         assertEquals(Uint8.valueOf(5), ls.getPeerSetSids().get(0).getWeight().getValue());
282         assertEquals(Uint32.valueOf(168496143L), ((SidCase) ls.getPeerAdjSid().getSidLabelIndex()).getSid());
283         assertEquals(Uint8.valueOf(5), ls.getPeerAdjSid().getWeight().getValue());
284
285         // Performance Metrics
286         assertEquals(Uint32.valueOf(10000L), ls.getLinkDelay().getValue());
287         assertEquals(Uint32.valueOf(5000L), ls.getLinkMinMaxDelay().getMinDelay().getValue());
288         assertEquals(Uint32.valueOf(20000L), ls.getLinkMinMaxDelay().getMaxDelay().getValue());
289         assertEquals(Uint32.valueOf(10000L), ls.getDelayVariation().getValue());
290         assertEquals(Uint32.ZERO, ls.getLinkLoss().getValue());
291         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
292                 ls.getResidualBandwidth().getValue());
293         assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
294                 ls.getAvailableBandwidth().getValue());
295         assertArrayEquals(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 },
296                 ls.getUtilizedBandwidth().getValue());
297
298         //serialization
299         final ByteBuf buff = Unpooled.buffer();
300         this.parser.serializeAttribute(builder.build(), buff);
301         // The LINK_ATTR buffer is now greater than 255 bytes. Need to skip one more byte
302         buff.skipBytes(4);
303         // there is unresolved TLV at the end, that needs to be cut off
304
305         assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff));
306     }
307
308     @Test
309     public void testPositiveNodes() throws BGPParsingException, BGPDocumentedException {
310         final AttributesBuilder builder = createBuilder(new NodeCaseBuilder().build());
311         this.parser.parseAttribute(Unpooled.copiedBuffer(NODE_ATTR), builder, null);
312
313         final Attributes1 attrs = builder.augmentation(Attributes1.class);
314         final NodeAttributes ls = ((NodeAttributesCase) attrs.getLinkStateAttribute()).getNodeAttributes();
315         assertNotNull(ls);
316
317         assertEquals(2, ls.getTopologyIdentifier().size());
318         assertEquals(42, ls.getTopologyIdentifier().get(0).getValue().intValue());
319         assertTrue(ls.getNodeFlags().isOverload());
320         assertFalse(ls.getNodeFlags().isAttached());
321         assertTrue(ls.getNodeFlags().isExternal());
322         assertTrue(ls.getNodeFlags().isAbr());
323         assertTrue(ls.getNodeFlags().isRouter());
324         assertTrue(ls.getNodeFlags().isV6());
325
326         assertEquals("12K-2", ls.getDynamicHostname());
327         assertEquals(2, ls.getIsisAreaId().size());
328         assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
329
330         //serialization
331         final ByteBuf buff = Unpooled.buffer();
332         this.parser.serializeAttribute(builder.build(), buff);
333         buff.skipBytes(3);
334         assertArrayEquals(NODE_ATTR_S, ByteArray.getAllBytes(buff));
335     }
336
337     @Test
338     public void testPositiveV4Prefixes() throws BGPParsingException, BGPDocumentedException {
339         final AttributesBuilder builder = createUnreachBuilder(new PrefixCaseBuilder().setPrefixDescriptors(
340             new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32")))
341             .build()).build());
342         this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder, null);
343
344         final Attributes1 attrs = builder.augmentation(Attributes1.class);
345         final PrefixAttributes ls = ((PrefixAttributesCase) attrs.getLinkStateAttribute()).getPrefixAttributes();
346         assertNotNull(ls);
347
348         assertNotNull(ls.getSrRange());
349         assertFalse(ls.getSrRange().isInterArea());
350         assertEquals(1, ls.getSrRange().getSubTlvs().size());
351         assertNotNull(ls.getSrBindingSidLabels());
352         final IgpBits ispBits = ls.getIgpBits();
353         assertTrue(ispBits.getUpDown().isUpDown());
354         assertTrue(ispBits.isIsIsUpDown());
355         assertTrue(ispBits.isOspfNoUnicast());
356         assertTrue(ispBits.isOspfLocalAddress());
357         assertTrue(ispBits.isOspfPropagateNssa());
358         assertEquals(2, ls.getRouteTags().size());
359         assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0)
360             .getValue());
361         assertEquals(1, ls.getExtendedTags().size());
362         assertArrayEquals(new byte[] {
363             (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70
364         }, ls.getExtendedTags().get(0).getValue());
365         assertEquals(10, ls.getPrefixMetric().getValue().intValue());
366         assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4AddressNoZone().getValue());
367
368         //serialization
369         final ByteBuf buff = Unpooled.buffer();
370         this.parser.serializeAttribute(builder.build(), buff);
371         buff.skipBytes(3);
372         // there is unresolved TLV at the end, that needs to be cut off
373         assertArrayEquals(P4_ATTR, ByteArray.getAllBytes(buff));
374     }
375
376     @Test
377     public void testPositiveTELspAttribute() throws BGPParsingException, BGPDocumentedException {
378         final AttributesBuilder builder = createBuilder(new TeLspCaseBuilder().build());
379         this.parser.parseAttribute(Unpooled.copiedBuffer(TE_LSP_ATTR), builder, null);
380
381         final Attributes1 attrs = builder.augmentation(Attributes1.class);
382         final TeLspAttributes teLspAttributes = ((TeLspAttributesCase) attrs.getLinkStateAttribute())
383                 .getTeLspAttributes();
384         assertNotNull(teLspAttributes);
385         final TspecObject tSpec = teLspAttributes.getTspecObject();
386         assertNotNull(tSpec);
387         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01}),
388             tSpec.getTokenBucketRate());
389         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02}),
390             teLspAttributes.getTspecObject().getTokenBucketSize());
391         assertEquals(new Float32(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03}),
392             tSpec.getPeakDataRate());
393         assertEquals(Uint32.valueOf(4), tSpec.getMinimumPolicedUnit());
394         assertEquals(Uint32.valueOf(5), tSpec.getMaximumPacketSize());
395
396         final AssociationObject associationObject = teLspAttributes.getAssociationObject();
397         assertEquals(AssociationType.Recovery, associationObject.getAssociationType());
398         final IpAddressNoZone ipv4 = new IpAddressNoZone(Ipv4Util.addressForByteBuf(Unpooled.copiedBuffer(
399             new byte[]{0x01, 0x02, 0x03, 0x04})));
400         assertEquals(ipv4, associationObject.getIpAddress());
401         final short associationId = 2;
402         assertEquals(associationId, associationObject.getAssociationId().shortValue());
403
404         //serialization
405         final ByteBuf buff = Unpooled.buffer();
406         this.parser.serializeAttribute(builder.build(), buff);
407         assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff));
408         assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)));
409     }
410 }