main.c

Go to the documentation of this file.
00001 
00033 #include <stdlib.h>
00034 #include <sys/stat.h>
00035 #include <signal.h>
00036 #include <time.h>
00037 #include <stdio.h>
00038 
00039 #ifdef _MSC_VER
00040 #define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */
00041 #include <windows.h>
00042 #include <io.h>
00043 #include <crtdbg.h>
00044 #else
00045 #include <unistd.h>
00046 #endif
00047 
00048 #include "../flutelib/flute.h"
00049 
00054 #define _DEBUG_MEMORY 0
00055 
00056 int s_id; 
00065 void signal_handler(int sig){
00066 
00067   printf("Exiting...\n");
00068   fflush(stdout);
00069 
00070 #ifdef USE_FILE_REPAIR
00071   set_all_flute_sessions_state(SExiting);
00072 #else
00073   set_flute_session_state(s_id, SExiting);
00074 #endif
00075 }
00076 
00082 void usage(void) {
00083   printf("\nFLUTE Version %s, %s\n\n", MAD_FCL_RELEASE_VERSION, MAD_FCL_RELEASE_DATE);
00084   printf("  Copyright (c) 2003-2007 TUT - Tampere University of Technology\n");
00085   printf("  main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi\n");
00086   printf("  web site: http://www.atm.tut.fi/mad/\n\n");
00087   printf("  This is free software, and you are welcome to redistribute it\n");
00088   printf("  under certain conditions; See the GNU General Public License\n");
00089   printf("  as published by the Free Software Foundation, version 2 or later,\n");
00090   printf("  for more details.\n\n");
00091   printf("  * mad_rlc.c & mad_rlc.h -- Portions of code derived from MCLv3 library by\n");
00092   printf("  * Vincent Roca et al. (http://planete-bcast.inrialpes.fr/)\n");
00093   printf("  *\n");
00094   printf("  * Copyright (c) 1999-2004 INRIA - Universite Paris 6 - All rights reserved\n");
00095   printf("  * (main author: Julien Laboure - julien.laboure@inrialpes.fr\n");
00096   printf("  *               Vincent Roca - vincent.roca@inrialpes.fr)\n\n");
00097   printf("  * fec.c & fec.h -- forward error correction based on Vandermonde matrices\n");
00098   printf("  * 980624\n");
00099   printf("  * (C) 1997-98 Luigi Rizzo (luigi@iet.unipi.it)\n");
00100   printf("  *\n");
00101   printf("  * Portions derived from code by Phil Karn (karn@ka9q.ampr.org),\n");
00102   printf("  * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and\n");
00103   printf("  * Hari Thirumoorthy (harit@spectra.eng.hawaii.edu), Aug 1995\n");
00104   printf("  *\n");
00105   printf("  * Redistribution and use in source and binary forms, with or without\n");
00106   printf("  * modification, are permitted provided that the following conditions\n");
00107   printf("  * are met:\n");
00108   printf("  *\n");
00109   printf("  * 1. Redistributions of source code must retain the above copyright\n");
00110   printf("  *    notice, this list of conditions and the following disclaimer.\n");
00111   printf("  * 2. Redistributions in binary form must reproduce the above\n");
00112   printf("  *    copyright notice, this list of conditions and the following\n");
00113   printf("  *    disclaimer in the documentation and/or other materials\n");
00114   printf("  *    provided with the distribution.\n");
00115   printf("  *\n");
00116   printf("  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND\n");
00117   printf("  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n");
00118   printf("  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n");
00119   printf("  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS\n");
00120   printf("  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n");
00121   printf("  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n");
00122   printf("  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n");
00123   printf("  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n");
00124   printf("  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n");
00125   printf("  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT\n");
00126   printf("  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY\n");
00127   printf("  * OF SUCH DAMAGE.\n\n");
00128   printf("Sender usage: flute [-a:str] [-B:str] [-c:int] [-C] [-d:str] [-D:ull] [-e:int]\n"); 
00129   printf("                    [-f:str] [-F:str,str,...] [-G] [-h] [-H] [-i:str] [-k:int] [-l:int]\n");
00130   printf("                    [-L:int] [-m:str] [-n:int] [-p:int] [-P:float,float]\n");
00131   printf("                    [-q:int] [-r:int]");
00132 #ifdef USE_FILE_REPAIR
00133   printf(" [-R:str] [-S] [-t:ull] [-T:int] [-U]\n");
00134   printf("                    [-v:int] [-V:str] [-w:int] [-W] [-x:int] [-X:int] [-z:int]\n");
00135   printf("                    [-Z]\n\n");
00136 #else
00137   printf(" [-S] [-t:ull] [-T:int] [-U] [-v:int]\n");
00138   printf("                    [-V:str] [-w:int] [-W] [-x:int] [-X:int] [-z:int] [-Z]\n\n");
00139 #endif
00140   printf("Receiver usage: flute [-a:str] [-A] [-b:int] [-B:str] [-c:int] [-d:str] [-D:ull]\n"); 
00141   printf("                      [-E] [-F:str,str,...] [-h] [-i:str]"); 
00142 #ifdef _MSC_VER
00143   printf(" [-I:int]");
00144 #else
00145   printf(" [-I:str]");
00146 #endif
00147   printf(" [-m:str]"); 
00148 #ifdef SSM
00149   printf(" [-M]\n");
00150 #endif
00151   printf("                      [-N] [-o:ull]");
00152 #ifdef _MSC_VER
00153   printf(" [-O]");
00154 #endif
00155   printf(" [-p:int] [-P:float,float]");
00156 #ifdef USE_FILE_REPAIR
00157   printf(" [-R:str]\n");
00158   printf("                      [-s:str] [-t:ull] [-U] [-v:int] [-V:str] [-w:int] [-W]\n\n");
00159 #else
00160   printf(" [-s:str]\n");
00161   printf("                      [-t:ull] [-U] [-v:int] [-V:str] [-w:int] [-W]\n\n");
00162 #endif
00163   printf("Common options:\n\n");
00164   printf("   -a:str           Address family [IPv4 or IPv6], default: IPv4\n");
00165   printf("   -d:str           SDP file (start/join FLUTE session based on SDP file),\n");
00166   printf("                    default: no\n");
00167   printf("   -h               Print this help\n");
00168   printf("   -i:str           Local interface to bind to, default: INADDR_ANY\n");
00169   printf("   -m:str           IPv4 or IPv6 address for base channel,\n");
00170   printf("                    default: %s or %s\n", DEF_MCAST_IPv4_ADDR, DEF_MCAST_IPv6_ADDR);
00171   printf("   -p:int           Port number for base channel, default: %s\n", DEF_MCAST_PORT);
00172   printf("   -P[:float,float] Simulate packet losses, default packet loss\n");
00173   printf("                    percentages: %.1f,%.1f\n", (float)P_LOSS_WHEN_OK, (float)P_LOSS_WHEN_LOSS);
00174   printf("   -S               Act as sender, send data; otherwise receive data\n");
00175   printf("   -t:ull           TSI for the session, default: %i\n", DEF_TSI);
00176   printf("   -U               Address type is unicast, default: multicast\n");
00177   printf("   -v:int           Log verbosity level [0 = No output, 1 = File level,\n");
00178   printf("                    2 = 1 + percent, 3 = 2 + blocks, 4 = 3 + FDT], default: 1\n");
00179   printf("   -V:str           Print logs to 'str' file, default: print to stdout\n");  
00180   printf("   -w:int           Congestion control scheme [0 = Null, 1 = RLC],\n");
00181   printf("                    default: %i; the number of channels, defined by -c option,\n", DEF_CC);
00182   printf("                    are used with both schemes and bitrate of each channel is\n");
00183   printf("                    set according to RLC rules\n");
00184   printf("   -W               File table output mode. In receiver this work only with\n");
00185   printf("                    -A option\n\n");
00186   printf("Sender options:\n\n");
00187   printf("   -B:str           Base directory for files or directories to be sent,\n");
00188   printf("                    default: working directory\n");
00189   printf("   -c:int           Number of used channels, default: %i\n", DEF_NB_CHANNEL);
00190   printf("   -C               Continuous transmission, default: not used\n");
00191   printf("   -D:ull           Duration of the session in seconds, default: %i\n", DEF_SESSION_DURATION);
00192   printf("   -e:int           FEC-OTI for file objects\n");
00193   printf("                    [0 = FEC-OTI in FDT, 1 = FEC-OTI in EXT_FTI], default: 0\n");
00194   printf("   -f:str           FDT file (send based on FDT), default: %s\n", DEF_FDT);
00195   printf("   -F:str,str,...   Files or directories to be sent. Given base directory is\n");
00196   printf("                    same for all entries.\n");
00197   printf("   -G               Calculate session size, but do not send anything\n");
00198   printf("   -H               Use Half-word (when used, TSI field can be 16, 32 or 48\n");
00199   printf("                    bits long and TOI field can be 16, 32, 48 or 64 bits\n");
00200   printf("                    long), default: not used\n");
00201   printf("   -k:int           Send a Complete FDT in the beginning of the session\n");
00202   printf("                    [0 = No, 1 = Yes, 2 = Yes, only Complete FDT], default: 0\n");
00203   printf("   -l:int           Encoding symbol length in bytes, default: %i\n", DEF_SYMB_LENGTH);
00204   printf("   -L:int           Maximum source block length in multiple of encoding\n");
00205   printf("                    symbols, default: %i\n", DEF_MAX_SB_LEN);
00206   printf("   -n:int           Number of transmissions, default: %i\n", DEF_TX_NB);
00207   printf("   -q:int           Send session close packets [0 = No, 1 = Yes], default: 1\n");
00208   printf("   -r:int           Transmission rate at base channel in kbits/s, default: %i\n", DEF_TX_RATE);
00209 #ifdef USE_FILE_REPAIR
00210   printf("   -R[:str]         Save configuration to a file, default: %s\n", DEF_FLUTE_CONF_FILE);
00211 #endif
00212   printf("   -T:int           Time To Live or Hop Limit for the session, default: %i\n", DEF_TTL);
00213   printf("   -x:int           FEC Encoding [0 = Null, 1 = Simple XOR, 2 = Reed-Solomon\n");
00214   printf("                    (old I-D) 3 = Reed-Solomon (new I-D), default: %i\n", DEF_FEC);
00215   printf("   -X:int           FEC ratio percent, default: %i\n", DEF_FEC_RATIO);
00216 #ifdef USE_ZLIB
00217   printf("   -z:int           Encode content [0 = no, 1 = ZLIB FDT,\n");
00218   printf("                    2 = ZLIB FDT and GZIP files,\n");
00219   printf("                    3 = PAD files], default: 0\n");
00220 #else
00221   printf("   -z:int           Encode content [0 = no, 3 = PAD files],\n");
00222   printf("                    default: 0\n");
00223 #endif
00224   printf("   -Z               Optimize transmission rate (use more CPU)\n\n");
00225   printf("Receiver options:\n\n");
00226   printf("   -A               Receive files automatically\n");
00227   printf("   -b:int           Receiver's memory consumption [0 = high, 1 = medium,\n");
00228   printf("                    2 = low], default: 1\n");
00229   printf("   -B:str           Base directory for downloaded files,\n");
00230   printf("                    default: %s\n", DEF_BASE_DIR);
00231   printf("   -c:int           Maximum number of channels, default: %i\n", DEF_NB_CHANNEL);
00232   printf("   -D:ull           Reveiver will quit after this time (in seconds) if no\n");
00233   printf("                    packets is received from the session, default: %i\n", DEF_RECEIVER_TIMEOUT);
00234   printf("   -E               Accept expired FDT Instances\n");   
00235   printf("   -F:str,str,...   Files to be received\n");
00236 #ifdef _MSC_VER
00237   printf("   -I:int           Local interface index for IPv6 multicast join, use for\n");
00238   printf("                    example 'ipv6 if' command to see interface indexes;\n");
00239   printf("                    otherwise OS default\n");
00240 #else
00241   printf("   -I:str           Local interface name for IPv6 multicast join, use for\n");
00242   printf("                    example 'ifconfig' command to see interface names;\n");
00243   printf("                    otherwise OS default\n");
00244 #endif
00245 #ifdef SSM
00246   printf("   -M               Use Source-Specific Multicast, default: no\n");
00247 #endif
00248   printf("   -N               Name incomplete objects after the session has ended\n");
00249   printf("   -o:ull           TOI for the object to be received\n");
00250 #ifdef _MSC_VER
00251   printf("   -O               Open received file(s) automatically, default: no\n");
00252 #endif
00253 #ifdef USE_FILE_REPAIR
00254   printf("   -R[:str]         Use HTTP file repair with given config file, default:\n");
00255   printf("                    %s\n", DEF_APD_CONF_FILE);
00256 #endif
00257   printf("   -s:str           Source IPv4 or IPv6 address of this session. If not set,\n");
00258   printf("                    receiver locks to the first IP address found from the\n");
00259   printf("                    FLUTE packets.\n"); 
00260   printf("\nExample use cases:\n\n");
00261   printf("1. Send a file or directory n times\n\n\tflute -S -m:224.1.1.1 -p:4000 -t:2 -r:100 -F:files/flute-draft.txt\n");
00262   printf("\t      -n:2\n\n");
00263   printf("2. Send a file or directory in a loop\n\n\tflute -S -m:224.1.1.1 -p:4000 -t:2 -r:100 -F:files/flute-draft.txt\n");
00264   printf("\t      -C\n\n");
00265   printf("3. Send files defined in an FDT file\n\n\tflute -S -m:224.1.1.1 -p:4000 -t:2 -r:100 -f:fdt2.xml\n\n");
00266   printf("4. Send files defined in an FDT file in a loop\n\n\tflute -S -m:224.1.1.1 -p:4000 -t:2 -r:100 -f:fdt2.xml -C\n\n");
00267   printf("5. Send using unicast\n\n\tflute -S -U -m:1.2.3.4 -p:4000 -t:2 -r:100 -f:fdt2.xml -C\n\n");
00268   printf("6. Receive one object\n\n\tflute -m:224.1.1.1 -p:4000 -t:2 -s:2.2.2.2 -o:1\n\n");
00269   printf("7. Receive file(s) defined by file name(s)\n\n\tflute -m:224.1.1.1 -p:4000 -t:2 -s:2.2.2.2\n");
00270   printf("\t      -F:files/flute-man.txt,flute-draft.txt\n\n");
00271   printf("8. Receive file(s) defined by wild card option\n\n\tflute -m:224.1.1.1 -p:4000 -t:2 -s:2.2.2.2 -F:*.jpg\n\n");
00272   printf("9. Receive file(s) with User Interface\n\n\tflute -m:224.1.1.1 -p:4000 -t:2 -s:2.2.2.2\n\n");
00273   printf("10. Receive file(s) automatically from session\n\n\tflute -A -m:224.1.1.1 -p:4000 -t:2 -s:2.2.2.2\n\n");
00274   printf("11. Receive using unicast\n\n\tflute -A -U -p:4000 -t:2 -s:2.2.2.2\n\n");
00275   
00276   exit(1);
00277 }
00278 
00289 int main(int argc, char **argv) {
00290 
00291   int retval = 0;
00292     
00293   arguments_t a;
00294   unsigned long long session_size;
00295 
00296   /*flute_receiver_report_t *report;*/
00297 
00298 #if defined(_MSC_VER) && _DEBUG_MEMORY > 0
00299   _CrtSetDbgFlag(
00300         _CRTDBG_ALLOC_MEM_DF |
00301         _CRTDBG_CHECK_ALWAYS_DF |
00302         _CRTDBG_CHECK_CRT_DF |
00303         /*_CRTDBG_DELAY_FREE_MEM_DF |*/
00304         _CRTDBG_LEAK_CHECK_DF);
00305 #endif
00306   
00307   if(start_up_flute() != 0) {
00308     return -1;
00309   }
00310 
00311   /* Set signal handler */
00312   
00313   signal(SIGINT, signal_handler);
00314 #ifdef _MSC_VER
00315   signal(SIGBREAK, signal_handler);
00316 #endif
00317 
00318   srand((unsigned)time(NULL));
00319 
00320   retval = parse_args(argc, argv, &a);
00321   
00322   if(retval == -1) {
00323     usage();
00324   }
00325 
00326   s_id = -1;
00327   
00328   if(a.alc_a.mode == SENDER) {
00329     
00330     if(a.alc_a.calculate_session_size == TRUE) {
00331       
00332       session_size = flute_session_size(&a, &s_id);
00333 
00334       if(a.alc_a.verbosity > 0) {
00335 #ifdef _MSC_VER
00336         printf("Session size in bytes (including UDP/IP headers): %I64u\n", session_size);
00337 #else
00338         printf("Session size in bytes (including UDP/IP headers): %llu\n", session_size);
00339 #endif
00340       }
00341     }
00342     else {
00343       retval = flute_sender(&a, &s_id, &session_size);
00344 
00345       if(a.alc_a.verbosity > 0) {
00346 #ifdef _MSC_VER
00347         printf("Total bytes sent: %I64u\n", session_size);
00348 #else
00349         printf("Total bytes sent: %llu\n", session_size);
00350 #endif
00351       }
00352     }
00353   }
00354   else if(a.alc_a.mode == RECEIVER) {
00355     
00356     retval = flute_receiver(&a, &s_id);
00357     
00358     /*
00359     retval = flute_receiver_report(&a, &s_id, &report);
00360     free_receiver_report(report);
00361     */
00362   }
00363   
00364   shut_down_flute(&a);
00365 
00366   return retval;
00367 }

Generated on Fri Mar 9 19:59:52 2007 for MAD-FCL by  doxygen 1.5.0