+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ if (null != cfgdDpnList && !cfgdDpnList.isEmpty()) {
+ logger.trace("calling tunnels from css {}",cfgdDpnList);
+ tunnelsFromCSS(cfgdDpnList, idManagerService , futures, t , dataBroker);
+
+ }
+ if (null != cfgdHwVteps && !cfgdHwVteps.isEmpty() ) {
+ logger.trace("calling tunnels from hwTep {}",cfgdHwVteps);
+ tunnelsFromhWVtep(cfgdHwVteps, idManagerService, futures, t, dataBroker);
+ }
+
+ if ((cfgdDpnList != null && !cfgdDpnList.isEmpty()) || (cfgdHwVteps != null && !cfgdHwVteps.isEmpty()))
+ futures.add(t.submit());
+ return futures;
+ }
+
+ private static void tunnelsFromCSS(List<DPNTEPsInfo> cfgdDpnList, IdManagerService idManagerService, List<ListenableFuture<Void>> futures, WriteTransaction t, DataBroker dataBroker) {
+ for (DPNTEPsInfo dpn : cfgdDpnList) {
+ logger.trace("processing dpn {}" , dpn);
+ if (dpn.getTunnelEndPoints() != null && !dpn.getTunnelEndPoints().isEmpty())
+ for (TunnelEndPoints tep : dpn.getTunnelEndPoints()) {
+ InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey((tep.getTransportZone()))).build();
+ Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
+ if (tZoneOptional.isPresent()) {
+ TransportZone tZone = tZoneOptional.get();
+ //do we need to check tunnel type?
+ if (tZone.getSubnets() != null && !tZone.getSubnets().isEmpty()) {
+ for (Subnets sub : tZone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
+ String cssID = dpn.getDPNID().toString();
+ String nodeId = hwVtepDS.getNodeId();
+ //CSS-TOR
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
+ logger.trace("wire up {} and {}",tep, hwVtepDS);
+ if (!wireUp(dpn.getDPNID(), tep.getPortname(), sub.getVlanId(), tep.getIpAddress(), nodeId, hwVtepDS.getIpAddress(), tep.getSubnetMask(),
+ sub.getGatewayIp(), sub.getPrefix(), tZone.getTunnelType(),monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
+ logger.error("Unable to build tunnel {} -- {}", tep.getIpAddress(), hwVtepDS.getIpAddress());
+ //TOR-CSS
+ logger.trace("wire up {} and {}", hwVtepDS,tep);
+ if (!wireUp(hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), cssID, tep.getIpAddress(), sub.getPrefix(),
+ sub.getGatewayIp(), tep.getSubnetMask(), tZone.getTunnelType(), monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
+ logger.error("Unable to build tunnel {} -- {}", hwVtepDS.getIpAddress(), tep.getIpAddress());
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static void tunnelsFromhWVtep(List<HwVtep> cfgdHwVteps, IdManagerService idManagerService, List<ListenableFuture<Void>> futures, WriteTransaction t, DataBroker dataBroker) {
+ for (HwVtep hwTep : cfgdHwVteps) {
+ InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey((hwTep.getTransportZone()))).build();
+ Optional<TransportZone> tZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath, dataBroker);
+ Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
+ if (tZoneOptional.isPresent()) {
+ TransportZone tZone = tZoneOptional.get();
+ //do we need to check tunnel type?
+ if (tZone.getSubnets() != null && !tZone.getSubnets().isEmpty()) {
+ for (Subnets sub : tZone.getSubnets()) {
+ if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+ for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
+ if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp()))
+ continue;//dont mesh with self
+ //TOR1-TOR2
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
+ logger.trace("wire up {} and {}",hwTep, hwVtepDS);
+ if (!wireUp(hwTep.getTopo_id(), hwTep.getNode_id(), hwTep.getHwIp(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
+ hwTep.getIpPrefix(), hwTep.getGatewayIP(), sub.getPrefix(), tunType,monitorEnabled,
+ ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
+ logger.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), hwVtepDS.getIpAddress());
+ //TOR2-TOR1
+ logger.trace("wire up {} and {}", hwVtepDS,hwTep);
+ if (!wireUp(hwTep.getTopo_id(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getNode_id(), hwTep.getHwIp(),
+ sub.getPrefix(), sub.getGatewayIp(), hwTep.getIpPrefix(), tunType, monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t))
+ logger.error("Unable to build tunnel {} -- {}", hwVtepDS.getIpAddress(), hwTep.getHwIp());
+ }
+ }
+ if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
+ for (Vteps vtep : sub.getVteps()) {
+ //TOR-CSS
+ String cssID = vtep.getDpnId().toString();
+ Boolean monitorEnabled = ItmUtils.readMonitoringStateFromDS(dataBroker);
+ Integer monitorInterval = ItmUtils.readMonitorIntervalfromDS(dataBroker);
+ logger.trace("wire up {} and {}",hwTep, vtep);
+ if(!wireUp(hwTep.getTopo_id(), hwTep.getNode_id(), hwTep.getHwIp(), cssID, vtep.getIpAddress(), hwTep.getIpPrefix(),
+ hwTep.getGatewayIP(), sub.getPrefix(), tunType,monitorEnabled, ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL, idManagerService, dataBroker, futures, t ))
+ logger.error("Unable to build tunnel {} -- {}", hwTep.getHwIp(), vtep.getIpAddress());
+ //CSS-TOR
+ logger.trace("wire up {} and {}", vtep,hwTep);
+ if(!wireUp(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId(), vtep.getIpAddress(),
+ hwTep.getNode_id(),hwTep.getHwIp(),sub.getPrefix(), sub.getGatewayIp(),hwTep.getIpPrefix(),
+ tunType,monitorEnabled,ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL,idManagerService, dataBroker, futures, t ));
+
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //for tunnels from TOR device
+ private static boolean wireUp(String topo_id, String srcNodeid, IpAddress srcIp, String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet,
+ IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType,Boolean monitorEnabled,
+ Integer monitorInterval,IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? gatewayIpObj : gWIp;
+ String parentIf = ItmUtils.getHwParentIf(topo_id, srcNodeid);
+ String tunTypeStr = tunType.getName();
+ String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf,
+ srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue(), tunTypeStr);
+ logger.debug(" Creating ExternalTrunk Interface with parameters Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}", tunnelIfName, parentIf, srcIp, dstIp, gwyIpAddress);
+ Interface hwTunnelIf = ItmUtils.buildHwTunnelInterface(tunnelIfName, String.format("%s %s", tunType.getName(), "Trunk Interface"),
+ true, topo_id, srcNodeid, tunType, srcIp, dstIp, gwyIpAddress, monitorEnabled, monitorInterval);
+ InstanceIdentifier<Interface> ifIID = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(tunnelIfName)).build();
+ logger.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, hwTunnelIf);
+ ItmUtils.itmCache.addInterface(hwTunnelIf);
+ t.merge(LogicalDatastoreType.CONFIGURATION, ifIID, hwTunnelIf, true);
+ // also update itm-state ds?
+ InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
+ ExternalTunnelList.class)
+ .child(ExternalTunnel.class, new ExternalTunnelKey( getExternalTunnelKey(dstNodeId), getExternalTunnelKey(srcNodeid), tunType));
+ ExternalTunnel tnl = ItmUtils.buildExternalTunnel( getExternalTunnelKey(srcNodeid),
+ getExternalTunnelKey(dstNodeId),
+ tunType, tunnelIfName);
+ t.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+ ItmUtils.itmCache.addExternalTunnel(tnl);
+ return true;
+ }
+
+ //for tunnels from CSS
+ private static boolean wireUp(BigInteger dpnId,String portname, Integer vlanId, IpAddress srcIp, String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet,
+ IpAddress gWIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType,Boolean monitorEnabled, Integer monitorInterval,
+ IdManagerService idManagerService, DataBroker dataBroker, List<ListenableFuture<Void>> futures, WriteTransaction t) {
+ IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray());
+ IpAddress gwyIpAddress = (srcSubnet.equals(dstSubnet)) ? gatewayIpObj : gWIp;
+ String parentIf = ItmUtils.getInterfaceName(dpnId, portname, vlanId);
+ String tunTypeStr = tunType.getName();
+ String tunnelIfName = ItmUtils.getTrunkInterfaceName(idManagerService, parentIf,
+ srcIp.getIpv4Address().getValue(), dstIp.getIpv4Address().getValue(), tunTypeStr);
+ logger.debug(" Creating ExternalTrunk Interface with parameters Name - {}, parent I/f name - {}, source IP - {}, destination IP - {} gateway IP - {}", tunnelIfName, parentIf, srcIp, dstIp, gwyIpAddress);
+ Interface extTunnelIf = ItmUtils.buildTunnelInterface(dpnId, tunnelIfName, String.format("%s %s", tunType.getName(), "Trunk Interface"), true, tunType, srcIp, dstIp, gwyIpAddress, vlanId, false,monitorEnabled, monitorInterval);
+ InstanceIdentifier<Interface> ifIID = InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(tunnelIfName)).build();
+ logger.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, extTunnelIf);
+ t.merge(LogicalDatastoreType.CONFIGURATION, ifIID, extTunnelIf, true);
+ ItmUtils.itmCache.addInterface(extTunnelIf);
+ InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(
+ ExternalTunnelList.class)
+ .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId), dpnId.toString(), tunType));
+ ExternalTunnel tnl = ItmUtils.buildExternalTunnel( dpnId.toString(),
+ getExternalTunnelKey(dstNodeId),
+ tunType, tunnelIfName);
+ t.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+ ItmUtils.itmCache.addExternalTunnel(tnl);
+ return true;
+ }
+
+ static String getExternalTunnelKey(String nodeid) {
+ if (nodeid.indexOf("physicalswitch") > 0) {
+ nodeid = nodeid.substring(0, nodeid.indexOf("physicalswitch") - 1);
+ }
+ return nodeid;