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