From 8cc6e1c568a500d2fd193eed6a7b639bac051185 Mon Sep 17 00:00:00 2001 From: Sasidharan Sambasivam Date: Thu, 23 Apr 2015 16:25:37 +0530 Subject: [PATCH] add bgpmanager service dependency Change-Id: I1556be4489f84645a494df5a83d9b889d02264b9 Signed-off-by: Sasidharan Sambasivam --- features/src/main/features/features.xml | 6 +- vpnmanager/vpnmanager-impl/pom.xml | 5 ++ .../src/main/config/default-config.xml | 5 ++ .../vpnservice/VpnInterfaceManager.java | 56 +++++++++++++++++-- .../vpnservice/VpnserviceProvider.java | 10 +++- .../impl/rev150216/VpnserviceImplModule.java | 2 +- .../src/main/yang/vpnservice-impl.yang | 9 +++ 7 files changed, 85 insertions(+), 8 deletions(-) diff --git a/features/src/main/features/features.xml b/features/src/main/features/features.xml index 7147f6de..ffe2b953 100644 --- a/features/src/main/features/features.xml +++ b/features/src/main/features/features.xml @@ -29,21 +29,23 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-mdsal-broker odl-vpnservice-api mvn:org.opendaylight.vpnservice/bgpmanager-api/${project.version} + mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version} mvn:org.opendaylight.vpnservice/vpnmanager-impl/${vpnmanager.version} mvn:org.opendaylight.vpnservice/interfacemgr-impl/${interfacemgr.version} mvn:org.opendaylight.vpnservice/nexthopmgr-impl/${nexthopmgr.version} mvn:org.opendaylight.vpnservice/idmanager-impl/${idmanager.version} mvn:org.opendaylight.vpnservice/fibmanager-impl/${fibmanager.version} - mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version} + wrap:mvn:org.apache.thrift/libthrift/0.9.1$overwrite=merge&Bundle-Version=0.9.1&Export-Package=*;-noimport:=true;version="0.9.1" + mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version}/xml/config mvn:org.opendaylight.vpnservice/vpnmanager-impl/${vpnmanager.version}/xml/config mvn:org.opendaylight.vpnservice/interfacemgr-impl/${interfacemgr.version}/xml/config mvn:org.opendaylight.vpnservice/nexthopmgr-impl/${nexthopmgr.version}/xml/config mvn:org.opendaylight.vpnservice/idmanager-impl/${idmanager.version}/xml/config mvn:org.opendaylight.vpnservice/fibmanager-impl/${fibmanager.version}/xml/config - mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version}/xml/config + odl-vpnservice-impl diff --git a/vpnmanager/vpnmanager-impl/pom.xml b/vpnmanager/vpnmanager-impl/pom.xml index 3eaa892d..20886d9b 100644 --- a/vpnmanager/vpnmanager-impl/pom.xml +++ b/vpnmanager/vpnmanager-impl/pom.xml @@ -25,6 +25,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html ${project.groupId} vpnmanager-api ${project.version} + + + ${project.groupId} + bgpmanager-api + 1.0-SNAPSHOT diff --git a/vpnmanager/vpnmanager-impl/src/main/config/default-config.xml b/vpnmanager/vpnmanager-impl/src/main/config/default-config.xml index 040db603..65cfb17f 100644 --- a/vpnmanager/vpnmanager-impl/src/main/config/default-config.xml +++ b/vpnmanager/vpnmanager-impl/src/main/config/default-config.xml @@ -11,6 +11,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html urn:opendaylight:params:xml:ns:yang:vpnservice:impl?module=vpnservice-impl&revision=2015-02-16 urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 + urn:opendaylight:params:xml:ns:yang:bgpmanager:api?module=bgpmanager-api&revision=2015-04-20 @@ -23,6 +24,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html binding:binding-broker-osgi-registry binding-osgi-broker + + bgpmanager:bgpmanager-api + bgpmanager + diff --git a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java index e7bca533..76f1f494 100644 --- a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java +++ b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnInterfaceManager.java @@ -47,11 +47,11 @@ public class VpnInterfaceManager extends AbstractDataChangeListener DEFAULT_CALLBACK = new FutureCallback() { public void onSuccess(Void result) { - LOG.info("Success in Datastore write operation"); + LOG.info("Success in Datastore operation"); } public void onFailure(Throwable error) { - LOG.error("Error in Datastore write operation", error); + LOG.error("Error in Datastore operation", error); }; }; @@ -168,9 +168,57 @@ public class VpnInterfaceManager extends AbstractDataChangeListener identifier, VpnInterface del) { - // TODO Auto-generated method stub + protected void remove( InstanceIdentifier identifier, VpnInterface vpnInterface) { + LOG.info("Remove event - key: {}, value: {}" ,identifier, vpnInterface ); + final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class); + String interfaceName = key.getName(); + InstanceIdentifierBuilder idBuilder = + InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(interfaceName)); + InstanceIdentifier id = idBuilder.build(); + Optional port = read(LogicalDatastoreType.CONFIGURATION, id); + if (port.isPresent()) { + Interface interf = port.get(); + unbindServiceOnInterface(interf); + removeNextHops(identifier, vpnInterface); + } else { + LOG.info("No nexthops were available to handle remove event {}", interfaceName); + } + } + + private void removeNextHops(final InstanceIdentifier identifier, VpnInterface intf) { + //Read NextHops + InstanceIdentifier path = identifier.augmentation(Adjacencies.class); + Optional adjacencies = read(LogicalDatastoreType.OPERATIONAL, path); + String intfName = intf.getName(); + + if (adjacencies.isPresent()) { + List nextHops = adjacencies.get().getAdjacency(); + if (!nextHops.isEmpty()) { + LOG.trace("NextHops are " + nextHops); + for (Adjacency nextHop : nextHops) { + //TODO: Update BGP + removePrefixFromBGP(nextHop); + } + } + + InstanceIdentifier interfaceId = VpnUtil.getVpnInterfaceIdentifier(intfName); + delete(LogicalDatastoreType.OPERATIONAL, interfaceId); + } + } + + private void delete(LogicalDatastoreType datastoreType, InstanceIdentifier path) { + WriteTransaction tx = broker.newWriteOnlyTransaction(); + tx.delete(datastoreType, path); + Futures.addCallback(tx.submit(), DEFAULT_CALLBACK); + } + + private void unbindServiceOnInterface(Interface intf) { + //TODO: Remove Ingress flow on the interface to unbind the VPN service + } + + private void removePrefixFromBGP(Adjacency nextHop) { + //TODO: Update the Prefix to BGP } @Override diff --git a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java index 7514cf7f..a1e635c3 100644 --- a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java +++ b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/vpnservice/VpnserviceProvider.java @@ -7,10 +7,12 @@ */ package org.opendaylight.vpnservice; +import java.util.Collections; + +import org.opendaylight.bgpmanager.api.IBgpManager; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,6 +22,7 @@ public class VpnserviceProvider implements BindingAwareProvider, private static final Logger LOG = LoggerFactory.getLogger(VpnserviceProvider.class); private VpnInterfaceManager vpnInterfaceManager; private VpnManager vpnManager; + private IBgpManager bgpManager; @Override public void onSessionInitiated(ProviderContext session) { @@ -33,6 +36,11 @@ public class VpnserviceProvider implements BindingAwareProvider, } } + public void setBgpManager(IBgpManager bgpManager) { + LOG.debug("BGP Manager reference initialized"); + this.bgpManager = bgpManager; + } + @Override public void close() throws Exception { vpnManager.close(); diff --git a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/vpnservice/impl/rev150216/VpnserviceImplModule.java b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/vpnservice/impl/rev150216/VpnserviceImplModule.java index e484e95b..c0fe5586 100644 --- a/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/vpnservice/impl/rev150216/VpnserviceImplModule.java +++ b/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/vpnservice/impl/rev150216/VpnserviceImplModule.java @@ -27,7 +27,7 @@ public class VpnserviceImplModule extends org.opendaylight.yang.gen.v1.urn.opend public java.lang.AutoCloseable createInstance() { VpnserviceProvider provider = new VpnserviceProvider(); getBrokerDependency().registerProvider(provider); + provider.setBgpManager(getBgpmanagerDependency()); return provider; } - } diff --git a/vpnmanager/vpnmanager-impl/src/main/yang/vpnservice-impl.yang b/vpnmanager/vpnmanager-impl/src/main/yang/vpnservice-impl.yang index 3c5fb3dd..f77b000e 100644 --- a/vpnmanager/vpnmanager-impl/src/main/yang/vpnservice-impl.yang +++ b/vpnmanager/vpnmanager-impl/src/main/yang/vpnservice-impl.yang @@ -5,6 +5,7 @@ module vpnservice-impl { import config { prefix config; revision-date 2013-04-05; } import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} + import bgpmanager-api { prefix bgpmgr-api; revision-date 2015-04-20;} description "Service definition for vpnservice project"; @@ -30,6 +31,14 @@ module vpnservice-impl { } } } + container bgpmanager { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity bgpmgr-api:bgpmanager-api; + } + } + } } } } -- 2.36.6