[ovs-dev] [PATCH 1/4] ofproto/xlate: Add xlate_lookup_ofproto().

Jarno Rajahalme jrajahalme at nicira.com
Fri Aug 22 22:06:47 UTC 2014


On Aug 22, 2014, at 11:15 AM, Ben Pfaff <blp at nicira.com> wrote:

> On Fri, Aug 15, 2014 at 04:38:46PM -0700, Jarno Rajahalme wrote:
>> "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>
> 
> I think that with some small adjustments, xlate_receive() could call
> xlate_lookup_ofproto() and avoid a small amount of duplicated code.

We can’t expose the locally defined xport outside, so we need a new local helper. I’ll fold in the following and push soon.

  Jarno

diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 51e1fc1..0ea5830 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -946,15 +946,13 @@ xlate_lookup_xport(const struct dpif_backer *backer, const struct flow *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)
+static struct ofproto_dpif *
+xlate_lookup_ofproto_(const struct dpif_backer *backer, const struct flow *flow,
+                      ofp_port_t *ofp_in_port, const struct xport **xportp)
 {
     const struct xport *xport;
 
-    xport = xlate_lookup_xport(backer, flow);
+    *xportp = xport = xlate_lookup_xport(backer, flow);
 
     if (xport) {
         if (ofp_in_port) {
@@ -966,36 +964,48 @@ xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
     return NULL;
 }
 
+/* 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;
+
+    return xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
+}
+
 /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
  * 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.
  *
- * '*fp_in_port' is set to OFPP_NONE if 'flow''s in_port does not exist.
+ * '*ofp_in_port' is set to OFPP_NONE if 'flow''s in_port does not exist.
  *
  * 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 ofproto_dpif **ofprotop, struct dpif_ipfix **ipfix,
               struct dpif_sflow **sflow, struct netflow **netflow,
               ofp_port_t *ofp_in_port)
 {
+    struct ofproto_dpif *ofproto;
     const struct xport *xport;
 
-    xport = xlate_lookup_xport(backer, flow);
+    ofproto = xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
 
-    if (ofp_in_port) {
-        *ofp_in_port = xport ? xport->ofp_port : OFPP_NONE;
+    if (ofp_in_port && !xport) {
+        *ofp_in_port = OFPP_NONE;
     }
 
     if (!xport) {
         return ENODEV;
     }
 
-    if (ofproto) {
-        *ofproto = xport->xbridge->ofproto;
+    if (ofprotop) {
+        *ofprotop = ofproto;
     }
 
     if (ipfix) {

> 
> Acked-by: Ben Pfaff <blp at nicira.com>




More information about the dev mailing list