From: Johnson Li <johnson...@intel.com>

In user space, only standard VxLAN was support. This patch will
add the VxLAN-GBP support for the user space data path.

How to use:
1> Create VxLAN port with GBP extension
  $ovs-vsctl add-port br-int vxlan0 -- set interface vxlan0 \
           type=vxlan options:dst_port=6633 \
           options:remote_ip=192.168.60.22 \
           options:key=1000 options:exts=gbp
2> Add flow for transmitting
  $ovs-ofctl add-flow br-int "table=0, priority=260, \
             in_port=LOCAL actions=load:0x100->NXM_NX_TUN_GBP_ID[], \
             output:1"
3> Add flow for receiving
  $ovs-ofctl add-flow br-int "table=0, priority=260, \
             in_port=1,tun_gbp_id=0x100 actions=output:LOCAL"

Signed-off-by: Johnson Li <johnson...@intel.com>

diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index e398562..e6b35ed 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -1286,6 +1286,7 @@ netdev_vxlan_pop_header(struct dp_packet *packet)
     struct flow_tnl *tnl = &md->tunnel;
     struct vxlanhdr *vxh;
     unsigned int hlen;
+    uint32_t vxh_flags;
 
     pkt_metadata_init_tnl(md);
     if (VXLAN_HLEN > dp_packet_l4_size(packet)) {
@@ -1297,10 +1298,16 @@ netdev_vxlan_pop_header(struct dp_packet *packet)
         return EINVAL;
     }
 
-    if (get_16aligned_be32(&vxh->vx_flags) != htonl(VXLAN_FLAGS) ||
-       (get_16aligned_be32(&vxh->vx_vni) & htonl(0xff))) {
-        VLOG_WARN_RL(&err_rl, "invalid vxlan flags=%#x vni=%#x\n",
-                     ntohl(get_16aligned_be32(&vxh->vx_flags)),
+    vxh_flags = get_16aligned_be32(&vxh->vx_flags);
+    if ((vxh_flags & htonl(VXLAN_GBP_FLAGS)) == htonl(VXLAN_GBP_FLAGS)) {
+        tnl->gbp_id = htons(ntohl(vxh_flags) & 0xFFFF); /* VXLAN_GBP_ID_MASK */
+    } else if (vxh_flags != htonl(VXLAN_FLAGS)) {
+        VLOG_WARN_RL(&err_rl, "invalid vxlan flags=%#x\n",
+                     ntohl(get_16aligned_be32(&vxh->vx_flags)));
+        return EINVAL;
+    }
+    if (get_16aligned_be32(&vxh->vx_vni) & htonl(0xff)) {
+        VLOG_WARN_RL(&err_rl, "invalid vxlan vni=%#x\n",
                      ntohl(get_16aligned_be32(&vxh->vx_vni)));
         return EINVAL;
     }
@@ -1328,7 +1335,12 @@ netdev_vxlan_build_header(const struct netdev *netdev,
 
     vxh = udp_build_header(tnl_cfg, tnl_flow, data, &hlen);
 
-    put_16aligned_be32(&vxh->vx_flags, htonl(VXLAN_FLAGS));
+    if (tnl_cfg->exts & (1 << OVS_VXLAN_EXT_GBP)) {
+        put_16aligned_be32(&vxh->vx_flags,
+                htonl(VXLAN_GBP_FLAGS | ntohs(tnl_flow->tunnel.gbp_id)));
+    } else {
+        put_16aligned_be32(&vxh->vx_flags, htonl(VXLAN_FLAGS));
+    }
     put_16aligned_be32(&vxh->vx_vni, htonl(ntohll(tnl_flow->tunnel.tun_id) << 
8));
 
     ovs_mutex_unlock(&dev->mutex);
diff --git a/lib/packets.h b/lib/packets.h
index 8139a6b..d9a149d 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -1002,6 +1002,7 @@ struct vxlanhdr {
 };
 
 #define VXLAN_FLAGS 0x08000000  /* struct vxlanhdr.vx_flags required value. */
+#define VXLAN_GBP_FLAGS 0x88000000  /* Group Based Policy */
 
 void ipv6_format_addr(const struct in6_addr *addr, struct ds *);
 void ipv6_format_addr_bracket(const struct in6_addr *addr, struct ds *,
-- 
1.8.4.2

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to