.comment-link {margin-left:.6em;}

Enjoy Linux, yet another niche!

Friday, August 11, 2006

Support promiscuous mode in AODV

To add promiscuous mode to AODV, just do the following:
1. ns-mobilenode.tcl :
# Special processing for AODV
set aodvonly [string first "AODV" [$agent info class]]
if {$aodvonly != -1 } {
$agent if-queue [$self set ifq_(0)] ;# ifq between LL and MAC
$agent install-tap [$self set mac_(0)] ;# add this to install tap for AODV
}
2. aodv.h:
class AODV:public Tap, public Agent {...};

and overload virtual function tap(const Packet *packet)

3. aodv.cc
else if(argc == 3) {
....
else if (strcasecmp(argv[1], "install-tap") == 0) // install tap for AODV
{
mac_ = (Mac*) TclObject::lookup(argv[2]);
mac_->installTap(this);
return TCL_OK;
}
finally, implement tap function in aodv is ok.

I've tested it in aodv (ns2.26).

Thursday, July 20, 2006

Troubleshooting for updating from Breeze (Ubuntu 5.04) to Dapper (Ubuntu 6.06)

After apt-get dist-upgrade, wireless card sucks. It appears work but fails to connect with AP. Finally got a clue from here:

Re: breezy - dapper upgrade broke wireless
I had the same problem with my lucent wlan card. The problem was, that additionally to orinoco the module hostap was loaded.

I got my card working with blacklisting the hostap driver (Is AFAIK only needed if you want to emulate an AP with your prism 2 wlan card.):

To blacklist hostap add the two lines:

blacklist hostap
blacklist hostap_cs

to /etc/modprobe.d/blacklist

Now wifi works fine, cheers!

Tuesday, June 27, 2006

Extend ns2 to support multi-channle multi-interface for wireless networks

Inspired from Hyacinth: An IEEE 802.11-based Multi-channel Wireless Mesh Network.

The following modifications can be applied to ns-2.26. It should be applicable to 2.1b8a and 2.1b9 as well, but NOT to 2.28 and later version as I observed there is modification to the low level config of wireless channels in both tcl and c++ and I haven't figured it out.

At least following files should be modified:

tcl/lib/ns-lib.tcl : Add multiple interfaces

################################### BEGIN ###########################
...
Simulator instproc phyType {val} { $self set phyType_ $val }
Simulator instproc antType {val} { $self set antType_ $val }
Simulator instproc channel {val} {$self set channel_ $val}
#WHQ IMWN: multiple interface support
Simulator instproc channel2 {val} {$self set channel2_ $val}
Simulator instproc channel3 {val} {$self set channel3_ $val}
Simulator instproc channel4 {val} {$self set channel4_ $val}
Simulator instproc channel5 {val} {$self set channel5_ $val}
#WHQ IMWN: multiple interface support
Simulator instproc channelType {val} {$self set channelType_ $val}
Simulator instproc topoInstance {val} {$self set topoInstance_ $val}

...

Simulator instproc node-config args {
$self instvar addressType_ routingAgent_ propType_ macTrace_ routerTrace_ agentTrace_ movementTrace_ channelType_ channel_ channel2_ channel3_ channel4_ channel5_ chan chan2 chan3 chan4 chan5 topoInstance_ propInstance_ mobileIP_ rxPower_ txPower_ idlePower_ satNodeType_ eotTrace_

...

elseif {[info exists channel_]} {
# Multiple channel, multiple interfaces
set chan $channel_
#Add multiple interface support
if{[info exists channel2_]} {
set chan2 $channel2_
}
if{[info exists channel3_]} {
set chan2 $channel3_
}
if{[info exists channel4_]} {
set chan2 $channel4_
}
if{[info exists channel5_]} {
set chan2 $channel5_
}

.. .

Simulator instproc create-wireless-node args {
$self instvar routingAgent_ wiredRouting_ propInstance_ llType_ \
macType_ ifqType_ ifqlen_ phyType_ chan chan2 chan3 chan4 chan5 antType_ energyModel_ inic_tialEnergy_ txPower_ rxPower_ idlePower_ topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_

...
# Add main node interface
$node add-interface $chan $propInstance_ $llType_ $macType_ \
$ifqType_ $ifqlen_ $phyType_ $antType_ \
$inerrProc_ $outerrProc_ $FECProc_
#Add multiple interface support
$node add-interface $chan2 $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $inerrProc_ $outerrProc_ $FECProc_

$node add-interface $chan3 $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $inerrProc_ $outerrProc_ $FECProc_

$node add-interface $chan4 $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $inerrProc_ $outerrProc_ $FECProc_

$node add-interface $chan4 $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $inerrProc_ $outerrProc_ $FECProc_

################################### END ###########################

tcl/lib/ns-mobilenode.tcl: set up hooks with trace objects

################################### BEGIN ###########################

Node/MobileNode instproc add-target-rtagent { agent port } {
$self instvar imep_ toraDebug_

set ns [Simulator instance]
set newapi [$ns imep-support]
set namfp [$ns get-nam-traceall]

set dmux_ [$self demux]
set classifier_ [$self entry]

# let the routing agent know about the port dmux
$agent port-dmux $dmux_

if { [Simulator set RouterTrace_] == "ON" } {
#
# Send Target
#
if {$newapi != ""} {
#Add multiple interface support
#set sndT [$self mobility-trace Send "RTR"]
set sndT1 [$self mobility-trace Send "RTR"]
set sndT2 [$self mobility-trace Send "RTR"]
set sndT3 [$self mobility-trace Send "RTR"]
set sndT4 [$self mobility-trace Send "RTR"]
set sndT5 [$self mobility-trace Send "RTR"]
#Add multiple interface support
} else {
#Add multiple interface support
#set sndT [cmu-trace Send "RTR" $self]
set sndT1 [cmu-trace Send "RTR" $self]
set sndT2 [cmu-trace Send "RTR" $self]
set sndT3 [cmu-trace Send "RTR" $self]
set sndT4 [cmu-trace Send "RTR" $self]
set sndT5 [cmu-trace Send "RTR" $self
#Add multiple interface support
}
if { $namfp != "" } {
#Add multiple interface support
#$sndT namattach $namfp
$sndT1 namattach $namfp
$sndT2 namattach $namfp
$sndT3 namattach $namfp
$sndT4 namattach $namfp
$sndT5 namattach $namfp
#Add multiple interface support
}
if { $newapi == "ON" } {
$agent target $imep_(0)
$imep_(0) sendtarget $sndT
# second tracer to see the actual
# types of tora packets before imep packs them
if { [info exists toraDebug_] && $toraDebug_ == "ON"} {
set sndT2 [$self mobility-trace Send "TRP"]
$sndT2 target $imep_(0)
$agent target $sndT2
}
} else { ;# no IMEP
#Add multiple interface support
#$agent target $sndT
$agent down-target-1 $sndT1
$agent down-target-2 $sndT2
$agent down-target-3 $sndT3
$agent down-target-4 $sndT4
$agent down-target-5 $sndT5
#Add multiple interface support
}
#Add multiple interface support
#$sndT target [$self set ll_(0)]
$sndT1 target [$self set ll_(0)]
$sndT2 target [$self set ll_(1)]
$sndT3 target [$self set ll_(2)]
$sndT4 target [$self set ll_(3)]
$sndT5 target [$self set ll_(4)]
#Add multiple interface support
#
# Recv Target
#
if {$newapi != ""} {
set rcvT [$self mobility-trace Recv "RTR"]
} else {
set rcvT [cmu-trace Recv "RTR" $self]
}
if { $namfp != "" } {
$rcvT namattach $namfp
}
if {$newapi == "ON" } {
[$self set ll_(0)] up-target $imep_(0)
$classifier_ defaulttarget $agent
# need a second tracer to see the actual
# types of tora packets after imep unpacks them
# no need to support any hier node
if {[info exists toraDebug_] && $toraDebug_ == "ON" } {
set rcvT2 [$self mobility-trace Recv "TRP"]
$rcvT2 target $agent
$classifier_ defaulttarget $rcvT2
}
} else {
$rcvT target $agent
$classifier_ defaulttarget $rcvT
$dmux_ install $port $rcvT
}
} else {
#
# Send Target
#
# if tora is used
if { $newapi == "ON" } {
$agent target $imep_(0)
# second tracer to see the actual
# types of tora packets before imep packs them
if { [info exists toraDebug_] && $toraDebug_ == "ON"} {
set sndT2 [$self mobility-trace Send "TRP"]
$sndT2 target $imep_(0)
$agent target $sndT2
}
$imep_(0) sendtarget [$self set ll_(0)]

} else { ;# no IMEP
#Add multiple interface support
#$agent target [$self set ll_(0)]
#puts "Adding 5 targets to routing agent!\n"
$agent down-target-1 [$self set ll_(0)]
$agent down-target-2 [$self set ll_(1)]
$agent down-target-3 [$self set ll_(2)]
$agent down-target-4 [$self set ll_(3)]
$agent down-target-5 [$self set ll_(4)]
#Add multiple interface support
}
#
# Recv Target
#
if {$newapi == "ON" } {
[$self set ll_(0)] up-target $imep_(0)
$classifier_ defaulttarget $agent
# need a second tracer to see the actual
# types of tora packets after imep unpacks them
# no need to support any hier node
if {[info exists toraDebug_] && $toraDebug_ == "ON" } {
set rcvT2 [$self mobility-trace Recv "TRP"]
$rcvT2 target $agent
[$self set classifier_] defaulttarget $rcvT2
}
} else {
$classifier_ defaulttarget $agent
$dmux_ install $port $agent
}
}
}


################################### END ###########################

Then in routing protocol or whereever the packet will be sent to different NIC, define coresponding downtarget for each interface to send out packet like (in header file):
NsObject *downtarget1_;
NsObject *downtarget2_;
NsObject *downtarget3_;
NsObject *downtarget4_;
NsObject *downtarget5_;

Then get the corresponding objects from Tcl from command(int argc, const char*const* argv), for example in AODV:

aodv/aodv.cc

################################### BEGIN ###########################
int
AODV::command(int argc, const char*const* argv) {
if(argc == 2) {
Tcl& tcl = Tcl::instance();
...

else if(argc == 3) {

...

// multi-channel support
else if (strcasecmp (argv[1], "down-target-1") == 0) {
downtarget1_ = (NsObject *) TclObject::lookup(argv[2]);
return TCL_OK;
}
else if (strcasecmp (argv[1], "down-target-2") == 0) {
downtarget2_ = (NsObject *) TclObject::lookup(argv[2]);
return TCL_OK;
}
else if (strcasecmp (argv[1], "down-target-3") == 0) {
downtarget3_ = (NsObject *) TclObject::lookup(argv[2]);
return TCL_OK;
}
else if (strcasecmp (argv[1], "down-target-4") == 0) {
downtarget4_ = (NsObject *) TclObject::lookup(argv[2]);
return TCL_OK;
}
else if (strcasecmp (argv[1], "down-target-5") == 0) {
downtarget5_ = (NsObject *) TclObject::lookup(argv[2]);
return TCL_OK;
}

...
################################### END ###########################

When send out the packet to different interface, just call one of them:
downtarget1_->recv(p, (Handler *)0);
downtarget2_->recv(p, (Handler *)0);
downtarget3_->recv(p, (Handler *)0);
downtarget4_->recv(p, (Handler *)0);
downtarget5_->recv(p, (Handler *)0);

Finally, in the running script, configure each node with multiple interface and channel-assign-to-interface:
################################### BEGIN ###########################
...
#Creating Channel
set chan_0_ [new $val(chan)]
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
set chan_3_ [new $val(chan)]
set chan_4_ [new $val(chan)]

...

$ns_ node-config -channel $chan_3_ -channel2 $chan_11_ -channel3 $chan_12_ -channel4 $chan_12_ -channel5 $chan_12_
...
################################### END ###########################

If you use 802.11 DCF MAC, following changes are necessary to avoid error:

mac/mac-802_11.cc

#include "arp.h"
#include "ll.h"
#include "mac.h"
#include "mac-timers.h"
#include "mac-802_11.h"
#include "cmu-trace.h"

/*
multi-interface support
*/
#define NUM_NICS 5

...

int
Mac802_11::command(int argc, const char*const* argv)
{
if (argc == 3) {
if (strcmp(argv[1], "log-target") == 0) {
logtarget_ = (NsObject*) TclObject::lookup(argv[2]);
if(logtarget_ == 0)
return TCL_ERROR;
return TCL_OK;
} else if(strcmp(argv[1], "nodes") == 0) {
if(cache_) return TCL_ERROR;
/* multiple interface support

cache_node_count_ = atoi(argv[2]);
*/
cache_node_count_ = atoi(argv[2]) * NUM_NICS;
cache_ = new Host[cache_node_count_ + 1];
assert(cache_);
...

void
Mac802_11::recv_timer()
{
...

/* multiple interface support
*/
// if(dst != (u_int32_t)index_) {
if((dst/NUM_NICS) != (u_int32_t)(index_/NUM_NICS)) {
set_nav(mh->dh_duration);
}
...



Friday, December 30, 2005

install ns2.26 in Ubuntu

Objective: install ns-allinone-2.26 in Ubuntu 5.10 Breezy
Software needed: gcc-3.3, g++-3.3 (ns2.26 cannot be compiled with gcc >= 4.0), build-essential, autoconf, automaken, libxt-dev(tk need it), libxmu-dev(nam need it)
To do:
1. apt-get install build-essential
2. apt-get install gcc-3.3 g++-3.3 autoconf automake-1.9 libxt-dev
3. go to /usr/bin, del softlink to gcc, g++
4. ln -s gcc-3.3 gcc
5. ln -s g++-3.3 g++
6. vi .bash_profile and add:
export CC=gcc-3.3
export CXX=g++-3.3

That's all. Then compile ns as instruction.

Wednesday, October 19, 2005

Post blog from writely

Just read an article "Interview with Tony Bove, Author of Just Say No to Microsoft ". Tony thinks Ajax-based web applications will prevail in the next few years. Writely is mentioned as an example. So I just give it a try. I use it to edit this blog and post it with a click. So let's check it out.

Tuesday, October 18, 2005

Chinese display in Ubuntu 5.10 Breezy

Since utf-8 is adopted by Ubuntu by default, several popular softwares I use are impacted that cannot decide the encoding of Chinese characters. However, these softwares already build in support for configurable encoding.

XMMS
option->preferences->Audio I/O plugins->MPEG layer 1/2/3..->configure->Title:
tick Override default ID3V2 encoding, encoding name: GBK

vim
set encoding=utf-8
set fileencoding=GBK

Sunday, October 16, 2005

manually set cpu frequency

If you are like me that treasure my laptop very much and hate to hear the fans soaring, you can try it.

create a simple bash file like this:
#cpulow
#!/bin/bash
echo 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed

1200000 is the lowest availabe frequency for my cpu (P4-M). Put this file to /usr/local/bin and chmod +x. Simple?

#cpuhigh
#!/bin/bash
echo 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed

With these two files, I can manually control how far the cpu should run. Don't forget to remove powernowd service from service in Ubuntu.

-- update --
I found powernowd service cannot be just stopped since acpi modules are also loaded by this script to start the service. I think it's not difficult to modify the script to just stop powernowd deamon and exec cpulow meanwhile. To be updated later.

Install Ubuntu 5.10 (Breezy) on Compaq N800v

There are some reasons prompting me to abandon Gentoo on my laptop, the specific optimization to the desktop by Ubuntu is one of them.

The actually installation should be as smooth as stated, but I still get frustrated for quite a few hours :(

So one thing that I get more confirmed is: cdrom is the last storage you should try.

1. download iso image from ubuntu website, smooth

2. md5 check passes

3. burn it into cd

4. boot with cd, pcmcia wireless card auto recognized and DHCP config successfully which means I can connect to Internet

5. Partition:
40 GB hdd:
hda1: WinXP root, fat32, primary, bootable
hda2: shared by windows and linux, fat32, logic
hda6: 30M, ext3, /boot, logic
hda7: 6.7G, the root for ubuntu, reizser, /, logic

6. start install, failed at base system install, pool/main/l/linux-sources/linux-image.... md5 check failed!

7. burn another 2 cds the next day and repeat previous steps, failed again! /pool/main/linux-sources/linux-head... md5 check failed!

So far, I have no confidence in cdrom any more. Since the md5 check for the downloaded iso image has no problem, it must be in the burning procedure. Since the failed parts for 2 cds are different but near, I bet it's the cdrw's step increasing speed working mode harms it. Maybe I'll have to use my cdrw for some time, but remember to burn it steadily!

8. After research and experiment, finally get it clear how to install linux from image directly.

grub is needed to load bootable environment. Fortunately, even installation failed, ubuntu still gives you all the options for the installation which allow me to directly jump to the grub installation. And it recognizes WinXP installed and configures it automatically.

9. To start bootable environment, two files are needed: initrd.gz and vmlinuz (or linux for netboot version). However, there are several versions of them.

First, in the cdrom, under install, that two are for cdrom install which means the environment is set to insall linux from linux.

In install/netboot/ubuntu-installer/i386, the two are for network install. Using them, no cd and no image are needed for the whole install, only network!

However, what I needed cannot be found in the image itself. The version for install from harddisk image can be downloaded at any ubuntu mirror, under directory ubuntu/dists/breezy(the version)/main/installer-i386/current/images/hd-media
(surely I get information from the name)

To summarize, these two files are programs that guild linux install procedure after enter the bootable environment. Since for different method of install, specific procedure should be provided, the more important issue I guess is to keep these files as small as possible to be fit into any pc. So different versions instead of one versatile with different interfaces are provided.

10. copy these two files to the first primary partition which is also a bootable partition, the grub can get it then. /dev/hda1 is the one for my laptop. Then put the iso image file under the top directory in any of your partitions (but its file system must be recognized by the bootable environment, ubuntu in this case, fat32, ext3, reizser..)

11. reboot laptop, upon promtion by grub, press c
then input three commands:
grub> kernel (hd0,0)/vmlinuz root=/dev/ram ramdisk_size=20000 devfs=mount,dall
grub> initrd (hd0,0)/initrd.gz
grub> boot

It's not difficult to understand the commands. (hd0,0) indicates the hdd devise and the partion that store the files.

12. laptop reboot now and you'll be lead into the harddisk install program now which is slightly different from the one by cdrom install. It will search all reconizable partitions and find the right iso image and the following procedures are just as smooth as it should be. Huhu~~, finally get Ubuntu on my laptop!

Reference:
ubuntu wiki
Install GNU/Linux without any CD, floppy, USB-key, nor any other removable media