[ovs-dev] [metaflow-cleanup 2/3] flow: New functions for setting a VLAN VID or PCP value.

Ben Pfaff blp at nicira.com
Tue Nov 8 05:50:24 UTC 2011


---
 lib/flow.c |   21 +++++++++++++++++++++
 lib/flow.h |    3 +++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index 1263734..bf7ba6d 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -985,6 +985,27 @@ flow_hash_fields_valid(enum nx_hash_fields fields)
         || fields == NX_HASH_FIELDS_SYMMETRIC_L4;
 }
 
+void
+flow_set_vlan_vid(struct flow *flow, ovs_be16 vid)
+{
+    if (vid == htons(OFP_VLAN_NONE)) {
+        flow->vlan_tci = htons(0);
+    } else {
+        vid &= htons(VLAN_VID_MASK);
+        flow->vlan_tci &= ~htons(VLAN_VID_MASK);
+        flow->vlan_tci |= htons(VLAN_CFI) | vid;
+    }
+}
+
+void
+flow_set_vlan_pcp(struct flow *flow, uint8_t pcp)
+{
+    pcp &= 0x07;
+    flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
+    flow->vlan_tci |= htons((pcp << VLAN_PCP_SHIFT) | VLAN_CFI);
+}
+
+
 /* Puts into 'b' a packet that flow_extract() would parse as having the given
  * 'flow'.
  *
diff --git a/lib/flow.h b/lib/flow.h
index 0abfe5a..b26949c 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -97,6 +97,9 @@ static inline int flow_compare(const struct flow *, const struct flow *);
 static inline bool flow_equal(const struct flow *, const struct flow *);
 static inline size_t flow_hash(const struct flow *, uint32_t basis);
 
+void flow_set_vlan_vid(struct flow *, ovs_be16 vid);
+void flow_set_vlan_pcp(struct flow *, uint8_t pcp);
+
 void flow_compose(struct ofpbuf *, const struct flow *);
 
 static inline int
-- 
1.7.2.5




More information about the dev mailing list