[ODTN]Add SIP validation check

Add check of SIP which is input of create-connectivity-service is used

Change-Id: I95f50fcc98d40f462cc3c50a7f461e3f7e6686e4
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java
old mode 100644
new mode 100755
index c32558c..5bbed4a
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.odtn.utils.tapi;
 
+import java.util.List;
 import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext;
 import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid;
 import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.ConnectivityServiceKeys;
@@ -82,6 +83,10 @@
                 .build();
     }
 
+    public List<EndPoint> getEndPoint() {
+        return obj.endPoint();
+    }
+
     public TapiConnectivityServiceHandler addSep(EndPoint sep) {
         obj.addToEndPoint(sep);
         return this;
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java
old mode 100644
new mode 100755
index a5bed1f..c0ed956
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.odtn.internal;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.onosproject.config.DynamicConfigService;
@@ -43,6 +44,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static java.util.Collections.disjoint;
 import static org.onlab.osgi.DefaultServiceDirectory.getService;
 
 
@@ -75,9 +77,15 @@
         try {
             TapiCreateConnectivityInputHandler input = new TapiCreateConnectivityInputHandler();
             input.setRpcInput(inputVar);
-            // TODO validation check
             log.info("input SIPs: {}", input.getSips());
 
+            // check SIP validation
+            if (!disjoint(getUsedSips(), input.getSips())) {
+                log.error("check SIP validation : NG");
+                return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+            }
+            log.debug("check SIP validation : OK");
+
             List<TapiNepRef> nepRefs = input.getSips().stream()
                     .map(sipId -> resolver.getNepRef(sipId))
                     .collect(Collectors.toList());
@@ -116,7 +124,6 @@
 
     }
 
-
     /**
      * Service interface of deleteConnectivityService.
      *
@@ -195,7 +202,6 @@
         }
     }
 
-
     /**
      * Service interface of getConnectivityServiceDetails.
      *
@@ -249,4 +255,23 @@
         return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
 
     }
+
+    /**
+     * Get used SIPs.
+     *
+     * @return list of used SIPs
+     */
+    private List<String> getUsedSips() {
+        TapiContextHandler handler = TapiContextHandler.create();
+        handler.read();
+
+        List<String> usedSips = new ArrayList();
+        handler.getConnectivityServices().stream()
+            .forEach(connectivityService -> connectivityService.getEndPoint().stream()
+                .forEach(endPoint -> usedSips.add(endPoint.serviceInterfacePoint()
+                                                  .serviceInterfacePointUuid().toString())));
+
+        log.debug("usedSips: {}", usedSips);
+        return usedSips;
+    }
 }