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 com.google.common.collect.Lists;
20 import com.google.common.net.InetAddresses;
21 import java.net.InetSocketAddress;
22 import java.util.List;
23 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
24 import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
25 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
26 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParametersBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.as4.bytes._case.As4BytesCapabilityBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.multiprotocol._case.MultiprotocolCapabilityBuilder;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
42 public final class BGPPeerModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerModule {
43 private static final Logger LOG = LoggerFactory.getLogger(BGPPeerModule.class);
45 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
46 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
47 super(identifier, dependencyResolver);
50 public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
51 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final BGPPeerModule oldModule,
52 final java.lang.AutoCloseable oldInstance) {
54 super(identifier, dependencyResolver, oldModule, oldInstance);
58 protected void customValidation() {
59 JmxAttributeValidationException.checkNotNull(getHost(), "value is not set.", hostJmxAttribute);
60 JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute);
62 if (getPassword() != null) {
64 * This is a nasty hack, but we don't have another clean solution. We cannot allow
65 * password being set if the injected dispatcher does not have the optional
66 * md5-server-channel-factory set.
68 * FIXME: this is a use case for Module interfaces, e.g. RibImplModule
69 * should something like isMd5ServerSupported()
72 RIBImplModuleMXBean ribProxy = dependencyResolver.newMXBeanProxy(getRib(), RIBImplModuleMXBean.class);
73 BGPDispatcherImplModuleMXBean bgpDispatcherProxy = dependencyResolver.newMXBeanProxy(
74 ribProxy.getBgpDispatcher(), BGPDispatcherImplModuleMXBean.class);
75 boolean isMd5Supported = bgpDispatcherProxy.getMd5ChannelFactory() != null;
77 JmxAttributeValidationException.checkCondition(isMd5Supported,
78 "Underlying dispatcher does not support MD5 clients", passwordJmxAttribute);
83 private InetSocketAddress createAddress() {
84 final IpAddress ip = getHost();
85 if (ip.getIpv4Address() != null) {
86 return new InetSocketAddress(InetAddresses.forString(ip.getIpv4Address().getValue()), getPort().getValue());
87 } else if (ip.getIpv6Address() != null) {
88 return new InetSocketAddress(InetAddresses.forString(ip.getIpv6Address().getValue()), getPort().getValue());
90 throw new IllegalStateException("Failed to handle host " + getHost());
94 private static String peerName(final IpAddress host) {
95 if (host.getIpv4Address() != null) {
96 return host.getIpv4Address().getValue();
98 if (host.getIpv6Address() != null) {
99 return host.getIpv6Address().getValue();
106 public java.lang.AutoCloseable createInstance() {
107 final RIB r = getRibDependency();
109 final List<BgpParameters> tlvs = Lists.newArrayList();
110 tlvs.add(new BgpParametersBuilder().setCParameters(
111 new As4BytesCaseBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(r.getLocalAs()).build()).build()).build());
113 for (final BgpTableType t : getAdvertizedTableDependency()) {
114 if (!r.getLocalTables().contains(t)) {
115 LOG.info("RIB instance does not list {} in its local tables. Incoming data will be dropped.", t);
118 tlvs.add(new BgpParametersBuilder().setCParameters(
119 new MultiprotocolCaseBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder(t).build()).build()).build());
122 // Remote AS number defaults to our local AS
123 final AsNumber remoteAs;
124 if (getRemoteAs() != null) {
125 remoteAs = new AsNumber(getRemoteAs());
127 remoteAs = r.getLocalAs();
130 final String password;
131 if (getPassword() != null) {
132 password = getPassword().getValue();
137 return new BGPPeer(peerName(getHost()), createAddress(), password, new BGPSessionPreferences(r.getLocalAs(), getHoldtimer(), r.getBgpIdentifier(), tlvs), remoteAs, r);