[ODTN] Lumentum driver update to properly support maximum number of 130 configurations for each module on the device.

Change-Id: I037752d97166b8121c2f1cfc93a1f92e16746454
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumNetconfRoadmFlowRuleProgrammable.java b/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumNetconfRoadmFlowRuleProgrammable.java
index 1fe8148..d119cfa 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumNetconfRoadmFlowRuleProgrammable.java
+++ b/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumNetconfRoadmFlowRuleProgrammable.java
@@ -86,7 +86,7 @@
     protected static final long MUX_OUT = 4201;
     protected static final long DEMUX_IN = 5101;
     protected static final long GHZ = 1_000_000_000L;
-    protected static final int LUMENTUM_ROADM20_MAX_CONNECTIONS = 100;
+    protected static final int LUMENTUM_ROADM20_MAX_CONNECTIONS = 130;
 
     /**Get the flow entries that are present on the Lumentum device, called by FlowRuleDriverProvider.
      *
@@ -330,32 +330,40 @@
      * @param xc the cross connect flow rule
      * @return pair of module (1 for MUX/ADD, 2 for DEMUX/DROP) and connection number
      */
-    private Pair<Short, Short> setModuleConnection(LumentumFlowRule xc, Integer id) {
+    private Pair<Short, Short> setModuleIdConnection(LumentumFlowRule xc) {
+        int moduleId, connectionId;
+
         if (xc.isAddRule()) {
-            xc.setConnectionModule((short) 1);
-            xc.setConnectionId(id.shortValue());
-            return Pair.of((short) 1, id.shortValue());
+            moduleId = 1;
         } else {
-            xc.setConnectionModule((short) 2);
-            xc.setConnectionId(id.shortValue());
-            return Pair.of((short) 2, id.shortValue());
+            moduleId = 2;
         }
+
+        xc.setConnectionModule(moduleId);
+
+        connectionId = generateConnectionId(xc);
+
+        if (connectionId == 0) {
+            log.error("Max connections configured on device module {}", moduleId);
+            return null;
+        }
+
+        xc.setConnectionId(connectionId);
+
+        return Pair.of((short) moduleId, (short) connectionId);
     }
 
     //Following Lumentum documentation rpc operation to configure a new connection
     private boolean rpcAddConnection(LumentumFlowRule xc) {
 
-        int currentConnectionId = generateConnectionId();
-
-        if (currentConnectionId == 0) {
-            log.error("Lumentum driver - 100 connections are already configured on the device");
-            return false;
-        }
-
-        Pair<Short, Short> pair = setModuleConnection(xc, currentConnectionId);
+        Pair<Short, Short> pair = setModuleIdConnection(xc);
         String module = pair.getLeft().toString();
         String connectionId = pair.getRight().toString();
 
+        log.debug("Lumentum driver new connection sent moduleId {} connId {}",
+                xc.getConnectionModule(),
+                xc.getConnectionId());
+
         //Conversion of ochSignal format (center frequency + diameter) to Lumentum frequency slot format (start - end)
         Frequency freqRadius = Frequency.ofHz(xc.ochSignal().channelSpacing().frequency().asHz() / 2);
         Frequency center = xc.ochSignal().centralFrequency();
@@ -537,11 +545,13 @@
      * Generate a valid connectionId, the connectionId is a field required by the device every time
      * a connection is created/edited/removed.
      *
-     *
-     * Device only supports connection id < 100
+     * Device only supports connection id < 130
      */
-    private int generateConnectionId() {
-        //LUMENTUM_ROADM20_MAX_CONNECTIONS =  100, device only supports connection id < 100
+    private int generateConnectionId(LumentumFlowRule xc) {
+
+       int moduleNew = xc.getConnectionModule();
+
+        //LUMENTUM_ROADM20_MAX_CONNECTIONS =  100, device only supports connection id < 130
         for (int i = 1; i < LUMENTUM_ROADM20_MAX_CONNECTIONS; i++) {
             Set<FlowRule> rulesForDevice = getConnectionCache().get(did());
 
@@ -549,6 +559,7 @@
                 return 1;
             } else {
                 Set<Integer> connIds = rulesForDevice.stream()
+                        .filter(flow -> ((LumentumFlowRule) flow).getConnectionModule() == moduleNew)
                         .map(flow -> ((LumentumFlowRule) flow).getConnectionId())
                         .collect(Collectors.toSet());