[Click] Some questions about gen_config_cope.pl

欧阳鑫 yuanmmsip at gmail.com
Mon Apr 18 22:04:01 EDT 2011


Hi, everyone.
        I am running click experiments on 2 Ubuntu hosts with 2.6.32-26
kernel. Both are AR5416 cards with ath9k driver, and I have updated ath9k
driver to compat-wireless-2011-03-16. All cards run in Monitor mode. The
click with configure file gen_config_roofnet.pl can exactly run on mode b
and mode g. But now I need to run click with network coding. So I run the
other configure file gen_config_cope.pl, The gen_config_cope.pl is at the
bottom.
       I find the experiments result is not ideal. On two PCs, the result is
as follows:
init listen manager
init coding manager
constr, totencoded is 0
init overheard packets
tmp_so_sndbuf is set to 0
enchostfilter lookup
send manager done
receive manager done
srcr/ackreceiver: my alias is 96
guess manager done
starting listen manager
listen manager done
starting scramble queue
scramble queue done
starting overheard packets
overheard packets done
decoder done
sniff_dev/from_dev: setting socket rcvbuf to 4000000
sniff_dev/from_dev: value read by getsockopt is 262142
sniff_dev/to_dev: fd is 4, my_fd is 0
sniff_dev/to_dev: value read by getsockopt is 112640
srcr/scramble_q: 1482279259 sq pull 1, useless pulls 0, sleepiness 0, qsize
0
srcr/scramble_q here2
srcr/scramble_q: trying to find a new packet to send
srcr/scramble_q: 1482279259 sq pull 2, useless pulls 1, sleepiness 1, qsize
0
srcr/scramble_q here2
srcr/scramble_q: trying to find a new packet to send
srcr/scramble_q: 1482279259 sq pull 3, useless pulls 2, sleepiness 2, qsize
0
srcr/scramble_q here2
srcr/scramble_q: trying to find a new packet to send
fromdev:   78 |  1Mb + 0/ 0 | data nods ff:ff:ff:ff:ff:ff 00:25:86:20:ea:90
00:00:00:00:00:00 seq 0 [ TX ]
tx_filter packet length 78
fromdev:   78 |  6Mb + 0/ 0 | data nods ff:ff:ff:ff:ff:ff 00:25:86:20:ea:90
00:00:00:00:00:00 seq 0 [ TX ]
tx_filter packet length 78
fromdev:  321 |  1Mb +212/ 0 | mgmt beacon 1c:af:f7:a7:92:a2 ROMA chan 13
b_int 100 [ ESS PRIVACY ] ({2 4 11 22} 18 36 72 108 12 24 48 96)

The two PCs' result is the same, each PC can only send broadcast packets,
but do not send packets to each other.
The command "iwconfig wlan0" is as follows:

wlan0     IEEE 802.11bgn  Mode:Monitor  Tx-Power=18 dBm
          Retry limit:16   RTS thr:off   Fragment thr:off
          Power Management:off
And I also run read srcr/e.bcast_stats command, the result is:

read srcr/es.bcast_stats
200 Read handler 'srcr/es.bcast_stats' OK
DATA 0
I run tcpdump on two PC1, and find there is not any packets from PC2, so is
the PC2. The interface wlan0 is monitor mode, and the click result is each
PC can send broadcast packets, but why can not receive the other PC sending
packets on one PC?
I do not know which sources need to modify, can some body who knows this
help me? Thank you very much.

The gen_config_cope.pl is as follows:
#!/usr/bin/perl -w
use strict;
use Getopt::Long;

sub usage() {
    print STDERR "usage:
    --dev {e. g. ath0}
    --rate {2/4/11/22, default 2}
    --channel {default 6}
    --ssid
    --gateway
    --ap ( act as an access point. off by default)
    --txf (enable/disable tx-feedback. on by default)
";
    exit 1;
}
sub mac_addr_from_dev($) {
    my $device = $_[0];
    my $output = `/sbin/ifconfig $device 2>&1`;
    if ($output =~ /^$device: error/) {
        return "";
    }
    my @tmp = split(/\s+/, $output);
    my $mac = $tmp[4];
    $mac =~ s/-/:/g;
    my @hex = split(/:/, $mac);

    return uc (join ":", @hex[0 .. 5]);
}


sub mac_addr_to_ip($) {
    my $mac = $_[0];
    my @hex = split(/:/, $mac);
    if (scalar(@hex) != 6) {
        return "0";
    }
    # convert the hex digits to
decimals
    my $x = hex($hex[3]);
    my $y = hex($hex[4]);
    my $z = hex($hex[5]);
    return "$x.$y.$z";
}
my $dev;
my $rate;
my $cardrate;
my $power;
my $channel_no;
my $rawdev;
my $ssid;
my $gateway = 0;
my $ap = 0;
my $txf = 1;
my $interval = 10000;
my $rate_control = "static-2";
my $kernel = 0;
GetOptions('device=s' => \$dev,
    'rate:s' => \$rate,
    'channel:s' => \$channel_no,
     'power:s' => \$power,
    'ssid=s' => \$ssid,
    'gateway' => \$gateway,
    'ap!' => \$ap,
    'txf!' => \$txf,
    'rate-control=s' => \$rate_control,
    'kernel!' => \$kernel,
    ) or usage();

if (! defined $dev) {
    if (`/sbin/ifconfig ath0 2>&1` =~ /Device not found/) {
 if (`/sbin/ifconfig wlan0 2>&1` =~ /Device not found/) {
 } else {
     $dev = "wlan0";
 }
    } else {
 $dev = "ath0";
    }
}

if (! defined $dev) {
    usage();
}

if ($gateway) {
    $gateway = "true";
} else{
    $gateway = "false";
}
$rate = 2 unless defined $rate;
$cardrate = ($rate/2.0) * 1000000;
$power = 18 unless defined $power;
$channel_no = 6 unless defined $channel_no;
my $hostname = `hostname`;
my $wireless_mac = mac_addr_from_dev($dev);
my $suffix;
if ($hostname =~ /rn-pdos(\S+)-wired/) {
    $suffix = "0.0.$1";
} else {
    $suffix = mac_addr_to_ip($wireless_mac);
}

my $srcr_ip = "5." . $suffix;
my $safe_ip = "6." . $suffix;
my $rate_ip = "7." . $suffix;

my $srcr_nm = "255.0.0.0";
my $srcr_net = "5.0.0.0";
my $srcr_bcast = "5.255.255.255";
if (! defined $ssid) {
    $ssid = "roofnet.$srcr_ip";
}
if ($wireless_mac eq "" or
    $wireless_mac eq "00:00:00:00:00:00") {
    print STDERR "got invalid mac address!";
    exit -1;
}
$rawdev = $dev;
if ($dev =~ /ath/) {
    $rawdev = "${dev}raw";
    system "/sbin/sysctl -w dev.$dev.rxfilter=0xff > /dev/null 2>&1";
    system "/sbin/sysctl -w dev.$dev.rawdev_type=2 > /dev/null 2>&1";
    system "/sbin/sysctl -w dev.$dev.rawdev=1 > /dev/null 2>&1";
    system "/sbin/ifconfig $rawdev up";
}
my $iwconfig = "/home/roofnet/bin/iwconfig";
if (-f "/sbin/iwconfig") {
    $iwconfig = "/sbin/iwconfig";
}
if ($dev =~ /wlan/) {
    system "/sbin/ifconfig $dev mtu 1800";
#    system "/home/roofnet/scripts/prism2_param $dev ptype 6";
#    system "/home/roofnet/scripts/prism2_param $dev pseudo_ibss 1";
    system "/sbin/ifconfig $dev down";
##    system "$iwconfig $dev mode ad-hoc";
    system "$iwconfig $dev mode monitor";
    system "/sbin/ifconfig $dev up";
#    system "/home/roofnet/scripts/prism2_param $dev monitor_type 1";
#    system "$iwconfig $dev essid $ssid";
    system "$iwconfig $dev rts off";
    system "$iwconfig $dev retry 16";
    # make sure we broadcast at a fixed power
#    system "/home/roofnet/scripts/prism2_param $dev alc 0";
    system "$iwconfig $dev txpower 18";
    system "/sbin/ifconfig $dev up";
}
if ($dev =~ /ath/) {
    system "$iwconfig $dev mode Managed";
    system "$iwconfig $dev channel $channel_no";
    system "$iwconfig $dev rate $cardrate";
    system "$iwconfig $dev txpower $power";
    system "/sbin/ifconfig $dev up txqueuelen 5";
}
##my $mode = "b";
my $mode = "g";
my $iwconfig_result = `$iwconfig $dev 2>/dev/null`;
if ($iwconfig_result =~ /Frequency:(\d+)\.(\d+)\s*GHz/) {
    my $channel = "$1.$2";
    if ($channel > 5.0) {
 $mode = "a";
    } elsif ($dev =~ /ath/) {
 $mode = "g";
    }
}
##print STDERR "using mode $mode\n";
system "/sbin/modprobe tun > /dev/null 2>&1";
my $probes = "2 60 2 1500 4 1500 11 1500 22 1500";

# only probe at b rates for now.
# I am fixing rates of probes for the routing protocol, if we ever need to
do auto rates remember to chane rates too all rates, do this even for probes
if ($mode =~ /g/) {
    ##$probes = "2 60 $rate 1500";
    $probes = "2 60 12 60 2 1500 4 1500 11 1500 22 1500 12 1500 18 1500 24
1500 36 1500 48 1500 72 1500 96 1500 108 1500";
} elsif ($mode =~ /a/) {
#    $probes = "12 60 12 1500 24 1500 48 1500 72 1500 96 1500 108 1500";
    $probes = "12 60 $rate 1500";
}

my $srcr_es_ethtype = "0941";  # broadcast probes
my $srcr_forwarder_ethtype = "0943"; # data
my $srcr_ethtype = "0944";  # queries and replies
my $srcr_gw_ethtype = "092c"; # gateway ads
# I am fixing rates of probes for the routing protocol, if we ever need to
do auto rates remember to chane rates too all rates, do this even for probes
if (1 && $mode =~ /g/) {
  ##  print "rates :: AvailableRates(DEFAULT $rate,
##$wireless_mac $rate);\n\n";
    print "rates :: AvailableRates(DEFAULT 2 4 11 12 18 22 24 36 48 72 96
108,
$wireless_mac 2 4 11 12 18 22 24 36 48 72 96 108);\n\n";
} elsif ($mode =~ /a/) {
#    print "rates :: AvailableRates(DEFAULT 12 18 24 36 48 72 96 108,
#$wireless_mac 12 18 24 36 48 72 96 108);\n\n";
    print "rates :: AvailableRates(DEFAULT $rate,
$wireless_mac $rate);\n\n";
} else {
    print "rates :: AvailableRates(DEFAULT 2 4 11 22,
$wireless_mac 2 4 11 22);\n\n";
}

my $data = "";
for (my $x = 0; $x < 1500; $x++) {
    $data .= "ff";
}
$data = "\\<$data <file://%3c$data/>>";

# we need to find srcr.click
# first, try the directory where the script was run from
my $cope_file = $0;
$cope_file =~ s/gen_config_cope\.pl/cope_config\.click/g;
if (! -f $cope_file) {
    # ok, try srcr.click
    $cope_file = "/home/roofnet/scripts/cope.click";
}
if (! -f $cope_file) {
    die "couldn't find cope.click: tried $cope_file\n";
}
##print STDERR "using $cope_file\n";
system "cat $cope_file";
print <<EOF;
// has one input and one output
// takes and spits out ip packets
elementclass LinuxHost {
    \$dev, \$ip, \$nm, \$mac |
    input -> ToHost(\$dev);
    FromHost(\$dev, \$ip/\$nm, ETHER \$mac) -> output;
}

EOF
if ($kernel) {
print <<EOF;
elementclass LinuxIPHost {
    \$dev, \$ip, \$nm |
  input -> CheckIPHeader()
    -> EtherEncap(0x0800, 1:1:1:1:1:1, 2:2:2:2:2:2)
    -> SetPacketType(HOST)
    -> to_host :: ToHost(\$dev);

  from_host :: FromHost(\$dev, \$ip/\$nm)
    -> fromhost_cl :: Classifier(12/0806, 12/0800);

  // arp packets
  fromhost_cl[0]
    -> ARPResponder(0.0.0.0/0 1:1:1:1:1:1)
    -> SetPacketType(HOST)
    -> ToHost();

  // IP packets
  fromhost_cl[1]
    -> Strip(14)
    -> CheckIPHeader
    -> GetIPAddress(16)
    -> MarkIPHeader(0)
    -> output;
}


elementclass SniffDevice {
    \$device, \$promisc|
  from_dev :: FromDevice(\$device, PROMISC \$promisc, SO_RCVBUF 4000000)
  -> t1 :: Tee
  -> output;
    t1 [1] -> ToHostSniffers(\$device);
  input
  -> t2 :: PullTee
  -> to_dev :: ToDevice(\$device);
    t2 [1] -> ToHostSniffers(\$device);
}
EOF
} else {
    print <<EOF;
// has one input and one output
// takes and spits out ip packets
elementclass LinuxIPHost {
    \$dev, \$ip, \$nm |
  input -> KernelTun(\$ip/\$nm, MTU 1500, DEV_NAME \$dev)
  -> MarkIPHeader(0)
  -> CheckIPHeader()
  -> output;
}
elementclass SniffDevice {
    \$device, \$promisc|
 // we only want txf for NODS packets
 // ether[2:2] == 0x1200 means it has an ath_rx_radiotap header (it is 18
bytes long)
 // ether[2:2] == 0x1000 means it has an ath_tx_radiotap header (it is 16
bytes long)
 // ether[18] == 0x08 means NODS
  from_dev :: FromDevice(\$device,
    PROMISC \$promisc, SO_RCVBUF 4000000)
  -> output;
  input -> to_dev :: ToDevice(\$device);
}
EOF
    }
if (!$kernel) {
    print "control :: ControlSocket(\"TCP\", 7777);\n";
    print "chatter :: ChatterSocket(\"TCP\", 7778);\n";
}
print <<EOF;
sniff_dev :: SniffDevice($rawdev, true);
sched :: PrioSched()
-> set_power :: SetTXPower(POWER 63)
-> radiotap_encap :: RadiotapEncap()
-> sniff_dev;
route_q :: FullNoteQueue(10)
-> [0] sched;
data_encap :: WifiEncap(0x0, 00:00:00:00:00:00)
-> data_static_rate :: SetTXRate(RATE 2)
//-> data_madwifi_rate :: MadwifiRate(OFFSET 4,
//          ALT_RATE true,
//          RT rates,
//          ACTIVE true)
-> data_arf_rate :: AutoRateFallback(OFFSET 4,
    STEPUP 25,
    RT rates,
    ACTIVE false)
-> data_probe_rate :: ProbeTXRate(OFFSET 4,
        WINDOW 5000,
        RT rates,
        ACTIVE false)
-> SetTXRate(RATE $rate)
-> [1] sched;
Idle -> [1] data_probe_rate;
//Idle -> [1] data_madwifi_rate;
Idle -> [1] data_arf_rate;

srcr :: srcr_ett($srcr_ip, $srcr_nm, $wireless_mac, $gateway,
   "$probes");

// make sure this is listed first so it gets tap0
srcr_host :: LinuxIPHost(srcr, $srcr_ip, $srcr_nm)
-> [1] srcr;

route_encap :: WifiEncap(0x0, 00:00:00:00:00:00)
->  route_q;
srcr [0] -> route_encap;   // queries, replies
srcr [1] -> route_encap;   // bcast_stats
srcr [2] -> data_encap;    // data
srcr [3] -> srcr_host; // data to me

EOF

print <<EOF;
sniff_dev
//-> prism2_decap :: Prism2Decap()
//-> phyerr_filter :: FilterPhyErr()
//-> extra_decap :: ExtraDecap()
-> radiotap_decap :: RadiotapDecap()
-> phyerr_filter :: FilterPhyErr()
-> PrintWifi(fromdev)
-> beacon_cl :: Classifier(0/80, //beacons
       -)
-> bs :: BeaconScanner(RT rates)
-> Discard;
beacon_cl [1]
-> Classifier(0/08%0c) //data
-> tx_filter :: FilterTX()
-> dupe :: WifiDupeFilter()
-> WifiDecap()
-> ackfilter :: AckFilter(ETHTYPE 0x0980,
                       NOTHINGETHTYPE 0x0982);

ackfilter [0]
-> recpfilter :: RecpFilter(ETHTYPE 0x0981,
                            NOTHINGETHTYPE 0x0982)
-> enc_cl :: Classifier(12/0977, -);

ackfilter [1]
-> ncl :: Classifier(
       12/09??,
       -);
enc_cl [0]
-> EncHostEtherFilter(ETH $wireless_mac, ALIASTABLE aliastable, DROP_OTHER
false, DROP_OWN true)
-> rxstats :: RXStats();
enc_cl [1]
-> HostEtherFilter($wireless_mac, DROP_OTHER false, DROP_OWN true)
-> rxstats
-> ncl;
recpfilter [1] -> ncl;
ncl [0] -> srcr;
ncl[1]
EOF
if ($kernel) {
    print "-> ToHost(ath0);\n";
} else {
    print "-> Discard;\n";
}
    if ($txf) {
print <<EOF;
tx_filter [1]
-> PrintWifi(txf)
-> txf_t2 :: Tee(3);
txf_t2 [0] -> [1] data_arf_rate;
//txf_t2 [1] -> [1] data_madwifi_rate;
txf_t2 [1] -> Discard;
txf_t2 [2] -> [1] data_probe_rate;
EOF
}
Ouyang.


More information about the click mailing list