+static struct priority_to_dscp *
+get_priority(const struct ofport_dpif *ofport, uint32_t priority)
+{
+ struct priority_to_dscp *pdscp;
+ uint32_t hash;
+
+ hash = hash_int(priority, 0);
+ HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &ofport->priorities) {
+ if (pdscp->priority == priority) {
+ return pdscp;
+ }
+ }
+ return NULL;
+}
+
+static void
+ofport_clear_priorities(struct ofport_dpif *ofport)
+{
+ struct priority_to_dscp *pdscp, *next;
+
+ HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &ofport->priorities) {
+ hmap_remove(&ofport->priorities, &pdscp->hmap_node);
+ free(pdscp);
+ }
+}
+
+static int
+set_queues(struct ofport *ofport_,
+ const struct ofproto_port_queue *qdscp_list,
+ size_t n_qdscp)
+{
+ struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
+ struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
+ struct hmap new = HMAP_INITIALIZER(&new);
+ size_t i;
+
+ for (i = 0; i < n_qdscp; i++) {
+ struct priority_to_dscp *pdscp;
+ uint32_t priority;
+ uint8_t dscp;
+
+ dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
+ if (dpif_queue_to_priority(ofproto->dpif, qdscp_list[i].queue,
+ &priority)) {
+ continue;
+ }
+
+ pdscp = get_priority(ofport, priority);
+ if (pdscp) {
+ hmap_remove(&ofport->priorities, &pdscp->hmap_node);
+ } else {
+ pdscp = xmalloc(sizeof *pdscp);
+ pdscp->priority = priority;
+ pdscp->dscp = dscp;
+ ofproto->need_revalidate = true;
+ }
+
+ if (pdscp->dscp != dscp) {
+ pdscp->dscp = dscp;
+ ofproto->need_revalidate = true;
+ }
+
+ hmap_insert(&new, &pdscp->hmap_node, hash_int(pdscp->priority, 0));
+ }
+
+ if (!hmap_is_empty(&ofport->priorities)) {
+ ofport_clear_priorities(ofport);
+ ofproto->need_revalidate = true;
+ }
+
+ hmap_swap(&new, &ofport->priorities);
+ hmap_destroy(&new);
+
+ return 0;
+}
+\f