[ovs-dev] [PATCH] flow: New function hash_ofp_port() and hash_ofp_port().
Ethan Jackson
ethan at nicira.com
Mon Jun 24 20:59:09 UTC 2013
These functions are used so often, that having an easy to read
helper is worth it.
Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
lib/flow.h | 12 ++++++++++++
lib/learning-switch.c | 4 ++--
ofproto/ofproto-dpif-sflow.c | 7 +++----
ofproto/ofproto-dpif.c | 9 ++++-----
ofproto/ofproto.c | 5 ++---
ofproto/pinsched.c | 2 +-
vswitchd/bridge.c | 5 ++---
7 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/lib/flow.h b/lib/flow.h
index a020937..9a6e937 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -213,6 +213,18 @@ u32_to_ofp11(uint32_t port)
return OFP11_PORT_C(port);
}
+static inline uint32_t
+hash_ofp_port(ofp_port_t ofp_port)
+{
+ return hash_int(ofp_to_u16(ofp_port), 0);
+}
+
+static inline uint32_t
+hash_odp_port(odp_port_t odp_port)
+{
+ return hash_int(odp_to_u32(odp_port), 0);
+}
+
uint32_t flow_hash_in_minimask(const struct flow *, const struct minimask *,
uint32_t basis);
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index e786913..426cb37 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -460,7 +460,7 @@ process_switch_features(struct lswitch *sw, struct ofp_header *oh)
if (lp && hmap_node_is_null(&lp->hmap_node)) {
lp->port_no = port.port_no;
hmap_insert(&sw->queue_numbers, &lp->hmap_node,
- hash_int(ofp_to_u16(lp->port_no), 0));
+ hash_ofp_port(lp->port_no));
}
}
return 0;
@@ -517,7 +517,7 @@ get_queue_id(const struct lswitch *sw, ofp_port_t in_port)
{
const struct lswitch_port *port;
- HMAP_FOR_EACH_WITH_HASH (port, hmap_node, hash_int(ofp_to_u16(in_port), 0),
+ HMAP_FOR_EACH_WITH_HASH (port, hmap_node, hash_ofp_port(in_port),
&sw->queue_numbers) {
if (port->port_no == in_port) {
return port->queue_id;
diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c
index 5d53ee0..ee31f88 100644
--- a/ofproto/ofproto-dpif-sflow.c
+++ b/ofproto/ofproto-dpif-sflow.c
@@ -146,9 +146,8 @@ dpif_sflow_find_port(const struct dpif_sflow *ds, odp_port_t odp_port)
{
struct dpif_sflow_port *dsp;
- HMAP_FOR_EACH_IN_BUCKET (dsp, hmap_node,
- hash_int(odp_to_u32(odp_port), 0),
- &ds->ports) {
+ HMAP_FOR_EACH_IN_BUCKET (dsp, hmap_node, hash_odp_port(odp_port),
+ &ds->ports) {
if (dsp->odp_port == odp_port) {
return dsp;
}
@@ -363,7 +362,7 @@ dpif_sflow_add_port(struct dpif_sflow *ds, struct ofport *ofport,
dsp->ofport = ofport;
dsp->odp_port = odp_port;
SFL_DS_SET(dsp->dsi, SFL_DSCLASS_IFINDEX, ifindex, 0);
- hmap_insert(&ds->ports, &dsp->hmap_node, hash_int(odp_to_u32(odp_port), 0));
+ hmap_insert(&ds->ports, &dsp->hmap_node, hash_odp_port(odp_port));
/* Add poller. */
if (ds->sflow_agent) {
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 31cb69b..ebe2099 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1495,7 +1495,7 @@ port_construct(struct ofport *port_)
}
hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
- hash_int(odp_to_u32(port->odp_port), 0));
+ hash_odp_port(port->odp_port));
}
dpif_port_destroy(&dpif_port);
@@ -6293,7 +6293,7 @@ vlandev_find(const struct ofproto_dpif *ofproto, ofp_port_t vlandev_ofp_port)
struct vlan_splinter *vsp;
HMAP_FOR_EACH_WITH_HASH (vsp, vlandev_node,
- hash_int(ofp_to_u16(vlandev_ofp_port), 0),
+ hash_ofp_port(vlandev_ofp_port),
&ofproto->vlandev_map) {
if (vsp->vlandev_ofp_port == vlandev_ofp_port) {
return vsp;
@@ -6384,7 +6384,7 @@ vsp_add(struct ofport_dpif *port, ofp_port_t realdev_ofp_port, int vid)
vsp = xmalloc(sizeof *vsp);
hmap_insert(&ofproto->vlandev_map, &vsp->vlandev_node,
- hash_int(ofp_to_u16(port->up.ofp_port), 0));
+ hash_ofp_port(port->up.ofp_port));
hmap_insert(&ofproto->realdev_vid_map, &vsp->realdev_vid_node,
hash_realdev_vid(realdev_ofp_port, vid));
vsp->realdev_ofp_port = realdev_ofp_port;
@@ -6409,8 +6409,7 @@ odp_port_to_ofport(const struct dpif_backer *backer, odp_port_t odp_port)
{
struct ofport_dpif *port;
- HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node,
- hash_int(odp_to_u32(odp_port), 0),
+ HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node, hash_odp_port(odp_port),
&backer->odp_to_ofport_map) {
if (port->odp_port == odp_port) {
return port;
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index afd8e17..5e6a252 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1813,7 +1813,7 @@ ofport_install(struct ofproto *p,
/* Add port to 'p'. */
hmap_insert(&p->ports, &ofport->hmap_node,
- hash_int(ofp_to_u16(ofport->ofp_port), 0));
+ hash_ofp_port(ofport->ofp_port));
shash_add(&p->port_by_name, netdev_name, ofport);
update_mtu(p, ofport);
@@ -1937,8 +1937,7 @@ ofproto_get_port(const struct ofproto *ofproto, ofp_port_t ofp_port)
{
struct ofport *port;
- HMAP_FOR_EACH_IN_BUCKET (port, hmap_node,
- hash_int(ofp_to_u16(ofp_port), 0),
+ HMAP_FOR_EACH_IN_BUCKET (port, hmap_node, hash_ofp_port(ofp_port),
&ofproto->ports) {
if (port->ofp_port == ofp_port) {
return port;
diff --git a/ofproto/pinsched.c b/ofproto/pinsched.c
index 4c5f3e8..91e9c41 100644
--- a/ofproto/pinsched.c
+++ b/ofproto/pinsched.c
@@ -104,7 +104,7 @@ pinqueue_destroy(struct pinsched *ps, struct pinqueue *q)
static struct pinqueue *
pinqueue_get(struct pinsched *ps, ofp_port_t port_no)
{
- uint32_t hash = hash_int(ofp_to_u16(port_no), 0);
+ uint32_t hash = hash_ofp_port(port_no);
struct pinqueue *q;
HMAP_FOR_EACH_IN_BUCKET (q, node, hash, &ps->queues) {
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 6f573df..abae7f5 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -1285,7 +1285,7 @@ iface_set_ofp_port(struct iface *iface, ofp_port_t ofp_port)
ovs_assert(iface->ofp_port == OFPP_NONE && ofp_port != OFPP_NONE);
iface->ofp_port = ofp_port;
hmap_insert(&br->ifaces, &iface->ofp_port_node,
- hash_int(ofp_to_u16(ofp_port), 0));
+ hash_ofp_port(ofp_port));
iface_set_ofport(iface->cfg, ofp_port);
}
@@ -3485,8 +3485,7 @@ iface_from_ofp_port(const struct bridge *br, ofp_port_t ofp_port)
{
struct iface *iface;
- HMAP_FOR_EACH_IN_BUCKET (iface, ofp_port_node,
- hash_int(ofp_to_u16(ofp_port), 0),
+ HMAP_FOR_EACH_IN_BUCKET (iface, ofp_port_node, hash_ofp_port(ofp_port),
&br->ifaces) {
if (iface->ofp_port == ofp_port) {
return iface;
--
1.7.9.5
More information about the dev
mailing list