[ONOS-8143] Updates to Polatis optical switch NETCONF driver

 - fixed long standing bug in DeviceDescription behaviour
 - added a form of LinkDiscovery behaviour
 - added PortAdmin and InternalConnectivity behaviours
 - added a CLI command 'get-output-ports' to exploit the InternalConnectivity behaviour
 - overloaded the loadXml method in drivers/utilities/XmlConfigParser class to allow suppression of comma delimitation within
   XML tags

Change-Id: I042e5559cf358d969686a63da99e91371a085d83
diff --git a/drivers/polatis/netconf/BUILD b/drivers/polatis/netconf/BUILD
index faf52dc..39c39fa 100644
--- a/drivers/polatis/netconf/BUILD
+++ b/drivers/polatis/netconf/BUILD
@@ -1,4 +1,4 @@
-COMPILE_DEPS = CORE_DEPS + ONOS_YANG + [
+COMPILE_DEPS = CORE_DEPS + JACKSON + ONOS_YANG + [
     "//models/polatis:onos-models-polatis",
     "//drivers/utilities:onos-drivers-utilities",
     "//protocols/netconf/api:onos-protocols-netconf-api",
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
index ad77648..916a029 100644
--- a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
@@ -18,12 +18,9 @@
 
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.device.DefaultDeviceDescription;
 import org.onosproject.net.device.DeviceDescription;
 import org.onosproject.net.device.DeviceDescriptionDiscovery;
@@ -31,35 +28,32 @@
 import org.onosproject.net.device.PortDescription;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
 
-import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
-
 import org.onlab.packet.ChassisId;
-import org.onlab.util.Frequency;
-import org.onlab.util.Spectrum;
 
 import org.slf4j.Logger;
 import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onosproject.net.Device.Type.FIBER_SWITCH;
 
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.getPortsFilter;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.getProdInfoFilter;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.parsePorts;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_MANUFACTURER;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_HWVERSION;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_SWVERSION;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_SERIALNUMBER;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_INPUTPORTS;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_OUTPUTPORTS;
+
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configAt;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configsAt;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.subscribe;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlOpen;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlClose;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlEmpty;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORT;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTID;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTCONFIG;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PRODINF;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTCONFIG_XMLNS;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PRODINF_XMLNS;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_DATA_PRODINF;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_DATA_PORTCONFIG;
 
 /**
  * Representation of device information and ports via NETCONF for all Polatis
@@ -68,17 +62,6 @@
 public class PolatisDeviceDescription extends AbstractHandlerBehaviour
     implements DeviceDescriptionDiscovery {
 
-    public static final String DEFAULT_MANUFACTURER = "Polatis";
-    public static final String DEFAULT_DESCRIPTION_DATA = "Unknown";
-    public static final String KEY_MANUFACTURER = "manufacturer";
-    public static final String KEY_HWVERSION = "model-name";
-    public static final String KEY_SWVERSION = "software-version";
-    public static final String KEY_SERIALNUMBER = "serial-number";
-    public static final String KEY_PORTSTATUS = "status";
-    public static final String PORT_ENABLED = "ENABLED";
-    public static final String KEY_PORTLABEL = "label";
-    public static final int POLATIS_NUM_OF_WAVELENGTHS = 39;
-
     private final Logger log = getLogger(getClass());
 
     /**
@@ -89,32 +72,50 @@
      */
     @Override
     public DeviceDescription discoverDeviceDetails() {
+        log.debug("Discovering Polatis device detais...");
         return parseProductInformation();
     }
 
     private DeviceDescription parseProductInformation() {
         DeviceService devsvc = checkNotNull(handler().get(DeviceService.class));
-        DeviceId devid = handler().data().deviceId();
-        Device dev = devsvc.getDevice(devid);
-        if (dev == null) {
-            return new DefaultDeviceDescription(devid.uri(), FIBER_SWITCH,
-                    DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA,
-                    DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA,
-                    new ChassisId());
-        }
-        String reply = netconfGet(handler(), getProductInformationFilter());
+        DeviceId devID = handler().data().deviceId();
+        String reply = netconfGet(handler(), getProdInfoFilter());
         subscribe(handler());
         HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
-        return new DefaultDeviceDescription(dev.id().uri(), FIBER_SWITCH,
+        String hw = cfg.getString(KEY_HWVERSION);
+        String numInputPorts = "0";
+        String numOutputPorts = "0";
+        if (!hw.equals("")) {
+            Pattern patternSize = Pattern.compile("\\d+x[\\dC]+");
+            Matcher matcher = patternSize.matcher(hw);
+            if (matcher.find()) {
+                String switchSize = matcher.group();
+                log.debug("Got switch size: " + switchSize);
+                Pattern patternNumber = Pattern.compile("[\\dC]+");
+                matcher = patternNumber.matcher(switchSize);
+                if (matcher.find()) {
+                    numInputPorts = matcher.group();
+                    log.debug("numInputPorts=" + numInputPorts);
+                    if (matcher.find()) {
+                        if (!matcher.group().equals("CC")) {
+                            numOutputPorts = matcher.group();
+                        }
+                    }
+                log.debug("numOutputPorts=" + numOutputPorts);
+                }
+            }
+        } else {
+            log.warn("Unable to determine type of Polatis switch " + devID.toString());
+        }
+        DefaultAnnotations annotations = DefaultAnnotations.builder()
+                .set(KEY_INPUTPORTS, numInputPorts)
+                .set(KEY_OUTPUTPORTS, numOutputPorts)
+                .build();
+
+        return new DefaultDeviceDescription(devID.uri(), FIBER_SWITCH,
                 cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION),
                 cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER),
-                dev.chassisId());
-    }
-
-    private String getProductInformationFilter() {
-        return new StringBuilder(xmlOpen(KEY_PRODINF_XMLNS))
-                .append(xmlClose(KEY_PRODINF))
-                .toString();
+                new ChassisId(cfg.getString(KEY_SERIALNUMBER)), true, annotations);
     }
 
     /**
@@ -124,41 +125,14 @@
      */
     @Override
     public List<PortDescription> discoverPortDetails() {
+        log.debug("Discovering ports on Polatis switch...");
+        DeviceService deviceService = handler().get(DeviceService.class);
+        DeviceId deviceID = handler().data().deviceId();
+        Device device = deviceService.getDevice(deviceID);
+        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
+        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
         String reply = netconfGet(handler(), getPortsFilter());
-        List<PortDescription> descriptions = parsePorts(reply);
+        List<PortDescription> descriptions = parsePorts(reply, numInputPorts, numOutputPorts);
         return ImmutableList.copyOf(descriptions);
     }
-
-    private String getPortsFilter() {
-        return new StringBuilder(xmlOpen(KEY_PORTCONFIG_XMLNS))
-                .append(xmlOpen(KEY_PORT))
-                .append(xmlEmpty(KEY_PORTID))
-                .append(xmlEmpty(KEY_PORTSTATUS))
-                .append(xmlEmpty(KEY_PORTLABEL))
-                .append(xmlClose(KEY_PORT))
-                .append(xmlClose(KEY_PORTCONFIG))
-                .toString();
-    }
-
-    private List<PortDescription> parsePorts(String content) {
-        List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTCONFIG);
-        List<PortDescription> portDescriptions = Lists.newArrayList();
-        for (HierarchicalConfiguration portConfig : subtrees) {
-            portDescriptions.add(parsePort(portConfig));
-        }
-        return portDescriptions;
-    }
-
-    private PortDescription parsePort(HierarchicalConfiguration cfg) {
-        PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
-        DefaultAnnotations annotations = DefaultAnnotations.builder()
-                .set(AnnotationKeys.PORT_NAME, cfg.getString(KEY_PORTLABEL))
-                .build();
-        return omsPortDescription(portNumber,
-                cfg.getString(KEY_PORTSTATUS).equals(PORT_ENABLED),
-                Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX,
-                Frequency.ofGHz((Spectrum.O_BAND_MIN.asGHz() -
-                        Spectrum.L_BAND_MAX.asGHz()) /
-                    POLATIS_NUM_OF_WAVELENGTHS), annotations);
-    }
 }
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisFlowRuleProgrammable.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisFlowRuleProgrammable.java
index 52b7940..6f37960 100644
--- a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisFlowRuleProgrammable.java
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisFlowRuleProgrammable.java
@@ -19,59 +19,44 @@
 import org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.CrossConnects;
 import org.onosproject.yang.gen.v1.opticalswitch.rev20180322.opticalswitch.crossconnects.Pair;
 
-import com.google.common.collect.ImmutableList;
-
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.net.flow.DefaultFlowEntry;
 import org.onosproject.net.flow.FlowEntry;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.FlowRuleProgrammable;
-import org.onosproject.netconf.NetconfException;
 import org.slf4j.Logger;
 
 import java.util.Collection;
-import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.parseKeyPairCompat;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.parseConnections;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_SRC;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.KEY_DST;
 
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfEditConfig;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.opticalRevision;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configsAt;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlOpen;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlClose;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_CONNS;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_CONNS_XMLNS;
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_DATA_CONNS;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.CFG_MODE_MERGE;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
- * Flow rule programmable behaviour for polatis optical netconf devices.
+ * Flow rule programmable behaviour for Polatis optical netconf devices.
  */
 public class PolatisFlowRuleProgrammable
     extends AbstractHandlerBehaviour implements FlowRuleProgrammable {
 
     public static final String KEY_CHID = "wavelength-id";
-    public static final String KEY_SRC = "ingress";
-    public static final String KEY_DST = "egress";
     public static final String KEY_SRC_CHID = String.format("%s.%s", KEY_SRC, KEY_CHID);
     public static final String CFG_MODE_DELETE = "delete";
-    public static final String KEY_PAIR = "pair";
-    public static final String KEY_PAIRS = "pairs";
-    public static final String KEY_PAIR_DELETE = String.format("%s %s", KEY_PAIR, CFG_MODE_DELETE);
-    public static final String PAIR_COMPAT_REVISION = "2017-08-04";
 
     private static final Logger log = getLogger(PolatisFlowRuleProgrammable.class);
 
     @Override
     public Collection<FlowEntry> getFlowEntries() {
-        return parseConnections();
+        return parseConnections(this);
     }
 
     @Override
@@ -84,30 +69,6 @@
         return removeConnections(rules);
     }
 
-    private String getConnectionsFilter() {
-        return new StringBuilder(xmlOpen(KEY_CONNS_XMLNS))
-                .append(xmlClose(KEY_CONNS))
-                .toString();
-    }
-
-    private Collection<FlowEntry> parseConnections() {
-        log.debug("Fetch connections...");
-        String reply = netconfGet(handler(), getConnectionsFilter());
-        final String keyPairMode = String.format("%s.%s", KEY_DATA_CONNS, parseKeyPairCompat());
-        List<HierarchicalConfiguration> subtrees = configsAt(reply, keyPairMode);
-        ImmutableList.Builder<FlowEntry> connectionsBuilder = ImmutableList.builder();
-        for (HierarchicalConfiguration connection : subtrees) {
-            connectionsBuilder.add(new DefaultFlowEntry(parseConnection(connection), FlowEntry.FlowEntryState.ADDED));
-        }
-        return connectionsBuilder.build();
-    }
-
-    private FlowRule parseConnection(HierarchicalConfiguration cfg) {
-        return PolatisOpticalUtility.toFlowRule(this,
-                PortNumber.portNumber(cfg.getInt(KEY_SRC)),
-                PortNumber.portNumber(cfg.getInt(KEY_DST)));
-    }
-
     private Collection<FlowRule> applyConnections(Collection<FlowRule> rules) {
         return rules.stream()
                 .filter(c -> editConnection(c, CFG_MODE_MERGE))
@@ -118,7 +79,7 @@
         CrossConnects crossConnects = PolatisOpticalUtility.fromFlowRule(this, rule);
         final StringBuilder cfg = new StringBuilder(xmlOpen(KEY_CONNS_XMLNS));
         List<Pair> pairs = crossConnects.pair();
-        final String keyPairCompat = parseKeyPairCompat();
+        final String keyPairCompat = parseKeyPairCompat(this);
         final String keyPairMode = String.format("%s operation=\"%s\"", keyPairCompat, mode);
         pairs.forEach(p -> {
                 cfg.append(xmlOpen(keyPairMode))
@@ -140,24 +101,4 @@
                 .collect(Collectors.toList());
     }
 
-    private String parseKeyPairCompat() {
-        String rev = opticalRevision(handler());
-        if (rev == null) {
-            throw new IllegalStateException(new NetconfException("Failed to obtain the revision."));
-        }
-        String keyPairCompat;
-        try {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-            Date date = sdf.parse(PAIR_COMPAT_REVISION);
-
-            if (date.compareTo(sdf.parse(rev)) > 0) {
-                keyPairCompat = KEY_PAIRS;
-            } else {
-                keyPairCompat = KEY_PAIR;
-            }
-        } catch (ParseException e) {
-            throw new IllegalArgumentException(new NetconfException(String.format("Incorrect date format: %s", rev)));
-        }
-        return keyPairCompat;
-    }
 }
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisInternalConnectivity.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisInternalConnectivity.java
new file mode 100644
index 0000000..42fd5bb
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisInternalConnectivity.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2016-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.drivers.polatis.netconf;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.behaviour.InternalConnectivity;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.flow.FlowEntry;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.criteria.PortCriterion;
+import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.stream.Collectors;
+import org.slf4j.Logger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.*;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTDIR;
+
+
+/**
+ * Implements InternalConnectivity behaviour for Polatis optical switches.
+ */
+public class PolatisInternalConnectivity extends AbstractHandlerBehaviour
+        implements InternalConnectivity {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String JSON_PEERPORT_PEER_KEY = "peer";
+    private static final String JSON_PEERPORT_PEER_DEVICEID_KEY = "id";
+    private static final String JSON_PEERPORT_PEER_PORTID_KEY = "port";
+    private static final String SCHEME_NAME = "linkdiscovery";
+
+    /**
+     * Constructor just used to initiate logging when InternalConnectivity behaviour is invoked.
+     */
+    public PolatisInternalConnectivity() {
+        log.debug("Running PolatisInternalConnectivity handler");
+    }
+
+    /**
+     * Returns boolean in response to test of whether 2 ports on a given device can be internally connected.
+     * <p>
+     * This is a callback method required by the InternalConnectivity behaviour.
+     * @param  inputPortNum  Input port number on device
+     * @param  outputPortNum Output port number on device
+     * @return               Indication whether internal connection can be made
+     */
+    @Override
+    public boolean testConnectivity(PortNumber inputPortNum, PortNumber outputPortNum) {
+
+        // NOTE: this is implemented symmetrically reflecting the fact that reverse propagation
+        // is possible through a Polatis switch
+        if (inputPortNum.equals(outputPortNum)) {
+            log.debug("Input and output ports cannot be one and the same");
+            return false;
+        }
+        DeviceId deviceID = handler().data().deviceId();
+        DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
+        Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
+        Port outputPort = deviceService.getPort(new ConnectPoint(deviceID, outputPortNum));
+        if (!inputPort.isEnabled()) {
+            log.debug("Input port is DISABLED");
+            return false;
+        }
+        if (!outputPort.isEnabled()) {
+            log.debug("Output port is DISABLED");
+            return false;
+        }
+        if (!inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
+            if (inputPort.annotations().value(KEY_PORTDIR).equals(outputPort.annotations().value(KEY_PORTDIR))) {
+                log.debug("Dual sided switch and provided input & output ports on same side");
+                return false;
+            }
+        }
+        // Check if either port is used in an active cross-connect
+        Set<PortNumber> usedPorts = getUsedPorts();
+        if (usedPorts.contains(inputPortNum)) {
+            log.debug("Input port {} is used in an active cross-connect", inputPortNum);
+            return false;
+        }
+        if (usedPorts.contains(outputPortNum)) {
+            log.debug("Output port {} is used in an active cross-connect", outputPortNum);
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Returns a set of possible output PortNumbers to which a given input port can be internally connected
+     * on a given device.
+     * <p>
+     * This is a callback method required by the InternalConnectivity behaviour.
+     * @param inputPortNum Input port number on device
+     * @return             List of possible output ports
+     */
+    @Override
+    public Set<PortNumber> getOutputPorts(PortNumber inputPortNum) {
+
+        // NOTE: in this implementation, inputPortNum is the supplied port number and
+        // can be an "input" port OR an "output" port
+        // This reflects the fact that reverse propagation is possible through a Polatis switch
+        // (output port -> input port)
+
+        Set<PortNumber> ports = new HashSet<PortNumber>();
+        Set<PortNumber> enabledPorts = new HashSet<PortNumber>();
+        Collection<FlowEntry> flowEntries = parseConnections(this);
+        // Flow entries are very simple for an all-optical circuit switch which doesn't multicast
+        // e.g. one selector (IN_PORT) and one action (set output port)
+        if (flowEntries.stream().map(flow -> ((PortCriterion) flow.selector()
+                                             .getCriterion(Criterion.Type.IN_PORT)).port())
+                                .collect(Collectors.toSet())
+                                .contains(inputPortNum) ||
+            flowEntries.stream().map(flow -> ((OutputInstruction) flow.treatment()
+                                             .allInstructions().get(0)).port())
+                                .collect(Collectors.toSet())
+                                .contains(inputPortNum)) {
+            log.warn("Queried port {} is already used in a cross-connect", inputPortNum);
+            return ports;
+        } else {
+            DeviceId deviceID = handler().data().deviceId();
+            DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
+            Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
+            if (inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
+                ports = deviceService.getPorts(deviceID).stream()
+                        .filter(p -> !p.equals(inputPortNum))
+                        .map(p -> p.number())
+                        .collect(Collectors.toSet());
+            } else {
+                ports = deviceService.getPorts(deviceID).stream()
+                        .filter((p) -> {
+                            Port port = deviceService.getPort(new ConnectPoint(deviceID, p.number()));
+                            return !port.annotations().value(KEY_PORTDIR).equals(
+                                inputPort.annotations().value(KEY_PORTDIR));
+                         })
+                        .map(p -> p.number())
+                        .collect(Collectors.toSet());
+            }
+            // Remove disabled ports
+            enabledPorts = ports.stream()
+                .filter(p -> deviceService.getPort(new ConnectPoint(deviceID, p)).isEnabled())
+                .collect(Collectors.toSet());
+        }
+        log.debug("Ports before filtering out used and disabled ones: " + ports);
+        return filterUsedPorts(enabledPorts, flowEntries);
+    }
+
+    /**
+     * Returns a set of possible input PortNumbers to which a given output port can be internally connected
+     * on a given device.
+     * <p>
+     * This is a callback method required by the InternalConnectivity behaviour.
+     * This just calls the getOutputPorts method since reverse path optical transmission is possible through
+     * a Polatis switch.
+     * @param outputPortNum Input port number on device
+     * @return              List of possible input ports
+     */
+    @Override
+    public Set<PortNumber> getInputPorts(PortNumber outputPortNum) {
+
+        return getOutputPorts(outputPortNum);
+    }
+
+    private Set<PortNumber> filterUsedPorts(Set<PortNumber> ports, Collection<FlowEntry> flowEntries) {
+
+        if (ports.isEmpty() || flowEntries.isEmpty()) {
+            return ports;
+        }
+        for (FlowEntry flowEntry : flowEntries) {
+            PortNumber inputPort = ((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port();
+            ports.remove(inputPort);
+            PortNumber outputPort = ((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port();
+            ports.remove(outputPort);
+            log.debug("Cross-connection {}-{} removed from output port list", inputPort, outputPort);
+        }
+        log.debug("Ports after filtering out used ones: " + ports);
+        return ports;
+    }
+
+    private Set<PortNumber> getUsedPorts() {
+        Set<PortNumber> usedPorts = new HashSet<PortNumber>();
+        Collection<FlowEntry> flowEntries = parseConnections(this);
+        for (FlowEntry flowEntry : flowEntries) {
+            usedPorts.add(((PortCriterion) flowEntry.selector().getCriterion(Criterion.Type.IN_PORT)).port());
+            usedPorts.add(((OutputInstruction) flowEntry.treatment().allInstructions().get(0)).port());
+        }
+        return usedPorts;
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisLinkDiscovery.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisLinkDiscovery.java
new file mode 100644
index 0000000..3640a2a
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisLinkDiscovery.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright 2016-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.drivers.polatis.netconf;
+
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.Port;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.LinkDiscovery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfSession;
+import org.slf4j.Logger;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.*;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTPEER;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTDIR;
+
+
+/**
+ * Reads peer-port fields from a Polatis switch, parses them and returns a set of LinkDescriptions.
+ */
+public class PolatisLinkDiscovery extends AbstractHandlerBehaviour implements LinkDiscovery {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String JSON_PEERPORT_PEER_KEY = "peer";
+    private static final String JSON_PEERPORT_PEER_DEVICEID_KEY = "id";
+    private static final String JSON_PEERPORT_PEER_PORTID_KEY = "port";
+    private static final String SCHEME_NAME = "linkdiscovery";
+
+    /**
+     * Constructor just used to initiate logging when LinkDiscovery behaviour is invoked.
+     */
+    public PolatisLinkDiscovery() {
+        log.debug("Running PolatisLinkDiscovery handler");
+    }
+
+    /**
+     * Returns the set of LinkDescriptions originating from a Polatis switch.
+     * <p>
+     * This is the callback required by the LinkDiscovery behaviour.
+     * @return Set of outbound unidirectional links as LinkDescriptions
+     */
+    @Override
+    public Set<LinkDescription> getLinks() {
+        Set<LinkDescription> links = new HashSet<>();
+        DeviceId deviceID = handler().data().deviceId();
+        log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
+        NetconfController controller = checkNotNull(handler().get(NetconfController.class));
+        if (controller == null || controller.getDevicesMap() == null
+                || controller.getDevicesMap().get(deviceID) == null) {
+            log.warn("NETCONF session to device {} not yet established, will try again...", deviceID);
+            return links;
+        }
+        DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
+        Device device = deviceService.getDevice(deviceID);
+        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
+        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
+        log.trace("Talking to device " + handler().data().deviceId().toString());
+        String reply = netconfGet(handler(), getPortsFilter());
+        // Get port details from switch as PortDescription objects
+        List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
+        int numPeerPortEntries = 0;
+        int numPortsScanned = 0;
+        ObjectMapper mapper = new ObjectMapper();
+        for (PortDescription port : ports) {
+            numPortsScanned++;
+            if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
+                String peerPortData = port.annotations().value(KEY_PORTPEER);
+                if (!peerPortData.equals("")) {
+                    numPeerPortEntries++;
+                    if (peerPortData.charAt(0) == '{') {
+                        ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
+                        ConnectPoint farEndCP = null;
+                        try {
+                            farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
+                        } catch (JsonProcessingException jpe) {
+                            log.debug("Error processing peer-port JSON: {}", jpe.toString());
+                        }
+                        if (farEndCP != null) {
+                            log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(),
+                                      farEndCP.toString());
+                            if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
+                                log.trace("Peer {} checks out", farEndCP.toString());
+                                // now add link to Set<LinkDescription>
+                                DefaultAnnotations annotations = DefaultAnnotations.builder()
+                                                                 .set(KEY_LINKBIDIR, VALUE_FALSE)
+                                                                 .set(KEY_LINKALLOWED, VALUE_TRUE)
+                                                                 .build();
+                                ConnectPoint aEndCP = nearEndCP;
+                                ConnectPoint bEndCP = farEndCP;
+                                // reverse direction of unidirectional link if near-end port is INPUT
+                                if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
+                                    aEndCP = farEndCP;
+                                    bEndCP = nearEndCP;
+                                }
+                                LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP,
+                                                                  Link.Type.OPTICAL, true, annotations);
+                                links.add(newLinkDesc);
+                                log.debug("Adding link {}", newLinkDesc);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries,
+                  links.size(), links.size() == 1 ? "is" : "are");
+        log.trace("Links found on this iteration: {}", links);
+        return links;
+    }
+
+    private ConnectPoint parsePeerportDataForCP(JsonNode peerData) {
+    DeviceId idTo = DeviceId.NONE;
+    PortNumber portNumTo = PortNumber.portNumber(0L);
+        JsonNode peer = peerData.get(JSON_PEERPORT_PEER_KEY);
+        if (peer != null) {
+            log.trace("Found peer element: {}", peer.toString());
+            JsonNode devIDNode = peer.get(JSON_PEERPORT_PEER_DEVICEID_KEY);
+            if (devIDNode != null) {
+                String devID = peer.get(JSON_PEERPORT_PEER_DEVICEID_KEY).asText();
+                log.trace("Found devID: {}", devID);
+                idTo = DeviceId.deviceId(devID);
+                JsonNode portNode = peer.get(JSON_PEERPORT_PEER_PORTID_KEY);
+                if (portNode != null) {
+                    portNumTo = PortNumber.portNumber(portNode.asInt());
+                        if (portNumTo.toLong() != 0) {
+                            log.trace("Found legal peer JSON element: {}={}, {}={}", JSON_PEERPORT_PEER_DEVICEID_KEY,
+                                      idTo.toString(), JSON_PEERPORT_PEER_PORTID_KEY, portNumTo.toString());
+                        } else {
+                            log.trace("Malformed peer-port JSON: non-numerical or zero port value");
+                        }
+                    } else {
+                        log.trace("Malformed peer-port JSON: unable to find \"{}\" key in {}",
+                                  JSON_PEERPORT_PEER_PORTID_KEY, peer.toString());
+                    }
+                } else {
+                    log.trace("Malformed peer-port JSON: unable to find \"{}\" key in {}",
+                              JSON_PEERPORT_PEER_DEVICEID_KEY, peer.toString());
+                }
+            } else {
+                log.trace("Malformed peer-port JSON: unable to find \"{}\" key in {}", JSON_PEERPORT_PEER_KEY,
+                          peerData.toString());
+            }
+        return (idTo.equals(DeviceId.NONE) || portNumTo.toLong() == 0) ? null : new ConnectPoint(idTo, portNumTo);
+    }
+
+    private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
+        // check peerCP exists and is available (either via device service or direct from device)
+        DeviceId peerDeviceID = peerCP.deviceId();
+        boolean result = false;
+        DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
+        if (deviceService.isAvailable(peerDeviceID)) {
+            log.trace("Peer device {} exists", peerDeviceID.toString());
+            Device device = deviceService.getDevice(peerDeviceID);
+            int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
+            int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
+            List<Port> ports = deviceService.getPorts(peerDeviceID);
+            PortNumber farEndPortNum = peerCP.port();
+            Port port = deviceService.getPort(peerCP);
+            if (port != null) {
+                if (port.isEnabled()) {
+                    log.trace("Peer port {} exists", port.number().toLong());
+                    // check far end peer-port entry (use device service or retrieve direct from switch)
+                    Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
+                    String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
+                    if (direct) {
+                        log.trace("Checking device {} DIRECT", handler.data().deviceId());
+                        //A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
+                        NetconfController controller = checkNotNull(handler.get(NetconfController.class));
+                        NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
+                        String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
+                        PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
+                        log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
+                        String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
+                        farEndPortPeerportData = farEndPortPeerportDataDirect;
+                    }
+                    if (!farEndPortPeerportData.equals("")) {
+                        if (farEndPortPeerportData.charAt(0) == '{') {
+                            log.trace("Far-end peer-port value:" + farEndPortPeerportData);
+                            ObjectMapper mapper = new ObjectMapper();
+                            ConnectPoint checkNearEndCP = null;
+                            try {
+                                checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
+                            } catch (JsonProcessingException jpe) {
+                                log.trace("Error processing peer-port JSON: {}", jpe.toString());
+                            }
+                            if (nearEndCP.equals(checkNearEndCP)) {
+                                log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP,
+                                          checkNearEndCP);
+                                result = true;
+                            } else {
+                                log.trace("Peer-port entry for far-end port ({}) does not match near-end " +
+                                          "port number ({})", checkNearEndCP, nearEndCP);
+                            }
+                        }
+                    } else {
+                        log.trace("Null peer-port entry for far-end port ({})", peerCP);
+                    }
+                } else {
+                    log.trace("Peer port {} is DISABLED", port);
+                }
+            } else {
+                log.trace("Peer port {} does not exist", port);
+            }
+        } else {
+            log.trace("Far end device does not exist or is not available");
+        }
+        return result;
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
index ee1fe39..4f75923 100644
--- a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
@@ -43,16 +43,24 @@
     public static final String KEY_POLATIS_XMLNS = "xmlns=\"http://www.polatis.com/yang/polatis-switch\"";
     public static final String KEY_DATA = "data";
     public static final String KEY_PORT = "port";
+    public static final String KEY_PAIR = "pair";
+    public static final String KEY_PAIRS = "pairs";
     public static final String KEY_PORTID = "port-id";
+    public static final String KEY_PORTPEER = "portPeer";
+    public static final String KEY_PORTDIR = "portDir";
     public static final String KEY_PORTCONFIG = "port-config";
     public static final String KEY_SYSTEMALARMS = "system-alarms";
     public static final String KEY_ALARM = "alarm";
     public static final String KEY_CONNS = "cross-connects";
     public static final String KEY_PRODINF = "product-information";
+    public static final String KEY_PORTSETSTATE = "port-set-state";
+    public static final String KEY_RPCREPLY = "rpc-reply";
+    public static final String KEY_OK = "<ok/>";
     public static final String KEY_PORTCONFIG_XMLNS = String.format("%s %s", KEY_PORTCONFIG, KEY_XMLNS);
     public static final String KEY_SYSTEMALARMS_XMLNS = String.format("%s %s", KEY_SYSTEMALARMS, KEY_POLATIS_XMLNS);
     public static final String KEY_CONNS_XMLNS = String.format("%s %s", KEY_CONNS, KEY_XMLNS);
     public static final String KEY_PRODINF_XMLNS = String.format("%s %s", KEY_PRODINF, KEY_XMLNS);
+    public static final String KEY_PORTSETSTATE_XMLNS = String.format("%s %s", KEY_PORTSETSTATE, KEY_XMLNS);
     public static final String KEY_DATA_CONNS = String.format("%s.%s", KEY_DATA, KEY_CONNS);
     public static final String KEY_DATA_PRODINF = String.format("%s.%s", KEY_DATA, KEY_PRODINF);
     public static final String KEY_DATA_PORTCONFIG = String.format("%s.%s.%s", KEY_DATA, KEY_PORTCONFIG, KEY_PORT);
@@ -69,7 +77,7 @@
 
     public static final String CFG_MODE_MERGE = "merge";
 
-    private static final Logger log = getLogger(PolatisFlowRuleProgrammable.class);
+    private static final Logger log = getLogger(PolatisDeviceDescription.class);
 
     private PolatisNetconfUtility() {
     }
@@ -93,6 +101,23 @@
     }
 
     /**
+     * Retrieves session reply information for get operation.
+     *
+     * @param session explicit NETCONF session
+     * @param filter the filter string of xml content
+     * @return the reply string
+     */
+    public static String netconfGet(NetconfSession session, String filter) {
+        String reply;
+        try {
+            reply = session.get(filter, null);
+        } catch (NetconfException e) {
+            throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
+        }
+        return reply;
+    }
+
+    /**
      * Retrieves session reply information for get config operation.
      *
      * @param handler parent driver handler
@@ -130,6 +155,24 @@
     }
 
     /**
+     * Makes a NETCONF RPC.
+     *
+     * @param handler parent driver handler
+     * @param body body of RPC
+     * @return the reply string
+     */
+    public static String netconfRpc(DriverHandler handler, String body) {
+        NetconfSession session = getNetconfSession(handler);
+        String reply;
+        try {
+            reply = session.doWrappedRpc(body);
+        } catch (NetconfException e) {
+            throw new IllegalStateException(new NetconfException("Failed to make RPC..", e));
+        }
+        return reply;
+    }
+
+    /**
      * Retrieves specified node hierarchical configuration from the xml information.
      *
      * @param content the xml information
@@ -139,7 +182,7 @@
     public static HierarchicalConfiguration configAt(String content, String key) {
         HierarchicalConfiguration info;
         try {
-            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
+            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content, false);
             info = cfg.configurationAt(key);
         } catch (IllegalArgumentException e) {
             // Accept null for information polling
@@ -158,8 +201,9 @@
     public static List<HierarchicalConfiguration> configsAt(String content, String key) {
         List<HierarchicalConfiguration> info;
         try {
-            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
+            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content, false);
             info = cfg.configurationsAt(key);
+
         } catch (IllegalArgumentException e) {
             // Accept empty for information polling
             return ImmutableList.of();
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPortAdmin.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPortAdmin.java
new file mode 100644
index 0000000..55d88d2
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPortAdmin.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2018-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.drivers.polatis.netconf;
+
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.PortAdmin;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.slf4j.Logger;
+
+import java.util.concurrent.CompletableFuture;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisUtility.*;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfRpc;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_OK;
+
+
+/**
+ * Handles port administration for Polatis switches using NETCONF.
+ */
+public class PolatisPortAdmin extends AbstractHandlerBehaviour implements PortAdmin {
+
+    public static final Logger log = getLogger(PolatisPortAdmin.class);
+
+
+    /**
+     * Sets the administrative state of the given port to the given value.
+     *
+     * @param portNumber Port number
+     * @param state      State, PC_ENABLED or PC_DISABLED
+     * @return           True if successfully set
+     */
+    private CompletableFuture<Boolean> setAdminState(PortNumber portNumber, String state) {
+
+        boolean result = false;
+        try {
+            log.debug("Sending RPC to {} to set port {} to {}", handler().data().deviceId(), portNumber, state);
+            String cmdBody = getRpcSetPortStateBody(state.equals(PORT_ENABLED) ? KEY_ENABLE : KEY_DISABLE, portNumber);
+            String response = netconfRpc(handler(),
+                              getRpcSetPortStateBody(state.equals(PORT_ENABLED) ? KEY_ENABLE : KEY_DISABLE,
+                              portNumber));
+            log.trace("Response from RPC: " + response);
+            result = response.contains(KEY_OK);
+        } catch (IllegalStateException e) {
+            log.error("Unable to set port admin state for {}/{} to {}", handler().data().deviceId(), portNumber,
+                      state, e);
+        }
+        return CompletableFuture.completedFuture(result);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> enable(PortNumber portNumber) {
+        return setAdminState(portNumber, PORT_ENABLED);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> disable(PortNumber portNumber) {
+        return setAdminState(portNumber, PORT_DISABLED);
+    }
+
+    @Override
+    public CompletableFuture<Boolean> isEnabled(PortNumber portNumber) {
+        boolean result = false;
+        try {
+            log.debug("Querying port state for port {} from device {}", portNumber, handler().data().deviceId());
+            String response = netconfGet(handler(), getPortStatusFilter(portNumber));
+            result = response.equals(PORT_ENABLED);
+            log.debug("Port {}/{} is {}", handler().data().deviceId(), portNumber, result);
+        } catch (IllegalStateException e) {
+            log.error("Unable to query port state for port {} from device {}", portNumber,
+                      handler().data().deviceId(), e);
+        }
+        return CompletableFuture.completedFuture(result);
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisUtility.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisUtility.java
new file mode 100644
index 0000000..ee55715
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisUtility.java
@@ -0,0 +1,317 @@
+/*
+ * Copyright 2017 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.drivers.polatis.netconf;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.onlab.util.Frequency;
+import org.onlab.util.Spectrum;
+
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import com.google.common.collect.ImmutableList;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.flow.DefaultFlowEntry;
+import org.onosproject.net.flow.FlowEntry;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.driver.HandlerBehaviour;
+import org.onosproject.netconf.NetconfException;
+
+import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configsAt;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlOpen;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xml;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlClose;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlEmpty;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.opticalRevision;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PAIR;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PAIRS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORT;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTID;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTPEER;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTDIR;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTCONFIG;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PRODINF;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_CONNS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTSETSTATE;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTCONFIG_XMLNS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PRODINF_XMLNS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_CONNS_XMLNS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTSETSTATE_XMLNS;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_DATA_PORTCONFIG;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_DATA_CONNS;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+
+/**
+ * Polatis common utilities.
+ */
+public final class PolatisUtility {
+
+    public static final String DEFAULT_MANUFACTURER = "Polatis";
+    public static final String DEFAULT_DESCRIPTION_DATA = "Unknown";
+    public static final String KEY_MANUFACTURER = "manufacturer";
+    public static final String KEY_HWVERSION = "model-name";
+    public static final String KEY_SWVERSION = "software-version";
+    public static final String KEY_SERIALNUMBER = "serial-number";
+    public static final String KEY_INPUTPORTS = "inputPorts";
+    public static final String KEY_OUTPUTPORTS = "outputPorts";
+    public static final String KEY_PORTSTATUS = "status";
+    public static final String KEY_ENABLE = "ENABLE";
+    public static final String KEY_DISABLE = "DISABLE";
+    public static final String KEY_INGRESS = "ingress";
+    public static final String KEY_EGRESS = "egress";
+    public static final String VALUE_TRUE = "true";
+    public static final String VALUE_FALSE = "false";
+    public static final String VALUE_INPUT = "INPUT";
+    public static final String VALUE_OUTPUT = "OUTPUT";
+    public static final String VALUE_UNKNOWN = "UNKNOWN";
+    public static final String VALUE_CC = "CC";
+    public static final String KEY_RPCENABLE = "port-enab";
+    public static final String KEY_RPCDISABLE = "port-disab";
+    public static final String PORT_ENABLED = "ENABLED";
+    public static final String PORT_DISABLED = "DISABLED";
+    public static final String KEY_PORTLABEL = "label";
+    public static final String KEY_PEERPORT = "peer-port";
+    public static final String KEY_LINKBIDIR = "bidirectional";
+    public static final String KEY_LINKALLOWED = "allowed";
+    public static final String KEY_SRC = "ingress";
+    public static final String KEY_DST = "egress";
+    public static final String PAIR_COMPAT_REVISION = "2017-08-04";
+
+    public static final int POLATIS_NUM_OF_WAVELENGTHS = 39;
+
+    private static final Logger log = getLogger(PolatisDeviceDescription.class);
+
+    private PolatisUtility() {
+    }
+
+    /**
+     * Returns XML subtree filter term for NETCONF get[-config] RPC for retrieving product info from a Polatis switch.
+     *
+     * @return Filter term as string
+     */
+    public static String getProdInfoFilter() {
+        return new StringBuilder(xmlOpen(KEY_PRODINF_XMLNS))
+            .append(xmlClose(KEY_PRODINF))
+            .toString();
+    }
+
+    /**
+     * Returns XML subtree filter term for NETCONF get[-config] RPC for retrieving cross-connections on a
+     * Polatis switch.
+     *
+     * @return Filter term as string
+     */
+    public static String getConnectionsFilter() {
+        return new StringBuilder(xmlOpen(KEY_CONNS_XMLNS))
+                .append(xmlClose(KEY_CONNS))
+                .toString();
+    }
+
+    /**
+     * Returns XML subtree filter term for NETCONF get[-config] RPC for retrieving config and state data for all ports
+     * on a Polatis switch.
+     *
+     * @return Filter term as string
+     */
+    public static String getPortsFilter() {
+        return new StringBuilder(xmlOpen(KEY_PORTCONFIG_XMLNS))
+            .append(xmlOpen(KEY_PORT))
+            .append(xmlEmpty(KEY_PORTID))
+            .append(xmlEmpty(KEY_PORTSTATUS))
+            .append(xmlEmpty(KEY_PORTLABEL))
+            .append(xmlEmpty(KEY_PEERPORT))
+            .append(xmlClose(KEY_PORT))
+            .append(xmlClose(KEY_PORTCONFIG))
+            .toString();
+    }
+
+    /**
+     * Returns XML subtree filter term for NETCONF get[-config] RPC for retrieving config and state data for a specific
+     * port on a Polatis switch.
+     *
+     * @param portNum Port number as PortNumber object
+     * @return        Filter term as string
+     */
+    public static String getPortFilter(PortNumber portNum) {
+        return new StringBuilder(xmlOpen(KEY_PORTCONFIG_XMLNS))
+            .append(xmlOpen(KEY_PORT))
+            .append(xml(KEY_PORTID, portNum.toString()))
+            .append(xmlEmpty(KEY_PORTSTATUS))
+            .append(xmlEmpty(KEY_PORTLABEL))
+            .append(xmlEmpty(KEY_PEERPORT))
+            .append(xmlClose(KEY_PORT))
+            .append(xmlClose(KEY_PORTCONFIG))
+            .toString();
+    }
+
+    /**
+     * Returns XML subtree filter term for NETCONF get RPC for retrieving state data (only) for a specific port on a
+     * Polatis switch.
+     *
+     * @param portNum Port number as PortNumber object
+     * @return        Filter term as string
+     */
+    public static String getPortStatusFilter(PortNumber portNum) {
+        return new StringBuilder(xmlOpen(KEY_PORTCONFIG_XMLNS))
+            .append(xmlOpen(KEY_PORT))
+            .append(xml(KEY_PORTID, portNum.toString()))
+            .append(xmlEmpty(KEY_PORTSTATUS))
+            .append(xmlClose(KEY_PORT))
+            .append(xmlClose(KEY_PORTCONFIG))
+            .toString();
+    }
+
+     /**
+     * Returns XML body for NETCONF RPC for setting the admin status of a specific port on a Polatis switch.
+     *
+     * @param action  Action (enable/disable) to be performed on port as string
+     * @param portNum Port number as PortNumber object
+     * @return        RPC body (XML) as string
+     */
+    public static String getRpcSetPortStateBody(String action, PortNumber portNum) {
+        return new StringBuilder(xmlOpen(KEY_PORTSETSTATE_XMLNS))
+            .append(xmlOpen(action.equals(KEY_ENABLE) ? KEY_RPCENABLE : KEY_RPCDISABLE))
+            .append(portNum.toString())
+            .append(xmlClose(action.equals(KEY_ENABLE) ? KEY_RPCENABLE : KEY_RPCDISABLE))
+            .append(xmlClose(KEY_PORTSETSTATE))
+            .toString();
+    }
+
+     /**
+     * Returns a list of PortDescriptions from parsing the content of the reply to a get[-config] call to a
+     * Polatis switch.
+     *
+     * @param content        XML to be parsed as string
+     * @param numInputPorts  Number of input ports
+     * @param numOutputPorts Number of output ports
+     * @return               List of ports as PortDescription objects
+     */
+    public static List<PortDescription> parsePorts(String content, int numInputPorts, int numOutputPorts) {
+        List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTCONFIG);
+        List<PortDescription> portDescriptions = new ArrayList<PortDescription>();
+        for (HierarchicalConfiguration portConfig : subtrees) {
+            PortDescription parsedPort = parsePort(portConfig, numInputPorts, numOutputPorts == 0 ? true : false);
+            portDescriptions.add(parsedPort);
+        }
+        return portDescriptions;
+    }
+
+    /**
+     * Returns a single PortDescription from parsing a HierarchicalConfiguration object containing a Polatis switch
+     * port config.
+     *
+     * @param cfg            Single port as HierarchicalConfiguration object
+     * @param numInputPorts  Number of input ports
+     * @param isConfigurable Switch is CC
+     * @return               Single port as PortDescription object
+     */
+    public static PortDescription parsePort(HierarchicalConfiguration cfg, int numInputPorts, boolean isConfigurable) {
+        PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
+        String portType = VALUE_UNKNOWN;
+        if (isConfigurable) {
+            portType = VALUE_CC;
+        } else {
+            portType = portNumber.toLong() > numInputPorts ? VALUE_OUTPUT : VALUE_INPUT;
+        }
+        String peerPort = cfg.getString(KEY_PEERPORT);
+        DefaultAnnotations annotations = DefaultAnnotations.builder()
+                .set(AnnotationKeys.PORT_NAME, cfg.getString(KEY_PORTLABEL))
+                .set(KEY_PORTPEER, cfg.getString(KEY_PEERPORT))
+                .set(KEY_PORTDIR, portType)
+                .build();
+        return omsPortDescription(portNumber,
+                cfg.getString(KEY_PORTSTATUS).equals(PORT_ENABLED),
+                Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX,
+                Frequency.ofGHz(6_25), annotations);
+    }
+
+    /**
+     * Returns flow entries representing current cross-connections on a Polatis optical switch.
+     *
+     * @param behaviour HandlerBehaviour object associated with device being queried
+     * @return          Cross-connections as a collection of FlowEntry objects
+     */
+    public static Collection<FlowEntry> parseConnections(HandlerBehaviour behaviour) {
+        log.debug("Fetch connections...");
+        String reply = netconfGet(behaviour.handler(), getConnectionsFilter());
+        final String keyPairMode = String.format("%s.%s", KEY_DATA_CONNS, parseKeyPairCompat(behaviour));
+        List<HierarchicalConfiguration> subtrees = configsAt(reply, keyPairMode);
+        ImmutableList.Builder<FlowEntry> connectionsBuilder = ImmutableList.builder();
+        for (HierarchicalConfiguration connection : subtrees) {
+            connectionsBuilder.add(new DefaultFlowEntry(parseConnection(connection, behaviour),
+                                   FlowEntry.FlowEntryState.ADDED));
+        }
+        return connectionsBuilder.build();
+    }
+
+    /**
+     * Returns single cross-connection as FlowRule object from parsing HierarchicalConfiguration object.
+     *
+     * @param cfg       Single cross-connection as XML encoded in HierarchicalConfiguration object
+     * @param behaviour HandlerBehaviour object associated with device from which cross-connection has been retrieved
+     * @return          Cross-connection as a FlowEntry object
+     */
+    public static FlowRule parseConnection(HierarchicalConfiguration cfg, HandlerBehaviour behaviour) {
+        return PolatisOpticalUtility.toFlowRule(behaviour,
+                PortNumber.portNumber(cfg.getInt(KEY_SRC)),
+                PortNumber.portNumber(cfg.getInt(KEY_DST)));
+    }
+
+    /**
+     * Returns string containing the correct name of the YANG list node containing the cross-connections on a specific
+     * Polatis optical switch.
+     * <p>
+     * This handles the backwards incompatible change ('pairs' to 'pair') introduced in the Polatis optical-switch
+     * YANG module in revision 2017-08-04
+     *
+     * @param behaviour HandlerBehaviour object associated with the ONOS device representing a particular Polatis
+     *                  optical switch
+     * @return          Correct YANG list node name as string
+     */
+    public static String parseKeyPairCompat(HandlerBehaviour behaviour) {
+        String rev = opticalRevision(behaviour.handler());
+        if (rev == null) {
+            throw new IllegalStateException(new NetconfException("Failed to obtain the revision."));
+        }
+        String keyPairCompat;
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Date date = sdf.parse(PAIR_COMPAT_REVISION);
+
+            if (date.compareTo(sdf.parse(rev)) > 0) {
+                keyPairCompat = KEY_PAIRS;
+            } else {
+                keyPairCompat = KEY_PAIR;
+            }
+        } catch (ParseException e) {
+            throw new IllegalArgumentException(new NetconfException(String.format("Incorrect date format: %s", rev)));
+        }
+        return keyPairCompat;
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
index b1a8d45..e22bd79 100644
--- a/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
+++ b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
@@ -21,6 +21,12 @@
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.drivers.polatis.netconf.PolatisDeviceDescription"/>
+        <behaviour api="org.onosproject.net.behaviour.LinkDiscovery"
+		   impl="org.onosproject.drivers.polatis.netconf.PolatisLinkDiscovery"/>
+	<behaviour api="org.onosproject.net.behaviour.PortAdmin"
+                   impl="org.onosproject.drivers.polatis.netconf.PolatisPortAdmin"/>
+        <behaviour api="org.onosproject.net.behaviour.InternalConnectivity"
+                   impl="org.onosproject.drivers.polatis.netconf.PolatisInternalConnectivity"/>
         <behaviour api="org.onosproject.net.behaviour.PowerConfig"
                    impl="org.onosproject.drivers.polatis.netconf.PolatisPowerConfig"/>
         <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"