X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fitm%2Fconfighelpers%2FItmExternalTunnelAddWorker.java;h=54277d4a6b5a8a7b7bea1a780d5a891b926fcf41;hb=de28c9eeb14ae5e5f65bc4621f3802ee4f831d49;hp=49b882fb74d5cbbd24793ffd8af7a371d2d8a7e9;hpb=50bb8cd056ca25114a412398c4df672eac891b28;p=vpnservice.git 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 49b882fb..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 @@ -17,64 +17,78 @@ 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.params.xml.ns.yang.itm.op.rev150701.tunnels.DPNTEPsInfo; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.tunnels.dpn.teps.info.TunnelEndPoints; +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.interfacemgr.rev150331.TunnelTypeGre; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeVxlan; +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.ExternalTunnelBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnelKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.commons.net.util.SubnetUtils; +import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.ListenableFuture; public class ItmExternalTunnelAddWorker { private static final Logger logger = LoggerFactory.getLogger(ItmExternalTunnelAddWorker.class ) ; - public static List> buildTunnelsToExternalEndPoint(DataBroker dataBroker,List meshedDpnList, IpAddress extIp) { + private static final FutureCallback DEFAULT_CALLBACK = + new FutureCallback() { + public void onSuccess(Void result) { + logger.debug("Success in Datastore operation"); + } + + public void onFailure(Throwable error) { + logger.error("Error in Datastore operation", error); + }; + }; + + public static List> buildTunnelsToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService, + List cfgDpnList, IpAddress extIp, Class tunType) { List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - if( null == meshedDpnList) - ItmUtils.getTunnelMeshInfo(dataBroker) ; - if( null != meshedDpnList) { - for( DPNTEPsInfo teps : meshedDpnList ) { + if( null != cfgDpnList) { + for( DPNTEPsInfo teps : cfgDpnList ) { // CHECK -- Assumption -- Only one End Point / Dpn for GRE/Vxlan Tunnels TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ; String interfaceName = firstEndPt.getInterfaceName() ; - String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ; + String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue()) ; char[] subnetMaskArray = firstEndPt.getSubnetMask().getValue() ; String subnetMaskStr = String.valueOf(subnetMaskArray) ; SubnetUtils utils = new SubnetUtils(subnetMaskStr); String dcGwyIpStr = String.valueOf(extIp.getValue()); IpAddress gwyIpAddress = (utils.getInfo().isInRange(dcGwyIpStr) ) ? null : firstEndPt.getGwIpAddress() ; - Class tunType = (teps.getTunnelEndPoints().get(0).getTunnelType().equals("GRE") ) ? TunnelTypeGre.class :TunnelTypeVxlan.class ; - String ifDescription = (tunType.equals("GRE") ) ? "GRE" : "VxLan" ; + 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_tunnel_list ds + InstanceIdentifier path = InstanceIdentifier.create( + ExternalTunnelList.class) + .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()) ; } return futures ; } - public static List> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker,BigInteger dpnId,List meshedDpnList, IpAddress extIp) { + public static List> buildTunnelsFromDpnToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService, + List dpnId, IpAddress extIp, Class tunType) { List> futures = new ArrayList<>(); - List cfgDpnList = new ArrayList() ; - if( null != meshedDpnList) { - for( DPNTEPsInfo teps : meshedDpnList ) { - if( teps.getDPNID().equals(dpnId)) { - cfgDpnList.add(teps) ; - } - } - futures = buildTunnelsToExternalEndPoint( dataBroker, cfgDpnList, extIp) ; - } + List cfgDpnList =( dpnId == null ) ? ItmUtils.getTunnelMeshInfo(dataBroker) :ItmUtils.getDPNTEPListFromDPNId(dataBroker, dpnId) ; + futures = buildTunnelsToExternalEndPoint( dataBroker, idManagerService, cfgDpnList, extIp, tunType) ; return futures ; } }