+ @Override
+ public Future<RpcResult<GetInternalOrExternalInterfaceNameOutput>> getInternalOrExternalInterfaceName(
+ GetInternalOrExternalInterfaceNameInput input) {
+ RpcResultBuilder<GetInternalOrExternalInterfaceNameOutput> resultBld = RpcResultBuilder.failed();
+ BigInteger srcDpn = input.getSourceDpid() ;
+ String srcNode = srcDpn.toString();
+ IpAddress dstIp = input.getDestinationIp() ;
+ InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
+ ExternalTunnelList.class)
+ .child(ExternalTunnel.class, new ExternalTunnelKey(String.valueOf(dstIp), srcDpn.toString(), TunnelTypeMplsOverGre.class));
+
+ 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 {
+ 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(teps.getDPNID(), srcDpn, input.getTunnelType()));
+
+ 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());
+ break;
+ }
+ }
+ }
+ }
+ return Futures.immediateFuture(resultBld.build());
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> deleteL2GwDevice(DeleteL2GwDeviceInput input) {
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final String node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id);
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ //TO DO: add retry if it fails
+ t.delete(LogicalDatastoreType.CONFIGURATION, path);
+
+ ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Deleting l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> addL2GwDevice(AddL2GwDeviceInput input) {
+
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final String node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id);
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
+ DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(
+ node_id).setTopologyId(input.getTopologyId()).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ //TO DO: add retry if it fails
+ t.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
+
+ ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ else {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No TransportZones configured").build());
+ return result;
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> addL2GwMlagDevice(AddL2GwMlagDeviceInput input)
+ {
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final List<String> node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id.get(0));
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
+ DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(node_id.get(0)).setTopologyId(input.getTopologyId()).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ LOG.trace("writing hWvtep{}",deviceVtep);
+ t.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
+ if(node_id.size() == 2) {
+ LOG.trace("second node-id {}",node_id.get(1));
+ DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, node_id.get(1));
+ InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
+ DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().setKey(deviceVtepKey2).setIpAddress(hwIp).setNodeId(node_id.get(1))
+ .setTopologyId(input.getTopologyId()).build();
+ LOG.trace("writing {}",deviceVtep2);
+ t.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
+ }ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }
+ @Override
+ public Future<RpcResult<Void>> deleteL2GwMlagDevice(DeleteL2GwMlagDeviceInput input) {
+ final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
+ try {
+ final IpAddress hwIp = input.getIpAddress();
+ final List<String> node_id = input.getNodeId();
+ InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
+ Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
+ if (tZonesOptional.isPresent()) {
+ TransportZones tZones = tZonesOptional.get();
+ if (tZones.getTransportZone() == null || tZones.getTransportZone().isEmpty()) {
+ LOG.error("No teps configured");
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
+ return result;
+ }
+ String transportZone = tZones.getTransportZone().get(0).getZoneName();
+ if (tZones.getTransportZone().get(0).getSubnets() == null || tZones.getTransportZone().get(0).getSubnets().isEmpty()) {
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
+ return result;
+ }
+ SubnetsKey subnetsKey = tZones.getTransportZone().get(0).getSubnets().get(0).getKey();
+ DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, node_id.get(0));
+ InstanceIdentifier<DeviceVteps> path =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+ deviceVtepKey).build();
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ t.delete(LogicalDatastoreType.CONFIGURATION, path);
+ DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, node_id.get(1));
+ InstanceIdentifier<DeviceVteps> path2 =
+ InstanceIdentifier.builder(TransportZones.class)
+ .child(TransportZone.class, new TransportZoneKey(transportZone))
+ .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+ deviceVtepKey2).build();
+ t.delete(LogicalDatastoreType.CONFIGURATION, path2);
+ ListenableFuture<Void> futureCheck = t.submit();
+ Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void aVoid) {
+ result.set(RpcResultBuilder.<Void>success().build());
+ }
+ @Override
+ public void onFailure(Throwable error) {
+ String msg = String.format("Unable to write HwVtep {} to datastore", node_id);
+ LOG.error("Unable to write HwVtep {}, {} to datastore", node_id , hwIp);
+ result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+ }
+ });
+ }
+ return result;
+ } catch (Exception e) {
+ RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().
+ withError(RpcError.ErrorType.APPLICATION, "Deleting l2 Gateway to DS Failed", e);
+ return Futures.immediateFuture(resultBuilder.build());
+ }
+ }