1 | function [report servrep report_port] = matperfServer |
---|
2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3 | % usage: matperfServer |
---|
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
5 | % initialize all variables |
---|
6 | pnet('closeall'); |
---|
7 | |
---|
8 | yes = 1; t1 = []; t2 = []; b1 = []; b2 = []; |
---|
9 | j1 = []; j2 = []; l1 = []; l2 = []; tp1= []; |
---|
10 | t3 = []; t4 = []; b3 = []; b4 = []; j3 = []; |
---|
11 | j4 = []; l3 = []; l4 = []; tp3= []; oisup = 0; |
---|
12 | ti = []; ti2 = []; |
---|
13 | req_band = []; leng = []; times = []; |
---|
14 | reqports = []; repnum = 0; portadd = 0; |
---|
15 | numexp = 1; data_old = 0; |
---|
16 | windows = []; |
---|
17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
18 | disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); |
---|
19 | disp('server quits when matperfClient_complete with specific address is called'); |
---|
20 | disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); |
---|
21 | |
---|
22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
23 | % This is the server that receives signals from the client and execute |
---|
24 | % the commands client demands. Different from the client, server will |
---|
25 | % execute the commands and parse and collect the outputs into vectors and |
---|
26 | % structs. |
---|
27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
28 | |
---|
29 | |
---|
30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
31 | % To check if this program is running properly, check the struct values |
---|
32 | % with the iperf results recorded in checkresult.txt |
---|
33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
34 | udp = pnet('udpsocket', 3333); |
---|
35 | while 1, |
---|
36 | pnet(udp,'setreadtimeout',15); |
---|
37 | len = pnet(udp,'readpacket'); |
---|
38 | |
---|
39 | if len > 0, |
---|
40 | |
---|
41 | [ip] = pnet(udp,'gethost'); % receives the address of the responded client |
---|
42 | address = strcat(num2str(ip(1)),{'.'},num2str(ip(2)),{'.'},num2str(ip(3)),{'.'},num2str(ip(4))); |
---|
43 | |
---|
44 | |
---|
45 | data = pnet(udp,'read',1000,'double'); |
---|
46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
47 | % mode 1 -> single |
---|
48 | % mode 2 -> double |
---|
49 | % mode 3 -> tradeoff |
---|
50 | % UdpTcp = 1 ->> UDP |
---|
51 | % UdpTcp = 2 ->> TCP |
---|
52 | % experiment request => 0 |
---|
53 | % trial request => 1 |
---|
54 | % asking success/failure => 4 |
---|
55 | % asking to parse & collect the data => 6 |
---|
56 | % complete exp => 7 |
---|
57 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
58 | |
---|
59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
60 | % when the server receives 0, it should also have received % |
---|
61 | % information of whether the client is UDP or TCP and % |
---|
62 | % its mode. % |
---|
63 | % [req; UDP/TCP ; mode] <- do not change during the exp. % |
---|
64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
65 | |
---|
66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
67 | % when the server receives 1, it also receives length, bandwidth, % |
---|
68 | % window size, port # the client wants to access on server and % |
---|
69 | % prepare the iperf command line to be executed. Then it % |
---|
70 | % executes the command and send the client a signal that allows the |
---|
71 | % client to execute its iperf command. % |
---|
72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
73 | |
---|
74 | if data(1) == 0, |
---|
75 | if exist('checkresult.txt','file') == 2, |
---|
76 | system('rm checkresult.txt'); |
---|
77 | end |
---|
78 | data_old = data; |
---|
79 | servrep = 0; |
---|
80 | report = 0; |
---|
81 | report_port = 0; |
---|
82 | disp('experiment request submitted'); |
---|
83 | clear_set; % delete all the temporary files being used in previous trial. |
---|
84 | req = 0; |
---|
85 | UdpTcp = data(2); % collects info if UDP/TCP test |
---|
86 | mode = data(3); % collects info if single/dual/tradeoff |
---|
87 | pnet(udp,'write',req); |
---|
88 | pnet(udp,'setwritetimeout',1.2); |
---|
89 | pnet(udp,'writepacket',char(address),3333); % this sends to client that server recognized the client |
---|
90 | oisup = 1; |
---|
91 | continue; |
---|
92 | elseif data(1) ==1, |
---|
93 | if oisup == 0, |
---|
94 | disp('experiment not initialized'); |
---|
95 | return |
---|
96 | end |
---|
97 | clear_set; |
---|
98 | data_old = data(1); |
---|
99 | |
---|
100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
101 | % WARNING: only one iperf should run during the test % |
---|
102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
103 | pac = data; |
---|
104 | if pac(2) == 1 %if UDP, |
---|
105 | length = pac(3); % these pac variables are from the received packet from the client |
---|
106 | reqband = pac(4); |
---|
107 | timeb = pac(5); |
---|
108 | reqport = pac(6); |
---|
109 | systemcall = 'iperf -s -u -P 1 -f B -f b'; |
---|
110 | systemcall = strcat(systemcall,{' -p '},num2str(reqport),{' > tempo_result.txt &'}); |
---|
111 | elseif pac(2) ==2, % if TCP, |
---|
112 | window = pac(3); |
---|
113 | timeb = pac(4); |
---|
114 | reqport = pac(5); |
---|
115 | systemcall = 'iperf -s -P 1 -f B -f b'; |
---|
116 | systemcall = strcat(systemcall,{' -p '},num2str(reqport),{' > tempo_result.txt &'}); |
---|
117 | end |
---|
118 | |
---|
119 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
120 | % based on received data, above two if statements build a |
---|
121 | % command line to be used to call iperf |
---|
122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
123 | system('ps -a > jobs_l'); |
---|
124 | system('python weird'); |
---|
125 | jobs_l = load('check_jobs'); |
---|
126 | if jobs_l == 1, |
---|
127 | system('killall iperf'); |
---|
128 | end |
---|
129 | disp('trial request submitted'); |
---|
130 | |
---|
131 | % call iperf |
---|
132 | system(char(systemcall)); |
---|
133 | |
---|
134 | pnet(udp,'write',1); |
---|
135 | pnet(udp,'setwritetimeout',.6); |
---|
136 | pnet(udp,'writepacket',char(address),3333); % server tells client to begin the iperf trial |
---|
137 | continue |
---|
138 | elseif data == 5 |
---|
139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
140 | % when the server receives 5, matlab begins to check the iperf |
---|
141 | % results written on the specified file. In our case it |
---|
142 | % is tempo_reult.txt. First matlab uses python to call pint.txt. |
---|
143 | % pint.txt is a python script that gets rid of all unnecessary |
---|
144 | % lines in the iperf output s othat all the outputs have the same |
---|
145 | % structures. |
---|
146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
147 | if oisup == 0, |
---|
148 | disp('experiment not initialized'); |
---|
149 | return |
---|
150 | end |
---|
151 | data_old = data; |
---|
152 | |
---|
153 | system('python pint.txt'); |
---|
154 | |
---|
155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
156 | % below serverudpsingle/dual/tradeoff are the scripts that |
---|
157 | % parse the output to the vectors saved into different files so |
---|
158 | % that matlab can call each of them in order to use them as |
---|
159 | % variables. |
---|
160 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
161 | if mode == 1, |
---|
162 | if UdpTcp == 1, |
---|
163 | system('python serverudpsingle'); |
---|
164 | elseif UdpTcp == 2, |
---|
165 | system('python servertcpsingle'); |
---|
166 | end |
---|
167 | elseif mode ==2, |
---|
168 | if UdpTcp == 1, |
---|
169 | system('python serverudpdual'); |
---|
170 | elseif UdpTcp ==2, |
---|
171 | system('python servertcpdual'); |
---|
172 | end |
---|
173 | elseif mode == 3, |
---|
174 | if UdpTcp == 1, |
---|
175 | system('python serverudptradeoff'); |
---|
176 | end |
---|
177 | end |
---|
178 | |
---|
179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
180 | % below script lines will load the results saved in separate |
---|
181 | % files into matlab workspace. They will also check if the |
---|
182 | % server got stuck or not by checking whether there were |
---|
183 | % outputs or not. If the server gets stuck, there are no lines |
---|
184 | % to parse and save into files. So If files don't exist, that |
---|
185 | % means there are no outputs and also means the server was |
---|
186 | % stuck. If the matlab determines that server is stuck, then it |
---|
187 | % will kill the running iperf and send client 3, which means |
---|
188 | % the trial failed and client has to execute the same command again. |
---|
189 | % But if those lines successively parse and save them into |
---|
190 | % separate files then it will send client 2, which means the |
---|
191 | % trial has succeeded. |
---|
192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
193 | |
---|
194 | if exist('repnum.txt','file') == 2 && exist('portadd.txt','file') == 2, |
---|
195 | temp_repnum = textread('repnum.txt','%s') ; |
---|
196 | temp_portadd = textread('portadd.txt','%s'); |
---|
197 | sf = 2; |
---|
198 | if mode == 2, |
---|
199 | if exist('dual_repnum.txt','file') ==2 && exist('dual_portadd.txt','file') == 2, |
---|
200 | tempd_repnum = textread('dual_repnum.txt','%s'); |
---|
201 | tempd_portadd = textread('dual_portadd.txt','%s'); |
---|
202 | else |
---|
203 | disp('server stuck') |
---|
204 | system('killall iperf'); % kills iperf |
---|
205 | sf = 3; %fail |
---|
206 | end |
---|
207 | elseif mode == 3, |
---|
208 | if exist('tradeoff_repnum.txt','file') ==2 && exist('tradeoff_portadd.txt','file') == 2, |
---|
209 | t_repnum = textread('tradeoff_repnum.txt','%s'); |
---|
210 | t_portadd = textread('tradeoff_portadd.txt','%s'); |
---|
211 | else |
---|
212 | disp('server stuck') |
---|
213 | system('killall iperf'); %klls iperf |
---|
214 | sf = 3; %fail |
---|
215 | end |
---|
216 | end |
---|
217 | else |
---|
218 | disp('server stuck'); |
---|
219 | system('killall iperf'); |
---|
220 | sf = 3; %fail |
---|
221 | end |
---|
222 | clear_set; |
---|
223 | pnet(udp,'write',sf); %success |
---|
224 | pnet(udp,'setwritetimeout',.5); |
---|
225 | pnet(udp,'writepacket',char(address),3333); % server tells client whether trial succeeded or failed |
---|
226 | continue; |
---|
227 | |
---|
228 | elseif data == 6, |
---|
229 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
230 | % below if statement prevents the results are presented twice |
---|
231 | % at the same time. data_old is the copied version of data and |
---|
232 | % if signal 6 is sent twice at the same time, server jumps back |
---|
233 | % to the start. |
---|
234 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
235 | if data_old == data, |
---|
236 | pnet(udp,'write',yes); |
---|
237 | pnet(udp,'setwritetimeout',1.5); |
---|
238 | pnet(udp,'writepacket',char(address),3333); |
---|
239 | continue; |
---|
240 | end |
---|
241 | if mode == 2, |
---|
242 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
243 | % first, portadd, the vector that carries information about |
---|
244 | % the port numbers has been examined. It checks if that |
---|
245 | % line tells whether server connected to client back or |
---|
246 | % client connected to server. Then portadd becomes the |
---|
247 | % vector consist of line that contains the data of client |
---|
248 | % connected to server, and d_portadd becomes the vector that |
---|
249 | % consist of line that contains the data of server |
---|
250 | % connected to client. |
---|
251 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
252 | porter = cell2mat(temp_portadd(7)); |
---|
253 | |
---|
254 | if num2str(reqport) == porter, |
---|
255 | portadd = temp_portadd; |
---|
256 | d_portadd = tempd_portadd; |
---|
257 | else |
---|
258 | portadd = tempd_portadd; |
---|
259 | d_portadd = temp_portadd; |
---|
260 | end |
---|
261 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
262 | % these below liines are to check if the results are sorted |
---|
263 | % correctly or not. I checked if the results are correctly |
---|
264 | % sorted by checking the ID in every lines. For example [3] |
---|
265 | % is sorted with all [3] lines and [142] lines are all |
---|
266 | % sorted with [142]. |
---|
267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
268 | |
---|
269 | numer = cell2mat(portadd(2)); |
---|
270 | if numer == cell2mat(temp_repnum(2)), |
---|
271 | repnum = temp_repnum; |
---|
272 | d_repnum = tempd_repnum; |
---|
273 | else |
---|
274 | repnum = tempd_repnum; |
---|
275 | d_repnum = temp_repnum; |
---|
276 | end |
---|
277 | |
---|
278 | elseif mode == 3, |
---|
279 | repnum = temp_repnum; |
---|
280 | portadd = temp_portadd; |
---|
281 | |
---|
282 | elseif mode == 1, |
---|
283 | repnum = temp_repnum; |
---|
284 | portadd = temp_portadd; |
---|
285 | end |
---|
286 | |
---|
287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
288 | % repnum contains info about the jitter, totalpacket,loss, etc. |
---|
289 | % and portadd contains info about the port and address of |
---|
290 | % client and server. d_repnum and d_portadd contain info of the |
---|
291 | % client's server report. |
---|
292 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
293 | |
---|
294 | |
---|
295 | |
---|
296 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
297 | % These are the algorithms that create the struct that will be |
---|
298 | % shown as a result. First, I loaded a file that contains |
---|
299 | % information about the bandwidth, jitter, lost, |
---|
300 | % totalpackets, and port numbers of client and server into work |
---|
301 | % space. Then, I just picked up a number from that vector by |
---|
302 | % giving a matlab a location of those necessary values. number |
---|
303 | % in below box is the row # of the vectors that contain the |
---|
304 | % answers i need. |
---|
305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
306 | if UdpTcp == 1 |
---|
307 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
308 | % for UDP results |
---|
309 | % j ==> Transfer => 7; Bandwidth => 9; Jitter => 12; |
---|
310 | % Lost => 14; Total => 15; time => 5; |
---|
311 | % k ==> s.add => 5 s.port => 7 c.add => 10 c.port => 12 |
---|
312 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
313 | for i = 1: size(repnum) |
---|
314 | % change rem(i,j) j to the # of lines of one report. |
---|
315 | j = rem(i,18); |
---|
316 | if (j == 5) |
---|
317 | Ti = str2double(cell2mat(repnum(i))); |
---|
318 | ti = [ti;Ti]; |
---|
319 | elseif (j == 7) |
---|
320 | T1 = str2double(cell2mat(repnum(i))); |
---|
321 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
322 | % conversion.m |
---|
323 | % this conversion function changes the size of the |
---|
324 | % values for example from Bytes to GBytes or |
---|
325 | % KBytes. inputs are what size you want, the value, |
---|
326 | % and the current size. |
---|
327 | % e.g. conversion('Bytes',T1,'KBytes') |
---|
328 | % first one is what size you want, second one is |
---|
329 | % the value, and the third one is the current size. |
---|
330 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
331 | T1 = conversion('Bytes',T1,repnum(i+1)); |
---|
332 | % it creates saves the value as vectors. |
---|
333 | t1 = [t1;T1]; |
---|
334 | elseif (j == 9) |
---|
335 | B1 = str2double(cell2mat(repnum(i))); |
---|
336 | B1 = conversion('bits',B1,repnum(i+1)); |
---|
337 | b1 = [b1;B1]; |
---|
338 | elseif (j == 12) |
---|
339 | J1 = str2double(cell2mat(repnum(i))); |
---|
340 | j1 = [j1;J1]; |
---|
341 | elseif (j == 14) |
---|
342 | L1 = str2double(cell2mat(repnum(i))); |
---|
343 | l1 = [l1;L1]; |
---|
344 | elseif (j == 15) |
---|
345 | TP1 = str2double(cell2mat(repnum(i))); |
---|
346 | tp1 = [tp1; TP1]; |
---|
347 | end |
---|
348 | end |
---|
349 | for k = 1:size(portadd) |
---|
350 | % change rem(k,l) l to the # of lines of one report. |
---|
351 | l = rem(k,12); |
---|
352 | if (l == 5) |
---|
353 | T2 = (cell2mat(portadd(k))); |
---|
354 | t2 = [t2; T2]; |
---|
355 | elseif (l == 7) |
---|
356 | B2 = (cell2mat(portadd(k))); |
---|
357 | b2 = [b2;B2]; |
---|
358 | elseif (l == 10) |
---|
359 | J2 = (cell2mat(portadd(k))); |
---|
360 | j2 = [j2; J2]; |
---|
361 | elseif (l == 0) |
---|
362 | L2 = (cell2mat(portadd(k))); |
---|
363 | l2 = [l2; L2]; |
---|
364 | end |
---|
365 | end |
---|
366 | if(mode == 2) |
---|
367 | for i1 = 1: size(d_repnum) |
---|
368 | % change rem(i,j) j to the # of lines of one report. |
---|
369 | j = rem(i1,18); |
---|
370 | if (j == 5) |
---|
371 | Ti2 = str2double(cell2mat(d_repnum(i1))); |
---|
372 | ti2 = [ti2;Ti2]; |
---|
373 | elseif (j == 7) |
---|
374 | T3 = str2double(cell2mat(d_repnum(i1))); |
---|
375 | T3 = conversion('Bytes',T3,d_repnum(i1+1)); |
---|
376 | t3 = [t3;T3]; |
---|
377 | elseif (j == 9) |
---|
378 | B3 = str2double(cell2mat(d_repnum(i1))); |
---|
379 | B3 = conversion('bits',B3,d_repnum(i1+1)); |
---|
380 | b3 = [b3;B3]; |
---|
381 | elseif (j == 12) |
---|
382 | J3 = str2double(cell2mat(d_repnum(i1))); |
---|
383 | j3 = [j3;J3]; |
---|
384 | elseif (j == 14) |
---|
385 | L3 = str2double(cell2mat(d_repnum(i1))); |
---|
386 | l3 = [l3;L3]; |
---|
387 | elseif (j == 15) |
---|
388 | TP3 = str2double(cell2mat(d_repnum(i1))); |
---|
389 | tp3 = [tp3; TP3]; |
---|
390 | end |
---|
391 | end |
---|
392 | |
---|
393 | for k1 = 1:size(d_portadd) |
---|
394 | % change rem(k,l) l to the # of lines of one report. |
---|
395 | l = rem(k1,12); |
---|
396 | if (l == 5) |
---|
397 | T4 = (cell2mat(d_portadd(k1))); |
---|
398 | t4 = [t4; T4]; |
---|
399 | elseif (l == 7) |
---|
400 | B4 = (cell2mat(d_portadd(k1))); |
---|
401 | b4 = [b4;B4]; |
---|
402 | elseif (l == 10) |
---|
403 | J4 = (cell2mat(d_portadd(k1))); |
---|
404 | j4 = [j4; J4]; |
---|
405 | elseif (l == 0) |
---|
406 | L4 = (cell2mat(d_portadd(k1))); |
---|
407 | l4 = [l4; L4]; |
---|
408 | end |
---|
409 | end |
---|
410 | elseif mode == 3, |
---|
411 | for i1 = 1: size(t_repnum) |
---|
412 | % change rem(i,j) j to the # of lines of one report. |
---|
413 | j = rem(i1,18); |
---|
414 | if (j == 5) |
---|
415 | Ti2 = str2double(cell2mat(t_repnum(i1))); |
---|
416 | ti2 = [ti2;Ti2]; |
---|
417 | elseif (j == 7) |
---|
418 | T3 = str2double(cell2mat(t_repnum(i1))); |
---|
419 | T3 = conversion('Bytes',T3,t_repnum(i1+1)); |
---|
420 | t3 = [t3;T3]; |
---|
421 | elseif (j == 9) |
---|
422 | B3 = str2double(cell2mat(t_repnum(i1))); |
---|
423 | B3 = conversion('bits',B3,t_repnum(i1+1)); |
---|
424 | b3 = [b3;B3]; |
---|
425 | elseif (j == 12) |
---|
426 | J3 = str2double(cell2mat(t_repnum(i1))); |
---|
427 | j3 = [j3;J3]; |
---|
428 | elseif (j == 14) |
---|
429 | L3 = str2double(cell2mat(t_repnum(i1))); |
---|
430 | l3 = [l3;L3]; |
---|
431 | elseif (j == 15) |
---|
432 | TP3 = str2double(cell2mat(t_repnum(i1))); |
---|
433 | tp3 = [tp3; TP3]; |
---|
434 | end |
---|
435 | end |
---|
436 | |
---|
437 | for k1 = 1:size(t_portadd) |
---|
438 | % change rem(k,l) l to the # of lines of one report. |
---|
439 | l = rem(k1,12); |
---|
440 | if (l == 5) |
---|
441 | T4 = (cell2mat(t_portadd(k1))); |
---|
442 | t4 = [t4; T4]; |
---|
443 | elseif (l == 7) |
---|
444 | B4 = (cell2mat(t_portadd(k1))); |
---|
445 | b4 = [b4;B4]; |
---|
446 | elseif (l == 10) |
---|
447 | J4 = (cell2mat(t_portadd(k1))); |
---|
448 | j4 = [j4; J4]; |
---|
449 | elseif (l == 0) |
---|
450 | L4 = (cell2mat(t_portadd(k1))); |
---|
451 | l4 = [l4; L4]; |
---|
452 | end |
---|
453 | end |
---|
454 | |
---|
455 | end |
---|
456 | leng = [leng; length]; |
---|
457 | req_band = [req_band;reqband]; |
---|
458 | |
---|
459 | elseif UdpTcp == 2, |
---|
460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
461 | % for TCP results: |
---|
462 | % j ==> Throughput = 7; Bandwidth = 9; Jitter = 12; |
---|
463 | % Lost = 14; Total 15; time => 5; |
---|
464 | % k ==> s.add 5 s.port 7 c.add 10 c.port 12 |
---|
465 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
466 | for i = 1: size(repnum) |
---|
467 | % change rem(i,j) j to the # of lines of one report. |
---|
468 | j = rem(i,11); |
---|
469 | if (j == 5) |
---|
470 | Ti = str2double(cell2mat(repnum(i))); |
---|
471 | ti = [ti;Ti]; |
---|
472 | elseif (j == 7) |
---|
473 | T1 = str2double(cell2mat(repnum(i))); |
---|
474 | T1 = conversion('Bytes',T1,repnum(i+1)); |
---|
475 | t1 = [t1;T1]; |
---|
476 | elseif (j == 9) |
---|
477 | B1 = str2double(cell2mat(repnum(i))); |
---|
478 | B1 = conversion('bits',B1,repnum(i+1)); |
---|
479 | b1 = [b1;B1]; |
---|
480 | end |
---|
481 | end |
---|
482 | for k = 1:size(portadd) |
---|
483 | % change rem(k,l) l to the # of lines of one report. |
---|
484 | l = rem(k,12); |
---|
485 | if (l == 5) |
---|
486 | T2 = (cell2mat(portadd(k))); |
---|
487 | t2 = [t2; T2]; |
---|
488 | elseif (l == 7) |
---|
489 | B2 = (cell2mat(portadd(k))); |
---|
490 | b2 = [b2;B2]; |
---|
491 | elseif (l == 10) |
---|
492 | J2 = (cell2mat(portadd(k))); |
---|
493 | j2 = [j2; J2]; |
---|
494 | elseif (l == 0) |
---|
495 | L2 = (cell2mat(portadd(k))); |
---|
496 | l2 = [l2; L2]; |
---|
497 | end |
---|
498 | end |
---|
499 | if mode == 2, |
---|
500 | for i1 = 1: size(d_repnum) |
---|
501 | % change rem(i,j) j to the # of lines of one report. |
---|
502 | j = rem(i1,11); |
---|
503 | if (j == 5) |
---|
504 | Ti2 = str2double(cell2mat(d_repnum(i1))); |
---|
505 | ti2 = [ti2;Ti2]; |
---|
506 | elseif (j == 7) |
---|
507 | T3 = str2double(cell2mat(d_repnum(i1))); |
---|
508 | T3 = conversion('Bytes',T3,d_repnum(i1+1)); |
---|
509 | t3 = [t3;T3]; |
---|
510 | elseif (j == 9) |
---|
511 | B3 = str2double(cell2mat(d_repnum(i1))); |
---|
512 | B3 = conversion('bits',B3,d_repnum(i1+1)); |
---|
513 | b3 = [b3;B3]; |
---|
514 | end |
---|
515 | end |
---|
516 | |
---|
517 | for k1 = 1:size(d_portadd) |
---|
518 | % change rem(k,l) l to the # of lines of one report. |
---|
519 | l = rem(k1,12); |
---|
520 | if (l == 5) |
---|
521 | T4 = (cell2mat(d_portadd(k1))); |
---|
522 | t4 = [t4; T4]; |
---|
523 | elseif (l == 7) |
---|
524 | B4 = (cell2mat(d_portadd(k1))); |
---|
525 | b4 = [b4;B4]; |
---|
526 | elseif (l == 10) |
---|
527 | J4 = (cell2mat(d_portadd(k1))); |
---|
528 | j4 = [j4; J4]; |
---|
529 | elseif (l == 0) |
---|
530 | L4 = (cell2mat(d_portadd(k1))); |
---|
531 | l4 = [l4; L4]; |
---|
532 | end |
---|
533 | end |
---|
534 | |
---|
535 | end |
---|
536 | % requested window size |
---|
537 | windows = [windows;window]; |
---|
538 | |
---|
539 | end |
---|
540 | % create and save the requested time & port values as vectors |
---|
541 | times = [times;timeb]; |
---|
542 | reqports = [reqports; reqport]; |
---|
543 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
544 | % based on the created vectors, below command lines create |
---|
545 | % structs that will be out as results. |
---|
546 | % report carries information from the server report. Servrep |
---|
547 | % carries info from the client server report when dualtest or |
---|
548 | % tradeoff test was ran. report_port carries the used port |
---|
549 | % numbers of client and server. |
---|
550 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
551 | if UdpTcp == 1, |
---|
552 | report = struct('Transfer',t1','length',leng','req_bandwidth',req_band','bandwidth',b1','jitter',j1','losses',l1','totalpackets',tp1','requested_time_int',times','actual_time_int',ti','used_ports',reqports'); |
---|
553 | if mode == 2 || mode == 3, |
---|
554 | servrep = struct('Transfer',t3','length',leng','req_bandwidth',req_band','bandwidth',b3','jitter',j3','losses',l3','totalpackets', tp3','requested_time_int',times','actual_time_int',ti2','used_ports',reqports'); |
---|
555 | end |
---|
556 | elseif UdpTcp == 2, |
---|
557 | report = struct('Transfer',t1','bandwidth',b1','window',windows','requested_time_int',times','actual_time_int',ti','used_ports',reqports'); |
---|
558 | if mode == 2 || mode == 3, |
---|
559 | servrep = struct('Transfer',t3','bandwidth',b3,'window',windows','requested_time_int',times','actual_time_int',ti2','used_ports',reqports'); |
---|
560 | end |
---|
561 | end |
---|
562 | report_port = struct('s_address',t2,'s_port',b2,'c_address',j2,'c_port',l2); |
---|
563 | pnet(udp,'write',yes); |
---|
564 | pnet(udp,'writepacket',char(address),3333); |
---|
565 | nmep = sprintf('%d trial is done',numexp); |
---|
566 | disp(nmep); |
---|
567 | numexp = numexp + 1; |
---|
568 | data_old = data; |
---|
569 | save temp_matperf_data |
---|
570 | continue |
---|
571 | elseif data == 7, |
---|
572 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
573 | % when 7 is received from client, the server returns the result |
---|
574 | % to the matlab. |
---|
575 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
576 | disp('experiment done'); |
---|
577 | return |
---|
578 | else |
---|
579 | disp('no such code'); |
---|
580 | continue |
---|
581 | end |
---|
582 | |
---|
583 | else |
---|
584 | % give server time to prepare |
---|
585 | pnet('closeall'); |
---|
586 | udp = pnet('udpsocket',3333); |
---|
587 | continue; |
---|
588 | end |
---|
589 | end |
---|
590 | |
---|
591 | pnet('closeall'); |
---|
592 | |
---|
593 | return |
---|