-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathwfa_tg.c
More file actions
1732 lines (1460 loc) · 53.9 KB
/
wfa_tg.c
File metadata and controls
1732 lines (1460 loc) · 53.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
*
* Copyright (c) 2016 Wi-Fi Alliance
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
* USE OR PERFORMANCE OF THIS SOFTWARE.
*
*****************************************************************************/
/*
* File: wfa_tg.c
* Library functions for traffic generator.
* They are shared with both TC and DUT agent.
*/
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <fcntl.h>
#include <netdb.h>
#include <pthread.h>
#include <math.h>
#include "wfa_portall.h"
#include "wfa_stdincs.h"
#include "wfa_debug.h"
#include "wfa_ver.h"
#include "wfa_main.h"
#include "wfa_tlv.h"
#include "wfa_tg.h"
#include "wfa_cmds.h"
#include "wfa_sock.h"
#include "wfa_rsp.h"
#include "wfa_wmmps.h"
#include "wfa_miscs.h"
extern tgStream_t gStreams[];
extern BOOL gtgRecv;
extern BOOL gtgSend;
extern BOOL gtgTransac;
extern int gtimeOut;
extern int gRegSec;
extern BOOL gtgCaliRTD;
int btSockfd = -1;
int adj_latency;
extern tgStream_t *findStreamProfile(int);
extern int wfaTrafficSendTo(int, char *, int, struct sockaddr *);
extern int wfaTrafficRecv(int, char *, struct sockaddr *);
extern void wfaSendPing(tgPingStart_t *staPing, float *interval, int streamid);
extern int wfaStopPing(dutCmdResponse_t *stpResp, int streamid);
extern unsigned short wfa_defined_debug;
extern int tgSockfds[];
extern tgWMM_t wmm_thr[];
extern double min_rttime;
extern double gtgPktRTDelay;
extern void int2BuffBigEndian(int val, char *buf);
extern int bigEndianBuff2Int(char *buff);
#ifdef WFA_WMM_PS_EXT
extern int gtgWmmPS;
extern wfaWmmPS_t wmmps_info;
extern tgWMM_t wmmps_mutex_info;
extern int psSockfd;
extern unsigned int psTxMsg[];
extern unsigned int psRxMsg[];
extern int gtgPsPktRecvd;
extern void wfaSetDUTPwrMgmt(int mode);
void wmmps_wait_state_proc();
extern void wfaWmmpsInitFlag();
#endif
static int streamId = 0;
static int totalTranPkts = 0, sentTranPkts = 0;
int slotCnt = 0;
extern int usedThread;
extern int runLoop;
extern int sendThrId;
char e2eResults[124];
#if 0 /* for test purpose only */
char *e2eResults = "/tmp/e2e1198798626.txt";
#endif
extern dutCmdResponse_t gGenericResp;
static int tableDscpToTos[15] [2] = {{0,0},{8,32},{10,40},{14,56},{18,72},{22,88},{24,96},{28,112},{30,120},{34,136},{36,144},{38,152},{40,160},{46,184},{48,192},{56,224}};
/* Some devices may only support UDP ECHO and do not have ICMP level ping */
// #define WFA_PING_UDP_ECHO_ONLY 1
/*
* findStreamProfile(): search existing stream profile by stream id
* input: id - stream id;
* return: matched stream profile
*/
tgStream_t *findStreamProfile(int id)
{
int i;
tgStream_t *myStream = gStreams;
for(i = 0; i< WFA_MAX_TRAFFIC_STREAMS; i++)
{
if(myStream->id == id)
return myStream;
myStream++;
}
return NULL;
}
tgProfile_t *findTGProfile(int streamId)
{
volatile int i;
tgStream_t *myStream = gStreams;
for(i = 0; i< WFA_MAX_TRAFFIC_STREAMS; i++)
{
if(myStream->id == streamId)
return &(myStream->profile);
myStream++;
}
return NULL;
}
int convertDscpToTos(int dscp)// return >=0 as TOS, otherwise error.
{
int i =0;
for (i=0; i< WFA_DSCP_TABLE_SIZE; i++)
{
if ( tableDscpToTos[i][0] == dscp)
return tableDscpToTos[i][1];
}
return -1;
}
/*
* wfaTGSendPing(): Instruct Traffic Generator to send ping packets
*
*/
int wfaTGSendPing(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
int streamid = ++streamId;
float interval; /* it could be subseconds/100s minisecond */
tgPingStart_t *staPing = (tgPingStart_t *)caCmdBuf;
dutCmdResponse_t *spresp = &gGenericResp;
#ifdef WFA_PING_UDP_ECHO_ONLY
tgStream_t *myStream = NULL;
#endif
DPRINT_INFO(WFA_OUT, "\nEntering wfaTGSendPing ...\n");
if(staPing->frameSize == 0)
staPing->frameSize = 100;
if(staPing->frameRate == 0)
staPing->frameRate = 1;
interval = (float) 1/staPing->frameRate;
if(staPing->duration == 0)
staPing->duration = 30;
printf("framerate %f interval %f streamID %d duration %d\n",
staPing->frameRate, interval, streamId,staPing->duration);
switch(staPing->type)
{
case WFA_PING_ICMP_ECHO:
#ifndef WFA_PING_UDP_ECHO_ONLY
wfaSendPing(staPing, &interval, streamId);
spresp->status = STATUS_COMPLETE;
spresp->streamId = streamid;
#else
printf("Only support UDP ECHO\n");
#endif
break;
case WFA_PING_UDP_ECHO:
{
#ifdef WFA_PING_UDP_ECHO_ONLY
/*
* Make this like a transaction testing
* Then make it a profile and run it
*/
myStream = &gStreams[slotCnt++];
memset(myStream, 0, sizeof(tgStream_t));
memcpy(&myStream->profile, caCmdBuf, len);
myStream->id = streamid; /* the id start from 1 */
myStream->tblidx = slotCnt-1;
btSockfd = wfaCreateUDPSock("127.0.0.1", WFA_UDP_ECHO_PORT);
if((btSockfd = wfaConnectUDPPeer(btSockfd, staPing->dipaddr, WFA_UDP_ECHO_PORT)) > 0)
{
gtgTransac = streamid;
gtgSend = streamid;
totalTranPkts = 512;
sentTranPkts = 0;
/*
* the framerate here is used to derive the timeout
* value for waiting transaction echo responses.
*/
gtimeOut = MINISECONDS/staPing->frameRate; /* in msec */
/* set to longest time */
if(staPing->duration == 0)
staPing->duration = 3600;
}
#else
printf("Doesn't support UDP Echo\n");
#endif
break;
}
default:
{
spresp->status = STATUS_INVALID;
spresp->streamId = streamid;
}
}
wfaEncodeTLV(WFA_TRAFFIC_SEND_PING_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)spresp, respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
return WFA_SUCCESS;
}
/*
* tgStopPing(): Instruct Traffic Generator to stop ping packets
*
*/
int wfaTGStopPing(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
int streamid = *(int *)(caCmdBuf);
dutCmdResponse_t *stpResp = &gGenericResp;
tgStream_t *myStream;
int i;
stpResp->status = STATUS_COMPLETE;
printf("CS: The length %d\n and the command buff is \n",len);
for (i=0; i<8; i++)
printf(" %x ",caCmdBuf[i]);
printf("\nthe stream id is %d",streamid);
if( gtgTransac == streamid&>gSend == streamid)
{
gtgTransac =0;
gtgSend = 0;
gtgRecv = 0;
alarm(0);
myStream = findStreamProfile(streamid);
if(myStream == NULL)
{
stpResp->status = STATUS_INVALID;
}
stpResp->cmdru.pingStp.sendCnt = myStream->stats.txFrames;
stpResp->cmdru.pingStp.repliedCnt = myStream->stats.rxFrames;
}
else
{
#if 0
if(wfaStopPing(stpResp, streamid)== WFA_FAILURE)
{
stpResp->status = STATUS_COMPLETE;
wfaEncodeTLV(WFA_TRAFFIC_STOP_PING_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)stpResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
}
#endif
wfaStopPing(stpResp, streamid);
}
wfaEncodeTLV(WFA_TRAFFIC_STOP_PING_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)stpResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
return WFA_SUCCESS;
}
/*
* wfaTGConfig: store the traffic profile setting that will be used to
* instruct traffic generation.
* input: cmd -- not used
* response: send success back to controller
* return: success or fail
* Note: the profile storage is a global space.
*/
int wfaTGConfig(int len, BYTE *caCmdBuf, int *respLen, BYTE *respBuf)
{
int ret = WFA_FAILURE;
tgStream_t *myStream = NULL;
dutCmdResponse_t *confResp = &gGenericResp;
/* if the stream table over maximum, reset it */
if(slotCnt == WFA_MAX_TRAFFIC_STREAMS)
slotCnt = 0;
if(slotCnt == 0)
{
printf("resetting stream table\n");
wMEMSET(gStreams, 0, WFA_MAX_TRAFFIC_STREAMS*sizeof(tgStream_t));
}
DPRINT_INFO(WFA_OUT, "entering tcConfig ...\n");
myStream = &gStreams[slotCnt++];
wMEMSET(myStream, 0, sizeof(tgStream_t));
wMEMCPY(&myStream->profile, caCmdBuf, len);
myStream->id = ++streamId; /* the id start from 1 */
myStream->tblidx = slotCnt-1;
#if 0
DPRINT_INFO(WFA_OUT, "profile %i direction %i dest ip %s dport %i source %s sport %i rate %i duration %i size %i class %i delay %i\n", myStream->profile.profile, myStream->profile.direction, myStream->profile.dipaddr, myStream->profile.dport, myStream->profile.sipaddr, myStream->profile.sport, myStream->profile.rate, myStream->profile.duration, myStream->profile.pksize, myStream->profile.trafficClass, myStream->profile.startdelay);
#endif
confResp->status = STATUS_COMPLETE;
confResp->streamId = myStream->id;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_CONFIG_RESP_TLV, sizeof(dutCmdResponse_t), (BYTE *)confResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
return ret;
}
/* RecvStart: instruct traffic generator to start receiving
* based on a profile
* input: cmd -- not used
* response: inform controller for "running"
* return: success or failed
*/
int wfaTGRecvStart(int len, BYTE *parms, int *respLen, BYTE *respBuf)
{
int status = STATUS_COMPLETE, i;
int numStreams = len/4;
int streamid;
tgProfile_t *theProfile;
tgStream_t *myStream;
DPRINT_INFO(WFA_OUT, "entering tgRecvStart\n");
/*
* The function wfaSetProcPriority called here is to enhance the real-time
* performance for packet receiving. It is only for tuning and optional
* to implement
*/
for(i=0; i<numStreams; i++)
{
wMEMCPY(&streamid, parms+(4*i), 4); /* changed from 2 to 4, bug reported by n.ojanen */
myStream = findStreamProfile(streamid);
if(myStream == NULL)
{
status = STATUS_INVALID;
return status;
}
theProfile = &myStream->profile;
if(theProfile == NULL)
{
status = STATUS_INVALID;
return status;
}
/* calculate the frame interval which is used to derive its jitter */
if(theProfile->rate != 0 && theProfile->rate < 5000)
myStream->fmInterval = 1000000/theProfile->rate; /* in ms */
else
myStream->fmInterval = 0;
if(theProfile->direction != DIRECT_RECV)
{
status = STATUS_INVALID;
return status;
}
wMEMSET(&myStream->stats, 0, sizeof(tgStats_t));
// mark the stream active
myStream->state = WFA_STREAM_ACTIVE;
switch(theProfile->profile)
{
#ifdef WFA_WPA2_SINGLE_THREAD
case PROF_MCAST:
case PROF_FILE_TX:
btSockfd = wfaCreateUDPSock(theProfile->dipaddr, theProfile->dport);
gtgRecv = streamid;
if(btSockfd < 0)
status = STATUS_ERROR;
else
{
/* get current flags setting */
int ioflags = wFCNTL(btSockfd, F_GETFL, 0);
/* set only BLOCKING flag to non-blocking */
wFCNTL(btSockfd, F_SETFL, ioflags | O_NONBLOCK);
}
break;
#else
case PROF_TRANSC:
case PROF_CALI_RTD: /* Calibrate roundtrip delay */
gtgTransac = streamid;
case PROF_MCAST:
case PROF_FILE_TX:
case PROF_BURST: /* This has to be extended instead of reusing PROF_IPTV */
case PROF_IPTV:
gtgRecv = streamid;
wmm_thr[usedThread].thr_flag = streamid;
wPT_MUTEX_LOCK(&wmm_thr[usedThread].thr_flag_mutex);
wPT_COND_SIGNAL(&wmm_thr[usedThread].thr_flag_cond);
wPT_MUTEX_UNLOCK(&wmm_thr[usedThread].thr_flag_mutex);
printf("Recv Start in thread %i for streamid %i\n", usedThread, streamid);
usedThread++;
break;
#endif
case PROF_UAPSD:
#ifdef WFA_WMM_PS_EXT
#if 0
status = STATUS_COMPLETE;
psSockfd = wfaCreateUDPSock(theProfile->dipaddr, WFA_WMMPS_UDP_PORT);
wmmps_info.sta_state = 0;
wmmps_info.wait_state = WFA_WAIT_STAUT_00;
wMEMSET(&wmmps_info.psToAddr, 0, sizeof(wmmps_info.psToAddr));
wmmps_info.psToAddr.sin_family = AF_INET;
wmmps_info.psToAddr.sin_addr.s_addr = inet_addr(theProfile->sipaddr);
wmmps_info.psToAddr.sin_port = htons(theProfile->sport);
wmmps_info.reset = 0;
wmm_thr[usedThread].thr_flag = streamid;
wmmps_info.streamid = streamid;
wPT_MUTEX_LOCK(&wmm_thr[usedThread].thr_flag_mutex);
wPT_COND_SIGNAL(&wmm_thr[usedThread].thr_flag_cond);
gtgWmmPS = streamid;;
wPT_MUTEX_UNLOCK(&wmm_thr[usedThread].thr_flag_mutex);
DPRINT_INFO(WFA_OUT, "wfaTGRecvStart, WMMPS rcv start, streamId=%d, usedThread=%d\n", streamid, usedThread);
usedThread++;
#endif // remove for now.
status = STATUS_COMPLETE;
wfaWmmpsInitFlag();
theProfile->trafficClass = 0; // init to no traffic Class set
// from STA point view, in the WMMPS, source addr is PCEnd also as dest address to send to
strcpy(theProfile->dipaddr, theProfile->sipaddr);
memset(&wmmps_info.psToAddr, 0, sizeof(wmmps_info.psToAddr));
wmmps_info.psToAddr.sin_family = AF_INET;
wmmps_info.psToAddr.sin_addr.s_addr = inet_addr(theProfile->sipaddr);
wmmps_info.psToAddr.sin_port = htons(theProfile->sport);
wmmps_info.streamid = streamid;
wmmps_mutex_info.thr_flag = streamid;
gtgWmmPS = streamid;
pthread_cond_signal(&wmmps_mutex_info.thr_flag_cond);//Aaron's//Wake up the wfa_wmmps_thread
DPRINT_INFO(WFA_OUT, "wfaTGRecvStart PROF_UAPSD srcIPAddr=%s desIPAddr=%s streamId=%d\n",
theProfile->sipaddr, theProfile->dipaddr, wmmps_info.streamid );
gtimeOut = MINISECONDS/10; /* in msec */
#endif /* WFA_WMM_PS_EXT */
break;
}
}
/* encode a TLV for response for "complete/error ..." */
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RECV_START_RESP_TLV, sizeof(int),
(BYTE *)&status, respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(int);
return WFA_SUCCESS;
}
/*
* tgRecvStop: instruct traffic generator to stop receiving based on a profile
* input: cmd -- not used
* response: inform controller for "complete"
* return: success or failed
*/
int wfaTGRecvStop(int len, BYTE *parms, int *respLen, BYTE *respBuf)
{
int status = STATUS_COMPLETE, i;
int numStreams = len/4;
unsigned int streamid;
tgProfile_t *theProfile;
tgStream_t *myStream=NULL;
dutCmdResponse_t statResp;
BYTE dutRspBuf[WFA_RESP_BUF_SZ];
int id_cnt = 0;
DPRINT_INFO(WFA_OUT, "entering tgRecvStop with length %d\n",len);
/* in case that send-stream not done yet, an optional delay */
while(sendThrId != 0)
sleep(1);
/*
* After finishing the receiving command, it should lower itself back to
* normal level. It is optional implementation if it is not called
* while it starts receiving for raising priority level.
*/
wMEMSET(dutRspBuf, 0, WFA_RESP_BUF_SZ);
for(i=0; i<numStreams; i++)
{
wMEMCPY(&streamid, parms+(4*i), 4);
printf(" stop stream id %i\n", streamid);
myStream = findStreamProfile(streamid);
if(myStream == NULL)
{
status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RECV_STOP_RESP_TLV, 4, (BYTE *)&status, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
printf("stream table empty\n");
continue;
}
theProfile = &myStream->profile;
if(theProfile == NULL)
{
status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RECV_STOP_RESP_TLV, 4, (BYTE *)&status, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
if(theProfile->direction != DIRECT_RECV)
{
status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RECV_STOP_RESP_TLV, 4, (BYTE *)&status, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
/* reset its flags , close sockets */
switch(theProfile->profile)
{
case PROF_TRANSC:
case PROF_CALI_RTD:
gtgTransac = 0;
case PROF_MCAST:
case PROF_FILE_TX:
case PROF_BURST: /* This has to be extended instead of reusing PROF_IPTV */
case PROF_IPTV:
gtgRecv = 0;
if(tgSockfds[myStream->tblidx] != -1)
{
wCLOSE(tgSockfds[myStream->tblidx]);
tgSockfds[myStream->tblidx] = -1;
}
break;
case PROF_UAPSD:
#ifdef WFA_WMM_PS_EXT
#if 0
gtgWmmPS = 0;
gtgPsPktRecvd = 0;
if(psSockfd != -1)
{
wCLOSE(psSockfd);
psSockfd = -1;
}
wMEMSET(&wmmps_info, 0, sizeof(wfaWmmPS_t));
wfaSetDUTPwrMgmt(PS_OFF);
#endif // remove old code
DPRINT_INFO(WFA_OUT, "entering tgRecvStop PROF_UAPSD\n");
if(psSockfd > 0)
{
wCLOSE(psSockfd);
psSockfd = -1;
}
wMEMSET(&wmmps_info, 0, sizeof(wfaWmmPS_t));
wfaSetDUTPwrMgmt(PS_OFF);
wSLEEP(3);
gtgWmmPS = 0;
gtgPsPktRecvd = 0;
#endif /* WFA_WMM_PS_EXT */
break;
}
/* encode a TLV for response for "complete/error ..." */
statResp.status = STATUS_COMPLETE;
statResp.streamId = streamid;
#if 1
DPRINT_INFO(WFA_OUT, "stream Id %u rx %u total %llu\n", streamid, myStream->stats.rxFrames, myStream->stats.rxPayloadBytes);
#endif
wMEMCPY(&statResp.cmdru.stats, &myStream->stats, sizeof(tgStats_t));
wMEMCPY((dutRspBuf + i * sizeof(dutCmdResponse_t)), (BYTE *)&statResp, sizeof(dutCmdResponse_t));
id_cnt++;
// Not empty it but require to reset the entire table before test starts.
//wMEMSET(myStream, 0, sizeof(tgStream_t));
}
// mark the stream inactive
myStream->state = WFA_STREAM_INACTIVE;
printf("Sending back the statistics at recvstop\n");
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RECV_STOP_RESP_TLV, id_cnt * sizeof(dutCmdResponse_t), dutRspBuf, respBuf);
/* done here */
*respLen = WFA_TLV_HDR_LEN + numStreams * sizeof(dutCmdResponse_t);
return WFA_SUCCESS;
}
/*
* wfaTGSendStart: instruct traffic generator to start sending based on a profile
* input: cmd -- not used
* response: inform controller for "running"
* return: success or failed
*/
int wfaTGSendStart(int len, BYTE *parms, int *respLen, BYTE *respBuf)
{
int i=0, streamid=0;
int numStreams = len/4;
char gCmdStr[WFA_CMD_STR_SZ];
tgProfile_t *theProfile;
tgStream_t *myStream = NULL;
dutCmdResponse_t staSendResp;
DPRINT_INFO(WFA_OUT, "Entering tgSendStart for %i streams ...\n", numStreams);
for(i=0; i<numStreams; i++)
{
wMEMCPY(&streamid, parms+(4*i), 4);
myStream = findStreamProfile(streamid);
if(myStream == NULL)
{
staSendResp.status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
theProfile = &myStream->profile;
if(theProfile == NULL)
{
staSendResp.status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
if(theProfile->direction != DIRECT_SEND)
{
staSendResp.status = STATUS_INVALID;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, 4, (BYTE *)&staSendResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
/*
* need to reset the stats
*/
wMEMSET(&myStream->stats, 0, sizeof(tgStats_t));
// mark the stream active;
myStream->state = WFA_STREAM_ACTIVE;
switch(theProfile->profile)
{
case PROF_FILE_TX:
case PROF_MCAST:
case PROF_TRANSC:
gtgTransac = streamid;
gtgSend = streamid;
case PROF_CALI_RTD:
gtgCaliRTD = streamid;
case PROF_BURST: /* This has to be extended instead of reusing PROF_IPTV */
case PROF_IPTV:
gtgSend = streamid;
/*
* singal the thread to Sending WMM traffic
*/
wmm_thr[usedThread].thr_flag = streamid;
wPT_MUTEX_LOCK(&wmm_thr[usedThread].thr_flag_mutex);
wPT_COND_SIGNAL(&wmm_thr[usedThread].thr_flag_cond);
wPT_MUTEX_UNLOCK(&wmm_thr[usedThread].thr_flag_mutex);
usedThread++;
*respLen = 0;
break;
case PROF_UAPSD:
{
int ttout = 20;
printf(" Run wfa_con timer = %d sec\n", ttout);
sprintf(gCmdStr,"/usr/bin/wfa_con -t %d %s",ttout,theProfile->WmmpsTagName);
if(system(gCmdStr))
printf("Done with wfa_con\n");
staSendResp.status = STATUS_COMPLETE;
staSendResp.streamId = streamid;
myStream->stats.txFrames = 10;
myStream->stats.txPayloadBytes = 10000;
wMEMCPY(&staSendResp.cmdru.stats, &myStream->stats, sizeof(tgStats_t));
wfaEncodeTLV(WFA_TRAFFIC_AGENT_SEND_RESP_TLV, sizeof(dutCmdResponse_t),
(BYTE *)&staSendResp, (BYTE *)respBuf);
*respLen = WFA_TLV_HDR_LEN + sizeof(dutCmdResponse_t);
}
break;
} /* switch */
}/* for */
return WFA_SUCCESS;
}
int wfaTGReset(int len, BYTE *parms, int *respLen, BYTE *respBuf)
{
dutCmdResponse_t *resetResp = &gGenericResp;
int i;
/* need to reset all traffic socket fds */
if(btSockfd != -1)
{
wCLOSE(btSockfd);
btSockfd = -1;
}
for(i = 0; i<WFA_MAX_TRAFFIC_STREAMS; i++)
{
if(tgSockfds[i] != -1)
{
wCLOSE(tgSockfds[i]);
tgSockfds[i] = -1;
}
}
/* reset the timer alarm if it was armed */
wALARM(0);
/* just reset the flags for the command */
gtgRecv = 0;
gtgSend = 0;
gtgTransac = 0;
#ifdef WFA_VOICE_EXT
gtgCaliRTD = 0;
min_rttime = 0xFFFFFFFF;
gtgPktRTDelay = 0xFFFFFFFF;
#endif
totalTranPkts = 0;
runLoop = 0;
usedThread = 0;
#ifdef WFA_WMM_PS_EXT
gtgWmmPS = 0;
gtgPsPktRecvd = 0;
if(psSockfd != -1)
{
wCLOSE(psSockfd);
psSockfd = -1;
}
wMEMSET(&wmmps_info, 0, sizeof(wfaWmmPS_t));
#endif
e2eResults[0] = '\0';
/* Also need to clean up WMM streams NOT DONE YET!*/
slotCnt = 0; /* reset stream profile container */
wMEMSET(gStreams, 0, WFA_MAX_TRAFFIC_STREAMS);
/*
* After be asked to reset, it should lower itself back to
* normal level. It is optional implementation if it is not called
* while it starts sending/receiving for raising priority level.
*/
/* encode a TLV for response for "complete ..." */
resetResp->status = STATUS_COMPLETE;
wfaEncodeTLV(WFA_TRAFFIC_AGENT_RESET_RESP_TLV, 4,
(BYTE *)resetResp, respBuf);
*respLen = WFA_TLV_HDR_LEN + 4;
return WFA_SUCCESS;
}
/*
* calculate the sleep time for different frame rate
* It should be done according the device
* This is just one way to adjust the packet delivery speed. If you find
* you device does not meet the test requirements, you MUST re-adjust
* the method.
*/
/* The HZ value could be found in the build header file */
/* 100 -> 10ms, 1000 -> 1ms , etc */
#define WFA_KERNEL_MIN_TIMER_RES 100 /* HZ Value for 10 ms */
void wfaTxSleepTime(int profile, int rate, int *sleepTime, int *throttledRate)
{
*sleepTime=0; /* in microseconds */
/* calculate the sleep time based on frame rate */
/*
* Framerate is still required for Multicast traffic
* Sleep and hold for a timeout.
*
* For WMM traffic, the framerate must also need for VO and VI.
* the framerate 500, OS may not handle it precisely.
*/
switch(profile)
{
/*
* make it a fix rate
* according to test plan, it requires ~80kbps which is around 50 frames/s
* For other cases which may want to run experiments for very high rate,
* the change should accommodate the requirement.
*/
case PROF_MCAST:
if(rate < 500 && rate >= 50)
{
*sleepTime = 100000; /* sleep for 100 ms */
*throttledRate = WFA_MCAST_FRATE;
}
else
{
*sleepTime = 100000;
*throttledRate = rate;
}
#if 0
*throttledRate = WFA_MCAST_FRATE;
#endif
break;
/*
* Vendor must find ways to better adjust the speed for their own device
*/
case PROF_BURST: /* This has to be extended instead of reusing PROF_IPTV */
case PROF_IPTV:
case PROF_FILE_TX:
if(rate >=50 || rate == 0)
{
/*
* this sleepTime indeed is now being used for time period
* to send packets in the throttled Rate.
* The idea here is that in each fixed 20 minisecond period,
* The device will send rate/50 (rate = packets / second),
* then go sleep for rest of time.
*/
*sleepTime = 20000; /* fixed 20 miniseconds */
*throttledRate = (rate?rate:20000)/50;
printf("Hi Sleep time %i, throttledRate %i\n", *sleepTime, *throttledRate);
}
else if (rate > 0 && rate <= 50) /* typically for voice */
{
*throttledRate = 1;
*sleepTime = 1000*1000/rate;
}
break;
default:
DPRINT_ERR(WFA_ERR, "Incorrect profile\n");
}
}
#define WFA_TIME_DIFF(before, after, rtime, dtime) \
dtime = rtime + (after.tv_sec*1000000 + after.tv_usec) - (before.tv_sec*1000000 + before.tv_usec);
void buzz_time(int delay)
{
struct timeval now, stop;
int diff;
int remain_time = 0;
wGETTIMEOFDAY(&stop, 0);
stop.tv_usec += delay;
if(stop.tv_usec > 1000000)
{
stop.tv_usec -=1000000;
stop.tv_sec +=1;
}
do
{
wGETTIMEOFDAY(&now, 0);
WFA_TIME_DIFF(now, stop, remain_time, diff);
}
while(diff>0);
}
/**************************************************/
/* the actually functions to send/receive packets */
/**************************************************/
/* This is going to be a blocking SEND till it finishes */
int wfaSendLongFile(int mySockfd, int streamid, BYTE *aRespBuf, int *aRespLen)
{
tgProfile_t *theProf = NULL;
tgStream_t *myStream = NULL;
struct sockaddr_in toAddr;
char *packBuf;
int packLen;
int bytesSent;
dutCmdResponse_t sendResp;
int sleepTime = 0;
int throttledRate = 0;
struct timeval before, after,af;
int difftime = 0, counter = 0;
struct timeval stime;
int act_sleep_time;
gettimeofday(&af,0);
DPRINT_INFO(WFA_OUT, "Entering sendLongFile %i\n", streamid);
/* find the profile */
myStream = findStreamProfile(streamid);
if(myStream == NULL)
{
return WFA_FAILURE;
}
theProf = &myStream->profile;
if(theProf == NULL)
{
return WFA_FAILURE;
}
/* If RATE is 0 which means to send as much as possible, the frame size set to max UDP length */
if(theProf->rate == 0)
{
if(theProf->hti == 0 && theProf->pksize)
packLen = theProf->pksize;
else
packLen = MAX_UDP_LEN;
}
else
packLen = theProf->pksize;
/* allocate a buf */
packBuf = (char *)malloc(packLen+1);
wMEMSET(packBuf, 0, packLen);
/* fill in the header */
wSTRNCPY(packBuf, "1345678", sizeof(tgHeader_t));
/* initialize the destination address */
wMEMSET(&toAddr, 0, sizeof(toAddr));
toAddr.sin_family = AF_INET;
toAddr.sin_addr.s_addr = inet_addr(theProf->dipaddr);
toAddr.sin_port = htons(theProf->dport);
/* if a frame rate and duration are defined, then we know
* interval for each packet and how many packets it needs to
* send.
*/
if(theProf->duration != 0)
{
printf("duration %i\n", theProf->duration);
/*