1 /*****************************************************************************
2  *   rude.h
3  *
4  *   Copyright (C) 1999 Juha Laine and Sampo Saaristo
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  *   Authors:      Juha Laine     <james@cs.tut.fi>
21  *                 Sampo Saaristo <sambo@cc.tut.fi>
22  *
23  *****************************************************************************/
24 #ifndef _RUDE_H
25 #define _RUDE_H
26 
27 #include <sys/types.h>
28 #include <netinet/in.h>  /* for struct sockaddr_in */
29 #include <sys/time.h>    /* for struct timeval     */
30 
31 #define DNMAXLEN 128
32 #define TMAXLEN  32
33 #define PMINSIZE 20     /* Minimum accepted UDP-data field/packet size      */
34 #define PMAXSIZE 32768  /* Maximum accepted UDP-data field/packet size      */
35 #define MINDURAT 0.001  /* Minimum allowed flow duration in seconds (float) */
36 
37 #define VERSION "0.70"
38 
39 /*
40  * Enumeration definition for different (known) flow types
41  */
42 typedef enum {
43   UNKNOWN = -1,
44   CBR = 1,
45   CONSTANT = 1,
46   TRACE = 2
47 } f_type;
48 
49 
50 /*
51  * Private struct for CONSTANT BIT RATE traffic
52  */
53 struct cbr_params{
54   f_type ftype;                        /* Flow TRAFFIC TYPE              */
55   int    rate;                         /* Flow PACKET RATE (per second)  */
56   int    psize;                        /* Flow PACKET SIZE               */
57 };
58 
59 /*
60  * Private structs for TRACE based traffic
61  */
62 struct trace_list{
63   int    psize;                        /* XMITTED PACKET SIZE        */
64   struct timeval wait;                 /* TIME TO WAIT FOT NEXT XMIT */
65 };
66 
67 struct trace_params{
68   f_type ftype;                        /* Flow TRAFFIC TYPE       */
69   int          max_psize;              /* PRECALCULATED VALUE...  */
70   unsigned int list_size;              /* # OF PACKETS IN TRACE   */
71   unsigned int list_index;             /* CURRENT INDEX IN TRACE  */
72   struct trace_list* list;             /* ACTUAL TRACE PARAMETERS */
73 };
74 
75 
76 /*
77  * The main building block for flows
78  */
79 struct flow_cfg {
80   struct flow_cfg    *next;            /* Pointer to NEXT flow           */
81   struct flow_cfg    *mod_flow;        /* Next action-block for the flow */
82   struct sockaddr_in dst;              /* Destination information        */
83   int                send_sock;	       /* Socket to be used by this flow */
84 
85   long int           flow_id;          /* Flow IDENTIFICATION number     */
86   unsigned short     flow_sport;       /* Flow SOURCE PORT number        */
87   struct timeval     flow_start;       /* Absolute flow cmd START TIME   */
88   struct timeval     flow_stop;        /* Absolute flow cmd END TIME     */
89   struct timeval     next_tx;          /* Absolute next packet TX TIME   */
90 
91   void (*send_func)(struct flow_cfg*); /* TX function for this flow */
92 
93   int errors;                          /*                   */
94   int success;                         /* Internal counters */
95   int sequence_nmbr;                   /*                   */
96 
97   int tos;                             /* IP TOS byte if positive */
98 
99   union {
100     f_type              ftype;
101     struct cbr_params   cbr;
102     struct trace_params trace;
103   } params;
104 };
105 
106 
107 /*
108  * Wrapper structure that helps filling the "header" to the buffer
109  */
110 struct udp_data{
111   unsigned long sequence_number;
112   unsigned long tx_time_seconds;
113   unsigned long tx_time_useconds;
114   unsigned long flow_id;
115   unsigned long dest_addr;
116 }__attribute__ ((packed));
117 
118 
119 /*
120  * Structure used by the CRUDE
121  */
122 struct crude_struct{
123   unsigned long  rx_time_seconds;
124   unsigned long  rx_time_useconds;
125   unsigned long  src_addr;
126   long           pkt_size;
127   unsigned short src_port;
128   unsigned short dest_port;
129 };
130 
131 
132 /*
133  * Debug print macros - neat isn't it :)
134  */
135 #if (DEBUG > 0)
136 #  define RUDEBUG1(msg...) fprintf(stderr, ## msg)
137 #else
138 #  define RUDEBUG1(msg...) {}
139 #endif
140 
141 #if (DEBUG > 6)
142 #  define RUDEBUG7(msg...) fprintf(stderr, ## msg)
143 #else
144 #  define RUDEBUG7(msg...) {}
145 #endif
146 
147 /* Some macro definitions. Added for non-Linux systems :) */
148 #ifndef timeradd
149 #define timeradd(a, b, result)                           \
150   do {                                                   \
151     (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;        \
152     (result)->tv_usec = (a)->tv_usec + (b)->tv_usec;     \
153     if ((result)->tv_usec >= 1000000)                    \
154       {                                                  \
155         ++(result)->tv_sec;                              \
156         (result)->tv_usec -= 1000000;                    \
157       }                                                  \
158   } while (0)
159 #endif
160 
161 #endif /* _RUDE_H */
162