<mdsal.version>1.2.0-SNAPSHOT</mdsal.version>
<openflowplugin.version>0.1.0-SNAPSHOT</openflowplugin.version>
<yangtools.version>0.7.0-SNAPSHOT</yangtools.version>
+ <vpnmanager.version>0.0.1-SNAPSHOT</vpnmanager.version>
<interfacemgr.version>0.0.1-SNAPSHOT</interfacemgr.version>
+ <nexthopmgr.version>0.0.1-SNAPSHOT</nexthopmgr.version>
+ <fibmanager.version>0.0.1-SNAPSHOT</fibmanager.version>
+ <idmanager.version>0.0.1-SNAPSHOT</idmanager.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vpnmanager-impl</artifactId>
- <version>${project.version}</version>
+ <version>${vpnmanager.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vpnmanager-impl</artifactId>
- <version>${project.version}</version>
+ <version>${vpnmanager.version}</version>
<classifier>config</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vpnmanager-api</artifactId>
- <version>${project.version}</version>
+ <version>${vpnmanager.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>model-bgp</artifactId>
<version>2013.07.15.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>nexthopmgr-impl</artifactId>
+ <version>${nexthopmgr.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>nexthopmgr-impl</artifactId>
+ <version>${nexthopmgr.version}</version>
+ <classifier>config</classifier>
+ <type>xml</type>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>nexthopmgr-api</artifactId>
+ <version>${nexthopmgr.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fibmanager-impl</artifactId>
+ <version>${fibmanager.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fibmanager-impl</artifactId>
+ <version>${fibmanager.version}</version>
+ <classifier>config</classifier>
+ <type>xml</type>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fibmanager-api</artifactId>
+ <version>${fibmanager.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>idmanager-impl</artifactId>
+ <version>${idmanager.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>idmanager-impl</artifactId>
+ <version>${idmanager.version}</version>
+ <classifier>config</classifier>
+ <type>xml</type>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>idmanager-api</artifactId>
+ <version>${idmanager.version}</version>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<feature version='${yangtools.version}'>odl-yangtools-models</feature>
<feature version='${openflowplugin.version}'>odl-openflowplugin-nsf-model</feature>
<bundle>mvn:org.opendaylight.vpnservice/model-bgp/{{VERSION}}</bundle>
- <bundle>mvn:org.opendaylight.vpnservice/vpnmanager-api/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/vpnmanager-api/${vpnmanager.version}</bundle>
<bundle>mvn:org.opendaylight.vpnservice/interfacemgr-api/${interfacemgr.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/nexthopmgr-api/${nexthopmgr.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/idmanager-api/${idmanager.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/fibmanager-api/${fibmanager.version}</bundle>
<bundle>mvn:org.opendaylight.vpnservice/bgpmanager-api/${project.version}</bundle>
</feature>
<feature name='odl-vpnservice-impl' version='${project.version}' description='OpenDaylight :: vpnservice :: impl '>
<feature version='${mdsal.version}'>odl-mdsal-broker</feature>
<feature version='${project.version}'>odl-vpnservice-api</feature>
- <bundle>mvn:org.opendaylight.vpnservice/vpnmanager-impl/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/vpnmanager-impl/${vpnmanager.version}</bundle>
<bundle>mvn:org.opendaylight.vpnservice/interfacemgr-impl/${interfacemgr.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/nexthopmgr-impl/${nexthopmgr.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/idmanager-impl/${idmanager.version}</bundle>
+ <bundle>mvn:org.opendaylight.vpnservice/fibmanager-impl/${fibmanager.version}</bundle>
<bundle>mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version}</bundle>
<!--<bundle>mvn:org.opendaylight.vpnservice.third-party/org.apache.thriftlib/1.0.1-SNAPSHOT</bundle>-->
<bundle>wrap:mvn:org.apache.thrift/libthrift/0.9.1$overwrite=merge&Bundle-Version=0.9.1&Export-Package=*;-noimport:=true;version="0.9.1"</bundle>
<!--<bundle>wrap:mvn:javax.servlet/servlet-api/2.5</bundle>-->
- <configfile finalname="vpnmanager-impl-default-config.xml">mvn:org.opendaylight.vpnservice/vpnmanager-impl/${project.version}/xml/config</configfile>
+ <configfile finalname="vpnmanager-impl-default-config.xml">mvn:org.opendaylight.vpnservice/vpnmanager-impl/${vpnmanager.version}/xml/config</configfile>
<configfile finalname="interfacemgr-impl-default-config.xml">mvn:org.opendaylight.vpnservice/interfacemgr-impl/${interfacemgr.version}/xml/config</configfile>
+ <configfile finalname="nexthopmgr-impl-default-config.xml">mvn:org.opendaylight.vpnservice/nexthopmgr-impl/${nexthopmgr.version}/xml/config</configfile>
+ <configfile finalname="idmanager-impl-default-config.xml">mvn:org.opendaylight.vpnservice/idmanager-impl/${idmanager.version}/xml/config</configfile>
+ <configfile finalname="fibmanager-impl-default-config.xml">mvn:org.opendaylight.vpnservice/fibmanager-impl/${fibmanager.version}/xml/config</configfile>
<configfile finalname="bgpmanager-impl-default-config.xml">mvn:org.opendaylight.vpnservice/bgpmanager-impl/${project.version}/xml/config</configfile>
</feature>
<feature name='odl-vpnservice-impl-rest' version='${project.version}' description='OpenDaylight :: vpnservice :: impl :: REST '>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opendaylight.vpnservice</groupId>
<artifactId>fibmanager-api</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<properties>
<artifactId>yang-common</artifactId>
<version>${yangtools.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>yang-ext</artifactId>
+ <version>${yang.ext.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-inet-types</artifactId>
namespace "urn:opendaylight:vpnservice:l3nexthop";
prefix l3nexthop;
- revision "2015-03-30" {
+ revision "2015-04-09" {
description "L3 NextHop module";
}
container l3nexthop {
+ config false;
list vpnNexthops{
key "vpnId";
leaf vpnId {type uint32;}
list vpnNexthop{
key "IpAddress";
leaf IpAddress {type string;}
- leaf dpnId {type uint32;}
leaf egressPointer {type uint32;}
}
}
- list genNexthops{
- key "IpAddress";
- leaf IpAddress {type string;}
+ list tunnelNexthops{
+ key "dpnId";
leaf dpnId {type uint32;}
- leaf egressPointer {type uint32;}
+ list tunnelNexthop{
+ key "IpAddress";
+ leaf IpAddress {type string;}
+ leaf egressPointer {type uint32;}
+ }
}
}
+
rpc getEgressPointer {
description "returns egress pointer, an OF Group Id";
input {
leaf dpnId {type uint32;}
leaf vpnId { type uint32;} /* optional */
- leaf ipAddress{type string;}
+ leaf ipPrefix {type string;}
+ leaf nexthopIp {type string;}
}
output {
leaf egressPointer {type uint32;}
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>nexthopmgr-api</artifactId>
+ <artifactId>vpnmanager-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>interfacemgr-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>vpnmanager-api</artifactId>
+ <artifactId>nexthopmgr-api</artifactId>
<version>${project.version}</version>
</dependency>
* AbstractDataChangeListener implemented basic {@link DataChangeListener} processing for
* VPN related Data Objects.
*/
-public abstract class AbstractDataChangeListener <T extends DataObject> implements DataChangeListener {
+public abstract class AbstractDataChangeListener<T extends DataObject> implements DataChangeListener {
protected final Class<T> clazz;
/* All DataObjects for create */
final Map<InstanceIdentifier<?>, DataObject> createdData = changeEvent.getCreatedData() != null
- ? changeEvent.getCreatedData() : Collections.<InstanceIdentifier<?>, DataObject> emptyMap();
+ ? changeEvent.getCreatedData() : Collections.<InstanceIdentifier<?>, DataObject>emptyMap();
/* All DataObjects for remove */
final Set<InstanceIdentifier<?>> removeData = changeEvent.getRemovedPaths() != null
? changeEvent.getRemovedPaths() : Collections.<InstanceIdentifier<?>> emptySet();
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.vpnservice.nexthopmgr;
-/**********************************************************************************
-** NextHop MD-SAL DS
-** ------------------------------------------------
-** DP_ID | VPN | IP Address | GroupId |
-** ------------------------------------------------
-**
-** Listen to DCNs from vpn-inetrfaces
-** if a next-hop is added/removed in vpn-interfaces DS
-** call add/removeNextHop(interface.dpn, interface.port, vpn_instance.vpnId, AdjacencyIpAddress);
-**
-** if a tunnel-interface is added inn interfaces DS --
-** call add/removeNextHop(interface.dpn, interface.port, 00, RemoteIpAddress);
-*************************************************************************************/
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-import java.util.List;
-import com.google.common.base.Optional;
-import com.google.common.collect.FluentIterable;
+import com.google.common.base.Optional;
+import java.util.concurrent.Future;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.FutureCallback;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
-/*import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.NextHopList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.next.hop.list.L3NextHops;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.VpnInterface1;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
-*/
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150330.L3nexthop;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150330.l3nexthop.VpnNexthops;
-
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.VpnInstance1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.l3nexthop.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.l3nexthop.tunnelnexthops.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.l3nexthop.rev150409.l3nexthop.vpnnexthops.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NexthopManager extends AbstractDataChangeListener<L3nexthop> implements AutoCloseable{
- private static final Logger LOG = LoggerFactory.getLogger(L3nexthop.class);
- private ListenerRegistration<DataChangeListener> listenerRegistration;
+public class NexthopManager implements L3nexthopService, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NexthopManager.class);
private final DataBroker broker;
+ private static final FutureCallback<Void> DEFAULT_CALLBACK =
+ new FutureCallback<Void>() {
+ public void onSuccess(Void result) {
+ LOG.info("Success in Datastore write operation");
+ }
+ public void onFailure(Throwable error) {
+ LOG.error("Error in Datastore write operation", error);
+ };
+ };
+
+ /**
+ * Provides nexthop functions
+ * Creates group ID pool
+ *
+ * @param db - dataBroker reference
+ */
public NexthopManager(final DataBroker db) {
- super(L3nexthop.class);
+ // create nexhhop ID pool
+ // getIdManager.createIdPool("nextHopGroupIdPool", 10000, 100000);
broker = db;
- registerListener(db);
}
- @Override
+
+ @Override
public void close() throws Exception {
- if (listenerRegistration != null) {
- try {
- listenerRegistration.close();
- } catch (final Exception e) {
- LOG.error("Error when cleaning up DataChangeListener.", e);
- }
- listenerRegistration = null;
+ LOG.info("NextHop Manager Closed");
+ }
+
+
+ public void createLocalNextHop(String ifName, String vpnName, String ipAddress)
+ {
+ String nhKey = new String("nexthop." + vpnName + ipAddress);
+ int groupId = 1;//getIdManager().getUniqueId("nextHopGroupIdPool", nhKey);
+
+ long vpnId = getVpnId(vpnName);
+ VpnNexthop nexthop = getVpnNexthop(vpnId, ipAddress);
+ if (nexthop == null) {
+
+ /* List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
+ List<ActionInfo> listActionInfo = interfacemgr.getEgressGroupActions(ifName);
+ BucketInfo bucket = new BucketInfo(listActionInfo);
+ // MAC re-write??
+ listBucketInfo.add(bucket);
+ GroupEntity groupEntity = MDSALUtil.buildGroupEntity
+ (dpId, groupId, IPAddress, GroupTypes.GroupIndirect, listBucketInfo);
+ getMdsalApiManager().installGroup(groupEntity, objTransaction???);
+ */
+
+ //update MD-SAL DS
+ addVpnNexthopToDS(vpnId, ipAddress, groupId);
+ } else {
+ //check update
+ }
+ }
+
+ private long getVpnId(String vpnName) {
+ InstanceIdentifierBuilder<VpnInstance> idBuilder = InstanceIdentifier.builder(VpnInstances.class)
+ .child(VpnInstance.class, new VpnInstanceKey(vpnName));
+
+ InstanceIdentifier<VpnInstance> id = idBuilder.build();
+ InstanceIdentifier<VpnInstance1> idx = id.augmentation(VpnInstance1.class);
+ Optional<VpnInstance1> vpn = read(LogicalDatastoreType.CONFIGURATION, idx);
+
+ if (vpn.isPresent()) return vpn.get().getVpnId();
+ else return 0;
+ }
+
+ private long getDpnId(String ifName) {
+ return 1;
+ }
+
+ public void createRemoteNextHop(String ifName, String ipAddress)
+ {
+ String nhKey = new String("nexthop." + ifName + ipAddress);
+ int groupId = 1;//getIdManager().getUniqueId("nextHopGroupIdPool", nhKey);
+
+ long dpnId = getDpnId(ifName);
+ TunnelNexthop nexthop = getTunnelNexthop(dpnId, ipAddress);
+ if (nexthop == null) {
+
+ /* List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
+ List<ActionInfo> listActionInfo = interfacemgr.getEgressGroupActions(ifName);
+ BucketInfo bucket = new BucketInfo(listActionInfo);
+ // MAC re-write??
+ listBucketInfo.add(bucket);
+ GroupEntity groupEntity = MDSALUtil.buildGroupEntity
+ (dpId, groupId, IPAddress, GroupTypes.GroupIndirect, listBucketInfo);
+ getMdsalApiManager().installGroup(groupEntity, objTransaction???);
+ */
+
+ //update MD-SAL DS
+ addTunnelNexthopToDS(dpnId, ipAddress, groupId);
+ } else {
+ //check update
}
- LOG.info("VPN Interface Manager Closed");
}
+ private void addVpnNexthopToDS(long vpnId, String ipPrefix, long egressPointer){
+
+
+ InstanceIdentifierBuilder<VpnNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
+ .child(VpnNexthops.class, new VpnNexthopsKey(vpnId));
+
+ // check if vpn node is there or to be created
+ InstanceIdentifier<VpnNexthops> id = idBuilder.build();
+ Optional<VpnNexthops> nexthops = read(LogicalDatastoreType.CONFIGURATION, id);
+ if (!nexthops.isPresent()) {
+ // create a new node
+ VpnNexthops node = new VpnNexthopsBuilder().setKey(new VpnNexthopsKey(vpnId)).setVpnId(vpnId).build();
+ asyncWrite(LogicalDatastoreType.OPERATIONAL, id, node, DEFAULT_CALLBACK);
+ }
+
+ // Add nexthop to vpn node
+ VpnNexthop nh = new VpnNexthopBuilder().
+ setKey(new VpnNexthopKey(ipPrefix)).
+ setIpAddress(ipPrefix).
+ setEgressPointer(egressPointer).build();
+
+ InstanceIdentifier<VpnNexthop> id1 = idBuilder
+ .child(VpnNexthop.class, new VpnNexthopKey(ipPrefix)).build();
- private void registerListener(final DataBroker db) {
+ asyncWrite(LogicalDatastoreType.OPERATIONAL, id1, nh, DEFAULT_CALLBACK);
+
+ }
+
+ private void addTunnelNexthopToDS(long dpnId, String ipPrefix, long egressPointer){
+ InstanceIdentifierBuilder<TunnelNexthops> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
+ .child(TunnelNexthops.class, new TunnelNexthopsKey(dpnId));
+
+ // check if dpn node is there or to be created
+ InstanceIdentifier<TunnelNexthops> id = idBuilder.build();
+ Optional<TunnelNexthops> nexthops = read(LogicalDatastoreType.CONFIGURATION, id);
+ if (!nexthops.isPresent()) {
+ // create a new node
+ TunnelNexthops node = new TunnelNexthopsBuilder().setKey(new TunnelNexthopsKey(dpnId)).setDpnId(dpnId).build();
+ asyncWrite(LogicalDatastoreType.OPERATIONAL, id, node, DEFAULT_CALLBACK);
+ }
+
+ // Add nexthop to dpn node
+ TunnelNexthop nh = new TunnelNexthopBuilder().
+ setKey(new TunnelNexthopKey(ipPrefix)).
+ setIpAddress(ipPrefix).
+ setEgressPointer(egressPointer).build();
+
+ InstanceIdentifier<TunnelNexthop> id1 = idBuilder
+ .child(TunnelNexthop.class, new TunnelNexthopKey(ipPrefix)).build();
+
+ asyncWrite(LogicalDatastoreType.OPERATIONAL, id1, nh, DEFAULT_CALLBACK);
+
+ }
+
+ private VpnNexthop getVpnNexthop(long vpnId, String ipAddress) {
+
+ InstanceIdentifierBuilder<VpnNexthop> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
+ .child(VpnNexthops.class, new VpnNexthopsKey(vpnId))
+ .child(VpnNexthop.class, new VpnNexthopKey(ipAddress));
+ InstanceIdentifier<VpnNexthop> id = idBuilder.build();
+ Optional<VpnNexthop> nextHop = read(LogicalDatastoreType.CONFIGURATION, id);
+
+ if(nextHop.isPresent()) return nextHop.get();
+ else return null;
+ }
+
+ private TunnelNexthop getTunnelNexthop(long dpnId, String ipAddress) {
+ InstanceIdentifierBuilder<TunnelNexthop> idBuilder = InstanceIdentifier.builder(L3nexthop.class)
+ .child(TunnelNexthops.class, new TunnelNexthopsKey(dpnId))
+ .child(TunnelNexthop.class, new TunnelNexthopKey(ipAddress));
+ InstanceIdentifier<TunnelNexthop> id = idBuilder.build();
+ Optional<TunnelNexthop> nextHop = read(LogicalDatastoreType.CONFIGURATION, id);
+
+ if(nextHop.isPresent()) return nextHop.get();
+ else return null;
+ }
+
+ public long getNextHopPointer(long dpnId, long vpnId, String prefixIp, String nextHopIp) {
+ String endpointIp = "10.10.10.1";//interfaceManager.getLocalEndpointIp(dpnId);
+ if (nextHopIp.equals(endpointIp)) {
+ VpnNexthop vpnNextHop = getVpnNexthop(vpnId, prefixIp);
+ return vpnNextHop.getEgressPointer();
+ } else {
+ TunnelNexthop tunnelNextHop = getTunnelNexthop(dpnId, nextHopIp);
+ return tunnelNextHop.getEgressPointer();
+ }
+ }
+
+ public void removeRemoteNextHop(String ifname, String IpAddress)
+ {
+ String nhKey = new String("nexthop" + ifname + IpAddress);
+ int groupId = 1;//getIdManager().getUniqueId(L3Constants.L3NEXTHOP_GROUPID_POOL, nhKey);
+
+/* if (getNextHop(groupId) != Null){
+ List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
+ List<ActionInfo> listActionInfo = null;//nextHop.getActions({output to port});
+ BucketInfo bucket = new BucketInfo(listActionInfo);
+ listBucketInfo.add(bucket);
+ //GroupEntity groupEntity = MDSALUtil.buildGroupEntity
+ (dpId, groupId, IPAddress, GroupTypes.GroupIndirect, listBucketInfo);
+ //getMdsalApiManager().removeGroup(groupEntity, objTransaction???);
+
+ //update MD-SAL DS
+ removeNextHopFromDS(dpId, vpn, ipAddress);
+ }else{
+ //check update
+ }*/
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
try {
- listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- getWildCardPath(), NexthopManager.this, DataChangeScope.SUBTREE);
- } catch (final Exception e) {
- LOG.error("Nexthop Manager DataChange listener registration fail!", e);
- throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
+
+ return result;
}
-
- public void addNextHop(long dpnId, int port, String vpnRD, String IpAddress)
- {
- String nhKey = new String("nexthop"+vpnRD+IpAddress);
-
- int groupId = 1;//getIdManager().getUniqueId("nextHopGroupIdPool", nhKey);
-
-/* if (getNextHop(groupId) == Null){
- List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
- List<ActionInfo> listActionInfo = null;//nextHop.getActions({output to port});
- BucketInfo bucket = new BucketInfo(listActionInfo);
- listBucketInfo.add(bucket);
- //GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpId, groupId, IPAddress, GroupTypes.GroupIndirect, listBucketInfo);
- //getMdsalApiManager().installGroup(groupEntity, objTransaction???);
-
- //update MD-SAL DS
- addNextHopToDS(dpId, vpn, ipAddress, groupId);
- }else{
- //check update
- }*/
- }
-
- public void removeNextHop(long dpnId, int port, String vpnRD, String IpAddress)
- {
- String nhKey = new String("nexthop"+vpnRD+IpAddress);
- int groupId = 1;//getIdManager().getUniqueId(L3Constants.L3NEXTHOP_GROUPID_POOL, nhKey);
-
-/* if (getNextHop(groupId) != Null){
- List<BucketInfo> listBucketInfo = new ArrayList<BucketInfo>();
- List<ActionInfo> listActionInfo = null;//nextHop.getActions({output to port});
- BucketInfo bucket = new BucketInfo(listActionInfo);
- listBucketInfo.add(bucket);
- //GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpId, groupId, IPAddress, GroupTypes.GroupIndirect, listBucketInfo);
- //getMdsalApiManager().removeGroup(groupEntity, objTransaction???);
-
- //update MD-SAL DS
- removeNextHopFromDS(dpId, vpn, ipAddress);
- }else{
- //check update
- }*/
- }
-
- public long getNextHopPointer(long dpnId, int vpnId, String prefixIp, String nxetHopIp)
- {
-/* String endpointIp = interfaceManager.getLocalEndpointIp(dpnId);
- if (nextHopIp.equals(endpointIp)) {
- return getGidFromDS(dpnId, vpnId, prefixIp);
- } else {
- return getGidFromDS(dpnId, 00, nextHopIp);
- }*/
- return 0;
- }
-
- private InstanceIdentifier<L3nexthop> getWildCardPath() {
- return InstanceIdentifier.create(L3nexthop.class);//.child(l3nexthop.vpnNexthops.class);
+
+ private <T extends DataObject> void asyncWrite(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path, T data, FutureCallback<Void> callback) {
+ WriteTransaction tx = broker.newWriteOnlyTransaction();
+ tx.put(datastoreType, path, data, true);
+ Futures.addCallback(tx.submit(), callback);
}
- private void addNextHopToDS(long dpId, int vpnId, String ipAddress, long groupId)
- {
-
- }
-
- private long getGidFromDS(String ipaddress)
- {
- return 0;
-
- }
-
- @Override
- protected void remove(InstanceIdentifier<L3nexthop> identifier,
- L3nexthop del) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- protected void update(InstanceIdentifier<L3nexthop> identifier,
- L3nexthop original, L3nexthop update) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- protected void add(InstanceIdentifier<L3nexthop> identifier, L3nexthop add) {
- // TODO Auto-generated method stub
-
- }
+
+ @Override
+ public Future<RpcResult<GetEgressPointerOutput>> getEgressPointer(
+ GetEgressPointerInput input) {
+ long egressGroupId =
+ getNextHopPointer(input.getDpnId(), input.getVpnId(), input.getIpPrefix(), input.getNexthopIp());
+
+ GetEgressPointerOutputBuilder output = new GetEgressPointerOutputBuilder();
+ output.setEgressPointer(egressGroupId);
+
+ /*RpcResult<GetEgressPointerOutput> result = Rpcs.<GetEgressPointerOutput> getRpcResult(false, output.build());
+ return Futures.immediateFuture(result);*/
+ return null;
+ }
}
\ No newline at end of file
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.opendaylight.vpnservice.nexthopmgr.NexthopManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NexthopmgrProvider implements BindingAwareProvider,
- AutoCloseable {
+public class NexthopmgrProvider implements BindingAwareProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NexthopmgrProvider.class);
- // private nexthopmgr nhManager;
+ private VpnInterfaceChangeListener vpnIfListener;
+ private OdlInterfaceChangeListener odlIfListener;
+ private NexthopManager nhManager;
@Override
public void onSessionInitiated(ProviderContext session) {
- final DataBroker dataBroker = session.getSALService(DataBroker.class);
- // nhManager = new nexthopManager(dataBroker);
- LOG.info("NexthopmgrProvider Session Initiated");
+ final DataBroker dbx = session.getSALService(DataBroker.class);
+ nhManager = new NexthopManager(dbx);
+ vpnIfListener = new VpnInterfaceChangeListener(dbx, nhManager);
+ odlIfListener = new OdlInterfaceChangeListener(dbx, nhManager);
+ LOG.info("NexthopmgrProvider Session Initiated");
}
@Override
public void close() throws Exception {
- //nhManager.close();
- LOG.info("NexthopmgrProvider Closed");
+ vpnIfListener.close();
+ odlIfListener.close();
+ nhManager.close();
+ LOG.info("NexthopmgrProvider Closed");
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.nexthopmgr;
+
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.L3tunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL3tunnel;
+
+import org.opendaylight.vpnservice.nexthopmgr.AbstractDataChangeListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class OdlInterfaceChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(OdlInterfaceChangeListener.class);
+
+ private ListenerRegistration<DataChangeListener> listenerRegistration;
+ private final DataBroker broker;
+ private NexthopManager nexthopManager;
+
+ public OdlInterfaceChangeListener(final DataBroker db, NexthopManager nhm) {
+ super(Interface.class);
+ broker = db;
+ nexthopManager = nhm;
+ registerListener(db);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (listenerRegistration != null) {
+ try {
+ listenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up DataChangeListener.", e);
+ }
+ listenerRegistration = null;
+ }
+ LOG.info("odlInterface listener Closed");
+ }
+
+
+ private void registerListener(final DataBroker db) {
+ try {
+ listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+ getWildCardPath(), OdlInterfaceChangeListener.this, DataChangeScope.SUBTREE);
+ } catch (final Exception e) {
+ LOG.error("Nexthop Manager Interfaces DataChange listener registration fail!", e);
+ throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
+ }
+ }
+
+ @Override
+
+ protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
+ LOG.info("key: " + identifier + ", value=" + intrf );
+
+ if (intrf.getType().equals(L3tunnel.class)) {
+ IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
+ String gwIp = intfData.getGatewayIp().toString();
+ String remoteIp = intfData.getRemoteIp().toString();
+ if (gwIp != null) {
+ remoteIp = gwIp;
+ }
+ nexthopManager.createRemoteNextHop(intrf.getName(), remoteIp);
+ }
+ }
+
+
+ private InstanceIdentifier<Interface> getWildCardPath() {
+ return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<Interface> identifier,
+ Interface intrf) {
+ if (intrf.getType().equals(L3tunnel.class)) {
+ IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
+ String gwIp = intfData.getGatewayIp().toString();
+ String remoteIp = intfData.getRemoteIp().toString();
+ if (gwIp != null) {
+ remoteIp = gwIp;
+ }
+ nexthopManager.removeRemoteNextHop(intrf.getName(), remoteIp);
+ }
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<Interface> identifier,
+ Interface original, Interface update) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.nexthopmgr;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import com.google.common.base.Optional;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.list.Adjacency;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
+import org.opendaylight.vpnservice.nexthopmgr.AbstractDataChangeListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class VpnInterfaceChangeListener extends AbstractDataChangeListener<VpnInterface> implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(VpnInterfaceChangeListener.class);
+
+ private ListenerRegistration<DataChangeListener> listenerRegistration;
+ private final DataBroker broker;
+ private NexthopManager nexthopManager;
+
+ public VpnInterfaceChangeListener(final DataBroker db, NexthopManager nhm) {
+ super(VpnInterface.class);
+ broker = db;
+ nexthopManager = nhm;
+ registerListener(db);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (listenerRegistration != null) {
+ try {
+ listenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up DataChangeListener.", e);
+ }
+ listenerRegistration = null;
+ }
+ LOG.info("VPN Interface Manager Closed");
+ }
+
+
+ private void registerListener(final DataBroker db) {
+ try {
+ listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+ getWildCardPath(), VpnInterfaceChangeListener.this, DataChangeScope.SUBTREE);
+ } catch (final Exception e) {
+ LOG.error("Nexthop Manager DataChange listener registration fail!", e);
+ throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
+ }
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<VpnInterface> identifier,
+ VpnInterface vpnIf) {
+ LOG.info("key: " + identifier + ", value=" + vpnIf );
+
+ String vpnName = vpnIf.getVpnInstanceName();
+ final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
+ String interfaceName = key.getName();
+ InstanceIdentifierBuilder<Interface> idBuilder =
+ InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(interfaceName));
+ InstanceIdentifier<Interface> id = idBuilder.build();
+ Optional<Interface> port = read(LogicalDatastoreType.CONFIGURATION, id);
+ if (port.isPresent()) {
+ //Interface interf = port.get();
+
+ //Read NextHops
+ InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
+ Optional<Adjacencies> adjacencies = read(LogicalDatastoreType.CONFIGURATION, path);
+
+ if (adjacencies.isPresent()) {
+ List<Adjacency> nextHops = adjacencies.get().getAdjacency();
+ List<Adjacency> value = new ArrayList<>();
+
+ if (!nextHops.isEmpty()) {
+ LOG.info("NextHops are " + nextHops);
+ for (Adjacency nextHop : nextHops) {
+ nexthopManager.createLocalNextHop(interfaceName, vpnName, nextHop.getIpAddress());
+ }
+ }
+ }
+ }
+
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ private InstanceIdentifier<VpnInterface> getWildCardPath() {
+ return InstanceIdentifier.create(VpnInterfaces.class).child(VpnInterface.class);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<VpnInterface> identifier,
+ VpnInterface del) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<VpnInterface> identifier,
+ VpnInterface original, VpnInterface update) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
\ No newline at end of file
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>odlparent</artifactId>
<version>1.5.0-SNAPSHOT</version>
- <relativePath/>
+ <relativePath/>
</parent>
<groupId>org.opendaylight.vpnservice</groupId>
<modules>
<module>model-bgp</module>
<module>vpnmanager</module>
- <module>distribution/karaf</module>
- <module>features</module>
- <module>vpnservice-artifacts</module>
<module>interfacemgr</module>
<module>nexthopmgr</module>
<module>idmanager</module>
<module>fibmanager</module>
<module>mdsalutil</module>
<module>bgpmanager</module>
+ <module>distribution/karaf</module>
+ <module>features</module>
+ <module>vpnservice-artifacts</module>
</modules>
<!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
<dependencyManagement>
<dependencies>
- <dependency>
+ <!--<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vpnmanager-api</artifactId>
<version>${project.version}</version>
<groupId>${project.groupId}</groupId>
<artifactId>vpnmanager-impl</artifactId>
<version>${project.version}</version>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vpnservice-features</artifactId>