Added cleanup tlv to session proposal.
[bgpcep.git] / pcep / ietf-stateful02 / src / test / java / org / opendaylight / protocol / pcep / ietf / PCEPObjectParserTest.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
12 import java.io.IOException;
13
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.ietf.stateful02.PCEPOpenObjectParser;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
19 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
20 import org.opendaylight.protocol.util.ByteArray;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1Builder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs1Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanupBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.StatefulBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
32
33 public class PCEPObjectParserTest {
34
35         private TlvHandlerRegistry tlvRegistry;
36
37         @Before
38         public void setUp() throws Exception {
39                 this.tlvRegistry = ServiceLoaderPCEPExtensionProviderContext.create().getTlvHandlerRegistry();
40         }
41
42         @Test
43         public void testOpenObjectWithTLV() throws PCEPDeserializerException, IOException {
44                 final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry);
45                 final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin");
46
47                 final OpenBuilder builder = new OpenBuilder();
48                 builder.setProcessingRule(false);
49                 builder.setIgnore(false);
50                 builder.setVersion(new ProtocolVersion((short) 1));
51                 builder.setKeepalive((short) 30);
52                 builder.setDeadTimer((short) 120);
53                 builder.setSessionId((short) 1);
54
55                 final Stateful tlv1 = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).setIncludeDbVersion(Boolean.FALSE).addAugmentation(
56                                 Stateful1.class, new Stateful1Builder().setInitiation(true).build()).build();
57
58                 final Tlvs2Builder statBuilder = new Tlvs2Builder();
59                 statBuilder.setStateful(tlv1);
60
61                 final Tlvs1Builder cleanupBuilder = new Tlvs1Builder();
62                 cleanupBuilder.setLspCleanup(new LspCleanupBuilder().setTimeout(180L).build());
63
64                 builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().addAugmentation(
65                                 Tlvs2.class, statBuilder.build()).addAugmentation(Tlvs1.class, cleanupBuilder.build()).build());
66
67                 // FIXME: enable once the registry is rewritten
68                 // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
69                 // ByteArray.cutBytes(result, 4)));
70                 // assertArrayEquals(result, parser.serializeObject(builder.build()));
71         }
72
73         @Test
74         public void testLspObjectWithTLV() throws IOException, PCEPDeserializerException {
75                 // final PCEPLspObjectParser parser = new PCEPLspObjectParser(this.tlvRegistry);
76                 // final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLspObject1WithTLV.bin");
77                 //
78                 // final LspBuilder builder = new LspBuilder();
79                 // builder.setProcessingRule(true);
80                 // builder.setIgnore(true);
81                 // builder.setDelegate(false);
82                 // builder.setRemove(true);
83                 // builder.setSync(false);
84                 //
85                 // final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
86                 // final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName(
87                 // new
88                 // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med".getBytes())).build();
89                 // builder.setTlvs(new
90                 // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspErrorCode(
91                 // tlv1).setSymbolicPathName(tlv2).build());
92                 // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
93                 // 4)));
94                 // assertArrayEquals(result, parser.serializeObject(builder.build()));
95         }
96 }