[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-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");
                     }