[ONOS-5565]Implementation of QosConfig and QueueConfig

Change-Id: I6a367b53cfca2e85e8aaa6cddb541d7b3ffccbc0
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 8c4397a..8c11c3d 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
@@ -18,9 +18,12 @@
 import com.google.common.util.concurrent.ListenableFuture;
 import org.onlab.packet.IpAddress;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.net.behaviour.MirroringStatistics;
 import org.onosproject.net.behaviour.MirroringName;
+import org.onosproject.net.behaviour.QosId;
+import org.onosproject.net.behaviour.QueueId;
 import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRpc;
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
 import org.onosproject.ovsdb.rfc.notation.Row;
@@ -77,6 +80,82 @@
     void dropMirror(MirroringName mirroringName);
 
     /**
+     * apply qos to port.
+     *
+     * @param  portNumber port identifier
+     * @param  qosName the qos name
+     */
+    void applyQos(PortNumber portNumber, String qosName);
+
+    /**
+     * Creates a qos port.
+     *
+     * @param  portNumber port identifier
+     */
+    void removeQos(PortNumber portNumber);
+
+    /**
+     * Creates a qos. associates with queue to
+     * provide the ability of limit the rate of different flows
+     * depend on itself priority.
+     *
+     * @param  ovsdbQos the OVSDB Qos
+     * @return true if qos creation is successful, false otherwise
+     */
+    boolean createQos(OvsdbQos ovsdbQos);
+
+    /**
+     * Drops the configuration for qos.
+     *
+     * @param qosId qos identifier
+     */
+    void dropQos(QosId qosId);
+
+    /**
+     * Gets a qos of node.
+     * @param qosId qos identifier
+     * @return null if no qos is find
+     */
+    OvsdbQos getQos(QosId qosId);
+
+    /**
+     * Gets qoses of node.
+     *
+     * @return set of qoses; empty if no qos is find
+     */
+    Set<OvsdbQos> getQoses();
+
+    /**
+     * Creates queues. limits the rate of each flow
+     * depend on itself priority.
+     *
+     * @param  queue the OVSDB queue description
+     * @return true if queue creation is successful, false otherwise
+     */
+    boolean createQueue(OvsdbQueue queue);
+
+    /**
+     * Drops the configuration for queue.
+     *
+     * @param queueId  queue identifier
+     */
+    void dropQueue(QueueId queueId);
+
+    /**
+     * Gets a queue of node.
+     * @param queueId the queue identifier
+     * @return null if no queue is find
+     */
+    OvsdbQueue getQueue(QueueId queueId);
+
+    /**
+     * Gets queues of node.
+     *
+     * @return set of queues; empty if no queue is find
+     */
+    Set<OvsdbQueue> getQueues();
+
+    /**
      * Creates a tunnel port with given options.
      *
      * @deprecated version 1.7.0 - Hummingbird
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
index aea0845..cb2a31e 100644
--- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbConstant.java
@@ -49,6 +49,7 @@
     /** Port table. */
     public static final String PORT = "Port";
     public static final String INTERFACES = "interfaces";
+    public static final String PORT_QOS = "qos";
 
     /** Interface table. */
     public static final String INTERFACE = "Interface";
@@ -70,6 +71,26 @@
     /** Mirror table. */
     public static final String MIRROR = "Mirror";
 
+    /* Qos table */
+    public static final String QOS = "QoS";
+    public static final String QUEUES = "queues";
+    public static final String CIR = "cir";
+    public static final String CBS = "cbs";
+    public static final String QOS_EXTERNAL_ID_KEY = "onos-qos-id";
+    public static final String QOS_TYPE_PREFIX = "linux-";
+    public static final String QOS_EGRESS_POLICER = "egress-policer";
+
+    /* Queue table */
+    public static final String QUEUE = "Queue";
+    public static final String MIN_RATE = "min-rate";
+    public static final String MAX_RATE = "max-rate";
+    public static final String BURST = "burst";
+    public static final String PRIORITY = "priority";
+    public static final String QUEUE_EXTERNAL_ID_KEY = "onos-queue-id";
+
+    /* external id */
+    public static final String EXTERNAL_ID = "external_ids";
+
     /** Ovsdb bridge name. */
     // TODO remove this particular bridge name from OVSDB provider
     public static final String INTEGRATION_BRIDGE = "br-int";
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQos.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQos.java
new file mode 100644
index 0000000..467ccfc
--- /dev/null
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQos.java
@@ -0,0 +1,250 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.ovsdb.controller;
+
+import com.google.common.collect.Maps;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.QosDescription;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.CBS;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.CIR;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.MAX_RATE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EGRESS_POLICER;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EXTERNAL_ID_KEY;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QOS_TYPE_PREFIX;
+
+/**
+ * The class representing an OVSDB Qos.
+ * This class is immutable.
+ */
+public final class OvsdbQos {
+
+    private final String type;
+    private Optional<Map<Long, String>> queues;
+    private Map<String, String> otherConfigs;
+    private Map<String, String> externalIds;
+
+    /**
+     * Creates an OvsdbQos using the given inputs.
+     *
+     * @param type the type of the qos
+     * @param queues rate queues
+     * @param otherConfigs Key-value pairs for configuring rarely used features
+     * @param externalIds Key-value pairs for use by external frameworks, rather than by OVS itself
+     */
+    private OvsdbQos(String type, Optional<Map<Long, String>> queues,
+                     Map<String, String> otherConfigs,
+                     Map<String, String> externalIds) {
+
+        this.type = checkNotNull(type);
+        this.queues = queues;
+        this.otherConfigs = otherConfigs;
+        this.externalIds = externalIds;
+    }
+
+    /**
+     * Returns the type of qos.
+     *
+     * @return the type of qos
+     */
+    public String qosType() {
+        return type;
+    }
+
+    /**
+     * Returns the map of queues.
+     *
+     * @return the queues.
+     */
+    public Optional<Map<Long, String>> qosQueues() {
+        return queues;
+    }
+
+    /**
+     * Returns other configurations of the qos.
+     *
+     * @return map of configurations
+     */
+    public Map<String, String> otherConfigs() {
+        return otherConfigs;
+    }
+
+    /**
+     * Returns the optional external ids.
+     *
+     * @return the external ids.
+     */
+    public Map<String, String> externalIds() {
+        return externalIds;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type, queues, externalIds);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof OvsdbQos) {
+            final OvsdbQos other = (OvsdbQos) obj;
+            return Objects.equals(this.type, other.type) &&
+                    Objects.equals(this.otherConfigs, other.otherConfigs) &&
+                    Objects.equals(this.queues, other.queues) &&
+                    Objects.equals(this.externalIds, other.externalIds);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("qosType", qosType())
+                .add("qosQueues", qosQueues())
+                .add("otherConfigs", otherConfigs())
+                .add("externalIds", externalIds())
+                .toString();
+    }
+
+    /**
+     * Returns new OVSDB qos builder.
+     *
+     * @return ovsdb qos builder
+     */
+    public static OvsdbQos.Builder builder() {
+        return new OvsdbQos.Builder();
+    }
+
+    /**
+     * Returns new OVSDB qos builder with Qos description.
+     *
+     * @param qosDesc qos description
+     * @return ovsdb qos builder
+     */
+    public static Builder builder(QosDescription qosDesc) {
+        return new Builder(qosDesc);
+    }
+
+    /**
+     * Builder of OVSDB qos entities.
+     */
+    public static final class Builder {
+        private String type;
+        private Optional<Map<Long, String>> queues = Optional.empty();
+        private Map<String, String> otherConfigs = Maps.newHashMap();
+        private Map<String, String> externalIds = Maps.newHashMap();
+
+        /**
+         * Constructs an empty builder.
+         */
+        private Builder() {
+
+        }
+
+        /**
+         * Constructs a builder with a given Qos description.
+         *
+         * @param qosDesc Qos description
+         */
+        private Builder(QosDescription qosDesc) {
+            if (qosDesc.maxRate().isPresent()) {
+                otherConfigs.put(MAX_RATE, String.valueOf((long) qosDesc.maxRate().get().bps()));
+            }
+            if (qosDesc.cir().isPresent()) {
+                otherConfigs.put(CIR, qosDesc.cir().get().toString());
+            }
+            if (qosDesc.cbs().isPresent()) {
+                otherConfigs.put(CBS, qosDesc.cbs().get().toString());
+            }
+
+            if (qosDesc.queues().isPresent()) {
+                Map<Long, String> map = new HashMap();
+                qosDesc.queues().get().forEach((k, v) -> map.put(k, v.queueId().name()));
+                queues = Optional.ofNullable(map);
+            }
+            type = qosDesc.type() == QosDescription.Type.EGRESS_POLICER ?
+                    QOS_EGRESS_POLICER :
+                    QOS_TYPE_PREFIX.concat(qosDesc.type().name().toLowerCase());
+            externalIds.putAll(((DefaultAnnotations) qosDesc.annotations()).asMap());
+            externalIds.put(QOS_EXTERNAL_ID_KEY, qosDesc.qosId().name());
+        }
+
+        /**
+         * Returns new OVSDB qos.
+         *
+         * @return ovsdb qos
+         */
+        public OvsdbQos build() {
+            return new OvsdbQos(type, queues, otherConfigs, externalIds);
+        }
+
+        /**
+         * Returns OVSDB qos builder with a given type.
+         *
+         * @param type name of the qos
+         * @return ovsdb qos builder
+         */
+        public Builder qosType(String type) {
+            this.type = type;
+            return this;
+        }
+
+        /**
+         * Returns OVSDB qos builder with a given queues.
+         *
+         * @param queues the map of queue
+         * @return ovsdb qos builder
+         */
+        public Builder queues(Map<Long, String> queues) {
+            this.queues = Optional.ofNullable(queues);
+            return this;
+        }
+
+        /**
+         * Returns OVSDB qos builder with given configs.
+         *
+         * @param otherConfigs other configs
+         * @return ovsdb qos builder
+         */
+        public Builder otherConfigs(Map<String, String> otherConfigs) {
+            this.otherConfigs = Maps.newHashMap(otherConfigs);
+            return this;
+        }
+
+        /**
+         * Returns OVSDB qos builder with given external ids.
+         *
+         * @param ids the external ids
+         * @return ovsdb qos builder
+         */
+        public Builder externalIds(Map<String, String> ids) {
+            this.externalIds = ids;
+            return this;
+        }
+
+    }
+
+}
diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQueue.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQueue.java
new file mode 100644
index 0000000..3a326f1
--- /dev/null
+++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbQueue.java
@@ -0,0 +1,215 @@
+/*
+ * 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.
+ */
+
+package org.onosproject.ovsdb.controller;
+
+import com.google.common.collect.Maps;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.behaviour.QueueDescription;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.BURST;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.MAX_RATE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.MIN_RATE;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.PRIORITY;
+import static org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY;
+
+/**
+ * The class representing an OVSDB Queue.
+ * This class is immutable.
+ */
+public final class OvsdbQueue {
+    private final Optional<Long> dscp;
+    private final Map<String, String> otherConfigs;
+    private final Map<String, String> externalIds;
+
+    /**
+     * Creates an OvsdbQueue using the given inputs.
+     *
+     * @param dscp the dscp of queue
+     * @param otherConfigs Key-value pairs for configuring rarely used features
+     * @param externalIds Key-value pairs for use by external frameworks, rather than by OVS itself
+     */
+    private OvsdbQueue(Optional<Long> dscp, Map<String, String> otherConfigs,
+                       Map<String, String> externalIds) {
+        this.dscp = dscp;
+        this.otherConfigs = otherConfigs;
+        this.externalIds = externalIds;
+    }
+
+    /**
+     * Returns the dscp of queue.
+     *
+     * @return the dscp
+     */
+    public Optional<Long> dscp() {
+        return dscp;
+    }
+
+    /**
+     * Returns other configurations of the queue.
+     *
+     * @return map of configurations
+     */
+    public Map<String, String> otherConfigs() {
+        return otherConfigs;
+    }
+
+    /**
+     * Returns the optional external ids.
+     *
+     * @return the external ids.
+     */
+    public Map<String, String> externalIds() {
+        return externalIds;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(dscp, otherConfigs, externalIds);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof OvsdbQueue) {
+            final OvsdbQueue other = (OvsdbQueue) obj;
+            return Objects.equals(this.dscp, other.dscp) &&
+                    Objects.equals(this.otherConfigs, other.otherConfigs) &&
+                    Objects.equals(this.externalIds, other.externalIds);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this)
+                .add("dscp", dscp())
+                .add("maxRate", otherConfigs())
+                .add("externalIds", externalIds())
+                .toString();
+    }
+
+    /**
+     * Returns new OVSDB queue builder.
+     *
+     * @return ovsdb queue builder
+     */
+    public static OvsdbQueue.Builder builder() {
+        return new OvsdbQueue.Builder();
+    }
+
+    /**
+     * Returns new OVSDB queue builder with queue description.
+     *
+     * @param queueDescription queue description
+     * @return ovsdb queue builder
+     */
+    public static Builder builder(QueueDescription queueDescription) {
+        return new Builder(queueDescription);
+    }
+
+    /**
+     * Builder of OVSDB queue entities.
+     */
+    public static final class Builder {
+        private Optional<Long> dscp = Optional.empty();
+        private Map<String, String> otherConfigs = Maps.newHashMap();
+        private Map<String, String> externalIds  = Maps.newHashMap();
+
+        /**
+         * Constructs an empty builder.
+         */
+        private Builder() {
+
+        }
+
+        /**
+         * Constructs a builder with a given queue description.
+         *
+         * @param queueDescription queue description
+         */
+        private Builder(QueueDescription queueDescription) {
+            if (queueDescription.maxRate().isPresent()) {
+                otherConfigs.put(MAX_RATE, String.valueOf((long) queueDescription.maxRate().get().bps()));
+            }
+            if (queueDescription.minRate().isPresent()) {
+                otherConfigs.put(MIN_RATE, String.valueOf((long) queueDescription.minRate().get().bps()));
+            }
+            if (queueDescription.burst().isPresent()) {
+                otherConfigs.put(BURST, queueDescription.burst().get().toString());
+            }
+            if (queueDescription.priority().isPresent()) {
+                otherConfigs.put(PRIORITY, queueDescription.priority().get().toString());
+            }
+            if (queueDescription.dscp().isPresent()) {
+                dscp = Optional.of(queueDescription.dscp().get().longValue());
+            }
+
+            externalIds.putAll(((DefaultAnnotations) queueDescription.annotations()).asMap());
+            externalIds.put(QUEUE_EXTERNAL_ID_KEY, queueDescription.queueId().name());
+        }
+
+        /**
+         * Returns new OVSDB queue.
+         *
+         * @return ovsdb queue
+         */
+        public OvsdbQueue build() {
+            return new OvsdbQueue(dscp, otherConfigs, externalIds);
+        }
+
+        /**
+         * Returns OVSDB queue builder with dscp.
+         *
+         * @param dscp dscp
+         * @return ovsdb queue builder
+         */
+        public Builder dscp(Long dscp) {
+            this.dscp = Optional.ofNullable(dscp);
+            return this;
+        }
+
+        /**
+         * Returns OVSDB queue builder with given configs.
+         *
+         * @param otherConfigs other configs
+         * @return ovsdb queue builder
+         */
+        public Builder otherConfigs(Map<String, String> otherConfigs) {
+            this.otherConfigs = Maps.newHashMap(otherConfigs);
+            return this;
+        }
+
+        /**
+         * Returns OVSDB queue builder with given external ids.
+         *
+         * @param ids the external ids
+         * @return ovsdb queue builder
+         */
+        public Builder externalIds(Map<String, String> ids) {
+            this.externalIds = ids;
+            return this;
+        }
+
+    }
+
+}
\ No newline at end of file
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 e8dbcb5..f60d48c 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
@@ -30,10 +30,13 @@
 
 import org.onlab.packet.IpAddress;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.BridgeDescription;
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.net.behaviour.MirroringStatistics;
 import org.onosproject.net.behaviour.MirroringName;
+import org.onosproject.net.behaviour.QosId;
+import org.onosproject.net.behaviour.QueueId;
 import org.onosproject.ovsdb.controller.OvsdbBridge;
 import org.onosproject.ovsdb.controller.OvsdbClientService;
 import org.onosproject.ovsdb.controller.OvsdbInterface;
@@ -43,6 +46,8 @@
 import org.onosproject.ovsdb.controller.OvsdbPort;
 import org.onosproject.ovsdb.controller.OvsdbPortName;
 import org.onosproject.ovsdb.controller.OvsdbPortNumber;
+import org.onosproject.ovsdb.controller.OvsdbQos;
+import org.onosproject.ovsdb.controller.OvsdbQueue;
 import org.onosproject.ovsdb.controller.OvsdbRowStore;
 import org.onosproject.ovsdb.controller.OvsdbStore;
 import org.onosproject.ovsdb.controller.OvsdbTableStore;
@@ -50,6 +55,7 @@
 import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
 import org.onosproject.ovsdb.rfc.message.OperationResult;
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
+import org.onosproject.ovsdb.rfc.notation.Column;
 import org.onosproject.ovsdb.rfc.notation.Condition;
 import org.onosproject.ovsdb.rfc.notation.Mutation;
 import org.onosproject.ovsdb.rfc.notation.OvsdbMap;
@@ -70,6 +76,8 @@
 import org.onosproject.ovsdb.rfc.table.Mirror;
 import org.onosproject.ovsdb.rfc.table.OvsdbTable;
 import org.onosproject.ovsdb.rfc.table.Port;
+import org.onosproject.ovsdb.rfc.table.Qos;
+import org.onosproject.ovsdb.rfc.table.Queue;
 import org.onosproject.ovsdb.rfc.table.TableGenerator;
 import org.onosproject.ovsdb.rfc.utils.ConditionUtil;
 import org.onosproject.ovsdb.rfc.utils.FromJsonUtil;
@@ -81,6 +89,7 @@
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -449,7 +458,7 @@
         String portUuid = getPortUuid(portName, bridgeUuid);
         if (portUuid != null) {
             log.info("Port {} delete", portName);
-            deleteConfig(PORT, UUID, portUuid, BRIDGE, PORTS);
+            deleteConfig(PORT, UUID, portUuid, BRIDGE, PORTS, Uuid.uuid(portUuid));
         }
     }
 
@@ -575,7 +584,7 @@
         }
 
         removeControllers.forEach(c -> deleteConfig(CONTROLLER, UUID, c.getRow().uuid().value(),
-                                                    BRIDGE, "controller"));
+                                                    BRIDGE, "controller", c.getRow().uuid()));
         newControllers.stream().map(c -> {
             Controller controller = (Controller) TableGenerator
                     .createTable(dbSchema, OvsdbTable.CONTROLLER);
@@ -612,9 +621,261 @@
             log.warn("Could not find bridge in node", nodeId.getIpAddress());
             return;
         }
-        deleteConfig(BRIDGE, UUID, bridgeUuid, DATABASENAME, BRIDGES);
+        deleteConfig(BRIDGE, UUID, bridgeUuid, DATABASENAME, BRIDGES, Uuid.uuid(bridgeUuid));
     }
 
+    @Override
+    public void applyQos(PortNumber portNumber, String qosName) {
+        DatabaseSchema dbSchema = schema.get(DATABASENAME);
+        OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
+        if (portRowStore == null) {
+            log.debug("The port uuid is null");
+            return;
+        }
+        OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
+        if (qosRowStore == null) {
+            log.debug("The qos uuid is null");
+            return;
+        }
+
+        // Due to Qos Table doesn't have a unique identifier except uuid, unlike
+        // Bridge or Port Table has a name column,in order to make the api more
+        // general, put qos name in external_ids column of Qos Table if this qos
+        // created by onos.
+        ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
+        ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
+        Row qosRow = qosTableRows.values().stream().filter(r -> {
+            OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
+            return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
+        }).findFirst().orElse(null);
+
+        Row portRow = portTableRows.values().stream()
+                .filter(r -> r.getColumn("name").data().equals(portNumber.name()))
+                .findFirst().orElse(null);
+        if (portRow != null && qosRow != null) {
+            String qosId = qosRow.uuid().value();
+            Uuid portUuid = portRow.uuid();
+            Map<String, Column> columns = new HashMap<>();
+            Row newPortRow = new Row(PORT, portUuid, columns);
+            Port newport = new Port(dbSchema, newPortRow);
+            columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
+            newport.setQos(Uuid.uuid(qosId));
+            updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
+        }
+    }
+
+    @Override
+    public void removeQos(PortNumber portNumber) {
+        DatabaseSchema dbSchema = schema.get(DATABASENAME);
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, PORT);
+        if (rowStore == null) {
+            log.debug("The qos uuid is null");
+            return;
+        }
+
+        ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore();
+        Row portRow = ovsTableRows.values().stream()
+                .filter(r -> r.getColumn("name").data().equals(portNumber.name()))
+                .findFirst().orElse(null);
+        if (portRow == null) {
+            log.warn("Couldn't find port {} in ovsdb port table.", portNumber.name());
+            return;
+        }
+
+        OvsdbSet ovsdbSet = ((OvsdbSet) portRow.getColumn(PORT_QOS).data());
+        @SuppressWarnings("unchecked")
+        Set<Uuid> qosIdSet = ovsdbSet.set();
+        if (qosIdSet == null || qosIdSet.isEmpty()) {
+            return;
+        }
+        Uuid qosUuid = (Uuid) qosIdSet.toArray()[0];
+        Condition condition = ConditionUtil.isEqual(UUID, portRow.uuid());
+        List<Condition> conditions = Lists.newArrayList(condition);
+        Mutation mutation = MutationUtil.delete(PORT_QOS, qosUuid);
+        List<Mutation> mutations = Lists.newArrayList(mutation);
+
+        ArrayList<Operation> operations = Lists.newArrayList();
+        Mutate mutate = new Mutate(dbSchema.getTableSchema(PORT), conditions, mutations);
+        operations.add(mutate);
+        transactConfig(DATABASENAME, operations);
+    }
+
+    @Override
+    public boolean createQos(OvsdbQos ovsdbQos) {
+        DatabaseSchema dbSchema = schema.get(DATABASENAME);
+        Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
+        if (rowStore == null) {
+            log.debug("The qos uuid is null");
+            return false;
+        }
+
+        ArrayList<Operation> operations = Lists.newArrayList();
+        Set<String> types = Sets.newHashSet();
+        Map<Long, Uuid> queues = Maps.newHashMap();
+
+        types.add(ovsdbQos.qosType());
+        qos.setOtherConfig(ovsdbQos.otherConfigs());
+        qos.setExternalIds(ovsdbQos.externalIds());
+        qos.setType(types);
+        if (ovsdbQos.qosQueues().isPresent()) {
+            for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
+                OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
+                if (queueRowStore != null) {
+                    ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
+                    Row queueRow = queueTableRows.values().stream().filter(r -> {
+                        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
+                        return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
+                    }).findFirst().orElse(null);
+                    if (queueRow != null) {
+                        queues.put(entry.getKey(), queueRow.uuid());
+                    }
+                }
+            }
+            qos.setQueues(queues);
+        }
+
+        Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
+        operations.add(qosInsert);
+        try {
+            transactConfig(DATABASENAME, operations).get();
+        } catch (InterruptedException | ExecutionException e) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public void dropQos(QosId qosId) {
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
+        if (rowStore != null) {
+            ConcurrentMap<String, Row> qosTableRows = rowStore.getRowStore();
+            Row qosRow = qosTableRows.values().stream().filter(r -> {
+                        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
+                        return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
+                    }).findFirst().orElse(null);
+            if (qosRow != null) {
+                deleteConfig(QOS, UUID, qosRow.uuid().value(), PORT, PORT_QOS, qosRow.uuid());
+            }
+        }
+    }
+    @Override
+    public OvsdbQos getQos(QosId qosId) {
+        Set<OvsdbQos> ovsdbQoses = getQoses();
+        return ovsdbQoses.stream().filter(r ->
+                qosId.name().equals(r.externalIds().get(QOS_EXTERNAL_ID_KEY))).
+                findFirst().orElse(null);
+    }
+
+    @Override
+    public Set<OvsdbQos> getQoses() {
+        Set<OvsdbQos> ovsdbQoses = new HashSet<>();
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
+        if (rowStore == null) {
+            log.debug("The qos uuid is null");
+            return ovsdbQoses;
+        }
+        ConcurrentMap<String, Row> rows = rowStore.getRowStore();
+        for (String uuid : rows.keySet()) {
+            Row row = getRow(DATABASENAME, QOS, uuid);
+            OvsdbQos ovsdbQos = getOvsdbQos(row);
+            if (ovsdbQos != null) {
+                ovsdbQoses.add(ovsdbQos);
+            }
+        }
+        return ovsdbQoses;
+    }
+
+    @Override
+    public boolean createQueue(OvsdbQueue ovsdbQueue) {
+        DatabaseSchema dbSchema = schema.get(DATABASENAME);
+        Queue queue = (Queue) TableGenerator.createTable(dbSchema, OvsdbTable.QUEUE);
+        ArrayList<Operation> operations = Lists.newArrayList();
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, QUEUE);
+        if (rowStore == null) {
+            log.debug("The queue uuid is null");
+            return false;
+        }
+
+        if (ovsdbQueue.dscp().isPresent()) {
+            queue.setDscp(ImmutableSet.of(ovsdbQueue.dscp().get()));
+        }
+        queue.setOtherConfig(ovsdbQueue.otherConfigs());
+        queue.setExternalIds(ovsdbQueue.externalIds());
+        Insert queueInsert = new Insert(dbSchema.getTableSchema(QUEUE), QUEUE, queue.getRow());
+        operations.add(queueInsert);
+
+        try {
+            transactConfig(DATABASENAME, operations).get();
+        } catch (InterruptedException | ExecutionException e) {
+            log.error("createQueue transactConfig get exception !");
+        }
+        return true;
+    }
+
+    @Override
+    public void dropQueue(QueueId queueId) {
+        OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
+        if (queueRowStore == null) {
+            return;
+        }
+
+        ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
+        Row queueRow = queueTableRows.values().stream().filter(r -> {
+            OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
+            return queueId.name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
+        }).findFirst().orElse(null);
+        if (queueRow == null) {
+            return;
+        }
+
+        String queueUuid = queueRow.uuid().value();
+        OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
+        if (qosRowStore != null) {
+            Map<Long, Uuid> queueMap = new HashMap<>();
+            ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
+            qosTableRows.values().stream().filter(r -> {
+                Map<Integer, Uuid> ovsdbMap = ((OvsdbMap) r.getColumn(QUEUES).data()).map();
+                Set<Integer> keySet = ovsdbMap.keySet();
+                for (Integer keyId : keySet) {
+                    if (ovsdbMap.get(keyId).equals(Uuid.uuid(queueUuid))) {
+                        queueMap.put(keyId.longValue(), Uuid.uuid(queueUuid));
+                        return true;
+                    }
+                }
+                return false;
+            }).findFirst().orElse(null);
+            deleteConfig(QUEUE, UUID, queueUuid, QOS, QUEUES, OvsdbMap.ovsdbMap(queueMap));
+        } else {
+            deleteConfig(QUEUE, UUID, queueUuid, null, null, null);
+        }
+    }
+    @Override
+    public OvsdbQueue getQueue(QueueId queueId) {
+        Set<OvsdbQueue> ovsdbQueues = getQueues();
+        return ovsdbQueues.stream().filter(r ->
+                queueId.name().equals(r.externalIds().get(QUEUE_EXTERNAL_ID_KEY))).
+                findFirst().orElse(null);
+    }
+
+    @Override
+    public Set<OvsdbQueue> getQueues() {
+        Set<OvsdbQueue> ovsdbqueues = new HashSet<>();
+        OvsdbRowStore rowStore = getRowStore(DATABASENAME, QUEUE);
+        if (rowStore == null) {
+            log.debug("The queue uuid is null");
+            return ovsdbqueues;
+        }
+        ConcurrentMap<String, Row> rows = rowStore.getRowStore();
+        for (String uuid : rows.keySet()) {
+            Row row = getRow(DATABASENAME, QUEUE, uuid);
+            OvsdbQueue ovsdbQueue = getOvsdbQueue(row);
+            if (ovsdbQueue != null) {
+                ovsdbqueues.add(ovsdbQueue);
+            }
+        }
+        return ovsdbqueues;
+    }
     /**
      * Creates a mirror port. Mirrors the traffic
      * that goes to selectDstPort or comes from
@@ -745,7 +1006,7 @@
         String mirrorUuid = getMirrorUuid(mirroringName.name());
         if (mirrorUuid != null) {
             log.info("Deleted mirror {}", mirroringName.name());
-            deleteConfig(MIRROR, UUID, mirrorUuid, BRIDGE, MIRRORS);
+            deleteConfig(MIRROR, UUID, mirrorUuid, BRIDGE, MIRRORS, Uuid.uuid(mirrorUuid));
         }
         log.warn("Unable to delete {}", mirroringName.name());
         return;
@@ -834,7 +1095,7 @@
 
         if (bridgeId.isPresent()) {
             String portId = getPortUuid(ifaceName, bridgeId.get());
-            deleteConfig(PORT, UUID, portId, BRIDGE, PORTS);
+            deleteConfig(PORT, UUID, portId, BRIDGE, PORTS, Uuid.uuid(portId));
             return true;
         } else {
             log.warn("Unable to find the interface with name {}", ifaceName);
@@ -850,26 +1111,25 @@
      * @param childUuid        child row uuid
      * @param parentTableName  parent table name
      * @param parentColumnName parent column
+     * @param referencedValue  referenced value
      */
     private void deleteConfig(String childTableName, String childColumnName,
                               String childUuid, String parentTableName,
-                              String parentColumnName) {
+                              String parentColumnName, Object referencedValue) {
         DatabaseSchema dbSchema = schema.get(DATABASENAME);
         TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);
 
         ArrayList<Operation> operations = Lists.newArrayList();
-        if (parentTableName != null && parentColumnName != null) {
+        if (parentTableName != null && parentColumnName != null && referencedValue != null) {
             TableSchema parentTableSchema = dbSchema
                     .getTableSchema(parentTableName);
             ColumnSchema parentColumnSchema = parentTableSchema
                     .getColumnSchema(parentColumnName);
             List<Mutation> mutations = Lists.newArrayList();
-            Mutation mutation = MutationUtil.delete(parentColumnSchema.name(),
-                                                    Uuid.uuid(childUuid));
+            Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), referencedValue);
             mutations.add(mutation);
             List<Condition> conditions = Lists.newArrayList();
-            Condition condition = ConditionUtil.includes(parentColumnName,
-                                                         Uuid.uuid(childUuid));
+            Condition condition = ConditionUtil.includes(parentColumnName, referencedValue);
             conditions.add(condition);
             Mutate op = new Mutate(parentTableSchema, conditions, mutations);
             operations.add(op);
@@ -1134,7 +1394,6 @@
         SettableFuture<List<JsonNode>> sf = SettableFuture.create();
         requestResult.put(id, sf);
         requestMethod.put(id, "transact");
-
         channel.writeAndFlush(transactString);
         return sf;
     }
@@ -1351,6 +1610,50 @@
         return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
     }
 
+    private OvsdbQos getOvsdbQos(Row row) {
+        DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
+        Qos qos = (Qos) TableGenerator.getTable(dbSchema, row, OvsdbTable.QOS);
+        if (qos == null) {
+            return null;
+        }
+
+        String type = (String) qos.getTypeColumn().data();
+        Map<String, String> otherConfigs;
+        Map<String, String> externalIds;
+        Map<Long, String> queues;
+
+        otherConfigs = ((OvsdbMap) qos.getOtherConfigColumn().data()).map();
+        externalIds  = ((OvsdbMap) qos.getExternalIdsColumn().data()).map();
+        queues = ((OvsdbMap) qos.getQueuesColumn().data()).map();
+        return OvsdbQos.builder().qosType(type).
+                queues(queues).otherConfigs(otherConfigs).
+                externalIds(externalIds).build();
+    }
+
+    private OvsdbQueue getOvsdbQueue(Row row) {
+        DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
+        Queue queue = (Queue) TableGenerator.getTable(dbSchema, row, OvsdbTable.QUEUE);
+        if (queue == null) {
+            return null;
+        }
+
+        OvsdbSet dscpOvsdbSet = ((OvsdbSet) queue.getDscpColumn().data());
+        @SuppressWarnings("unchecked")
+        Set<String> dscpSet = dscpOvsdbSet.set();
+        Long dscp = null;
+        if (dscpSet != null && !dscpSet.isEmpty()) {
+            dscp = Long.valueOf((String) dscpSet.toArray()[0]);
+        }
+
+        Map<String, String> otherConfigs;
+        Map<String, String> externalIds;
+
+        otherConfigs = ((OvsdbMap) queue.getOtherConfigColumn().data()).map();
+        externalIds  = ((OvsdbMap) queue.getExternalIdsColumn().data()).map();
+        return OvsdbQueue.builder().dscp(dscp).
+                otherConfigs(otherConfigs).externalIds(externalIds).build();
+    }
+
     private long getOfPort(Interface intf) {
         OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
         @SuppressWarnings("unchecked")
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 e4cad7d..f6982d6 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
@@ -21,15 +21,20 @@
 
 import org.onlab.packet.IpAddress;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.ControllerInfo;
 import org.onosproject.net.behaviour.MirroringStatistics;
 import org.onosproject.net.behaviour.MirroringName;
+import org.onosproject.net.behaviour.QosId;
+import org.onosproject.net.behaviour.QueueId;
 import org.onosproject.ovsdb.controller.OvsdbBridge;
 import org.onosproject.ovsdb.controller.OvsdbClientService;
 import org.onosproject.ovsdb.controller.OvsdbInterface;
 import org.onosproject.ovsdb.controller.OvsdbMirror;
 import org.onosproject.ovsdb.controller.OvsdbNodeId;
 import org.onosproject.ovsdb.controller.OvsdbPort;
+import org.onosproject.ovsdb.controller.OvsdbQos;
+import org.onosproject.ovsdb.controller.OvsdbQueue;
 import org.onosproject.ovsdb.rfc.message.TableUpdates;
 import org.onosproject.ovsdb.rfc.notation.Row;
 import org.onosproject.ovsdb.rfc.operations.Operation;
@@ -86,7 +91,52 @@
         return null;
     }
 
+    @Override
+    public void applyQos(PortNumber portNumber, String qosId) {
 
+    }
+
+    @Override
+    public void removeQos(PortNumber portNumber) {
+    }
+
+    @Override
+    public boolean createQos(OvsdbQos ovsdbQos) {
+        return false;
+    }
+
+    @Override
+    public void dropQos(QosId qosId) {
+    }
+
+    @Override
+    public OvsdbQos getQos(QosId qosId) {
+        return null;
+    };
+
+    @Override
+    public Set<OvsdbQos> getQoses() {
+      return null;
+    }
+
+    @Override
+    public boolean createQueue(OvsdbQueue queue) {
+        return false;
+    }
+
+    @Override
+    public void dropQueue(QueueId queueId) {
+    }
+
+    @Override
+    public OvsdbQueue getQueue(QueueId queueId) {
+        return null;
+    };
+
+    @Override
+    public Set<OvsdbQueue> getQueues() {
+        return null;
+    }
     /**
      * Drops the configuration for mirror.
      *
diff --git a/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Port.java b/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Port.java
index 3ff33e9..60ccdb5 100644
--- a/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Port.java
+++ b/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/table/Port.java
@@ -237,9 +237,25 @@
      * Add a Column entity which column name is "qos" to the Row entity of
      * attributes.
      * @param qos the column data which column name is "qos"
+     * @deprecated in Junco (1.9.1), use version with Uuid instead
      */
+    @Deprecated
     public void setQos(Set<Uuid> qos) {
         ColumnDescription columndesc = new ColumnDescription(
+                PortColumn.QOS
+                        .columnName(),
+                "setQos",
+                VersionNum.VERSION100);
+        super.setDataHandler(columndesc, qos);
+    }
+
+    /**
+     * Add a Column entity which column name is "qos" to the Row entity of
+     * attributes.
+     * @param qos the column data which column name is "qos"
+     */
+    public void setQos(Uuid qos) {
+        ColumnDescription columndesc = new ColumnDescription(
                                                              PortColumn.QOS
                                                                      .columnName(),
                                                              "setQos",