
#magic creates here (c) plisket,2013
#As input - get string in DOT format from main string.
#As result returning string with right direction(for NEATO). On the left side from -> set $rootmac, given as variable from main script. To the right side from -> locates MAC_address of other device.
#Ports of devices change place if nessasery


function kav(num)
{
kav1 = match(num,"\"");
if ( kav1 != 0 )
{ num = substr(num,0,1) }
return num;
}



{
#Here: source - source MAC from given string, dest - destination MAC from given script

a=substr($1,2,14)
source=$1
dest=$3

# Get ports on source switch and on destination switch

tmp=match($0,"headlabel")
tmp1=substr($0,tmp + 13,2)
destport=kav(tmp1);
destp=destport;


tmp=match($0,"taillabel")
tmp1=substr($0,tmp + 13,2)
sourceport=kav(tmp1);
sourcep=sourceport;

# If in source string rootmac was to the right from ->   - swaping variables.

if ( a != rootmac )  {  source=$3;  dest=$1;sourcep=destport;destp=sourceport;  }




print source,"->",dest, "[taillabel=\"1/"  sourcep "\"," , "headlabel=\"1/" destp   "\","    ,$6,$7,$8;


}
