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: bgp-rib-impl yang module local name: bgp-peer
12 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13 * Generated at: Sat Jan 25 11:00:14 CET 2014
15 * Do not modify this file unless it is present under src/main directory
17 package org.opendaylight.controller.config.yang.bgp.rib.impl;
19 import java.lang.management.ManagementFactory;
20 import java.net.InetSocketAddress;
21 import java.util.List;
23 import javax.management.AttributeNotFoundException;
24 import javax.management.InstanceNotFoundException;
25 import javax.management.MBeanException;
26 import javax.management.MBeanServer;
27 import javax.management.ObjectName;
28 import javax.management.ReflectionException;
30 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
31 import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
32 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
33 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParametersBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.as4.bytes._case.As4BytesCapabilityBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.multiprotocol._case.MultiprotocolCapabilityBuilder;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import com.google.common.collect.Lists;
47 import com.google.common.net.InetAddresses;
52 public final class BGPPeerModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerModule
54 private static final Logger LOG = LoggerFactory.getLogger(BGPPeerModule.class);
56 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
57 super(identifier, dependencyResolver);
60 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
61 final BGPPeerModule oldModule, final java.lang.AutoCloseable oldInstance) {
63 super(identifier, dependencyResolver, oldModule, oldInstance);
67 protected void customValidation(){
68 JmxAttributeValidationException.checkNotNull(getHost(),
69 "value is not set.", hostJmxAttribute);
70 JmxAttributeValidationException.checkNotNull(getPort(),
71 "value is not set.", portJmxAttribute);
73 if (getPassword() != null) {
75 * This is a nasty hack, but we don't have another clean solution. We cannot allow
76 * password being set if the injected dispatcher does not have the optional
77 * md5-server-channel-factory set.
79 * FIXME: this is a use case for Module interfaces, e.g. RibImplModule
80 * should something like isMd5ServerSupported()
82 final MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
84 final ObjectName ribi = (ObjectName) srv.getAttribute(getRib(), "CurrentImplementation");
86 // FIXME: AbstractRIBImplModule.bgpDispatcherJmxAttribute.getAttributeName()
87 final ObjectName disp = (ObjectName) srv.getAttribute(ribi, "BgpDispatcher");
89 final ObjectName dispi = (ObjectName) srv.getAttribute(disp, "CurrentImplementation");
91 // FIXME: AbstractBGPDispatcherImplModule.md5ChannelFactoryJmxAttribute.getAttributeName()
92 final Object cf = srv.getAttribute(dispi, "Md5ChannelFactory");
93 JmxAttributeValidationException.checkCondition(cf != null, "Underlying dispatcher does not support MD5 clients", passwordJmxAttribute);
94 } catch (AttributeNotFoundException | InstanceNotFoundException
95 | MBeanException | ReflectionException e) {
96 JmxAttributeValidationException.wrap(e, "support could not be validated", passwordJmxAttribute);
101 private InetSocketAddress createAddress() {
102 final IpAddress ip = getHost();
103 if (ip.getIpv4Address() != null) {
104 return new InetSocketAddress(InetAddresses.forString(ip.getIpv4Address().getValue()), getPort().getValue());
105 } else if (ip.getIpv6Address() != null) {
106 return new InetSocketAddress(InetAddresses.forString(ip.getIpv6Address().getValue()), getPort().getValue());
108 throw new IllegalStateException("Failed to handle host " + getHost());
112 private static String peerName(final IpAddress host) {
113 if (host.getIpv4Address() != null) {
114 return host.getIpv4Address().getValue();
116 if (host.getIpv6Address() != null) {
117 return host.getIpv6Address().getValue();
124 public java.lang.AutoCloseable createInstance() {
125 final RIB r = getRibDependency();
127 final List<BgpParameters> tlvs = Lists.newArrayList();
128 tlvs.add(new BgpParametersBuilder().setCParameters(
129 new As4BytesCaseBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(r.getLocalAs()).build()).build()).build());
131 for (final BgpTableType t : getAdvertizedTableDependency()) {
132 if (!r.getLocalTables().contains(t)) {
133 LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", t);
136 tlvs.add(new BgpParametersBuilder().setCParameters(
137 new MultiprotocolCaseBuilder().setMultiprotocolCapability(
138 new MultiprotocolCapabilityBuilder(t).build()).build()).build());
141 // Remote AS number defaults to our local AS
142 final AsNumber remoteAs;
143 if (getRemoteAs() != null) {
144 remoteAs = new AsNumber(getRemoteAs());
146 remoteAs = r.getLocalAs();
149 final String password;
150 if (getPassword() != null) {
151 password = getPassword().getValue();
156 return new BGPPeer(peerName(getHost()), createAddress(), password,
157 new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), tlvs), remoteAs, r);