summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vlib-api.am4
-rw-r--r--src/vlibsocket/api.h87
-rw-r--r--src/vlibsocket/sock_test.c155
-rw-r--r--src/vlibsocket/sockclnt_vlib.c209
4 files changed, 0 insertions, 455 deletions
diff --git a/src/vlib-api.am b/src/vlib-api.am
index f1fdb8d2228..4c732b0c9eb 100644
--- a/src/vlib-api.am
+++ b/src/vlib-api.am
@@ -64,10 +64,6 @@ BUILT_SOURCES += \
vlibmemory/memclnt.api.h \
vlibmemory/memclnt.api.json
-noinst_PROGRAMS += sock_test
-
-sock_test_SOURCES = vlibsocket/sock_test.c
-
API_FILES += vlibmemory/memclnt.api
# vi:syntax=automake
diff --git a/src/vlibsocket/api.h b/src/vlibsocket/api.h
deleted file mode 100644
index d7b7055d596..00000000000
--- a/src/vlibsocket/api.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *------------------------------------------------------------------
- * api.h
- *
- * Copyright (c) 2009 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
- */
-
-#ifndef included_vlibsocket_api_h
-#define included_vlibsocket_api_h
-
-#include <vlibapi/api.h>
-
-typedef struct
-{
- /* Server port number */
- int portno;
-
- /* By default, localhost... */
- u32 bind_address;
-
- /*
- * (listen, server, client) registrations. Shared memory
- * registrations are in shared memory
- */
- vl_api_registration_t *registration_pool;
- /*
- * Chain-drag variables, so message API handlers
- * (generally) don't know whether they're talking to a socket
- * or to a shared-memory connection.
- */
- vl_api_registration_t *current_rp;
- clib_file_t *current_uf;
- /* One input buffer, shared across all sockets */
- i8 *input_buffer;
-} socket_main_t;
-
-extern socket_main_t socket_main;
-
-void socksvr_add_pending_output (clib_file_t * uf,
- struct vl_api_registration_ *cf,
- u8 * buffer, uword buffer_bytes);
-
-#define SOCKSVR_DEFAULT_PORT 32741 /* whatever */
-
-void vl_free_socket_registration_index (u32 pool_index);
-void vl_socket_process_msg (clib_file_t * uf,
- struct vl_api_registration_ *rp, i8 * input_v);
-clib_error_t *vl_socket_read_ready (clib_file_t * uf);
-void vl_socket_add_pending_output (clib_file_t * uf,
- struct vl_api_registration_ *rp,
- u8 * buffer, uword buffer_bytes);
-clib_error_t *vl_socket_write_ready (clib_file_t * uf);
-void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
-void vl_socket_api_send_with_data (vl_api_registration_t * rp,
- u8 * elem, u8 * data_vector);
-void vl_socket_api_send_with_length (vl_api_registration_t * rp,
- u8 * elem, u32 msg_length);
-void vl_socket_api_send_with_length_no_free (vl_api_registration_t * rp,
- u8 * elem, u32 msg_length);
-u32 sockclnt_open_index (char *client_name, char *hostname, int port);
-void sockclnt_close_index (u32 index);
-void vl_client_msg_api_send (vl_api_registration_t * cm, u8 * elem);
-vl_api_registration_t *sockclnt_get_registration (u32 index);
-void socksvr_set_port (u16 port);
-void socksvr_set_bind_address (u32 bind_address);
-
-#endif /* included_vlibsocket_api_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vlibsocket/sock_test.c b/src/vlibsocket/sock_test.c
deleted file mode 100644
index e563b9a8d61..00000000000
--- a/src/vlibsocket/sock_test.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-
-#define SOCKCLNT_SERVER_PORT 1234 /* whatever */
-
-typedef signed char i8;
-typedef signed short i16;
-typedef signed int i32;
-typedef signed long long i64;
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long long u64;
-typedef unsigned long uword;
-
-#define VL_API_PACKED(x) x __attribute__ ((packed))
-
-typedef VL_API_PACKED (struct _vl_api_sockclnt_create
- {
- u16 _vl_msg_id; u8 name[64];
- u32 context;
- }) vl_api_sockclnt_create_t;
-
-typedef VL_API_PACKED (struct _vl_api_sockclnt_create_reply
- {
- u16 _vl_msg_id;
- i32 response; u64 handle; u32 index; u32 context;
- }) vl_api_sockclnt_create_reply_t;
-
-typedef VL_API_PACKED (struct _vl_api_sockclnt_delete
- {
- u16 _vl_msg_id; u32 index;
- u64 handle;
- }) vl_api_sockclnt_delete_t;
-
-typedef VL_API_PACKED (struct _vl_api_sockclnt_delete_reply
- {
- u16 _vl_msg_id; i32 response; u64 handle;
- }) vl_api_sockclnt_delete_reply_t;
-
-void
-error (char *msg)
-{
- perror (msg);
- exit (0);
-}
-
-int
-main (int argc, char *argv[])
-{
- int sockfd, portno, n;
- struct sockaddr_in serv_addr;
- struct hostent *server;
- char buffer[256];
- int i;
- u32 nbytes;
- vl_api_sockclnt_create_t *mp;
- vl_api_sockclnt_create_reply_t *rp;
- char *rdptr;
- int total_bytes;
-
- for (i = 0; i < 1; i++)
- {
- portno = SOCKCLNT_SERVER_PORT;
- sockfd = socket (AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0)
- error ("ERROR opening socket");
- server = gethostbyname ("localhost");
- if (server == NULL)
- {
- fprintf (stderr, "ERROR, no such host\n");
- exit (0);
- }
- bzero ((char *) &serv_addr, sizeof (serv_addr));
- serv_addr.sin_family = AF_INET;
- bcopy ((char *) server->h_addr,
- (char *) &serv_addr.sin_addr.s_addr, server->h_length);
- serv_addr.sin_port = htons (portno);
- if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
- error ("ERROR connecting");
-
- memset (buffer, 0, sizeof (buffer));
-
- mp = (vl_api_sockclnt_create_t *) buffer;
- mp->_vl_msg_id = ntohs (13); /* VL_API_SOCKCLNT_CREATE */
- strncpy ((char *) mp->name, "socket-test", sizeof (mp->name) - 1);
- mp->name[sizeof (mp->name) - 1] = 0;
- mp->context = 0xfeedface;
- /* length of the message, including the length itself */
- nbytes = sizeof (*mp) + sizeof (nbytes);
- nbytes = ntohl (nbytes);
- n = write (sockfd, &nbytes, sizeof (nbytes));
- if (n < 0)
- error ("ERROR writing len to socket");
- n = write (sockfd, mp, sizeof (*mp));
- if (n < 0)
- error ("ERROR writing msg to socket");
-
- memset (buffer, 0, sizeof (buffer));
-
- total_bytes = 0;
- rdptr = buffer;
- do
- {
- n = read (sockfd, rdptr, sizeof (buffer) - (rdptr - buffer));
- if (n < 0)
- error ("ERROR reading from socket");
- printf ("read %d bytes\n", n);
- total_bytes += n;
- rdptr += n;
- }
- while (total_bytes < sizeof (vl_api_sockclnt_create_reply_t) + 4);
-
- rp = (vl_api_sockclnt_create_reply_t *) (buffer + 4);
- /* VL_API_SOCKCLNT_CREATE_REPLY */
- if (ntohs (rp->_vl_msg_id) != 14)
- {
- printf ("WARNING: msg id %d\n", ntohs (rp->_vl_msg_id));
- }
-
- printf ("response %d, handle 0x%llx, index %d, context 0x%x\n",
- ntohl (rp->response), rp->handle, rp->index, rp->context);
- close (sockfd);
- }
- return 0;
-}
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vlibsocket/sockclnt_vlib.c b/src/vlibsocket/sockclnt_vlib.c
deleted file mode 100644
index 34470c56266..00000000000
--- a/src/vlibsocket/sockclnt_vlib.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- *------------------------------------------------------------------
- * sockclnt_vlib.c
- *
- * Copyright (c) 2009 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <sys/ioctl.h>
-#include <vppinfra/byte_order.h>
-#include <netdb.h>
-
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#include <vlibmemory/api.h>
-
-
-#include <vlibmemory/vl_memory_msg_enum.h>
-
-#define vl_typedefs /* define message structures */
-#include <vlibmemory/vl_memory_api_h.h>
-#undef vl_typedefs
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vlibmemory/vl_memory_api_h.h>
-#undef vl_printfun
-
-/* instantiate all the endian swap functions we know about */
-#define vl_endianfun
-#include <vlibmemory/vl_memory_api_h.h>
-#undef vl_endianfun
-
-static void
-vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
-{
- vl_api_registration_t *rp = socket_main.current_rp;
-
- rp->server_handle = mp->handle;
- rp->server_index = mp->index;
-}
-
-static void
-vl_api_sockclnt_delete_reply_t_handler (vl_api_sockclnt_delete_reply_t * mp)
-{
- clib_file_main_t *fm = &file_main;
- clib_file_t *uf = socket_main.current_uf;
- vl_api_registration_t *rp = socket_main.current_rp;
-
- clib_file_del (fm, uf);
- vl_socket_free_registration_index (rp->vl_api_registration_pool_index);
-}
-
-u32
-sockclnt_open_index (char *client_name, char *hostname, int port)
-{
- vl_api_registration_t *rp;
- clib_file_main_t *fm = &file_main;
- clib_file_t template = { 0 };
- int sockfd;
- int one = 1;
- int rv;
- struct sockaddr_in serv_addr;
- struct hostent *server;
- vl_api_sockclnt_create_t *mp;
- char my_hostname[64];
-
- server = gethostbyname (hostname);
- if (server == NULL)
- {
- clib_warning ("Couldn't translate server name %s", hostname);
- return ~0;
- }
-
- /* Set up non-blocking server socket on CLIENT_API_SERVER_PORT */
- sockfd = socket (AF_INET, SOCK_STREAM, 0);
-
- if (sockfd < 0)
- {
- clib_unix_warning ("socket");
- return ~0;
- }
-
- bzero ((char *) &serv_addr, sizeof (serv_addr));
- serv_addr.sin_family = AF_INET;
- bcopy ((char *) server->h_addr,
- (char *) &serv_addr.sin_addr.s_addr, server->h_length);
- serv_addr.sin_port = htons (port);
-
- if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
- {
- clib_unix_warning ("Connect failure to (%s, %d)", hostname, port);
- close (sockfd);
- return ~0;
- }
-
- rv = ioctl (sockfd, FIONBIO, &one);
- if (rv < 0)
- {
- clib_unix_warning ("FIONBIO");
- close (sockfd);
- return ~0;
- }
-
- pool_get (socket_main.registration_pool, rp);
- memset (rp, 0, sizeof (*rp));
- rp->registration_type = REGISTRATION_TYPE_SOCKET_CLIENT;
- rp->vl_api_registration_pool_index = rp - socket_main.registration_pool;
-
- template.read_function = vl_socket_read_ready;
- template.write_function = vl_socket_write_ready;
- template.file_descriptor = sockfd;
- template.private_data = rp - socket_main.registration_pool;
-
- rp->clib_file_index = clib_file_add (fm, &template);
- rp->name = format (0, "%s:%d", hostname, port);
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_CREATE);
- mp->context = rp - socket_main.registration_pool;
-
- if (gethostname (my_hostname, sizeof (my_hostname)) < 0)
- {
- clib_unix_warning ("gethostname");
- strncpy (my_hostname, "unknown!", sizeof (my_hostname) - 1);
- }
- strncpy ((char *) mp->name, my_hostname, sizeof (mp->name) - 1);
-
- vl_api_send_msg (rp, (u8 *) mp);
- return rp - socket_main.registration_pool;
-}
-
-void
-sockclnt_close_index (u32 index)
-{
- vl_api_sockclnt_delete_t *mp;
- vl_api_registration_t *rp;
-
- /* Don't crash / assert if fed garbage */
- if (pool_is_free_index (socket_main.registration_pool, index))
- {
- clib_warning ("registration_pool index %d already free", index);
- return;
- }
- rp = pool_elt_at_index (socket_main.registration_pool, index);
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_DELETE);
- mp->handle = rp->server_handle;
- mp->index = rp->server_index;
- vl_api_send_msg (rp, (u8 *) mp);
-}
-
-vl_api_registration_t *
-sockclnt_get_registration (u32 index)
-{
- return pool_elt_at_index (socket_main.registration_pool, index);
-}
-
-/*
- * Both rx and tx msgs MUST be initialized, or we'll have
- * precisely no idea how many bytes to write into the API trace...
- */
-#define foreach_sockclnt_api_msg \
-_(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \
-_(SOCKCLNT_DELETE_REPLY, sockclnt_delete_reply)
-
-
-static clib_error_t *
-sockclnt_vlib_api_init (vlib_main_t * vm)
-{
-#define _(N,n) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_sockclnt_api_msg;
-#undef _
- return 0;
-}
-
-VLIB_API_INIT_FUNCTION (sockclnt_vlib_api_init);
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */