I am a Postdoctoral Research Fellow with The SUTD-MIT International Design Centre (IDC), Singapore University of Technology and Design (SUTD). My research topic is about protocol and algorithm design, resource allocation and localisation in wireless sensor network, UAV network and Ad Hoc network. I also enjoy the mobile programming (Android and Objective-C) and web server development. Thanks for sharing.
Dec 15, 2012
E: Internal Error, No file name for libssl1.0.0
The problem of libssl1.0.0 in Ubuntu 12.04 is "E: Internal Error, No file name for libssl1.0.0". So we can type:
sudo apt-get update
sudo apt-get clean
sudo apt-get install -fy
sudo dpkg -i /var/cache/apt/archives/*.deb
sudo dpkg --configure -a
sudo apt-get install -fy
sudo apt-get dist-upgrade
This method could solve the problem.
Nov 25, 2012
Ubuntu login from GUI and command line
Switch to command prompt: Ctrl + F1
Switch to GUI: Ctrl + F7
Command line to start GUI: sudo lightdm
Nov 11, 2012
Programming on Tinyos
Installation (a simple way)
1) deb http://tinyos.stanford.edu/tinyos/dists/ubuntu natty main
2) sudo apt-get update
3) sudo apt-get install tinyos
4) sudo apt-get install tinyos-2.1.1
5) Add the following line to your ~/.bashrc or ~/.profile file in your home directory to set up the environment for TinyOS development at login
#Sourcing the tinyos environment variable setup script
source /opt/tinyos-2.1.1/tinyos.sh
Oct 3, 2012
How to decompress multiple files on Linux
To unzip multiple zipped .zip files:
for file in *.zip; do unzip "${file}"; done
To unzip multiple zipped .gz files;
gunzip *.gz
To unzip multiple zipped .bz2 files;
bunzip2 *.bz2
To extract multiple .tar.gz files;
for file in *.tar.gz; do tar zxf "${file}"; done
To extract multiple .tar.bz2 files;
for file in *.tar.bz2; do tar jxf "${file}"; done
Sep 19, 2012
Generate ssh key on Mac OS
Open a terminal and enter the following commands,
$ cd ~/
$ ssh-keygen -t rsa
It will ask you to specify the location, so just use the default one (~/.ssh/id_rsa.pub) by pressing return. If you do not need passphrase, just press return. After that, you may get something like this,
Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
45:a0:5b:34:23:73:8c:43:03:27:b5:92:9d:80:b1:7d
yourusername@XXXmac
The key's randomart image is:
+--[ RSA 2048]----+
| ... o*+=*o.|
| ... = -+++ |
| .. + ..+.|
| .. .|
| P . |
| .. Y |
| x |
| . |
| |
+-----------------+
Then you can find your public key in the "file ~/.ssh/id_rsa.pub".
Sep 5, 2012
How to format a hard drive for Mac OS
Video tutorial links:
http://www.youtube.com/watch?v=8te1bg07MsQ
http://www.youtube.com/watch?v=WzQF0Qo5Kv0
Aug 7, 2012
Command line to check the version
We can use this command to check whether the linux is 32 bits or 64 bits:
uname -m
if the output is i686, then it is 32 bits;
if the output is x86_64, then it is 64 bits.
How to change the icon of an application
First of all, copy the new icon into clipboard;
Then, open the Info window for the application (File » Get Info, or Command-I), click the icon in that window (a blue border will appear), and paste in a new icon.
Jul 12, 2012
Ubuntu 11.04 bug - Update Manager
When I logged in my Ubuntu, update manager window was popped up to ask for update. I clicked "Install Updates" button, but this time it said "waiting for apt-get to exit..." and then the window was dead. I closed all the other applications including firefox, terminal and editor, but the problem was not solved.
So I posted a bug report to the website. Someone suggested to restart virtual machine in order to solve it. Then I tried it. I did not know why my Ubuntu got this problem but this solution did work.
Good luck, Ubuntu!
Jun 2, 2012
Compile java files in all subfolders
On Windows...
Firstly create a batch file as complie.bat. Write these lines in that
for /r %%a in (*.java) do ( javac "%%a" )
now execute.
On Linux....
javac $(find ./rootdir/* | grep .java)
May 21, 2012
2012 ACM ICPC Final
Check out the problems
And the final results
Apr 3, 2012
How to program nodes movement using FOR loop in NS2
In fact, we know how to set the nodes` movement in NS2, it could be < $ns at TIME "$NODE1 setdest $val(X1) $val(Y1) SPEED" >. However, for some scenario, it may contain a large number of nodes` movement and simulation time could be one or several hours. It is impossible to program in this static way.
So we consider using a FOR loop. Here is an example where a node is moving up and down. The simulation time can be any value and we just need five lines program. The program is like the following,
for {set i 1} {$i < ($val(stop))} {set i [expr {$i + 10}]} {
$ns at $i "$node_(1) setdest $val(X1) $val(Y1) NodeSpeed"
set i [expr {$i + 10}]
$ns at $i "$node_(1) setdest $val(X2) $val(Y2) NodeSpeed"
}
Mar 7, 2012
Extend hard disc space for VMware in Mac OS
It is a common problem that the system space in the virtual machine is not enough we allocated before. We may need to extend its size after the system installation. So here is the way.
1) Open VMware Fusion and choose your virtual machine from the "Virtual Machine Library" list. Choose "Settings" from the "Virtual Machine" menu and select "Hard Disks."
2) Adjust the size of your hard disk by using the slider. Click "Apply" when finished.
If you have a Windows 7 or Vista virtual machine,
3) Start your virtual machine and log in as an administrator. Click "Start" and select "Control Panel." Click "System and Security" and then "Administrative Tools." Double-click the "Computer Management" option and click "Disk Management" on the left pane of the window that appears. Right-click on your virtual machine's volume and choose "Extend Volume." Click "Next" twice and then "Finish.
Labels:
virtual machine
Location:
UNSW, New South Wales, Australia
Feb 29, 2012
Feb 2, 2012
Check the number of words in LATEX
We use a perl program to count the LATEX article words.
BEGIN {
%cutlist = (
'begin' => 1,
'end' => 1,
'usepackage' => 1,
'addtolength' => 1,
'documentclass' => 1,
'author' => 1,
'title' => 1,
'chapter' => 1,
'bibliography' => 1,
'bibliographystyle' => 1,
'section' => 1,
'subsection' => 1,
'subsubsection' => 1,
'thanks' => 1,
'pagestyle' => 1,
);
my $line = '';
my $cumline = '';
my $depth = 0;
my $words = 0;
my $fnwords = 0;
my $i = 0;
my @tags = ();
my $thistag = '';
}
$line = $_;
# Regularize line endings
$line =~ s/\r/\n/g;
# Remove comments
$line =~ s/(?
# Count curly braces
while($line =~ /\{/g){$depth++}
while($line =~ /\}/g){$depth--}
$cumline .= $line;
if ($depth == 0) {
while($cumline =~ s/(\\\w+)?\s*\{([^\{\}]*)\}/<"$i"<$2>"$i">/s){push @tags, $1; $i++;}
$i = 0;
while($#tags >= 0){
$thistag = shift @tags;
$thistag =~ s/\\//;
if ($thistag eq 'footnote') {
# Footnotes are counted separately.
$cumline =~ s/<"$i"<(.*)>"$i">//s;
$line = $1;
while($line =~ /\b\w+\b/g){$fnwords++};
} elsif (defined($cutlist{$thistag})) {
# The arguments of these tags are removed.
$cumline =~ s/<"$i"<.*>"$i">//s;
} else {
# The arguments of other tags are left in.
$cumline =~ s/<"$i"<(.*)>"$i">/$1/s;
};
$i++;
}
$cumline =~ s/\\\w+//g;
# Count the remaining words in the present bit of text.
while($cumline =~ /\b\w+\b/g){$words++}
$cumline = '';
$i = 0;
}
END{
print "\n$words words in the main text\n$fnwords in the footnotes\n";
print ($words+$fnwords);
print " total\n\n";
}
Store this program in a XXX.pl file, and run it in command line.
>perl XXX.pl foo.tex
Jan 21, 2012
Add multiple Interfaces and multiple channels into NS2.34
First of all, I install ns2.34 on Ubuntu 11.04. If you don`t know how to do it, just follow this page, http://itantenna.blogspot.com/2012/01/install-ns234-on-ubuntu-1004.html
Here, I just give the program which I modified. If you want to check the details, please download this document, http://personales.unican.es/aguerocr/files/ucMultiIfacesSupport.pdf. Please notice that I am not following this tutorial wholly.
Before we modify the original NS2 program, we`d better make a backup copy of it.(This is very important) OK, the first file we need to modify is "ns-lib.tcl". We will define four procedures,
-------------------------------------/tcl/lib/ns-lib.tcl-----------------------------------------------------------
Simulator instproc change−numifs {newnumifs} {
$self instvar numifs_
set numifs_ $newnumifs
}
Simulator instproc add−channel {indexch ch} {
$self instvar chan
set chan($indexch) $ch
}
Simulator instproc get−numifs { } {
$self instvar numifs
if [ info exists numifs ] {
return $numifs }else{
return ””
}
}
Simulator instproc ifNum {val} {$self set numifs $val}
Then changes the "node-config" procedure like this,
Simulator instproc node−config args {
......
set args [eval $self init−vars $args]
$self instvar addressType_ routingAgent_ propType_ macTrace_ \
routerTrace_ agentTrace_ movementTrace_ channelType_ channel_ numifs_ \
chan_ topoInstance_ propInstance_ mobileIP_ rxPower_ \
# change wrt Mike ’ s code
txPower_ idlePower_ satNodeType_ eotTrace_
......
# Single channel, single interface
warn ”Please use −channel as shown in tcl/ex/
wireless−mitf.tcl”
if {![ info exists chan]} {
set chan [new $channelType_ ]
}
} elseif {[info exists channel_ ]} {
# Multiple channel, multiple interfaces
if {[ info exists numifs_ ]} {
set chan(0) $channel_ } else {
set chan $channel_
}
if [ info exists topoInstance_ ] {
$propInstance_ topography $topoInstance_
}
......
Simulator instproc create−wireless−node args {
$self instvar routingAgent_ wiredRouting_ propInstance_ llType_ \
macType_ ifqType_ ifqlen_ phyType_ chan_ antType_ energyModel_ \
initialEnergy_ txPower_ rxPower_ idlePower_ \
topoInstance_ level1_ level2_ inerrProc_ outerrProc_ FECProc_ numifs_
Simulator set IMEPFlag_ OFF
......
# Adding Interface
if {[info exist numifs_] } {
for {set i 0} {$i < $numifs_} {incr i} {
# Add one interface per channel
$node add−interface $chan( $i ) $propInstance_ $llType_ $macType_ \
$ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \
$inerrProc_ $outerrProc_ $FECProc_
}
} else {
$node add−interface $chan $propInstance_ $llType_ $macType_ \
$ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ \
$inerrProc_ $outerrProc_ $FECProc_
}
# Attach agent
if {$routingAgent_ != ”DSR”} {
$node attach $ragent [Node set rtagent_ port_ ]
}
......
-------------------------------------/tcl/lib/ns-mobilenode.tcl-----------------------------------------------------------
......
Node/MobileNode instproc add−target { agent port } {
$self instvar dmux_ imep_ toraDebug_
set ns [ Simulator instance ]
set newapi [ $ns imep−support ]
$agent set sport_ $port
# We get the number of interfaces from the simulator object
set numIfsSimulator [ $ns get−numifs ]
# special processing for TORA/IMEP node
set toraonly [string first ”TORA” [$agent info class]]
......
#
# Special processing for ZBR
# set zbronly [string first ”ZBR” [$agent info class]]
# if {$zbronly != −1 } {
# $agent if−queue [ $self set ifq_(0) ] ;
# ifq between LL and MAC
#
if { $port == [Node set rtagent_ port_ ] } {
# Special processing when multiple interfaces are supported
if {$numIfsSimulator != ””} {
for {set i 0} {$i < [$self set nifs_]} {incr i} {
$agent if−queue $i [$self set ifq_($i)]
}
}
# Ad hoc routing agent setup needs special handling
$self add−target−rtagent $agent $port
return
}
......
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]
# We see whether we have multiple interfaces in the simulation
set numIfsSimulator [ $ns get−numifs ]
# let the routing agent know about the port dmux
$agent port−dmux $dmux_
......
# 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
}
$sndT target [$self set ll_(0)]
} else { ;# noIMEP
i f {$numIfsSimulator != ””} {
for {set i 0} {$i < [$self set nifs_ ]} {incr i} {
set sndT [cmu−trace Send ”RTR” $self ]
$agent target $i $sndT
$sndT target [$self set ll_($i)]
}
} else {
$agent target $sndT
$sndT target [$self set ll_(0)]
}
}
......
$imep_(0) sendtarget [ $self set ll_(0) ]
} else { ;# noIMEP
if {$numIfsSimulator != ””} {
for {set i 0} {$i< [$self set nifs_] } {incr i} {
$agent target $i [$self set ll_($i)]
}
} else {
$agent target [$self set ll_(0)]
}
}
#
# Recv Target
#
if {$newapi == ”ON” } {
[$self set ll_(0)] up−target $imep_(0)
$classifier_ defaulttarget $agent
......
Node/MobileNode instproc add−interface { channel pmodel lltype mactype qtype qlen iftype anttype topo inerrproc outerrproc fecproc} {
$self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_ inerr_ outerr_ fec_
set ns [ Simulator instance ]
set imepflag [ $ns imep−support ]
set t $nifs_
incr nifs_
...
set inerr $inerr_($t)
set outerr $outerr_($t)
set fec $fec_($t)
# We also create one ARP table per interface
set arptable_($t) [new ARPTable $self $mac]
set arptable $arptable_($t)
if {$imepflag != ””} {
set drpT [ $self mobility−trace Drop ”IFQ”]
} else {
set drpT [cmu−trace Drop ”IFQ” $self ]
}
$arptable drop−target $drpT
if { $namfp != ”” } { $drpT namattach $namfp
}
#
# Link Layer
#
$ l l arptable $arptable
$ll mac $mac
$ll down−target $ifq
......
Node/MobileNode instproc init args {
...
$self instvar nifs_ arptable_ X_ Y_ Z_ nodetype_
set X 0.0
set Y 0.0
set Z 0.0
# set arptable ”” ;# no ARP table yet
set nifs 0 ;# number of network interfaces
......
Node/MobileNode instproc reset {} {
$self instvar arptable_ nifs_ netif_ mac_ ifq_ ll_ imep_
for {set i 0} {$i < $nifs_} {incr i} {
$netif_($i) reset
$mac_($i) reset
$ll_($i) reset
$ifq_($i) reset
if { [info exists opt(imep)] && $opt(imep) == ”ON” } {
$imep_( $i ) reset
}
if { $arptable_($i) != ”” } {
$arptable _( $i ) reset
}
}
}
-------------------------------------/common/mobilenode.h-----------------------------------------------------------
...
# define MAX_CHANNELS 20
...
/∗ For list−keeper ∗/
MobileNode∗ nextX_[MAX_CHANNELS] ;
MobileNode∗ prevX_[MAX_CHANNELS] ;
...
void start(void);
void getLoc(double ∗x, double ∗y, double ∗z);
inline void getVelo(double ∗dx, double ∗dy, double ∗dz) {
∗dx= dX_ ∗ speed_; ∗dy= dY_ ∗ speed_; ∗dz= 0.0;
}
...
-------------------------------------/common/mobilenode.cc-----------------------------------------------------------
void MobileNode::getLoc(double ∗x, double ∗y, double ∗z)
{
update position ()
∗x = X_;
∗y = Y_;
∗z = Z_;
}
-------------------------------------/mac/channel.cc-----------------------------------------------------------
Replace ALL the nextX_ and prevX_ by the following arrays in this program.
nextX_[this−>index()]
prevX_[this−>index()]
And modify this part,
affectedNodes = getAffectedNodes(mtnode, distCST_ + /∗ safety ∗/ 5, &numAffectedNodes ) ;
for (i=0; i < numAffectedNodes; i++) {
rnode = affectedNodes [ i ] ;
if (rnode == tnode)
continue ;
newp = p−>copy();
propdelay = get_pdelay(tnode, rnode);
rifp = (rnode−>ifhead()).lh_first;
for(; rifp; rifp = rifp−>nextnode()){
if(rifp−>channel() == this) {
s.schedule(rifp , newp, propdelay);
}
}
}
delete []affectedNodes ;
-------------------------------------/mac/mac-802_11.cc-----------------------------------------------------------
......
if(tx_active_ && hdr−>error() == 0) {
hdr−>error () = 1;
}
hdr−>iface() = addr();
if(rx_state_ == MAC_IDLE){
......
For routing part, I use the AODV protocol as an example here.
-------------------------------------/aodv/aodv.h-----------------------------------------------------------
......
# define MinHelloInterval (0.75 * HELLO_INTERVAL)
# define MAX_IF 11
......
/*
* Route Table Management
*/
void rt_update(aodv_rt_entry *rt, u_int32_t seqnum, u_int16_t metric, nsaddr_t nexthop, double expire_time, u_int8_t interface);
......
int nIfaces ;
NsObject ∗targetlist[MAX_IF];
PriQueue ∗ifqueuelist [MAX_IF];
......
-------------------------------------/aodv/aodv.cc-----------------------------------------------------------
......
int
AODV::command(int argc, const char*const* argv) {
......
else if(argc == 3) {
......
}
else if(argc == 4) {
if (strcmp(argv[1] ,”if−queue”) == 0) {
PriQueue ∗ ifq = (PriQueue ∗) TclObject::lookup(argv[3]);
int temp_ = atoi(argv[2]);
if(temp_ == nIfaces) {
nIfaces++;
}
ifqueuelist [temp_] = ifq ;
if (ifqueuelist[temp_]) {
return TCL_OK;
}else{
return TCL_ERROR;
}
}
if (strcmp(argv[1] ,”target”) == 0) {
int temp_ = atoi(argv[2]);
if(temp_ == nIfaces) {
nIfaces++;
}
targetlist[temp_] = (NsObject ∗) TclObject::lookup(argv[3]);
if(targetlist[temp_]) {
return TCL_OK;
} else {
return TCL_ERROR;
}
}
}
return Agent::command(argc, argv);
} // Be careful, there are many brackets here!
/*
Constructor
*/
AODV::AODV(nsaddr_t id) : Agent(PT_AODV), btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() {
index = id;
seqno = 2;
bid = 1;
LIST_INIT(&nbhead);
LIST_INIT(&bihead);
logtarget = 0;
ifqueue = 0;
nIfaces = 0;
}
......
void
AODV::rt_update(aodv_rt_entry *rt, u_int32_t seqnum, u_int16_t metric,
nsaddr_t nexthop, double expire_time, u_int8_t interface) {
rt->rt_seqno = seqnum;
rt->rt_hops = metric;
rt->rt_flags = RTF_UP;
rt->rt_nexthop = nexthop;
rt->rt_expire = expire_time;
rt->rt_interface = interface;
}
......
void
AODV::recvRequest(Packet *p) {
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p);
aodv_rt_entry *rt;
struct hdr_cmn *ch = HDR_CMN(p);
u_int8_t Iface;
...
}
......
if ( (rq->rq_src_seqno > rt0->rt_seqno ) || ((rq->rq_src_seqno == rt0->rt_seqno) && (rq->rq_hop_count < rt0->rt_hops)) ) {
// If we have a fresher seq no. or lesser #hops for the
// same seq no., update the rt entry. Else don't bother.
if(nIfaces){
Iface = ch ->iface()-((Mac *) ifqueuelist[0]->target())->addr();
} else {
Iface = -1;
}
rt_update(rt0, rq->rq_src_seqno, rq->rq_hop_count, ih->saddr(),
max(rt0->rt_expire, (CURRENT_TIME + REV_ROUTE_LIFE)), Iface );
if (rt0->rt_req_timeout > 0.0) {
// Reset the soft state and
// Set expiry time to CURRENT_TIME + ACTIVE_ROUTE_TIMEOUT
// This is because route is used in the forward direction,
// but only sources get benefited by this change
rt0->rt_req_cnt = 0;
rt0->rt_req_timeout = 0.0;
rt0->rt_req_last_ttl = rq->rq_hop_count;
rt0->rt_expire = CURRENT_TIME + ACTIVE_ROUTE_TIMEOUT;
}
...
}
......
void
AODV::recvReply(Packet *p) {
//struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_reply *rp = HDR_AODV_REPLY(p);
aodv_rt_entry *rt;
char suppress_reply = 0;
double delay = 0.0;
#ifdef DEBUG
fprintf(stderr, "%d - %s: received a REPLY\n", index, __FUNCTION__);
#endif // DEBUG
struct hdr_cmn *ch = HDR_CMN(p);
u_int8_t Iface;
...
if(nIfaces){
Iface = ch ->iface()-((Mac *) ifqueuelist[0]->target())->addr();
} else {
Iface = -1;
}
rt_update(rt, rp->rp_dst_seqno, rp->rp_hop_count,
rp->rp_src, CURRENT_TIME + rp->rp_lifetime, Iface);
// reset the soft state
rt->rt_req_cnt = 0;
rt->rt_req_timeout = 0.0;
rt->rt_req_last_ttl = rp->rp_hop_count;
...
}
......
void
AODV::forward(aodv_rt_entry *rt, Packet *p, double delay) {
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
if(ih->ttl_ == 0) {
#ifdef DEBUG
fprintf(stderr, "%s: calling drop()\n", __PRETTY_FUNCTION__);
#endif // DEBUG
drop(p, DROP_RTR_TTL);
return;
}
if (ch->ptype() != PT_AODV && ch->direction() == hdr_cmn::UP &&
((u_int32_t)ih->daddr() == IP_BROADCAST)
|| (ih->daddr() == here_.addr_)) {
dmux_->recv(p,0);
return;
}
if (rt) {
assert(rt->rt_flags == RTF_UP);
rt->rt_expire = CURRENT_TIME + ACTIVE_ROUTE_TIMEOUT;
ch->next_hop_ = rt->rt_nexthop;
ch->addr_type() = NS_AF_INET;
ch->direction() = hdr_cmn::DOWN; //important: change the packet's direction
}
else { // if it is a broadcast packet
// assert(ch->ptype() == PT_AODV); // maybe a diff pkt type like gaf
assert(ih->daddr() == (nsaddr_t) IP_BROADCAST);
ch->addr_type() = NS_AF_NONE;
ch->direction() = hdr_cmn::DOWN; //important: change the packet's direction
}
if (ih->daddr() == (nsaddr_t) IP_BROADCAST) {
// If it is a broadcast packet
assert(rt == 0);
if (ch->ptype() == PT_AODV) {
/*
* Jitter the sending of AODV broadcast packets by 10ms
*/
if(nIfaces) {
for(int i=0; i
Packet *p_copy = p->copy();
Scheduler::instance().schedule(targetlist[i], p_copy, 0.01*Random::uniform());
}
Packet::free(p);
} else {
Scheduler::instance().schedule(target_, p, 0.01*Random::uniform()); // No jitter
}
} else {
if(nIfaces) {
for(int i=0; i
Packet *p_copy = p->copy();
Scheduler::instance().schedule(targetlist[i], p_copy, 0);
}
Packet::free(p);
} else {
Scheduler::instance().schedule(target_, p, 0); // No jitter
}
}
}
else { // Not a broadcast packet
if(delay > 0.0) {
if(nIfaces) {
Scheduler::instance().schedule(targetlist[rt->rt_interface], p, delay);
} else {
Scheduler::instance().schedule(target_, p, delay);
}
}
else {
// Not a broadcast packet, no delay, send immediately
if(nIfaces) {
Scheduler::instance().schedule(targetlist[rt->rt_interface], p, 0.);
} else {
Scheduler::instance().schedule(target_, p, 0.);
}
}
}
} // Be careful, many brackets here!
......
void
AODV::sendReply(nsaddr_t ipdst, u_int32_t hop_count, nsaddr_t rpdst,
u_int32_t rpseq, u_int32_t lifetime, double timestamp) {
Packet *p = Packet::alloc();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_reply *rp = HDR_AODV_REPLY(p);
aodv_rt_entry *rt = rtable.rt_lookup(ipdst);
#ifdef DEBUG
fprintf(stderr, "sending Reply from %d at %.2f\n", index, Scheduler::instance().clock());
#endif // DEBUG
assert(rt);
rp->rp_type = AODVTYPE_RREP;
//rp->rp_flags = 0x00;
rp->rp_hop_count = hop_count;
rp->rp_dst = rpdst;
rp->rp_dst_seqno = rpseq;
rp->rp_src = index;
rp->rp_lifetime = lifetime;
rp->rp_timestamp = timestamp;
// ch->uid() = 0;
ch->ptype() = PT_AODV;
ch->size() = IP_HDR_LEN + rp->size();
ch->iface() = -2;
ch->error() = 0;
ch->addr_type() = NS_AF_INET;
ch->next_hop_ = rt->rt_nexthop;
ch->prev_hop_ = index; // AODV hack
ch->direction() = hdr_cmn::DOWN;
ih->saddr() = index;
ih->daddr() = ipdst;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl_ = NETWORK_DIAMETER;
if(nIfaces) {
Scheduler::instance().schedule(targetlist[rt->rt_interface], p, 0.);
} else {
Scheduler::instance().schedule(target_, p, 0.);
}
}
void
AODV::sendError(Packet *p, bool jitter) {
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_error *re = HDR_AODV_ERROR(p);
#ifdef ERROR
fprintf(stderr, "sending Error from %d at %.2f\n", index, Scheduler::instance().clock());
#endif // DEBUG
re->re_type = AODVTYPE_RERR;
//re->reserved[0] = 0x00; re->reserved[1] = 0x00;
// DestCount and list of unreachable destinations are already filled
// ch->uid() = 0;
ch->ptype() = PT_AODV;
ch->size() = IP_HDR_LEN + re->size();
ch->iface() = -2;
ch->error() = 0;
ch->addr_type() = NS_AF_NONE;
ch->next_hop_ = 0;
ch->prev_hop_ = index; // AODV hack
ch->direction() = hdr_cmn::DOWN; //important: change the packet's direction
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl_ = 1;
// Do we need any jitter? Yes
if (jitter) {
if(nIfaces) {
for(int i=0; i
Packet *p_copy = p->copy();
Scheduler::instance().schedule(targetlist[i], p_copy, 0.01*Random::uniform());
}
Packet::free(p);
} else {
Scheduler::instance().schedule(target_, p, 0.01*Random::uniform());
}
}
else {
if(nIfaces) {
for(int i=0; i
Packet *p_copy = p->copy();
Scheduler::instance().schedule(targetlist[i], p_copy, 0.0);
}
Packet::free(p);
}
else {
Scheduler::instance().schedule(target_, p, 0.0);
}
}
}
void
AODV::sendHello() {
Packet *p = Packet::alloc();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_reply *rh = HDR_AODV_REPLY(p);
#ifdef DEBUG
fprintf(stderr, "sending Hello from %d at %.2f\n", index, Scheduler::instance().clock());
#endif // DEBUG
rh->rp_type = AODVTYPE_HELLO;
//rh->rp_flags = 0x00;
rh->rp_hop_count = 1;
rh->rp_dst = index;
rh->rp_dst_seqno = seqno;
rh->rp_lifetime = (1 + ALLOWED_HELLO_LOSS) * HELLO_INTERVAL;
// ch->uid() = 0;
ch->ptype() = PT_AODV;
ch->size() = IP_HDR_LEN + rh->size();
ch->iface() = -2;
ch->error() = 0;
ch->addr_type() = NS_AF_NONE;
ch->prev_hop_ = index; // AODV hack
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl_ = 1;
if(nIfaces) {
for(int i=0; i
Packet *p_copy = p->copy();
Scheduler::instance().schedule(targetlist[i], p_copy, 0.0);
}
Packet::free(p);
}
else {
Scheduler::instance().schedule(target_, p, 0.0);
}
}
Jan 9, 2012
Record video in Ubuntu
In Ubuntu, I use XvidCap to record video on the screen. The package link is https://launchpad.net/ubuntu/natty/+package/xvidcap.
One of the most useful features of XvidCap is that it allows to select the recording area instead of the whole screen. And it also supports to output the video in MPEG format.
You may need to convert it to other video format, such as WMV, ASF, MOV and some for ipod or iphone. Since I am working on Mac OS, I recommend a free software which is called iSkysoft iMedia Converter. Actually, there is a video teaching you how to crack, http://www.youtube.com/watch?v=cLo-zuMxSNM.
Hopefully, these two softwares are helpful to you.
Jan 4, 2012
Set nodes` color in NS2 simulation program
This is a pretty tricky way to hit the target. And we can change the color at any time.
set ns [new Simulator]
set node [$ns node 0]
$ns at 0.0 "$node color red"
$ns at 1.0 "$node color blue"
One NS2 old trace format analysis
After NS2 simulations are finished, someone may need to analyze the trace file which is output by TCL program. I got the trace file format which is like this
"s 38.212991274 _2_ MAC --- 86 MYTYPE 178 [13a 3 2 800] ------- [2:0 3:0 30 3]"
"s 38.418136390 _3_ AGT --- 89 MYTYPE 100 [0 0 0 0] ------- [3:0 2:0 32 0]"
The first field is the event type, whose value can be s (send), r (receive), d (drop) or f (forward).
The second field the time this event happens.
The third field records the id of the node, on which this event takes place.
The fourth field shows the layer where this event happens. Its possible value may be one of the following four: AGT (agent), RTR (router), IFQ (interface queue), and MAC (mac).
The fifth field is normally a short broken line, which is reserved for special events. For example, when collision occurs, the broken line is replaced with COL.
The sixth field is the global sequence number for this packet, which is the integer number used to identify this packet in the whole network and distinguish it from others. Sequence number is only available for data packets and not allocated for control packets, like RTS/CTS/ACK and SYNC packets in S-MAC (using a zero instead).
The seventh field is the packet type. The actual value is determined by the application or MAC layer, which creates this packet. For example, cbr represents that it is a data packet generated by a CBR traffic source.
The eighth field is the packet size in bytes.
Since I use AODV routing protocol, the ninth field is AODV trace information including three numbers in brackets concerns MAC layer information. Usually, there will be four numbers in the brackets. Its format is like "[0x%x %d [%d %d] %f] (%s)" 1)| hexadecimal | Type | 2)| int | Hop Count | 3)|int | Destination | Destination Sequence Number | 4)|double | Lifetime | 5)|string | Operation (REPLY, ERROR, HELLO) |
The tenth field is IP trace info including | Source IP Address:Source Port Number | Destination IP Address:Destination Port Number | TTL Value | Next Hop Address, If Any |
Jan 2, 2012
Install ns2.34 on Ubuntu 10.04
1) Download ns2.34 allinone package from http://sourceforge.net/projects/nsnam/files%2Fallinone%2Fns-allinone-2.34/
2) Uncompress to your own directory by using command "tar -zvxf ns-allinone-2.34.tar.gz"
3) Install some development files,
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential
sudo apt-get install libc6-dev g++ gcc-4.3
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev
sudo apt-get install autoconf automake libxmu-dev libxmu-headers
4) Then,
$cd ns-allinone.2.34/
$./install
5) If got "otcl-1.13 make failed! Exiting" error,
i)edit the configure.in file in otcl-1.13, Line77 SHLIB_LD="ld -shared" -> SHLIB_LD="gcc -shared"
ii)edit the configure file in otcl-1.13, Line6304 SHLIB_LD="ld -shared" -> SHLIB_LD="gcc -shared"
6) Edit otcl-1.13/Makefile.in,
CC= @CC@ -> CC= gcc-4.3
7) Then,
$cd ns-allinone.2.34/
$./install
8) If got an error like
"`.gnu.linkonce.t._ZN11taskPending10taskStatusEh' referenced in section `.rodata' of wpan/p802_15_4mac.o: defined in discarded section `.gnu.linkonce.t._ZN11taskPending10taskStatusEh' of wpan/p802_15_4mac.o
collect2: ld returned 1 exit status
make: *** [ns] error 1"
, that is because you are using gcc3.3 to compile it. And you have to change gcc compiler version to gcc4 or above.9) Then, it should work. Finally, dont forget to modify .bashrc file to add environment variables.
export PATH=$PATH:/YOURDIR/ns-allinone-2.34/bin:/YOURDIR/ns-allinone-2.34/tcl8.4.18/unix:/YOURDIR/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/YOURDIR/ns-allinone-2.34/otcl-1.13:/YOURDIR/ns-allinone-2.34/lib
export TCL_LIBRARY=$TCL_LIBRARY:/YOURDIR/ns-allinone-2.34/tcl8.4.18/library
Subscribe to:
Posts (Atom)