From de28c9eeb14ae5e5f65bc4621f3802ee4f831d49 Mon Sep 17 00:00:00 2001 From: HemaTG Date: Thu, 14 Jan 2016 14:56:44 +0530 Subject: [PATCH] Implemented new RPCs, add/delete int/ext I/f name Change-Id: I315c882baeb6c9a9d48250423b2d07e5d1b386b7 Signed-off-by: HemaTG --- itm/itm-api/.gitignore | 4 + itm/itm-api/src/main/yang/itm-rpc.yang | 23 +++++- itm/itm-api/src/main/yang/itm-state.yang | 6 +- .../ItmExternalTunnelAddWorker.java | 26 ++----- .../ItmExternalTunnelDeleteWorker.java | 26 +++++-- .../ItmInternalTunnelAddWorker.java | 19 ++--- .../ItmInternalTunnelDeleteWorker.java | 21 +++++ .../vpnservice/itm/impl/ItmUtils.java | 37 ++++++++- .../itm/rpc/ItmManagerRpcService.java | 78 ++++++++++++++++--- 9 files changed, 183 insertions(+), 57 deletions(-) create mode 100644 itm/itm-api/.gitignore diff --git a/itm/itm-api/.gitignore b/itm/itm-api/.gitignore new file mode 100644 index 00000000..b49c5639 --- /dev/null +++ b/itm/itm-api/.gitignore @@ -0,0 +1,4 @@ +/target/ +/target/ +/target/ +/target/ diff --git a/itm/itm-api/src/main/yang/itm-rpc.yang b/itm/itm-api/src/main/yang/itm-rpc.yang index 69e1ea9b..2347e6eb 100644 --- a/itm/itm-api/src/main/yang/itm-rpc.yang +++ b/itm/itm-api/src/main/yang/itm-rpc.yang @@ -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; diff --git a/itm/itm-api/src/main/yang/itm-state.yang b/itm/itm-api/src/main/yang/itm-state.yang index ea54594c..ca39c03e 100644 --- a/itm/itm-api/src/main/yang/itm-state.yang +++ b/itm/itm-api/src/main/yang/itm-state.yang @@ -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{ } diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.java index c44e96a2..54277d4a 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelAddWorker.java @@ -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 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 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> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService, List dpnId, IpAddress extIp, Class tunType) { List> futures = new ArrayList<>(); - List cfgDpnList = new ArrayList() ; - List meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ; - if( null != meshedDpnList) { - for (BigInteger dpn : dpnId){ - for( DPNTEPsInfo teps : meshedDpnList ) { - if( teps.getDPNID().equals(dpn)) { - cfgDpnList.add(teps) ; - } - } - } + List cfgDpnList =( dpnId == null ) ? ItmUtils.getTunnelMeshInfo(dataBroker) :ItmUtils.getDPNTEPListFromDPNId(dataBroker, dpnId) ; futures = buildTunnelsToExternalEndPoint( dataBroker, idManagerService, cfgDpnList, extIp, tunType) ; - } return futures ; } } diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java index b976155d..81f6aaef 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmExternalTunnelDeleteWorker.java @@ -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> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService, - List dpnTepsList, IpAddress extIp ) { + public static List> deleteTunnels(DataBroker dataBroker, IdManagerService idManagerService, List dpnTepsList,IpAddress extIp, Class tunType ) { logger.trace( " Delete Tunnels towards DC Gateway with Ip {}", extIp ) ; List> 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 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 trunkIdentifier = ItmUtils.buildId(trunkInterfaceName); + t.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + + InstanceIdentifier 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 ; diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java index faa2c6bf..bde34d01 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelAddWorker.java @@ -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 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 path = InstanceIdentifier.create( + InstanceIdentifier 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; } diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java index cb0b23f1..096d81cf 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/confighelpers/ItmInternalTunnelDeleteWorker.java @@ -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 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 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); } } diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java index 74d143c4..0750ea47 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/impl/ItmUtils.java @@ -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 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 getTunnelMeshInfo(DataBroker dataBroker) { List dpnTEPs= null ; @@ -227,4 +246,18 @@ public class ItmUtils { LOG.warn("Exception when getting Unique Id for key {}", idKey, e); } } + + public static List getDPNTEPListFromDPNId(DataBroker dataBroker, List dpnIds) { + List meshedDpnList = getTunnelMeshInfo(dataBroker) ; + List cfgDpnList = new ArrayList(); + if( null != meshedDpnList) { + for(BigInteger dpnId : dpnIds) { + for( DPNTEPsInfo teps : meshedDpnList ) { + if( dpnId.equals(teps.getDPNID())) + cfgDpnList.add( teps) ; + } + } + } + return cfgDpnList; + } } diff --git a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java index ce672334..066e5059 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/vpnservice/itm/rpc/ItmManagerRpcService.java @@ -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 resultBld = null; BigInteger sourceDpn = input.getSourceDpid() ; BigInteger destinationDpn = input.getDestinationDpid() ; - InstanceIdentifier path = InstanceIdentifier.create( + InstanceIdentifier path = InstanceIdentifier.create( TunnelList.class) - .child(Tunnel.class, new TunnelKey(destinationDpn, sourceDpn)); + .child(InternalTunnel.class, new InternalTunnelKey(destinationDpn, sourceDpn)); - Optional tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker); + Optional 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> removeExternalTunnelEndpoint( RemoveExternalTunnelEndpointInput input) { - // TODO Auto-generated method stub - return null; + //Ignore the Futures for now + final SettableFuture> result = SettableFuture.create(); + List meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ; + ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService,meshedDpnList , input.getDestinationIp(), input.getTunnelType()); + result.set(RpcResultBuilder.success().build()); + return result; } @Override @@ -121,7 +130,8 @@ public class ItmManagerRpcService implements ItmRpcService { RemoveExternalTunnelFromDpnsInput input) { //Ignore the Futures for now final SettableFuture> result = SettableFuture.create(); -// ItmExternalTunnelDeleteWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, input.getDpnId(), null, input.getDestinationIp()); + List cfgDpnList = ItmUtils.getDPNTEPListFromDPNId(dataBroker, input.getDpnId()) ; + ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, idManagerService, cfgDpnList, input.getDestinationIp(), input.getTunnelType()); result.set(RpcResultBuilder.success().build()); return result; } @@ -131,7 +141,7 @@ public class ItmManagerRpcService implements ItmRpcService { BuildExternalTunnelFromDpnsInput input) { //Ignore the Futures for now final SettableFuture> result = SettableFuture.create(); - List> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, idManagerService, input.getDpnId(), input.getDestinationIp(), input.getTunnelType()); + List> extTunnelResultList = ItmExternalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(dataBroker, idManagerService,input.getDpnId(), input.getDestinationIp(), input.getTunnelType()); for (ListenableFuture extTunnelResult : extTunnelResultList) { Futures.addCallback(extTunnelResult, new FutureCallback(){ @@ -159,7 +169,8 @@ public class ItmManagerRpcService implements ItmRpcService { //Ignore the Futures for now final SettableFuture> result = SettableFuture.create(); - // ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, null, input.getDestinationIp()) ; + List meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ; + ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, idManagerService,meshedDpnList, input.getDestinationIp(), input.getTunnelType()) ; result.set(RpcResultBuilder.success().build()); return result; } @@ -288,4 +299,49 @@ public class ItmManagerRpcService implements ItmRpcService { return new StringBuffer().append(termSvcTable).append(svcId).toString(); } + @Override + public Future> getInternalOrExternalInterfaceName( + GetInternalOrExternalInterfaceNameInput input) { + RpcResultBuilder resultBld = null; + BigInteger srcDpn = input.getSourceDpid() ; + IpAddress dstIp = input.getDestinationIp() ; + List 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 path = InstanceIdentifier.create( + TunnelList.class) + .child(InternalTunnel.class, new InternalTunnelKey(srcDpn, teps.getDPNID())); + + Optional 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 path1 = InstanceIdentifier.create( + ExternalTunnelList.class) + .child(ExternalTunnel.class, new ExternalTunnelKey(dstIp, srcDpn)); + + Optional 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()); + } + } -- 2.36.6