Fix some problems for oplink netconf driver:
    1. Uses NETCONF get operation instead of get-config.
    2. Prevents reply-error log flooding in netconf session when polling port power range with protection switch, which does not support power range configuration retrieving.
    3. Some code optimization.

Change-Id: I5c4d0b0f6681dd1bf6b8c7450daf07db0104a758
diff --git a/drivers/oplink/src/main/java/org/onosproject/drivers/oplink/OplinkOpticalPowerConfig.java b/drivers/oplink/src/main/java/org/onosproject/drivers/oplink/OplinkOpticalPowerConfig.java
index 92847f9..6aba155 100755
--- a/drivers/oplink/src/main/java/org/onosproject/drivers/oplink/OplinkOpticalPowerConfig.java
+++ b/drivers/oplink/src/main/java/org/onosproject/drivers/oplink/OplinkOpticalPowerConfig.java
@@ -19,10 +19,12 @@
 import com.google.common.collect.Range;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.onosproject.driver.extensions.OplinkAttenuation;
+import org.onosproject.net.Device;
 import org.onosproject.net.Direction;
 import org.onosproject.net.OchSignal;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.PowerConfig;
+import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 import org.onosproject.net.flow.DefaultFlowRule;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -33,11 +35,11 @@
 
 import java.util.Optional;
 
-import static org.onosproject.drivers.oplink.OplinkOpticalUtility.MAX_ATTENUATION;
-import static org.onosproject.drivers.oplink.OplinkOpticalUtility.MIN_ATTENUATION;
 import static org.onosproject.drivers.oplink.OplinkOpticalUtility.POWER_MULTIPLIER;
-import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.drivers.oplink.OplinkOpticalUtility.RANGE_ATT;
+import static org.onosproject.drivers.oplink.OplinkOpticalUtility.RANGE_GENERAL;
 import static org.onosproject.drivers.oplink.OplinkNetconfUtility.*;
+import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  * Get current or target port/channel power from an Oplink optical netconf device.
@@ -65,7 +67,6 @@
     // log
     private static final Logger log = getLogger(OplinkOpticalPowerConfig.class);
 
-
     @Override
     public Optional<Long> getTargetPower(PortNumber port, T component) {
         return Optional.ofNullable(acquireTargetPower(port, component));
@@ -162,7 +163,7 @@
     }
 
     private Long acquirePortPower(PortNumber port, String selection) {
-        String reply = netconfGetConfig(handler(), getPortPowerFilter(port, selection));
+        String reply = netconfGet(handler(), getPortPowerFilter(port, selection));
         HierarchicalConfiguration info = configAt(reply, KEY_PORTS_PORT);
         if (info == null) {
             return null;
@@ -172,7 +173,7 @@
 
     private Long acquireChannelAttenuation(PortNumber port, OchSignal channel) {
         log.debug("Get port{} channel{} attenuation...", port, channel.channelSpacing());
-        String reply = netconfGetConfig(handler(), getChannelAttenuationFilter(port, channel));
+        String reply = netconfGet(handler(), getChannelAttenuationFilter(port, channel));
         HierarchicalConfiguration info = configAt(reply, KEY_CONNS);
         if (info == null) {
             return null;
@@ -182,7 +183,7 @@
 
     private Long acquireChannelPower(PortNumber port, OchSignal channel) {
         log.debug("Get port{} channel{} power...", port, channel.channelSpacing());
-        String reply = netconfGetConfig(handler(), getChannelPowerFilter(port, channel));
+        String reply = netconfGet(handler(), getChannelPowerFilter(port, channel));
         HierarchicalConfiguration info = configAt(reply, KEY_DATA_CONNS);
         if (info == null) {
             return null;
@@ -235,7 +236,15 @@
     }
 
     private Range<Long> getPowerRange(PortNumber port, String directionKey, String minKey, String maxKey) {
-        String reply = netconfGetConfig(handler(), getPowerRangeFilter(port, directionKey));
+        // TODO
+        // Optical protection switch does not support power range configuration, it'll reply error.
+        // To prevent replying error log flooding from netconf session when polling all ports information,
+        // use general power range of [-60, 60] instead.
+        if (handler().get(DeviceService.class).getDevice(data().deviceId()).type()
+                == Device.Type.FIBER_SWITCH) {
+            return RANGE_GENERAL;
+        }
+        String reply = netconfGet(handler(), getPowerRangeFilter(port, directionKey));
         HierarchicalConfiguration info = configAt(reply, KEY_PORTS_PORT_PROPERTY);
         if (info == null) {
             return null;
@@ -251,7 +260,7 @@
             return getPowerRange(port, KEY_PORTDIRECT_TX, KEY_PORTPWRCAPMINTX, KEY_PORTPWRCAPMAXTX);
         } else {
             log.debug("Get channel attenuation range...");
-            return Range.closed(MIN_ATTENUATION, MAX_ATTENUATION);
+            return RANGE_ATT;
         }
     }