Add a Polatis NETCONF driver

Change-Id: Iecfe8df9d656bebbe82bf01bcaf185a77ccd26d8
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/config/PolatisDeviceDiscovery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/config/PolatisDeviceDiscovery.java
deleted file mode 100644
index 170930f..0000000
--- a/drivers/optical/src/main/java/org/onosproject/driver/optical/config/PolatisDeviceDiscovery.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2017-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.driver.optical.config;
-
-import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.LongStream;
-
-import org.onlab.packet.ChassisId;
-import org.onlab.util.Frequency;
-import org.onlab.util.Spectrum;
-import org.onosproject.net.Device.Type;
-import org.onosproject.net.DefaultAnnotations;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.SparseAnnotations;
-import org.onosproject.net.device.DefaultDeviceDescription;
-import org.onosproject.net.device.DeviceDescription;
-import org.onosproject.net.device.DeviceDescriptionDiscovery;
-import org.onosproject.net.device.PortDescription;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-
-/**
- * DeviceDescriptionDiscovery for Polatis.
- */
-public class PolatisDeviceDiscovery
-    extends AbstractHandlerBehaviour
-    implements DeviceDescriptionDiscovery {
-
-
-    @Override
-    public DeviceDescription discoverDeviceDetails() {
-        Type type = Type.FIBER_SWITCH;
-        String manufacturer = "Polatis";
-        String hwVersion = "N-VST-48x48-HU1-DMHNV-805";
-        String swVersion = "6.6.1.7";
-        String serialNumber = "1503";
-        ChassisId chassis = new ChassisId();
-        boolean defaultAvailable = true;
-        SparseAnnotations annotations = DefaultAnnotations.builder().build();
-        return new DefaultDeviceDescription(this.data().deviceId().uri(),
-                                            type,
-                                            manufacturer,
-                                            hwVersion,
-                                            swVersion,
-                                            serialNumber,
-                                            chassis,
-                                            defaultAvailable,
-                                            annotations);
-    }
-
-    @Override
-    public List<PortDescription> discoverPortDetails() {
-        SparseAnnotations ingress = DefaultAnnotations.builder()
-                .set("port-type", "INGRESS_PORT")
-                .build();
-        SparseAnnotations egress = DefaultAnnotations.builder()
-                .set("port-type", "EGRESS_PORT")
-                .build();
-        return LongStream.rangeClosed(1, 96)
-            .mapToObj(n -> omsPortDescription(PortNumber.portNumber(n),
-                           true,
-                           Spectrum.U_BAND_MIN,
-                           Spectrum.O_BAND_MAX,
-                           Frequency.ofGHz(100),
-                           (n <= 48) ? ingress : egress)
-                )
-            .collect(Collectors.toList());
-    }
-
-}
diff --git a/drivers/optical/src/main/resources/optical-drivers.xml b/drivers/optical/src/main/resources/optical-drivers.xml
index a83441d..743cbd5 100644
--- a/drivers/optical/src/main/resources/optical-drivers.xml
+++ b/drivers/optical/src/main/resources/optical-drivers.xml
@@ -104,17 +104,6 @@
                    impl="org.onosproject.driver.optical.query.ConfigLambdaQuery"/>
     </driver>
 
-    <driver name="polatis-config" manufacturer="Polatis" hwVersion="config" swVersion=".*">
-        <behaviour api="org.onosproject.net.optical.OpticalDevice"
-                   impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
-        <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
-                   impl="org.onosproject.driver.optical.config.PolatisDeviceDiscovery"/>
-        <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"
-                   impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
-        <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
-                   impl="org.onosproject.driver.optical.query.ConfigLambdaQuery"/>
-    </driver>
-
     <driver name="optical-config" manufacturer="config" hwVersion="config" swVersion="config">
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
diff --git a/drivers/polatis/netconf/BUCK b/drivers/polatis/netconf/BUCK
new file mode 100644
index 0000000..8eee937
--- /dev/null
+++ b/drivers/polatis/netconf/BUCK
@@ -0,0 +1,42 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//models/polatis:onos-models-polatis',
+    '//drivers/utilities:onos-drivers-utilities',
+    '//protocols/netconf/api:onos-protocols-netconf-api',
+    '//lib:onos-yang-model',
+    '//apps/optical-model:onos-apps-optical-model',
+]
+
+APPS = [
+    'org.onosproject.netconf',
+    'org.onosproject.models.common',
+    'org.onosproject.models.polatis',
+    'org.onosproject.optical-model',
+]
+
+TEST_DEPS = [
+    '//lib:TEST_ADAPTERS',
+    '//utils/osgi:onlab-osgi-tests',
+]
+
+BUNDLES = [
+    ':onos-drivers-polatis-netconf',
+    '//drivers/utilities:onos-drivers-utilities',
+]
+
+osgi_jar_with_tests(
+    deps = COMPILE_DEPS,
+    test_deps = TEST_DEPS,
+    resources_root = 'src/main/resources',
+    resources = glob(['src/main/resources/**']),
+)
+
+onos_app(
+    app_name = 'org.onosproject.drivers.polatis.netconf',
+    title = 'Polatis Device Drivers',
+    category = 'Drivers',
+    url = 'http://www.polatis.com',
+    description = 'ONOS Polatis Device Drivers application.',
+    included_bundles = BUNDLES,
+    required_apps = APPS
+)
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
new file mode 100644
index 0000000..76c8bdb
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2017-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.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;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+
+import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
+
+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 static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.Device.Type.FIBER_SWITCH;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
+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.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
+ * optical circuit switches.
+ */
+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());
+
+    /**
+     * Discovers device details, for polatis device by getting the system
+     * information.
+     *
+     * @return device description
+     */
+    @Override
+    public DeviceDescription discoverDeviceDetails() {
+        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(dev.id().uri(), FIBER_SWITCH,
+                    DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA,
+                    DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA,
+                    dev.chassisId());
+        }
+        String reply = netconfGet(handler(), getProductInformationFilter());
+        HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
+        return new DefaultDeviceDescription(dev.id().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();
+    }
+
+    /**
+     * Discovers port details, for polatis device.
+     *
+     * @return port list
+     */
+    @Override
+    public List<PortDescription> discoverPortDetails() {
+        String reply = netconfGet(handler(), getPortsFilter());
+        List<PortDescription> descriptions = parsePorts(reply);
+        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/PolatisDriversLoader.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDriversLoader.java
new file mode 100644
index 0000000..7548eaf
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDriversLoader.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-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.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+/**
+ * Loader for Polatis device drivers.
+ */
+@Component(immediate = true)
+public class PolatisDriversLoader extends AbstractDriverLoader {
+
+    public PolatisDriversLoader() {
+        super("/polatis-drivers.xml");
+    }
+}
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
new file mode 100644
index 0000000..0b0dc65
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisFlowRuleProgrammable.java
@@ -0,0 +1,163 @@
+/*
+ * 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.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.CrossConnects;
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.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.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.slf4j.LoggerFactory.getLogger;
+
+/**
+ * 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_MERGE = "merge";
+    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();
+    }
+
+    @Override
+    public Collection<FlowRule> applyFlowRules(Collection<FlowRule> rules) {
+        return applyConnections(rules);
+    }
+
+    @Override
+    public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
+        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))
+                .collect(Collectors.toList());
+    }
+
+    private boolean editConnection(FlowRule rule, String mode) {
+        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 keyPairMode = String.format("%s operation=\"%s\"", keyPairCompat, mode);
+        pairs.forEach(p -> {
+                cfg.append(xmlOpen(keyPairMode))
+                .append(xmlOpen(KEY_SRC))
+                .append(p.ingress())
+                .append(xmlClose(KEY_SRC))
+                .append(xmlOpen(KEY_DST))
+                .append(p.egress())
+                .append(xmlClose(KEY_DST))
+                .append(xmlClose(keyPairCompat));
+        });
+        cfg.append(xmlClose(KEY_CONNS));
+        return netconfEditConfig(handler(), null, cfg.toString());
+    }
+
+    private Collection<FlowRule> removeConnections(Collection<FlowRule> rules) {
+        return rules.stream()
+                .filter(c -> editConnection(c, CFG_MODE_DELETE))
+                .collect(Collectors.toList());
+    }
+
+    private String parseKeyPairCompat() {
+        String rev = opticalRevision(handler());
+        if (rev == null) {
+            throw new RuntimeException(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 RuntimeException(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/PolatisNetconfUtility.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
new file mode 100644
index 0000000..8a6b89a
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
@@ -0,0 +1,225 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.onosproject.drivers.utilities.XmlConfigParser;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.netconf.DatastoreId;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
+import org.onosproject.netconf.NetconfSession;
+
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Netconf utility for polatis netconf drivers.
+ */
+public final class PolatisNetconfUtility {
+
+    public static final String KEY_XMLNS = "xmlns=\"http://www.polatis.com/yang/optical-switch\"";
+    public static final String KEY_DATA = "data";
+    public static final String KEY_PORT = "port";
+    public static final String KEY_PORTID = "port-id";
+    public static final String KEY_PORTCONFIG = "port-config";
+    public static final String KEY_CONNS = "cross-connects";
+    public static final String KEY_PRODINF = "product-information";
+    public static final String KEY_PORTCONFIG_XMLNS = String.format("%s %s", KEY_PORTCONFIG, KEY_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_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);
+    public static final String KEY_OPM = "opm-power";
+    public static final String KEY_OPM_XMLNS = String.format("%s %s", KEY_OPM, KEY_XMLNS);
+    public static final String KEY_POWER = "power";
+    public static final String KEY_DATA_OPM_PORT = String.format("%s.%s.%s", KEY_DATA, KEY_OPM, KEY_PORT);
+    public static final String OPTICAL_CAPABILITY_PREFIX
+                        = "http://www.polatis.com/yang/optical-switch?module=optical-switch&amp;revision=";
+
+    private static final Logger log = getLogger(PolatisFlowRuleProgrammable.class);
+
+    private PolatisNetconfUtility() {
+    }
+
+    /**
+     * Retrieves session reply information for get operation.
+     *
+     * @param handler parent driver handler
+     * @param filter the filter string of xml content
+     * @return the reply string
+     */
+    public static String netconfGet(DriverHandler handler, String filter) {
+        NetconfSession session = getNetconfSession(handler);
+        String reply;
+        try {
+            reply = session.get(filter, null);
+        } catch (NetconfException e) {
+            throw new RuntimeException(new NetconfException("Failed to retrieve configuration.", e));
+        }
+        return reply;
+    }
+
+    /**
+     * Retrieves session reply information for get config operation.
+     *
+     * @param handler parent driver handler
+     * @param filter the filter string of xml content
+     * @return the reply string
+     */
+    public static String netconfGetConfig(DriverHandler handler, String filter) {
+        NetconfSession session = getNetconfSession(handler);
+        String reply;
+        try {
+            reply = session.getConfig(DatastoreId.RUNNING, filter);
+        } catch (NetconfException e) {
+            throw new RuntimeException(new NetconfException("Failed to retrieve configuration.", e));
+        }
+        return reply;
+    }
+
+    /**
+     * Retrieves session reply information for edit config operation.
+     *
+     * @param handler parent driver handler
+     * @param mode selected mode to change the configuration
+     * @param cfg the new configuration to be set
+     * @return the reply string
+     */
+    public static boolean netconfEditConfig(DriverHandler handler, String mode, String cfg) {
+        NetconfSession session = getNetconfSession(handler);
+        boolean reply = false;
+        try {
+            reply = session.editConfig(DatastoreId.RUNNING, mode, cfg);
+        } catch (NetconfException e) {
+            throw new RuntimeException(new NetconfException("Failed to edit configuration.", e));
+        }
+        return reply;
+    }
+
+    /**
+     * Retrieves specified node hierarchical configuration from the xml information.
+     *
+     * @param content the xml information
+     * @param key the configuration key node
+     * @return the hierarchical configuration, null if exception happens
+     */
+    public static HierarchicalConfiguration configAt(String content, String key) {
+        HierarchicalConfiguration info;
+        try {
+            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
+            info = cfg.configurationAt(key);
+        } catch (IllegalArgumentException e) {
+            // Accept null for information polling
+            return null;
+        }
+        return info;
+    }
+
+    /**
+     * Retrieves specified node hierarchical configurations from the xml information.
+     *
+     * @param content the xml information
+     * @param key the configuration key node
+     * @return the hierarchical configurations, empty if exception happens
+     */
+    public static List<HierarchicalConfiguration> configsAt(String content, String key) {
+        List<HierarchicalConfiguration> info;
+        try {
+            HierarchicalConfiguration cfg = XmlConfigParser.loadXmlString(content);
+            info = cfg.configurationsAt(key);
+        } catch (IllegalArgumentException e) {
+            // Accept empty for information polling
+            return ImmutableList.of();
+        }
+        return info;
+    }
+
+    /**
+     * Makes a xml format sentence.
+     *
+     * @param node the node name
+     * @param content the node content
+     * @return the xml format sentence
+     */
+    public static String xml(String node, String content) {
+        return String.format("<%s>%s</%s>", node, content, node);
+    }
+
+    /**
+     * Makes a xml format open tag.
+     *
+     * @param node the node name
+     * @return the xml head format string
+     */
+    public static String xmlOpen(String node) {
+        return String.format("<%s>", node);
+    }
+
+    /**
+     * Makes a xml format close tag.
+     *
+     * @param node the node name
+     * @return the xml end format string
+     */
+    public static String xmlClose(String node) {
+        return String.format("</%s>", node);
+    }
+
+    /**
+     * Makes a xml format empty tag.
+     *
+     * @param node the node name
+     * @return the xml format of empty tag
+     */
+    public static String xmlEmpty(String node) {
+        return String.format("<%s/>", node);
+    }
+
+    public static String opticalRevision(DriverHandler handler) {
+        NetconfSession session = getNetconfSession(handler);
+        Set<String> capabilities = session.getDeviceCapabilitiesSet();
+        for (String c : capabilities) {
+            if (c.startsWith(OPTICAL_CAPABILITY_PREFIX)) {
+                return c.substring(OPTICAL_CAPABILITY_PREFIX.length());
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the NETCONF session of the device.
+     *
+     * @return session
+     */
+    private static NetconfSession getNetconfSession(DriverHandler handler) {
+        NetconfController controller = checkNotNull(handler.get(NetconfController.class));
+        NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
+        if (session == null) {
+            throw new RuntimeException(new NetconfException("Failed to retrieve the netconf device."));
+        }
+        return session;
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisOpticalUtility.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisOpticalUtility.java
new file mode 100644
index 0000000..bac9f63
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisOpticalUtility.java
@@ -0,0 +1,154 @@
+/*
+ * 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 com.google.common.collect.Range;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.driver.HandlerBehaviour;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowEntry;
+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.criteria.Criterion;
+import org.onosproject.net.flow.criteria.PortCriterion;
+import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions;
+
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.CrossConnects;
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.crossconnects.Pair;
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.crossconnects.DefaultPair;
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.DefaultCrossConnects;
+import org.onosproject.yang.gen.v1.opticalswitch.rev20170804.opticalswitch.PortFormat;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Polatis optical utilities.
+ */
+public final class PolatisOpticalUtility {
+
+    private static final int DEFAULT_PRIORITY = 88;
+    private static final String DEFAULT_APP = "org.onosproject.drivers.polatis.netconf";
+    public static final int POWER_MULTIPLIER = 100;
+    public static final Range<Long> POWER_RANGE = Range.closed(-6000L, 2800L);
+
+    private PolatisOpticalUtility() {
+    }
+
+    /**
+     * Transforms a flow FlowRule object to a cross-connect object.
+     * @param behaviour the parent driver handler
+     * @param rule FlowRule object
+     * @return cross connect object
+     */
+    public static CrossConnects fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
+        // TrafficSelector
+        Set<Criterion> criterions = rule.selector().criteria();
+        PortNumber inPort = criterions.stream()
+                .filter(c -> c instanceof PortCriterion)
+                .map(c -> ((PortCriterion) c).port())
+                .findAny()
+                .orElse(null);
+        // TrafficTreatment
+        List<Instruction> instructions = rule.treatment().immediate();
+        PortNumber outPort = instructions.stream()
+                .filter(c -> c instanceof Instructions.OutputInstruction)
+                .map(c -> ((Instructions.OutputInstruction) c).port())
+                .findAny()
+                .orElse(null);
+        DefaultCrossConnects crossConnects = new DefaultCrossConnects();
+        DefaultPair p = new DefaultPair();
+        p.ingress(new PortFormat(inPort.toLong()));
+        p.egress(new PortFormat(outPort.toLong()));
+        crossConnects.addToPair(p);
+        return crossConnects;
+    }
+
+    /**
+     * Finds the FlowRule from flow rule store by the given cross connect information.
+     * Returns an extra flow to remove the flow by ONOS if not found.
+     * @param behaviour the parent driver handler
+     * @param cfg cross connect information
+     * @return the flow rule
+     */
+    public static FlowRule toFlowRule(HandlerBehaviour behaviour, CrossConnects cfg) {
+        // Note: do we need to handle more than one pair? In any case, this
+        // looks strange.
+        Pair p = cfg.pair().get(0);
+        long i = p.ingress().uint32();
+        long o = p.egress().uint32();
+        PortNumber iPortNumber = PortNumber.portNumber(i);
+        PortNumber oPortNumber = PortNumber.portNumber(o);
+        return toFlowRule(behaviour, iPortNumber, oPortNumber);
+    }
+
+    /**
+     * Finds the FlowRule from flow rule store by the given ports and channel.
+     * Returns an extra flow to remove the flow by ONOS if not found.
+     * @param behaviour the parent driver handler
+     * @param inPort the input port
+     * @param outPort the output port
+     * @return the flow rule
+     */
+    public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort,
+                                      PortNumber outPort) {
+        FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
+        Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
+        // Try to Find the flow from flow rule store.
+        for (FlowEntry entry : entries) {
+            Set<Criterion> criterions = entry.selector().criteria();
+            // input port
+            PortNumber ip = criterions.stream()
+                    .filter(c -> c instanceof PortCriterion)
+                    .map(c -> ((PortCriterion) c).port())
+                    .findAny()
+                    .orElse(null);
+            // output port
+            PortNumber op = entry.treatment().immediate().stream()
+                    .filter(c -> c instanceof Instructions.OutputInstruction)
+                    .map(c -> ((Instructions.OutputInstruction) c).port())
+                    .findAny()
+                    .orElse(null);
+            if (inPort.equals(ip) && outPort.equals(op)) {
+                // Find the flow.
+                return entry;
+            }
+        }
+        // Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
+        TrafficSelector selector = DefaultTrafficSelector.builder()
+                .matchInPort(inPort)
+                .build();
+        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+                .setOutput(outPort)
+                .build();
+        return DefaultFlowRule.builder()
+                .forDevice(behaviour.data().deviceId())
+                .withSelector(selector)
+                .withTreatment(treatment)
+                .makePermanent()
+                .withPriority(DEFAULT_PRIORITY)
+                .fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP))
+                .build();
+
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPowerConfig.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPowerConfig.java
new file mode 100644
index 0000000..d382b90
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisPowerConfig.java
@@ -0,0 +1,138 @@
+/*
+ * 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 com.google.common.collect.Range;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+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.driver.AbstractHandlerBehaviour;
+import org.slf4j.Logger;
+
+import java.util.Optional;
+
+import static org.onosproject.drivers.polatis.netconf.PolatisOpticalUtility.POWER_MULTIPLIER;
+import static org.onosproject.drivers.polatis.netconf.PolatisOpticalUtility.POWER_RANGE;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.*;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Get current or target port/channel power from a Polatis optical netconf device.
+ * Set target port power or channel attenuation to an optical netconf device.
+ */
+public class PolatisPowerConfig<T> extends AbstractHandlerBehaviour
+    implements PowerConfig<T> {
+
+    private static final Logger log = getLogger(PolatisPowerConfig.class);
+
+    @Override
+    public Optional<Long> getTargetPower(PortNumber port, T component) {
+        return Optional.ofNullable(acquireTargetPower(port, component));
+    }
+
+    @Override
+    public void setTargetPower(PortNumber port, T component, long power) {
+        if (component instanceof OchSignal) {
+            log.warn("Channel power is not applicable.");
+            return;
+        }
+        setPortTargetPower(port, power);
+    }
+
+    @Override
+    public Optional<Long> currentPower(PortNumber port, T component) {
+        return Optional.ofNullable(acquireCurrentPower(port, component));
+    }
+
+    @Override
+    public Optional<Range<Long>> getTargetPowerRange(PortNumber port, T component) {
+        return Optional.ofNullable(getTxPowerRange(port, component));
+    }
+
+    @Override
+    public Optional<Range<Long>> getInputPowerRange(PortNumber port, T component) {
+        return Optional.ofNullable(getRxPowerRange(port, component));
+    }
+
+    private String getPortPowerFilter(PortNumber port) {
+        return new StringBuilder(xmlOpen(KEY_OPM_XMLNS))
+                .append(xmlOpen(KEY_PORT))
+                .append(xmlOpen(KEY_PORTID))
+                .append(port.toLong())
+                .append(xmlClose(KEY_PORTID))
+                .append(xmlClose(KEY_PORT))
+                .append(xmlClose(KEY_OPM))
+                .toString();
+    }
+
+    private Long acquireTargetPower(PortNumber port, T component) {
+        if (component instanceof OchSignal) {
+            log.warn("Channel power is not applicable.");
+            return null;
+        }
+        log.debug("Get port{} target power...", port);
+        log.warn("This is currently unimplemented");
+        return null;
+    }
+
+    private Long acquireCurrentPower(PortNumber port, T component) {
+        if (component instanceof OchSignal) {
+            log.warn("Channel power is not applicable.");
+            return null;
+        }
+        log.debug("Get port{} current power...", port);
+        return acquirePortPower(port);
+    }
+
+    private Long acquirePortPower(PortNumber port) {
+        String filter = getPortPowerFilter(port);
+        String reply = netconfGet(handler(), filter);
+        HierarchicalConfiguration info = configAt(reply, KEY_DATA_OPM_PORT);
+        if (info == null) {
+            return null;
+        }
+        return (long) (info.getDouble(KEY_POWER) * POWER_MULTIPLIER);
+    }
+
+    private boolean setPortTargetPower(PortNumber port, long power) {
+        log.debug("Set port{} target power...", port);
+        log.warn("This is currently unimplemented");
+        return false;
+    }
+
+    private Range<Long> getPowerRange() {
+        return POWER_RANGE;
+    }
+
+    private Range<Long> getTxPowerRange(PortNumber port, T component) {
+        if (component instanceof Direction) {
+            log.debug("Get target port{} power range...", port);
+            return getPowerRange();
+        } else {
+            log.debug("Get channel attenuation range...");
+            log.warn("Channel power is not applicable.");
+            return null;
+        }
+    }
+
+    private Range<Long> getRxPowerRange(PortNumber port, T component) {
+        log.debug("Get input port{} power range...", port);
+        return getPowerRange();
+    }
+}
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/package-info.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/package-info.java
new file mode 100644
index 0000000..53dad3c
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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 for Polatis device drivers.
+ */
+package org.onosproject.drivers.polatis;
diff --git a/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
new file mode 100644
index 0000000..12bb4ca
--- /dev/null
+++ b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-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.
+  -->
+<drivers>
+    <driver name="polatis-netconf" extends="" manufacturer="Polatis"
+            hwVersion="" swVersion="">
+        <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
+                   impl="org.onosproject.drivers.polatis.netconf.PolatisDeviceDescription"/>
+        <behaviour api="org.onosproject.net.behaviour.PowerConfig"
+                   impl="org.onosproject.drivers.polatis.netconf.PolatisPowerConfig"/>
+        <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"
+                   impl="org.onosproject.drivers.polatis.netconf.PolatisFlowRuleProgrammable"/>
+    </driver>
+</drivers>
diff --git a/models/polatis/BUCK b/models/polatis/BUCK
new file mode 100644
index 0000000..44c439f
--- /dev/null
+++ b/models/polatis/BUCK
@@ -0,0 +1,9 @@
+COMPILE_DEPS = [
+    '//models/common:onos-models-common',
+]
+
+yang_model (
+  app_name = 'org.onosproject.models.polatis',
+  title = 'Polatis YANG Model',
+  deps = COMPILE_DEPS,
+)
diff --git a/models/polatis/src/main/yang/optical-switch.yang b/models/polatis/src/main/yang/optical-switch.yang
new file mode 100644
index 0000000..035c926
--- /dev/null
+++ b/models/polatis/src/main/yang/optical-switch.yang
@@ -0,0 +1,1046 @@
+module optical-switch {
+    namespace "http://www.polatis.com/yang/optical-switch";
+    prefix opsw;
+
+    import ietf-yang-types {
+        prefix yang;
+    }
+
+    import ietf-inet-types {
+        prefix inet;
+    }
+
+    organization "Polatis Limited";
+    contact
+        "Adam Hughes
+
+        Polatis Limited
+        332/2 Cambridge Science Park
+        Cambridge CB4 0WN
+        United Kingdom
+
+        Phone: +44 (0) 1223 424200
+        Email: yang-support@polatis.com";
+
+    description "Implements the data model for an Optical Circuit Switch";
+
+    revision "2017-08-04" {
+        description " 1. Removed the state and config data dependencies.
+                      2. Added new port configuration containers for better performance.
+                      3. Deprecated old ports/port container ";
+    }
+
+    revision "2017-06-13" {
+        description "Moved the common typedef into separate yang module";
+    }
+
+    revision "2017-02-09" {
+        description "Added APS container and notifications";
+    }
+
+    revision "2016-04-22" {
+        description "Added support for peer port configuration";
+    }
+
+    revision "2016-02-17" {
+        description "1. Added support for Variable Optical Attenuation
+                             2. Defined new portFormat datatype to represent non-zero port Id.
+                             3. Changed the default values of power-high-alarm from +100 to +25 and
+                                and for power-low-alarm from -100 to -60.";
+    }
+
+    revision "2015-09-14" {
+        description "Initial revision.";
+    }
+
+    typedef namesFormat {
+        type string {
+            pattern "[ -~]{1,128}"; // Trying to be 0x20 to 0x7e (7f is DEL).
+        }
+        description "Characters between 1-128, of printable ascii values, 0x20 07e";
+    }
+
+    typedef namesFormatNullable {
+        type string {
+            pattern "[ -~]{0,128}"; // Trying to be 0x20 to 0x7e (7f is DEL).
+        }
+        description "Characters between 0-128, of printable ascii values, 0x20 07e, so can be nullable";
+    }
+
+    typedef floatFormat2d {
+        type decimal64 {
+            fraction-digits 2;
+        }
+        description "Floating point number, displayed with 2 decimal places.";
+    }
+
+    typedef portFormat {
+        type uint32 {
+            range "1 .. 65535";
+        }
+    }
+
+    typedef PortStatus {
+        type enumeration {
+            enum PO_ENABLED  { value 1; }
+            enum PO_DISABLED { value 2; }
+            enum PO_FAILED   { value 3; }
+        }
+        description "ENABLED means that light can pass through the port, shutters are open.
+        DISABLED indicates the opposite. FAILED is reported when the port cannot be used.";
+    }
+
+    typedef apsOperationalState {
+        type enumeration {
+            enum ON_WORKING     { value 0; }
+            enum WORKING_FAIL   { value 1; }
+            enum SWITCH_PROT    { value 2; }
+            enum ON_PROTECT     { value 3; }
+            enum PROTECT_FAIL   { value 4; }
+            enum SWITCH_WORK    { value 5; }
+            enum NOT_APPLICABLE { value 6; }
+        }
+        description "Describes the currently operational state of a port in an aps-protection group,
+        be it on the worker, be it on the protected, or be it that both have failed in effect, which is
+        protect failed. Most of the states are for Worker ports, protect ports are marked NOT_APPLICABLE.";
+    }
+
+    typedef apsPortType {
+        type enumeration {
+            enum WORKER     { value 1; }
+            enum PROTECT    { value 2; }
+        }
+        description "The type of the aps port. They are either a worker, or a port which is protecting one or many
+        working ports.";
+    }
+
+    typedef apsFlags {
+        type bits {
+            bit GLP {position 0;}
+            bit FTP {position 1;}
+            bit FTW {position 2;}
+            bit MTP {position 3;}
+            bit MTW {position 4;}
+            bit DNR {position 5;}
+        }
+        description "Commands which can be sent to an aps-port, they are:
+            GLP - Global Lock Protect
+            FTP - Force switch to Protector
+            FTW - Force switch to Worker
+            MTP - Manual switch To Protector
+            MTW - Manual switch To Worker
+            DNR - Do Not Revert
+            Lack of any of these bits are clear of that status, so a total clear is 000000";
+    }
+
+    typedef hostFormat {
+        type string {
+            pattern "[ -~]{1,64}"; // 0x20 to 07e
+        }
+        description "Characters between 1-64 length, of printable ascii values, 0x20 07e";
+    }
+
+    typedef secretFormat {
+        type string {
+            pattern "[a-zA-Z0-9]{1,128}"; // Alphanumeric
+        }
+        description "Characters between 1-128 length, alphanumeric";
+    }
+
+    container product-information {
+        config false;
+        leaf manufacturer {
+            type string;
+            description "Name of the manufacturer";
+        }
+        leaf serial-number {
+            type string;
+            description "Unique number given to the product during manufacturing.";
+        }
+        leaf model-name {
+            type string;
+            description "Describes the product and the features that the product supports.";
+        }
+        leaf software-version {
+            type string;
+            description "Version of the software that is currently running on the optical switch";
+        }
+    }
+
+    container port-config {
+        list port {
+            key port-id;
+            leaf port-id {
+                type portFormat;
+                description "Unique Id for port";
+            }
+            leaf status {
+                config false;
+                type enumeration {
+                    enum UNSUPPORTED   { value 0; }
+                    enum ENABLED       { value 1; }
+                    enum DISABLED      { value 2; }
+                    enum FAILED        { value 3; }
+                }
+                description "Status of port. When status is ENABLED optical path is clear and signal
+                passes through. When the status is DISABLED optical signal is blocked. When status
+                is UPSUPPORTED port doesn't have the enable/disable feature on that port. And, when
+                the port has failed to report its status correctly status is FAILED. ";
+            }
+            leaf label {
+                type namesFormatNullable;
+                default "";
+
+                description "When set, notifications sent by the server will include the label.";
+            }
+            leaf peer-port {
+                type namesFormatNullable;
+                default "";
+
+                description "This leaf describes the remote port on another switch to which this
+                port is connected physically through the optical fibres. Management interface can
+                set this parameter to configure the network topology.";
+            }
+        }
+    }
+    rpc port-set-state {
+        input {
+            leaf-list port-enab {
+                type portFormat;
+                description "List of port-ids that will be enabled after the RPC finishes successfully.";
+            }
+            leaf-list port-disab {
+                type portFormat;
+                description "List of port-ids that will be enabled after the RPC finishes successfully.";
+            }
+        }
+        description "This RPC is used to enable or disable an port. When the port is disabled
+        optical signal is blocked. When the port is enabled optical path is clear and signal passes through.";
+    }
+
+    container opm-power {
+        config false;
+        list port {
+            key port-id;
+            leaf port-id {
+                type opsw:portFormat;
+                description "Id of the Switch port with OPM sensors.";
+            }
+            leaf power {
+                type opsw:floatFormat2d;
+                description "Optical signal strength that is read at the OPM sensor. Specified in dbm.";
+            }
+            description "List of OPM sensors that return the optical signal strength in the fibre.";
+        }
+    }
+    container opm-config {
+        list port {
+            key port-id;
+            leaf port-id {
+                type opsw:portFormat;
+                description "Switch port with OPM";
+            }
+            leaf wavelength {
+                type opsw:floatFormat2d {
+                    range 1260.0..1640.0;
+                }
+                default 1550.0;
+
+                description "Wavelength against which the power measurements are calibrated.
+                specified in nm.";
+            }
+            leaf offset {
+                type opsw:floatFormat2d {
+                    range -100.0..100.0;
+                }
+                default 0;
+
+                description "Offset for the power measurement; the value is added to power
+                monitor measurements when reporting /opsw:ports/opsw:port[]/opsw:opm/opsw:power.
+                Thus, specifying an offset can be used as a means of referencing the power
+                monitors against external meters.
+                It should be noted that the offset feature does NOT impact the behaviour
+                of the alarm or attenuation features:
+                alarm and attenuation settings always operate relative to the actual
+                power monitor readings, i.e. without any user-specified offsets.
+                Specified in dBm.";
+            }
+            leaf averaging-time {
+                type uint32 {
+                    range "1..8";
+                }
+                default 4;
+
+                description "Selects the period for which the power average is calculated. Each increment
+                in this value doubles the length of the time for which the OPM power readings are averaged.
+                Setting the value to 1 results in the shortest averaging period, around 10ms.
+                Setting the value to 8 results in the longest averaging period, 128 times greater.";
+            }
+        }
+    }
+    container opm-alarm-config {
+        list port {
+            key port-id;
+            leaf port-id {
+                type opsw:portFormat;
+                description "Switch port with OPM";
+            }
+            leaf mode {
+                type enumeration {
+                    enum POWER_ALARM_DISABLED;
+                    enum POWER_ALARM_ENABLED;
+                }
+                default POWER_ALARM_DISABLED;
+
+                description "Power alarms or notifications from ports can be individually enabled or disabled.
+                When enabled, Loss of Signal (LOS) or Signal Degrade notifications are generated when power
+                levels cross the set thresholds";
+            }
+            leaf signal-loss-threshold {
+                type opsw:floatFormat2d;
+                default -60.0;
+
+                description "The switch will generate loss of service notifications should the power
+                level go below this threshold. Specified in dBm.";
+            }
+            leaf signal-degrade-threshold {
+                type opsw:floatFormat2d;
+                default -60.0;
+
+                description "The switch can generate warning (signal degrade) notifications should the
+                power level go below the configured warning threshold. Specified in dBm.";
+            }
+            leaf signal-high-threshold {
+                type opsw:floatFormat2d;
+                default 25.0;
+
+                description "The switch will generate notifications should the power level go beyond this
+                level. Specified in dBm.";
+            }
+            leaf alarm-clear-holdoff {
+                type uint32;
+                default 10;
+
+                description "Minimum time (in seconds) for which the optical power level needs
+                to be restored within the power alarm thresholds for the switch to generate
+                an alarm clear notification.";
+            }
+        }
+    }
+
+    container voa {
+        list port {
+            key port-id;
+            leaf port-id {
+                type opsw:portFormat;
+                description "Switch port with VOA";
+            }
+            leaf atten-mode {
+                type enumeration {
+                    enum VOA_MODE_NONE        { value 0; }
+                    enum VOA_MODE_RELATIVE    { value 1; }
+                    enum VOA_MODE_ABSOLUTE    { value 2; }
+                    enum VOA_MODE_CONVERGED   { value 3; }
+                    enum VOA_MODE_MAXIMUM     { value 4; }
+                    enum VOA_MODE_FIXED       { value 5; }
+                }
+                default VOA_MODE_NONE;
+
+                description " VOA_MODE_NONE: Attenuation on the port is disabled. The light on the port will
+                have the actual power level. VOA_MODE_ABSOLUTE:  Port will achieve the configured attentuation
+                level and power of the light on the port will have the absolute level configured.
+                VOA_MODE_RELATIVE:  Port will achieve the attentuation with respect to the power of the light
+                of the reference port. The actual attenuation achieved depends on the configured level and
+                power of the light of the reference port. VOA_MODE_CONVERGED: This is similar in behaviour to
+                ABSOLUTE mode, but once the attenuation converges to the desired level the switch freezes the
+                VOA control loop. This reduces noise caused by the control loop continually striving to improve
+                the attenuation. VOA_MODE_MAXIMUM: Port will achieve the maximum attenuation level. In this
+                case configured attenuation level is not used. VOA_MODE_FIXED: Disables closed loop updating
+                of the attenuation feature for the specified port. Following issuance of this command, the port
+                will continue to hold their current attenuation level without any optical feedback. Thus, any
+                changes in input power levels will no longer be tracked";
+            }
+            leaf atten-level {
+                when "../atten-mode = 'VOA_MODE_ABSOLUTE' or ../atten-mode = 'VOA_MODE_RELATIVE'" +
+                     "or ../atten-mode = 'VOA_MODE_CONVERGED'";
+                type opsw:floatFormat2d;
+                default 0;
+
+                description "The attenuated output level configured for this port. Specified in dBm
+                (or dB for RELATIVE as it is an offset value with respect to reference port).";
+            }
+            leaf reference-port {
+                when "../atten-mode = 'VOA_MODE_RELATIVE'";
+                type uint32;
+                default 0;
+
+                description "Reference port for attenuation (for use with relative attenuation only). If this port
+                is specified as zero then the default reference port will be used. The default port is the ingress
+                to which the egress port being attenuated is connected. For attenuation states other than RELATIVE
+                this data is ignored. When reading this object, a value of zero is returned for all modes other
+                than RELATIVE. For relative attenuation, the value returned is the current reference port in use.";
+            }
+        }
+    }
+
+    container ports {
+        status "deprecated";
+        list port {
+            key port-id;
+            leaf port-id {
+                type portFormat;
+                description "Unique Id for port";
+            }
+            leaf port-label {
+                type namesFormatNullable;
+                description "When set, notifications will include the label.";
+        }
+            leaf port-state {
+                type enumeration {
+                    enum PC_ENABLED { value 1; }
+                    enum PC_DISABLED { value 2; }
+                }
+                default PC_ENABLED;
+
+                description "State of a port shutter. When port is enabled, shutter is open and
+                when port is disabled, shutter is closed.";
+            }
+            leaf port-status {
+                config false;
+                type PortStatus;
+
+                description "Switch port status. The switch can report FAILED port status when the port fails to
+                correctly report its state";
+            }
+            leaf peer-port {
+                type namesFormatNullable;
+
+                description "This leaf describes the remote port on another switch to which this
+                port is connected physically through the optical fibres. Management interface can
+                set this parameter to configure the network topology.";
+            }
+            container opm {
+                description "Optical Power Monitor (OPM) measures the optical signal strength in the fibre.";
+
+                leaf lambda {
+                    type floatFormat2d;
+                    default 1550.0;
+
+                    description "Wavelength against which the power measurements are calibrated.
+                    Specified in nm.";
+                }
+                leaf power-high-alarm {
+                    type floatFormat2d;
+                    default 25.0;
+
+                    description "The switch will generate notifications should the power level go beyond this
+                    level. Specified in dBm.";
+                }
+                leaf power-low-alarm {
+                    type floatFormat2d;
+                    default -60.0;
+
+                    description "The switch will generate notifications should the power level go below this
+                    level. Specified in dBm.";
+                }
+                leaf power-high-warning-offset {
+                    type floatFormat2d;
+                    default 0;
+
+                    description "The switch will generate (warning) notifications should the power go beyond
+                    the set level. This warning offset is subtracted from power-high-alarm to get the warning threshold.
+                    A zero value means that warnings are disabled. Specified in dBm.";
+                }
+                leaf power-low-warning-offset {
+                    type floatFormat2d;
+                    default 0;
+
+                    description "The switch can generate (warning) notifications should the power go below
+                    the set level. This warning offset is added into power-low-alarm to get the warning threshold.
+                    A zero value means that warnings are disabled. Specified in dBm.";
+                }
+                leaf power-alarm-control {
+                    type enumeration {
+                        enum POWER_ALARM_DISABLED;
+                        enum POWER_ALARM_SINGLE;
+                        enum POWER_ALARM_CONTINUOUS;
+                    }
+                    default POWER_ALARM_DISABLED;
+
+                    description "Power alarms or notifications from ports can be individually enabled or disabled.
+                    When power-alarm-control is POWER_ALARM_SINGLE then only one alarm is generated, following
+                    which power-alarm-control reverts to POWER_ALARM_DISABLED.
+                    When power-alarm-control is POWER_ALARM_CONTINUOUS then power alarms are always generated
+                    when power levels exceed the defined power alarm thresholds.";
+                }
+                leaf power-alarm-status {
+                    config false;
+                    type enumeration {
+                        enum POWER_ALARM_STATUS_OFF;
+                        enum POWER_ALARM_STATUS_ARMED;
+                        enum POWER_ALARM_STATUS_TRIGGERED;
+                    }
+
+                    description "POWER_ALARM_STATUS_OFF       - Power alarms are not enabled.
+                                 POWER_ALARM_STATUS_ARMED     - Alarms can be generated.
+                                 POWER_ALARM_STATUS_TRIGGERED - Port has an active alarm. When the alarm
+                                                                clears, power-alarm-status will change to
+                                                                one of POWER_ALARM_STATUS_OFF or
+                                                                POWER_ALARM_STATUS_ARMED depending on the
+                                                                power-alarm-control mode.";
+                }
+                leaf power {
+                    config false;
+                    type floatFormat2d;
+
+                    description "Power readings for this port. Specified in dBm.";
+                }
+                container voa {
+
+                    description "Variable Optical Attenuation (VOA) functionality controls the the optical
+                    power level of light on the port. It allows to set the desired attenuation level
+                    that the port should achieve.";
+
+                    leaf attenuation-level {
+                        type floatFormat2d;
+                        default 0;
+
+                        description "The attenuated output level configured for this port. Specified in dBm
+                        (or dB for RELATIVE as it is an offset value with respect to reference port).";
+                    }
+                    leaf attenuation-mode {
+                        type enumeration {
+                            enum VOA_ATTEN_MODE_NONE        { value 1; }
+                            enum VOA_ATTEN_MODE_ABSOLUTE    { value 2; }
+                            enum VOA_ATTEN_MODE_RELATIVE    { value 3; }
+                            enum VOA_ATTEN_MODE_VENDOR      { value 128; }
+                        }
+                        default VOA_ATTEN_MODE_NONE;
+
+                        description " VOA_ATTEN_MODE_NONE: Attenuation on the port is disabled. The light on the
+                        port will have the actual power level. VOA_ATTEN_MODE_ABSOLUTE: Port will achieve the configured
+                        attentuation level and power of the light on the port will have the absolute level configured.
+                        VOA_ATTEN_MODE_RELATIVE: Port will achieve the attentuation with respect to the power of the light
+                        of the reference port. The actual attenuation achieved depends on the configured level and power
+                        of the light of the reference port. VOA_ATTEN_MODE_VENDOR: This is vendor specific mode.";
+                    }
+                    leaf attenuation-reference-port {
+                        type uint32;
+                        default 0;
+
+                        description "Reference port for attenuation (for use with relative attenuation only). If this port
+                        is specified as zero then the default reference port will be used. The default port is the ingress
+                        to which the egress port being attenuated is connected. For attenuation states other than RELATIVE
+                        this data is ignored. When reading this object, a value of zero is returned for all modes other
+                        than RELATIVE. For relative attenuation, the value returned is the current reference port in use.";
+                    }
+                }
+            }
+        }
+    }
+
+    container cross-connects {
+        list pair {
+            key ingress;
+            leaf ingress {
+                type portFormat;
+                description "Input port that makes the connection pair.";
+            }
+            leaf egress {
+                type portFormat;
+                description "Output port that makes the connection pair.";
+            }
+        }
+        description "List of all cross connections in the system.";
+    }
+
+    grouping network-interface-group {
+        leaf ip-address {
+            type inet:ip-address;
+            description "IP address of the switch control plane.";
+        }
+        leaf gateway {
+            type inet:ip-address;
+            description "Gateway address for the switch control plane.";
+        }
+        leaf subnet {
+            type inet:ip-address;
+            description "Subnet to which the switch control plane belongs.";
+        }
+        leaf broadcast {
+            type inet:ip-address;
+            description "Broadcast IP address for the switch control plane.";
+        }
+    }
+
+    container system-config {
+        list interface-status {
+            config false;
+            key name;
+
+            leaf name {
+                type string;
+                description "Unique name of the network interface";
+            }
+            uses network-interface-group;
+            leaf hw-addr {
+                type yang:mac-address;
+            }
+            description "List of Switch network interface and their current running configuration.";
+        }
+        list interface {
+            key name;
+            unique ip-address;
+
+            leaf name {
+                type string;
+                description "Unique name of the network interface";
+            }
+            uses network-interface-group;
+
+            description "List of Switch network interfaces and their user configuration.
+            On system restart, switch will start to use this configuration as their running
+            configuration.";
+        }
+        list user {
+            key name;
+            leaf name {
+                type namesFormat;
+                description "The user name string identifying this entry.";
+            }
+            leaf type {
+                type enumeration {
+                    enum RADIUS_USER { value 1; }
+                    enum LOCAL_USER  { value 2; }
+                }
+                mandatory true;
+                description "Type of user. When set to RADIUS_USER, the user will be authenticated against the radius-servers.
+                When set to LOCAL_USER, user will be authenticated locally.";
+            }
+            leaf password {
+                when "../type != 'RADIUS_USER'";
+
+                type namesFormatNullable;
+                description "The password for this entry. May not be set to empty, but will report empty.
+                If set to 'RADIUS' it will report 'RADIUS', and the user will authenticate against radius-servers.";
+            }
+            list authorized-key {
+                when "../type != 'RADIUS_USER'";
+
+                key name;
+                description "A list of public SSH keys for this user. These keys are allowed for SSH
+                authentication, as described in RFC 4253.";
+                reference "RFC 4253: The Secure Shell (SSH) Transport Layer Protocol";
+                leaf name {
+                    type string;
+                    description "An arbitrary name for the SSH key.";
+                }
+                leaf algorithm {
+                    type string;
+                    mandatory true;
+                    description "The public key algorithm name for this SSH key. Valid values are the
+                    values in the IANA 'Secure Shell (SSH) Protocol Parameters' registry, Public Key
+                    Algorithm Names.";
+                    reference "IANA 'Secure Shell (SSH) Protocol Parameters' registry, Public Key
+                    Algorithm Names";
+                }
+                leaf key-data {
+                    type binary;
+                    mandatory true;
+                    description "The binary public key data for this SSH key, as specified by RFC 4253,
+                    Section 6.6, i.e.: string certificate or public key format identifier byte[n]
+                    key/certificate data.";
+                    reference "RFC 4253: The Secure Shell (SSH) Transport Layer Protocol";
+                }
+            }
+            description "The list of local users configured on this device. This model is adopted from
+            System Management yang model. (https://tools.ietf.org/html/rfc7317)";
+        }
+        container activity-log
+        {
+            leaf log-filter {
+                type bits {
+                    bit SYSTEM {position 0;}
+                    bit USER   {position 1;}
+                    bit OXC    {position 2;}
+                    bit OPM    {position 3;}
+                }
+            }
+            leaf log-access {
+                type enumeration {
+                    enum NONE { value 0; }
+                    enum SELF { value 1; }
+                    enum ALL  { value 2; }
+                }
+                default NONE;
+            }
+            leaf logging-enabled {
+                type boolean;
+                default false;
+            }
+        }
+        container radius-servers
+        {
+            list radius-server {
+                key "ip-address port";
+
+                leaf ip-address {
+                    type inet:ip-address;
+                    description "Ip address of the radius server.";
+                }
+                leaf port {
+                    type uint32;
+                    description "Port of the radius server.";
+                }
+                leaf secret {
+                    type secretFormat;
+                    mandatory true;
+                    description "The secret used to authenticate with the radius server.";
+                }
+                leaf timeout {
+                    type uint32 {
+                        range "1..30";
+                    }
+                    default 3;
+                    description "Length of time in seconds before timing out on connection to server.";
+                }
+            }
+            description "The list of radius servers for the nic, the order of the list determines the priority of usage.";
+        }
+        container ntp-servers
+        {
+            list ntp-server {
+                key ip-address;
+
+                leaf ip-address {
+                    type inet:ip-address;
+                    description "The ip address of a ntp server to use";
+                }
+                leaf minpoll {
+                    type uint32 {
+                        range "4..6";
+                    }
+                    default 6;
+                    description "The minimum polling in seconds";
+                }
+                leaf maxpoll {
+                    type uint32 {
+                        range "10..17";
+                    }
+                    default 10;
+                    description "The maximum polling in seconds";
+                }
+                leaf version {
+                    type uint32 {
+                        range "1..4";
+                    }
+                    default 4;
+                    description "The version that the ntp server runs.";
+                }
+            }
+            description "The list of ntp servers in order of usage to get the ntp time";
+        }
+        container remote-syslog
+        {
+            leaf rname {
+                type inet:ipv4-address;
+                description "IPv4 address of remote collector.  Use 0.0.0.0 to disable sending.  This field will change to inet:host type.";
+            }
+            leaf rport {
+                type inet:port-number;
+                description "UDP port receiving syslog on 'rname'. Set to zero to use the default (514).";
+            }
+            leaf facility {
+                type enumeration {
+                    enum USER { value 8; }
+                    enum LOCAL0 { value 128; }
+                    enum LOCAL1  { value 136; }
+                    enum LOCAL2  { value 144; }
+                    enum LOCAL3  { value 152; }
+                    enum LOCAL4  { value 160; }
+                    enum LOCAL5  { value 168; }
+                    enum LOCAL6  { value 176; }
+                    enum LOCAL7  { value 184; }
+                }
+                default USER;
+                description "The facility to send messages under.  See RFC 3164.  All values are 8 times the value listed in the RFC, to pack the severity value in the low bits.";
+            }
+            must "(boolean(rname) = true() and string(rname) != '0.0.0.0') or (boolean(rport) = false() or rport = 0)" { error-message "Cannot have port without name"; }
+            description "The destination for syslog messages. ";
+        }
+        container protocols
+        {
+            list protocol {
+                key protocol-id;
+
+                leaf protocol-id {
+                    type uint32;
+                }
+                leaf protocol-name {
+                    config false;
+                    type string;
+                }
+                leaf protocol-type {
+                    config false;
+                    type string;
+                }
+                leaf protocol-port {
+                    config false;
+                    type uint32;
+                }
+                leaf enabled {
+                    type boolean;
+                    default true;
+                }
+            }
+        }
+
+        leaf current-datetime {
+            config false;
+            type yang:date-and-time;
+
+            description "The current system date and time.";
+        }
+        leaf boot-datetime {
+            config false;
+            type yang:date-and-time;
+
+            description "The system date and time when the system last restarted.";
+        }
+
+        leaf alarm-clear-hysteresis {
+            type decimal64 {
+                fraction-digits 2;
+                range "1..5";
+            }
+
+            default 1;
+
+            description "Added to 'power-low-alarm' and subtracted from 'power-high-alarm'
+            to generate alarm clear notifications. Specified in dBm.";
+        }
+
+    }
+
+    // APS config and status
+    container aps
+    {
+        description "Automatic Protection Switching (APS) feature provides optical redundancy on the Polatis switch.
+        When the switch detects signal failure on the primary optical path, it automatically switches to an alternative
+        optical path. The switch also provides manual operation through which the optical paths can be changed.
+        APS feature consists of list of protection service, where each service is list of working and protection ports. ";
+        list protection-service
+        {
+            description "This the list of APS protection services on the system";
+            key sname;
+            leaf sname {
+                type namesFormat;
+                description "Protection Service name. Should be unique on the switch.";
+            }
+            leaf active
+            {
+                config false;
+                type boolean;
+                description "Whether the Protection Service is Active, or in Config mode.";
+            }
+            list working-port
+            {
+                key port-id;
+
+                description "This the list of APS port configurations on the system. This defines the APS service, and
+                generates port-status and protection-services to represent them";
+
+                leaf port-id
+                {
+                    type portFormat;
+                }
+                leaf client
+                {
+                    type uint32;
+                    mandatory true;
+                    description "Client port to which the working will connect when the service is activated.";
+                }
+                leaf priority
+                {
+                    type uint32;
+                    default 0;
+                    description "A number to be used when deciding the priority of protection switched when there is contention.";
+                }
+                leaf wtr-timeout
+                {
+                    type uint32;
+                    default 0;
+                    description "Wait To Restore timeout value. The amount, in seconds, before a restore is possible on this port.";
+                }
+                leaf ovs
+                {
+                    type boolean;
+                    default false;
+                    description "Override Valid Signal. Allows us to override the need for a valid signal in manual/automatic switch.";
+                }
+                leaf protected-port
+                {
+                    config false;
+
+                    type uint32;
+                    description "If a worker port, and is currently being protected, it is the port id of the protecting port.
+                    If not being protected, it is 0. Vice versa if it is a protecting port.";
+                }
+                leaf operational-state
+                {
+                    config false;
+
+                    type apsOperationalState;
+                    description "The current operational state of the port, being working, protected, protection failed. This does not apply for PROTECTED ports.";
+                }
+                leaf user_command
+                {
+                    config false;
+                    type apsFlags;
+                }
+            }
+            leaf-list protection-port
+            {
+                type uint32;
+                description "";
+            }
+        }
+    }
+
+    rpc set-current-datetime {
+        description "Set the /product-information/clock/current-datetime leaf to the specified value.
+        Also changes /product-information/clock/boot-datetime, relative to current-datetime";
+        input {
+            leaf current-datetime {
+                type yang:date-and-time;
+                mandatory true;
+                description "The current system date and time.";
+            }
+        }
+    }
+
+    rpc system-restart {
+        description "Request to restart the Network Interface Card (NIC).";
+        input {
+            leaf seconds {
+                type uint32;
+                default 0;
+
+                description "Restart the system in the specified time. Given in seconds.
+                Value of 0 will restart the system immediately, and in that case there
+                won't be any response";
+            }
+        }
+    }
+
+    rpc system-restart-cancel {
+        description "Request to cancel the restart. This has no effect when
+        system-restart was not requested. Cancel is done immediately";
+    }
+
+    // APS rpcs and notification
+    rpc aps-command {
+        description "This is a command to apply flags to a number of ports at the same time.
+        You can provide either the sname of the service, to do all ports for that service, or
+        specify ports, which do not have to be on the same protection service.
+        The command is applied via combination of a bitwise mask and bitwise command values, to set/unset
+        different attributes at the same time. Some combinations are mutually exclusive:
+        GLP/FTP/FTW/MTP/MTW are exclusive to each other.
+
+        Some commands are per port, and some per service (GLP). This is why the choice of a service name, or ports are provided.";
+
+        input {
+            leaf mask {
+                type apsFlags;
+                mandatory true;
+            }
+            leaf flags {
+                type apsFlags;
+                mandatory true;
+            }
+            choice parameter
+            {
+                mandatory true;
+                leaf sname
+                {
+                    type namesFormat;
+                }
+                list port
+                {
+                    key port-id;
+                    leaf port-id         { type portFormat; }
+                    leaf target-port-id
+                    {
+                        type uint32;
+                        default 0;
+                        description "This is an optional parameter, used when a target is also needed, ie: FTP/MTP on
+                        M:N protection, where you wish to switch to a specific protection port. It is ignored on other cases.";
+                    }
+                    description "The port-id is in effect mandatory to specify a source port.";
+                }
+            }
+        }
+    }
+
+    rpc aps-activate {
+        description "Used to activate or deactive a protection service.";
+        input {
+            leaf sname {
+                type namesFormat;
+            }
+            leaf active {
+                type boolean;
+                mandatory true;
+            }
+        }
+    }
+
+    rpc radius-server-set-position {
+        description "Used to change the order of radius-servers.";
+        input {
+            leaf ip-address {
+                type inet:ip-address;
+                mandatory true;
+
+                description "Ip address of the radius server.";
+            }
+            leaf port {
+                type portFormat;
+                mandatory true;
+
+                description "Port of the radius server.";
+            }
+            leaf position {
+                type int32;
+                mandatory true;
+
+                description "Position, either explicit, from 0, or -1 to move to end";
+            }
+        }
+    }
+    notification aps-notification {
+        description "This is the notification which is sent whenever an operational state changes.";
+        leaf notification-type {
+            type apsOperationalState;
+        }
+        leaf notification-details { type string; }
+    }
+    container subswitches {
+        list subswitch {
+            key "sname";
+            leaf sname {
+                type string;
+                description "The sub-switch name";
+            }
+            leaf-list username {
+                type string;
+                description "The user associated with the sub-switch";
+            }
+            leaf-list port-id {
+                type uint32;
+                description "The port number of the sub-switch";
+            }
+        }
+    }
+}
+
diff --git a/models/polatis/src/main/yang/polatis-switch.yang b/models/polatis/src/main/yang/polatis-switch.yang
new file mode 100644
index 0000000..d8f5d94
--- /dev/null
+++ b/models/polatis/src/main/yang/polatis-switch.yang
@@ -0,0 +1,479 @@
+module polatis-switch {
+    namespace "http://www.polatis.com/yang/polatis-switch";
+    prefix plts;
+
+    import optical-switch {
+        prefix opsw;
+    }
+
+    import ietf-yang-types {
+        prefix yang;
+    }
+
+    import ietf-inet-types {
+        prefix inet;
+    }
+
+    organization "Polatis Limited";
+    contact
+        "Adam Hughes
+
+        Polatis Limited
+        332/2 Cambridge Science Park
+        Cambridge CB4 0WN
+        United Kingdom
+
+        Phone: +44 (0) 1223 424200
+        Email: yang-support@polatis.com";
+
+    description "This module describes features that are specific to Polatis optical switches";
+
+    revision "2017-05-30" {
+        description "1. Added support for activity-log configuration and notifications.
+                     2. Added an RPC to get current system alarm
+                     3. Added the default value for enable-notifications. ";
+    }
+    revision "2016-04-22" {
+        description "1. Added support for the smart fibre Id identification and reporting.
+                     2. Added support for configuring and operation programmable shutters. ";
+    }
+    revision "2016-02-17" {
+        description "1. Added Polatis specific Variable Optical Attenuation (VOA) modes
+                     2. Changed the data type for power alarm hysteresis and defined the range.";
+    }
+    revision "2015-09-14" {
+        description "Initial revision.";
+    }
+
+    augment /opsw:ports/opsw:port {
+        leaf fibre-id {
+            type string;
+
+            config false;
+
+            description "Id of the smart fibre that is connected to this port. Polatis switches report
+            'NA' if smart fibre is not connected on this port. Management interface can find matching Id
+            from a different switch to establish the network topology.";
+        }
+    }
+    augment /opsw:ports/opsw:port/opsw:opm {
+        leaf offset {
+            type opsw:floatFormat2d;
+
+            default 0;
+
+            description "Offset for the power measurement; the value is added to power
+            monitor measurements when reporting /opsw:ports/opsw:port[]/opsw:opm/opsw:power.
+            Thus, specifying an offset can be used as a means of referencing the power
+            monitors against external meters.
+            It should be noted that the offset feature does NOT impact the behaviour
+            of the alarm or attenuation features:
+            alarm and attenuation settings always operate relative to the actual
+            power monitor readings, i.e. without any user-specified offsets.
+            Specified in dBm.";
+        }
+        leaf averaging-time-select {
+            type uint8 {
+                range "1..8";
+            }
+
+            default 4;
+
+            description "Selects the averaging period; each increment
+            in this value doubles the length of the time for which the OPM power
+            readings are averaged.
+            Setting the value to 1 results in the shortest averaging period, around 10ms.
+            Setting the value to 8 results in the longest averaging period, 128 times greater.";
+        }
+        leaf power-alarm-hysteresis {
+            type decimal64 {
+                fraction-digits 2;
+                range "1..5";
+            }
+
+            default 1;
+
+            description "Added to 'power-low-alarm' and subtracted from 'power-high-alarm'
+            to generate alarm clear notifications. Specified in dBm.";
+        }
+        leaf power-alarm-clear-holdoff {
+            type uint32;
+            default 10;
+
+            description "Minimum time (in seconds) for which the optical power level needs
+            to be restored within the power alarm thresholds for the switch to generate
+            an alarm clear notification.";
+        }
+    }
+    augment /opsw:ports/opsw:port/opsw:opm/opsw:voa {
+        leaf polatis-atten-modes {
+            type enumeration {
+                enum VOA_ATTEN_MODE_CONVERGED   { value 1; }
+                enum VOA_ATTEN_MODE_MAXIMUM     { value 2; }
+                enum VOA_ATTEN_MODE_FIXED       { value 3; }
+            }
+            description " VOA_ATTEN_MODE_CONVERGED: This is similar in behaviour to ABSOLUTE mode, but once
+                        the attenuation converges to the desired level the switch freezes the VOA control loop.
+            This reduces noise caused by the control loop continually striving to improve the attenuation.
+            VOA_ATTEN_MODE_MAXIMUM: Port will achieve the maximum attenuation level. In this case configured
+            attenuation level is not used.
+            VOA_ATTEN_MODE_FIXED: Disables closed loop updating of the attenuation feature for the specified port.
+            Following issuance of this command, the port will continue to hold their current attenuation level
+                        without any optical feedback. Thus, any changes in input power levels will no longer be tracked";
+        }
+    }
+    augment "/opsw:system-config" {
+        leaf startup-mode {
+            type enumeration {
+                enum MODE_VOLATILE;
+                enum MODE_PRESERVE;
+            }
+            default MODE_PRESERVE;
+
+            description "Specifies that the configuration needs to be stored
+            across a system-reset. When the mode is set to MODE_PRESERVE all new configurations will
+            be saved and switch will boot to last saved configuration. When the startup mode is MODE_VOLATILE
+            the switch will not retain the given configuration through system reset.";
+        }
+        list logged-in-users {
+            config false;
+            key username;
+
+            leaf username {
+                type opsw:namesFormat;
+            }
+
+            description "Users that are currently logged into the system.";
+        }
+    }
+    augment "/opsw:system-config/opsw:user" {
+        leaf group {
+            type enumeration {
+                enum "admin";
+                enum "user";
+                enum "view";
+            }
+            description "The permissions group to which user belongs.
+            Users in 'admin' group can read and write every data defined for the switch. They can
+            create, delete or edit users, change system-config data.
+            Users in 'user' group cannot change anything in the 'opsw:system-config', otherwise
+            they can change port configuration, cross-connect, only view notification log;
+            Users in 'view' group can only read data";
+        }
+    }
+
+    typedef polatis-switch-status {
+        type enumeration {
+            enum OPERATIONAL;
+            enum REQUEST_SERVICE;
+        }
+
+        description "Polatis switches are designed to recover from most system errors and will report
+        OPERATIONAL after most system errors. Some system errors require service by Polatis engineers. Users are advised to
+        Contact Polatis when REQUEST_SERVICE is reported.";
+    }
+
+    typedef notification-types {
+        type bits {
+            bit NOTIF_NONE {
+                position 0;
+                description "No notification";
+            }
+            bit NOTIF_PORT_POWER {
+                position 1;
+                description "Issued when power readings are outside power-alarm thresholds.";
+            }
+            bit NOTIF_PORT_POWER_WARN {
+                position 2;
+                description "Issued when power readings are outside power-warning thresholds.";
+            }
+            bit NOTIF_SYSTEM {
+                position 5;
+                description "Issued for an internal error";
+            }
+            bit NOTIF_APS {
+                position 7;
+                description "Issued for aps events.";
+            }
+            bit NOTIF_ACTIVITY {
+                position 8;
+                description "Issued for any configuration changes performed by users.";
+            }
+        }
+    }
+
+    leaf enable-notifications {
+        type notification-types;
+
+        default NOTIF_NONE;
+
+        description "Decide which class of netconf notification to send.
+        All notifications are disabled by default";
+    }
+
+    notification port-power-alarm {
+        description "Sent when power reading moves outside the thresholds set.";
+
+        leaf port-id {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-id";
+            }
+            mandatory true;
+        }
+        leaf port-label {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-label";
+            }
+            description "Label of the notification port";
+        }
+    }
+    notification port-power-clear {
+        description "Sent when power reading returns within the thresholds set, including hysteresis.";
+
+        leaf port-id {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-id";
+            }
+            mandatory true;
+        }
+        leaf port-label {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-label";
+            }
+            description "Label of the notification port";
+        }
+    }
+    notification port-power-warn-alarm {
+        description "Sent when power reading moves outside the warning offsets to the thresholds set.";
+
+        leaf port-id {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-id";
+            }
+            mandatory true;
+        }
+        leaf port-label {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-label";
+            }
+            description "Label of the notification port";
+        }
+    }
+    notification port-power-warn-clear {
+        description "Sent when power reading returns within offsets to the thresholds set,
+        including hysteresis.";
+
+        leaf port-id {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-id";
+            }
+            mandatory true;
+        }
+        leaf port-label {
+            type leafref {
+                path "/opsw:ports/opsw:port/opsw:port-label";
+            }
+            description "Label of the notification port";
+        }
+    }
+    notification system-error {
+        description "This notification is generated when switch encounters an unexpected error.";
+
+        leaf error-code {
+            type uint32;
+            mandatory true;
+            description "Description of the system error.";
+        }
+        leaf switch-status {
+            type polatis-switch-status;
+            mandatory true;
+            description "Status of the switch after the system error which
+            resulted in this notification";
+        }
+        leaf message {
+            type string;
+            description "Message related to system error.";
+        }
+    }
+    notification activity-log-notification {
+        description "Sent when a new entry appears in the activity log.";
+        leaf notification-username { type string; }
+        leaf notification-ip-address { type inet:ip-address; }
+        leaf notification-protocol { type string; }
+        leaf notification-activity { type string; }
+    }
+
+
+    container notification-log {
+        config false;
+
+        list log {
+            key notif-id;
+            leaf notif-id {
+                type uint32;
+                description "Unique Id for the notification.";
+            }
+            leaf notif-type {
+                type notification-types;
+                mandatory true;
+            }
+            leaf notif-count {
+                type uint32;
+                description "The number of notifications of the same notif-id.";
+            }
+            leaf notif-time-first {
+                type yang:date-and-time;
+                mandatory true;
+                description "Time at which the first notification was generated";
+            }
+            leaf notif-time-last {
+                type yang:date-and-time;
+                mandatory true;
+                description "Time at which the last notification was generated";
+            }
+            leaf notif-message {
+                type string;
+                mandatory true;
+                description "Useful textual representation of the notification cause.";
+            }
+            leaf notif-port {
+                type leafref {
+                    path "/opsw:ports/opsw:port/opsw:port-id";
+                }
+                when "../notif-type = 'NOTIF_PORT_POWER' or " +
+                     "../notif-type = 'NOTIF_PORT_POWER_WARN' or " +
+                     "../notif-type = 'NOTIF_PORT'";
+            }
+            leaf notif-port-status {
+                type opsw:PortStatus;
+                when "../notif-type = 'NOTIF_PORT'";
+            }
+            container notif-system {
+                leaf error-code {
+                    type uint32;
+                }
+                leaf switch-status {
+                    type polatis-switch-status;
+                }
+                when "../notif-type = 'NOTIF_SYSTEM'";
+            }
+            description "Contains the log of all the notifications generated by the switch.";
+        }
+    }
+
+    rpc shutter-config {
+        input {
+            leaf duration-on {
+                type uint32;
+                mandatory true;
+
+                description "Set how long the shutter will switched on in ms";
+            }
+            leaf duration-off {
+                type uint32;
+                mandatory true;
+
+                description "Set how long the shutter will be switched off in ms";
+            }
+            leaf cycles {
+                type int32;
+
+                description "Set the specific number of cycles the repeating
+                    shutter operates for";
+            }
+
+            list port-interval {
+                key port-id;
+                leaf port-id { type opsw:portFormat; }
+                min-elements 1;
+            }
+        }
+    }
+
+    rpc shutter-status {
+        output {
+            list port-interval {
+                key port-id;
+                leaf port-id { type opsw:portFormat; }
+
+                leaf duration-on {
+                    type uint32;
+                    mandatory true;
+
+                    description "Get how long the shutter will be switched on in ms";
+                }
+                leaf duration-off {
+                    type uint32;
+                    mandatory true;
+
+                    description "Get how long the shutter will be switched off in ms";
+                }
+
+                leaf cycles {
+                    type uint32;
+
+                    description "Get the specific number of cycles the repeating
+                        shutter operates for";
+                }
+            }
+        }
+
+    }
+
+    rpc shutter-operation {
+        input {
+            leaf operation-on {
+                type boolean;
+                mandatory true;
+
+                description "The leaf starts or stops the given mode for programmable shutters. It will
+                             continue until it is stopped. Double stops and double starts have no effect.";
+            }
+        }
+    }
+
+    rpc clear-notification-ids {
+        description "This clears named or all notifications from the log, don't provide any input, or empty list to remove all.";
+        input {
+            list notif-ids {
+                leaf notif-id {
+                    type uint32;
+                    description "Unique Id for the notification.";
+                }
+            }
+        }
+    }
+
+    rpc get-alarm-state {
+        description "This returns the alarm states currently active.";
+        output {
+            list alarm-state {
+                key alarm-index;
+                leaf alarm-index {
+                    type uint32;
+                    description "This is simply a count to have a unique key in the list";
+                }
+
+                leaf alarm-type {
+                    type notification-types;
+                    mandatory true;
+                }
+                leaf alarm-time {
+                    type yang:date-and-time;
+                    mandatory true;
+                    description "Time at which the first notification was generated.";
+                }
+                leaf alarm-message {
+                    type string;
+                    mandatory true;
+                    description "Useful textual representation of the alarm cause.";
+                }
+                leaf port-id {
+                    type uint32;
+                    description "Port id parsed out the alarm message, set to 0 if not simple.";
+                }
+            }
+        }
+    }
+
+}
diff --git a/modules.defs b/modules.defs
index 345f4f9..389e91f 100644
--- a/modules.defs
+++ b/modules.defs
@@ -107,6 +107,7 @@
     '//drivers/bmv2:onos-drivers-bmv2-oar',
     '//drivers/hp:onos-drivers-hp-oar',
     '//drivers/p4runtime:onos-drivers-p4runtime-oar',
+    '//drivers/polatis/netconf:onos-drivers-polatis-netconf-oar',
 ]
 
 ONOS_PROVIDERS = [
@@ -236,7 +237,8 @@
     '//models/openconfig:onos-models-openconfig-oar',
     '//models/openroadm:onos-models-openroadm-oar',
     '//models/l3vpn:onos-models-l3vpn-oar',
-    '//models/microsemi:onos-models-microsemi-oar'
+    '//models/microsemi:onos-models-microsemi-oar',
+    '//models/polatis:onos-models-polatis-oar',
 ]
 
 APP_JARS = [