[ONOS-5565]Implementation of QosConfig and QueueConfig
Change-Id: I6a367b53cfca2e85e8aaa6cddb541d7b3ffccbc0
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQosDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQosDescription.java
new file mode 100644
index 0000000..39bd548
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQosDescription.java
@@ -0,0 +1,180 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.AbstractDescription;
+import org.onosproject.net.SparseAnnotations;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+
+/**
+ * Default implementation of Qos description entity.
+ */
+@Beta
+public final class DefaultQosDescription extends AbstractDescription
+ implements QosDescription {
+
+ private final QosId qosId;
+ private final Type type;
+ private final Optional<Bandwidth> maxRate;
+ private final Optional<Long> cir;
+ private final Optional<Long> cbs;
+ private final Optional<Map<Long, QueueDescription>> queues;
+
+ private DefaultQosDescription(QosId qosId, Type type, Optional<Bandwidth> maxRate,
+ Optional<Long> cir, Optional<Long> cbs,
+ Optional<Map<Long, QueueDescription>> queues,
+ SparseAnnotations... annotations) {
+ super(annotations);
+ this.qosId = checkNotNull(qosId);
+ this.type = checkNotNull(type);
+ this.maxRate = maxRate;
+ this.cir = cir;
+ this.cbs = cbs;
+ this.queues = queues;
+ }
+
+ @Override
+ public QosId qosId() {
+ return qosId;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public Optional<Bandwidth> maxRate() {
+ return maxRate;
+ }
+
+ @Override
+ public Optional<Long> cir() {
+ return cir;
+ }
+
+ @Override
+ public Optional<Long> cbs() {
+ return cbs;
+ }
+
+ @Override
+ public Optional<Map<Long, QueueDescription>> queues() {
+ return queues;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(qosId, type, maxRate, cir, cbs, queues);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultQosDescription) {
+ final DefaultQosDescription other = (DefaultQosDescription) obj;
+ return Objects.equals(this.qosId, other.qosId) &&
+ Objects.equals(this.type, other.type) &&
+ Objects.equals(this.maxRate, other.maxRate) &&
+ Objects.equals(this.cir, other.cir) &&
+ Objects.equals(this.cbs, other.cbs) &&
+ Objects.equals(this.queues, other.queues);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("qosId", qosId())
+ .add("type", type())
+ .add("maxRate", maxRate().orElse(null))
+ .add("cir", cir().orElse(0L))
+ .add("cbs", cbs().orElse(0L))
+ .add("queues", queues().orElse(null))
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements QosDescription.Builder {
+
+ private QosId qosId;
+ private Type type;
+ private Optional<Bandwidth> maxRate = Optional.empty();
+ private Optional<Long> cir = Optional.empty();
+ private Optional<Long> cbs = Optional.empty();
+ private Optional<Map<Long, QueueDescription>> queues = Optional.empty();
+
+ private Builder() {
+ }
+
+ @Override
+ public QosDescription build() {
+ return new DefaultQosDescription(qosId, type, maxRate, cir, cbs, queues);
+ }
+
+ @Override
+ public Builder qosId(QosId qosId) {
+ this.qosId = qosId;
+ return this;
+ }
+
+ @Override
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public Builder maxRate(Bandwidth maxRate) {
+ this.maxRate = Optional.ofNullable(maxRate);
+ return this;
+ }
+
+ @Override
+ public Builder cir(Long cir) {
+ this.cir = Optional.ofNullable(cir);
+ return this;
+ }
+
+ @Override
+ public Builder cbs(Long cbs) {
+ this.cbs = Optional.ofNullable(cbs);
+ return this;
+ }
+
+ @Override
+ public Builder queues(Map<Long, QueueDescription> queues) {
+ this.queues = Optional.ofNullable(queues);
+ return this;
+ }
+ }
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQueueDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQueueDescription.java
new file mode 100644
index 0000000..400c2a5
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/DefaultQueueDescription.java
@@ -0,0 +1,202 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.AbstractDescription;
+import org.onosproject.net.SparseAnnotations;
+
+import java.util.EnumSet;
+import java.util.Objects;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default implementation of Queue description entity.
+ */
+@Beta
+public final class DefaultQueueDescription extends AbstractDescription
+ implements QueueDescription {
+
+ private final QueueId queueId;
+ private final Optional<Integer> dscp;
+ private final EnumSet<Type> type;
+ private final Optional<Bandwidth> maxRate;
+ private final Optional<Bandwidth> minRate;
+ private final Optional<Long> burst;
+ private final Optional<Long> priority;
+
+ public static final int MIN_DSCP = 0;
+ public static final int MAX_DSCP = 63;
+
+ private DefaultQueueDescription(QueueId queueId, Optional<Integer> dscp, EnumSet<Type> type,
+ Optional<Bandwidth> maxRate, Optional<Bandwidth> minRate,
+ Optional<Long> burst, Optional<Long> priority,
+ SparseAnnotations... annotations) {
+ super(annotations);
+ if (dscp.isPresent()) {
+ checkArgument(dscp.get() < MIN_DSCP || dscp.get() > MAX_DSCP, "dscp should be in range 0 to 63.");
+ }
+ this.queueId = checkNotNull(queueId);
+ this.dscp = dscp;
+ this.type = type;
+ this.maxRate = maxRate;
+ this.minRate = minRate;
+ this.burst = burst;
+ this.priority = priority;
+ }
+
+ @Override
+ public QueueId queueId() {
+ return queueId;
+ }
+
+ @Override
+ public EnumSet<Type> type() {
+ return type;
+ }
+
+ @Override
+ public Optional<Integer> dscp() {
+ return dscp;
+ }
+
+ @Override
+ public Optional<Bandwidth> maxRate() {
+ return maxRate;
+ }
+
+ @Override
+ public Optional<Bandwidth> minRate() {
+ return minRate;
+ }
+
+ @Override
+ public Optional<Long> burst() {
+ return burst;
+ }
+
+ @Override
+ public Optional<Long> priority() {
+ return priority;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(queueId, type, dscp, maxRate, minRate, burst, priority);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof DefaultQueueDescription) {
+ final DefaultQueueDescription other = (DefaultQueueDescription) obj;
+ return Objects.equals(this.queueId, other.queueId) &&
+ Objects.equals(this.type, other.type) &&
+ Objects.equals(this.dscp, other.dscp) &&
+ Objects.equals(this.maxRate, other.maxRate) &&
+ Objects.equals(this.minRate, other.minRate) &&
+ Objects.equals(this.burst, other.burst) &&
+ Objects.equals(this.priority, other.priority);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("name", queueId())
+ .add("type", type())
+ .add("dscp", dscp().orElse(0))
+ .add("maxRate", maxRate().orElse(null))
+ .add("minRate", minRate().orElse(null))
+ .add("burst", burst().orElse(0L))
+ .add("priority", priority().orElse(0L))
+ .toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements QueueDescription.Builder {
+
+ private QueueId queueId;
+ private Optional<Integer> dscp = Optional.empty();
+ private EnumSet<Type> type;
+ private Optional<Bandwidth> minRate = Optional.empty();
+ private Optional<Bandwidth> maxRate = Optional.empty();
+ private Optional<Long> burst = Optional.empty();
+ private Optional<Long> priority = Optional.empty();
+
+ private Builder() {
+ }
+
+ @Override
+ public QueueDescription build() {
+ return new DefaultQueueDescription(queueId, dscp, type,
+ maxRate, minRate, burst, priority);
+ }
+
+ @Override
+ public Builder queueId(QueueId queueId) {
+ this.queueId = queueId;
+ return this;
+ }
+
+ @Override
+ public Builder dscp(Integer dscp) {
+ this.dscp = Optional.ofNullable(dscp);
+ return this;
+ }
+
+ @Override
+ public Builder type(EnumSet<Type> type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public Builder maxRate(Bandwidth maxRate) {
+ this.maxRate = Optional.ofNullable(maxRate);
+ return this;
+ }
+
+ @Override
+ public Builder minRate(Bandwidth minRate) {
+ this.minRate = Optional.ofNullable(minRate);
+ return this;
+ }
+
+ @Override
+ public Builder burst(Long burst) {
+ this.burst = Optional.ofNullable(burst);
+ return this;
+ }
+
+ @Override
+ public Builder priority(Long priority) {
+ this.priority = Optional.ofNullable(priority);
+ return this;
+ }
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/PortConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/PortConfig.java
index e14d336..35130e8 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/PortConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/PortConfig.java
@@ -21,7 +21,9 @@
/**
* Means to configure a logical port at the device.
+ * @deprecated in Junco (1.9.1), use PortConfigBehaviour instead
*/
+@Deprecated
public interface PortConfig extends HandlerBehaviour {
/**
@@ -37,4 +39,4 @@
*/
void removeQoS(PortDescription port);
-}
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/PortConfigBehaviour.java b/core/api/src/main/java/org/onosproject/net/behaviour/PortConfigBehaviour.java
new file mode 100644
index 0000000..ebf11da
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/PortConfigBehaviour.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015-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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+/**
+ * Means to configure a logical port at the device.
+ */
+@Beta
+public interface PortConfigBehaviour extends HandlerBehaviour {
+
+ /**
+ * Apply QoS configuration on a device.
+ * @param port a port description
+ * @param qosDesc qos description
+ */
+ void applyQoS(PortDescription port, QosDescription qosDesc);
+
+ /**
+ * Remove a QoS configuration.
+ * @param portNumber port identifier
+ */
+ void removeQoS(PortNumber portNumber);
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QosConfigBehaviour.java b/core/api/src/main/java/org/onosproject/net/behaviour/QosConfigBehaviour.java
new file mode 100644
index 0000000..178ff92
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QosConfigBehaviour.java
@@ -0,0 +1,54 @@
+/*
+ * 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.net.behaviour;
+import com.google.common.annotations.Beta;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.Collection;
+
+/**
+ * Behaviour for handling various operations for qos configurations.
+ */
+@Beta
+public interface QosConfigBehaviour extends HandlerBehaviour {
+
+ /**
+ * Obtain all qoses configured on a device.
+ *
+ * @return a set of qos descriptions
+ */
+ Collection<QosDescription> getQoses();
+
+ /**
+ * Obtain a qos configured on a device.
+ * @param qosDesc qos description
+ * @return a qos description
+ */
+ QosDescription getQos(QosDescription qosDesc);
+
+ /**
+ * create QoS configuration on a device.
+ * @param qosDesc qos description
+ * @return true if succeeds, or false
+ */
+ boolean addQoS(QosDescription qosDesc);
+
+ /**
+ * Delete a QoS configuration.
+ * @param qosId qos identifier
+ */
+ void deleteQoS(QosId qosId);
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QosDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/QosDescription.java
new file mode 100644
index 0000000..53e34d0
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QosDescription.java
@@ -0,0 +1,174 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.Description;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Default implementation of immutable Qos description.
+ */
+@Beta
+public interface QosDescription extends Description, Annotated {
+
+ /**
+ * Denotes the type of the Qos.
+ */
+ enum Type {
+ /**
+ * Corresponds to Hierarchy token bucket classifier.
+ */
+ HTB,
+
+ /**
+ * Corresponds to Hierarchical Fair Service Curve classifier.
+ */
+ HFSC,
+
+ /**
+ * Corresponds to Stochastic Fairness Queueing classifier.
+ */
+ SFQ,
+
+ /**
+ * Corresponds to Controlled Delay classifier classifier.
+ */
+ CODEL,
+
+ /**
+ * Corresponds to Fair Queuing with Controlled Delay classifier.
+ */
+ FQ_CODEL,
+
+ /**
+ * No operation.
+ */
+ NOOP,
+
+ /**
+ * DPDK egress policer.
+ */
+ EGRESS_POLICER
+ }
+
+ /**
+ * Returns qos identifier.
+ *
+ * @return qos identifier
+ */
+ QosId qosId();
+
+ /**
+ * Returns qos type.
+ *
+ * @return qos type
+ */
+ Type type();
+
+ /**
+ * Returns the max rate of qos, Valid only in specific qos type.
+ *
+ * @return Maximum rate shared by all queued traffic, in bit/s.
+ */
+ Optional<Bandwidth> maxRate();
+
+ /**
+ * Returns Committed Information Rate of Qos, Valid only in specific qos type.
+ * the CIR is measured in bytes of IP packets per second.
+ *
+ * @return cir
+ */
+ Optional<Long> cir();
+
+ /**
+ * Returns Committed Burst Size of Qos, Valid only in specific qos type.
+ * the CBS is measured in bytes and represents a token bucket.
+ *
+ * @return cbs
+ */
+ Optional<Long> cbs();
+
+ /**
+ * Returns map of integer-Queue pairs, Valid only in specific qos type.
+ *
+ * @return queues
+ */
+ Optional<Map<Long, QueueDescription>> queues();
+
+ /**
+ * Builder of qos description entities.
+ */
+ interface Builder {
+ /**
+ * Returns qos description builder with a given name.
+ *
+ * @param qosId qos identifier
+ * @return bridge description builder
+ */
+ Builder qosId(QosId qosId);
+
+ /**
+ * Returns qos description builder with a given type.
+ *
+ * @param type qos type
+ * @return bridge description builder
+ */
+ Builder type(Type type);
+
+ /**
+ * Returns qos description builder with given maxRate.
+ *
+ * @param maxRate qos max rate
+ * @return qos description builder
+ */
+ Builder maxRate(Bandwidth maxRate);
+
+ /**
+ * Returns qos description builder with a given cir.
+ * @param cir in bytes of IP packets per second
+ * @return qos description builder
+ */
+ Builder cir(Long cir);
+
+ /**
+ * Returns qos description builder with a given cbs.
+ *
+ * @param cbs in bytes and represents a token bucket
+ * @return qos description builder
+ */
+ Builder cbs(Long cbs);
+
+ /**
+ * Returns qos description builder with a given queues.
+ *
+ * @param queues the map from queue numbers to Queue records
+ * @return qos description builder
+ */
+ Builder queues(Map<Long, QueueDescription> queues);
+
+ /**
+ * Builds an immutable qos description.
+ *
+ * @return qos description
+ */
+ QosDescription build();
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QosId.java b/core/api/src/main/java/org/onosproject/net/behaviour/QosId.java
new file mode 100644
index 0000000..db98970
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QosId.java
@@ -0,0 +1,65 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Immutable representation of a Qos identity.
+ */
+@Beta
+public final class QosId {
+
+ private final String name;
+
+ private QosId(String name) {
+ this.name = checkNotNull(name);
+ }
+
+ public static QosId qosId(String name) {
+ return new QosId(name);
+ }
+
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QosId) {
+ final QosId that = (QosId) obj;
+ return this.getClass() == that.getClass() &&
+ Objects.equals(this.name, that.name);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfig.java
index 1a44110..d5f6aaa 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfig.java
@@ -21,7 +21,9 @@
/**
* Means to alter a device's dataplane queues.
+ * @deprecated in Junco (1.9.1), use QueueConfigBehaviour instead
*/
+@Deprecated
public interface QueueConfig {
/**
@@ -53,4 +55,4 @@
*/
void removeQueue(UnsignedInteger queueId);
-}
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfigBehaviour.java b/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfigBehaviour.java
new file mode 100644
index 0000000..4a48ce2
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QueueConfigBehaviour.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2015-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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.Collection;
+
+/**
+ * Behaviour for handling various operations for queue configurations.
+ */
+@Beta
+public interface QueueConfigBehaviour extends HandlerBehaviour {
+
+ /**
+ * Obtain all queues configured on a device.
+ *
+ * @return a list of queue descriptions
+ */
+ Collection<QueueDescription> getQueues();
+
+ /**
+ * Obtain a queue configured on a device.
+ * @param queueDesc queue description
+ * @return a queue description
+ */
+ QueueDescription getQueue(QueueDescription queueDesc);
+
+ /**
+ * Create a queue to a device.
+ * @param queueDesc a queue description
+ * @return true if succeeds, or false
+ */
+ boolean addQueue(QueueDescription queueDesc);
+
+ /**
+ * Delete a queue from a device.
+ * @param queueId queue identifier
+ */
+ void deleteQueue(QueueId queueId);
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QueueDescription.java b/core/api/src/main/java/org/onosproject/net/behaviour/QueueDescription.java
new file mode 100644
index 0000000..43cb0a0
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QueueDescription.java
@@ -0,0 +1,172 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.Annotated;
+import org.onosproject.net.Description;
+
+import java.util.EnumSet;
+import java.util.Optional;
+
+/**
+ * Default implementation of immutable Queue description.
+ */
+@Beta
+public interface QueueDescription extends Description, Annotated {
+
+ /**
+ * Denotes the type of the Queue.
+ */
+ enum Type {
+ /**
+ * Support min rate.
+ */
+ MIN,
+
+ /**
+ * Support max rate.
+ */
+ MAX,
+
+ /**
+ * Support priority.
+ */
+ PRIORITY,
+
+ /**
+ * Support burst.
+ */
+ BURST
+ }
+
+ /**
+ * Returns queue identifier.
+ *
+ * @return queue identifier
+ */
+ QueueId queueId();
+
+ /**
+ * Returns dscp in range 0 to 63.
+ *
+ * @return dscp
+ */
+ Optional<Integer> dscp();
+
+ /**
+ * Returns type.
+ *
+ * @return type
+ */
+ EnumSet<Type> type();
+
+ /**
+ * Returns max rate, Valid only in specific type.
+ *
+ * @return Maximum allowed bandwidth, in bit/s.
+ */
+ Optional<Bandwidth> maxRate();
+
+ /**
+ * Returns min rate, Valid only in specific type.
+ *
+ * @return Minimum guaranteed bandwidth, in bit/s.
+ */
+ Optional<Bandwidth> minRate();
+
+ /**
+ * Returns burst, Valid only in specific type.
+ *
+ * @return Burst size, in bits
+ */
+ Optional<Long> burst();
+
+ /**
+ * Returns priority, Valid only in specific type.
+ * small number have higher priority, in range 0 to 0xFFFFFFFF
+ * @return priority
+ */
+ Optional<Long> priority();
+
+
+
+ interface Builder {
+
+ /**
+ * Returns queue description builder with given name.
+ *
+ * @param queueId queue identifier
+ * @return queue description builder
+ */
+ Builder queueId(QueueId queueId);
+
+ /**
+ * Returns queue description builder with given dscp.
+ *
+ * @param dscp dscp
+ * @return queue description builder
+ */
+ Builder dscp(Integer dscp);
+
+ /**
+ * Returns queue description builder with given type.
+ *
+ * @param type type
+ * @return queue description builder
+ */
+ Builder type(EnumSet<Type> type);
+
+ /**
+ * Returns queue description builder with max rate.
+ * @param maxRate Maximum allowed bandwidth
+ * @return queue description builder
+ */
+ Builder maxRate(Bandwidth maxRate);
+
+ /**
+ * Returns queue description builder with a given min rate.
+ *
+ * @param minRate Minimum guaranteed bandwidth
+ * @return queue description builder
+ */
+ Builder minRate(Bandwidth minRate);
+
+ /**
+ * Returns queue description builder with a given burst.
+ *
+ * @param burst burst size
+ * @return queue description builder
+ */
+ Builder burst(Long burst);
+
+ /**
+ * Returns queue description builder with a given priority.
+ * small number have higher priority, in range 0 to 0xFFFFFFFF
+ * @param priority priority
+ * @return queue description builder
+ */
+ Builder priority(Long priority);
+
+ /**
+ * Builds an immutable bridge description.
+ *
+ * @return queue description
+ */
+ QueueDescription build();
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QueueId.java b/core/api/src/main/java/org/onosproject/net/behaviour/QueueId.java
new file mode 100644
index 0000000..61e5dfd
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QueueId.java
@@ -0,0 +1,64 @@
+/*
+ * 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.net.behaviour;
+
+import com.google.common.annotations.Beta;
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Immutable representation of a Queue identity.
+ */
+@Beta
+public final class QueueId {
+ private final String name;
+
+ private QueueId(String name) {
+ this.name = checkNotNull(name);
+ }
+
+ public static QueueId queueId(String name) {
+ return new QueueId(name);
+ }
+
+ public String name() {
+ return name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof QueueId) {
+ final QueueId that = (QueueId) obj;
+ return this.getClass() == that.getClass() &&
+ Objects.equals(this.name, that.name);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/QueueInfo.java b/core/api/src/main/java/org/onosproject/net/behaviour/QueueInfo.java
index 116ac7c..7758896 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/QueueInfo.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/QueueInfo.java
@@ -18,8 +18,10 @@
import com.google.common.primitives.UnsignedInteger;
/**
- * Represents a dataplane queue.
+ * @deprecated in Junco Release (1.9.1), Use QueueDescription instead
+ * {@link org.onosproject.net.behaviour.QueueDescription}
*/
+@Deprecated
public class QueueInfo {
public enum Type {
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbPortConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbPortConfig.java
new file mode 100644
index 0000000..0c08e6b
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbPortConfig.java
@@ -0,0 +1,77 @@
+/*
+ * 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.drivers.ovsdb;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.PortConfigBehaviour;
+import org.onosproject.net.behaviour.QosDescription;
+import org.onosproject.net.device.PortDescription;
+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.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * OVSDB-based implementation of port config behaviour.
+ */
+public class OvsdbPortConfig extends AbstractHandlerBehaviour implements PortConfigBehaviour {
+
+ private final Logger log = getLogger(getClass());
+
+ @Override
+ public void applyQoS(PortDescription portDesc, QosDescription qosDesc) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return;
+ }
+ ovsdbClient.applyQos(portDesc.portNumber(), qosDesc.qosId().name());
+ }
+
+ @Override
+ public void removeQoS(PortNumber portNumber) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return;
+ }
+ ovsdbClient.removeQos(portNumber);
+ }
+
+ // 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.length < 1) {
+ return null;
+ }
+ IpAddress ipAddress = IpAddress.valueOf(splits[1]);
+ return new OvsdbNodeId(ipAddress, 0);
+ }
+
+ private OvsdbClientService getOvsdbClient(DriverHandler handler) {
+ OvsdbController ovsController = handler.get(OvsdbController.class);
+ OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId());
+
+ return ovsController.getOvsdbClient(nodeId);
+ }
+}
+
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQosConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQosConfig.java
new file mode 100644
index 0000000..00fcb80
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQosConfig.java
@@ -0,0 +1,138 @@
+/*
+ * 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.drivers.ovsdb;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.DefaultQosDescription;
+import org.onosproject.net.behaviour.QosConfigBehaviour;
+import org.onosproject.net.behaviour.QosDescription;
+import org.onosproject.net.behaviour.QosId;
+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.OvsdbQos;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+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;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * OVSDB-based implementation of qos config behaviour.
+ */
+public class OvsdbQosConfig extends AbstractHandlerBehaviour implements QosConfigBehaviour {
+
+ private final Logger log = getLogger(getClass());
+
+ @Override
+ public Collection<QosDescription> getQoses() {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return null;
+ }
+ Set<OvsdbQos> qoses = ovsdbClient.getQoses();
+
+ return qoses.stream()
+ .map(qos -> DefaultQosDescription.builder()
+ .qosId(QosId.qosId(qos.externalIds().get(QOS_EXTERNAL_ID_KEY)))
+ .type(QOS_EGRESS_POLICER.equals(qos.qosType()) ?
+ QosDescription.Type.EGRESS_POLICER :
+ QosDescription.Type.valueOf(qos.qosType()
+ .replace(QOS_TYPE_PREFIX, "")
+ .toUpperCase()))
+ .maxRate(qos.otherConfigs().get(MAX_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(qos.otherConfigs().get(MAX_RATE))) :
+ Bandwidth.bps(0L))
+ .cbs(qos.otherConfigs().get(CBS) != null ?
+ Long.valueOf(qos.otherConfigs().get(CBS)) : null)
+ .cir(qos.otherConfigs().get(CIR) != null ?
+ Long.valueOf(qos.otherConfigs().get(CIR)) : null)
+ .build())
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public QosDescription getQos(QosDescription qosDesc) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return null;
+ }
+ OvsdbQos qos = ovsdbClient.getQos(qosDesc.qosId());
+ if (qos == null) {
+ return null;
+ }
+ return DefaultQosDescription.builder()
+ .qosId(QosId.qosId(qos.externalIds().get(QOS_EXTERNAL_ID_KEY)))
+ .type(QOS_EGRESS_POLICER.equals(qos.qosType()) ?
+ QosDescription.Type.EGRESS_POLICER :
+ QosDescription.Type.valueOf(qos.qosType()
+ .replace(QOS_TYPE_PREFIX, "")
+ .toUpperCase()))
+ .maxRate(qos.otherConfigs().get(MAX_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(qos.otherConfigs().get(MAX_RATE))) :
+ Bandwidth.bps(0L))
+ .cbs(qos.otherConfigs().get(CBS) != null ?
+ Long.valueOf(qos.otherConfigs().get(CBS)) : null)
+ .cir(qos.otherConfigs().get(CIR) != null ?
+ Long.valueOf(qos.otherConfigs().get(CIR)) : null)
+ .build();
+ }
+
+ @Override
+ public boolean addQoS(QosDescription qos) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ OvsdbQos ovsdbQos = OvsdbQos.builder(qos).build();
+ return ovsdbClient.createQos(ovsdbQos);
+ }
+
+ @Override
+ public void deleteQoS(QosId qosId) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ ovsdbClient.dropQos(qosId);
+ }
+
+ // 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.length < 1) {
+ return null;
+ }
+ IpAddress ipAddress = IpAddress.valueOf(splits[1]);
+ return new OvsdbNodeId(ipAddress, 0);
+ }
+
+ private OvsdbClientService getOvsdbClient(DriverHandler handler) {
+ OvsdbController ovsController = handler.get(OvsdbController.class);
+ OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId());
+
+ return ovsController.getOvsdbClient(nodeId);
+ }
+}
+
diff --git a/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQueueConfig.java b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQueueConfig.java
new file mode 100644
index 0000000..79ed4fc
--- /dev/null
+++ b/drivers/ovsdb/src/main/java/org/onosproject/drivers/ovsdb/OvsdbQueueConfig.java
@@ -0,0 +1,161 @@
+/*
+ * 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.drivers.ovsdb;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.DefaultQueueDescription;
+import org.onosproject.net.behaviour.QueueConfigBehaviour;
+import org.onosproject.net.behaviour.QueueDescription;
+import org.onosproject.net.behaviour.QueueDescription.Type;
+import org.onosproject.net.behaviour.QueueId;
+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.OvsdbQueue;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+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;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * OVSDB-based implementation of queue config behaviour.
+ */
+public class OvsdbQueueConfig extends AbstractHandlerBehaviour implements QueueConfigBehaviour {
+
+ private final Logger log = getLogger(getClass());
+
+ @Override
+ public Collection<QueueDescription> getQueues() {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return Collections.emptyList();
+ }
+
+ Set<OvsdbQueue> queues = ovsdbClient.getQueues();
+ return queues.stream()
+ .map(q -> DefaultQueueDescription.builder()
+ .queueId(QueueId.queueId(q.externalIds().get(QUEUE_EXTERNAL_ID_KEY)))
+ .type(types(q))
+ .dscp(q.dscp().isPresent() ? q.dscp().get().intValue() : null)
+ .maxRate(q.otherConfigs().get(MAX_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(q.otherConfigs().get(MAX_RATE))) :
+ Bandwidth.bps(0L))
+ .minRate(q.otherConfigs().get(MIN_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(q.otherConfigs().get(MIN_RATE))) :
+ Bandwidth.bps(0L))
+ .burst(q.otherConfigs().get(BURST) != null ?
+ Long.valueOf(q.otherConfigs().get(BURST)) : 0L)
+ .priority(q.otherConfigs().get(PRIORITY) != null ?
+ Long.valueOf(q.otherConfigs().get(PRIORITY)) : 0L)
+ .build())
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public QueueDescription getQueue(QueueDescription queueDesc) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ if (ovsdbClient == null) {
+ return null;
+ }
+
+ OvsdbQueue queue = ovsdbClient.getQueue(queueDesc.queueId());
+ if (queue == null) {
+ return null;
+ }
+ return DefaultQueueDescription.builder()
+ .queueId(QueueId.queueId(queue.externalIds().get(QUEUE_EXTERNAL_ID_KEY)))
+ .type(types(queue))
+ .dscp(queue.dscp().isPresent() ? queue.dscp().get().intValue() : null)
+ .maxRate(queue.otherConfigs().get(MAX_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(queue.otherConfigs().get(MAX_RATE))) :
+ Bandwidth.bps(0L))
+ .minRate(queue.otherConfigs().get(MIN_RATE) != null ?
+ Bandwidth.bps(Long.parseLong(queue.otherConfigs().get(MIN_RATE))) :
+ Bandwidth.bps(0L))
+ .burst(queue.otherConfigs().get(BURST) != null ?
+ Long.valueOf(queue.otherConfigs().get(BURST)) : 0L)
+ .priority(queue.otherConfigs().get(PRIORITY) != null ?
+ Long.valueOf(queue.otherConfigs().get(PRIORITY)) : 0L)
+ .build();
+ }
+
+ @Override
+ public boolean addQueue(QueueDescription queue) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ OvsdbQueue ovsdbQueue = OvsdbQueue.builder(queue).build();
+ return ovsdbClient.createQueue(ovsdbQueue);
+ }
+
+ @Override
+ public void deleteQueue(QueueId queueId) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(handler());
+ ovsdbClient.dropQueue(queueId);
+ }
+
+ private EnumSet<Type> types(OvsdbQueue queue) {
+ EnumSet<Type> enumSet = EnumSet.noneOf(Type.class);
+ if (queue == null) {
+ return enumSet;
+ }
+
+ if (queue.otherConfigs().get(MAX_RATE) != null) {
+ enumSet.add(Type.MAX);
+ }
+ if (queue.otherConfigs().get(MIN_RATE) != null) {
+ enumSet.add(Type.MIN);
+ }
+ if (queue.otherConfigs().get(BURST) != null) {
+ enumSet.add(Type.BURST);
+ }
+ if (queue.otherConfigs().get(PRIORITY) != null) {
+ enumSet.add(Type.PRIORITY);
+ }
+ return enumSet;
+ }
+
+ // 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.length < 1) {
+ return null;
+ }
+ IpAddress ipAddress = IpAddress.valueOf(splits[1]);
+ return new OvsdbNodeId(ipAddress, 0);
+ }
+
+ private OvsdbClientService getOvsdbClient(DriverHandler handler) {
+ OvsdbController ovsController = handler.get(OvsdbController.class);
+ OvsdbNodeId nodeId = changeDeviceIdToNodeId(handler.data().deviceId());
+
+ return ovsController.getOvsdbClient(nodeId);
+ }
+}
\ 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
index 15d7d5f..bb00f22 100644
--- a/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
+++ b/drivers/ovsdb/src/main/resources/ovsdb-drivers.xml
@@ -23,6 +23,8 @@
impl="org.onosproject.drivers.ovsdb.OvsdbBridgeConfig"/>
<behaviour api="org.onosproject.net.behaviour.InterfaceConfig"
impl="org.onosproject.drivers.ovsdb.OvsdbInterfaceConfig"/>
+ <behaviour api="org.onosproject.net.behaviour.PortConfigBehaviour"
+ impl="org.onosproject.drivers.ovsdb.OvsdbPortConfig"/>
</driver>
<driver name="ovs" extends="default"
manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">
@@ -30,6 +32,10 @@
impl="org.onosproject.drivers.ovsdb.OvsdbControllerConfig"/>
<behaviour api="org.onosproject.net.behaviour.MirroringConfig"
impl="org.onosproject.drivers.ovsdb.OvsdbMirroringConfig"/>
+ <behaviour api="org.onosproject.net.behaviour.QosConfigBehaviour"
+ impl="org.onosproject.drivers.ovsdb.OvsdbQosConfig"/>
+ <behaviour api="org.onosproject.net.behaviour.QueueConfigBehaviour"
+ impl="org.onosproject.drivers.ovsdb.OvsdbQueueConfig"/>
</driver>
</drivers>
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",