2 * Copyright (c) 2013 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
11 * Generated from: yang module name: config-pcep-topology-provider yang module local name: pcep-topology-impl
12 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13 * Generated at: Mon Nov 18 21:08:29 CET 2013
15 * Do not modify this file unless it is present under src/main directory
17 package org.opendaylight.controller.config.yang.pcep.topology.provider;
19 import com.google.common.base.Charsets;
20 import com.google.common.net.InetAddresses;
22 import java.lang.management.ManagementFactory;
23 import java.net.InetAddress;
24 import java.net.InetSocketAddress;
25 import java.util.concurrent.ExecutionException;
27 import javax.management.AttributeNotFoundException;
28 import javax.management.InstanceNotFoundException;
29 import javax.management.MBeanException;
30 import javax.management.MBeanServer;
31 import javax.management.ObjectName;
32 import javax.management.ReflectionException;
34 import org.opendaylight.bgpcep.pcep.topology.provider.PCEPTopologyProvider;
35 import org.opendaylight.bgpcep.tcpmd5.KeyMapping;
36 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
48 public final class PCEPTopologyProviderModule extends
49 org.opendaylight.controller.config.yang.pcep.topology.provider.AbstractPCEPTopologyProviderModule {
50 private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyProviderModule.class);
52 public PCEPTopologyProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
53 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
54 super(identifier, dependencyResolver);
57 public PCEPTopologyProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
58 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final PCEPTopologyProviderModule oldModule,
59 final java.lang.AutoCloseable oldInstance) {
60 super(identifier, dependencyResolver, oldModule, oldInstance);
63 private KeyMapping contructKeys() {
64 final KeyMapping ret = new KeyMapping();
65 if (getClient() != null) {
66 for (Client c : getClient()) {
67 if (c.getAddress() == null) {
68 LOG.warn("Client {} does not have an address skipping it", c);
71 if (c.getPassword() != null) {
72 final String s = getAddressString(c.getAddress());
73 ret.put(InetAddresses.forString(s), c.getPassword().getValue().getBytes(Charsets.US_ASCII));
80 private String getAddressString(final IpAddress address) {
81 if (address.getIpv4Address() != null) {
82 return address.getIpv4Address().getValue();
84 if (address.getIpv6Address() != null) {
85 return address.getIpv6Address().getValue();
88 throw new IllegalArgumentException(String.format("Address %s is invalid", address));
92 public void customValidation() {
93 JmxAttributeValidationException.checkNotNull(getTopologyId(), "is not set.", topologyIdJmxAttribute);
94 JmxAttributeValidationException.checkNotNull(getListenAddress(), "is not set.", listenAddressJmxAttribute);
95 JmxAttributeValidationException.checkNotNull(getListenPort(), "is not set.", listenPortJmxAttribute);
96 JmxAttributeValidationException.checkNotNull(getStatefulPlugin(), "is not set.", statefulPluginJmxAttribute);
98 final KeyMapping keys = contructKeys();
99 if (!keys.isEmpty()) {
101 * This is a nasty hack, but we don't have another clean solution. We cannot allow
102 * password being set if the injected dispatcher does not have the optional
103 * md5-server-channel-factory set.
105 * FIXME: this is a use case for Module interfaces, e.g. PCEPDispatcherImplModule
106 * should something like isMd5ServerSupported()
108 final MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
111 final ObjectName ci = (ObjectName) srv.getAttribute(getDispatcher(), "CurrentImplementation");
113 // FIXME: AbstractPCEPDispatcherImplModule.md5ServerChannelFactoryJmxAttribute.getAttributeName()
114 scf = srv.getAttribute(ci, "Md5ServerChannelFactory");
115 JmxAttributeValidationException.checkCondition(scf != null, "password is not compatible with selected dispatcher",
117 } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
118 JmxAttributeValidationException.wrap(e, "password support could not be validated", clientJmxAttribute);
123 private InetAddress listenAddress() {
124 final IpAddress a = getListenAddress();
125 if (a.getIpv4Address() != null) {
126 return InetAddresses.forString(a.getIpv4Address().getValue());
127 } else if (a.getIpv6Address() != null) {
128 return InetAddresses.forString(a.getIpv6Address().getValue());
130 throw new IllegalArgumentException("Address " + a + " not supported");
135 public java.lang.AutoCloseable createInstance() {
136 final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
137 new TopologyKey(getTopologyId())).toInstance();
138 final InetSocketAddress address = new InetSocketAddress(listenAddress(), getListenPort().getValue());
139 final KeyMapping keys = contructKeys();
142 return PCEPTopologyProvider.create(getDispatcherDependency(), address, keys.isEmpty() ? null : keys, getSchedulerDependency(),
143 getDataProviderDependency(), getRpcRegistryDependency(), topology, getStatefulPluginDependency());
144 } catch (InterruptedException | ExecutionException e) {
145 LOG.error("Failed to instantiate topology provider at {}", address, e);
146 throw new IllegalStateException("Failed to instantiate provider", e);