Main testbench and user-application for mceuropeanengine on host. Client
90 if ((argc < 3) || (argc > 4)) {
91 cerr <<
"Usage: " << argv[0] <<
" <Server> <Server Port> \n";
103 string s_servAddress = argv[1];
104 char *s_servPort = argv[2];
107 string servAddress = s_servAddress;
108 unsigned short servPort;
110 if (net_type ==
udp) {
111 servPort = Socket::resolveService(s_servPort,
"udp");
113 else if (net_type ==
tcp) {
114 servPort = atoi(s_servPort);
117 cout <<
"ERROR: Invalid type of socket type provided: " << net_type <<
" Choosed one of (tcp=0 or udp=1)" << endl;
120 if ((servPort <= 0) || (servPort <= 1024) || (servPort >= 65536)) {
121 cerr <<
"ERROR: Invalid port number " << servPort <<
122 ". Please select a value at range [1025-65535]. Aborting..." << endl;
127 unsigned int recvMsgSize;
129 std::string input_string;
140 #if (NET_TYPE == udp)
141 #ifndef TB_SIM_CFP_VITIS
142 UDPSocket udpsock(servPort);
149 TCPSocket tcpsock(servAddress, servPort);
168 instruct.
seed = 4332 ;
190 clock_t start_cycle_main =
clock();
191 cout <<
" ___________________________________________________________________ " << endl;
192 cout <<
"/ \\" << endl;
193 cout <<
"INFO: Batch # " << ++
num_frame << endl;
198 unsigned int total_pack_tx = 1 + (
sizeof(instruct) - 1) /
PACK_SIZE;
200 unsigned int total_bytes = total_pack_tx *
PACK_SIZE;
201 unsigned int bytes_in_last_pack_tx =
sizeof(instruct) - (total_pack_tx - 1) *
PACK_SIZE;
204 cout <<
"INFO: Network socket : " << ((net_type ==
tcp) ?
"TCP" :
"UDP") << endl;
205 cout <<
"INFO: Total packets to send : " << total_pack_tx << endl;
206 cout <<
"INFO: Total packets to receive : " << total_pack_rx << endl;
207 cout <<
"INFO: Total bytes to send : " <<
sizeof(instruct) << endl;
208 cout <<
"INFO: Total bytes to receive : " << instruct.
loop_nm*
sizeof(
DtUsed) << endl;
209 cout <<
"INFO: Total bytes in " << total_pack_tx <<
" packets : " << total_bytes << endl;
210 cout <<
"INFO: Bytes in last packet send: " << bytes_in_last_pack_tx << endl;
211 cout <<
"INFO: Bytes in last packet recv: " << bytes_in_last_pack_rx << endl;
212 cout <<
"INFO: Packet size (custom MTU) : " <<
PACK_SIZE << endl;
217 clock_t start_cycle_mceuropeanengine_hw =
clock();
222 clock_t last_cycle_tx =
clock();
224 for (
unsigned int i = 0; i < total_pack_tx; i++) {
225 if ( i == total_pack_tx - 1 ) {
226 sending_now = bytes_in_last_pack_tx;
228 #if (NET_TYPE == udp)
229 udpsock.sendTo( & instruct, sending_now, servAddress, servPort);
231 tcpsock.send( & instruct, sending_now);
236 clock_t next_cycle_tx =
clock();
237 double duration_tx = (next_cycle_tx - last_cycle_tx) / (
double) CLOCKS_PER_SEC;
238 cout <<
"INFO: Effective SPS TX:" << (1 / duration_tx) <<
" \tkbps:" << (
PACK_SIZE *
239 total_pack_tx / duration_tx / 1024 * 8) << endl;
240 last_cycle_tx = next_cycle_tx;
246 clock_t last_cycle_rx =
clock();
248 cout <<
"INFO: Expecting length of packs:" << total_pack_rx << endl;
249 char * longbuf =
new char[
PACK_SIZE * total_pack_rx];
250 memset(longbuf, 0,
PACK_SIZE * total_pack_rx);
251 for (
unsigned int i = 0; i < instruct.
loop_nm*
sizeof(
DtUsed); ) {
253 if ( i == total_pack_rx - 1 ) {
254 receiving_now = bytes_in_last_pack_rx;
256 #if (NET_TYPE == udp)
257 recvMsgSize = udpsock.recvFrom(buffer,
BUF_LEN, servAddress, servPort);
259 recvMsgSize = tcpsock.recv(buffer,
BUF_LEN);
261 memcpy( & longbuf[i], buffer, recvMsgSize);
263 if (recvMsgSize != receiving_now) {
264 cerr <<
"WARNING: Received unexpected size pack:" << recvMsgSize <<
". Expected: " <<
265 receiving_now +
" . Breaking Rx..."<< endl;
271 cout <<
"INFO: Received packet from " << servAddress <<
":" << servPort << endl;
278 for (
unsigned int i = 0, j = 0; i < instruct.
loop_nm; i++, j+=
sizeof(
DtUsed)) {
279 memcpy(&
out[i], &longbuf[j],
sizeof(
DtUsed));
282 cout <<
"INFO: Received option price vector: " << endl;
283 for (
unsigned int i = 0; i < instruct.
loop_nm; i++) {
284 cout << i<<
" : " <<
out[i] << endl;
287 clock_t next_cycle_rx =
clock();
288 double duration_rx = (next_cycle_rx - last_cycle_rx) / (
double) CLOCKS_PER_SEC;
289 cout <<
"INFO: Effective SPS RX:" << (1 / duration_rx) <<
" \tkbps:" << (
PACK_SIZE *
290 total_pack_rx / duration_rx / 1024 * 8) << endl;
291 last_cycle_rx = next_cycle_rx;
293 clock_t end_cycle_mceuropeanengine_hw = next_cycle_rx;
295 double duration_mceuropeanengine_hw = (end_cycle_mceuropeanengine_hw - start_cycle_mceuropeanengine_hw) /
296 (
double) CLOCKS_PER_SEC;
297 cout <<
"INFO: HW exec. time:" << duration_mceuropeanengine_hw <<
" seconds" << endl;
298 cout <<
"INFO: Effective SPS HW:" << (1 / duration_mceuropeanengine_hw) <<
" \tkbps:" <<
299 (
PACK_SIZE * (total_pack_rx + total_pack_rx) / duration_mceuropeanengine_hw / 1024 * 8) << endl;
301 double duration_main = (
clock() - start_cycle_main) / (
double) CLOCKS_PER_SEC;
305 cout <<
"INFO: Effective SPS E2E:" << (1 / duration_main) << endl;
306 cout <<
"\\___________________________________________________________________/" << endl
310 }
catch (SocketException & e) {
311 cerr << e.what() << endl;
cat GET request dos socat stdio tcp
void delay(unsigned int mseconds)
DtUsedInt requiredSamples