flow: Support OF1.5+ (draft) actset_output field.
[cascardo/ovs.git] / lib / flow.h
index b9c9f1b..2259680 100644 (file)
@@ -38,7 +38,7 @@ struct pkt_metadata;
 /* This sequence number should be incremented whenever anything involving flows
  * or the wildcarding of flows changes.  This will cause build assertion
  * failures in places which likely need to be updated. */
-#define FLOW_WC_SEQ 27
+#define FLOW_WC_SEQ 28
 
 /* Number of Open vSwitch extension 32-bit registers. */
 #define FLOW_N_REGS 8
@@ -94,7 +94,7 @@ const char *flow_tun_flag_to_string(uint32_t flags);
  * reflected in miniflow_extract()!
  */
 struct flow {
-    /* L1 */
+    /* Metadata */
     struct flow_tnl tunnel;     /* Encapsulating tunnel parameters. */
     ovs_be64 metadata;          /* OpenFlow Metadata. */
     uint32_t regs[FLOW_N_REGS]; /* Registers. */
@@ -102,10 +102,12 @@ struct flow {
     uint32_t pkt_mark;          /* Packet mark. */
     uint32_t recirc_id;         /* Must be exact match. */
     union flow_in_port in_port; /* Input port.*/
+    ofp_port_t actset_output;   /* Output port in action set. */
+    ovs_be16 pad1;              /* Pad to 32 bits. */
 
     /* L2, Order the same as in the Ethernet header! */
-    uint8_t dl_dst[6];          /* Ethernet destination address. */
-    uint8_t dl_src[6];          /* Ethernet source address. */
+    uint8_t dl_dst[ETH_ADDR_LEN]; /* Ethernet destination address. */
+    uint8_t dl_src[ETH_ADDR_LEN]; /* Ethernet source address. */
     ovs_be16 dl_type;           /* Ethernet frame type. */
     ovs_be16 vlan_tci;          /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
     ovs_be32 mpls_lse[FLOW_MAX_MPLS_LABELS]; /* MPLS label stack entry. */
@@ -120,11 +122,11 @@ struct flow {
     uint8_t nw_tos;             /* IP ToS (including DSCP and ECN). */
     uint8_t nw_ttl;             /* IP TTL/Hop Limit. */
     uint8_t nw_proto;           /* IP protocol or low 8 bits of ARP opcode. */
-    uint8_t arp_sha[6];         /* ARP/ND source hardware address. */
-    uint8_t arp_tha[6];         /* ARP/ND target hardware address. */
+    uint8_t arp_sha[ETH_ADDR_LEN]; /* ARP/ND source hardware address. */
+    uint8_t arp_tha[ETH_ADDR_LEN]; /* ARP/ND target hardware address. */
     struct in6_addr nd_target;  /* IPv6 neighbor discovery (ND) target. */
     ovs_be16 tcp_flags;         /* TCP flags. With L3 to avoid matching L4. */
-    ovs_be16 pad;               /* Padding. */
+    ovs_be16 pad2;              /* Pad to 32 bits. */
 
     /* L4 */
     ovs_be16 tp_src;            /* TCP/UDP/SCTP source port. */
@@ -138,10 +140,24 @@ BUILD_ASSERT_DECL(sizeof(struct flow) % 4 == 0);
 
 #define FLOW_U32S (sizeof(struct flow) / 4)
 
+/* Some flow fields are mutually exclusive or only appear within the flow
+ * pipeline.  IPv6 headers are bigger than IPv4 and MPLS, and IPv6 ND packets
+ * are bigger than TCP,UDP and IGMP packets. */
+#define FLOW_MAX_PACKET_U32S (FLOW_U32S                                   \
+    /* Unused in datapath */  - FLOW_U32_SIZE(regs)                       \
+                              - FLOW_U32_SIZE(metadata)                   \
+                              - FLOW_U32_SIZE(actset_output)              \
+    /* L2.5/3 */              - FLOW_U32_SIZE(nw_src)                     \
+                              - FLOW_U32_SIZE(nw_dst)                     \
+                              - FLOW_U32_SIZE(mpls_lse)                   \
+    /* L4 */                  - FLOW_U32_SIZE(tcp_flags) /* incl. pad. */ \
+                              - FLOW_U32_SIZE(igmp_group_ip4)             \
+                             )
+
 /* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
 BUILD_ASSERT_DECL(offsetof(struct flow, dp_hash) + sizeof(uint32_t)
-                  == sizeof(struct flow_tnl) + 176
-                  && FLOW_WC_SEQ == 27);
+                  == sizeof(struct flow_tnl) + 180
+                  && FLOW_WC_SEQ == 28);
 
 /* Incremental points at which flow classification may be performed in
  * segments.
@@ -314,6 +330,7 @@ void flow_wildcards_init_catchall(struct flow_wildcards *);
 
 void flow_wildcards_init_for_packet(struct flow_wildcards *,
                                     const struct flow *);
+uint64_t flow_wc_map(const struct flow *);
 
 void flow_wildcards_clear_non_packet_fields(struct flow_wildcards *);
 
@@ -494,31 +511,45 @@ flow_get_next_in_map(const struct flow *flow, uint64_t map, uint32_t *value)
     (((UINT64_C(1) << FLOW_U32_SIZE(FIELD)) - 1)  \
      << (offsetof(struct flow, FIELD) / 4))
 
-static inline uint32_t
-mf_get_next_in_map(uint64_t *fmap, uint64_t rm1bit, const uint32_t **fp,
-                   uint32_t *value)
-{
-    *value = 0;
-    if (*fmap & rm1bit) {
-        uint64_t trash = *fmap & (rm1bit - 1);
+struct mf_for_each_in_map_aux {
+    const uint32_t *values;
+    uint64_t fmap;
+    uint64_t map;
+};
 
-        if (trash) {
-            *fmap -= trash;
-            *fp += count_1bits(trash);
+static inline bool
+mf_get_next_in_map(struct mf_for_each_in_map_aux *aux, uint32_t *value)
+{
+    if (aux->map) {
+        uint64_t rm1bit = rightmost_1bit(aux->map);
+        aux->map -= rm1bit;
+
+        if (aux->fmap & rm1bit) {
+            /* Advance 'aux->values' to point to the value for 'rm1bit'. */
+            uint64_t trash = aux->fmap & (rm1bit - 1);
+            if (trash) {
+                aux->fmap -= trash;
+                aux->values += count_1bits(trash);
+            }
+
+            /* Retrieve the value for 'rm1bit' then advance past it. */
+            aux->fmap -= rm1bit;
+            *value = *aux->values++;
+        } else {
+            *value = 0;
         }
-        *value = **fp;
+        return true;
+    } else {
+        return false;
     }
-    return rm1bit != 0;
 }
 
-/* Iterate through all miniflow u32 values specified by 'MAP'.
- * This works as the first statement in a block.*/
+/* Iterate through all miniflow u32 values specified by 'MAP'. */
 #define MINIFLOW_FOR_EACH_IN_MAP(VALUE, FLOW, MAP)                      \
-    const uint32_t *fp_ = miniflow_get_u32_values(FLOW);                \
-    uint64_t rm1bit_, fmap_, map_;                                      \
-    for (fmap_ = (FLOW)->map, map_ = (MAP), rm1bit_ = rightmost_1bit(map_); \
-         mf_get_next_in_map(&fmap_, rm1bit_, &fp_, &(VALUE));           \
-         map_ -= rm1bit_, rm1bit_ = rightmost_1bit(map_))
+    for (struct mf_for_each_in_map_aux aux__                            \
+             = { miniflow_get_u32_values(FLOW), (FLOW)->map, MAP };     \
+         mf_get_next_in_map(&aux__, &(VALUE));                          \
+        )
 
 /* Get the value of 'FIELD' of an up to 4 byte wide integer type 'TYPE' of
  * a miniflow. */