Skip to content

Commit

Permalink
Merge pull request FDio#27 from TetsuyaMurakami/ietf105-hackathon
Browse files Browse the repository at this point in the history
This commit fix FDio#20, fix FDio#25 and fix FDio#26
  • Loading branch information
matsusato3 authored Jul 12, 2019
2 parents a7cf6c6 + 6086397 commit c2089eb
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 46 deletions.
20 changes: 5 additions & 15 deletions extras/ietf105/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,17 @@ COPY . / {{vpp_path}}/
WORKDIR {{vpp_path}}

RUN set -eux; \
make wipe

RUN set -eux; \
make wipe; \
export UNATTENDED=y; \
make install-dep; \
rm -rf /var/lib/apt/lists/*

RUN set -eux; \
export UNATTENDED=y; \
rm -rf /var/lib/apt/lists/* ; \
make build; \
make pkg-deb; \
rm -rf .ccache; \
find . -type f -name '*.o' -delete

WORKDIR {{vpp_path}}/build-root

RUN set -eux; \
find . -type f -name '*.o' -delete ; \
cd {{vpp_path}}/build-root; \
rm vpp-api-python_*.deb; \
dpkg -i *.deb

RUN set -euex; \
dpkg -i *.deb ; \
cp {{vpp_path}}/startup.conf /etc/startup.conf; \
rm -rf {{vpp_path}}

Expand Down
42 changes: 42 additions & 0 deletions extras/ietf105/Dockerfile.j2.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

FROM ubuntu:18.04

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
inetutils-traceroute \
ca-certificates \
build-essential \
git gdb sudo \
iputils-ping \
net-tools \
iproute2 \
tcpdump \
python3-cffi \
netcat; \
rm -rf /var/lib/apt/lists/*; \
mv /usr/sbin/tcpdump /usr/bin/tcpdump

WORKDIR /tmp

RUN set -eux; \
git clone -b ietf105-hackathon https://github.com/filvarga/srv6-mobile.git; \
cd /tmp/srv6-mobile; \
make wipe; \
export UNATTENDED=y; \
make install-dep; \
rm -rf /var/lib/apt/lists/* ; \
make build; \
make pkg-deb; \
rm -rf .ccache; \
find . -type f -name '*.o' -delete ; \
cd /tmp/srv6-mobile/build-root; \
rm vpp-api-python_*.deb; \
dpkg -i *.deb ; \
cp /tmp/srv6-mobile/extras/ietf105/startup.conf.j2 /etc/startup.conf; \
rm -rf /tmp/srv6-mobile

WORKDIR /

CMD vpp -c /etc/startup.conf

28 changes: 23 additions & 5 deletions extras/ietf105/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ def build(self, path, vpp_path):
tag=self.image, rm=True)
return ref

def release(self, path, vpp_path):
env = Environment(
loader=FileSystemLoader(path),
trim_blocks=True)

self.tmp_render(join(vpp_path, "Dockerfile"),
env.get_template("Dockerfile.j2.release"),
{'vpp_path': vpp_path})

ref, _ = self.client.images.build(path=vpp_path,
tag=self.image, rm=True)
return ref

def new(self, name):
return Container.new(self.client, self.image, name)

Expand Down Expand Up @@ -519,14 +532,14 @@ def test_tmap(self):
local_mac="aa:bb:cc:dd:ee:11", remote_mac="aa:bb:cc:dd:ee:22")

c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D1:: next D2:: next D3:: gtp4_removal sr_prefix D4::/32 local_prefix C1::/64")
c1.vppctl_exec("sr policy add bsid D1:: next D2:: next D3:: gtp4_removal sr_prefix D4::/32 v6src_prefix C1::/64")
c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D1::")

c2.vppctl_exec("sr localsid address D2:: behavior end")

c3.vppctl_exec("sr localsid address D3:: behavior end")

c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e C1::/64")
c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e v4src_position 64")

c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
c2.set_ipv6_route("eth1", "A1::1", "C::/120")
Expand Down Expand Up @@ -580,14 +593,14 @@ def test_tmap_ipv6(self):
local_mac="aa:bb:cc:dd:ee:11", remote_mac="aa:bb:cc:dd:ee:22")

c1.vppctl_exec("set sr encaps source addr A1::1")
c1.vppctl_exec("sr policy add bsid D1:: next D2:: next D3:: gtp4_removal sr_prefix D4::/32 local_prefix C1::/64")
c1.vppctl_exec("sr policy add bsid D1:: next D2:: next D3:: gtp4_removal sr_prefix D4::/32 v6src_prefix C1::/64")
c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D1::")

c2.vppctl_exec("sr localsid address D2:: behavior end")

c3.vppctl_exec("sr localsid address D3:: behavior end")

c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e C1::/64")
c4.vppctl_exec("sr localsid prefix D4::/32 behavior end.m.gtp4.e v4src_position 64")

c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
c2.set_ipv6_route("eth1", "A1::1", "C::/120")
Expand Down Expand Up @@ -914,6 +927,9 @@ def build_image(self):
# TODO: optimize build process for speed and image size
self.containers.build(self.path, self.vpp_path)

def release_image(self):
self.containers.release(self.path, self.vpp_path)

def vppctl(self, index, command=None):
if index >= len(self.instance_names):
return
Expand Down Expand Up @@ -943,7 +959,7 @@ def get_args():
help="Infrastructure related commands.")

p1.add_argument("op", choices=[
'stop', 'start', 'status', 'restart', 'build'])
'stop', 'start', 'status', 'restart', 'build', 'release'])

p1.add_argument("--prefix")
p1.add_argument("--image")
Expand Down Expand Up @@ -984,6 +1000,8 @@ def main(op=None, image=None, prefix=None, verbose=None, index=None, command=Non
try:
if op == 'build':
program.build_image()
elif op == 'release':
program.release_image()
elif op == 'stop':
program.stop_containers()
elif op == 'start':
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/srv6-mobile/gtp4_e.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ clb_format_srv6_end_m_gtp4_e (u8 * s, va_list * args)

s = format (s, "SRv6 End gtp4.e\n\t");

s = format (s, "Local Prefix: %U/%d\n", format_ip6_address, &ls_mem->local_prefix, ls_mem->local_prefixlen);
s = format (s, "IPv4 address position: %d\n", ls_mem->local_prefixlen);

return s;
}
Expand All @@ -79,18 +79,16 @@ clb_unformat_srv6_end_m_gtp4_e (unformat_input_t * input, va_list * args)
{
void **plugin_mem_p = va_arg (*args, void **);
srv6_end_gtp4_param_t *ls_mem;
ip6_address_t local_prefix;
u32 local_prefixlen;

if (!unformat (input, "end.m.gtp4.e %U/%d",
unformat_ip6_address, &local_prefix, &local_prefixlen))
if (!unformat (input, "end.m.gtp4.e v4src_position %d",
&local_prefixlen))
return 0;

ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
clib_memset (ls_mem, 0, sizeof *ls_mem);
*plugin_mem_p = ls_mem;

ls_mem->local_prefix = local_prefix;
ls_mem->local_prefixlen = local_prefixlen;

return 1;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/srv6-mobile/mobile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef struct srv6_end_gtp6_param_s

typedef struct srv6_end_gtp4_param_s
{
ip6_address_t local_prefix;
u32 local_prefixlen;
} srv6_end_gtp4_param_t;

Expand Down
54 changes: 35 additions & 19 deletions src/plugins/srv6-mobile/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ typedef enum
SRV6_END_M_GTP6_D_DI_N_NEXT,
} srv6_end_m_gtp6_d_di_next_t;

static inline u16
hash_uword_to_u16 (uword *key)
{
u16 *val;
val = (u16 *)key;
#if uword_bits == 64
return val[0] ^ val[1] ^ val[3] ^ val[4];
#else
return val[0] ^ val[1];
#endif
}

// Function for SRv6 GTP4.E function.
VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
vlib_node_runtime_t * node,
Expand Down Expand Up @@ -219,6 +231,14 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
}
else
{
u32 teid;
u8 *teid8p = (u8 *)&teid;
u32 index;
u32 offset, shift;
uword key;
u16 port;
void *p;

// we need to be sure there is enough space before
// ip6srv0 header, there is some extra space
// in the pre_data area for this kind of
Expand All @@ -237,6 +257,8 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
}

// get length of encapsulated IPv6 packet (the remaining part)
p = vlib_buffer_get_current (b0);

len0 = vlib_buffer_length_in_chain (vm, b0);

// jump back to data[0] or pre_data if required
Expand All @@ -246,11 +268,6 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,

clib_memcpy (hdr0, &sm->cache_hdr, sizeof (ip4_gtpu_header_t));

u32 teid;
u8 *teid8p = (u8 *)&teid;
u32 index;
u32 offset, shift;

offset = ls0->localsid_len / 8;
shift = ls0->localsid_len % 8;

Expand Down Expand Up @@ -283,32 +300,43 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
shift = ls_param->local_prefixlen % 8;

if (PREDICT_TRUE(shift == 0)) {
#if 0
u8 *pp;

pp = (u8 *) &hdr0->udp.src_port;
#endif

for (index = 0; index < 4; index ++) {
hdr0->ip4.src_address.as_u8[index] = src0.as_u8[offset + index];
}

#if 0
for (index = 0; index < 2; index++) {
pp[index] = src0.as_u8[offset + 4 + index];
}
#endif
} else {
#if 0
u8 *pp;

pp = (u8 *) &hdr0->udp.src_port;
#endif

for (index = 0; index < 4; index ++) {
hdr0->ip4.src_address.as_u8[index] = src0.as_u8[offset + index] << shift;
hdr0->ip4.src_address.as_u8[index] |= src0.as_u8[offset + index + 1] >> (8 - shift);
}

#if 0
for (index = 0; index < 2; index++) {
pp[index] = src0.as_u8[offset + index + 4] << shift;
pp[index] |= src0.as_u8[offset + index + 5] >> (8 - shift);
}
#endif
}

key = hash_memory(p, len0, 0);
port = hash_uword_to_u16(&key);
hdr0->udp.src_port = port;

hdr0->udp.length = clib_host_to_net_u16 (len0 +
sizeof (udp_header_t) + sizeof (gtpu_header_t));

Expand Down Expand Up @@ -372,18 +400,6 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) = {
},
};

static inline u16
hash_uword_to_u16 (uword *key)
{
u16 *val;
val = (u16 *)key;
#if uword_bits == 64
return val[0] ^ val[1] ^ val[3] ^ val[4];
#else
return val[0] ^ val[1];
#endif
}

// Function for SRv6 GTP6.E function
VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
vlib_node_runtime_t * node,
Expand Down
Loading

0 comments on commit c2089eb

Please sign in to comment.