source: PlatformSupport/matperf/client/matperfClient_StartExp.m

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

adding matperf

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1function matperfClient_StartExp(varargin)
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% options :
4%       UDP/TCP single
5%       UDP/TCP dualtest
6%       UDP/TCP tradeoff
7% usage :
8%       matperfClient_StartExp('UDP','10.96.94.199','dualtest')
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11
12UdpTcp  = 0; % UdpTcp is 1 when UDP and it is 2 when TCP
13clear_set;
14
15if strcmp(varargin(1),'UDP'),
16    UdpTcp = 1;
17    tmp_add = varargin(2);
18elseif strcmp(varargin(1), 'TCP'),
19    UdpTcp = 2;
20    tmp_add = varargin(2);
21end
22% tells matlab what mode user wants to use.
23if strcmp(varargin(3), 'single'),
24    mode = 1; % single
25elseif strcmp(varargin(3), 'dualtest'),
26    mode = 2; % dualtest
27elseif strcmp(varargin(3), 'tradeoff'),
28    mode = 3; % tradeoff
29else
30    return 
31end
32
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34% Ask server to generate & accept experiment
35% 0 - experiment request
36% 1 - trial request
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40% In the below while loop, it will generate a udp packet that includese whether
41% the client is in UDP/TCP single, dualtest or trade off mode and asks the
42% server to get ready for the experiment. If the server successfully
43% recognizes the request and be ready, it will send 0 back to the client
44% and matlab gets out of this while loop.
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46udp = pnet('udpsocket', 3333);
47packet = [0; UdpTcp; mode]; % prepares a package
48while(1),
49    pnet(udp,'write',packet);
50    pnet(udp,'writepacket',char(tmp_add),3333); % sends a packet carrying signal 0.
51    pnet(udp,'setreadtimeout',1.2); % wait for the response for 1.2 seconds
52    len = pnet(udp,'readpacket');
53    [address] = pnet(udp,'gethost');
54    if len == 0 || len < 0, % if the client does not receive the response
55        disp('server not responding...reasking to acknowledge');
56        pnet('closeall');
57        udp = pnet('udpsocket',3333);
58        continue;
59    elseif len >0,          % client has received a response.
60        data = pnet(udp,'read',1000,'double');
61        if data == 0,
62            disp('server approved experiment request');
63        else
64            disp('Wrong Code');
65            continue
66        end
67        break;
68    end
69end
70pnet('closeall');
71
72%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% calling the matperfClient_StartTrial(length, bandwidth, UdpTcp, mode)
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77% if need to define port #              %
78% define here                           %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80reqport = 5001; % default               %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82% if need to define time #              %
83% define here                           %
84time = 10; % default                    %
85%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86oneM = 1024 * 1024; % defined as 1 Mbits
87i = 1;
88%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89oneWM = 1024 * 8;
90%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91% when UDP is selected, the client will run the two for loops with
92% different values of bandwidth and length; and it will set the windows
93% value to 0, which is not needed here.
94%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95if UdpTcp == 1,
96    windows = 0;
97    for length = [200,1400]
98        for bandwidth = linspace(256*1024,oneM * 4,5)
99    %   for bandwidth = oneM*10
100            tic;
101            matperfClient_StartTrial(length, windows, bandwidth, UdpTcp, mode, time,address,reqport)
102            nem = sprintf('executed %d trial',i);
103            i = i + 1;
104            disp(nem);
105            toker = toc;
106            disp(toker) % Display how much time it took to run a experiment.
107
108           
109        end
110    end
111    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112    % when TCP is selected, length and bandwidth are kept constant and only
113    % window value is being changed
114    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115elseif UdpTcp == 2,
116    length = 0;
117    bandwidth = 0;
118    for windows = linspace(2* oneWM, 216* oneWM, 10)
119        matperfClient_StartTrial(length, windows, bandwidth, UdpTcp, mode, time,address,reqport)
120        nem = sprintf('executed %d trial',i);
121        reqport = reqport + 1;
122        i = i + 1;
123        disp(nem);
124    end
125   
126end
127return
Note: See TracBrowser for help on using the repository browser.