Merge "Implemented new RPCs, add/delete int/ext I/f name"
authorVivek Srivastava <vivek.v.srivastava@ericsson.com>
Thu, 14 Jan 2016 10:20:48 +0000 (10:20 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 14 Jan 2016 10:20:48 +0000 (10:20 +0000)
itm/itm-api/.gitignore [new file with mode: 0644]
itm/itm-api/src/main/yang/itm-rpc.yang
itm/itm-api/src/main/yang/itm-state.yang
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java
itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java

diff --git a/itm/itm-api/.gitignore b/itm/itm-api/.gitignore
new file mode 100644 (file)
index 0000000..b49c563
--- /dev/null
@@ -0,0 +1,4 @@
+/target/
+/target/
+/target/
+/target/
index 69e1ea9bd8e8111ca46a19f7117f02ea7656b48d..2347e6eb055a472dedc967c4e85e9a7a82f73598 100644 (file)
@@ -47,6 +47,23 @@ module itm-rpc {
         }
     }
 
+    rpc get-internal-or-external-interface-name {
+        description "used to retrieve tunnel interface id with src Dpn and destination ip";
+            input {
+                leaf source-dpid {
+                type uint64;
+                }
+                leaf destination-ip {
+                type inet:ip-address;
+                }
+            }
+            output {
+                leaf interface-name {
+                    type string;
+                }
+        }
+    }
+
     rpc get-external-tunnel-interface-name {
         description "used to retrieve tunnel interface id between Dpns";
         input {
@@ -111,7 +128,7 @@ module itm-rpc {
         }
      }
 
-     rpc remove-external-tunnel-endpoint { 
+     rpc remove-external-tunnel-endpoint {
         description "used for building tunnels between teps on all Dpns and external node";
         input {
             leaf destination-ip {
@@ -129,7 +146,7 @@ module itm-rpc {
          description  "used for programming the terminating service actions";
          input {
              leaf dpn-id {
-               type uint64;  
+               type uint64;
              }
              leaf service-id {
                 type uint16;
@@ -142,7 +159,7 @@ module itm-rpc {
               description  "used for removing the terminating service actions";
               input {
                   leaf dpn-id {
-                    type uint64;  
+                    type uint64;
                   }
                   leaf service-id {
                      type uint16;
index ea54594c351f00b4658e850967002d6cd7b9f4f2..ca39c03eda5c66365aa14b392680a80a069cee92 100644 (file)
@@ -79,7 +79,7 @@ module itm-state {
 
 
       container tunnel-list {
-             list tunnel {
+             list internal-tunnel {
 
                key  "source-DPN destination-DPN";
 
@@ -98,7 +98,7 @@ module itm-state {
                }
              }
           }
-          
+
       container external-tunnel-list {
              list external-tunnel {
 
@@ -120,7 +120,7 @@ module itm-state {
 
              }
           }
-          
+
           notification itm-tunnel-build-complete{
           }
 
index c44e96a28157e2c0315f67ad1b22a4fbc0db97d7..54277d4a6b5a8a7b7bea1a780d5a891b926fcf41 100644 (file)
@@ -66,22 +66,18 @@ public class ItmExternalTunnelAddWorker {
               IpAddress gwyIpAddress = (utils.getInfo().isInRange(dcGwyIpStr) ) ? null : firstEndPt.getGwIpAddress() ;
               String ifDescription = tunType.getName();
               logger.debug(  " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, DC Gateway IP - {} gateway IP - {}",trunkInterfaceName, interfaceName, firstEndPt.getIpAddress(), extIp, gwyIpAddress ) ;
-              Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress) ;
+              Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress, false) ;
               logger.debug(  " Trunk Interface builder - {} ", iface ) ;
               InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
               logger.debug(  " Trunk Interface Identifier - {} ", trunkIdentifier ) ;
               logger.trace(  " Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface ) ;
-              //ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION,trunkIdentifier, iface , dataBroker, ItmUtils.DEFAULT_CALLBACK);
               t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
-       //       update_external_tunnels_ds(teps.getDPNID(), extIp, trunkInterfaceName, tunType);
+              // update external_tunnel_list ds  
               InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
                       ExternalTunnelList.class)
-                          .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));   
-              ExternalTunnel tnl = new ExternalTunnelBuilder().setKey(new ExternalTunnelKey(extIp, teps.getDPNID()))
-                                             .setDestinationIP(extIp)
-                                             .setSourceDPN(teps.getDPNID())
-                                             .setTunnelInterfaceName(trunkInterfaceName).build();
-              ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+                          .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));
+              ExternalTunnel tnl = ItmUtils.buildExternalTunnel(teps.getDPNID(), extIp, trunkInterfaceName);
+              t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
           }
           futures.add( t.submit()) ;
        }
@@ -91,18 +87,8 @@ public class ItmExternalTunnelAddWorker {
     public static List<ListenableFuture<Void>> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService,
                                                                                      List<BigInteger> dpnId, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
         List<ListenableFuture<Void>> futures = new ArrayList<>();
-        List<DPNTEPsInfo> cfgDpnList = new ArrayList<DPNTEPsInfo>() ;
-        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
-        if( null != meshedDpnList) {
-          for (BigInteger dpn : dpnId){
-                 for( DPNTEPsInfo teps : meshedDpnList ) {
-                     if( teps.getDPNID().equals(dpn)) {
-                        cfgDpnList.add(teps) ;
-                     }
-                  }
-          }
+        List<DPNTEPsInfo> cfgDpnList =( dpnId == null ) ? ItmUtils.getTunnelMeshInfo(dataBroker) :ItmUtils.getDPNTEPListFromDPNId(dataBroker, dpnId) ;
           futures = buildTunnelsToExternalEndPoint( dataBroker, idManagerService, cfgDpnList, extIp, tunType) ;
-       }
         return futures ;
     }
 }
index b976155d7d12386f73f095ec4fef5fd56df0d7d7..81f6aaefbe0a6bbd8fd36c7b98bc715e26b1a961 100644 (file)
@@ -16,9 +16,13 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 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.idmanager.rev150403.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,8 +32,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 public class ItmExternalTunnelDeleteWorker {
     private static final Logger logger = LoggerFactory.getLogger(ItmExternalTunnelDeleteWorker.class ) ;
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService,
-                                                             List<DPNTEPsInfo> dpnTepsList, IpAddress extIp ) {
+    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService, List<DPNTEPsInfo> dpnTepsList,IpAddress extIp, Class<? extends TunnelTypeBase> tunType ) {
         logger.trace( " Delete Tunnels towards DC Gateway with Ip  {}", extIp ) ;
         List<ListenableFuture<Void>> futures = new ArrayList<>();
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
@@ -40,10 +43,19 @@ public class ItmExternalTunnelDeleteWorker {
             }
             for( DPNTEPsInfo teps : dpnTepsList) {
                 TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
-                String interfaceName = firstEndPt.getInterfaceName() ;
-                String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
-                InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
-                t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+                if( firstEndPt.getTunnelType().equals(tunType)) {
+                    String interfaceName = firstEndPt.getInterfaceName() ;
+                    String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ;
+                    InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
+                    t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+                    InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
+                            ExternalTunnelList.class)
+                                .child(ExternalTunnel.class, new ExternalTunnelKey(extIp, teps.getDPNID()));
+                    t.delete(LogicalDatastoreType.CONFIGURATION, path);
+                    // Release the Ids for the trunk interface
+                    ItmUtils.releaseId(idManagerService, trunkInterfaceName);
+                }
             }
             futures.add(t.submit()) ;
         return futures ;
index faa2c6bf1efac0c6e6dc3b8d4ced67e0551d9957..bde34d017104f5c85d67f14b71542f2bf87c5fb8 100644 (file)
@@ -33,9 +33,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.slf4j.Logger;
@@ -150,21 +149,19 @@ public class ItmInternalTunnelAddWorker {
         String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName,srcte.getIpAddress().getIpv4Address().getValue(), dstte.getIpAddress().getIpv4Address().getValue()) ;
         IpAddress gwyIpAddress = ( srcte.getSubnetMask().equals(dstte.getSubnetMask()) ) ? null : srcte.getGwIpAddress() ;
         logger.debug(  " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}",trunkInterfaceName, interfaceName, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress ) ;
-        Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress) ;
+        Interface iface = ItmUtils.buildTunnelInterface(srcDpnId, trunkInterfaceName, String.format( "%s %s",ifDescription, "Trunk Interface"), true, tunType, srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress, true) ;
         logger.debug(  " Trunk Interface builder - {} ", iface ) ;
         InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
         logger.debug(  " Trunk Interface Identifier - {} ", trunkIdentifier ) ;
         logger.trace(  " Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface ) ;
         t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
         // also update itm-state ds?
-        InstanceIdentifier<Tunnel> path = InstanceIdentifier.create(
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
                 TunnelList.class)
-                    .child(Tunnel.class, new TunnelKey(dstDpnId, srcDpnId));   
-        Tunnel tnl = new TunnelBuilder().setKey(new TunnelKey(dstDpnId, srcDpnId))
-                                       .setDestinationDPN(dstDpnId)
-                                       .setSourceDPN(srcDpnId)
-                                       .setTunnelInterfaceName(trunkInterfaceName).build();
-        ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+                    .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
+        InternalTunnel tnl = ItmUtils.buildInternalTunnel(srcDpnId, dstDpnId, trunkInterfaceName);
+        //ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tnl, dataBroker, DEFAULT_CALLBACK);
+        t.merge(LogicalDatastoreType.CONFIGURATION,path, tnl, true) ;
         return true;
     }
 
index cb0b23f1d86368c7aa2b602119f2f3a2b0a2b8d6..096d81cffdec780ed96d74ee54cc12be3022ffa4 100644 (file)
@@ -19,8 +19,11 @@ import org.opendaylight.vpnservice.itm.impl.ItmUtils;
 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.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.DpnEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -121,6 +124,15 @@ public class ItmInternalTunnelDeleteWorker {
         InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
         logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+        // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list
+        InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                TunnelList.class)
+                    .child(InternalTunnel.class, new InternalTunnelKey( srcDpnId, dstDpnId));   
+        t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+        // Release the Id for the forward trunk
+        ItmUtils.releaseId(idManagerService, trunkfwdIfName);
+
         String trunkRevIfName =
                         ItmUtils.getTrunkInterfaceName(idManagerService, dstTep.getInterfaceName(), dstTep.getIpAddress()
                                         .getIpv4Address().getValue(), srcTep.getIpAddress().getIpv4Address()
@@ -129,5 +141,14 @@ public class ItmInternalTunnelDeleteWorker {
         trunkIdentifier = ItmUtils.buildId(trunkfwdIfName);
         logger.debug(  " Removing Trunk Interface Name - {} , Id - {} from Config DS {}, {} ", trunkfwdIfName, trunkIdentifier ) ;
         t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+
+     // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list
+        path = InstanceIdentifier.create(
+                TunnelList.class)
+                    .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId));   
+        t.delete(LogicalDatastoreType.CONFIGURATION,path) ;
+        
+        // Release the Id for the Reverse trunk
+        ItmUtils.releaseId(idManagerService, trunkRevIfName);
     }
 }
index 74d143c4da4ab149b1846813865d27597ed182ae..0750ea479213dc7f63648f453a25b4f7aa7fc320 100644 (file)
@@ -40,6 +40,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPointsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@@ -169,17 +175,30 @@ public class ItmUtils {
     }
 
     public static Interface buildTunnelInterface(BigInteger dpn, String ifName, String desc, boolean enabled, Class<? extends TunnelTypeBase> tunType,
-       IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp) {
+       IpAddress localIp, IpAddress remoteIp, IpAddress gatewayIp, boolean internal) {
        InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(ifName)).setName(ifName)
        .setDescription(desc).setEnabled(enabled).setType(Tunnel.class);
        ParentRefs parentRefs = new ParentRefsBuilder().setDatapathNodeIdentifier(dpn).build();
        builder.addAugmentation(ParentRefs.class, parentRefs);
        IfTunnel tunnel = new IfTunnelBuilder().setTunnelDestination(remoteIp).setTunnelGateway(gatewayIp).setTunnelSource(localIp)
-       .setTunnelInterfaceType( tunType).build();
+       .setTunnelInterfaceType( tunType).setInternal(internal).build();
        builder.addAugmentation(IfTunnel.class, tunnel);
        return builder.build();
     }
 
+    public static InternalTunnel buildInternalTunnel( BigInteger srcDpnId, BigInteger dstDpnId, String trunkInterfaceName) {
+        InternalTunnel tnl = new InternalTunnelBuilder().setKey(new InternalTunnelKey(srcDpnId, dstDpnId))
+            .setDestinationDPN(dstDpnId)
+            .setSourceDPN(srcDpnId)
+            .setTunnelInterfaceName(trunkInterfaceName).build();
+        return tnl ;
+    }
+
+    public static ExternalTunnel buildExternalTunnel( BigInteger srcDpnId, IpAddress dstIp, String trunkInterfaceName) {
+        ExternalTunnel extTnl = new ExternalTunnelBuilder().setKey(new ExternalTunnelKey(dstIp, srcDpnId)).setSourceDPN(srcDpnId).setDestinationIP(dstIp).setTunnelInterfaceName(trunkInterfaceName).build();
+        return extTnl ;
+    }
+
     public static List<DPNTEPsInfo> getTunnelMeshInfo(DataBroker dataBroker) {
         List<DPNTEPsInfo> dpnTEPs= null ;
 
@@ -227,4 +246,18 @@ public class ItmUtils {
             LOG.warn("Exception when getting Unique Id for key {}", idKey, e);
         }
     }
+
+    public static List<DPNTEPsInfo> getDPNTEPListFromDPNId(DataBroker dataBroker, List<BigInteger> dpnIds) {
+        List<DPNTEPsInfo> meshedDpnList = getTunnelMeshInfo(dataBroker) ;
+        List<DPNTEPsInfo> cfgDpnList = new ArrayList<DPNTEPsInfo>();
+        if( null != meshedDpnList) {
+           for(BigInteger dpnId : dpnIds) {
+              for( DPNTEPsInfo teps : meshedDpnList ) {
+                 if( dpnId.equals(teps.getDPNID()))
+                 cfgDpnList.add( teps) ;
+              }
+            }
+        }
+        return cfgDpnList;
+    }
 }
index ce67233439497e64f0c3d3c518eca04ee70b14d9..066e5059226d4a9f6b8f2d6740cae0c94b595a6c 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelAddWorker;
+import org.opendaylight.vpnservice.itm.confighelpers.ItmExternalTunnelDeleteWorker;
 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
@@ -27,16 +28,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.Tunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.TunnelKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnelKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.AddExternalTunnelEndpointInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.BuildExternalTunnelFromDpnsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.CreateTerminatingServiceActionsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetExternalTunnelInterfaceNameOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetInternalOrExternalInterfaceNameOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.GetTunnelInterfaceNameOutputBuilder;
@@ -88,15 +93,15 @@ public class ItmManagerRpcService implements ItmRpcService {
          RpcResultBuilder<GetTunnelInterfaceNameOutput> resultBld = null;
          BigInteger sourceDpn = input.getSourceDpid() ;
          BigInteger destinationDpn = input.getDestinationDpid() ;
-         InstanceIdentifier<Tunnel> path = InstanceIdentifier.create(
+         InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
                  TunnelList.class)
-                     .child(Tunnel.class, new TunnelKey(destinationDpn, sourceDpn));      
+                     .child(InternalTunnel.class, new InternalTunnelKey(destinationDpn, sourceDpn));      
          
-         Optional<Tunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+         Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
 
          if( tnl != null && tnl.isPresent())
          {
-              Tunnel tunnel = tnl.get();
+              InternalTunnel tunnel = tnl.get();
               GetTunnelInterfaceNameOutputBuilder output = new GetTunnelInterfaceNameOutputBuilder() ;
               output.setInterfaceName(tunnel.getTunnelInterfaceName()) ;
               resultBld = RpcResultBuilder.success();
@@ -112,8 +117,12 @@ public class ItmManagerRpcService implements ItmRpcService {
     @Override
     public Future<RpcResult<Void>> removeExternalTunnelEndpoint(
             RemoveExternalTunnelEndpointInput input) {
-        // TODO Auto-generated method stub
-        return null;
+         //Ignore the Futures for now
+        final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService,meshedDpnList , input.getDestinationIp(), input.getTunnelType());
+        result.set(RpcResultBuilder.<Void>success().build());
+        return result;
     }
 
     @Override
@@ -121,7 +130,8 @@ public class ItmManagerRpcService implements ItmRpcService {
             RemoveExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-//        ItmExternalTunnelDeleteWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, input.getDpnId(), null, input.getDestinationIp());
+        List<DPNTEPsInfo> cfgDpnList = ItmUtils.getDPNTEPListFromDPNId(dataBroker, input.getDpnId()) ;
+        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, cfgDpnList, input.getDestinationIp(), input.getTunnelType());
         result.set(RpcResultBuilder.<Void>success().build());
         return result;
     }
@@ -131,7 +141,7 @@ public class ItmManagerRpcService implements ItmRpcService {
             BuildExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-        List<ListenableFuture<Void>> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, idManagerService, input.getDpnId(), input.getDestinationIp(), input.getTunnelType());
+        List<ListenableFuture<Void>> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, idManagerService,input.getDpnId(), input.getDestinationIp(), input.getTunnelType());
         for (ListenableFuture<Void> extTunnelResult : extTunnelResultList) {
             Futures.addCallback(extTunnelResult, new FutureCallback<Void>(){
 
@@ -159,7 +169,8 @@ public class ItmManagerRpcService implements ItmRpcService {
 
         //Ignore the Futures for now
         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
-    //    ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, null, input.getDestinationIp()) ;
+        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+        ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, idManagerService,meshedDpnList, input.getDestinationIp(), input.getTunnelType()) ;
         result.set(RpcResultBuilder.<Void>success().build());
         return result;
     }
@@ -288,4 +299,49 @@ public class ItmManagerRpcService implements ItmRpcService {
         return new StringBuffer().append(termSvcTable).append(svcId).toString();
     }
 
+    @Override
+    public Future<RpcResult<GetInternalOrExternalInterfaceNameOutput>> getInternalOrExternalInterfaceName(
+       GetInternalOrExternalInterfaceNameInput input) {
+       RpcResultBuilder<GetInternalOrExternalInterfaceNameOutput> resultBld = null;
+       BigInteger srcDpn = input.getSourceDpid() ;
+       IpAddress dstIp = input.getDestinationIp() ;
+       List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
+       // Look for external tunnels if not look for internal tunnel
+       for( DPNTEPsInfo teps : meshedDpnList) {
+           TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
+           if( dstIp.equals(firstEndPt.getIpAddress())) {
+              InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                       TunnelList.class)
+                           .child(InternalTunnel.class, new InternalTunnelKey(srcDpn, teps.getDPNID()));      
+               
+               Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+               if( tnl != null && tnl.isPresent())
+               {
+                    InternalTunnel tunnel = tnl.get();
+                    GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(tunnel.getTunnelInterfaceName() );
+                    resultBld = RpcResultBuilder.success();
+                    resultBld.withResult(output.build()) ;
+               }else {
+                   //resultBld = RpcResultBuilder.failed();
+                   InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
+                           ExternalTunnelList.class)
+                               .child(ExternalTunnel.class, new ExternalTunnelKey(dstIp, srcDpn));      
+                   
+                   Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path1, dataBroker);
+
+                   if( ext != null && ext.isPresent())
+                   {
+                        ExternalTunnel extTunnel = ext.get();
+                        GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(extTunnel.getTunnelInterfaceName() );
+                        resultBld = RpcResultBuilder.success();
+                        resultBld.withResult(output.build()) ;
+                   }else {
+                       resultBld = RpcResultBuilder.failed();
+                   }
+               }
+           }
+       }
+       return Futures.immediateFuture(resultBld.build());
+    }
+
 }