[ovs-dev] [PATCH v4 1/7] userspace: Add packet_type in dp_packet and flow

Ben Pfaff blp at ovn.org
Wed May 3 23:57:02 UTC 2017


On Tue, Apr 25, 2017 at 04:29:59PM +0000, Zoltán Balogh wrote:
> From: Jan Scheurich <jan.scheurich at ericsson.com>
> 
> This commit adds a packet_type attribute to the structs dp_packet and flow
> to explicitly carry the type of the packet as prepration for the
> introduction of the so-called packet type-aware pipeline (PTAP) in OVS.
> 
> The packet_type is a big-endian 32 bit integer with the encoding as
> specified in OpenFlow verion 1.5.
> 
> The upper 16 bits contain the packet type name space. Pre-defined values
> are defined in openflow-common.h:
> 
> enum ofp_header_type_namespaces {
>     OFPHTN_ONF = 0,             /* ONF namespace. */
>     OFPHTN_ETHERTYPE = 1,       /* ns_type is an Ethertype. */
>     OFPHTN_IP_PROTO = 2,        /* ns_type is a IP protocol number. */
>     OFPHTN_UDP_TCP_PORT = 3,    /* ns_type is a TCP or UDP port. */
>     OFPHTN_IPV4_OPTION = 4,     /* ns_type is an IPv4 option number. */
> };
> 
> The lower 16 bits specify the actual type in the context of the name space.
> 
> Only name spaces 0 and 1 will be supported for now.
> 
> For name space OFPHTN_ONF the relevant packet type is 0 (Ethernet).
> This is the default packet_type in OVS and the only one supported so far.
> Packets of type (OFPHTN_ONF, 0) are called Ethernet packets.
> 
> In name space OFPHTN_ETHERTYPE the type is the Ethertype of the packet.
> A packet of type (OFPHTN_ETHERTYPE, <Ethertype>) is a standard L2 packet
> whith the Ethernet header (and any VLAN tags) removed to expose the L3
> (or L2.5) payload of the packet. These will simply be called L3 packets.
> 
> The Ethernet address fields dl_src and dl_dst in struct flow are not
> applicable for an L3 packet and must be zero. However, to maintain
> compatibility with the large code base, we have chosen to copy the
> Ethertype of an L3 packet into the the dl_type field of struct flow.
> 
> This does not mean that it will be possible to match on dl_type for L3
> packets with PTAP later on. Matching must be done on packet_type instead.
> 
> New dp_packets are initialized with packet_type Ethernet. Ports that
> receive L3 packets will have to explicitly adjust the packet_type.
> 
> Signed-off-by: Jean Tourrilhes <jt at labs.hpe.com>
> Signed-off-by: Jan Scheurich <jan.scheurich at ericsson.com>
> Co-authored-by: Zoltan Balogh <zoltan.balogh at ericsson.com>

Thanks!  This looks good.  I applied this to master.  I folded in the
following minor stylistic changes:

--8<--------------------------cut here-------------------------->8--

diff --git a/include/openvswitch/ofp-print.h b/include/openvswitch/ofp-print.h
index 14497e2f335a..08b642900434 100644
--- a/include/openvswitch/ofp-print.h
+++ b/include/openvswitch/ofp-print.h
@@ -38,7 +38,8 @@ extern "C" {
 #endif
 
 void ofp_print(FILE *, const void *, size_t, int verbosity);
-void ofp_print_packet(FILE *stream, const void *data, size_t len, ovs_be32 packet_type);
+void ofp_print_packet(FILE *stream, const void *data,
+                      size_t len, ovs_be32 packet_type);
 void ofp_print_dp_packet(FILE *stream, const struct dp_packet *packet);
 
 void ofp10_match_print(struct ds *, const struct ofp10_match *, int verbosity);
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index b32f98b10b7f..319808f909f9 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -2049,8 +2049,9 @@ parse_odp_packet(const struct dpif_netlink *dpif, struct ofpbuf *buf,
     } else {
         /* Non-Ethernet packet. Get the Ethertype from the NL attributes */
         ovs_be16 ethertype = 0;
-        const struct nlattr *et_nla =
-                nl_attr_find__(upcall->key, upcall->key_len, OVS_KEY_ATTR_ETHERTYPE);
+        const struct nlattr *et_nla = nl_attr_find__(upcall->key,
+                                                     upcall->key_len,
+                                                     OVS_KEY_ATTR_ETHERTYPE);
         if (et_nla) {
             ethertype = nl_attr_get_be16(et_nla);
         }
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 25f08bdde49d..7ca953100539 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -3773,7 +3773,8 @@ ofp_print(FILE *stream, const void *oh, size_t len, int verbosity)
 /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at
  * 'data' to 'stream'. */
 void
-ofp_print_packet(FILE *stream, const void *data, size_t len, ovs_be32 packet_type)
+ofp_print_packet(FILE *stream, const void *data, size_t len,
+                 ovs_be32 packet_type)
 {
     print_and_free(stream, ofp_packet_to_string(data, len, packet_type));
 }
diff --git a/lib/packets.h b/lib/packets.h
index 0b4692801022..8acfbf50884f 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -1143,20 +1143,20 @@ pt_ns(ovs_be32 packet_type)
     return ntohl(packet_type) >> 16;
 }
 
-/* Returns the host byte ordered namespace type of 'packet type'. */
-static inline uint16_t
-pt_ns_type (ovs_be32 packet_type)
-{
-    return ntohs(be32_to_be16(packet_type));
-}
-
 /* Returns the network byte ordered namespace type of 'packet type'. */
 static inline ovs_be16
-pt_ns_type_be (ovs_be32 packet_type)
+pt_ns_type_be(ovs_be32 packet_type)
 {
     return be32_to_be16(packet_type);
 }
 
+/* Returns the host byte ordered namespace type of 'packet type'. */
+static inline uint16_t
+pt_ns_type(ovs_be32 packet_type)
+{
+    return ntohs(pt_ns_type_be(packet_type));
+}
+
 /* Well-known packet_type field values. */
 enum packet_type {
     PT_ETH  = PACKET_TYPE(OFPHTN_ONF, 0x0000),  /* Default: Ethernet */


More information about the dev mailing list