Further migration of test code from legacy setters
[bgpcep.git] / pcep / ietf-stateful07 / src / test / java / org / opendaylight / protocol / pcep / ietf / PCEPTlvParserTest.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.pcep.ietf;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.fail;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.pcep.ietf.stateful07.PathBindingTlvParser;
18 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LSPIdentifierIpv4TlvParser;
19 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LSPIdentifierIpv6TlvParser;
20 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspSymbolicNameTlvParser;
21 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspUpdateErrorTlvParser;
22 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser;
23 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
24 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
25 import org.opendaylight.protocol.pcep.sync.optimizations.SyncOptimizationsCapabilityTlvParser;
26 import org.opendaylight.protocol.util.ByteArray;
27 import org.opendaylight.protocol.util.Ipv4Util;
28 import org.opendaylight.protocol.util.Ipv6Util;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCode;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCodeBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiers;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv4CaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv6CaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4Builder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6Builder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.PathBinding;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.PathBindingBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.path.binding.binding.type.value.MplsLabelBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.path.binding.binding.type.value.MplsLabelEntryBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.RsvpErrorSpec;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.RsvpErrorSpecBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.rsvp.error.spec.error.type.RsvpCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.rsvp.error.spec.error.type.UserCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.rsvp.error.spec.error.type.rsvp._case.RsvpErrorBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.rsvp.error.spec.tlv.rsvp.error.spec.error.type.user._case.UserErrorBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.stateful.capability.tlv.Stateful;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.stateful.capability.tlv.StatefulBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.symbolic.path.name.tlv.SymbolicPathName;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.symbolic.path.name.tlv.SymbolicPathNameBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv6ExtendedTunnelId;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
58 import org.opendaylight.yangtools.yang.common.Uint16;
59 import org.opendaylight.yangtools.yang.common.Uint32;
60 import org.opendaylight.yangtools.yang.common.Uint8;
61
62 public class PCEPTlvParserTest {
63
64     private static final byte[] STATEFUL_BYTES = { 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01 };
65     private static final byte[] STATEFUL_SYNC_OPT_BYTES = new byte[]{ 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x33 };
66     private static final byte[] SYMBOLIC_NAME_BYTES = {
67         0x00, 0x11, 0x00, 0x1C, 0x4d, 0x65, 0x64, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x6f,
68         0x66, 0x20, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x69, 0x63, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x65, 0x65, 0x65
69     };
70     private static final byte[] LSP_UPDATE_ERROR_BYTES = { 0x00, 0x14, 0x00, 0x04, 0x25, 0x68, (byte) 0x95, 0x03 };
71     private static final byte[] LSP_IDENTIFIERS4_BYTES = {
72         0x00, 0x12, 0x00, 0x10, 0x12, 0x34, 0x56, 0x78, (byte) 0xFF, (byte) 0xFF, 0x12,
73         0x34, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78
74     };
75     private static final byte[] LSP_IDENTIFIERS6_BYTES = {
76         0x00, 0x13, 0x00, 0x34, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC,
77         (byte) 0xDE, (byte) 0xF0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, 0x12,
78         0x34, (byte) 0xFF, (byte) 0xFF, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 0x23, 0x45, 0x67, 0x01,
79         0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, 0x12, 0x34, 0x56,
80         0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0
81     };
82     private static final byte[] RSVP_ERROR_BYTES = {
83         0x00, 0x15, 0x00, 0x0c, 0, 0x0c, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16, 0x02
84     };
85     private static final byte[] RSVP_ERROR6_BYTES = {
86         0x00, 0x15, 0x00, 0x18, 0, 0x18, 0x06, 0x02, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde,
87         (byte) 0xf0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, 0x02, (byte) 0xd5,
88         (byte) 0xc5, (byte) 0xd9
89     };
90     private static final byte[] USER_ERROR_BYTES = {
91         0x00, 0x15, 0x00, 0x18, 0, 0x18, (byte) 0xc2, 0x01, 0x00, 0x00, 0x30, 0x39, 0x05, 0x09, 0x00,
92         0x26, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x73, 0x63, 0, 0, 0
93     };
94
95     @Test
96     public void testStatefulTlv() throws PCEPDeserializerException {
97         final Stateful07StatefulCapabilityTlvParser parser = new Stateful07StatefulCapabilityTlvParser();
98         final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).build();
99         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(STATEFUL_BYTES, 4))));
100         final ByteBuf buff = Unpooled.buffer();
101         parser.serializeTlv(tlv, buff);
102         assertArrayEquals(STATEFUL_BYTES, ByteArray.getAllBytes(buff));
103     }
104
105     @Test
106     public void testStatefulTlvSyncOptimizationExtension() throws PCEPDeserializerException {
107         final SyncOptimizationsCapabilityTlvParser parser = new SyncOptimizationsCapabilityTlvParser();
108         final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE)
109             .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
110                 .optimizations.rev181109.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
111                     .ns.yang.controller.pcep.sync.optimizations.rev181109.Stateful1Builder()
112                     .setTriggeredInitialSync(Boolean.TRUE)
113                     .setDeltaLspSyncCapability(Boolean.TRUE)
114                     .setIncludeDbVersion(Boolean.TRUE)
115                     .build())
116             .build();
117         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(STATEFUL_SYNC_OPT_BYTES, 4))));
118         final ByteBuf buff = Unpooled.buffer();
119         parser.serializeTlv(tlv, buff);
120         assertArrayEquals(STATEFUL_SYNC_OPT_BYTES, ByteArray.getAllBytes(buff));
121     }
122
123     @Test
124     public void testSymbolicNameTlv() throws PCEPDeserializerException {
125         final Stateful07LspSymbolicNameTlvParser parser = new Stateful07LspSymbolicNameTlvParser();
126         final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
127             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109
128                 .SymbolicPathName("Med test of symbolic nameeee".getBytes())).build();
129         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SYMBOLIC_NAME_BYTES, 4))));
130         final ByteBuf buff = Unpooled.buffer();
131         parser.serializeTlv(tlv, buff);
132         assertArrayEquals(SYMBOLIC_NAME_BYTES, ByteArray.getAllBytes(buff));
133     }
134
135     @Test
136     public void testLspErrorCodeTlv() throws PCEPDeserializerException {
137         final Stateful07LspUpdateErrorTlvParser parser = new Stateful07LspUpdateErrorTlvParser();
138         final LspErrorCode tlv = new LspErrorCodeBuilder().setErrorCode(Uint32.valueOf(627610883)).build();
139         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(LSP_UPDATE_ERROR_BYTES, 4))));
140         final ByteBuf buff = Unpooled.buffer();
141         parser.serializeTlv(tlv, buff);
142         assertArrayEquals(LSP_UPDATE_ERROR_BYTES, ByteArray.getAllBytes(buff));
143     }
144
145     @Test
146     public void testLspIdentifiers4Tlv() throws PCEPDeserializerException {
147         final Stateful07LSPIdentifierIpv4TlvParser parser = new Stateful07LSPIdentifierIpv4TlvParser();
148         final Ipv4Builder afi = new Ipv4Builder();
149         afi.setIpv4TunnelSenderAddress(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
150             new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
151         afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.noZoneAddressForByteBuf(
152             Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
153         afi.setIpv4TunnelEndpointAddress(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
154             new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
155         final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(
156             new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(new LspId(Uint32.valueOf(65535)))
157                 .setTunnelId(new TunnelId(Uint16.valueOf(4660))).build();
158         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(LSP_IDENTIFIERS4_BYTES, 4))));
159         final ByteBuf buff = Unpooled.buffer();
160         parser.serializeTlv(tlv, buff);
161         assertArrayEquals(LSP_IDENTIFIERS4_BYTES, ByteArray.getAllBytes(buff));
162     }
163
164     @Test
165     public void testLspIdentifiers6Tlv() throws PCEPDeserializerException {
166         final Stateful07LSPIdentifierIpv6TlvParser parser = new Stateful07LSPIdentifierIpv6TlvParser();
167         final Ipv6Builder afi = new Ipv6Builder();
168         afi.setIpv6TunnelSenderAddress(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
169             new byte[] {
170                 (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
171                 (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
172                 (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0
173             })));
174         afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
175             new byte[] {
176                 (byte) 0x12, (byte) 0x34, (byte) 0x56,
177                 (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45,
178                 (byte) 0x67, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67
179             }))));
180         afi.setIpv6TunnelEndpointAddress(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
181             new byte[] {
182                 (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
183                 (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
184                 (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0
185             })));
186         final LspIdentifiers tlv = new LspIdentifiersBuilder()
187                 .setAddressFamily(new Ipv6CaseBuilder().setIpv6(afi.build()).build())
188                 .setLspId(new LspId(Uint32.valueOf(4660))).setTunnelId(new TunnelId(Uint16.MAX_VALUE)).build();
189         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(LSP_IDENTIFIERS6_BYTES, 4))));
190         final ByteBuf buff = Unpooled.buffer();
191         parser.serializeTlv(tlv, buff);
192         assertArrayEquals(LSP_IDENTIFIERS6_BYTES, ByteArray.getAllBytes(buff));
193     }
194
195     @Test
196     public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
197         final Stateful07RSVPErrorSpecTlvParser parser = new Stateful07RSVPErrorSpecTlvParser();
198         final RsvpErrorBuilder builder = new RsvpErrorBuilder()
199                 .setNode(new IpAddressNoZone(Ipv4Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(
200                     new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))))
201                 .setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec
202                     .Flags(false, true))
203                 .setCode(Uint8.valueOf(146))
204                 .setValue(Uint16.valueOf(5634));
205         final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder()
206                 .setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
207         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(RSVP_ERROR_BYTES, 4))));
208         final ByteBuf buff = Unpooled.buffer();
209         parser.serializeTlv(tlv, buff);
210         assertArrayEquals(RSVP_ERROR_BYTES, ByteArray.getAllBytes(buff));
211     }
212
213     @Test
214     public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
215         final Stateful07RSVPErrorSpecTlvParser parser = new Stateful07RSVPErrorSpecTlvParser();
216         final RsvpErrorBuilder builder = new RsvpErrorBuilder()
217                 .setNode(new IpAddressNoZone(Ipv6Util.noZoneAddressForByteBuf(Unpooled.wrappedBuffer(new byte[] {
218                     (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
219                     (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56,
220                     (byte) 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0
221                 }))))
222                 .setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec
223                     .Flags(false, true))
224                 .setCode(Uint8.valueOf(213))
225                 .setValue(Uint16.valueOf(50649));
226         final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder()
227                 .setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
228         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(RSVP_ERROR6_BYTES, 4))));
229         final ByteBuf buff = Unpooled.buffer();
230         parser.serializeTlv(tlv, buff);
231         assertArrayEquals(RSVP_ERROR6_BYTES, ByteArray.getAllBytes(buff));
232     }
233
234     @Test
235     public void testUserErrorSpecTlv() throws PCEPDeserializerException {
236         final Stateful07RSVPErrorSpecTlvParser parser = new Stateful07RSVPErrorSpecTlvParser();
237         final UserErrorBuilder builder = new UserErrorBuilder()
238                 .setEnterprise(new EnterpriseNumber(Uint32.valueOf(12345)))
239                 .setSubOrg(Uint8.valueOf(5))
240                 .setValue(Uint16.valueOf(38))
241                 .setDescription("user desc");
242         final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder()
243                 .setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
244         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(USER_ERROR_BYTES, 4))));
245         final ByteBuf buff = Unpooled.buffer();
246         parser.serializeTlv(tlv, buff);
247         assertArrayEquals(USER_ERROR_BYTES, ByteArray.getAllBytes(buff));
248     }
249
250     @Test
251     public void testPathBindingTlvMplsLabel() {
252         final byte[] pathBindingBytes = {
253             0x00, 0x1f, 0x00, 0x06, 0x00, 0x00, (byte) 0xA8, 0x0F, (byte) 0x60, 0x00, 0x00, 0x00
254         };
255         final PathBindingTlvParser parser = new PathBindingTlvParser();
256         final PathBindingBuilder builder = new PathBindingBuilder();
257         builder.setBindingTypeValue(new MplsLabelBuilder().setMplsLabel(new MplsLabel(Uint32.valueOf(688374))).build());
258         final ByteBuf buff = Unpooled.buffer();
259         parser.serializeTlv(builder.build(), buff);
260         assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
261
262         try {
263             final byte[] wrong = {0, 0x1f, 0, 4, 1, 1, 2, 3};
264             parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(wrong, 4)));
265             fail();
266         } catch (final PCEPDeserializerException e) {
267             assertEquals("Unsupported Path Binding Type: 257", e.getMessage());
268         }
269     }
270
271     @Test
272     public void testPathBindingTlvMplsLabelEntry() {
273         final byte[] pathBindingBytes = {
274             0x00, 0x1f, 0x00, 0x06, 0x00, 0x01, (byte) 0xA8, (byte) 0x0F, (byte) 0x6D, (byte)0xAD, 0x00, 0x00
275         };
276         final PathBindingTlvParser parser = new PathBindingTlvParser();
277         final PathBindingBuilder builder = new PathBindingBuilder();
278         builder.setBindingTypeValue(new MplsLabelEntryBuilder()
279             .setTrafficClass(Uint8.valueOf(6))
280             .setTimeToLive(Uint8.valueOf(173))
281             .setBottomOfStack(true)
282             .setLabel(new MplsLabel(Uint32.valueOf(688374))).build());
283         final PathBinding tlv = builder.build();
284         final ByteBuf buff = Unpooled.buffer();
285         parser.serializeTlv(tlv, buff);
286         assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
287     }
288 }