Python-API: Inital commit of Python bindings for the VPP API.

See: https://wiki.fd.io/view/VPP/Python_API

Change-Id: If135fc32208c7031787e1935b399d930e0e1ea1f
Signed-off-by: Ole Troan <ot@cisco.com>
This commit is contained in:
Ole Troan
2016-04-09 03:16:30 +02:00
committed by Dave Wallace
parent 633951c3d8
commit 6855f6cdfe
60 changed files with 1333 additions and 10115 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ endif
@echo 'export PATH=$(BR)/tools/ccache-bin:$$PATH' >> $(BR)/path_setup
@echo 'export PATH=$(BR)/tools/bin:$$PATH' >> $(BR)/path_setup
@echo 'export CCACHE_DIR=$(CCACHE_DIR)' >> $(BR)/path_setup
ifeq ("$(wildcard /usr/bin/ccache )","")
@echo "WARNING: Please install ccache AYEC and re-run this script"
else
@@ -1,4 +1,4 @@
vpp-japi_configure_depend = \
vpp-api_configure_depend = \
vppinfra-install \
svm-install \
vlib-api-install \
@@ -6,7 +6,7 @@ vpp-japi_configure_depend = \
vnet-install \
vpp-install
vpp-japi_CPPFLAGS = $(call installed_includes_fn, \
vpp-api_CPPFLAGS = $(call installed_includes_fn, \
vppinfra \
svm \
vlib \
@@ -14,10 +14,10 @@ vpp-japi_CPPFLAGS = $(call installed_includes_fn, \
vnet \
vpp)
vpp-japi_LDFLAGS = $(call installed_libs_fn, \
vpp-api_LDFLAGS = $(call installed_libs_fn, \
vppinfra \
svm \
vlib \
vlib-api)
vpp-japi_CPPFLAGS += -I/usr/lib/jvm/java-7-openjdk-amd64/include
vpp-api_CPPFLAGS += -I/usr/lib/jvm/java-7-openjdk-amd64/include
+1 -1
View File
@@ -18,7 +18,7 @@ virl_native_tools = vppapigen
virl_uses_dpdk = yes
virl_root_packages = vpp vlib vlib-api vnet svm dpdk vpp-api-test \
vpp-japi
vpp-api
vpp_configure_args_virl = --with-dpdk
vnet_configure_args_virl = --with-dpdk --with-virl
+1 -1
View File
@@ -21,7 +21,7 @@ vpp_uses_dpdk = yes
# vpp_enable_tests = yes
vpp_root_packages = vpp vlib vlib-api vnet svm vpp-api-test \
vpp-japi gmod
vpp-api gmod
vpp_configure_args_vpp = --with-dpdk
vnet_configure_args_vpp = --with-dpdk
+1 -1
View File
@@ -18,7 +18,7 @@ vpp_lite_native_tools = vppapigen
vpp_lite_uses_dpdk = no
vpp_lite_root_packages = vpp vlib vlib-api vnet svm vpp-api-test \
vpp-japi gmod
vpp-api gmod
vlib_configure_args_vpp_lite = --with-pre-data=128
+7
View File
@@ -86,6 +86,13 @@ typedef struct vl_shmem_hdr_ {
} vl_shmem_hdr_t;
/* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */
typedef struct msgbuf_ {
unix_shared_memory_queue_t *q;
u32 data_len;
u8 data[0];
} msgbuf_t;
#define VL_SHM_VERSION 2
#define VL_API_EPOCH_MASK 0xFF
+6 -8
View File
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
@@ -38,11 +39,6 @@
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_typedefs
typedef struct msgbuf_ {
unix_shared_memory_queue_t *q;
u8 data[0];
} msgbuf_t;
static inline void *vl_msg_api_alloc_internal(int nbytes, int pool)
{
int i;
@@ -119,12 +115,13 @@ static inline void *vl_msg_api_alloc_internal(int nbytes, int pool)
pthread_mutex_lock (&am->vlib_rp->mutex);
oldheap = svm_push_data_heap (am->vlib_rp);
rv = clib_mem_alloc(nbytes + sizeof(msgbuf_t));
rv = clib_mem_alloc(nbytes);
rv->q = 0;
svm_pop_heap (oldheap);
pthread_mutex_unlock (&am->vlib_rp->mutex);
out:
rv->data_len = htonl(nbytes - sizeof(msgbuf_t));
return(rv->data);
}
@@ -152,7 +149,8 @@ void vl_msg_api_free(void *a)
void *oldheap;
api_main_t *am = &api_main;
rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv));
rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data));
/*
* Here's the beauty of the scheme. Only one proc/thread has
* control of a given message buffer. To free a buffer, we just clear the
@@ -176,7 +174,7 @@ static void vl_msg_api_free_nolock (void *a)
void *oldheap;
api_main_t *am = &api_main;
rv = (msgbuf_t *)(((u8 *)a) - sizeof(*rv));
rv = (msgbuf_t *)(((u8 *)a) - offsetof(msgbuf_t, data));
/*
* Here's the beauty of the scheme. Only one proc/thread has
* control of a given message buffer. To free a buffer, we just clear the
+141
View File
@@ -0,0 +1,141 @@
#!/usr/bin/env python
import time,argparse,sys,cmd, unittest
from ipaddress import *
parser = argparse.ArgumentParser(description='VPP MAP test')
parser.add_argument('-i', nargs='*', action="store", dest="inputdir")
args = parser.parse_args()
for dir in args.inputdir:
sys.path.append(dir)
from vpp_papi import *
#
# 1:1 Shared IPv4 address, shared BR (16) VPP CLI
#
def lw46_shared(ip4_pfx_str, ip6_pfx_str, ip6_src_str, ea_bits_len, psid_offset, psid_len, ip6_src_ecmp = False):
ip4_pfx = ip_network(ip4_pfx_str)
ip6_src = ip_address(ip6_src_str)
ip6_dst = ip_network(ip6_pfx_str)
ip6_nul = IPv6Address(u'0::0')
mod = ip4_pfx.num_addresses / 1024
for i in range(ip4_pfx.num_addresses):
a = time.clock()
t = map_add_domain(0, ip6_nul.packed, ip4_pfx[i].packed, ip6_src.packed, 0, 32, 128, ea_bits_len, psid_offset, psid_len, 0, 0)
#print "Return from map_add_domain", t
if t == None:
print "map_add_domain failed"
continue
if t.retval != 0:
print "map_add_domain failed", t
continue
for psid in range(0x1 << int(psid_len)):
r = map_add_del_rule(0, t.index, 1, (ip6_dst[(i * (0x1<<int(psid_len))) + psid]).packed, psid)
#print "Return from map_add_del_rule", r
if ip6_src_ecmp and not i % mod:
ip6_src = ip6_src + 1
print "Running time:", time.clock() - a
class TestMAP(unittest.TestCase):
'''
def test_delete_all(self):
t = map_domain_dump(0)
self.assertNotEqual(t, None)
print "Number of domains configured: ", len(t)
for d in t:
ts = map_del_domain(0, d.domainindex)
self.assertNotEqual(ts, None)
t = map_domain_dump(0)
self.assertNotEqual(t, None)
print "Number of domains configured: ", len(t)
self.assertEqual(len(t), 0)
'''
def test_a_million_rules(self):
ip4_pfx = u'192.0.2.0/24'
ip6_pfx = u'2001:db8::/32'
ip6_src = u'2001:db8::1'
psid_offset = 6
psid_len = 6
ea_bits_len = 0
lw46_shared(ip4_pfx, ip6_pfx, ip6_src, ea_bits_len, psid_offset, psid_len)
#
# RX thread, that should sit on blocking vpe_api_read()
#
#
#
#
import threading
class RXThread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
print "Starting "
i = 0
while True:
msg = vpe_api_read()
if msg:
#print msg
id = unpack('>H', msg[0:2])
size = unpack('>H', msg[2:4])
print "Received", id, "of size", size
i += 1
#del msg
continue
#time.sleep(0.001)
return
# Create RX thread
rxthread = RXThread()
rxthread.setDaemon(True)
print "Connect", connect_to_vpe("client124")
import timeit
rxthread.start()
print "After thread started"
#pneum_kill_thread()
print "After thread killed"
#t = show_version(0)
#print "Result from show version", t
print timeit.timeit('t = show_version(0)', number=1000, setup="from __main__ import show_version")
time.sleep(10)
#print timeit.timeit('control_ping(0)', number=10, setup="from __main__ import control_ping")
disconnect_from_vpe()
sys.exit()
print t.program, t.version,t.builddate,t.builddirectory
'''
t = map_domain_dump(0)
if not t:
print('show map domain failed')
for d in t:
print("IP6 prefix:",str(IPv6Address(d.ip6prefix)))
print( "IP4 prefix:",str(IPv4Address(d.ip4prefix)))
'''
suite = unittest.TestLoader().loadTestsFromTestCase(TestMAP)
unittest.TextTestRunner(verbosity=2).run(suite)
disconnect_from_vpe()
+2
View File
@@ -0,0 +1,2 @@
AUTOMAKE_OPTIONS = foreign
SUBDIRS = java python
+15
View File
@@ -0,0 +1,15 @@
AC_INIT(vpp-api, 1.0.0)
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SUBDIRS([java])
AM_INIT_AUTOMAKE
AM_SILENT_RULES
AM_PROG_AS
AC_PROG_CC
AM_PROG_CC_C_O
AC_OUTPUT([python/Makefile])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
@@ -54,7 +54,7 @@ japi/org_openvpp_vppjapi_vppConn.h: \
japi/org/openvpp/vppjapi/vppVxlanTunnelDetails.java \
japi/org/openvpp/vppjapi/vppConn.java \
japi/org/openvpp/vppjapi/vppApiCallbacks.java \
../vpp/api/vpe.api.h
../../vpp/api/vpe.api.h
$(JAVAC) -classpath . -d . @srcdir@/japi/org/openvpp/vppjapi/vppVersion.java ; \
$(JAVAH) -classpath . -d japi org.openvpp.vppjapi.vppVersion ; \
$(JAVAC) -classpath . -d . @srcdir@/japi/org/openvpp/vppjapi/vppInterfaceDetails.java ; \
@@ -79,8 +79,8 @@ japi/org_openvpp_vppjapi_vppConn.h: \
japi/vppapi.c: japi/org_openvpp_vppjapi_vppConn.h
pushd .. ; dir=`pwd` ; popd ; \
instdir=`echo $${dir} | sed -e 's:build-root/build:build-root/install:'` ; \
vppapigen --input $${instdir}/vpp/api/vpe.api --jni japi/vppapi.c --app vpe ; \
vppapigen --input $${instdir}/vpp/api/vpe.api --java japi/vppApi.java --app vpe ; \
vppapigen --input $${instdir}/../vpp/api/vpe.api --jni japi/vppapi.c --app vpe ; \
vppapigen --input $${instdir}/../vpp/api/vpe.api --java japi/vppApi.java --app vpe ; \
$(JAVAC) -classpath . -d . japi/vppApi.java ; \
$(JAVAH) -classpath . -d japi org.openvpp.vppjapi.vppApi ; \
$(JAVAC) -classpath . -d . @srcdir@/japi/org/openvpp/vppjapi/vppApiCallbacks.java ; \

Some files were not shown because too many files have changed in this diff Show More