Updating CassiniDriver according to testing with IPI

Change-Id: Ia183f0a9ef432909aafa5480ee5b740425aa1832
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/OpticalModulationCommand.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/OpticalModulationCommand.java
index 78c5ec2..257ea11 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/OpticalModulationCommand.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/OpticalModulationCommand.java
@@ -22,6 +22,7 @@
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.NetconfOperationCompleter;
 import org.onosproject.cli.net.OpticalConnectPointCompleter;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Device;
@@ -48,8 +49,9 @@
 
     private static final Logger log = getLogger(OpticalModulationCommand.class);
 
-    @Argument(index = 0, name = "-s", description = "set modulation",
+    @Argument(index = 0, name = "operation", description = "set modulation",
             required = true, multiValued = false)
+    @Completion(NetconfOperationCompleter.class)
     private String operation = null;
 
     @Argument(index = 1, name = "connection point", description = "{DeviceID}/{PortNumber}",
@@ -57,9 +59,9 @@
     @Completion(OpticalConnectPointCompleter.class)
     private String connectPoint = null;
 
-    @Argument(index = 2, name = "value", description = "bit rate value in bps, e.g. 100FlowRu = 100GBps",
+    @Argument(index = 2, name = "value", description = "example: dp_qpsk, dp_8qam, dp_16qam",
             required = false, multiValued = false)
-    private Long value = null;
+    private String value = null;
 
     @Override
     protected void doExecute() throws Exception {
@@ -78,25 +80,37 @@
             return;
         }
         Device device = deviceService.getDevice(cp.deviceId());
-        ModulationConfig<Object> modulationConfig = device.as(ModulationConfig.class);
-        // FIXME the parameter "component" equals NULL now, because there is one-to-one mapping between
-        //  <component> and <optical-channel>.
-        if (operation == null) {
-            Direction component = Direction.ALL;
-            Optional<ModulationScheme> scheme = modulationConfig.getModulationScheme(cp.port(), component);
-            if (scheme.isPresent()) {
-                print("The modulation value in port %s on device %s is %s.",
-                        cp.port().toString(), cp.deviceId().toString(), scheme.get().name());
-            } else {
-                print("Can't get modulation for port %s on device %s.",
+        if (device.is(ModulationConfig.class)) {
+            ModulationConfig<Object> modulationConfig = device.as(ModulationConfig.class);
+            // FIXME the parameter "component" equals NULL now, because there is one-to-one mapping between
+            //  <component> and <optical-channel>.
+            if (operation.equals("get")) {
+                Direction component = Direction.ALL;
+                Optional<ModulationScheme> scheme = modulationConfig.getModulationScheme(cp.port(), component);
+                if (scheme.isPresent()) {
+                    print("The modulation value in port %s on device %s is %s.",
+                            cp.port().toString(), cp.deviceId().toString(), scheme.get().name());
+                } else {
+                    print("Can't get modulation for port %s on device %s.",
+                            cp.port().toString(), cp.deviceId().toString());
+                }
+            } else if (operation.equals("edit-config")) {
+                long bitRate = 0;
+                if (value.equalsIgnoreCase(ModulationScheme.DP_QPSK.name())) {
+                    bitRate = 100;
+                } else {
+                    bitRate = 200;
+                }
+                checkNotNull(value);
+                Direction component = Direction.ALL;
+                modulationConfig.setModulationScheme(cp.port(), component, bitRate);
+                print("Set modulation for " + value + " for port %s on device %s.",
                         cp.port().toString(), cp.deviceId().toString());
+            } else {
+                log.warn("Operation {} are not supported now.", operation);
             }
-        } else if (operation.equals("-s")) {
-            checkNotNull(value);
-            Direction component = Direction.ALL;
-            modulationConfig.setModulationScheme(cp.port(), component, value);
         } else {
-            log.warn("Operation {} are not supported now.", operation);
+            print("Device is not capable of handling modulation");
         }
     }
 }
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortAvailableWaveLengthCommand.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortAvailableWaveLengthCommand.java
new file mode 100644
index 0000000..b53644d
--- /dev/null
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortAvailableWaveLengthCommand.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.onosproject.net.optical.cli;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.OpticalConnectPointCompleter;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.behaviour.LambdaQuery;
+import org.onosproject.net.device.DeviceService;
+
+/**
+ * Lists all the available wavelengths (lambdas) for a given port.
+ */
+@Service
+@Command(scope = "onos", name = "available-wavelength",
+        description = "Lists all the available wavelengths for a given port")
+public class PortAvailableWaveLengthCommand extends AbstractShellCommand {
+
+    private static final String FMT =
+            "signal=%s, central-frequency=%f";
+
+    @Argument(index = 0, name = "connectPoint",
+            description = "Device/Port Description",
+            required = true, multiValued = false)
+    @Completion(OpticalConnectPointCompleter.class)
+    String connectPointString = "";
+
+
+    @Override
+    protected void doExecute() throws Exception {
+        DeviceService deviceService = get(DeviceService.class);
+        ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString);
+
+        Device d = deviceService.getDevice(cp.deviceId());
+        if (d.is(LambdaQuery.class)) {
+            LambdaQuery lambdaQuery = d.as(LambdaQuery.class);
+            lambdaQuery.queryLambdas(cp.port()).forEach(lambda -> {
+                print(FMT, lambda.toString(), lambda.centralFrequency().asGHz());
+            });
+
+        } else {
+            print("Device is not capable of querying lambdas");
+        }
+
+    }
+}
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortWaveLengthCommand.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortWaveLengthCommand.java
index df66587..9f50458 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortWaveLengthCommand.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/cli/PortWaveLengthCommand.java
@@ -15,7 +15,6 @@
  */
 
 
-
 package org.onosproject.net.optical.cli;
 
 import com.google.common.collect.ImmutableMap;
@@ -24,22 +23,23 @@
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.NetconfOperationCompleter;
 import org.onosproject.cli.net.OpticalConnectPointCompleter;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
+import org.onosproject.net.ChannelSpacing;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
 import org.onosproject.net.GridType;
 import org.onosproject.net.OchSignal;
-import org.onosproject.net.ChannelSpacing;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleService;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.DefaultFlowRule;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.FlowRuleService;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.Device;
 import org.onosproject.net.flow.instructions.Instructions;
 
 import java.util.Map;
@@ -51,7 +51,7 @@
  * Enable the optical channel and tune the wavelength via a flow rule based on a given Signal.
  */
 @Service
-@Command(scope = "onos", name = "port-wavelength",
+@Command(scope = "onos", name = "wavelength-config",
         description = "Enable the optical channel and tune the wavelength via a flow rule ")
 public class PortWaveLengthCommand extends AbstractShellCommand {
 
@@ -72,15 +72,19 @@
             .put(CH_50, ChannelSpacing.CHL_50GHZ)
             .put(CH_100, ChannelSpacing.CHL_100GHZ)
             .build();
+    @Argument(index = 0, name = "operation", description = "Netconf Operation including get, edit-config, etc.",
+            required = true, multiValued = false)
+    @Completion(NetconfOperationCompleter.class)
+    private String operation = null;
 
-    @Argument(index = 0, name = "connectPoint",
+    @Argument(index = 1, name = "connectPoint",
             description = "Device/Port Description",
             required = true, multiValued = false)
     @Completion(OpticalConnectPointCompleter.class)
     String connectPointString = "";
 
 
-    @Argument(index = 1, name = "signal",
+    @Argument(index = 2, name = "signal",
             description = "Optical Signal. Format = " + SIGNAL_FORMAT,
             required = true, multiValued = false)
     String signal = "";
@@ -116,38 +120,44 @@
 
     @Override
     protected void doExecute() throws Exception {
-        FlowRuleService flowService = get(FlowRuleService.class);
-        DeviceService deviceService = get(DeviceService.class);
-        CoreService coreService = get(CoreService.class);
-        ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString);
+        if (operation.equals("edit-config")) {
+            FlowRuleService flowService = get(FlowRuleService.class);
+            DeviceService deviceService = get(DeviceService.class);
+            CoreService coreService = get(CoreService.class);
+            ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString);
 
-        TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
-        TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
-        FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
+            TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
+            TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
+            FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
 
 
-        // an empty traffic selector
-        TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(cp.port()).build();
-        OchSignal ochSignal = createOchSignal();
+            // an empty traffic selector
+            TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(cp.port()).build();
+            OchSignal ochSignal = createOchSignal();
 
-        TrafficTreatment trafficTreatment = trafficTreatmentBuilder
-                .add(Instructions.modL0Lambda(ochSignal))
-                .add(Instructions.createOutput(deviceService.getPort(cp).number()))
-                .build();
+            TrafficTreatment trafficTreatment = trafficTreatmentBuilder
+                    .add(Instructions.modL0Lambda(ochSignal))
+                    .add(Instructions.createOutput(deviceService.getPort(cp).number()))
+                    .build();
 
-        Device device = deviceService.getDevice(cp.deviceId());
-        int priority = 100;
-        ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
-        log.info(appId.name());
-        FlowRule addFlow = flowRuleBuilder
-                .withPriority(priority)
-                .fromApp(appId)
-                .withTreatment(trafficTreatment)
-                .withSelector(trafficSelector)
-                .forDevice(device.id())
-                .makePermanent()
-                .build();
-        flowService.applyFlowRules(addFlow);
+            Device device = deviceService.getDevice(cp.deviceId());
+            int priority = 100;
+            ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
+            log.info(appId.name());
+            FlowRule addFlow = flowRuleBuilder
+                    .withPriority(priority)
+                    .fromApp(appId)
+                    .withTreatment(trafficTreatment)
+                    .withSelector(trafficSelector)
+                    .forDevice(device.id())
+                    .makePermanent()
+                    .build();
+            flowService.applyFlowRules(addFlow);
+            String msg = String.format("Setting wavelength %s", ochSignal.centralFrequency().asGHz());
+            print(msg);
+        } else {
+            print("Operation %s are not supported now.", operation);
+        }
 
     }
 }