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.controller.config.yang.pcep.tunnel.provider;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12 import io.netty.channel.nio.NioEventLoopGroup;
13 import java.util.Arrays;
14 import java.util.List;
15 import javax.management.ObjectName;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.config.api.ValidationException;
19 import org.opendaylight.controller.config.api.jmx.CommitStatus;
20 import org.opendaylight.controller.config.spi.ModuleFactory;
21 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
22 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
23 import org.opendaylight.controller.config.yang.pcep.impl.PCEPDispatcherImplModuleFactory;
24 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleFactory;
25 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleMXBean;
26 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleTest;
27 import org.opendaylight.controller.config.yang.pcep.topology.provider.Stateful07TopologySessionListenerModuleFactory;
28 import org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSchedulerTest;
29 import org.opendaylight.protocol.pcep.PCEPDispatcher;
30 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
31 import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
32 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
33 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
34 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
35 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
36 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
39 public class PCEPTunnelTopologyProviderModuleTest extends AbstractInstructionSchedulerTest {
41 private static final String FACTORY_NAME = PCEPTunnelTopologyProviderModuleFactory.NAME;
42 private static final String INSTANCE_NAME = "pcep-tunnel-topology-provider-instance";
44 private static final TopologyId TOPOLOGY_ID = new TopologyId("pcep-topology");
48 public void setUp() throws Exception {
51 SimplePCEPExtensionProviderContext extContext = new SimplePCEPExtensionProviderContext();
52 setupMockService(PCEPExtensionProviderContext.class, extContext);
53 BasePCEPSessionProposalFactory proposalFactory = new BasePCEPSessionProposalFactory(120, 30,
54 Arrays.asList(new PCEPStatefulCapability(true, true, true, true, true, true, true)));
55 setupMockService(PCEPSessionProposalFactory.class, proposalFactory);
56 NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup();
57 setupMockService(PCEPDispatcher.class, new PCEPDispatcherImpl(extContext.getMessageHandlerRegistry(),
58 new DefaultPCEPSessionNegotiatorFactory(proposalFactory, 5), eventLoopGroup, eventLoopGroup));
62 public void testValidationExceptionTopologyIdNotSet() throws Exception {
66 } catch (final ValidationException e) {
67 assertTrue(e.getMessage().contains("TopologyId is not set"));
72 public void testCreateBean() throws Exception {
73 final CommitStatus status = createInstance();
74 assertBeanCount(1, FACTORY_NAME);
75 assertStatus(status, 14, 0, 0);
79 public void testReusingOldInstance() throws Exception {
81 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
82 assertBeanCount(1, FACTORY_NAME);
83 final CommitStatus status = transaction.commit();
84 assertBeanCount(1, FACTORY_NAME);
85 assertStatus(status, 0, 0, 14);
89 public void testReconfigure() throws Exception {
91 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
92 assertBeanCount(1, FACTORY_NAME);
93 final PCEPTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(
94 transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), PCEPTopologyProviderModuleMXBean.class);
95 mxBean.setTopologyId(new TopologyId("new-pcep-topology"));
96 final CommitStatus status = transaction.commit();
97 assertBeanCount(1, FACTORY_NAME);
98 assertStatus(status, 0, 1, 13);
101 private CommitStatus createInstance(final TopologyId topologyId) throws Exception {
102 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
103 createPCEPTopologyProviderModuleInstance(transaction, topologyId);
104 return transaction.commit();
107 private CommitStatus createInstance() throws Exception {
108 return createInstance(TOPOLOGY_ID);
111 private ObjectName createPCEPTopologyProviderModuleInstance(final ConfigTransactionJMXClient transaction, final TopologyId topologyId)
113 final ObjectName objectName = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
114 final ObjectName asyncDataBrokerON = createAsyncDataBrokerInstance(transaction);
115 final ObjectName dataBrokerON = createCompatibleDataBrokerInstance(transaction);
116 final ObjectName notificationBrokerON = createNotificationBrokerInstance(transaction);
117 final ObjectName bindingBrokerON = createBindingBrokerImpl(transaction, dataBrokerON, notificationBrokerON);
118 final ObjectName schedulerON = createInstructionSchedulerModuleInstance(transaction, asyncDataBrokerON, bindingBrokerON,
119 notificationBrokerON);
120 final ObjectName sourceTopology = PCEPTopologyProviderModuleTest.createPCEPTopologyProviderModuleInstance(transaction,
121 asyncDataBrokerON, bindingBrokerON, schedulerON);
123 final PCEPTunnelTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(objectName,
124 PCEPTunnelTopologyProviderModuleMXBean.class);
125 mxBean.setDataProvider(asyncDataBrokerON);
126 mxBean.setRpcRegistry(bindingBrokerON);
127 mxBean.setScheduler(schedulerON);
128 mxBean.setTopologyId(topologyId);
129 mxBean.setSourceTopology(sourceTopology);
134 public List<ModuleFactory> getModuleFactories() {
135 final List<ModuleFactory> moduleFactories = super.getModuleFactories();
136 moduleFactories.add(new PCEPTunnelTopologyProviderModuleFactory());
137 moduleFactories.add(new PCEPTopologyProviderModuleFactory());
138 moduleFactories.add(new PCEPDispatcherImplModuleFactory());
139 moduleFactories.add(new NettyThreadgroupModuleFactory());
140 moduleFactories.add(new Stateful07TopologySessionListenerModuleFactory());
141 return moduleFactories;
145 public List<String> getYangModelsPaths() {
146 final List<String> paths = super.getYangModelsPaths();
147 paths.add("/META-INF/yang/network-topology@2013-10-21.yang");
148 paths.add("/META-INF/yang/network-topology-pcep.yang");
149 paths.add("/META-INF/yang/network-topology-pcep-programming.yang");
150 paths.add("/META-INF/yang/network-topology-programming.yang");
151 paths.add("/META-INF/yang/topology-tunnel.yang");
152 paths.add("/META-INF/yang/topology-tunnel-pcep.yang");
153 paths.add("/META-INF/yang/topology-tunnel-pcep-programming.yang");
154 paths.add("/META-INF/yang/topology-tunnel-p2p.yang");
155 paths.add("/META-INF/yang/topology-tunnel-programming.yang");
156 paths.add("/META-INF/yang/odl-network-topology.yang");
157 paths.add("/META-INF/yang/yang-ext.yang");
158 paths.add("/META-INF/yang/pcep-types.yang");
159 paths.add("/META-INF/yang/rsvp.yang");
160 paths.add("/META-INF/yang/iana.yang");
161 paths.add("/META-INF/yang/network-concepts.yang");
162 paths.add("/META-INF/yang/ieee754.yang");