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
Line 
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
21function wl_setup
22
23REQUIRED_MEX_VERSION = '1.0.4a';
24
25
26fprintf('Setting up WARPLab Paths...\n');
27
28%------------------------------------------------------------------------------
29% Remove any paths from previous WARPLab installations
30
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
38% Remove legacy WARPLab v6 paths
39%   NOTE:  warplab_defines is not used in WARPLab v7
40done = false;
41while(~done)
42    [wl_path,ig,ig] = fileparts(which('warplab_defines'));
43    if(~isempty(wl_path))
44        fprintf('   removing path ''%s''\n',wl_path);
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
55    else
56        done = true;
57    end
58end
59
60% Check on  .../M_Code_Reference/classes
61done = false;
62while(~done)
63    [wl_path,ig,ig] = fileparts(which('wl_node'));
64    if(~isempty(wl_path))
65        fprintf('   removing path ''%s''\n',wl_path);
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
76    else
77        done = true;
78    end
79end
80
81% Check on  .../M_Code_Reference/util
82done = false;
83while(~done)
84    [wl_path,ig,ig] = fileparts(which('wl_ver'));
85    if(~isempty(wl_path))
86        fprintf('   removing path ''%s''\n',wl_path);
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
97    else
98        done = true;
99    end
100end
101
102% Check on  .../M_Code_Reference/util/inifile
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);
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
118    else
119        done = true;
120    end
121end
122
123% Check on  .../M_Code_Reference/config
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);
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
139    else
140        done = true;
141    end
142end
143
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);
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
160    else
161        done = true;
162    end
163end
164
165
166
167%------------------------------------------------------------------------------
168% Add new paths
169
170% Add  .../M_Code_Reference/classes
171myPath = sprintf('%s%sclasses',pwd,filesep);
172fprintf('   adding path ''%s''\n',myPath);
173addpath(myPath)
174
175% Add  .../M_Code_Reference/util
176myPath = sprintf('%s%sutil',pwd,filesep);
177fprintf('   adding path ''%s''\n',myPath);
178addpath(myPath)
179
180% Add  .../M_Code_Reference/util/inifile
181myPath = sprintf('%s%sutil%sinifile',pwd,filesep,filesep);
182fprintf('   adding path ''%s''\n',myPath);
183addpath(myPath)
184
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
191configPath = sprintf('%s%sconfig',pwd,filesep);
192fprintf('   adding path ''%s''\n',configPath);
193addpath(configPath) 
194
195configFile = sprintf('%s%swl_config.ini',configPath,filesep);
196
197% Example of adding a user path to WARPLab setup:
198%   In this example, C:\WARP_Repository\ResearchApps\PHY\WARPLAB\WARPLab7\M_Code_Reference\mex is added to the MATLAB path
199%
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)
203
204fprintf('   saving path\n\n\n');
205savepath
206
207%------------------------------------------------------------------------------
208% Read config file
209
210IP                         = '';
211host                       = '';
212port_unicast               = '';
213port_bcast                 = '';
214transport                  = '';
215max_transport_payload_size = '';
216
217% Read existing config file for defaults
218if(exist(configFile))
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');
222   
223    readKeys = {'network', '', 'host_address',''};
224    IP = inifile(configFile, 'read', readKeys);
225    IP = IP{1};
226   
227    readKeys = {'network', '', 'host_ID', ''};
228    host = inifile(configFile, 'read', readKeys);
229    host = host{1};
230   
231    readKeys = {'network', '', 'unicast_starting_port', ''};
232    port_unicast = inifile(configFile, 'read', readKeys);
233    port_unicast = port_unicast{1}; 
234   
235    readKeys = {'network', '', 'bcast_port', ''};
236    port_bcast = inifile(configFile, 'read', readKeys);
237    port_bcast = port_bcast{1}; 
238   
239    readKeys = {'network', '', 'transport', ''};
240    transport = inifile(configFile, 'read', readKeys);
241    transport = transport{1}; 
242   
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};
246end
247
248% Sane Defaults
249if(isempty(IP))
250    IP = '10.0.0.250';
251end   
252if(isempty(host))
253    host = '250';
254end   
255if(isempty(port_unicast))
256    port_unicast = '9000';
257end   
258if(isempty(port_bcast))
259    port_bcast = '10000';
260end   
261% if(isempty(transport))               % Moved lower in the function
262%     transport = 'java';
263% end   
264if(isempty(max_transport_payload_size))
265    max_transport_payload_size = '1470';
266end   
267
268inifile(configFile,'new')
269
270writeKeys = {'config_info', '', 'date_created', date};
271inifile(configFile, 'write', writeKeys, 'tabbed')
272
273[MAJOR,MINOR,REVISION] = wl_ver();
274writeKeys = {'config_info', '', 'wl_ver', sprintf('%d.%d.%d', MAJOR, MINOR, REVISION)};
275inifile(configFile, 'write', writeKeys, 'tabbed')
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')
281fprintf('IP address of: %s\n\n', IP);
282
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
301end
302
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
315writeKeys = {'network', '', 'host_address', temp};
316inifile(configFile, 'write', writeKeys, 'tabbed')
317
318fprintf('\n\n')
319fprintf('------------------------------------------------------------\n')
320fprintf('Please enter a WARPLab host ID.\n')
321fprintf('Valid host IDs are integers in the range of [200,254]\n\n')
322fprintf('Pressing enter without typing an input will use a default\n')
323fprintf('host ID of: %s\n\n', host);
324
325temp = input('WARPLab Host ID: ', 's');
326if(isempty(temp))
327   temp = host; 
328   if(isempty(str2num(temp)))
329        error('Host ID must be an integer in the range of [200,254]');
330   else
331       if((str2num(temp) < 200) || ((str2num(temp) > 254)))
332           error('Host ID must be an integer in the range of [200,254]');
333       end
334   end
335   fprintf('   defaulting to %s\n', temp);
336else
337   if(isempty(str2num(temp)))
338        error('Host ID must be an integer in the range of [200,254]');
339   else
340       if((str2num(temp) < 200) || ((str2num(temp) > 254)))
341           error('Host ID must be an integer in the range of [200,254]');
342       end
343   end
344   
345   fprintf('   setting to %s\n', temp); 
346end
347
348writeKeys = {'network', '', 'host_ID', temp};
349inifile(configFile, 'write', writeKeys, 'tabbed')
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')
355fprintf('unicast starting port of: %s\n\n', port_unicast);
356
357temp = input('Unicast Starting Port: ', 's');
358if(isempty(temp))
359   temp = port_unicast; 
360   fprintf('   defaulting to %s\n', temp);
361else
362   fprintf('   setting to %s\n', temp); 
363end
364
365writeKeys = {'network', '', 'unicast_starting_port', temp};
366inifile(configFile, 'write', writeKeys, 'tabbed')
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')
373fprintf('broadcast port of: %s\n\n', port_bcast);
374
375temp = input('Broadcast Port: ', 's');
376if(isempty(temp))
377   temp = port_bcast; 
378   fprintf('   defaulting to %s\n', temp);
379else
380   fprintf('   setting to %s\n', temp); 
381end
382
383writeKeys = {'network', '', 'bcast_port', temp};
384inifile(configFile, 'write', writeKeys, 'tabbed')
385
386
387fprintf('\n\n')
388fprintf('------------------------------------------------------------\n')
389%%%%%%%% Transport Setup %%%%%%%%
390I_JAVA       = 1;
391I_WL_MEX_UDP = 2;
392
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';
397
398TRANS_AVAIL(I_JAVA)        = true;
399TRANS_AVAIL(I_WL_MEX_UDP)  = false;
400
401fprintf('Select from the following available transports:\n')
402
403try
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))
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');
415        version_req = REQUIRED_MEX_VERSION;
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')
421    end
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;
427end
428
429% Set MEX to be the default transport if available
430if(isempty(transport))
431    if(TRANS_AVAIL(I_WL_MEX_UDP))
432        transport = 'wl_mex_udp';
433    else
434        transport = 'java';
435    end
436end
437
438% Check if any transports are available
439if(any(TRANS_AVAIL)==0)
440   error('no supported transports were found installed on your computer'); 
441end
442
443defaultSel = 1;
444sel        = 1;
445for k = 1:length(TRANS_AVAIL)
446    if(TRANS_AVAIL(k))
447        if(strcmp(TRANS_NAME_SHORT{k}, transport))
448            defaultSel = sel;
449            fprintf('[%d] (default) %s\n', sel, TRANS_NAME_LONG{k})
450        else
451            fprintf('[%d]           %s\n', sel, TRANS_NAME_LONG{k})
452        end
453        selectionToIndex(sel) = k;
454        sel = sel + 1;
455    end
456end
457
458temp = input('Selection: ');
459if(isempty(temp))
460    temp = defaultSel;
461end
462
463if(temp>(sel-1))
464   error('invalid selection') 
465end
466
467transport = TRANS_NAME_SHORT{selectionToIndex(temp)};
468
469fprintf('   setting to %s\n', transport);
470
471writeKeys = {'network', '', 'transport', transport};
472inifile(configFile, 'write', writeKeys, 'tabbed')
473
474fprintf('\n\n')
475fprintf('------------------------------------------------------------\n')
476%%%%%%%% Transport Setup %%%%%%%%
477PAYLOAD_SIZE{1} = '1470';
478PAYLOAD_SIZE{2} = '5000';
479PAYLOAD_SIZE{3} = '8966';
480
481fprintf('Select from the following maximum transport payload size:\n')
482
483sel = 1;
484for k = 1:3
485
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;
501end
502
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
506temp = input('Selection: ');
507
508if(isempty(temp))
509   temp = defaultSel;
510end
511
512if(temp > (sel - 1))
513   error('invalid selection') 
514end
515
516max_transport_payload_size = PAYLOAD_SIZE{selectionToIndex(temp)};
517
518fprintf('   setting maximum transport payload size to %s bytes\n', max_transport_payload_size);
519
520writeKeys = {'network', '', 'max_transport_payload_size', max_transport_payload_size};
521inifile(configFile, 'write', writeKeys, 'tabbed')
522
523
524fprintf('\n\n')
525fprintf('------------------------------------------------------------\n')
526fprintf('\n\nSetup Complete\nwl_ver():\n');
527wl_ver()
528fprintf('\n')
529
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
536    warning('Matlab version does not support uint64 arithmetic.  Please use Matlab R2011a or later.');
537end
538
539end
Note: See TracBrowser for help on using the repository browser.