2 * Copyright (c) 2014 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.pcep.segment.routing;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.pce.capability.tlv.SrPceCapability;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.pce.capability.tlv.SrPceCapabilityBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
22 import org.opendaylight.yangtools.yang.common.Uint8;
24 public class SrTlvParserTest {
26 private static final byte[] SPC_TLV_BYTES = { 0x0, 0x1a, 0x0, 0x4, 0x0, 0x0, 0x3, 0x1 };
28 private static final byte[] SR_TE_PST_BYTES = { 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
31 public void testSrPceCapabilityParser() throws PCEPDeserializerException {
32 final SrPceCapabilityTlvParser parser = new SrPceCapabilityTlvParser();
33 final SrPceCapability spcTlv = new SrPceCapabilityBuilder().setNFlag(Boolean.TRUE).setXFlag(Boolean.TRUE)
34 .setMsd(Uint8.ONE).build();
35 assertEquals(spcTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SPC_TLV_BYTES, 4))));
36 final ByteBuf buff = Unpooled.buffer();
37 parser.serializeTlv(spcTlv, buff);
38 assertArrayEquals(SPC_TLV_BYTES, ByteArray.getAllBytes(buff));
42 public void testPathSetupTypeTlvParser() throws PCEPDeserializerException {
43 final SrPathSetupTypeTlvParser parser = new SrPathSetupTypeTlvParser();
44 final PathSetupType pstTlv = new PathSetupTypeBuilder().setPst(Uint8.ONE).build();
45 assertEquals(pstTlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(SR_TE_PST_BYTES, 4))));
46 final ByteBuf buff = Unpooled.buffer();
47 parser.serializeTlv(pstTlv, buff);
48 assertArrayEquals(SR_TE_PST_BYTES, ByteArray.getAllBytes(buff));