3 @@ -37,6 +37,9 @@ $$LIC$$
5 #include <netinet/sctp.h>
13 @@ -123,6 +126,18 @@ static uint16_t g_lasttid;
14 static ipfix_datarecord_t g_data = { NULL, NULL, 0 }; /* ipfix_export */
16 static ipfix_field_t *g_ipfix_fields;
18 +static pthread_mutex_t g_mutex;
19 +#define mod_lock() { \
20 + if ( pthread_mutex_lock( &g_mutex ) !=0 ) \
21 + mlogf( 0, "[ipfix] mutex_lock() failed: %s\n", \
22 + strerror( errno ) ); \
24 +#define mod_unlock() { pthread_mutex_unlock( &g_mutex ); }
30 /*----- prototypes -------------------------------------------------------*/
32 @@ -133,6 +148,7 @@ int _ipfix_send_message( ipfix_t *ifh,
33 ipfix_message_t *message );
34 int _ipfix_write_msghdr( ipfix_t *ifh, ipfix_message_t *msg, iobuf_t *buf );
35 void _ipfix_disconnect( ipfix_collector_t *col );
36 +int _ipfix_export_flush( ipfix_t *ifh );
39 /* name : do_writeselect
40 @@ -576,16 +592,18 @@ int ipfix_decode_float( void *in, void *
42 int ipfix_snprint_float( char *str, size_t size, void *data, size_t len )
51 - ipfix_decode_float( data, &tmp32, 4);
52 - return snprintf( str, size, "%f", tmp32 );
53 + memcpy( &tmp32, data, len );
54 + tmp32 = htonl( tmp32 );
55 + return snprintf( str, size, "%f", (float)tmp32 );
57 - ipfix_decode_float( data, &tmp64, 8);
58 - return snprintf( str, size, "%lf", tmp64);
59 + memcpy( &tmp64, data, len );
60 + tmp64 = HTONLL( tmp64 );
61 + return snprintf( str, size, "%lf", (double)tmp64 );
65 @@ -682,12 +700,19 @@ int ipfix_get_eno_ieid( char *field, int
67 * remarks: init module, read field type info.
69 -int ipfix_init ( void )
70 +int ipfix_init( void )
77 + if ( pthread_mutex_init( &g_mutex, NULL ) !=0 ) {
78 + mlogf( 0, "[ipfix] pthread_mutex_init() failed: %s\n",
83 g_tstart = time(NULL);
84 signal( SIGPIPE, SIG_IGN );
86 @@ -806,6 +831,9 @@ void ipfix_cleanup ( void )
91 + (void)pthread_mutex_destroy( &g_mutex );
95 int _ipfix_connect ( ipfix_collector_t *col )
96 @@ -1465,7 +1493,7 @@ int _ipfix_write_template( ipfix_t
99 if ( tsize+ifh->offset > IPFIX_DEFAULT_BUFLEN ) {
100 - if ( ipfix_export_flush( ifh ) < 0 )
101 + if ( _ipfix_export_flush( ifh ) < 0 )
103 if ( tsize+ifh->offset > IPFIX_DEFAULT_BUFLEN )
105 @@ -1474,6 +1502,8 @@ int _ipfix_write_template( ipfix_t
106 /* write template prior to data */
107 if ( ifh->offset > 0 ) {
108 memmove( ifh->buffer + tsize, ifh->buffer, ifh->offset );
110 + ifh->cs_header += tsize;
114 @@ -1615,8 +1645,11 @@ int ipfix_open( ipfix_t **ipfixh, int so
120 node->next = g_ipfixlist;
126 @@ -1633,7 +1666,8 @@ void ipfix_close( ipfix_t *h )
130 - ipfix_export_flush( h );
132 + _ipfix_export_flush( h );
134 while( h->collectors )
135 _ipfix_drop_collector( (ipfix_collector_t**)&h->collectors );
136 @@ -1659,6 +1693,7 @@ void ipfix_close( ipfix_t *h )
144 @@ -2156,6 +2191,22 @@ void ipfix_release_template( ipfix_t *if
145 ipfix_delete_template( ifh, templ );
148 +static void _finish_cs( ipfix_t *ifh )
153 + /* finish current dataset */
154 + if ( (buf=ifh->cs_header) ==NULL )
157 + INSERTU16( buf+buflen, buflen, ifh->cs_tid );
158 + INSERTU16( buf+buflen, buflen, ifh->cs_bytes );
160 + ifh->cs_header = NULL;
164 int ipfix_export( ipfix_t *ifh, ipfix_template_t *templ, ... )
167 @@ -2199,13 +2250,14 @@ int ipfix_export( ipfix_t *ifh, ipfix_te
168 g_data.addrs, g_data.lens );
171 -int ipfix_export_array( ipfix_t *ifh,
172 - ipfix_template_t *templ,
175 - uint16_t *lengths )
177 +_ipfix_export_array( ipfix_t *ifh,
178 + ipfix_template_t *templ,
181 + uint16_t *lengths )
185 size_t buflen, datasetlen;
188 @@ -2249,7 +2301,19 @@ int ipfix_export_array( ipfix_t
190 /** get size of data set, check space
192 - for ( i=0, datasetlen=4; i<nfields; i++ ) {
193 + if ( templ->tid == ifh->cs_tid ) {
198 + if ( ifh->cs_tid > 0 ) {
205 + for ( i=0; i<nfields; i++ ) {
206 if ( templ->fields[i].flength == IPFIX_FT_VARLEN ) {
207 if ( lengths[i]>254 )
209 @@ -2263,21 +2327,29 @@ int ipfix_export_array( ipfix_t
211 datasetlen += lengths[i];
213 - if ( ((ifh->offset + datasetlen) > IPFIX_DEFAULT_BUFLEN )
214 - && (ipfix_export_flush( ifh ) <0) ) {
217 + if ( (ifh->offset + datasetlen) > IPFIX_DEFAULT_BUFLEN ) {
222 + if ( _ipfix_export_flush( ifh ) <0 )
229 buf = (uint8_t*)(ifh->buffer) + ifh->offset;
235 - INSERTU16( buf+buflen, buflen, templ->tid );
236 - INSERTU16( buf+buflen, buflen, datasetlen );
241 + ifh->cs_header = buf;
242 + ifh->cs_tid = templ->tid;
243 + INSERTU16( buf+buflen, buflen, templ->tid );
244 + INSERTU16( buf+buflen, buflen, 4 );
247 /* insert data record
249 @@ -2303,7 +2375,9 @@ int ipfix_export_array( ipfix_t
250 buflen += lengths[i];
254 ifh->offset += buflen;
255 + ifh->cs_bytes += buflen;
256 if ( ifh->version == IPFIX_VERSION )
259 @@ -2313,7 +2387,7 @@ int ipfix_export_array( ipfix_t
261 * remarks: rewrite this func!
263 -int ipfix_export_flush( ipfix_t *ifh )
264 +int _ipfix_export_flush( ipfix_t *ifh )
267 ipfix_collector_t *col;
268 @@ -2322,8 +2396,14 @@ int ipfix_export_flush( ipfix_t *ifh )
269 if ( (ifh==NULL) || (ifh->offset==0) )
272 - if ( (buf=_ipfix_getbuf()) ==NULL )
273 + if ( ifh->cs_tid > 0 ) {
274 + /* finish current dataset */
278 + if ( (buf=_ipfix_getbuf()) ==NULL ) {
283 mlogf( 0, "[ipfix_export_flush] msg has %d records, %d bytes\n",
284 @@ -2350,3 +2430,30 @@ int ipfix_export_flush( ipfix_t *ifh )
285 _ipfix_freebuf( buf );
289 +int ipfix_export_array( ipfix_t *ifh,
290 + ipfix_template_t *templ,
293 + uint16_t *lengths )
298 + ret = _ipfix_export_array( ifh, templ, nfields, fields, lengths );
304 +int ipfix_export_flush( ipfix_t *ifh )
309 + ret = _ipfix_export_flush( ifh );
317 @@ -142,6 +142,12 @@ typedef struct
318 int nrecords; /* no. of records in buffer */
319 size_t offset; /* output buffer fill level */
320 uint32_t seqno; /* sequence no. of next message */
323 + int cs_tid; /* template id of current dataset */
324 + int cs_bytes; /* size of current set */
325 + uint8_t *cs_header; /* start of current set */
330 --- a/lib/ipfix_col.c
331 +++ b/lib/ipfix_col.c
332 @@ -897,6 +897,8 @@ int ipfix_decode_datarecord( ipfixt_node
336 + n->ipfixt->fields[i].elem->decode(p,p,len);
341 @@ -907,7 +909,7 @@ int ipfix_decode_datarecord( ipfixt_node
345 -static void do_free_datarecord( ipfix_datarecord_t *data )
346 +void ipfix_free_datarecord( ipfix_datarecord_t *data )
350 @@ -925,6 +927,7 @@ int ipfix_parse_msg( ipfix_input_t *inpu
351 ipfix_hdr_t hdr; /* ipfix packet header */
353 ipfix_datarecord_t data = { NULL, NULL, 0 };
355 uint8_t *buf; /* ipfix payload */
356 uint16_t setid, setlen; /* set id, set lenght */
357 int i, nread, offset; /* counter */
358 @@ -1042,6 +1045,12 @@ int ipfix_parse_msg( ipfix_input_t *inpu
362 + for ( e=g_exporter; e!=NULL; e=e->next ) {
363 + if ( e->elem->export_dset )
364 + (void) e->elem->export_dset( t, buf+nread, setlen,
368 /** read data records
370 for ( offset=nread, bytesleft=setlen; bytesleft>4; ) {
371 @@ -1076,11 +1085,11 @@ int ipfix_parse_msg( ipfix_input_t *inpu
375 - do_free_datarecord( &data );
376 + ipfix_free_datarecord( &data );
380 - do_free_datarecord( &data );
381 + ipfix_free_datarecord( &data );
385 @@ -1093,7 +1102,7 @@ void process_client_tcp( int fd, int mas
386 tcp_conn_t *tcon = (tcp_conn_t*)data;
387 char *func = "process_client_tcp";
389 - mlogf( 3, "[%s] fd %d mask %d called.\n", func, fd, mask );
390 + mlogf( 4, "[%s] fd %d mask %d called.\n", func, fd, mask );
392 /** read ipfix header
394 --- a/lib/ipfix_col.h
395 +++ b/lib/ipfix_col.h
396 @@ -88,6 +88,7 @@ typedef struct ipfix_col_info
397 int (*export_newsource)(ipfixs_node_t*,void*);
398 int (*export_newmsg)(ipfixs_node_t*,ipfix_hdr_t*,void*);
399 int (*export_trecord)(ipfixs_node_t*,ipfixt_node_t*,void*);
400 + int (*export_dset)(ipfixt_node_t*,uint8_t*,size_t,void*);
401 int (*export_drecord)(ipfixs_node_t*,ipfixt_node_t*,
402 ipfix_datarecord_t*,void*);
403 void (*export_cleanup)(void*);
404 --- a/lib/ipfix_col_files.c
405 +++ b/lib/ipfix_col_files.c
406 @@ -68,7 +68,7 @@ static int export_newsource_file( ipfixs
409 snprintf( s->fname+strlen(s->fname), PATH_MAX-strlen(s->fname),
411 + "/%u", (unsigned int)s->odid );
412 if ( (access( s->fname, R_OK ) <0 )
413 && (mkdir( s->fname, S_IRWXU ) <0) ) {
414 mlogf( 0, "[%s] cannot access dir '%s': %s\n",
415 --- a/lib/ipfix_FOKUS_IEs.txt
416 +++ b/lib/ipfix_FOKUS_IEs.txt
418 196, IPFIX_FT_PKTID, 4, IPFIX_CODING_UINT, "pktId", "FOKUS packet id"
419 197, IPFIX_FT_STARTTIME, 4, IPFIX_CODING_INT, "startTime", "FOKUS interval start"
420 198, IPFIX_FT_ENDTIME, 4, IPFIX_CODING_INT, "endTime", "FOKUS interval end"
421 +199, IPFIX_FT_RTT_USEC, 8, IPFIX_CODING_UINT, "rtt_usec", "FOKUS rtt in us"
423 300, IPFIX_FT_FLOWCREATIONTIMEUSEC, 4, IPFIX_CODING_INT, "flowCreationTimeUsec", "FOKUS flow start usec fraction"
424 301, IPFIX_FT_FLOWENDTIMEUSEC, 4, IPFIX_CODING_INT, "flowEndTimeUsec", "FOKUS flow end usec fraction"
425 303, IPFIX_FT_TC_PACKETS, 4, IPFIX_CODING_UINT, "tcPackets", "DAIDALOS Packets seen"
427 313, IPFIX_FT_OWDVARMIN_NSEC, 4, IPFIX_CODING_INT, "owdvarmin_nsec", "FOKUS minimum owd variance in ns"
428 314, IPFIX_FT_OWDVARMAX_NSEC, 4, IPFIX_CODING_INT, "owdvarmax_nsec", "FOKUS maximum ow variance in ns"
430 +# Project INTERSECTION
431 +315, IPFIX_FT_SOURCEIPV4FANOUT, 4, IPFIX_CODING_UINT,"sourceIPv4FanOut", "FOKUS IPv4 fanout"
432 +316, IPFIX_FT_DESTINATIONIPV4FANIN, 4, IPFIX_CODING_UINT,"destinationIPv4FanIn", "FOKUS IPv4 fanin"
436 +330, IPFIX_FT_PR_SESSIONID, 4, IPFIX_CODING_UINT, "sessionId", "PRISM Session ID"
437 +331, IPFIX_FT_PR_TRANSACTIONID, 4, IPFIX_CODING_UINT, "transactionId", "PRISM Transaction ID"
438 +332, IPFIX_FT_PR_ENCRYPTEDDATA, 65535, IPFIX_CODING_STRING, "encryptedData", "PRISM encrypted data"
439 +333, IPFIX_FT_PR_DECRYPTIONKEY, 65535, IPFIX_CODING_STRING, "decryptionKey", "PRISM decryption key"
440 +334, IPFIX_FT_PR_KEYSHARE, 65535, IPFIX_CODING_STRING, "keyShare", "PRISM key share"
441 +335, IPFIX_FT_PR_KEYSHAREADP, 65535, IPFIX_CODING_STRING, "keyShareAdp", "PRISM key share ADP"
442 +336, IPFIX_FT_PR_INITVECTOR, 65535, IPFIX_CODING_STRING, "cryptoInitVector", "PRISM crypto init vector"
445 +# these information elements have been defined by FOKUS for the Oracle project
447 +402, IPFIX_FT_ORsignalBandwidth, 4, IPFIX_CODING_UINT, "ORsignalBandwidth", "signal bandwidth"
448 +403, IPFIX_FT_ORsignalPower, 2, IPFIX_CODING_UINT, "ORsignalPower", "ERIP"
449 +404, IPFIX_FT_ORmodulationType, 2, IPFIX_CODING_UINT, "ORmodulationType", "AM/FM,.."
450 +405, IPFIX_FT_ORsymbolRate, 2, IPFIX_CODING_UINT, "ORsymbolRate", "symbol rate"
451 +406, IPFIX_FT_ORmodulationOrder, 1, IPFIX_CODING_UINT, "ORmodulationOrder", "number of levels"
452 +407, IPFIX_FT_ORrolloffFactor, 2, IPFIX_CODING_UINT, "ORrolloffFactor", "roll of factor"
453 +408, IPFIX_FT_ORgeopositionLon, 4, IPFIX_CODING_UINT, "ORgeopositionLon", "GPS coordinate, resolution 1 cm"
454 +409, IPFIX_FT_ORgeopositionLat, 4, IPFIX_CODING_UINT, "ORgeopositionLat", "GPS coordinate, resolution 1 cm"
455 +410, IPFIX_FT_ORgeopositionElev, 4, IPFIX_CODING_UINT, "ORgeopositionElev", "GPS coordinate, resolution 1 cm"
456 +411, IPFIX_FT_ORpolicyRecord, 65535, IPFIX_CODING_STRING, "ORpolicyRecord", "policy record has variable length, First 8 bits in data describe the length (in bytes) of the field"
457 +420, IPFIX_FT_channel_status, 1, IPFIX_CODING_UINT, "channel_status", vacancy of the scanned channel (1: channel busy, 0: channel idle)"
458 +421, IPFIX_FT_sensing_value, 2, IPFIX_CODING_UINT, "sensing_value", "Cost function output"
459 +422, IPFIX_FT_sensing_threshold, 2, IPFIX_CODING_UINT, "sensing_threshold", "Decision threshold"
460 +423, IPFIX_FT_OR_terminal_id, 1, IPFIX_CODING_UINT, "OR_terminal_id", "terminal identifier"
461 +424, IPFIX_FT_OR_terminal_id_list, 65535, IPFIX_CODING_STRING, "OR_terminal_id_list", "terminal identifier list"
462 +425, IPFIX_FT_Infrastructure_network_id, 1, IPFIX_CODING_UINT, "Infrastructure_network_id", "network identifier"
463 +426, IPFIX_FT_Infrastructure_network_type, 1, IPFIX_CODING_UINT, "Infrastructure_network_type", "network type (GSM - 1, UMTS - 2, WiMAX - 3, WiFi - 4)"
464 +427, IPFIX_FT_Battery_lifetime_min, 1, IPFIX_CODING_UINT, "Battery_lifetime_min", "expected battery lifetime to provide requested services or functionalities, in minutes"
465 +428, IPFIX_FT_Battery_lifetime_h, 1, IPFIX_CODING_UINT, "Battery_lifetime_h", "expected battery lifetime to provide requested services or functionalities, in hours"
466 +429, IPFIX_FT_Battery_status, 1, IPFIX_CODING_UINT, "Battery_status", "expected battery lifetime to provide requested services or functionalities, 1 bit status flag, values 1 or 0"
467 +430, IPFIX_FT_Cell_id_number, 4, IPFIX_CODING_UINT, "Cell_id_number", "16-32 bit cell id number, identifier"
468 +431, IPFIX_FT_Spectral_allocation_vector, 1, IPFIX_CODING_UINT, "Spectral_allocation_vector", "binary vector to indicate whether a band is free 1 bit 0 or not 1 bit 1"
469 +432, IPFIX_FT_Spectral_allocation_profile, 2, IPFIX_CODING_UINT, "Spectral_allocation_profile", "received power spectral density vs. frequency to indicate spectral activity in the band of interest (8-16 bits per discrete frequency value)"
470 +433, IPFIX_FT_Center_frequency, 2, IPFIX_CODING_UINT, "Center_frequency", "Center frequency of the sensed band"
471 +434, IPFIX_FT_Bandwidth_of_CAP, 2, IPFIX_CODING_UINT, "Bandwidth_of_CAP", "Bandwidth of the spectral allocation profile"
472 +435, IPFIX_FT_ORmodulation, 1, IPFIX_CODING_UINT, "ORmodulation", "CREST factor"
473 +436, IPFIX_FT_ORprofileRecord, 65535, IPFIX_CODING_STRING, "ORprofileRecord", "profile record has variable length, First 8 bits in data describe the length (in bytes) of the field"