/* * Copyright (c) 2013, 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ /** * Generated file * Generated from: yang module name: bgp-rib-impl yang module local name: bgp-peer * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator * Generated at: Sat Jan 25 11:00:14 CET 2014 * * Do not modify this file unless it is present under src/main directory */ package org.opendaylight.controller.config.yang.bgp.rib.impl; import com.google.common.reflect.AbstractInvocationHandler; import com.google.common.reflect.Reflection; import io.netty.channel.epoll.Epoll; import java.lang.reflect.Method; import org.opendaylight.controller.config.api.JmxAttributeValidationException; import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker; import org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil; import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer; import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType; import org.opendaylight.protocol.bgp.rib.impl.spi.RIB; import org.opendaylight.protocol.util.Ipv4Util; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborKey; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.rfc2385.cfg.rev160324.Rfc2385Key; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.osgi.framework.BundleContext; /** * */ @Deprecated public final class BGPPeerModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerModule { private BundleContext bundleContext; public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } public BGPPeerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final BGPPeerModule oldModule, final java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } @Override protected void customValidation() { final IpAddress host = getHost(); JmxAttributeValidationException.checkNotNull(host, "value is not set.", hostJmxAttribute); JmxAttributeValidationException.checkCondition(host.getIpv4Address() != null || host.getIpv6Address() != null, "Unexpected host", hostJmxAttribute); JmxAttributeValidationException.checkNotNull(getPort(), "value is not set.", portJmxAttribute); if (getPeerRole() != null) { final boolean isNotPeerRoleInternal= getPeerRole() != PeerRole.Internal; JmxAttributeValidationException.checkCondition(isNotPeerRoleInternal, "Internal Peer Role is reserved for Application Peer use.", peerRoleJmxAttribute); } if (isPasswordPresent(getPassword())) { JmxAttributeValidationException.checkCondition(Epoll.isAvailable(), "BGP Peer is configured with password but native transport is not available", passwordJmxAttribute); } } @Override public java.lang.AutoCloseable createInstance() { final RIB rib = getRibDependency(); final WaitingServiceTracker bgpDeployerTracker = WaitingServiceTracker.create(BgpDeployer.class, this.bundleContext); final BgpDeployer bgpDeployer = bgpDeployerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); //map configuration to OpenConfig BGP final Neighbor neighbor = OpenConfigMappingUtil.fromBgpPeer(getAddPathDependency(), getAdvertizedTableDependency(), getHoldtimer(), getHost(), getInitiateConnection(), getPassword(), getPort(), getRetrytimer(), getRemoteAs(), getPeerRole(), getSimpleRoutingPolicy(), bgpDeployer.getMappingService()); //write to configuration DS final KeyedInstanceIdentifier protocolIId = bgpDeployer.getInstanceIdentifier().child(Protocols.class) .child(Protocol.class, new ProtocolKey(BGP.class, rib.getInstanceIdentifier().getKey().getId().getValue())); final InstanceIdentifier bgpIID = protocolIId.augmentation(Protocol1.class).child(Bgp.class); final KeyedInstanceIdentifier neighborIId = protocolIId.augmentation(Protocol1.class).child(Bgp.class) .child(Neighbors.class).child(Neighbor.class, neighbor.getKey()); bgpDeployer.onNeighborModified(bgpIID, neighbor, () -> bgpDeployer.writeConfiguration(neighbor, neighborIId)); //get rib instance service, use filter final WaitingServiceTracker peerTracker = WaitingServiceTracker.create(BGPPeerRuntimeMXBean.class, this.bundleContext, "(" + InstanceType.PEER.getBeanName() + "=" + Ipv4Util.toStringIP(getHost()) + ")"); final BGPPeerRuntimeMXBean peer = peerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); final BGPPeerRuntimeRegistration runtimeRegistration = getRootRuntimeBeanRegistratorWrapper().register(peer); return Reflection.newProxy(AutoCloseablePeer.class, new AbstractInvocationHandler() { @Override protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getName().equals("close")) { bgpDeployer.onNeighborRemoved(bgpIID, neighbor); runtimeRegistration.close(); bgpDeployerTracker.close(); peerTracker.close(); return null; } else { return method.invoke(peer, args); } } }); } private static boolean isPasswordPresent(final Rfc2385Key password) { return password != null && ! password.getValue().isEmpty(); } public void setBundleContext(final BundleContext bundleContext) { this.bundleContext = bundleContext; } private static interface AutoCloseablePeer extends RIB, AutoCloseable { } }