@ -41,6 +41,7 @@ sub usage
$ output . = "\t-F --filter-common: filter common headers:\n" ;
$ output . = "\t\t@common_hdrs\n" ;
$ output . = "\t-i --ids: subst ids present in scenarios_ids.yml file\n" ;
$ output . = "\t-n --network: subst sipp ports using networks defined at scenarios.yml file\n" ;
return $ output
}
@ -48,23 +49,46 @@ sub load_ids
{
my $ yml = LoadFile ( $ _ [ 0 ] ) ;
my $ res = { } ;
get_ uu id( $ yml , "" , $ res ) ;
get_ id( $ yml , "" , $ res , 'id' ) ;
return $ res ;
}
sub get_uuid
sub load_uuids
{
my $ yml = LoadFile ( $ _ [ 0 ] ) ;
my $ res = { } ;
get_id ( $ yml , "" , $ res , 'uuid' ) ;
return $ res ;
}
sub load_network
{
my $ yml = LoadFile ( $ _ [ 0 ] ) ;
my @ res = ( ) ;
foreach ( @ { $ yml - > { scenarios } } ) {
push @ res , $ _ - > { ip } ;
foreach ( @ { $ _ - > { responders } } ) {
push @ res , $ _ - > { ip } ;
}
}
@ res = uniq ( @ res ) ;
return \ @ res ;
}
sub get_id
{
my $ data = shift ;
my $ str_key = shift ;
my $ res = shift ;
my $ id = shift ;
foreach my $ key ( sort keys % { $ data } ) {
my $ new_key = $ { str_key } ? "${str_key}.${key}" : "${key}" ;
if ( $ key eq 'uuid' ) {
if ( $ key eq $ id ) {
$ res - > { $ data - > { $ key } } = $ new_key ;
} else {
my $ _type = defined ( reftype ( $ data - > { $ key } ) ) ? reftype ( $ data - > { $ key } ) : "" ;
if ( $ _type eq 'HASH' ) {
get_uuid ( $ data - > { $ key } , $ new_key , $ res ) ;
get_ id( $ data - > { $ key } , $ new_key , $ res , $ id ) ;
}
}
}
@ -72,6 +96,7 @@ sub get_uuid
}
my $ uuids ;
my $ ids ;
sub subst_uuids
{
my $ line = shift ;
@ -84,6 +109,17 @@ sub subst_uuids
return $ line ;
}
sub subst_ids
{
my $ line = shift ;
foreach my $ id ( sort keys % { $ ids } ) {
if ( $ line =~ s/(=|: )\Q${id}\E([^\d]?)/${1}[% $ids->{$id} %]${2}/g ) {
return $ line ;
}
}
return $ line ;
}
sub subst_common
{
my $ line = shift ;
@ -91,14 +127,43 @@ sub subst_common
$ line =~ s/;tag=(.+)/;tag=[\\w-]+/ ;
} elsif ( $ line =~ /^CSeq: /i ) {
$ line =~ s/:[ ]+\d+[ ]+/: \\d+ / ;
} elsif ( $ line =~ /^WWW-Authenticate: /i ) {
$ line =~ s/nonce=".+"/nonce=".+"/ ;
} elsif ( $ line =~ /^Server: Sipwise/i ) {
$ line =~ s/^: Sipwise .+/: Sipwise NGCP Proxy/ ;
} elsif ( $ line =~ /^(WWW|Proxy)-Authenticate: /i ) {
$ line =~ s/nonce="[^"]+"/nonce=".+"/ ;
} elsif ( $ line =~ /^(WWW|Proxy)-Authorization: /i ) {
$ line =~ s/response="[^"]+"/response=".+"/ ;
$ line =~ s/nonce="[^"]+"/nonce=".+"/ ;
} elsif ( $ line =~ /^(Server|User-Agent): Sipwise/i ) {
$ line =~ s/: Sipwise NGCP (Proxy|PBX) Server.+/: Sipwise NGCP ${1} Server/ ;
} elsif ( $ line =~ /^Content-Length:[ ]+[1-9]/i ) {
$ line =~ s/:[ ]+\d+/: \\d+/ ;
$ line =~ s/:[ ]+\d+/: \\s+ \\d+/;
} elsif ( $ line =~ /^P-LB-Uptime: /i ) {
$ line =~ s/: \d+/: \\d+/ ;
} elsif ( $ line =~ /^P-NGCP-Src-Port: /i ) {
$ line =~ s/: \d+/: \\d+/ ;
} elsif ( $ line =~ /^P-NGCP-Acc-(Src|Dst)-Leg: /i ) {
$ line =~ s/: .+/: .+/ ;
} elsif ( $ line =~ /^SIP-If-Match: /i ) {
$ line =~ s/: .+/: .+/ ;
} elsif ( $ line =~ /127\.0\.0\.1(:|;port=)508[58]/ ) {
$ line =~ s/127\.0\.0\.1(:|;port=)\d+/127.0.0.1${1}508[58]/g ;
} elsif ( $ line =~ /^Content-Type: application\/dialog\-info\+xml/i ) {
$ line =~ s/: application\/dialog\-info\+xml/: application\/dialog\\-info\\+xml/ ;
}
return $ line ;
}
my $ network ;
sub subst_network
{
my $ line = shift ;
if ( $ line =~ /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/ ) {
foreach my $ ip ( @ { $ network } ) {
if ( $ line =~ s/\Q${ip}\E:\d+/${ip}:\\d+/g ) {
return $ line ;
} elsif ( $ line =~ s/ip=\Q${ip}\E;port=\d+/ip=${ip};port=\\d+/g ) {
return $ line ;
}
}
}
return $ line ;
}
@ -112,7 +177,13 @@ sub print_header
if ( $ uuids ) {
$ line = subst_uuids ( $ _l ) ;
}
if ( $ ids ) {
$ line = subst_ids ( $ line ) ;
}
$ line = subst_common ( $ line ) ;
if ( $ network ) {
$ line = subst_network ( $ line ) ;
}
if ( $ _type eq 'sip_in' ) {
print " - '$line'\n" ;
} else {
@ -135,11 +206,13 @@ sub filter_header
my $ help = 0 ;
my $ f_common = 0 ;
my $ f_ids ;
my $ f_net ;
GetOptions (
"h|help" = > \ $ help ,
"f|filter=s" = > \ @ headers ,
"F|filter-common" = > \ $ f_common ,
"i|ids=s" = > \ $ f_ids ,
"n|network=s" = > \ $ f_net ,
) or die ( "Error in command line arguments\n" . usage ( ) ) ;
if ( $# ARGV != 0 || $ help )
@ -162,7 +235,12 @@ my $json;
my $ inlog = decode_json ( $ json ) ;
if ( $ f_ids ) {
$ uuids = load_ids ( abs_path ( $ f_ids ) ) ;
$ uuids = load_uuids ( abs_path ( $ f_ids ) ) ;
$ ids = load_ids ( abs_path ( $ f_ids ) ) ;
}
if ( $ f_net ) {
$ network = load_network ( abs_path ( $ f_net ) ) ;
}
print "flow:\n" ;
@ -189,21 +267,25 @@ foreach my $i (@{$inlog->{'sip_in'}})
}
}
}
print "sip_out:\n" ;
foreach my $ i ( @ { $ inlog - > { 'sip_out' } } )
{
my @ line = split ( /\r\n/ , $ i ) ;
print " - [\n" ;
foreach my $ l ( @ line )
if ( @ { $ inlog - > { 'sip_out' } } ) {
print "sip_out:\n" ;
foreach my $ i ( @ { $ inlog - > { 'sip_out' } } )
{
if ( $ l ) {
if ( ! filter_header ( $ l ) ) {
print_header ( 'sip_out' , $ l ) ;
my @ line = split ( /\r\n/ , $ i ) ;
print " - [\n" ;
foreach my $ l ( @ line )
{
if ( $ l ) {
if ( ! filter_header ( $ l ) ) {
print_header ( 'sip_out' , $ l ) ;
}
} else {
# we don't care about SDP
last ;
}
} else {
# we don't care about SDP
last ;
}
print " ]\n" ;
}
print " ]\n" ;
}
} else {
print "sip_out: []\n" ;
}