delay_config 1.8 KB
Newer Older
1
2
3
#!/usr/bin/perl -w

if ( @ARGV < 1 ) {
4
  print STDERR "Usage: delay_config <node> [<delay>] [<bw>] [<plr>]\n".
Robert Ricci's avatar
Robert Ricci committed
5
       " node = pcX, where pcX is the delay node to be configured\n".
6
7
       "delay = one-way link delay in milliseconds\n".
       "   bw = bw<NNN><U>, N=bandwidth (1-100), U=units (M=Mbps, k=kbps)\n".
8
9
       "  plr = packet loss rate (0 <= plr < 1)\n";
  exit(0); # so plasticwrap doesn't think ssh failed.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
}

@_ = @ARGV;
my $node = shift;

my $delay=-1;
my $bw=-1;
my $unit=-1;
my $plr=-1;

sub applyChanges {
  my $cmd = "";
  if ( $delay != -1) { $cmd .= " delay ".($delay)."ms"; }
  if ( $bw != -1 ) { $cmd .= " bw ${bw}${unit}bit/s"; }
  my $cmd2 = $cmd;
  if ( $plr != -1 ) { $cmd .= " plr $plr"; }
  if ($cmd ne "") {
    if ($cmd2 ne "") {
      #print "ssh $node 'sudo /sbin/ipfw pipe 110 config $cmd;sudo /sbin/ipfw pipe 120 config $cmd2'\n";
      system("ssh -f -n $node 'sudo /sbin/ipfw pipe 110 config $cmd;sudo /sbin/ipfw pipe 120 config $cmd2'");
    } else {
      #print "ssh $node 'sudo /sbin/ipfw pipe 110 config $cmd'\n";
      system("ssh -f -n $node 'sudo /sbin/ipfw pipe 110 config $cmd'");
    }
  }
}

my $n;
while (defined ($n = shift)) {
  if ($n =~ /bw(\d+)(\w)/) {
    $bw = $1;
    $unit = $2;
    if (($bw > 100) || ($bw < 1) || !($unit =~ /^M|k$/)) {
      die ("Illegal Bandwidth spec '$n'\n");
    }
    print "Setting Bandwidth $bw ${unit}bit/s.\n";
  } elsif ( !($n =~ /^[0-9.]*$/) ) {
    die ("Illegal parameter '$n'\n");
  } elsif ($n >= 1 ) { 
    if ($n % 10 != 0) {
      print "(Delay of $n may be rounded according to kernel settings)\n";
    }
    $delay = $n;
    print "Setting Delay $delay ms.\n";
  } elsif (($n >= 0) && ($n < 1)) {
    $plr = $n;
    print "Setting Packet Loss Rate ".($plr*100)."%.\n";
  } else {
    die ("Illegal parameter '$n'\n");
  }
}

applyChanges();