Disable to create duplicate (with same IP Address) PCEP sessions.
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / PCCMockTest.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.pcc.mock;
10
11 import io.netty.buffer.Unpooled;
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
19 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
24
25
26
27 public class PCCMockTest {
28
29     @Test
30     public void testSessionEstablishment() {
31         try {
32             org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.1.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
33             Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.1.0", "--pcc", "2", "--lsp", "1", "--log-level", "DEBUG", "-ka", "10", "-d", "0",});
34         } catch (Exception e) {
35             Assert.fail(e.getMessage());
36         }
37     }
38
39     @Test
40     public void testMockPCCToManyPCE() {
41         try {
42             org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.4.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
43             org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.2.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
44             org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.3.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
45             Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.4.0,127.0.2.0,127.0.3.0", "--pcc", "3"});
46         } catch (Exception e) {
47             Assert.fail(e.getMessage());
48         }
49     }
50
51     @Test
52     public void testSrpObjectParser() throws PCEPDeserializerException {
53         final byte[] bytes = {
54             0x00, 0x00, 0x00, 0x00,
55             0x00, 0x00, 0x00, 0x00,
56         };
57         final PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
58         final PCCSrpObjectParser parser = new PCCSrpObjectParser(ctx.getTlvHandlerRegistry(), ctx.getVendorInformationTlvRegistry());
59         final Srp srp = new SrpBuilder().setIgnore(true).setProcessingRule(true).setOperationId(new SrpIdNumber(0L)).setTlvs(new TlvsBuilder().build()).build();
60         Assert.assertEquals(srp, parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.wrappedBuffer(bytes)));
61     }
62
63     @Test(expected=UnsupportedOperationException.class)
64     public void testPrivateConstructor() throws Throwable {
65         final Constructor<MsgBuilderUtil> c = MsgBuilderUtil.class.getDeclaredConstructor();
66         c.setAccessible(true);
67         try {
68             c.newInstance();
69         } catch (InvocationTargetException e) {
70             throw e.getCause();
71         }
72     }
73
74 }