/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <stdlib.h>
#include "flow.h"
#include "hash.h"
-#include "hmap.h"
-#include "ofpbuf.h"
+#include "openvswitch/hmap.h"
+#include "openvswitch/ofpbuf.h"
#include "openflow/openflow.h"
#include "poll-loop.h"
#include "random.h"
#include "rconn.h"
#include "sat-math.h"
#include "timeval.h"
-#include "token-bucket.h"
-#include "vconn.h"
+#include "openvswitch/token-bucket.h"
+#include "openvswitch/vconn.h"
struct pinqueue {
struct hmap_node node; /* In struct pinsched's 'queues' hmap. */
- ofp_port_t port_no; /* Port number. */
- struct list packets; /* Contains "struct ofpbuf"s. */
+ ofp_port_t port_no; /* Port number. */
+ struct ovs_list packets; /* Contains "struct ofpbuf"s. */
int n; /* Number of packets in 'packets'. */
};
static struct ofpbuf *
dequeue_packet(struct pinsched *ps, struct pinqueue *q)
{
- struct ofpbuf *packet = ofpbuf_from_list(list_pop_front(&q->packets));
+ struct ofpbuf *packet = ofpbuf_from_list(ovs_list_pop_front(&q->packets));
q->n--;
ps->n_queued--;
return packet;
q = xmalloc(sizeof *q);
hmap_insert(&ps->queues, &q->node, hash);
q->port_no = port_no;
- list_init(&q->packets);
+ ovs_list_init(&q->packets);
q->n = 0;
return q;
}
void
pinsched_send(struct pinsched *ps, ofp_port_t port_no,
- struct ofpbuf *packet, struct list *txq)
+ struct ofpbuf *packet, struct ovs_list *txq)
{
- list_init(txq);
+ ovs_list_init(txq);
if (!ps) {
- list_push_back(txq, &packet->list_node);
+ ovs_list_push_back(txq, &packet->list_node);
} else if (!ps->n_queued && get_token(ps)) {
/* In the common case where we are not constrained by the rate limit,
* let the packet take the normal path. */
ps->n_normal++;
- list_push_back(txq, &packet->list_node);
+ ovs_list_push_back(txq, &packet->list_node);
} else {
/* Otherwise queue it up for the periodic callback to drain out. */
- struct pinqueue *q;
-
- /* We might be called with a buffer obtained from dpif_recv() that has
- * much more allocated space than actual content most of the time.
- * Since we're going to store the packet for some time, free up that
- * otherwise wasted space. */
- ofpbuf_trim(packet);
-
if (ps->n_queued * 1000 >= ps->token_bucket.burst) {
drop_packet(ps);
}
- q = pinqueue_get(ps, port_no);
- list_push_back(&q->packets, &packet->list_node);
+
+ struct pinqueue *q = pinqueue_get(ps, port_no);
+ ovs_list_push_back(&q->packets, &packet->list_node);
q->n++;
ps->n_queued++;
ps->n_limited++;
}
void
-pinsched_run(struct pinsched *ps, struct list *txq)
+pinsched_run(struct pinsched *ps, struct ovs_list *txq)
{
- list_init(txq);
+ ovs_list_init(txq);
if (ps) {
int i;
* number of iterations to allow other code to get work done too. */
for (i = 0; ps->n_queued && get_token(ps) && i < 50; i++) {
struct ofpbuf *packet = get_tx_packet(ps);
- list_push_back(txq, &packet->list_node);
+ ovs_list_push_back(txq, &packet->list_node);
}
}
}
pinsched_destroy(struct pinsched *ps)
{
if (ps) {
- struct pinqueue *q, *next;
+ struct pinqueue *q;
- HMAP_FOR_EACH_SAFE (q, next, node, &ps->queues) {
- hmap_remove(&ps->queues, &q->node);
+ HMAP_FOR_EACH_POP (q, node, &ps->queues) {
ofpbuf_list_delete(&q->packets);
free(q);
}