source: ResearchApps/PHY/WARPLAB/WARPLab7/M_Code_Reference/wl_setup.m

Last change on this file was 4975, checked in by welsh, 8 years ago

fixed typos.

File size: 16.9 KB
RevLine 
[2175]1%******************************************************************************
2% WARPLab Setup
3%
4% File   :  wl_setup.m
5% Authors:  Chris Hunter (chunter [at] mangocomm.com)
6%           Patrick Murphy (murphpo [at] mangocomm.com)
7%           Erik Welsh (welsh [at] mangocomm.com)
8% License:  Copyright 2013, Mango Communications. All rights reserved.
9%           Distributed under the WARP license  (http://warpproject.org/license)
10%
11%******************************************************************************
12% MODIFICATION HISTORY:
13%
14% Ver   Who  Date     Changes
15% ----- ---- -------- -------------------------------------------------------
16% 3.00a ejw  8/21/13  Update to use new WARPLab MEX transport;
17%                     Added mex/ directory to MATLAB path
18%
19%******************************************************************************
20
[1915]21function wl_setup
22
[4818]23REQUIRED_MEX_VERSION = '1.0.4a';
24
25
[1915]26fprintf('Setting up WARPLab Paths...\n');
27
[2175]28%------------------------------------------------------------------------------
29% Remove any paths from previous WARPLab installations
30
[2180]31% NOTE:  We had to add in code involving regular expressions to catch a absolute vs
32%     relative path issue that we found.  For example, if ./util exists in the path,
33%     then the previous version of the code will run forever because it will find
34%     the file using 'which' but then the absolute path returned will not be in the
35%     actual path.  Now, we use regular expressions to make sure the path exists
36%     before removing it.
37
[2175]38% Remove legacy WARPLab v6 paths
39%   NOTE:  warplab_defines is not used in WARPLab v7
[1915]40done = false;
41while(~done)
[2175]42    [wl_path,ig,ig] = fileparts(which('warplab_defines'));
[1915]43    if(~isempty(wl_path))
44        fprintf('   removing path ''%s''\n',wl_path);
[2180]45       
46        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
47        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
48        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
49               
50        if ( ~isempty( path_comp ) )       
51            rmpath(wl_path)
52        else
53            done = true;
54        end
[1915]55    else
56        done = true;
57    end
58end
59
[2175]60% Check on  .../M_Code_Reference/classes
[1915]61done = false;
62while(~done)
[2175]63    [wl_path,ig,ig] = fileparts(which('wl_node'));
[1915]64    if(~isempty(wl_path))
65        fprintf('   removing path ''%s''\n',wl_path);
[2180]66
67        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
68        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
69        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
70               
71        if ( ~isempty( path_comp ) )       
72            rmpath(wl_path)
73        else
74            done = true;
75        end
[1915]76    else
77        done = true;
78    end
79end
80
[2175]81% Check on  .../M_Code_Reference/util
[1915]82done = false;
83while(~done)
[2175]84    [wl_path,ig,ig] = fileparts(which('wl_ver'));
[1915]85    if(~isempty(wl_path))
86        fprintf('   removing path ''%s''\n',wl_path);
[2180]87
88        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
89        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
90        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
91               
92        if ( ~isempty( path_comp ) )       
93            rmpath(wl_path)
94        else
95            done = true;
96        end
[1915]97    else
98        done = true;
99    end
100end
101
[2175]102% Check on  .../M_Code_Reference/util/inifile
[1915]103done = false;
104while(~done)
105    [wl_path,ig,ig] = fileparts(which('inifile'));
106    if(~isempty(wl_path))
107        fprintf('   removing path ''%s''\n',wl_path);
[2180]108
109        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
110        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
111        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
112               
113        if ( ~isempty( path_comp ) )       
114            rmpath(wl_path)
115        else
116            done = true;
117        end
[1915]118    else
119        done = true;
120    end
121end
122
[2175]123% Check on  .../M_Code_Reference/config
[1915]124done = false;
125while(~done)
126    [wl_path,ig,ig] = fileparts(which('wl_config.ini'));
127    if(~isempty(wl_path))
128        fprintf('   removing path ''%s''\n',wl_path);
[2180]129
130        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
131        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
132        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
133               
134        if ( ~isempty( path_comp ) )       
135            rmpath(wl_path)
136        else
137            done = true;
138        end
[1915]139    else
140        done = true;
141    end
142end
143
[2175]144% Check on  .../M_Code_Reference/mex
145done = false;
146while(~done)
147    [wl_path,ig,ig] = fileparts(which('wl_mex_udp_transport'));
148    if(~isempty(wl_path))
149        fprintf('   removing path ''%s''\n',wl_path);
[2180]150
151        my_path     = regexprep( sprintf('%s', path), ';', ' ' );
152        search_term = regexprep( sprintf('%s ',wl_path), '\\', '\\\\' );
153        path_comp   = regexp( sprintf('%s',my_path), sprintf('%s',search_term), 'match' );
154               
155        if ( ~isempty( path_comp ) )       
156            rmpath(wl_path)
157        else
158            done = true;
159        end
[2175]160    else
161        done = true;
162    end
163end
164
165
166
167%------------------------------------------------------------------------------
168% Add new paths
169
170% Add  .../M_Code_Reference/classes
[1940]171myPath = sprintf('%s%sclasses',pwd,filesep);
172fprintf('   adding path ''%s''\n',myPath);
173addpath(myPath)
[1915]174
[2175]175% Add  .../M_Code_Reference/util
[1940]176myPath = sprintf('%s%sutil',pwd,filesep);
177fprintf('   adding path ''%s''\n',myPath);
178addpath(myPath)
[1915]179
[2175]180% Add  .../M_Code_Reference/util/inifile
[1940]181myPath = sprintf('%s%sutil%sinifile',pwd,filesep,filesep);
182fprintf('   adding path ''%s''\n',myPath);
183addpath(myPath)
[1915]184
[2175]185% Add  .../M_Code_Reference/mex
186myPath = sprintf('%s%smex',pwd,filesep);
187fprintf('   adding path ''%s''\n',myPath);
188addpath(myPath)
189
190% Add  .../M_Code_Reference/config
[1940]191configPath = sprintf('%s%sconfig',pwd,filesep);
192fprintf('   adding path ''%s''\n',configPath);
193addpath(configPath) 
[1915]194
[1940]195configFile = sprintf('%s%swl_config.ini',configPath,filesep);
[1915]196
[2149]197% Example of adding a user path to WARPLab setup:
[2175]198%   In this example, C:\WARP_Repository\ResearchApps\PHY\WARPLAB\WARPLab7\M_Code_Reference\mex is added to the MATLAB path
[2149]199%
[2175]200% myPath = sprintf('C:%sWARP_Repository%sResearchApps%sPHY%sWARPLAB%sWARPLab7%sM_Code_Reference%smex',filesep,filesep,filesep,filesep,filesep,filesep,filesep);
201% fprintf('   adding path ''%s''\n',myPath);
202% addpath(myPath)
[2149]203
[1915]204fprintf('   saving path\n\n\n');
205savepath
206
[2175]207%------------------------------------------------------------------------------
208% Read config file
209
[4375]210IP                         = '';
211host                       = '';
212port_unicast               = '';
213port_bcast                 = '';
214transport                  = '';
215max_transport_payload_size = '';
[1924]216
[4375]217% Read existing config file for defaults
218if(exist(configFile))
[1915]219    fprintf('A wl_config.ini file was found in your path. Values specified in this\n');
220    fprintf('configuration file will be used as defaults in the construction of the\n');
221    fprintf('new file.\n');
[4375]222   
223    readKeys = {'network', '', 'host_address',''};
224    IP = inifile(configFile, 'read', readKeys);
[1915]225    IP = IP{1};
226   
[4375]227    readKeys = {'network', '', 'host_ID', ''};
228    host = inifile(configFile, 'read', readKeys);
[1915]229    host = host{1};
230   
[4375]231    readKeys = {'network', '', 'unicast_starting_port', ''};
232    port_unicast = inifile(configFile, 'read', readKeys);
[1915]233    port_unicast = port_unicast{1}; 
234   
[4375]235    readKeys = {'network', '', 'bcast_port', ''};
236    port_bcast = inifile(configFile, 'read', readKeys);
[1915]237    port_bcast = port_bcast{1}; 
238   
[4375]239    readKeys = {'network', '', 'transport', ''};
240    transport = inifile(configFile, 'read', readKeys);
[1915]241    transport = transport{1}; 
[1997]242   
[4375]243    readKeys = {'network', '', 'max_transport_payload_size', ''};
244    max_transport_payload_size = inifile(configFile, 'read', readKeys);
245    max_transport_payload_size = max_transport_payload_size{1};
[1924]246end
247
[4375]248% Sane Defaults
[1924]249if(isempty(IP))
250    IP = '10.0.0.250';
251end   
252if(isempty(host))
[1915]253    host = '250';
[1924]254end   
255if(isempty(port_unicast))
[1915]256    port_unicast = '9000';
[1924]257end   
258if(isempty(port_bcast))
259    port_bcast = '10000';
260end   
[4416]261% if(isempty(transport))               % Moved lower in the function
262%     transport = 'java';
263% end   
[4375]264if(isempty(max_transport_payload_size))
265    max_transport_payload_size = '1470';
[1997]266end   
[1915]267
268inifile(configFile,'new')
269
[4375]270writeKeys = {'config_info', '', 'date_created', date};
271inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]272
273[MAJOR,MINOR,REVISION] = wl_ver();
[4375]274writeKeys = {'config_info', '', 'wl_ver', sprintf('%d.%d.%d', MAJOR, MINOR, REVISION)};
275inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]276
277fprintf('\n\n')
278fprintf('------------------------------------------------------------\n')
279fprintf('Please enter a WARPLab Ethernet interface address.\n\n')
280fprintf('Pressing enter without typing an input will use a default\n')
[4375]281fprintf('IP address of: %s\n\n', IP);
[1915]282
[2347]283% Sanity check input due to errors users were experiencing on the forums
284ip_valid = 0;
285
286while( ip_valid == 0 ) 
287
288    temp = input('WARPNet Ethernet Interface Address: ','s');
289    if( isempty(temp) )
290       temp     = IP; 
291       ip_valid = 1;
292       fprintf('   defaulting to %s\n',temp);
293    else
294       if ( regexp( temp, '\d+\.\d+\.\d+\.\d+' ) == 1 ) 
295           ip_valid = 1;
296           fprintf('   setting to %s\n',temp)
297       else
298           fprintf('   %s is not a valid IP address.  Please enter a valid IP address.\n',temp); 
299       end
300    end
[1915]301end
302
[1924]303if(ispc)
304   [status, tempret] = system('ipconfig /all');
305elseif(ismac||isunix)
306   [status, tempret] = system('ifconfig -a');
307end
308tempret = strfind(tempret,temp);
309
310if(isempty(tempret))
311   warning('No interface found. Please ensure that your network interface is connected and configured with static IP %s',temp);
312   pause(1)
313end
314
[4375]315writeKeys = {'network', '', 'host_address', temp};
316inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]317
318fprintf('\n\n')
319fprintf('------------------------------------------------------------\n')
[2036]320fprintf('Please enter a WARPLab host ID.\n')
321fprintf('Valid host IDs are integers in the range of [200,254]\n\n')
[1915]322fprintf('Pressing enter without typing an input will use a default\n')
[4375]323fprintf('host ID of: %s\n\n', host);
[1915]324
[4375]325temp = input('WARPLab Host ID: ', 's');
[1915]326if(isempty(temp))
327   temp = host; 
[2036]328   if(isempty(str2num(temp)))
[2867]329        error('Host ID must be an integer in the range of [200,254]');
[2036]330   else
[4375]331       if((str2num(temp) < 200) || ((str2num(temp) > 254)))
[2867]332           error('Host ID must be an integer in the range of [200,254]');
[2036]333       end
334   end
[4375]335   fprintf('   defaulting to %s\n', temp);
[1915]336else
[2036]337   if(isempty(str2num(temp)))
[2867]338        error('Host ID must be an integer in the range of [200,254]');
[2036]339   else
[4375]340       if((str2num(temp) < 200) || ((str2num(temp) > 254)))
[2867]341           error('Host ID must be an integer in the range of [200,254]');
[2036]342       end
343   end
344   
[4375]345   fprintf('   setting to %s\n', temp); 
[1915]346end
347
[4375]348writeKeys = {'network', '', 'host_ID', temp};
349inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]350
351fprintf('\n\n')
352fprintf('------------------------------------------------------------\n')
353fprintf('Please enter a unicast starting port.\n\n')
354fprintf('Pressing enter without typing an input will use a default\n')
[4375]355fprintf('unicast starting port of: %s\n\n', port_unicast);
[1915]356
[4375]357temp = input('Unicast Starting Port: ', 's');
[1915]358if(isempty(temp))
359   temp = port_unicast; 
[4375]360   fprintf('   defaulting to %s\n', temp);
[1915]361else
[4375]362   fprintf('   setting to %s\n', temp); 
[1915]363end
364
[4375]365writeKeys = {'network', '', 'unicast_starting_port', temp};
366inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]367
368
369fprintf('\n\n')
370fprintf('------------------------------------------------------------\n')
371fprintf('Please enter a broadcast port.\n\n')
372fprintf('Pressing enter without typing an input will use a default\n')
[4375]373fprintf('broadcast port of: %s\n\n', port_bcast);
[1915]374
[4375]375temp = input('Broadcast Port: ', 's');
[1915]376if(isempty(temp))
377   temp = port_bcast; 
[4375]378   fprintf('   defaulting to %s\n', temp);
[1915]379else
[4375]380   fprintf('   setting to %s\n', temp); 
[1915]381end
382
[4375]383writeKeys = {'network', '', 'bcast_port', temp};
384inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]385
386
387fprintf('\n\n')
388fprintf('------------------------------------------------------------\n')
389%%%%%%%% Transport Setup %%%%%%%%
[2855]390I_JAVA       = 1;
391I_WL_MEX_UDP = 2;
[1915]392
[2149]393TRANS_NAME_LONG{I_JAVA}        = 'Java UDP';
394TRANS_NAME_SHORT{I_JAVA}       = 'java';
395TRANS_NAME_LONG{I_WL_MEX_UDP}  = 'WARPLab Mex UDP';
396TRANS_NAME_SHORT{I_WL_MEX_UDP} = 'wl_mex_udp';
[1915]397
[2084]398TRANS_AVAIL(I_JAVA)        = true;
[2149]399TRANS_AVAIL(I_WL_MEX_UDP)  = false;
[1915]400
[2149]401fprintf('Select from the following available transports:\n')
402
[4699]403try
[4818]404    version     = wl_mex_udp_transport('version');
405    version     = sscanf(version, '%d.%d.%d%c');
406    version_req = sscanf(REQUIRED_MEX_VERSION, '%d.%d.%d%c');
407
408    % Version must match required version   
409    if(version(1) == version_req(1) && version(2) == version_req(2) && version(3) == version_req(3) && version(4) >= version_req(4))
[4699]410        TRANS_AVAIL(I_WL_MEX_UDP) = true;
411    else
412        [major, minor, rev]  = wl_ver();
413        wl_version  = sprintf('v%d.%d.%d', major, minor, rev);
414        version     = wl_mex_udp_transport('version');
[4818]415        version_req = REQUIRED_MEX_VERSION;
[4699]416        fprintf('\nERROR:  MEX transport version mismatch: \n')
417        fprintf('ERROR:  WARPLab %s requires MEX transport version %s.\n', wl_version, version_req )
418        fprintf('ERROR:  Current complied version is %s.  \n', version)
419        fprintf('ERROR:  Please recompile to use the MEX transport:\n', version)
420        fprintf('ERROR:      http://warpproject.org/trac/wiki/WARPLab/MEX \n\n')
[2084]421    end
[4699]422   
423catch me
424    fprintf('   For better transport performance, please setup the WARPLab Mex UDP transport: \n')
425    fprintf('      http://warpproject.org/trac/wiki/WARPLab/MEX \n')
426    TRANS_AVAIL(I_WL_MEX_UDP) = false;
[2084]427end
428
[4375]429% Set MEX to be the default transport if available
[4416]430if(isempty(transport))
431    if(TRANS_AVAIL(I_WL_MEX_UDP))
432        transport = 'wl_mex_udp';
433    else
434        transport = 'java';
435    end
[4375]436end
437
438% Check if any transports are available
[1915]439if(any(TRANS_AVAIL)==0)
440   error('no supported transports were found installed on your computer'); 
441end
442
[2175]443defaultSel = 1;
444sel        = 1;
[1915]445for k = 1:length(TRANS_AVAIL)
446    if(TRANS_AVAIL(k))
[4375]447        if(strcmp(TRANS_NAME_SHORT{k}, transport))
[1915]448            defaultSel = sel;
[4375]449            fprintf('[%d] (default) %s\n', sel, TRANS_NAME_LONG{k})
[1915]450        else
[4375]451            fprintf('[%d]           %s\n', sel, TRANS_NAME_LONG{k})
[1915]452        end
453        selectionToIndex(sel) = k;
[4375]454        sel = sel + 1;
[1915]455    end
456end
457
458temp = input('Selection: ');
459if(isempty(temp))
[2175]460    temp = defaultSel;
[1915]461end
462
463if(temp>(sel-1))
464   error('invalid selection') 
465end
466
467transport = TRANS_NAME_SHORT{selectionToIndex(temp)};
468
[4375]469fprintf('   setting to %s\n', transport);
[1915]470
[4375]471writeKeys = {'network', '', 'transport', transport};
472inifile(configFile, 'write', writeKeys, 'tabbed')
[1915]473
[1997]474fprintf('\n\n')
[1915]475fprintf('------------------------------------------------------------\n')
[1997]476%%%%%%%% Transport Setup %%%%%%%%
[4375]477PAYLOAD_SIZE{1} = '1470';
478PAYLOAD_SIZE{2} = '5000';
479PAYLOAD_SIZE{3} = '8966';
[1915]480
[4375]481fprintf('Select from the following maximum transport payload size:\n')
[1915]482
[4375]483sel = 1;
484for k = 1:3
[1915]485
[4375]486    % Check if this exercises jumbo mode
487    if (str2num(PAYLOAD_SIZE{k}) <= 1470)
488        jumbo = '(non-jumbo)';
489    else
490        jumbo = '(jumbo)';
491    end
492
493    if(strcmp(PAYLOAD_SIZE{k}, max_transport_payload_size))
494        defaultSel = sel;
495        fprintf('[%d] (default) %s bytes %s\n', sel, PAYLOAD_SIZE{k}, jumbo)
496    else
497        fprintf('[%d]           %s bytes %s\n', sel, PAYLOAD_SIZE{k}, jumbo)
498    end
499    selectionToIndex(sel) = k;
500    sel = sel + 1;
[1997]501end
[1915]502
[4375]503fprintf('\nDepending on your host NIC and network setup you may be able to\n')
504fprintf('use larger packets to increase your transport performance.\n\n')
505
[1997]506temp = input('Selection: ');
[4375]507
[1997]508if(isempty(temp))
509   temp = defaultSel;
510end
[1915]511
[4375]512if(temp > (sel - 1))
[1997]513   error('invalid selection') 
514end
515
[4375]516max_transport_payload_size = PAYLOAD_SIZE{selectionToIndex(temp)};
[1997]517
[4375]518fprintf('   setting maximum transport payload size to %s bytes\n', max_transport_payload_size);
[1997]519
[4375]520writeKeys = {'network', '', 'max_transport_payload_size', max_transport_payload_size};
521inifile(configFile, 'write', writeKeys, 'tabbed')
[1997]522
523
524fprintf('\n\n')
525fprintf('------------------------------------------------------------\n')
[1915]526fprintf('\n\nSetup Complete\nwl_ver():\n');
527wl_ver()
[4975]528fprintf('\n')
[1915]529
[4974]530% Catch 64-bit support issues in Matlab during wl_setup
531try
532    temp_1 = uint64(0);
533    temp_2 = uint64(0);
534    result = temp_1 + temp_2;
535catch
[4975]536    warning('Matlab version does not support uint64 arithmetic.  Please use Matlab R2011a or later.');
[4974]537end
538
[1915]539end
Note: See TracBrowser for help on using the repository browser.