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: rib-impl
12 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13 * Generated at: Wed Nov 06 13:02:32 CET 2013
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.reflect.AbstractInvocationHandler;
20 import com.google.common.reflect.Reflection;
21 import java.lang.reflect.Method;
22 import java.util.Collections;
23 import java.util.List;
25 import java.util.stream.Collectors;
26 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
27 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
28 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
29 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
30 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPBestPathSelection;
31 import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
32 import org.opendaylight.protocol.bgp.rib.impl.spi.InstanceType;
33 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
34 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
35 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
36 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
37 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
38 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
44 import org.osgi.framework.BundleContext;
50 public final class RIBImplModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractRIBImplModule {
52 private static final String IS_NOT_SET = "is not set.";
53 private BundleContext bundleContext;
55 public RIBImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
56 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
57 super(name, dependencyResolver);
60 public RIBImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
61 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final RIBImplModule oldModule,
62 final java.lang.AutoCloseable oldInstance) {
63 super(name, dependencyResolver, oldModule, oldInstance);
67 public void customValidation() {
68 JmxAttributeValidationException.checkNotNull(getExtensions(), IS_NOT_SET, extensionsJmxAttribute);
69 JmxAttributeValidationException.checkNotNull(getRibId(), IS_NOT_SET, ribIdJmxAttribute);
70 JmxAttributeValidationException.checkNotNull(getLocalAs(), IS_NOT_SET, localAsJmxAttribute);
71 JmxAttributeValidationException.checkNotNull(getBgpRibId(), IS_NOT_SET, bgpRibIdJmxAttribute);
72 JmxAttributeValidationException.checkNotNull(getLocalTable(), IS_NOT_SET, localTableJmxAttribute);
76 public java.lang.AutoCloseable createInstance() {
77 final WaitingServiceTracker<BgpDeployer> bgpDeployerTracker =
78 WaitingServiceTracker.create(BgpDeployer.class, this.bundleContext);
79 final BgpDeployer bgpDeployer = bgpDeployerTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
80 //map configuration to OpenConfig BGP
81 final Protocol protocol = bgpDeployer.getMappingService().fromRib(getBgpRibId(), getClusterId(), getRibId(),
82 new AsNumber(getLocalAs()), getLocalTableDependency(),
83 mapBestPathSelectionStrategyByFamily(getRibPathSelectionModeDependency()));
84 final Global global = protocol.getAugmentation(Protocol1.class).getBgp().getGlobal();
85 final KeyedInstanceIdentifier<Protocol, ProtocolKey> protocolIId = bgpDeployer.getInstanceIdentifier().child(Protocols.class)
86 .child(Protocol.class, protocol.getKey());
87 final InstanceIdentifier<Bgp> bgpIID = protocolIId.augmentation(Protocol1.class).child(Bgp.class);
88 bgpDeployer.onGlobalModified(bgpIID, global, () -> bgpDeployer.writeConfiguration(protocol, protocolIId));
90 //get rib instance service, use filter
91 final WaitingServiceTracker<RIB> ribTracker = WaitingServiceTracker.create(RIB.class,
92 this.bundleContext, "(" + InstanceType.RIB.getBeanName() + "=" + getRibId().getValue() + ")");
93 final RIB rib = ribTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
94 final RIBImplRuntimeRegistration register = getRootRuntimeBeanRegistratorWrapper().register(rib.getRenderStats());
96 return Reflection.newProxy(AutoCloseableRIB.class, new AbstractInvocationHandler() {
98 protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
99 if (method.getName().equals("close")) {
100 bgpDeployer.onGlobalRemoved(bgpIID);
102 bgpDeployerTracker.close();
106 return method.invoke(rib, args);
112 public void setBundleContext(final BundleContext bundleContext) {
113 this.bundleContext = bundleContext;
116 private Map<TablesKey, PathSelectionMode> mapBestPathSelectionStrategyByFamily(final List<BGPBestPathSelection> bestPathSelectionDependency) {
117 return Collections.unmodifiableMap(bestPathSelectionDependency.stream().collect(
118 Collectors.toMap(st -> new TablesKey(st.getAfi(), st.getSafi()), st -> st.getStrategy())));
121 private static interface AutoCloseableRIB extends RIB, AutoCloseable {