Commit ba1f9bf5 authored by Anta Huang's avatar Anta Huang
Browse files

Initial commit

parents
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
exec sudo -- "$0" "$@"
fi
# Start the OVS server
modprobe udp_tunnel
modprobe ip6_udp_tunnel
modprobe gtp
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
--private-key=db:Open_vSwitch,SSL,private_key \
--certificate=db:Open_vSwitch,SSL,certificate \
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
--pidfile --detach
ovs-vsctl --no-wait init
ovs-vswitchd --pidfile --detach --log-file=/home/grillon/log
#!/bin/bash
source config
# Check if root
if [ "$(whoami)" != "root" ]; then
exec sudo -- "$0" "$@"
fi
ovs-vsctl add-br edge -- set bridge edge protocols=$OF_VERSION # -- set bridge edge other-config:datapath-id=0000000000000004
sleep 1
ovs-vsctl add-port edge $EXT_INTERFACE
sleep 1
ovs-vsctl add-port edge s1u -- set Interface s1u type=gtp options:remote_ip=flow -- set Interface s1u type=gtp options:key=flow
ifconfig edge up
sleep 1
ifconfig $EXT_INTERFACE 0
sleep 1
ifconfig edge $EXT_IP
ovs-vsctl set-controller edge tcp:$CTRL_IP:$CTRL_PORT
#!/bin/bash
source config
# Check if root
if [ "$(whoami)" != "root" ]; then
exec sudo -- "$0" "$@"
fi
ovs-vsctl del-br edge
sleep 1
ifconfig $EXT_INTERFACE 0
#!/bin/bash
EXT_INTERFACE=enp3s0
EXT_IP=172.16.1.1
CTRL_IP=192.168.12.42
CTRL_PORT=6653
OF_VERSION=OpenFlow10,OpenFlow13
SUPPORTED_KERNEL_VERSION="4.9.0"
SUDO='sudo -S -E'
###############################
## echo and family
###############################
black='\E[30m'
red='\E[31m'
green='\E[32m'
yellow='\E[33m'
blue='\E[1;34m'
magenta='\E[35m'
cyan='\E[36m'
white='\E[37m'
reset_color='\E[00m'
COLORIZE=1
#-------------------------------------------------------------------------------
cecho() {
# Color-echo
# arg1 = message
# arg2 = color
local default_msg="No Message."
message=${1:-$default_msg}
color=${2:-$green}
[ "$COLORIZE" = "1" ] && message="$color$message$reset_color"
echo -e "$message"
return
}
echo_error() { cecho "$*" $red ;}
echo_fatal() { cecho "$*" $red; exit -1 ;}
echo_warning() { cecho "$*" $yellow ;}
echo_success() { cecho "$*" $green ;}
echo_info() { cecho "$*" $blue ;}
install_ovs_from_source(){
if [ $1 -eq 0 ]; then
OPTION=""
read -p "Do you want to install Open vSwitch patched? <y/N> " prompt
else
prompt='y'
OPTION="-y"
fi
if [[ $prompt =~ [yY](es)* ]]
then
# optional but recommended for secure connection towards controller
$SUDO apt-get install $OPTION libssl-dev libcap-ng-dev python-pip
# required by ovs
$SUDO pip install six
$SUDO rm -rf /tmp/gtp
mkdir /tmp/gtp
cd /tmp/gtp
git clone https://gitlab.eurecom.fr/oai/openair-cn-extras.git
cd openair-cn-extras/linux-4.9.0-gtp-module/
make
$SUDO make install
$SUDO modprobe udp_tunnel
$SUDO modprobe ip6_udp_tunnel
$SUDO modprobe gtp
#git_username=`git config --get user.name`
#if [ "$git_username" == "" ]; then
# echo "You haven't configured your Git yet. Please, provide a name and e-mail address."
# echo -n 'Name:'
# read git_username
# echo -n 'E-mail:'
# read git_email
# git config --global user.name "$git_username"
# git config --global user.email "$git_email"
#fi
$SUDO rm -rf /tmp/ovs
cd /tmp
git clone https://github.com/openvswitch/ovs.git
cd ovs
git checkout 31b88c97512b5dca9f1f6f73bb33292618eee88a
git am < /tmp/gtp/openair-cn-extras/ovs/0001-datapath-GPRS-Tunneling-Protocol-GTP-support.patch
git am < /tmp/gtp/openair-cn-extras/ovs/0002-userspace-GPRS-Tunneling-Protocol-GTP-support.patch
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build
make -j`nproc`
cat /tmp/gtp/openair-cn-extras/linux-4.9.0-gtp-module/Module.symvers >> datapath/linux/Module.symvers
make
$SUDO make modules_install # this overwrites openvswitch.ko, vport.ko, vport-gtp.ko, etc.
$SUDO make install
$SUDO mkdir -p /usr/local/etc/openvswitch
$SUDO mkdir -p /usr/local/var/run/openvswitch
$SUDO ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema
fi
}
source build_helper
function main()
{
install_ovs_from_source 1
}
main "$@"
From de200735c14ea4c8dfd43ff47774934090d00c84 Mon Sep 17 00:00:00 2001
From: Anta Huang <anta.huang@eurecom.fr>
Date: Wed, 5 Apr 2017 14:12:38 +0200
Subject: [PATCH 2/3] Fix the incompatible GTP tunnel patch for ovs-2.7
---
datapath/linux/compat/gtp.c | 91 ++++++++++++++++++---------
datapath/linux/compat/include/linux/if_link.h | 4 +-
datapath/linux/compat/include/net/gtp.h | 3 +
datapath/vport-gtp.c | 18 ++----
4 files changed, 71 insertions(+), 45 deletions(-)
diff --git a/datapath/linux/compat/gtp.c b/datapath/linux/compat/gtp.c
index 4671ec2..daf3010 100644
--- a/datapath/linux/compat/gtp.c
+++ b/datapath/linux/compat/gtp.c
@@ -23,6 +23,7 @@
#include <linux/module.h>
#include <linux/rculist.h>
#include <linux/udp.h>
+#include <linux/etherdevice.h>
#include <net/icmp.h>
#include <net/ip.h>
@@ -214,7 +215,7 @@ static int gtp_rcv(struct sock *sk, struct sk_buff *skb)
struct gtphdr *gtph;
struct iphdr *inner_iph;
struct metadata_dst *tun_dst;
-#ifndef HAVE_METADATA_DST
+#ifndef USE_UPSTREAM_TUNNEL
struct metadata_dst temp;
#endif
__be64 key;
@@ -225,7 +226,7 @@ static int gtp_rcv(struct sock *sk, struct sk_buff *skb)
if (unlikely(!dev))
goto error;
- if (iptunnel_pull_header(skb, GTP_HLEN, 0))
+ if (iptunnel_pull_header(skb, GTP_HLEN, 0, false))
goto error;
gtph = gtp_hdr(skb);
@@ -233,9 +234,9 @@ static int gtp_rcv(struct sock *sk, struct sk_buff *skb)
key = cpu_to_be64(ntohl(gtph->teid));
/* Save outer tunnel values */
-#ifndef HAVE_METADATA_DST
+#ifndef USE_UPSTREAM_TUNNEL
tun_dst = &temp;
- ovs_udp_tun_rx_dst(&tun_dst->u.tun_info, skb, AF_INET, TUNNEL_KEY, key, 0);
+ ovs_udp_tun_rx_dst(tun_dst, skb, AF_INET, TUNNEL_KEY, key, 0);
#else
tun_dst = udp_tun_rx_dst(skb, AF_INET, TUNNEL_KEY, key, 0);
#endif
@@ -269,6 +270,23 @@ out:
return 0;
}
+static struct rtable *gtp_get_rt(struct sk_buff *skb,
+ struct net_device *dev,
+ struct flowi4 *fl,
+ const struct ip_tunnel_key *key)
+{
+ struct gtp_dev *gtp_dev = netdev_priv(dev);
+ struct net *net = gtp_dev->net;
+// struct net *net = dev_net(dev);
+ memset(fl, 0, sizeof(*fl));
+ fl->daddr = key->u.ipv4.dst;
+ fl->saddr = key->u.ipv4.src;
+ fl->flowi4_tos = RT_TOS(key->tos);
+ fl->flowi4_mark = skb->mark;
+ fl->flowi4_proto = IPPROTO_UDP;
+ return ip_route_output_key(net, fl);
+}
+
netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb)
{
struct net_device *dev = skb->dev;
@@ -276,7 +294,7 @@ netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb)
struct net *net = gtp_dev->net;
int network_offset = skb_network_offset(skb);
struct ip_tunnel_info *info;
- struct ip_tunnel_key *tun_key;
+ struct ip_tunnel_key *key;
struct rtable *rt;
int min_headroom;
__be16 src_port, dst_port;
@@ -296,22 +314,23 @@ netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb)
goto error;
}
- tun_key = &info->key;
+ key = &info->key;
/* Route lookup */
- memset(&fl, 0, sizeof(fl));
- fl.daddr = tun_key->u.ipv4.dst;
- fl.saddr = tun_key->u.ipv4.src;
- fl.flowi4_tos = RT_TOS(tun_key->tos);
- fl.flowi4_mark = skb->mark;
- fl.flowi4_proto = IPPROTO_UDP;
- rt = ip_route_output_key(net, &fl);
+ //memset(&fl, 0, sizeof(fl));
+ //fl.daddr = tun_key->u.ipv4.dst;
+ //fl.saddr = tun_key->u.ipv4.src;
+ //fl.flowi4_tos = RT_TOS(tun_key->tos);
+ //fl.flowi4_mark = skb->mark;
+ //fl.flowi4_proto = IPPROTO_UDP;
+ //rt = ip_route_output_key(net, &fl);
+ rt = gtp_get_rt(skb, dev, &fl, key);
if (IS_ERR(rt)) {
err = PTR_ERR(rt);
goto error;
}
- min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
+ min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len
+ sizeof(struct iphdr) + GTP_HLEN;
if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
@@ -327,11 +346,10 @@ netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb)
/* Reset l2 headers. */
skb_pull(skb, network_offset);
skb_reset_mac_header(skb);
- vlan_set_tci(skb, 0);
+ skb->vlan_tci = 0;
- skb = udp_tunnel_handle_offloads(skb, false, 0, false);
- if (IS_ERR(skb)) {
- err = PTR_ERR(skb);
+ err = udp_tunnel_handle_offloads(skb, false);
+ if (err) {
skb = NULL;
goto err_free_rt;
}
@@ -339,20 +357,18 @@ netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb)
src_port = htons(get_src_port(net, skb));
dst_port = gtp_dev->dst_port;
- gtp_build_header(skb, tun_key);
+ gtp_build_header(skb, key);
skb->ignore_df = 1;
ovs_skb_set_inner_protocol(skb, skb->protocol);
- df = tun_key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
- err = udp_tunnel_xmit_skb(rt, gtp_dev->sock->sk, skb,
- fl.saddr, tun_key->u.ipv4.dst,
- tun_key->tos, tun_key->ttl,
- df, src_port, dst_port, false, true);
+ df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
+ udp_tunnel_xmit_skb(rt, gtp_dev->sock->sk, skb,
+ fl.saddr, key->u.ipv4.dst,
+ key->tos, key->ttl,
+ df, src_port, dst_port, false, true);
- iptunnel_xmit_stats(err, &dev->stats,
- (struct pcpu_sw_netstats __percpu *)dev->tstats);
return NETDEV_TX_OK;
err_free_rt:
@@ -437,7 +453,7 @@ static int gtp_stop(struct net_device *dev)
static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev)
{
-#ifdef HAVE_METADATA_DST
+#ifdef USE_UPSTREAM_TUNNEL
return rpl_gtp_xmit(skb);
#else
/* Drop All packets coming from networking stack. OVS-CB is
@@ -450,6 +466,24 @@ static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev)
#endif
}
+int ovs_gtp_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
+{
+ struct ip_tunnel_info *info = skb_tunnel_info(skb);
+ struct rtable *rt;
+ struct flowi4 fl4;
+
+ if (ip_tunnel_info_af(info) != AF_INET)
+ return -EINVAL;
+ rt = gtp_get_rt(skb, dev, &fl4, &info->key);
+ if (IS_ERR(rt))
+ return PTR_ERR(rt);
+
+ ip_rt_put(rt);
+ info->key.u.ipv4.src = fl4.saddr;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ovs_gtp_fill_metadata_dst);
+
static const struct net_device_ops gtp_netdev_ops = {
#ifdef HAVE_DEV_TSTATS
.ndo_init = gtp_init,
@@ -501,7 +535,7 @@ static void gtp_setup(struct net_device *dev)
dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
dev->hw_features |= NETIF_F_GSO_SOFTWARE;
#endif
-#ifdef HAVE_METADATA_DST
+#ifdef USE_UPSTREAM_TUNNEL
netif_keep_dst(dev);
#endif
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE;
@@ -686,7 +720,6 @@ static struct pernet_operations gtp_net_ops = {
.size = sizeof(struct gtp_net),
};
-DEFINE_COMPAT_PNET_REG_FUNC(device)
int rpl_gtp_init_module(void)
{
int rc;
diff --git a/datapath/linux/compat/include/linux/if_link.h b/datapath/linux/compat/include/linux/if_link.h
index 69fd038..c1a4781 100644
--- a/datapath/linux/compat/include/linux/if_link.h
+++ b/datapath/linux/compat/include/linux/if_link.h
@@ -64,9 +64,9 @@ enum {
/* GTP section */
enum {
IFLA_GTP_PORT, /* destination port */
- __IFLA_GTP_MAX
+ __IFLA_GTP_MAX
};
-#define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)
+#define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)
/* VXLAN section */
enum {
diff --git a/datapath/linux/compat/include/net/gtp.h b/datapath/linux/compat/include/net/gtp.h
index 05623bd..01708c5 100644
--- a/datapath/linux/compat/include/net/gtp.h
+++ b/datapath/linux/compat/include/net/gtp.h
@@ -21,4 +21,7 @@ void rpl_gtp_cleanup_module(void);
#define gtp_xmit rpl_gtp_xmit
netdev_tx_t rpl_gtp_xmit(struct sk_buff *skb);
+#define gtp_fill_metadata_dst ovs_gtp_fill_metadata_dst
+int ovs_gtp_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
+
#endif /*ifdef__NET_GTP_H */
diff --git a/datapath/vport-gtp.c b/datapath/vport-gtp.c
index 6892b2b..626fdea 100644
--- a/datapath/vport-gtp.c
+++ b/datapath/vport-gtp.c
@@ -52,18 +52,6 @@ static int gtp_get_options(const struct vport *vport,
return 0;
}
-static int gtp_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
- struct dp_upcall_info *upcall)
-{
- struct gtp_port *gtp_port = gtp_vport(vport);
- struct net *net = ovs_dp_get_net(vport->dp);
- __be16 dport = htons(gtp_port->port_no);
- __be16 sport = udp_flow_src_port(net, skb, 1, USHRT_MAX, true);
-
- return ovs_tunnel_get_egress_info(upcall, ovs_dp_get_net(vport->dp),
- skb, IPPROTO_UDP, sport, dport);
-}
-
static struct vport *gtp_tnl_create(const struct vport_parms *parms)
{
struct net *net = ovs_dp_get_net(parms->dp);
@@ -126,10 +114,12 @@ static struct vport *gtp_create(const struct vport_parms *parms)
static struct vport_ops ovs_gtp_vport_ops = {
.type = OVS_VPORT_TYPE_GTP,
.create = gtp_create,
- .destroy = ovs_netdev_tunnel_destroy,
.get_options = gtp_get_options,
+#ifndef USE_UPSTREAM_TUNNEL
+ .fill_metadata_dst = gtp_fill_metadata_dst,
+#endif
.send = gtp_xmit,
- .get_egress_tun_info = gtp_get_egress_tun_info,
+ .destroy = ovs_netdev_tunnel_destroy,
};
static int __init ovs_gtp_tnl_init(void)
--
2.7.4
From c822aaf6bbb7b18b1c431ebaa5a1f062a905120d Mon Sep 17 00:00:00 2001
From: Anta Huang <anta.huang@eurecom.fr>
Date: Sat, 8 Apr 2017 13:38:45 +0200
Subject: [PATCH 3/3] Fix incorrect Ethernet header when receiving GTP packet
---
datapath/linux/compat/gtp.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/datapath/linux/compat/gtp.c b/datapath/linux/compat/gtp.c
index daf3010..d27a3f9 100644
--- a/datapath/linux/compat/gtp.c
+++ b/datapath/linux/compat/gtp.c
@@ -220,6 +220,7 @@ static int gtp_rcv(struct sock *sk, struct sk_buff *skb)
#endif
__be64 key;
struct ethhdr *ethh;
+ struct ethhdr *test;
__be16 protocol;
dev = rcu_dereference_sk_user_data(sk);
@@ -255,10 +256,21 @@ static int gtp_rcv(struct sock *sk, struct sk_buff *skb)
skb->protocol = protocol;
/* Add Ethernet header */
+ test = (struct ethhdr *)skb_mac_header(skb);
ethh = (struct ethhdr *)skb_push(skb, ETH_HLEN);
memset(ethh, 0, ETH_HLEN);
- ethh->h_dest[0] = 0x06;
- ethh->h_source[0] = 0x06;
+ ethh->h_dest[0] = test->h_dest[0];
+ ethh->h_dest[1] = test->h_dest[1];
+ ethh->h_dest[2] = test->h_dest[2];
+ ethh->h_dest[3] = test->h_dest[3];
+ ethh->h_dest[4] = test->h_dest[4];
+ ethh->h_dest[5] = test->h_dest[5];
+ ethh->h_source[0] = test->h_source[0];
+ ethh->h_source[1] = test->h_source[1];
+ ethh->h_source[2] = test->h_source[2];
+ ethh->h_source[3] = test->h_source[3];
+ ethh->h_source[4] = test->h_source[4];
+ ethh->h_source[5] = test->h_source[5];
ethh->h_proto = protocol;
ovs_ip_tunnel_rcv(dev, skb, tun_dst);
--
2.7.4
#!/bin/bash
CUR_DIR=`pwd`
# Check if root
if [ "$(whoami)" != "root" ]; then
exec sudo -- "$0" "$@"
fi
# Download latest OVS-2.5 (LTS) sources
cd $CUR_DIR
rm -rf ovs
rm -rf /usr/local/etc/openvswitch
git clone https://github.com/openvswitch/ovs.git
cd ovs/
# Apply GTP patch
git checkout branch-2.7
git am < $CUR_DIR/0001-Basic-GTP-U-tunnel-implementation-in-ovs.patch
git am < $CUR_DIR/0001-4.6-Fix-the-incompatible-GTP-tunnel-patch-for-ovs-2..patch
git am < $CUR_DIR/0001-Fix-incorrect-Ethernet-header-when-receiving-GTP-pac.patch
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build
make clean
make
make install
make modules_install
rmmod openvswitch
modprobe -a `modinfo -F depends $CUR_DIR/ovs/datapath/linux/openvswitch.ko | sed 's/,/ /g'` # Install the dependencies
insmod $CUR_DIR/ovs/datapath/linux/openvswitch.ko
insmod $CUR_DIR/ovs/datapath/linux/vport-gtp.ko
# Initialize the configuration database
mkdir -p /usr/local/etc/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment