From: Ethan Jackson Date: Sat, 22 Jun 2013 17:33:27 +0000 (-0700) Subject: flow: New function hash_ofp_port() and hash_ofp_port(). X-Git-Tag: sliver-openvswitch-1.10.90-3~6^2~60 X-Git-Url: http://git.onelab.eu/?p=sliver-openvswitch.git;a=commitdiff_plain;h=f9c0c3eccdb8e14dc8fbf572e515dbef1eb7b2ee flow: New function hash_ofp_port() and hash_ofp_port(). These functions are used so often, that having an easy to read helper is worth it. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- diff --git a/lib/flow.h b/lib/flow.h index a02093773..9a6e93781 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 e786913c6..426cb375c 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 5d53ee08e..ee31f8887 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 2eaec8214..2fff66ecd 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1500,7 +1500,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); @@ -6557,7 +6557,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; @@ -6648,7 +6648,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; @@ -6673,8 +6673,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 afd8e170c..5e6a25258 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 4c5f3e836..91e9c411c 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 6f573df89..abae7f581 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;