TL1 device provider with driver for Lumentum WaveReady.

ONOS-5800 & ONOS-5801

Change-Id: Icd820285eb8db2fd92c03ebf11ce022b6a82b48a
diff --git a/protocols/tl1/api/BUCK b/protocols/tl1/api/BUCK
new file mode 100644
index 0000000..3ce3f98
--- /dev/null
+++ b/protocols/tl1/api/BUCK
@@ -0,0 +1,8 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:netty-transport',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
diff --git a/protocols/tl1/api/pom.xml b/protocols/tl1/api/pom.xml
new file mode 100644
index 0000000..bedfc6e
--- /dev/null
+++ b/protocols/tl1/api/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2016-present Open Networking Laboratory
+  ~
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>onos-tl1</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.9.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-tl1-api</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-handler</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Command.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Command.java
new file mode 100644
index 0000000..02dd4dc
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Command.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.tl1;
+
+import com.google.common.annotations.Beta;
+
+import java.util.Optional;
+
+/**
+ * Representation of a TL1 command, which is sent from the controller to a network element.
+ *
+ * The following shows the typical TL1 command structure:
+ *      {@literal VERB-MODIFIER:<tid>:<aid>:<ctag>::parameter-list;}
+ *
+ * The ctag must be a non-zero decimal number consisting of not more than six characters,
+ * and is assumed to be a unique message identifier per device.
+ */
+@Beta
+public interface Tl1Command {
+
+    /**
+     * Minimum CTAG value.
+     */
+    int MIN_CTAG = 0;
+
+    /**
+     * Maximum CTAG value.
+     */
+    int MAX_CTAG = 999999;
+
+    /**
+     * Returns the verb of the command.
+     *
+     * @return the verb
+     */
+    String verb();
+
+    /**
+     * Returns the modifier of the command.
+     *
+     * @return the modifier
+     */
+    String modifier();
+
+    /**
+     * Returns the optional target identifier (tid).
+     *
+     * @return the tid
+     */
+    Optional<String> tid();
+
+    /**
+     * Returns the optional access identifier (aid).
+     *
+     * @return the aid
+     */
+    Optional<String> aid();
+
+    /**
+     * Returns the correlation tag (ctag).
+     *
+     * @return correlation tag
+     */
+    int ctag();
+
+    /**
+     * Returns the optional parameters.
+     *
+     * @return the parameters
+     */
+    Optional<String> parameters();
+
+    /**
+     * TL1 command builder.
+     *
+     * @param <T> builder implementation type
+     */
+    interface Builder<T extends Builder<T>> {
+        /**
+         * Assigns a verb to this TL1 command.
+         *
+         * @param verb a verb
+         * @return this
+         */
+        T withVerb(String verb);
+
+        /**
+         * Assigns a modifier to this TL1 command.
+         *
+         * @param modifier a modifier
+         * @return this
+         */
+        T withModifier(String modifier);
+
+        /**
+         * Assigns a target identifier to this TL1 command.
+         *
+         * @param tid a tid
+         * @return this
+         */
+        T forTid(String tid);
+
+        /**
+         * Assigns an access identifier to this TL1 command.
+         *
+         * @param aid an aid
+         * @return this
+         */
+        T withAid(String aid);
+
+        /**
+         * Assigns a correlation tag to this TL1 command.
+         *
+         * @param ctag a ctag
+         * @return this
+         */
+        T withCtag(int ctag);
+
+        /**
+         * Assigns parameters to this TL1 command.
+         *
+         * @param parameters the parameters
+         * @return this
+         */
+        T withParameters(String parameters);
+
+        /**
+         * Builds a TL1 command.
+         *
+         * @return the TL1 command
+         */
+        Tl1Command build();
+    }
+}
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Controller.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Controller.java
new file mode 100644
index 0000000..feaa0dc0
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Controller.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.tl1;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+
+import java.util.Collection;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+@Beta
+public interface Tl1Controller {
+    /**
+     * Sends the message to the device asynchronously.
+     *
+     * @param deviceId the device to write to
+     * @param msg the message to write
+     * @return the device response
+     */
+    // TODO: return CompletableFuture<Tl1Message> once we have appropriate builders
+    CompletableFuture<String> sendMsg(DeviceId deviceId, Tl1Command msg);
+
+    /**
+     * Returns the device identified by given ID.
+     *
+     * @param deviceId the device ID to lookup
+     * @return optional Tl1Device
+     */
+    Optional<Tl1Device> getDevice(DeviceId deviceId);
+
+    /**
+    /**
+     * Adds a device to the controller.
+     * @param deviceId the device ID to add
+     * @param device the device to add
+     * @return true if device added, false if already known
+     */
+    boolean addDevice(DeviceId deviceId, Tl1Device device);
+
+    /**
+     * Disconnects the device and removes it from the controller.
+     * @param deviceId the device to remove
+     */
+    void removeDevice(DeviceId deviceId);
+
+    /**
+     * Connects the controller to the device.
+     * @param deviceId the device to disconnect to
+     */
+    void connectDevice(DeviceId deviceId);
+
+    /**
+     * Disconnects the device from the controller.
+     * @param deviceId the device to disconnect from
+     */
+    void disconnectDevice(DeviceId deviceId);
+
+    /**
+     * Returns a set of all devices IDs for this TL1 controller.
+     * @return set of device IDs
+     */
+    Set<DeviceId> getDeviceIds();
+
+    /**
+     * Returns a set of all devices for this TL1 controller.
+     * @return collection of TL1 devices
+     */
+    Collection<Tl1Device> getDevices();
+
+    /**
+     * Registers a listener for TL1 events.
+     *
+     * @param listener the listener to notify
+     */
+    void addListener(Tl1Listener listener);
+
+    /**
+     * Unregisters a listener for TL1 events.
+     *
+     * @param listener the listener to unregister
+     */
+    void removeListener(Tl1Listener listener);
+}
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Device.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Device.java
new file mode 100644
index 0000000..71dc01e
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Device.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.tl1;
+
+import com.google.common.annotations.Beta;
+import io.netty.channel.Channel;
+import org.onlab.packet.IpAddress;
+
+@Beta
+public interface Tl1Device {
+    IpAddress ip();
+
+    int port();
+
+    /**
+     * The username to log in to the switch.
+     *
+     * @return the user name
+     */
+    String username();
+
+    /**
+     * The password to log in to the switch.
+     *
+     * @return the password
+     */
+    String password();
+
+    /**
+     * The target identifier (TID) of the device.
+     *
+     * @return the tid
+     */
+    String tid();
+
+    /**
+     * Check if the switch is connected.
+     *
+     * @return true if connected, false otherwise
+     */
+    boolean isConnected();
+
+    /**
+     * Returns the netty channel of the switch.
+     *
+     * @return the netty channel, null if disconnected
+     */
+    Channel channel();
+
+    /**
+     * Connects the switch to the channel.
+     * @param channel the channel
+     */
+    void connect(Channel channel);
+
+    /**
+     * Disconnects the switch from its channel.
+     */
+    void disconnect();
+}
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Listener.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Listener.java
new file mode 100644
index 0000000..8260e05
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/Tl1Listener.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.tl1;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.DeviceId;
+
+@Beta
+public interface Tl1Listener {
+    /**
+     * Notify that the device has connected.
+     *
+     * @param deviceId the connected device
+     */
+    void deviceConnected(DeviceId deviceId);
+
+    /**
+     * Notify that the device has disconnected.
+     *
+     * @param deviceId the disconnected device
+     */
+    void deviceDisconnected(DeviceId deviceId);
+}
diff --git a/protocols/tl1/api/src/main/java/org/onosproject/tl1/package-info.java b/protocols/tl1/api/src/main/java/org/onosproject/tl1/package-info.java
new file mode 100644
index 0000000..964dcf6
--- /dev/null
+++ b/protocols/tl1/api/src/main/java/org/onosproject/tl1/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * TL1 protocol API.
+ */
+package org.onosproject.tl1;
\ No newline at end of file