1 /** \file mad.h \brief General ALC stuff
2  *
3  *  $Author: peltotal $ $Date: 2007/02/26 13:48:19 $ $Revision: 1.40 $
4  *
5  *  MAD-ALCLIB: Implementation of ALC/LCT protocols, Compact No-Code FEC,
6  *  Simple XOR FEC, Reed-Solomon FEC, and RLC Congestion Control protocol.
7  *  Copyright (c) 2003-2007 TUT - Tampere University of Technology
8  *  main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  *  In addition, as a special exception, TUT - Tampere University of Technology
25  *  gives permission to link the code of this program with the OpenSSL library (or
26  *  with modified versions of OpenSSL that use the same license as OpenSSL), and
27  *  distribute linked combinations including the two. You must obey the GNU
28  *  General Public License in all respects for all of the code used other than
29  *  OpenSSL. If you modify this file, you may extend this exception to your version
30  *  of the file, but you are not obligated to do so. If you do not wish to do so,
31  *  delete this exception statement from your version.
32  */
33 
34 #ifndef _MAD_H_
35 #define _MAD_H_
36 
37 #ifdef LINUX
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
42 #endif
43 
44 #include "utils.h"
45 #include "defines.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * Is library initialized?
53  */
54 
55 extern BOOL lib_init;
56 
57 /**
58  * Structure for ALC level arguments.
59  * @struct alc_arguments
60  */
61 
62 typedef struct alc_arguments {
63   unsigned long long tsi;				/**< transport session identifier */
64   unsigned long long start_time;			/**< start time of the session */
65   unsigned long long stop_time;			/**< stop time of the session */
66 
67   const char *port;                     /**< base channel port number  */
68   const char *addr;                     /**< base channel multicastast address */
69   const char *intface;                  /**< local interface to bind */
70   const char *intface_name;             /**< name/index of local interface for IPv6 multicast join */
71   unsigned int addr_family;             /**< address family */
72   unsigned char addr_type;              /**< address type, multicast (0) or unicast (1) */
73   unsigned char mode;                   /**< mode for the session (sender or receiver) */
74   unsigned char nb_channel;             /**< number of channels in the session */
75   unsigned char cc_id;                  /**< used congestion control, 0 = NULL, 1 = RLC */
76   unsigned char rx_memory_mode;         /**< used memory mode in the receiver */
77   int verbosity;                        /**< verbosity level */
78   const char *src_addr;                 /**< source address for the session in the receiver */
79   char base_dir[MAX_PATH_LENGTH];       /**< Base directory for downloaded/sent files */
80   BOOL accept_expired_fdt_inst;			/**< accept expired FDT instances */
81 
82 #ifdef SSM
83   BOOL use_ssm;                         /**< use source specific multicast */
84 #endif
85 
86   unsigned int tx_rate;                 /**< transmission rate in kbit/s */
87   unsigned char ttl;                    /**< time to live */
88   unsigned short nb_tx;                 /**< how many times to send the file/directory? */
89   BOOL simul_losses;                    /**< Simulate packet losses */
90   double loss_ratio1;                   /**< packet loss ratio one */
91   double loss_ratio2;                   /**< packet loss ratio two */
92   unsigned short fec_ratio;             /**< FEC ratio percent */
93   unsigned short es_len;                /**< encoding symbol length */
94   unsigned int max_sb_len;              /**< maximum Source block length */
95   unsigned char fec_enc_id;             /**< FEC encoding id */
96   unsigned short fec_inst_id;           /**< FEC instance id */
97   BOOL use_fec_oti_ext_hdr;             /**< use FEC OTI extension header */
98   unsigned char encode_content;         /**< encode content using zlib library (0 = no, 1 = FDT, 2 = FDT and files) */
99   BOOL half_word;						/**< use half word flag */
100   BOOL optimize_tx_rate;				/**< optimize transmission rate (use more CPU) */
101   BOOL calculate_session_size;
102 
103 } alc_arguments_t;
104 
105 #ifdef _MSC_VER
106 /**
107  * lldiv_t structure.
108  */
109 
110 typedef struct {
111   long long quot;
112   long long rem;
113 }lldiv_t;
114 #endif
115 
116 /**
117  * This function initializes the library.
118  *
119  */
120 
121 void alc_init(void);
122 
123 /**
124  * This function return number of seconds since sec_init() function was called.
125  *
126  * @return time since sec_init() was called
127  *
128  */
129 
130 double sec(void);
131 
132 /**
133  * This function increses IPv6 address by one.
134  *
135  * @param ipv6 pointer to IPv6 address to be increased
136  *
137  * @return 0 in success, -1 otherwise
138  *
139  */
140 
141 int increase_ipv6_address(struct in6_addr *ipv6);
142 
143 /**
144  * This function simulates packets losses randomly.
145  *
146  * @param lossprob loss probability percent
147  *
148  * @return 1 if packet should be dropped, 0 otherwize
149  *
150  */
151 
152 int randomloss(double lossprob);
153 
154 #ifdef _MSC_VER
155 /*
156  * This function computes the quotient and remainder of an integer division.
157  *
158  * @param num numerator
159  * @param denom denumerator
160  *
161  * @return lldiv_t structure
162  *
163  */
164 
165 lldiv_t lldiv(long long num, long long denom);
166 #endif
167 
168 #ifdef __cplusplus
169 }; //extern "C"
170 #endif
171 
172 #endif
173 
174