Supports methods to get interface-related information in ovsdbclient service.

Change-Id: Ic7e45178c8adc9b207b43d893e64b1f2f47cebd4
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
index d552a70..dd0d787 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java
@@ -15,11 +15,7 @@
  */
 package org.onosproject.ovsdb.controller;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
+import com.google.common.util.concurrent.ListenableFuture;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.ControllerInfo;
@@ -34,10 +30,14 @@
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
 import org.onosproject.ovsdb.rfc.notation.Row;
 import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
-
-import com.google.common.util.concurrent.ListenableFuture;
+import org.onosproject.ovsdb.rfc.table.Interface;
 import org.onosproject.ovsdb.rfc.table.OvsdbTable;
 
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
 /**
  * Represents to provider facing side of a node.
  */
@@ -267,6 +267,21 @@
     Set<OvsdbPort> getPorts();
 
     /**
+     * Gets interfaces of bridge.
+     *
+     * @return set of interfaces; empty if no interface is find
+     */
+    Set<Interface> getInterfaces();
+
+    /**
+     * Gets the interface with given portName.
+     *
+     * @param intf interface name
+     * @return interface
+     */
+    Interface getInterface(String intf);
+
+    /**
      * Checks if the node is still connected.
      *
      * @return true if the node is still connected
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
index 38f8ede..9ffa26e 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java
@@ -106,7 +106,29 @@
 import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
-import static org.onosproject.ovsdb.controller.OvsdbConstant.*;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGES;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE_CONTROLLER;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.DATABASENAME;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID_INTERFACE_ID;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACES;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.MIRROR;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.MIRRORS;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT_ERROR;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.PORT;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.PORTS;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.PORT_QOS;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QOS;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EXTERNAL_ID_KEY;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QUEUES;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.TYPEVXLAN;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.UUID;
 
 /**
  * An representation of an ovsdb client.
@@ -1600,7 +1622,15 @@
 
     @Override
     public Set<OvsdbPort> getPorts() {
-        Set<OvsdbPort> ovsdbPorts;
+        return (Set<OvsdbPort>) getElements(this::getOvsdbPort);
+    }
+
+    @Override
+    public Set<Interface> getInterfaces() {
+        return (Set<Interface>) getElements(this::getInterface);
+    }
+
+    private Set<?> getElements(Function<Row, ?> method) {
         OvsdbTableStore tableStore = getTableStore(DATABASENAME);
         if (tableStore == null) {
             return null;
@@ -1610,16 +1640,32 @@
             return null;
         }
         ConcurrentMap<String, Row> rows = rowStore.getRowStore();
-        ovsdbPorts = rows.keySet()
+
+        return rows.keySet()
                 .stream()
                 .map(uuid -> getRow(DATABASENAME, INTERFACE, uuid))
-                .map(this::getOvsdbPort)
+                .map(method)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
-        return ovsdbPorts;
     }
 
     @Override
+    public Interface getInterface(String intf) {
+        return getInterfaces().stream()
+                .filter(ovsdbIntf -> ovsdbIntf.getName().equals(intf))
+                .findAny().orElse(null);
+    }
+
+    private Interface getInterface(Row row) {
+        DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
+        Interface intf = (Interface) TableGenerator
+                .getTable(dbSchema, row, OvsdbTable.INTERFACE);
+        if (intf == null) {
+            return null;
+        }
+        return intf;
+    }
+    @Override
     public DatabaseSchema getDatabaseSchema(String dbName) {
         return schema.get(dbName);
     }
diff --git a/protocols/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java b/protocols/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
index 2d2b674..87dcc0b 100644
--- a/protocols/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
+++ b/protocols/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java
@@ -48,6 +48,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.onosproject.ovsdb.rfc.table.Interface;
 import org.onosproject.ovsdb.rfc.table.OvsdbTable;
 
 /**
@@ -218,6 +219,16 @@
     }
 
     @Override
+    public Set<Interface> getInterfaces() {
+        return null;
+    }
+
+    @Override
+    public Interface getInterface(String intf) {
+        return null;
+    }
+
+    @Override
     public boolean isConnected() {
         return false;
     }