ONOS-3758 restructuring driver module with sub-modules for different drivers

Change-Id: I3c65d19be87066448655610abf9d8b89385a4141
diff --git a/drivers/ovsdb/features.xml b/drivers/ovsdb/features.xml
new file mode 100644
index 0000000..981a24d
--- /dev/null
+++ b/drivers/ovsdb/features.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+  ~ Copyright 2016 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.
+  -->
+
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+    <feature name="${project.artifactId}" version="${project.version}"
+             description="${project.description}">
+        <feature>onos-api</feature>
+        <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
+
+        <bundle>mvn:${project.groupId}/onos-ovsdb-api/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-ovsdb-rfc/${project.version}</bundle>
+    </feature>
+</features>
diff --git a/drivers/ovsdb/pom.xml b/drivers/ovsdb/pom.xml
new file mode 100644
index 0000000..fcff99d
--- /dev/null
+++ b/drivers/ovsdb/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2016 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-drivers-general</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.5.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-drivers-ovsdb</artifactId>
+    <packaging>bundle</packaging>
+
+    <description>ovsdb device drivers</description>
+
+    <properties>
+        <onos.app.name>org.onosproject.drivers.ovsdb</onos.app.name>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-ovsdb-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-ovsdb-api</artifactId>
+            <version>${project.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java
new file mode 100644
index 0000000..e692eeb
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbBridgeConfig.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2016 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.drivers.ovsdb;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.BridgeConfig;
+import org.onosproject.net.behaviour.BridgeDescription;
+import org.onosproject.net.behaviour.BridgeName;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.net.behaviour.DefaultBridgeDescription;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.ovsdb.controller.OvsdbBridge;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbController;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+import org.onosproject.ovsdb.controller.OvsdbPort;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * The implementation of BridageConfig.
+ */
+public class OvsdbBridgeConfig extends AbstractHandlerBehaviour
+        implements BridgeConfig {
+
+    @Override
+    public void addBridge(BridgeName bridgeName) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        clientService.createBridge(bridgeName.name());
+    }
+
+    @Override
+    public void addBridge(BridgeName bridgeName, String dpid, String exPortName) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        clientService.createBridge(bridgeName.name(), dpid, exPortName);
+    }
+
+    @Override
+    public boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        return clientService.createBridge(bridgeName.name(), dpid, controllers);
+    }
+
+    @Override
+    public void deleteBridge(BridgeName bridgeName) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        clientService.dropBridge(bridgeName.name());
+    }
+
+    @Override
+    public Collection<BridgeDescription> getBridges() {
+        DriverHandler handler = handler();
+        DeviceId deviceId = handler.data().deviceId();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbBridge> bridges = clientService.getBridges();
+
+        return bridges.stream()
+                .map(x -> new DefaultBridgeDescription(
+                                BridgeName.bridgeName(x.bridgeName().value()),
+                                deviceId,
+                                DeviceId.deviceId("of:" + x.datapathId().value())
+                        )
+                )
+                .collect(Collectors.toSet());
+    }
+
+    @Override
+    public void addPort(PortDescription port) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
+        if (ovsdbSet != null && ovsdbSet.size() > 0) {
+            OvsdbBridge bridge = ovsdbSet.iterator().next();
+            clientService.createPort(bridge.bridgeName().toString(), port
+                    .portNumber().toString());
+        }
+    }
+
+    @Override
+    public void addPort(BridgeName bridgeName, String portName) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        clientService.createPort(bridgeName.name(), portName);
+    }
+
+    @Override
+    public void deletePort(PortDescription port) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbBridge> ovsdbSet = clientService.getBridges();
+        if (ovsdbSet != null && ovsdbSet.size() > 0) {
+            OvsdbBridge bridge = ovsdbSet.iterator().next();
+            clientService.dropPort(bridge.bridgeName().toString(), port
+                    .portNumber().toString());
+        }
+    }
+
+    @Override
+    public Collection<PortDescription> getPorts() {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbPort> ports = clientService.getPorts();
+
+        return ports.stream()
+                .map(x -> new DefaultPortDescription(
+                                PortNumber.portNumber(x.portNumber().value()),
+                                true,
+                                DefaultAnnotations.builder()
+                                        .set("portName", x.portName().value())
+                                        .build()))
+                .collect(Collectors.toSet());
+    }
+
+    // OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
+    // is used in the core. So DeviceId need be changed to OvsdbNodeId.
+    private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
+        String[] splits = deviceId.toString().split(":");
+        if (splits == null || splits.length < 1) {
+            return null;
+        }
+        IpAddress ipAddress = IpAddress.valueOf(splits[1]);
+        return new OvsdbNodeId(ipAddress, 0);
+    }
+
+    // Used for getting OvsdbClientService.
+    private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
+        OvsdbController ovsController = handler.get(OvsdbController.class);
+        DeviceId deviceId = handler.data().deviceId();
+        OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
+        return ovsController.getOvsdbClient(nodeId);
+    }
+
+    @Override
+    public Set<PortNumber> getPortNumbers() {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbPort> ports = clientService.getPorts();
+
+        return ports.stream()
+                .map(x -> PortNumber.portNumber(
+                                x.portNumber().value(),
+                                x.portName().value()
+                        )
+                )
+                .collect(Collectors.toSet());
+    }
+
+    @Override
+    public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) {
+        List<PortNumber> ports = new ArrayList<>();
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<OvsdbPort> ovsdbSet = clientService.getLocalPorts(ifaceIds);
+        ovsdbSet.forEach(o -> {
+            PortNumber port = PortNumber.portNumber(o.portNumber().value(),
+                                                    o.portName().value());
+            ports.add(port);
+        });
+        return ports;
+    }
+}
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfig.java
new file mode 100644
index 0000000..b04d566
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfig.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016 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.drivers.ovsdb;
+
+import com.google.common.collect.ImmutableSet;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerConfig;
+import org.onosproject.net.behaviour.ControllerInfo;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.ovsdb.controller.OvsdbBridge;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbController;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Preconditions.checkState;
+import static org.onlab.util.Tools.delay;
+
+/**
+ * Implementation of controller config which allows to get and set controllers.
+ */
+public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements ControllerConfig {
+    @Override
+    public List<ControllerInfo> getControllers() {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        Set<ControllerInfo> controllers = clientService.getControllers(
+                handler().data().deviceId());
+        return new ArrayList<>(controllers);
+    }
+
+    @Override
+    public void setControllers(List<ControllerInfo> controllers) {
+        DriverHandler handler = handler();
+        OvsdbClientService clientService = getOvsdbClientService(handler);
+        if (!clientService.getControllers(handler().data().deviceId())
+                .equals(ImmutableSet.copyOf(controllers))) {
+            clientService.setControllersWithDeviceId(handler().
+                    data().deviceId(), controllers);
+        }
+    }
+
+    // Used for getting OvsdbClientService.
+    private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
+        OvsdbController ovsController = handler.get(OvsdbController.class);
+        DeviceService deviceService = handler.get(DeviceService.class);
+        DeviceId ofDeviceId = handler.data().deviceId();
+        String[] mgmtAddress = deviceService.getDevice(ofDeviceId)
+                .annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
+        String targetIp = mgmtAddress[0];
+        TpPort targetPort = null;
+        if (mgmtAddress.length > 1) {
+            targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
+        }
+
+        List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream()
+                .filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
+                .collect(Collectors.toList());
+        if (nodeIds.size() == 0) {
+            //TODO decide what port?
+            ovsController.connect(IpAddress.valueOf(targetIp),
+                                  targetPort == null ? TpPort.tpPort(6640) : targetPort);
+            delay(1000); //FIXME... connect is async
+        }
+        List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream()
+                .filter(nodeId -> nodeId.getIpAddress().equals(targetIp))
+                .map(ovsController::getOvsdbClient)
+                .filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId)))
+                .collect(Collectors.toList());
+        checkState(clientServices.size() > 0, "No clientServices found");
+        //FIXME add connection to management address if null --> done ?
+        return clientServices.size() > 0 ? clientServices.get(0) : null;
+    }
+
+    private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) {
+        String bridgeDpid = "of:" + bridge.datapathId().value();
+        String ofDpid = deviceId.toString();
+        return bridgeDpid.equals(ofDpid);
+    }
+}
\ No newline at end of file
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbDriversLoader.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbDriversLoader.java
new file mode 100644
index 0000000..d3b127a
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbDriversLoader.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 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.drivers.ovsdb;
+
+import org.apache.felix.scr.annotations.Component;
+import org.onosproject.net.driver.AbstractDriverLoader;
+
+import java.io.InputStream;
+
+/**
+ * Loader for OVSDB device drivers from specific xml.
+ */
+@Component(immediate = true)
+public class OvsdbDriversLoader extends AbstractDriverLoader {
+
+    private static final String DRIVERS_XML = "/ovsdb-drivers.xml";
+
+    @Override
+    protected InputStream loadXMLDriversStream() {
+        return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
+    }
+
+    @Override
+    protected ClassLoader getClassLoaderInstance() {
+        return getClass().getClassLoader();
+    }
+}
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbTunnelConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbTunnelConfig.java
new file mode 100644
index 0000000..455c3ab
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbTunnelConfig.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2016 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.drivers.ovsdb;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.BridgeName;
+import org.onosproject.net.behaviour.DefaultTunnelDescription;
+import org.onosproject.net.behaviour.IpTunnelEndPoint;
+import org.onosproject.net.behaviour.TunnelConfig;
+import org.onosproject.net.behaviour.TunnelDescription;
+import org.onosproject.net.behaviour.TunnelName;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.ovsdb.controller.OvsdbClientService;
+import org.onosproject.ovsdb.controller.OvsdbController;
+import org.onosproject.ovsdb.controller.OvsdbNodeId;
+import org.onosproject.ovsdb.controller.OvsdbTunnel;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * OVSDB-based implementation of tunnel config behaviour.
+ */
+public class OvsdbTunnelConfig extends AbstractHandlerBehaviour
+        implements TunnelConfig {
+
+    private static final String DEFAULT_ADDRESS = "0.0.0.0";
+    private static final String OPTION_LOCAL_IP = "local_ip";
+    private static final String OPTION_REMOTE_IP = "remote_ip";
+
+    @Override
+    public void createTunnel(TunnelDescription tunnel) {
+        DriverHandler handler = handler();
+        OvsdbClientService ovsdbNode = getOvsdbNode(handler);
+        IpTunnelEndPoint ipSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                .valueOf(DEFAULT_ADDRESS));
+        IpTunnelEndPoint ipDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                .valueOf(DEFAULT_ADDRESS));
+        if (tunnel.src() instanceof IpTunnelEndPoint) {
+            ipSrc = (IpTunnelEndPoint) tunnel.src();
+        }
+        if (tunnel.dst() instanceof IpTunnelEndPoint) {
+            ipDst = (IpTunnelEndPoint) tunnel.dst();
+        }
+        //Even if source point ip or destination point ip equals 0:0:0:0, it is still work-in-progress.
+        ovsdbNode.createTunnel(ipSrc.ip(), ipDst.ip());
+    }
+
+    @Override
+    public boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel) {
+        Map<String, String> options = ((DefaultAnnotations) tunnel.annotations()).asMap();
+        if (tunnel.src() != null) {
+            options.put(OPTION_LOCAL_IP, ((IpTunnelEndPoint) tunnel.src()).ip().toString());
+        }
+        if (tunnel.dst() != null) {
+            options.put(OPTION_REMOTE_IP, ((IpTunnelEndPoint) tunnel.dst()).ip().toString());
+        }
+
+        DriverHandler handler = handler();
+        OvsdbClientService ovsdbClient = getOvsdbNode(handler);
+        return ovsdbClient.createTunnel(bridgeName.name(), tunnel.tunnelName().toString(),
+                                        tunnel.type().toString().toLowerCase(), options);
+    }
+
+    @Override
+    public void removeTunnel(TunnelDescription tunnel) {
+        DriverHandler handler = handler();
+        OvsdbClientService ovsdbNode = getOvsdbNode(handler);
+        IpTunnelEndPoint ipSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                .valueOf(DEFAULT_ADDRESS));
+        IpTunnelEndPoint ipDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+                .valueOf(DEFAULT_ADDRESS));
+        if (tunnel.src() instanceof IpTunnelEndPoint) {
+            ipSrc = (IpTunnelEndPoint) tunnel.src();
+        }
+        if (tunnel.dst() instanceof IpTunnelEndPoint) {
+            ipDst = (IpTunnelEndPoint) tunnel.dst();
+        }
+      //Even if source point ip or destination point ip equals 0:0:0:0, it is still work-in-progress.
+        ovsdbNode.dropTunnel(ipSrc.ip(), ipDst.ip());
+    }
+
+    @Override
+    public void updateTunnel(TunnelDescription tunnel) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public Collection<TunnelDescription> getTunnels() {
+        DriverHandler handler = handler();
+        OvsdbClientService ovsdbNode = getOvsdbNode(handler);
+        Set<OvsdbTunnel> tunnels = ovsdbNode.getTunnels();
+
+        return tunnels.stream()
+                .map(x ->
+                        new DefaultTunnelDescription(
+                                IpTunnelEndPoint.ipTunnelPoint(x.localIp()),
+                                IpTunnelEndPoint.ipTunnelPoint(x.remoteIp()),
+                                TunnelDescription.Type.VXLAN,
+                                TunnelName.tunnelName(x.tunnelName().toString())
+                        )
+                )
+                .collect(Collectors.toSet());
+    }
+
+    // OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP)
+    // is used in the core. So DeviceId need be changed to OvsdbNodeId.
+    private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) {
+        String[] splits = deviceId.toString().split(":");
+        if (splits == null || splits.length < 1) {
+            return null;
+        }
+        IpAddress ipAddress = IpAddress.valueOf(splits[1]);
+        return new OvsdbNodeId(ipAddress, 0);
+    }
+
+    private OvsdbClientService getOvsdbNode(DriverHandler handler) {
+        OvsdbController ovsController = handler.get(OvsdbController.class);
+        DeviceId deviceId = handler.data().deviceId();
+        OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId);
+        return ovsController.getOvsdbClient(nodeId);
+    }
+}
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/package-info.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/package-info.java
new file mode 100644
index 0000000..8d81f54
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 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 for OVSDB device drivers.
+ */
+package org.onosproject.drivers.ovsdb;
\ No newline at end of file
diff --git a/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml b/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
new file mode 100644
index 0000000..a32c614
--- /dev/null
+++ b/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 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.
+  -->
+<drivers>
+    <driver name="default"
+            manufacturer="ON.Lab" hwVersion="0.0.1" swVersion="0.0.1">
+        <behaviour api="org.onosproject.net.behaviour.TunnelConfig"
+                   impl="org.onosproject.drivers.ovsdb.OvsdbTunnelConfig"/>
+        <behaviour api="org.onosproject.net.behaviour.BridgeConfig"
+                   impl="org.onosproject.drivers.ovsdb.OvsdbBridgeConfig"/>
+    </driver>
+    <driver name="ovs" extends="default"
+            manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">
+        <behaviour api="org.onosproject.net.behaviour.ControllerConfig"
+                   impl="org.onosproject.drivers.ovsdb.OvsdbControllerConfig"/>
+    </driver>
+</drivers>
+
diff --git a/drivers/ovsdb/src/test/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfigTest.java b/drivers/ovsdb/src/test/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfigTest.java
new file mode 100644
index 0000000..c943a41
--- /dev/null
+++ b/drivers/ovsdb/src/test/java/org/onosproject/drivers/ovsdb/OvsdbControllerConfigTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015 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.drivers.ovsdb;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.ControllerConfig;
+import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.driver.DefaultDriver;
+import org.onosproject.net.driver.DefaultDriverData;
+import org.onosproject.net.driver.DefaultDriverHandler;
+import org.onosproject.ovsdb.controller.driver.OvsdbClientServiceAdapter;
+import org.onosproject.ovsdb.controller.driver.OvsdbControllerAdapter;
+
+import java.util.ArrayList;
+
+/**
+ * Created by Andrea on 10/7/15.
+ */
+public class OvsdbControllerConfigTest {
+
+
+    private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo");
+
+    private DefaultDriver ddc;
+    private DefaultDriverData data;
+    private DefaultDriverHandler handler;
+
+    private TestDeviceService deviceService = new TestDeviceService();
+    private TestOvsdbController controller = new TestOvsdbController();
+    private TestOvsdbClient client = new TestOvsdbClient();
+
+    private OvsdbControllerConfig controllerConfig;
+
+
+    @Before
+    public void setUp() {
+        controllerConfig = new OvsdbControllerConfig();
+
+        ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
+                                ImmutableMap.of(ControllerConfig.class,
+                                                OvsdbControllerConfig.class),
+                                ImmutableMap.of("foo", "bar"));
+        data = new DefaultDriverData(ddc, DEVICE_ID);
+        handler = new DefaultDriverHandler(data);
+        //handler.controllerConfig.setHandler(handler);
+        //TODO setTestService directory on handler
+        //TODO setup ovsdb fake controller with fake ovsdbclient
+        //TODO setup fake device service
+    }
+
+    @Test
+    public void testGetControllers() throws Exception {
+//        DriverService driverService = new Driv
+//        AbstractBehaviour ab = new AbstractBehaviour();
+//        DriverHandler handler = handler();
+//        List<ControllerInfo> controllersList =
+//              controllerConfig.getControllers(DeviceId.deviceId("0000000000000018"));
+//        log.info("controllers " + controllersList);
+
+    }
+
+    @Test
+    public void testSetControllers() throws Exception {
+
+    }
+
+
+    private class TestDeviceService extends DeviceServiceAdapter {
+
+    }
+
+    private class TestOvsdbController extends OvsdbControllerAdapter {
+
+
+    }
+
+    private class TestOvsdbClient extends OvsdbClientServiceAdapter {
+
+    }
+}
\ No newline at end of file