source: PlatformSupport/matperf/client/matperfClient_StartTrial.m

Last change on this file was 951, checked in by chunter, 16 years ago

adding matperf

  • Property svn:executable set to *
File size: 8.7 KB
Line 
1function matperfClient_StartTrial(length, windows, reqband, UdpTcp, mode, time,address,reqport)
2
3% initialize the variables
4retrying = 0;
5
6% server address received when a udp package was received from the server
7address = strcat(num2str(address(1)),{'.'},num2str(address(2)),{'.'},num2str(address(3)),{'.'},num2str(address(4)));
8
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10% when this function is called, it prepares a packet to send to the server
11% that includes Udp/Tcp length, bandwidth, time interval, port #, and
12% window size.
13%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15if UdpTcp == 1,
16    reqpack = [1 UdpTcp length reqband time reqport];
17elseif UdpTcp ==2,
18    reqpack = [1 UdpTcp windows time reqport];
19end
20
21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22% below commands set the time the matlab will wait for iperf in order to  %
23% check if iperf has completed successfully or not. time set here is the  %
24% time the trial takes with 2 more seconds since there are chances        %
25% that iperf can run over the set time.                                   %
26%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28if mode == 3,
29    time = 2 * time + 2;
30else
31    time = time + 2;
32end
33
34udp = pnet('udpsocket',3333);
35
36while 1,
37    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38    % in this while loop, it sends the prepared packet with 1 in front so that
39    % it tells server that client wants server to awknowledge a trial
40    % request.
41    % Then it waits for the server to send 1,  which tells a server is ready
42    % for a trial run. When the client or server does not somehow recognize the
43    % signal, then the client sends a packet again.
44    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45   
46    pnet(udp,'write', reqpack); 
47    pnet(udp,'writepacket',char(address),3333); % sends a packet carrying signal 1
48
49
50    pnet(udp,'setreadtimeout',3); % wait to receive a response for signal 1
51    len = pnet(udp,'readpacket');
52       
53    if len > 0,
54        data = pnet(udp,'read',1000,'double');
55        if data == 1,
56            disp('server approved trial request');
57        else
58            disp('fix your code StartTrial line 46');
59            continue
60        end
61    else
62        disp('sending trial request reapproval...');
63        pnet('closeall');
64        udp = pnet('udpsocket',3333);
65        continue
66    end
67
68    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69    % when the server approves the trial, the below commands begin to
70    % create a command that line calls iperf with given data.
71    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72    if data == 1,
73        systemcall = 'iperf -c';
74        if UdpTcp == 1,
75            systemcall = strcat(systemcall,{' '}, address, {' -u'},{' -b '},num2str(reqband),{' -l '},num2str(length),{' -t '},num2str(time), {' -p '},num2str(reqport));
76        elseif UdpTcp == 2,
77            systemcall = strcat(systemcall,{' '}, address, {' -w '},num2str(windows),{' -t '},num2str(time),{' -p '},num2str(reqport));
78        end
79        if mode == 2,
80            systemcall = strcat(systemcall, {' -d'});
81        elseif mode == 3,
82            systemcall = strcat(systemcall, {' -r'});
83        end
84        systemcall = strcat(systemcall,' -f B -f b > tempo_result.txt &');
85    end
86
87    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
88    %  calls iperf             
89    system(char(systemcall)); 
90    %%%%%%%%%%%%%%%%%%%%%%%%%%%%
91    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92    % use python language to check the output
93    % weird.txt is a python script that checks if iperf is still running or
94    % not. It is very simple. It loads the file jobs_l and check line by
95    % line to see if the word iperf exists or not. Because ps -a checks all
96    % programs that are in process, if iperf is terminated, it won't be on
97    % the list. And python scripts will output 0. If not, it will output 1.
98    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99   
100   
101    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102    % it is also the way to check if iperf client is not acting properly.
103    % if it takes more than a few seconds after a given amount of time,
104    % matlab will consider the client is not acting properly.
105    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107    % delay
108    pnet(udp,'setreadtimeout',time); % wait until the iperf finishes its job
109    pnet(udp,'readpacket');
110   
111    system('ps -a >jobs_l'); % dump ps -a result to jobs_l
112    system('python weird');  % run the python scripts to check if iperf is still running.
113    jobs_l = load('check_jobs'); % load the result to mamtlab
114
115   
116    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117    % matlab checks whether iperf is running after a given certain time +
118    % alpha. Sometimes in wireless, even we set the time to 10 as default,
119    % iperf runs over 11 or 12. This program checks if iperf is completed
120    % or not. And if not, it checks again if iperf is running after 2sec
121    % and if it is it kills the iperf and restarts the trial.
122    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123    if jobs_l == 1,
124        % delay
125        pnet(udp,'setreadtimeout',3);
126        pnet(udp,'readpacket');
127
128        system('ps -a >jobs_l');
129        system('python weird');
130        jobs_ll = load('check_jobs');
131    else
132        jobs_ll = 0;
133    end
134
135    if jobs_ll == 1,
136        disp('first jobs wrong');
137        %delay
138        pnet(udp,'setreadtimeout',3);
139        pnet(udp,'readpacket');
140
141        system('ps -a >jobs_l');
142        system('python weird');
143        jobs_lll = load('check_jobs');
144    else
145        jobs_lll = 0;
146    end
147
148    if jobs_lll ==1.
149        system('killall iperf');
150        disp('second jobs wrong');
151        continue;
152    end
153   
154    pnet('closeall');
155   
156    clear_set; % remove all data-recorded files that are unnecessary
157   
158    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159    % this while loop checks the signal received from the server whether
160    % the trial has succeeded or failed. When the server sends 3,
161    % the clinet will restart again. when it sends 2, then it will proceed
162    % to next while loop.
163    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164udp = pnet('udpsocket',3333);
165    while 1,
166
167        pnet(udp,'write',5); 
168        pnet(udp,'setwritetimeout',.5); %give a delay so that server can be ready when sending a packet
169        pnet(udp,'writepacket',char(address),3333); % sends a signal 5 to see if the server succeed its performance.
170        pause(1)
171        % now check if server sends 2 or 3
172        pnet(udp,'setreadtimeout',10);
173        len1 = pnet(udp,'readpacket');
174        if len1 > 0,
175            disp('got reply');
176            data = pnet(udp,'read',1000,'double');
177            checking = data; % stores info if trial succeeded or not
178            break;
179        else
180            disp('retrying to send 5');
181            retrying = retrying + 1;
182            if retrying == 10,
183                break;
184            end
185            continue;
186        end
187       
188    end
189    if retrying == 10,
190        retrying = 0;
191        system('killall iperf');
192        pnet('closeall');
193        udp = pnet('udpsocket',3333);
194        continue;
195    end
196   
197    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198    % this if statement asks server to restart the iperf server and returns
199    % to the first while loop in order to restart the process.
200    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201    if checking == 3, % when server says the trial failed...
202        disp('trial failed..restarting the trial');
203        system('killall iperf');
204        pnet('closeall');
205        udp = pnet('udpsocket',3333);
206        continue;
207    end
208
209    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210    % this while loop sends signal 6 to the server. 6 means the client is
211    % approving server to parse the output into result vectors, pick up
212    % the numbers it needs and structure them as a report structs.
213    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214    while 1,
215        !python pint.txt
216        pnet(udp,'write',6); 
217        pnet(udp,'writepacket',char(address),3333); % sends six to server
218
219        pnet(udp,'setreadtimeout', 1);
220        len2 = pnet(udp,'readpacket');
221        if len2 > 0,
222            data = pnet(udp,'read',1000,'double');
223            if data == 1,
224                break;
225            end
226        else
227            continue;
228        end
229
230    end
231    break;
232end
233pnet('closeall');
234return
Note: See TracBrowser for help on using the repository browser.