blob: 9f049bda5974400f9f543f63c8db5daf89ad9d9c [file] [log] [blame]
Florin Coras6792ec02017-03-13 03:49:51 -07001/*
2 * Copyright (c) 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 <stdio.h>
17#include <sys/types.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <netdb.h>
21#include <vppinfra/format.h>
22
23int
24main (int argc, char *argv[])
25{
26 int sockfd, portno, n;
27 struct sockaddr_in serv_addr;
28 struct hostent *server;
29 u8 *rx_buffer = 0, *tx_buffer = 0;
30 u32 offset;
31 int iter, i;
32 if (0 && argc < 3)
33 {
34 fformat (stderr, "usage %s hostname port\n", argv[0]);
35 exit (0);
36 }
37
38 portno = 1234; // atoi(argv[2]);
39 sockfd = socket (AF_INET, SOCK_STREAM, 0);
40 if (sockfd < 0)
41 {
42 clib_unix_error ("socket");
43 exit (1);
44 }
45 server = gethostbyname ("6.0.1.1" /* argv[1] */ );
46 if (server == NULL)
47 {
48 clib_unix_warning ("gethostbyname");
49 exit (1);
50 }
51 bzero ((char *) &serv_addr, sizeof (serv_addr));
52 serv_addr.sin_family = AF_INET;
53 bcopy ((char *) server->h_addr,
54 (char *) &serv_addr.sin_addr.s_addr, server->h_length);
55 serv_addr.sin_port = htons (portno);
56 if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
57 {
58 clib_unix_warning ("connect");
59 exit (1);
60 }
61
62 vec_validate (rx_buffer, 1400);
63 vec_validate (tx_buffer, 1400);
64
65 for (i = 0; i < vec_len (tx_buffer); i++)
66 tx_buffer[i] = (i + 1) % 0xff;
67
68 /*
69 * Send one packet to warm up the RX pipeline
70 */
71 n = send (sockfd, tx_buffer, vec_len (tx_buffer), 0 /* flags */ );
72 if (n != vec_len (tx_buffer))
73 {
74 clib_unix_warning ("write");
75 exit (0);
76 }
77
78 for (iter = 0; iter < 100000; iter++)
79 {
80 if (iter < 99999)
81 {
82 n = send (sockfd, tx_buffer, vec_len (tx_buffer), 0 /* flags */ );
83 if (n != vec_len (tx_buffer))
84 {
85 clib_unix_warning ("write");
86 exit (0);
87 }
88 }
89 offset = 0;
90
91 do
92 {
93 n = recv (sockfd, rx_buffer + offset,
94 vec_len (rx_buffer) - offset, 0 /* flags */ );
95 if (n < 0)
96 {
97 clib_unix_warning ("read");
98 exit (0);
99 }
100 offset += n;
101 }
102 while (offset < vec_len (rx_buffer));
103
104 for (i = 0; i < vec_len (rx_buffer); i++)
105 {
106 if (rx_buffer[i] != tx_buffer[i])
107 {
108 clib_warning ("[%d] read 0x%x not 0x%x",
109 rx_buffer[i], tx_buffer[i]);
110 exit (1);
111 }
112 }
113
114 }
115 close (sockfd);
116 return 0;
117}
118
119
120/*
121 * fd.io coding-style-patch-verification: ON
122 *
123 * Local Variables:
124 * eval: (c-set-style "gnu")
125 * End:
126 */