[ONOS-7893] TerminalDevice driver for OpenConfig transponders.
Includes FlowRuleProgrammable and DeviceDiscovery behaviours.
The patch enables the configuration of client and line sides of the transponder.
FlowRules coming from the compilation of OpticalConnectivity and OpticalCircuit intents are translated in proper netconf/xml messages.
The patch also fixes an issue in the OpticalCircuiIntentCompiler to avoid overwriting among generated flowrules in case of bidirectional intents.
The patch also extend optical-rest app to enable deletion of OpticalCircuit intents.
An example of OpenConfig TerminalDevice xml datastore is included.

patch 2: Addressed comments by Ramon Casellas. Checkstyle.

patch 3: Fixed typo in OpticalConnectivityIntentCompiler.

patch 4: Checkstyle.

patch 5: Addressed comments by Andrea Campanella.

patch 6: Introduced Jira tag

patch 7: Update commit message.

patch 8: Ranaming files.

patch 9: Checkstyle.

Change-Id: Ia50bc0877ecd314aaf48cdb8465451a68313ce3a
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index a484d66..7e873d1 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -127,6 +127,11 @@
 
     private ApplicationId appId;
 
+    //Priority value of created OpticalConnectivity intent rules.
+    //The OpticalCircuitIntent is created with DEFAULT_INTENT_PRIORITY = 100 (see Intent.java)
+    //The two values have to be different to avoid rules overwriting.
+    private static final int OPTICAL_CONNECTIVITY_INTENT_PRIORITY = 200;
+
     @Modified
     public void modified(ComponentContext context) {
         if (context == null) {
@@ -253,6 +258,7 @@
                     // but `key` field cannot be used for the purpose.
                     .src(srcCP)
                     .dst(dstCP)
+                    .priority(OPTICAL_CONNECTIVITY_INTENT_PRIORITY)
                     .signalType(ochPorts.getLeft().signalType())
                     .bidirectional(intent.isBidirectional())
                     .resourceGroup(intent.resourceGroup())
@@ -320,12 +326,14 @@
         // Create optical circuit intent
         List<FlowRule> rules = new LinkedList<>();
         // at the source: ODUCLT port mapping to OCH port
+        log.debug("OpticalCircuitIntent creating FlowRules");
         rules.add(connectPorts(higherIntent.getSrc(), lowerIntent.getSrc(), higherIntent.priority(), slots));
         // at the destination: OCH port mapping to ODUCLT port
         rules.add(connectPorts(lowerIntent.getDst(), higherIntent.getDst(), higherIntent.priority(), slots));
 
         // Create flow rules for reverse path
         if (higherIntent.isBidirectional()) {
+            log.debug("OpticalCircuitIntent creating FlowRules for reverse path");
            // at the destination: OCH port mapping to ODUCLT port
             rules.add(connectPorts(lowerIntent.getSrc(), higherIntent.getSrc(), higherIntent.priority(), slots));
             // at the source: ODUCLT port mapping to OCH port
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index dcd97bf..acedda2e 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -182,6 +182,7 @@
         return OpticalPathIntent.builder()
                 .appId(parentIntent.appId())
                 .key(parentIntent.key())
+                .priority(parentIntent.priority())
                 .src(parentIntent.getSrc())
                 .dst(parentIntent.getDst())
                 .path(path)
diff --git a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
index 4643d7b..cff8d93 100644
--- a/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
+++ b/apps/optical-rest/src/main/java/org/onosproject/net/optical/rest/OpticalIntentsWebResource.java
@@ -41,6 +41,7 @@
 import org.onosproject.net.intent.IntentState;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
+import org.onosproject.net.intent.OpticalCircuitIntent;
 import org.onosproject.net.link.LinkService;
 import org.onosproject.net.optical.json.OchSignalCodec;
 import org.onosproject.net.provider.ProviderId;
@@ -90,6 +91,7 @@
     private static final String MISSING_MEMBER_MESSAGE = " member is required";
     private static final String E_APP_ID_NOT_FOUND = "Application ID is not found";
     private static final ProviderId PROVIDER_ID = new ProviderId("netconf", "optical-rest");
+    private static final int NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE = 3;
 
     @Context
     private UriInfo uriInfo;
@@ -157,7 +159,8 @@
 
                 objectNode.put("intent id", opticalConnectivityIntent.id().toString());
                 objectNode.put("app id", opticalConnectivityIntent.appId().name());
-                objectNode.put("state", intentService.getIntentState(opticalConnectivityIntent.key()).toString());
+                objectNode.put("state",
+                        intentService.getIntentState(opticalConnectivityIntent.key()).toString());
                 objectNode.put("src", opticalConnectivityIntent.getSrc().toString());
                 objectNode.put("dst", opticalConnectivityIntent.getDst().toString());
                 objectNode.put("srcName", srcDeviceName);
@@ -174,10 +177,12 @@
                             .findFirst()
                             .orElse(null);
 
-                    //Retrieve used ochSignal from the Selector of one of the installed FlowRule
+                    //FlowRules computed by the OpticalConnectivityIntentCompiler includes 3 criteria, one of those
+                    //is the OchSignal, thus retrieve used ochSignal from the selector of one of the installed rules
                     //TODO store utilized ochSignal in the intent resources
                     if (installableIntent != null) {
                         OchSignal signal = installableIntent.flowRules().stream()
+                                .filter(r -> r.selector().criteria().size() == NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE)
                                 .map(r -> ((OchSignalCriterion)
                                         r.selector().getCriterion(Criterion.Type.OCH_SIGID)).lambda())
                                 .findFirst()
@@ -239,7 +244,7 @@
         }
         nullIsNotFound(intent, "Intent Id is not found");
 
-        if (intent instanceof OpticalConnectivityIntent) {
+        if ((intent instanceof OpticalConnectivityIntent) || (intent instanceof OpticalCircuitIntent)) {
             intentService.withdraw(intent);
         } else {
             throw new IllegalArgumentException("Specified intent is not of type OpticalConnectivityIntent");
@@ -306,8 +311,6 @@
 
                     Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
                     if (link == null) {
-                        log.warn("Not existing link in the suggested path src {} dst {}",
-                                 srcConnectPoint, dstConnectPoint);
                         throw new IllegalArgumentException("Not existing link in the suggested path");
                     }
 
diff --git a/apps/optical-rest/src/main/resources/definitions/CreateIntent.json b/apps/optical-rest/src/main/resources/definitions/CreateIntent.json
index da4f215..3106421 100644
--- a/apps/optical-rest/src/main/resources/definitions/CreateIntent.json
+++ b/apps/optical-rest/src/main/resources/definitions/CreateIntent.json
@@ -20,11 +20,11 @@
       "properties": {
         "device": {
           "type": "string",
-          "example": "netconf:10.255.255.14:2022"
+          "example": "netconf:10.10.255.14:2022"
         },
         "port": {
           "type": "string",
-          "example": "101"
+          "example": "10102"
         }
       }
     },
@@ -38,15 +38,15 @@
       "properties": {
         "device": {
           "type": "string",
-          "example": "netconf:10.255.255.17:2022"
+          "example": "netconf:10.10.255.15:2022"
         },
         "port": {
           "type": "string",
-          "example": "201"
+          "example": "10102"
         }
       }
     },
-    "bidirection": {
+    "bidirectional": {
       "type": "boolean",
       "example": false
     },
@@ -115,11 +115,11 @@
             "properties" : {
               "src": {
                 "type": "string",
-                "example": "netconf:10.255.255.14:2022/101"
+                "example": "netconf:10.10.255.14:2022/10102"
               },
               "dst": {
                 "type": "string",
-                "example": "netconf:10.255.255.9:2022/201"
+                "example": "netconf:10.10.255.15:2022/10102"
               }
             }
           }