2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vlib/vlib.h>
16 #include <vlib/unix/unix.h>
17 #include <vnet/pg/pg.h>
18 #include <vnet/ethernet/ethernet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ip/tcp.h>
22 #include <vlib/unix/cj.h>
27 vnet_example_init (vlib_main_t * vm)
29 clib_error_t * error = 0;
31 /* Due to crude comment-out of eliot's smp stuff */
32 vm->heap_size = 256<<20;
34 if ((error = vlib_call_init_function (vm, pg_init)))
36 if ((error = vlib_call_init_function (vm, ip_main_init)))
38 if ((error = vlib_call_init_function (vm, ethernet_init)))
40 if ((error = vlib_call_init_function (vm, ethernet_arp_init)))
42 if ((error = vlib_call_init_function (vm, osi_init)))
44 if ((error = vlib_call_init_function (vm, srp_init)))
47 if ((error = vlib_call_init_function (vm, ixge_init)))
49 if ((error = vlib_call_init_function (vm, ixgev_init)))
51 if ((error = vlib_call_init_function (vm, ige_init)))
54 if ((error = vlib_call_init_function (vm, dpdk_init)))
58 if ((error = vlib_call_init_function (vm, dhcp_proxy_init)))
60 if ((error = vlib_call_init_function (vm, mpls_init)))
62 if ((error = vlib_call_init_function (vm, mpls_interface_init)))
65 if ((error = vlib_call_init_function (vm, l2_init)))
67 if ((error = vlib_call_init_function (vm, l2tp_init)))
70 if ((error = unix_physmem_init (vm, /* physical_memory_required */ 0)))
73 if ((error = unix_physmem_init (vm, /* physical_memory_required */ 0)))
76 if ((error = vlib_call_init_function (vm, tuntap_init)))
79 vlib_unix_cli_set_prompt ("VNET: ");
84 VLIB_INIT_FUNCTION (vnet_example_init);
86 int main (int argc, char * argv[])
88 clib_mem_init (0, (2ULL << 30));
89 return vlib_unix_main (argc, argv);
93 #define foreach_tcp_test_error \
94 _ (SEGMENTS_RECEIVED, "segments received")
97 #define _(sym,str) TCP_TEST_ERROR_##sym,
98 foreach_tcp_test_error
103 static char * tcp_test_error_strings[] = {
104 #define _(sym,string) string,
105 foreach_tcp_test_error
110 tcp_test (vlib_main_t * vm,
111 vlib_node_runtime_t * node,
112 vlib_frame_t * frame)
114 uword n_packets = frame->n_vectors;
115 u32 * from, * to_next;
116 u32 n_left_from, n_left_to_next, next;
118 from = vlib_frame_vector_args (frame);
119 n_left_from = n_packets;
120 next = node->cached_next_index;
122 while (n_left_from > 0)
124 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
126 while (n_left_from > 0 && n_left_to_next > 0)
132 bi0 = to_next[0] = from[0];
139 p0 = vlib_get_buffer (vm, bi0);
141 clib_warning ("got '%U'", format_vlib_buffer_contents, vm, p0);
144 p0->error = node->errors[error0];
146 if (PREDICT_FALSE (next0 != next))
151 vlib_put_next_frame (vm, node, next, n_left_to_next);
154 vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
161 vlib_put_next_frame (vm, node, next, n_left_to_next);
164 return frame->n_vectors;
167 VLIB_REGISTER_NODE (tcp_test_node) = {
168 .function = tcp_test,
171 .vector_size = sizeof (u32),
178 .n_errors = TCP_TEST_N_ERROR,
179 .error_strings = tcp_test_error_strings,
182 static clib_error_t *
183 tcp_test_init (vlib_main_t * vm)
185 clib_error_t * error = 0;
188 tcp_listener_registration_t r = {
190 .flags = TCP_LISTENER_IP4,
191 .data_node_index = tcp_test_node.index,
195 tcp_register_listener (vm, &r);
201 VLIB_INIT_FUNCTION (tcp_test_init);