BUG-2738 : fixed path setup tlv type
[bgpcep.git] / pcep / segment-routing / src / test / java / org / opendaylight / protocol / pcep / segment / routing / SrTlvParserTest.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.protocol.pcep.segment.routing;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.sr.pce.capability.tlv.SrPceCapability;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.sr.pce.capability.tlv.SrPceCapabilityBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
23
24 public class SrTlvParserTest {
25
26     private static final byte[] SPC_TLV_BYTES = { 0x0, 0x1a, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
27
28     private static final byte[] SR_TE_PST_BYTES = { 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
29
30     @Test
31     public void testSrPceCapabilityParser() throws PCEPDeserializerException {
32         final SrPceCapabilityTlvParser parser = new SrPceCapabilityTlvParser();
33         final SrPceCapability spcTlv = new SrPceCapabilityBuilder().setMsd((short) 1).build();
34         assertEquals(spcTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SPC_TLV_BYTES, 4))));
35         final ByteBuf buff = Unpooled.buffer();
36         parser.serializeTlv(spcTlv, buff);
37         assertArrayEquals(SPC_TLV_BYTES, ByteArray.getAllBytes(buff));
38     }
39
40     @Test
41     public void testPathSetupTypeTlvParser() throws PCEPDeserializerException {
42         final SrPathSetupTypeTlvParser parser = new SrPathSetupTypeTlvParser();
43         final PathSetupType pstTlv = new PathSetupTypeBuilder().setPst((short) 1).build();
44         assertEquals(pstTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SR_TE_PST_BYTES, 4))));
45         final ByteBuf buff = Unpooled.buffer();
46         parser.serializeTlv(pstTlv, buff);
47         assertArrayEquals(SR_TE_PST_BYTES, ByteArray.getAllBytes(buff));
48     }
49
50 }