From: Dana Kutenicsova Date: Mon, 21 Oct 2013 09:44:30 +0000 (+0000) Subject: Merge "BUG-113: split off singleton nature of BGPExtensionProviderContextImpl" X-Git-Tag: jenkins-bgpcep-bulk-release-prepare-only-1~237^2~141 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=9f1c6b8043f932a2903b63d89a487919425ec1de;hp=178257a85792293d9b3920f67108b681ca80c1cc;p=bgpcep.git Merge "BUG-113: split off singleton nature of BGPExtensionProviderContextImpl" --- diff --git a/topology/pom.xml b/topology/pom.xml index c651e72c99..c799783492 100644 --- a/topology/pom.xml +++ b/topology/pom.xml @@ -17,7 +17,8 @@ ${project.artifactId} - api + api + provider-bgp tunnel-api tunnel-pcep segment-routing diff --git a/topology/provider-bgp/.project b/topology/provider-bgp/.project new file mode 100644 index 0000000000..58f8f71366 --- /dev/null +++ b/topology/provider-bgp/.project @@ -0,0 +1,24 @@ + + + topology-provider-bgp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/topology/provider-bgp/pom.xml b/topology/provider-bgp/pom.xml new file mode 100644 index 0000000000..f56d630ff5 --- /dev/null +++ b/topology/provider-bgp/pom.xml @@ -0,0 +1,86 @@ + + + + + + org.opendaylight.bgpcep + topology-parent + 0.3.0-SNAPSHOT + + + 4.0.0 + topology-provider-bgp + BGP Topology Provider + bundle + ${project.artifactId} + + 3.0.4 + + + + + ${project.groupId} + bgp-rib-api + ${project.version} + + + ${project.groupId} + bgp-linkstate + ${project.version} + + + ${project.groupId} + topology-api + ${project.version} + + + org.opendaylight.controller + sal-binding-api + 1.0-SNAPSHOT + + + org.slf4j + slf4j-api + ${slf4j.version} + + + ${project.groupId} + mockito-configuration + ${project.version} + test + + + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + + org.opendaylight.bgpcep.topology.provider.bgp + + + org.opendaylight.bgpcep.topology.provider.bgp.impl + + org.opendaylight.bgpcep.topology.provider.bgp.impl.Activator + + + + + + + + + ${project.artifactId} + TOPOLOGY-PROVIDER-BGP Module site + ${basedir}/target/site/${project.artifactId} + + + + diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java new file mode 100644 index 0000000000..b5bc4579a6 --- /dev/null +++ b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2013 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 + */ +package org.opendaylight.bgpcep.topology.provider.bgp; + +import java.util.EventListener; + +import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; + +public interface LocRIBListener extends EventListener { + /** + * @param trans Modification transaction. The implementation must explicitly commit + * it if it wishes to have its modifications propagated. The transaction + * is not shared with any other entity and will be cleaned up by the + * caller if it is not committed before this method returns. + * @param event Data change event + * @throws Exception throw it if you must. If you can handle it, please do so. + */ + public void onLocRIBChange(DataModification trans, DataChangeEvent event) throws Exception; +} diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java new file mode 100644 index 0000000000..cf8340bd5f --- /dev/null +++ b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java @@ -0,0 +1,39 @@ +package org.opendaylight.bgpcep.topology.provider.bgp; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public final class LocRIBListeners { + public interface Subscribtion { + public Class getAfi(); + public Class getSafi(); + public LocRIBListener getLocRIBListener(); + } + + private LocRIBListeners() { + + } + + public static ServiceRegistration subscribe(final BundleContext context, + final Class afi, final Class safi, final LocRIBListener listener) { + return context.registerService(Subscribtion.class, + new Subscribtion() { + @Override + public Class getAfi() { + return afi; + } + + @Override + public Class getSafi() { + return safi; + } + + @Override + public LocRIBListener getLocRIBListener() { + return listener; + } + }, null); + } +} diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java new file mode 100644 index 0000000000..77fe328789 --- /dev/null +++ b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013 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 + */ +package org.opendaylight.bgpcep.topology.provider.bgp.impl; + +import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners; +import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import com.google.common.base.Preconditions; + +public class Activator extends AbstractBindingAwareProvider { +// private ServiceRegistration ipv4, ipv6, linkstate; + private BundleContext context; + + @Override + public void onSessionInitiated(final ProviderContext session) { + final LocRIBListenerSubscriptionTracker reg = new LocRIBListenerSubscriptionTracker(context, session.getSALService(DataProviderService.class)); + reg.open(); + +// ipv4 = LocRIBListeners.subscribe(context, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4ReachabilityTopologyBuilder()); +// ipv6 = LocRIBListeners.subscribe(context, Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6ReachabilityTopologyBuilder()); +// linkstate = LocRIBListeners.subscribe(context, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateTopologyBuilder()); + } + + @Override + protected void startImpl(final BundleContext context) { + this.context = Preconditions.checkNotNull(context); + } +} diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java new file mode 100644 index 0000000000..054b5d6ecf --- /dev/null +++ b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013 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 + */ +package org.opendaylight.bgpcep.topology.provider.bgp.impl; + +import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListener; +import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners; +import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; +import org.opendaylight.protocol.concepts.ListenerRegistration; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.LocRib; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Preconditions; + +final class LocRIBListenerSubscriptionTracker extends ServiceTracker> { + private static final InstanceIdentifier locRIBPath = InstanceIdentifier.builder().node(LocRib.class).toInstance(); + private static final Logger logger = LoggerFactory.getLogger(LocRIBListenerSubscriptionTracker.class); + private final DataProviderService dps; + + LocRIBListenerSubscriptionTracker(final BundleContext context, final DataProviderService dps) { + super(context, LocRIBListeners.Subscribtion.class, null); + this.dps = Preconditions.checkNotNull(dps); + } + + @Override + public ListenerRegistration addingService(final ServiceReference reference) { + final LocRIBListeners.Subscribtion service = context.getService(reference); + if (service == null) { + logger.trace("Service for reference {} disappeared", reference); + return null; + } + + final InstanceIdentifier path = InstanceIdentifier.builder(locRIBPath). + node(Tables.class, new TablesKey(service.getAfi(), service.getSafi())).toInstance(); + final LocRIBListener listener = service.getLocRIBListener(); + + final DataChangeListener dcl = new DataChangeListener() { + + @Override + public void onDataChanged(final DataChangeEvent, DataObject> change) { + final DataModification trans = dps.beginTransaction(); + + try { + listener.onLocRIBChange(trans, change); + } catch (Exception e) { + logger.info("Data change {} was not completely propagated to listener {}", change, listener, e); + } + + // FIXME: abort the transaction if it's not committing + } + }; + + dps.registerChangeListener(path, dcl); + + return new ListenerRegistration(listener) { + @Override + protected void removeRegistration() { + dps.unregisterChangeListener(path, dcl); + } + }; + } + + @Override + public void removedService(final ServiceReference reference, final ListenerRegistration service) { + service.close(); + context.ungetService(reference); + } +}