[ovs-dev] [PATCH 1/4] ofproto/xlate: Add xlate_lookup_ofproto().
Jarno Rajahalme
jrajahalme at nicira.com
Fri Aug 15 23:38:46 UTC 2014
"xlate_receive" did not tell much about what it is used for. We have
two users of it that only want the ofproto and the OF port number, use the
new xlate_lookup_ofproto() for those.
Fix the comments of xlate_receive() as we no longer change the flow.
Also, the helper ofproto_dpif_contains_flow() seemed ill-named, so this
path removes it and uses xlate_lookup_ofproto() directly.
Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
ofproto/ofproto-dpif-xlate.c | 50 +++++++++++++++++++++++++++++++-----------
ofproto/ofproto-dpif-xlate.h | 3 +++
ofproto/ofproto-dpif.c | 28 ++++++-----------------
3 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index b4ad649..b3a8183 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -934,33 +934,57 @@ xlate_ofport_remove(struct ofport_dpif *ofport)
xlate_xport_remove(new_xcfg, xport);
}
+/* Given a datapath and flow metadata ('backer', and 'flow' respectively)
+ * returns the corresponding struct xport, or NULL if none is found. */
+static struct xport *
+xlate_lookup_xport(const struct dpif_backer *backer, const struct flow *flow)
+{
+ struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
+
+ return xport_lookup(xcfg, tnl_port_should_receive(flow)
+ ? tnl_port_receive(flow)
+ : odp_port_to_ofport(backer, flow->in_port.odp_port));
+}
+
+/* Given a datapath and flow metadata ('backer', and 'flow' respectively)
+ * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
+struct ofproto_dpif *
+xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
+ ofp_port_t *ofp_in_port)
+{
+ const struct xport *xport;
+
+ xport = xlate_lookup_xport(backer, flow);
+
+ if (xport) {
+ if (ofp_in_port) {
+ *ofp_in_port = xport->ofp_port;
+ }
+ return xport->xbridge->ofproto;
+ }
+
+ return NULL;
+}
+
/* Given a datapath and flow metadata ('backer', and 'flow' respectively),
- * Optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
+ * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
* openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
* handles for those protocols if they're enabled. Caller is responsible for
* unrefing them.
*
- * If 'ofproto' is nonnull, requires 'flow''s in_port to exist. Otherwise sets
- * 'flow''s in_port to OFPP_NONE.
+ * '*fp_in_port' is set to OFPP_NONE if 'flow''s in_port does not exist.
*
- * Similarly, this function also includes some logic to help with tunnels. It
- * may modify 'flow' as necessary to make the tunneling implementation
- * transparent to the upcall processing logic.
- *
- * Returns 0 if successful, ENODEV if the parsed flow has no associated ofport,
- * or some other positive errno if there are other problems. */
+ * Returns 0 if successful, ENODEV if the parsed flow has no associated ofport.
+ */
int
xlate_receive(const struct dpif_backer *backer, const struct flow *flow,
struct ofproto_dpif **ofproto, struct dpif_ipfix **ipfix,
struct dpif_sflow **sflow, struct netflow **netflow,
ofp_port_t *ofp_in_port)
{
- struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
const struct xport *xport;
- xport = xport_lookup(xcfg, tnl_port_should_receive(flow)
- ? tnl_port_receive(flow)
- : odp_port_to_ofport(backer, flow->in_port.odp_port));
+ xport = xlate_lookup_xport(backer, flow);
if (ofp_in_port) {
*ofp_in_port = xport ? xport->ofp_port : OFPP_NONE;
diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h
index 7394249..1864980 100644
--- a/ofproto/ofproto-dpif-xlate.h
+++ b/ofproto/ofproto-dpif-xlate.h
@@ -173,6 +173,9 @@ void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
bool may_enable);
void xlate_ofport_remove(struct ofport_dpif *);
+struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
+ const struct flow *,
+ ofp_port_t *ofp_in_port);
int xlate_receive(const struct dpif_backer *, const struct flow *,
struct ofproto_dpif **, struct dpif_ipfix **,
struct dpif_sflow **, struct netflow **,
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 7cf85f7..6b38825 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -4192,8 +4192,9 @@ parse_flow_and_packet(int argc, const char *argv[],
goto exit;
}
- if (xlate_receive(backer, flow, ofprotop, NULL, NULL, NULL,
- &flow->in_port.ofp_port)) {
+ *ofprotop = xlate_lookup_ofproto(backer, flow,
+ &flow->in_port.ofp_port);
+ if (*ofprotop == NULL) {
error = "Invalid datapath flow";
goto exit;
}
@@ -4574,24 +4575,6 @@ ofproto_unixctl_dpif_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
ds_destroy(&ds);
}
-static bool
-ofproto_dpif_contains_flow(const struct ofproto_dpif *ofproto,
- const struct nlattr *key, size_t key_len)
-{
- struct ofproto_dpif *ofp;
- struct flow flow;
-
- if (odp_flow_key_to_flow(key, key_len, &flow) == ODP_FIT_ERROR) {
- return false;
- }
-
- if (xlate_receive(ofproto->backer, &flow, &ofp, NULL, NULL, NULL, NULL)) {
- return false;
- }
-
- return ofp == ofproto;
-}
-
static void
ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
int argc OVS_UNUSED, const char *argv[],
@@ -4630,7 +4613,10 @@ ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
flow_dump = dpif_flow_dump_create(ofproto->backer->dpif);
flow_dump_thread = dpif_flow_dump_thread_create(flow_dump);
while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) {
- if (!ofproto_dpif_contains_flow(ofproto, f.key, f.key_len)) {
+ struct flow flow;
+
+ if (odp_flow_key_to_flow(f.key, f.key_len, &flow) == ODP_FIT_ERROR
+ || xlate_lookup_ofproto(ofproto->backer, &flow, NULL) != ofproto) {
continue;
}
--
1.7.10.4
More information about the dev
mailing list