local:
TUPLE[ INT .tot_pkts, INT .tot_bytes, INT .tot_flows ]
.results[ STR .src_net, STR .dest_net ] = { @ => [ 0, 0, 0 ] }
for_each_time [ .src_ip, .dest_ip, INT .pkts, INT .bytes, INT .src_mask, INT .dest_mask ]
is_such_that(
[ .src_ip, .dest_ip, 3?, .pkts, .bytes, 10?, .src_mask, .dest_mask, ? ]
= ptokens( for "gzcat /rootbak/jack/data/192.168.31.97.0354.gz" upto "|\n" )
){
set .results[ network(.src_ip, .src_mask), network(.dest_ip, .dest_mask) ]
= [ $#1+.pkts, $#2+.bytes, $#3+1 ];
}
for_each_time [ .src_net, .dest_net, .tot_pkts, .tot_bytes, .tot_flows ]
Is_The_Next_Where(
.results[ .src_net, .dest_net ] = [ .tot_pkts, .tot_bytes, .tot_flows ] )
sorted_by_spec[ -4 ]
{
do Write_Words( .src_net, .dest_net, .tot_pkts, .tot_bytes, .tot_flows );
}
define STR FUN( STR .ip, INT .right_mask_bits ) network
{ local:
static INT .byte_bits[ [0->3] ] = [ 24, 16, 8, 0 ]
static INT ARRAY[ [0->3] ] .octet, .masked_octet
set .octet = tokens( for .ip upto "." );
set .hit = _false_;
for_each_time .i Is_In [ 0->3 ]
{ /* the = case results in the same either way */
when( .right_mask_bits > .byte_bits[.i] )
{
when(.hit)
{
set .masked_octet[.i] = 0;
} else {
set .masked_octet[.i] =
.octet[.i] - (2<*(.right_mask_bits - .byte_bits[.i]) -1);
when( .masked_octet[.i] < 0 )
set .masked_octet[.i] = 0;
set .hit = _true_;
}
} else {
set .masked_octet[.i] = .octet[.i];
}
}
return( concat( [%.masked_octet], "." ) );
}
Back