aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_jvpp.py
blob: 2497ff680a4cb4c7d1e11c679bc205c5bbf3ab1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python

import os
import subprocess

from framework import VppTestCase

# Api files path
API_FILES_PATH = "vpp/vpp-api/java"

# Registry jar file name prefix
REGISTRY_JAR_PREFIX = "jvpp-registry"


class TestJVpp(VppTestCase):
    """ JVPP Core Test Case """

    def invoke_for_jvpp_core(self, api_jar_name, test_class_name):
        self.jvpp_connection_test(api_jar_name=api_jar_name,
                                  test_class_name=test_class_name,
                                  timeout=10)

    def test_vpp_core_callback_api(self):
        """ JVPP Core Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-core",
                                  test_class_name="io.fd.vpp.jvpp.core.test."
                                                  "CallbackApiTest")

    def test_vpp_core_future_api(self):
        """JVPP Core Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-core",
                                  test_class_name="io.fd.vpp.jvpp.core.test."
                                                  "FutureApiTest")

    def test_vpp_acl_callback_api(self):
        """ JVPP Acl Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-acl",
                                  test_class_name="io.fd.vpp.jvpp.acl.test."
                                                  "CallbackApiTest")

    def test_vpp_acl_future_api(self):
        """JVPP Acl Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-acl",
                                  test_class_name="io.fd.vpp.jvpp.acl.test."
                                                  "FutureApiTest")

    def test_vpp_ioamexport_callback_api(self):
        """ JVPP Ioamexport Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport",
                                  test_class_name="io.fd.vpp.jvpp.ioamexport."
                                                  "test.CallbackApiTest")

    def test_vpp_ioamexport_future_api(self):
        """JVPP Ioamexport Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamexport",
                                  test_class_name="io.fd.vpp.jvpp.ioamexport."
                                                  "test.FutureApiTest")

    def test_vpp_ioampot_callback_api(self):
        """ JVPP Ioampot Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot",
                                  test_class_name="io.fd.vpp.jvpp.ioampot."
                                                  "test.CallbackApiTest")

    def test_vpp_ioampot_future_api(self):
        """JVPP Ioampot Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioampot",
                                  test_class_name="io.fd.vpp.jvpp.ioampot."
                                                  "test.FutureApiTest")

    def test_vpp_ioamtrace_callback_api(self):
        """ JVPP Ioamtrace Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace",
                                  test_class_name="io.fd.vpp.jvpp.ioamtrace."
                                                  "test.CallbackApiTest")

    def test_vpp_ioamtrace_future_api(self):
        """JVPP Ioamtrace Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-ioamtrace",
                                  test_class_name="io.fd.vpp.jvpp.ioamtrace."
                                                  "test.FutureApiTest")

    def test_vpp_snat_callback_api(self):
        """ JVPP Snat Callback Api Test Case """
        self.invoke_for_jvpp_core(api_jar_name="jvpp-nat",
                                  test_class_name="io.fd.vpp.jvpp.nat.test."
                                                  "CallbackApiTest")

    def test_vpp_snat_future_api(self):
        """JVPP Snat Future Api Test Case"""
        self.invoke_for_jvpp_core(api_jar_name="jvpp-nat",
                                  test_class_name="io.fd.vpp.jvpp.nat.test."
                                                  "FutureApiTest")

    def full_jar_name(self, install_dir, jar_name, version):
        return os.path.join(install_dir, API_FILES_PATH,
                            "{0}-{1}.jar".format(jar_name, version))

    def jvpp_connection_test(self, api_jar_name, test_class_name, timeout):
        install_dir = os.getenv('VPP_TEST_BUILD_DIR')
        self.logger.info("Install directory : {0}".format(install_dir))

        version_reply = self.vapi.show_version()
        version = version_reply.version.split("-")[0]
        registry_jar_path = self.full_jar_name(install_dir,
                                               REGISTRY_JAR_PREFIX, version)
        self.logger.info("JVpp Registry jar path : {0}"
                         .format(registry_jar_path))

        api_jar_path = self.full_jar_name(install_dir, api_jar_name, version)
        self.logger.info("Api jar path : {0}".format(api_jar_path))

        # passes shm prefix as parameter to create connection with same value
        command = ["java", "-cp",
                   "{0}:{1}".format(registry_jar_path, api_jar_path),
                   test_class_name, "/{0}-vpe-api".format(self.shm_prefix)]
        self.logger.info("Test Command : {0}, Timeout : {1}".
                         format(command, timeout))

        self.process = subprocess.Popen(command, shell=False,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE, bufsize=1,
                                        universal_newlines=True)

        out, err = self.process.communicate()
        self.logger.info("Process output : {0}{1}".format(os.linesep, out))
        self.logger.info("Process error output : {0}{1}"
                         .format(os.linesep, err))
        self.assert_equal(self.process.returncode, 0, "process return code")

    def tearDown(self):
        self.logger.info("Tearing down jvpp test")
        super(TestJVpp, self).tearDown()
        if hasattr(self, 'process') and self.process.poll() is None:
            self.process.kill()
pan> clib_time; /* State of the connection, shared between msg RX thread and main thread */ volatile app_state_t app_state; vppcom_cfg_t cfg; /* Event thread */ vce_event_thread_t event_thread; /* IO thread */ vppcom_session_io_thread_t session_io_thread; #ifdef VCL_ELOG /* VPP Event-logger */ elog_main_t elog_main; elog_track_t elog_track; #endif /* VNET_API_ERROR_FOO -> "Foo" hash table */ uword *error_string_by_error_number; } vppcom_main_t; extern vppcom_main_t *vcm; #define VCL_SESSION_LOCK_AND_GET(I, S) \ do { \ clib_spinlock_lock (&vcm->sessions_lockp); \ rv = vppcom_session_at_index (I, S); \ if (PREDICT_FALSE (rv)) \ { \ clib_spinlock_unlock (&vcm->sessions_lockp); \ clib_warning ("VCL<%d>: ERROR: Invalid ##I (%u)!", \ getpid (), I); \ goto done; \ } \ } while (0) #define VCL_SESSION_LOCK() clib_spinlock_lock (&(vcm->sessions_lockp)) #define VCL_SESSION_UNLOCK() clib_spinlock_unlock (&(vcm->sessions_lockp)) #define VCL_IO_SESSIONS_LOCK() \ clib_spinlock_lock (&(vcm->session_io_thread.io_sessions_lockp)) #define VCL_IO_SESSIONS_UNLOCK() \ clib_spinlock_unlock (&(vcm->session_io_thread.io_sessions_lockp)) #define VCL_ACCEPT_FIFO_LOCK() clib_spinlock_lock (&(vcm->session_fifo_lockp)) #define VCL_ACCEPT_FIFO_UNLOCK() \ clib_spinlock_unlock (&(vcm->session_fifo_lockp)) #define VCL_EVENTS_LOCK() \ clib_spinlock_lock (&(vcm->event_thread.events_lockp)) #define VCL_EVENTS_UNLOCK() \ clib_spinlock_unlock (&(vcm->event_thread.events_lockp)) static inline int vppcom_session_at_index (u32 session_index, vcl_session_t * volatile *sess) { /* Assumes that caller has acquired spinlock: vcm->sessions_lockp */ if (PREDICT_FALSE ((session_index == ~0) || pool_is_free_index (vcm->sessions, session_index))) { clib_warning ("VCL<%d>: invalid session, sid (%u) has been closed!", getpid (), session_index); return VPPCOM_EBADFD; } *sess = pool_elt_at_index (vcm->sessions, session_index); return VPPCOM_OK; } static inline void vppcom_session_table_add_listener (u64 listener_handle, u32 value) { /* Session and listener handles have different formats. The latter has * the thread index in the upper 32 bits while the former has the session * type. Knowing that, for listeners we just flip the MSB to 1 */ listener_handle |= 1ULL << 63; hash_set (vcm->session_index_by_vpp_handles, listener_handle, value); } static inline vcl_session_t * vppcom_session_table_lookup_listener (u64 listener_handle) { uword *p; u64 handle = listener_handle | (1ULL << 63); vcl_session_t *session; p = hash_get (vcm->session_index_by_vpp_handles, handle); if (!p) { clib_warning ("VCL<%d>: couldn't find listen session: unknown vpp " "listener handle %llx", getpid (), listener_handle); return 0; } if (pool_is_free_index (vcm->sessions, p[0])) { VDBG (1, "VCL<%d>: invalid listen session, sid (%u)", getpid (), p[0]); return 0; } session = pool_elt_at_index (vcm->sessions, p[0]); ASSERT (session->session_state & STATE_LISTEN); return session; } const char *vppcom_session_state_str (session_state_t state); /* * VCL Binary API */ int vppcom_connect_to_vpp (char *app_name); void vppcom_init_error_string_table (void); void vppcom_send_session_enable_disable (u8 is_enable); void vppcom_app_send_attach (void); void vppcom_app_send_detach (void); void vppcom_send_connect_sock (vcl_session_t * session, u32 session_index); void vppcom_send_disconnect_session_reply (u64 vpp_handle, u32 session_index, int rv); void vppcom_send_disconnect_session (u64 vpp_handle, u32 session_index); void vppcom_send_bind_sock (vcl_session_t * session, u32 session_index); void vppcom_send_unbind_sock (u64 vpp_handle); void vppcom_api_hookup (void); void vppcom_send_accept_session_reply (u64 handle, u32 context, int retval); u32 vcl_max_nsid_len (void); #endif /* SRC_VCL_VCL_PRIVATE_H_ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */