Cleanup URI code and TCP bugfixing
[vpp.git] / src / vnet / tcp / builtin_server.c
1 /*
2 * Copyright (c) 2015-2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <vnet/vnet.h>
17 #include <vlibmemory/api.h>
18 #include <vnet/session/application.h>
19 #include <vnet/session/application_interface.h>
20
21 int
22 builtin_session_accept_callback (stream_session_t * s)
23 {
24   clib_warning ("called...");
25   s->session_state = SESSION_STATE_READY;
26   return 0;
27 }
28
29 void
30 builtin_session_disconnect_callback (stream_session_t * s)
31 {
32   clib_warning ("called...");
33 }
34
35 int
36 builtin_session_connected_callback (u32 client_index,
37                                     stream_session_t * s, u8 is_fail)
38 {
39   clib_warning ("called...");
40   return -1;
41 }
42
43 int
44 builtin_add_segment_callback (u32 client_index,
45                               const u8 * seg_name, u32 seg_size)
46 {
47   clib_warning ("called...");
48   return -1;
49 }
50
51 int
52 builtin_redirect_connect_callback (u32 client_index, void *mp)
53 {
54   clib_warning ("called...");
55   return -1;
56 }
57
58 int
59 builtin_server_rx_callback (stream_session_t * s)
60 {
61   clib_warning ("called...");
62   return 0;
63 }
64
65 static session_cb_vft_t builtin_session_cb_vft = {
66   .session_accept_callback = builtin_session_accept_callback,
67   .session_disconnect_callback = builtin_session_disconnect_callback,
68   .session_connected_callback = builtin_session_connected_callback,
69   .add_segment_callback = builtin_add_segment_callback,
70   .redirect_connect_callback = builtin_redirect_connect_callback,
71   .builtin_server_rx_callback = builtin_server_rx_callback
72 };
73
74 static int
75 server_create (vlib_main_t * vm)
76 {
77   vnet_bind_args_t _a, *a = &_a;
78   u64 options[SESSION_OPTIONS_N_OPTIONS];
79   char segment_name[128];
80
81   memset (a, 0, sizeof (*a));
82   memset (options, 0, sizeof (options));
83
84   a->uri = "tcp://0.0.0.0/80";
85   a->api_client_index = ~0;
86   a->session_cb_vft = &builtin_session_cb_vft;
87   a->options = options;
88   a->options[SESSION_OPTIONS_SEGMENT_SIZE] = 256 << 10;
89   a->options[SESSION_OPTIONS_RX_FIFO_SIZE] = 64 << 10;
90   a->options[SESSION_OPTIONS_TX_FIFO_SIZE] = 64 << 10;
91   a->segment_name = segment_name;
92   a->segment_name_length = ARRAY_LEN (segment_name);
93
94   return vnet_bind_uri (a);
95 }
96
97 static clib_error_t *
98 server_create_command_fn (vlib_main_t * vm,
99                           unformat_input_t * input, vlib_cli_command_t * cmd)
100 {
101   int rv;
102 #if 0
103   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
104     {
105       if (unformat (input, "whatever %d", &whatever))
106         ;
107       else
108         return clib_error_return (0, "unknown input `%U'",
109                                   format_unformat_error, input);
110     }
111 #endif
112
113   rv = server_create (vm);
114   switch (rv)
115     {
116     case 0:
117       break;
118     default:
119       return clib_error_return (0, "server_create returned %d", rv);
120     }
121   return 0;
122 }
123
124 VLIB_CLI_COMMAND (server_create_command, static) =
125 {
126 .path = "test server",.short_help = "test server",.function =
127     server_create_command_fn,};
128
129 /*
130 * fd.io coding-style-patch-verification: ON
131 *
132 * Local Variables:
133 * eval: (c-set-style "gnu")
134 * End:
135 */