#!/usr/bin/perl # File: createscenario.pl # # This Script takes a file with the form # # ---------------------------------- # > net1,net2,net3,... # # > r1 net1,net2 # > r2 net2,net3 # ---------------------------------- # # Comments are whole lines that begin with # # To change VNUML Settings just edit the variables $global, $net and $router # # Input file must have suffix .zvf # # Call this script with # ./createscenario.pl inputfile.zvf # It creates a scenario inputfile in file inputfile.xml # # Attention: No error-handling implemented use strict; use warnings; my $filename = shift; my $scenario = $filename; $scenario =~ s/(.*?)\.zvf/$1/; my $global=" 1.8 $scenario 2 /root/.ssh/id_rsa.pub /usr/share/vnuml/filesystems/mini_fs /usr/share/vnuml/kernels/linux \n"; # the prefix # "; # the start tag # # and the nets are added later my $router="\n conf sysctl -w net.ipv4.conf.all.rp_filter=0 hostname /usr/lib/quagga/zebra -f /etc/quagga/zebra.conf -d /usr/lib/quagga/ripd -f /etc/quagga/ripd.conf -d /usr/lib/quagga/ospfd -f /etc/quagga/ospfd.conf -d -P 2604 hostname killall zebra killall ripd killall ospfd for f in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 0 > \$f; done \n\n"; # --------- program start -------------- # open(FILE,"<$filename"); my @lines=; close(FILE); @lines = grep(/^[nr]/,@lines); my $netline = shift @lines; chomp $netline; my @nets = split(",",$netline); my $outfile = $global; my %netuses = (); foreach my $netname (@nets) { chomp $netname; $outfile .= "\n"; my @netlist = split(",",$actrouter[1]); my $id=1; foreach my $rnet (@netlist) { $outfile .= " \n"; my $netnum = $rnet; $netnum =~ s/net([0-9]+)/$1/; $outfile .= " 10.0.$netnum.$netuses{$rnet}\n\n"; $netuses{$rnet}++; $id++; } $outfile .= $router; } $outfile .= "\n"; open(OUTFILE,">$scenario.xml"); print OUTFILE "$outfile\n\n"; close(OUTFILE);