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