rude.h 5.82 KB
Newer Older
Sampo Saaristo's avatar
Sampo Saaristo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*****************************************************************************
 *   rude.h
 *
 *   Copyright (C) 1999 Juha Laine and Sampo Saaristo
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *   Authors:      Juha Laine     <james@cs.tut.fi>
 *                 Sampo Saaristo <sambo@cc.tut.fi>
 *
 *****************************************************************************/
#ifndef _RUDE_H
#define _RUDE_H

#include <netinet/in.h>  /* for struct sockaddr_in */
#include <sys/time.h>    /* for struct timeval     */
29
#include <stdint.h>
Sampo Saaristo's avatar
Sampo Saaristo committed
30 31 32

#define DNMAXLEN 128
#define TMAXLEN  32
Arne Øslebø's avatar
Arne Øslebø committed
33 34
#define PMINSIZE 24     /* Minimum accepted UDP-data field/packet size, in previouse version it was 20      */
#define PMINSIZE_V6 40	/* Minimum accepted UDP-data field/packet size for ipv6      */
Sampo Saaristo's avatar
Sampo Saaristo committed
35 36 37
#define PMAXSIZE 32768  /* Maximum accepted UDP-data field/packet size      */
#define MINDURAT 0.001  /* Minimum allowed flow duration in seconds (float) */

38
#define VERSION "0.9.2"
Sampo Saaristo's avatar
Sampo Saaristo committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

/*
 * Enumeration definition for different (known) flow types
 */
typedef enum {
  UNKNOWN = -1,
  CBR = 1,
  CONSTANT = 1,
  TRACE = 2
} f_type;


/*
 * Private struct for CONSTANT BIT RATE traffic
 */
struct cbr_params{
  f_type ftype;                        /* Flow TRAFFIC TYPE              */
Arne Øslebø's avatar
Arne Øslebø committed
56
  int    rate;                         /* Flow PACKET RATE - PACKAGE RATE per PERIOD */
Sampo Saaristo's avatar
Sampo Saaristo committed
57
  int    psize;                        /* Flow PACKET SIZE               */
Arne Øslebø's avatar
Arne Øslebø committed
58 59
  int 	 package_size;				   /* Flow NUMBER OF PACKETS IN ONE PACKAGE*/
  int    time_period;					   /* Flow TIME_PERIOD */		
Sampo Saaristo's avatar
Sampo Saaristo committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
};

/*
 * Private structs for TRACE based traffic
 */
struct trace_list{
  int    psize;                        /* XMITTED PACKET SIZE        */
  struct timeval wait;                 /* TIME TO WAIT FOT NEXT XMIT */
};

struct trace_params{
  f_type ftype;                        /* Flow TRAFFIC TYPE       */
  int          max_psize;              /* PRECALCULATED VALUE...  */
  unsigned int list_size;              /* # OF PACKETS IN TRACE   */
  unsigned int list_index;             /* CURRENT INDEX IN TRACE  */
  struct trace_list* list;             /* ACTUAL TRACE PARAMETERS */
};


/*
 * The main building block for flows
 */
struct flow_cfg {
Arne Øslebø's avatar
Arne Øslebø committed
83 84 85 86 87 88
  struct flow_cfg     *next;            /* Pointer to NEXT flow           */
  struct flow_cfg     *mod_flow;        /* Next action-block for the flow */
  struct sockaddr_storage dst;              /* Destination information        */
  int                 send_sock;	       /* Socket to be used by this flow */

	
89 90
  uint32_t            flow_id;          /* Flow IDENTIFICATION number     */
  uint16_t            flow_sport;       /* Flow SOURCE PORT number        */
Arne Øslebø's avatar
Arne Øslebø committed
91 92 93
  struct timeval      flow_start;       /* Absolute flow cmd START TIME   */
  struct timeval      flow_stop;        /* Absolute flow cmd END TIME     */
  struct timeval      next_tx;          /* Absolute next packet TX TIME   */
Sampo Saaristo's avatar
Sampo Saaristo committed
94 95 96 97 98 99 100 101

  void (*send_func)(struct flow_cfg*); /* TX function for this flow */

  int errors;                          /*                   */
  int success;                         /* Internal counters */
  int sequence_nmbr;                   /*                   */

  int tos;                             /* IP TOS byte if positive */
Arne Øslebø's avatar
Arne Øslebø committed
102 103
  char 				*localIf;			/* local interface to be used with multicast */	
  char prefferedVersion; 				/*preffered ip version(4 or 6)*/
Sampo Saaristo's avatar
Sampo Saaristo committed
104 105 106 107 108 109 110 111 112 113 114 115
  union {
    f_type              ftype;
    struct cbr_params   cbr;
    struct trace_params trace;
  } params;
};


/*
 * Wrapper structure that helps filling the "header" to the buffer
 */
struct udp_data{
116 117 118 119
  uint32_t sequence_number;
  uint32_t tx_time_seconds; 
  uint32_t tx_time_useconds; 
  uint32_t flow_id;
Arne Øslebø's avatar
Arne Øslebø committed
120
  struct sockaddr_storage dest_addr;
Sampo Saaristo's avatar
Sampo Saaristo committed
121 122 123 124 125 126 127
}__attribute__ ((packed));


/*
 * Structure used by the CRUDE
 */
struct crude_struct{
128 129
  uint32_t  rx_time_seconds;
  uint32_t  rx_time_useconds;
Arne Øslebø's avatar
Arne Øslebø committed
130
  //struct in6_addr  src_addr;
131
  uint32_t           pkt_size;
Arne Øslebø's avatar
Arne Øslebø committed
132 133
  struct sockaddr_storage src; 
	//unsigned short src_port;
134
  uint16_t dest_port;
Sampo Saaristo's avatar
Sampo Saaristo committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
};

 
/*
 * Debug print macros - neat isn't it :)
 */
#if (DEBUG > 0)
#  define RUDEBUG1(msg...) fprintf(stderr, ## msg)
#else
#  define RUDEBUG1(msg...) {}
#endif

#if (DEBUG > 6)
#  define RUDEBUG7(msg...) fprintf(stderr, ## msg)
#else
#  define RUDEBUG7(msg...) {}
#endif

/* Some macro definitions. Added for non-Linux systems :) */
#ifndef timeradd
#define timeradd(a, b, result)                           \
  do {                                                   \
    (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;        \
    (result)->tv_usec = (a)->tv_usec + (b)->tv_usec;     \
    if ((result)->tv_usec >= 1000000)                    \
      {                                                  \
        ++(result)->tv_sec;                              \
        (result)->tv_usec -= 1000000;                    \
      }                                                  \
  } while (0)
#endif

Arne Øslebø's avatar
Arne Øslebø committed
167 168 169 170 171 172 173 174 175 176 177 178 179
#ifndef timespecsub
  #define	timespecsub(tsp, usp, vsp)					\
	do {								\
		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;		\
		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;	\
		if ((vsp)->tv_nsec < 0) {				\
			(vsp)->tv_sec--;				\
			(vsp)->tv_nsec += 1000000000L;			\
		}							\
	} while (0)
#endif
  
  
Sampo Saaristo's avatar
Sampo Saaristo committed
180
#endif /* _RUDE_H */