migratened.pl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #
  2. #
  3. #
  4. $verbose = 1;
  5. $listfile = $ARGV[0];
  6. die "no listfile specified" if ($listfile eq '');
  7. # parse listfile
  8. print "reading $listfile...\n" if ($verbose);
  9. open(INFILE, $listfile) || die "cannot open $listfile";
  10. @fnames = ();
  11. while (<INFILE>) {
  12. chomp;
  13. s/\r$//; # cygwin/mingw perl does not do CR/LF translation
  14. push(@fnames,$_);
  15. }
  16. #print join(' ', @fnames);
  17. %replacements = (
  18. # gates
  19. "from_ip" => "ipIn",
  20. "from_ipv6" => "ipv6In",
  21. "from_udp" => "udpIn",
  22. "from_app" => "appIn",
  23. "from_mpls_switch" => "mplsSwitchIn",
  24. "to_ip" => "ipOut",
  25. "to_ipv6" => "ipv6Out",
  26. "to_udp" => "udpOut",
  27. "to_app" => "appOut",
  28. "to_appl" => "appOut",
  29. "TCPIn" => "tcpIn",
  30. "UDPIn" => "udpIn",
  31. "RSVPIn" => "rsvpIn",
  32. "OSPFIn" => "ospfIn",
  33. "UDPOut" => "udpOut",
  34. "RSVPOut" => "rsvpOut",
  35. "OSPFOut" => "ospfOut",
  36. "fromIPv6" => "ipv6In",
  37. "toIPv6" => "ipv6Out",
  38. # from RTP -- TBD only when RTP code has been patched!
  39. # "fromApp" => "appIn",
  40. # "fromProfile" => "profileIn",
  41. # "fromRTP" => "rtpIn",
  42. # "fromRTCP" => "rtcpIn",
  43. # "fromSocketLayer" => "socketLayerIn",
  44. # "fromSocketLayerRTP" => "socketLayerRTPIn",
  45. # "fromSocketLayerRTCP" =>"socketLayerRTCPIn",
  46. # "toApp" => "appOut",
  47. # "toProfile" => "profileOut",
  48. # "toRTCP" => "rtcpOut",
  49. # "toRTP" => "rtpOut",
  50. # "toSocketLayer" => "socketLayerOut",
  51. # "toSocketLayerRTP" => "socketLayerRTPOut",
  52. # "toSocketLayerRTCP" => "socketLayerRTCPOut",
  53. # parameters
  54. "local_port" => "localPort",
  55. "dest_port" => "destPort",
  56. "message_length" => "messageLength",
  57. "message_freq" => "messageFreq",
  58. "dest_addresses" => "destAddresses",
  59. );
  60. foreach $fname (@fnames)
  61. {
  62. print "reading $fname...\n" if ($verbose);
  63. $txt = readfile($fname);
  64. # process $txt:
  65. foreach my $from (keys(%replacements)) {
  66. my $to = $replacements{$from};
  67. $txt =~ s/\b$from\b/$to/sg;
  68. }
  69. writefile($fname, $txt);
  70. #writefile("$fname.new", $txt);
  71. }
  72. sub readfile ()
  73. {
  74. my $fname = shift;
  75. my $content;
  76. open FILE, "$fname" || die "cannot open $fname";
  77. read(FILE, $content, 1000000);
  78. close FILE;
  79. $content;
  80. }
  81. sub writefile ()
  82. {
  83. my $fname = shift;
  84. my $content = shift;
  85. open FILE, ">$fname" || die "cannot open $fname for write";
  86. print FILE $content;
  87. close FILE;
  88. }