From e7066039a80886bbaf6484504e636ba13f677234 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 10 Mar 2009 14:04:16 -0700 Subject: [PATCH] vswitch: Work in terms of ODP port numbers. The vswitch used to be an OpenFlow client, so all of its internals were in terms of OpenFlow port numbering. When it was converted to be a datapath client instead, a shim layer that converted between OpenFlow and ODP port numbering was inserted, so that it could still work internally in terms of OpenFlow port numbers. This commit makes the vswitch use ODP port numbering internally, removing this shim layer. --- vswitchd/bridge.c | 62 ++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 2aac3126..dc75e868 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -980,8 +980,7 @@ bridge_fetch_dp_ifaces(struct bridge *br) VLOG_WARN("dp%u reported interface %"PRIu16" twice", dpif_id(&br->dpif), p->port); } else { - uint16_t ofp_port = p->port == ODPP_LOCAL ? OFPP_LOCAL : p->port; - port_array_set(&br->ifaces, ofp_port, iface); + port_array_set(&br->ifaces, p->port, iface); iface->dp_ifidx = p->port; } } @@ -1325,6 +1324,7 @@ compose_dsts(const struct bridge *br, const flow_t *flow, uint16_t vlan, *tags |= in_port->stp_state_tag; if (out_port == FLOOD_PORT) { /* XXX use OFPP_FLOOD if no vlans or bonding. */ + /* XXX even better, define each VLAN as a datapath port group */ for (i = 0; i < br->n_ports; i++) { struct port *port = br->ports[i]; if (port != in_port && port_includes_vlan(port, vlan) @@ -1400,16 +1400,10 @@ send_packets(struct bridge *br, const flow_t *flow, struct ft_dst dsts[DP_MAX_PORTS * (MAX_MIRRORS + 1)]; size_t actions_len; /* Estimated length of actions, in bytes. */ size_t n_dsts; - flow_t odp_flow; n_dsts = compose_dsts(br, flow, vlan, in_port, out_port, dsts, &tags); actions_len = (sizeof(struct ofp_action_header) + 2) * n_dsts; - /* XXX for now everything in bridge.c is still in terms of OFP ports. In - * the long term we should change that (and avoid this awkward copy). */ - odp_flow = *flow; - odp_flow.in_port = ofp_port_to_odp_port(odp_flow.in_port); - if (setup_flow) { enum { NO_OP, ADD_FLOW, SET_ACTIONS } command; struct ft_flow *f; @@ -1448,7 +1442,7 @@ send_packets(struct bridge *br, const flow_t *flow, n_actions = abuf.size / sizeof(union ofp_action); if (command == ADD_FLOW) { - ofproto_add_flow(br->ofproto, &odp_flow, 0, UINT16_MAX, + ofproto_add_flow(br->ofproto, flow, 0, UINT16_MAX, abuf.data, n_actions, pkt, bridge_idle_time(br)); pkt = NULL; /* Already sent. */ @@ -1456,8 +1450,7 @@ send_packets(struct bridge *br, const flow_t *flow, /* ofproto_add_flow() will reset the byte counters. */ f->last_byte_count = f->byte_count = 0; } else { - ofproto_set_actions(br->ofproto, &odp_flow, abuf.data, - n_actions); + ofproto_set_actions(br->ofproto, flow, abuf.data, n_actions); } ofpbuf_uninit(&abuf); } @@ -1475,7 +1468,7 @@ send_packets(struct bridge *br, const flow_t *flow, ofpbuf_init(&abuf, actions_len); put_actions(dsts, n_dsts, ntohs(flow->dl_vlan), &abuf); - ofproto_send_packet(br->ofproto, &odp_flow, + ofproto_send_packet(br->ofproto, flow, abuf.data, abuf.size / sizeof(union ofp_action), pkt); ofpbuf_uninit(&abuf); @@ -1518,17 +1511,11 @@ process_flow(struct bridge *br, const flow_t *flow, const struct ofpbuf *pkt) * one of our bridge ports. */ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); - flow_t odp_flow; VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown " "interface %"PRIu16, br->name, flow->in_port); - /* XXX for now everything in bridge.c is still in terms of OFP - * ports. In the long term we should change that (and avoid this - * awkward copy). */ - odp_flow = *flow; - odp_flow.in_port = ofp_port_to_odp_port(odp_flow.in_port); - ofproto_add_flow(br->ofproto, &odp_flow, 0, UINT16_MAX, + ofproto_add_flow(br->ofproto, flow, 0, UINT16_MAX, NULL, 0, NULL, bridge_idle_time(br)); if (f) { ftf_set_dsts(f, NULL, 0); @@ -1546,16 +1533,9 @@ process_flow(struct bridge *br, const flow_t *flow, const struct ofpbuf *pkt) /* We're revalidating, not receiving a fresh packet. Most likely, * this interface existed and has now been deleted from the * datapath. Drop the flow. */ - flow_t odp_flow; - assert(f); - /* XXX for now everything in bridge.c is still in terms of OFP - * ports. In the long term we should change that (and avoid this - * awkward copy). */ - odp_flow = *flow; - odp_flow.in_port = ofp_port_to_odp_port(odp_flow.in_port); - ofproto_delete_flow(br->ofproto, &odp_flow, 0, UINT16_MAX); + ofproto_delete_flow(br->ofproto, flow, 0, UINT16_MAX); /* ofproto_delete_flow() better not call back to * bridge_flow_expired_ofhook_cb(). */ @@ -1728,7 +1708,7 @@ bridge_port_changed_ofhook_cb(enum ofp_port_reason reason, struct iface *iface; struct port *port; - iface = iface_from_dp_ifidx(br, opp->port_no); + iface = iface_from_dp_ifidx(br, ofp_port_to_odp_port(opp->port_no)); if (!iface) { return; } @@ -1756,33 +1736,27 @@ bridge_port_changed_ofhook_cb(enum ofp_port_reason reason, } static bool -bridge_packet_in_ofhook_cb(const flow_t *flow_, const struct ofpbuf *payload, +bridge_packet_in_ofhook_cb(const flow_t *flow, const struct ofpbuf *payload, void *br_) { struct bridge *br = br_; struct ft_flow *f; - flow_t flow; - - /* XXX for now everything in bridge.c is still in terms of OFP ports. In - * the long term we should change that (and avoid this awkward copy). */ - flow = *flow_; - flow.in_port = odp_port_to_ofp_port(flow.in_port); /* Delete any existing flow from the flow tracker. The flow cannot really * be in the flow table (otherwise we wouldn't be getting called). */ - f = ft_lookup(br->ft, &flow, flow_hash(&flow, 0)); + f = ft_lookup(br->ft, flow, flow_hash(flow, 0)); if (f) { ft_remove(br->ft, f); ftf_destroy(f); } - if (flow.dl_type == htons(OFP_DL_TYPE_NOT_ETH_TYPE) - && eth_addr_equals(flow.dl_dst, stp_eth_addr)) { - brstp_receive(br, &flow, payload); + if (flow->dl_type == htons(OFP_DL_TYPE_NOT_ETH_TYPE) + && eth_addr_equals(flow->dl_dst, stp_eth_addr)) { + brstp_receive(br, flow, payload); return true; } - process_flow(br, &flow, payload); + process_flow(br, flow, payload); return true; } @@ -1792,14 +1766,8 @@ bridge_flow_expired_ofhook_cb(const struct ofexpired *expired, void *br_) { struct bridge *br = br_; struct ft_flow *f; - flow_t flow; - - /* XXX for now everything in bridge.c is still in terms of OFP ports. In - * the long term we should change that (and avoid this awkward copy). */ - flow = expired->flow; - flow.in_port = odp_port_to_ofp_port(flow.in_port); - f = ft_lookup(br->ft, &flow, flow_hash(&flow, 0)); + f = ft_lookup(br->ft, &expired->flow, flow_hash(&expired->flow, 0)); if (f) { /* Update statistics. */ f->last_byte_count = f->byte_count; -- 2.30.2