Tuesday, March 23, 2021

Accessing Ethereum/Web Server from Guest OS running under Virtual Machine to any Computer in LAN

The objective of this post is to explain how to access the web server running under Guest OS in Virtual Machine (VM) software from Host OS and any other computer connected in a Local Area Network (LAN). I am explaining it for Ethereum blockchain software installed in VM box. However, the same procedure may be applicable for accessing web server or other services.

VM software is used to achieve virtualization and for running multiple Guest operating systems without disturbing the Host operating system. To achieve this, the  processor (CPU) attached to the computer should have the feature of Virtualization. Once the VM software has been installed on a Host OS, the VM software creates a virtual IP address to function networking related activities. As usual, an IP address can be statically set or dynamically (DHCP) obtained for every computer. To this end, a computer system running VM software contains two IP addresses such as 1) Virtual IP created by VM software, and 2) Actual IP address of the system. The following figure shows the block diagram of LAN in which a computer with VM software connected. 




Now we will see how to access a web server launched in Guest OS on VM software from another computer in the LAN.

Step 1: Obtain the IP address of the computer. It is found that the IP address of the system as 172.16.26.1


Step 2: Obtain the IP address of the HOST OS running in VM software. It was found that the IP address of the Host OS as 10.0.2.15




Wednesday, August 17, 2016

Configuring and working with NetTopo Simulator in Eclipse Kepler



Prerequisites:

The system should have either Java 6.0 or higher (i.e., both the JDK and JRE need to be installed), and the JAVA_HOME path should be set in the System variables.  

Configuration Procedure

Step 1:  Download and extract the Eclipse Kepler for JAVA by clicking here.
Step 2: Download Java3D and install in the Java installation directory by clicking here
Step 3:  Extract the Eclipse to C: Drive and run the Eclipse IDE.
Step 4:  Create CVS Project
               4.1 File -> New -> Project -> Project from CVS





               4.2  Set Host -> nettopo.cvs.sourceforge.net
                             Repository Path -> /cvsroot/nettopo/
                             User -> anonymous 
                             Password -> No password required (empty)
                             Connection type -> pserver
                             Port -> Use default port

                             click Next

              

                            
                   4.3  Project name -> NetTopo

 Step 5: Setting up Ant build and run
               
               5.1  In Window menu, select Preferences -> Ant -> Runtime


                   5.2  Select Ant Home Entries and Click on Add External Jar Files
                    
                   select

                  C:\Program Files\Java\jdk1.6.0\lib\tools.jar
                  C:\Program Files\Java\Java3D\1.5.2\lib\ext\j3dutils.jar
                  C:\Program Files\Java\Java3D\1.5.2\lib\ext\j3dcore.jar
                  C:\Program Files\Java\Java3D\1.5.2\lib\ext\vecmath.jar

                 and save the Entries.

Building and Running the NetTopo Project

Step 6:  In Run menu select Run Configurations 
               Project: NetTopo
               Main class: org.deri.nettopo.app.NetTopoApp



Step 7: In (X) argument tab enter the following under VM arguments

                -Djava.library.path=bin


Step 8: In the Package Explorer select NetTopo project and right click
              Run As -> Java Application -> NetTopo Application
            


                   

Friday, April 22, 2016

Jaypee Institute of Information Technology (JIIT), Noida, PhD Thesis LaTex Template

This post consists of the Ph.D Thesis template of Jaypee Institute of Information Technology, Noida, India. The details of the files and folders are as follows
This template is created using LyX platform.
It consists of three main folders namely
1.       front_matter: It consists of the files related to the contents that are placed before the chapters.
They are
cover_page.lyx – Cover page of the thesis
dedication.lyx – Dedication page of the thesis
acknowledgements.lyx – Acknowledgements page of the thesis
declaration by student.lyx – Scholar declaration
supervisor certificate.lyx – Supervisor certificate
abstract.lyx – Abstract of the thesis

2.       main_matter: It consists of chapters of the thesis. Separate folder is created for each chapter. Each chapter folder consists of Image folder in which figures of that chapters are stored.

3.       end_matter: It consists of the files related to the contents that are placed after chapters.
They are
annexure.lyx – annexure or appendix of the thesis
references.lyx – Bibliography of the thesis – references are placed in bibtex format in the references.bib file. It follows IEEE referencing format.
publications.lyx – list of publications out of the thesis
biography.lyx – Authors biography
end_page.lyx - Copyright information of the thesis

The full thesis can be seen by running thesis_main.lyx file.
For writing algorithms, Algorithm2e.pdf file is placed for reference.
For reference, you may view JIIT PhD thesis preparation guidelines in jiit_phd_thesis_guidelines.pdf file.


   Click Here to download the JIIT PhD thesis template  (Last updated 06-05-2016)


Sunday, February 21, 2016

Handling Segmentation Fault (Core Dumped) in ns-2

Programming c++ in ns-2 is a nightmare for beginners. It requires systematic planning and programming. Though the programming is systematically planned, even experienced programmers frequently encounter  bugs called "Segmentation fault (Core Dumped)" and Floating point exception (Core Dumped).  Generally, Floating point exception can be dealt with positive value in the denominator of an expression. This post explains how to debug these problem in ns2. The following procedure has been tested with ns-2.35.

Prerequisite: Your system should installed with gdb (GNU debugger).

Step 1: goto ns-allinone-2.35/ns-2.35, and edit the Makefile.in file

replace from
CCOPT    = @V_CCOPT@ 

to

CCOPT    = @V_CCOPT@ -g

Next, replace the following from

DEFINE    = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test

to

DEFINE    = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DNDEBUG -DDEBUG 

Step 2: Save the file and do the following

$ ./configure

$ make clean

$ make distclean

$ ./configure

$ make

$ sudo make install

Now debugging to your ns-2 is ready. If you have encountered the Segmentation fault bug while running any tcl file, then do the following

Step 3: goto the tcl folder and do the following

$ gdb ns

(gdb) run your_tcl_filename.tcl

TCL file runs with the above command and it stops at bug point showing the statement where the bug has present. 

 
 
 

Tuesday, October 20, 2015

Using AVRORA simulator with TinyOS

AVRORA is a popular AVR Simulation and analysis framework for simulating the programs developed for AVR micro controllers. This tool can be used to simulate the programs written in TinyOS environment with little modifications. This post explains how TinyOS programs can be simulated using AVRORA.

This was tested in UBUNTU 12.04 OS environment.

Save the files downloaded from the following steps to a folder. In my system it is
/home/prv/avrora

Step 1: Download the converter from http://compilers.cs.ucla.edu/avrora/jars/avrora-beta-1.7.091.jar

Step 2: Rename the downloaded file as avrora.jar

Step 3: Download the converter.sh file from https://drive.google.com/file/d/0B8u5Jm1ly3NYNm41UEU0ZjdzYkU/view?usp=sharing

Step 4: Open the bashrc file
            gedit ~./bashrc
            and add the following lines at the end of the file.

alias avrora='java -jar /home/prv/avrora/avrora.jar'
alias convert-avrora='sh /home/prv/avrora/converter.sh'

Step 5: Save the file and close all the consoles opened.

Now, to test the AVRORA setup, run any application programmed in TinyOS.

For example, go to the folder Blinks available in /opt/tinyos-2.1.2/tos/apps.

compile the program

make mica2

it creates a build folder in which you will find micaz2 sub folder. Move to it.
In micaz2 folder there exists a main.exe file. This file is the main file consists of  application and TinyOS environment.

convert it into avrora environment as follows

convert-avrora main.exe blink.od

Now, run the avrora

avrora -seconds=5.0 -platform=mica2 blink.od

This command runs the blink application for one sensor node. To do the same for multiple nodes use the following command

avrora -simulation=sensor-network -seconds=10.0 -nodecount=2 blink.od

The screen shot after running the command

avrora -simulation=sensor-network -seconds=2.0 -nodecount=1 blink.od

is as follows



References

[1] http://compilers.cs.ucla.edu/avrora/
[2] http://mythicalcomputer.blogspot.in


Saturday, September 12, 2015

Installing TinyOS in UBUNTU 12.04 LTS

This installation procedure was tested on UBUNTU 12.04 LTS

Requirements: An UNBTU 12.04 LTS 32-bit system with Internet connectivity

step 1: open command line and type

    sudo gedit /etc/apt/sources.list

step 2: add the following repository at the end of the list

    deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main

step 3: save the file and run

    sudo apt-get update

step 4: Install nesC compiler which is required for TinyOS programming. This step also install java environment.

    sudo apt-get install nesc

step 5: Install the cross tools (tool-chain), Debian MSP430 and Debian AVR using following

    sudo apt-get install msp430-tinyos avr-binutils-tinyos msp430-gcc-tinyos msp430-libc-tinyos

step 6: Install g++ compiler. (This step can be ignored if it is already installed on the system). Also install python development.


    sudo apt-get install g++

    sudo apt-get install  python-dev -y


step 7: Install automake tool

    sudo apt-get install automake

Step 8: Install tinyos operating system

    sudo apt-get install tinyos

    This command prompts for existing tinyos versions for download. Select a suitable version and download as shown below.

    sudo apt-get install tinyos-2.1.2
   
step 9: change the perimissions of tinyos installation folder

    sudo chmod -R 777 /opt/tinyos-2.1.2

step 10: create a file called tinyos.sh in /opt/tinyos-2.1.2

    sudo gedit /opt/tinyos-2.1.2/tinyos.sh

step 10: copy and past the following content in the tinyos.sh file

    # Here we setup the environment
    # variables needed by the tinyos
    # make system

    export TOSROOT=/opt/tinyos-2.1.2
    export TOSDIR=$TOSROOT/tos
    export MAKERULES=$TOSROOT/support/make/Makerules
    export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
    export PYTHONPATH=.:$TOSROOT/support/sdk/python:$PYTHONPATH
    export PATH=$TOSROOT/support/sdk/c:$PATH

    echo "setting up TinyOS on source path $TOSROOT"

step 11: open bashrc file

    sudo gedit ~/.bashrc

    and add the following content at the end of the file

    #Tinyos path
    source /opt/tinyos-2.1.2/tinyos.sh

step 12: close the terminal and reopen to see the tinyos path estalishment

   

Wednesday, March 4, 2015

Installing Lyx in UBUNTU

Lyx is a latex editor (WYSIWYM) which helps researchers and writers to edit their content. Latest version of the Lyx can be obtained as follows

$ sudo add-apt-repository ppa:lyx-devel/release
$ sudo apt-get update
$ sudo apt-get install lyx

Installing Remastersys in UBUNTU

Remastersys is a back up and recovery software that helps you to create custom/ boot able live CD/DVD of the entire UBUNTU distribution. This software can be installed as follows


$ sudo add-apt-repository "deb http://www.geekconnection.org/remastersys/repository karmic/"


$ sudo apt-get update
$ sudo apt-get install remastersys

Installing ns-2.35 in UBUNTU operating system

Step 1: open the command prompt Ctrl + Alt + T
Step 2: In the command prompt do the following
  $ sudo apt-get update
  $ sudo apt-get upgrade (this is optional)
  $  sudo apt-get install build-essential autoconf automake tcl8.5-dev tk8.5-dev perl xgraph libxt-dev  
   libx11-dev libxmu-dev    
Step 3: Download the ns allinone tar file to home folder (ex. home/prv/)
$ tar -xvzf /home/prv/Documents/ns-allinone-2.35.tar.gz
$ cd ns-allinone-2.35
prv@prv:~ns-allinone-2.35$  ./install
Step 4:  Perform the path settings
# LD_LIBRARY_PATH
OTCL_LIB=/home/prv/ns-allinone-2.35/otcl-1.14/
NS2_LIB=/home/prv/ns-allinone-2.35/lib/
USR_Local_LIB=/usr/local/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$USR_Local_LIB

# TCL_LIBRARY
TCL_LIB=/home/prv/ns-allinone-2.35/tcl8.5.10/library/
USR_LIB=/usr/lib/
export TCL_LIBRARY=$TCL_LIBRARY:$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/prv/ns-allinone-2.35/xgraph-12.2/:/home/prv/ns-allinone-2.35/bin/:/home/prv/ns-allinone-2.35/tcl8.5.10/unix/:/home/prv/ns-allinone-2.35/tk8.5.10/unix/
NS=/home/prv/ns-allinone-2.35/ns-2.35/
NAM=/home/prv/ns-allinone-2.35/nam-1.15/
export PATH=$PATH:$XGRAPH:$NS:$NAM


Tuesday, February 17, 2015

Simulating GAF in NS-2

Geographic Adaptive Fidelity (GAF) is a protocol that can be used along with other protocols such as AODV, DSR etc. 

Here I am providing steps to run GAF

One can look into the ../ns-2.35/tcl/test folder for already existing TCL files

GAF can run as follows

$ ns test-all-wireless-lan-gaf.tcl gaf

However this way doing can take very long time to complete the simulation. You may open the file and can change the simulation time to a small time (by default 800 seconds is the sim time). 

The simulation traces will be available in temp.rands file.

You can also add nam trace file as follows

set namtrace      [open $opt(tr).nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

in TestSuite instproc init {} function

Once the simulation is completed, you can view the simulation through nam by typing the command as follows

nam temp.rands.nam

Thursday, February 13, 2014

Fuzzylite-4.0 installation on Ubuntu 12.04

MATLAB Fuzzy Logic Tool Box is a popular tool box for designing and implementing fuzzy logic based applications or algorithms. This tool box generates a fis file to include in the Matlab programming. However, a developer working with other than Matlab tool need to face grate difficulty in porting such
.fis file into their applications. To mitigate this problem Open Source community had worked towards developing a flexible framework which is independent of other shared libraries. An out comes of this initiative is fuzzylite (www.fuzzylite.com). To use this, a user or developer need not require to install standard tools or packages. In this article, I will explain how to  install the fuzzylite framework on Ubuntu operating system.

Fuzzylite is a open source library thatsupport fuzzy logic based design and implementation of algorithms. Thisframework is suitable for application developers in C++ and Java. Since it is open source, fuzzylite can be installed on most commonly used operating environments such as Linux, Windows, Mac and Android without any difficulty. Fuzzylite covers all major features used by developers in their applications. In addition, It supports a GUI (Graphical User Interface) (called qtfuzzylite) version that enable the user to create fuzzy rules graphically and export them into fuzzy lite language (.fll). A user can import the rules from fuzzy interface system (.fis) (of MATLAB) and fuzzy control language (.fcl) (of Octave). Moreover, several examples are also placed along with source package for the purpose of understanding. 




Now I explain the installation of fuzzylite on UBUNTU 12.04LTS



To install fuzzylite user need to install two packages – cmake and qt4 ( a cross platform application framework)




step1: sudo gedit /etc/apt/sources.list


step2: add the source

deb http://cz.archive.ubuntu.com/ubuntu trusty main

step3: sudo apt-get update

step 4: sudo apt-get install cmake qt4-default

step 5: download source code of fuzzylite from
 http://www.fuzzylite.com/downloads/



step 6: extract the tar file – tar xvf fuzzylite-4.0.1-source.zip



step 7: cd fuzzylite-4.0



#fuzzylite-4.0:~$ cd fuzzylite



#fuzzylite-4.0/fuzzylite:~$ cmake .  
  


( cmake – space – and a dot
and press enter)



#fuzzylite-4.0/fuzzylite:~$ make



#fuzzylite-4.0/fuzzylite:~$ sudo make
install



#fuzzylite-4.0/fuzzylite:~$ cd ..



#fuzzylite-4.0:~$ cd qtfuzzylite

#fuzzylite-4.0/qtfuzzylite:~$ cmake .



#fuzzylite-4.0/qtfuzzylite:~$
make



#fuzzylite-4.0/qtfuzzylite:~$
sudo make install



#fuzzylite-4.0/qtfuzzylite:~$
gedit ~/.bashrc



at the end of the
file




export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH: /fuzzylite/bin



example,



export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH::/home/prv/fuzzylite-4.0/fuzzylite/bin



save the file and
relogin/resart your system



After
relogin/restart open command prompt and type



$ qtfuzzylite



and use the
fuzzylite GUI tool.








Friday, July 5, 2013

Overhearing Packets (or) Entering a node into Promiscuous Mode in NS-2

This post is an extension to the broadcast example. In this, I am going to explain how a node can be entered into promiscuous mode so that it can overhear the packets sent, forward or received by neighboring nodes. It all require a class called Tap which is available in mac.h header file. Tap class offer a function called void tap(const Packet *p).  To define the tap function, we need to inherit the class Tap. Usage of tap function and Tap class has shown with the broadcast example.

/* This Protocol perform Simple broad cast and overhear the packets of neighboring nodes
 * sbcast.h
 *
 *  Created on: 19-May-2013
 *      Author: P. RAGHU VAMSI
 *      @ JAYPEE INSTITUTE OF INFORMATION TECHNOLOGY UNIVERSITY, INDIA
 *      @ prvonline@yahoo.co.in
 */

#ifndef SBCAST_H_
#define SBCAST_H_

// Include mac header to overhear
#include

#define CURRENT_TIME Scheduler::instance().clock()

#define MAX_NODES 20

#define JITTER (Random::uniform()*0.5)
#define CURRENT_TIME Scheduler::instance().clock()
#define HDR_BEACON(p) (hdr_beacon *) hdr_beacon::access(p)

struct hdr_beacon {
nsaddr_t addr_;
u_int8_t seq_num_;
inline nsaddr_t & addr() { return addr_; }
inline u_int8_t & seq_num() { return seq_num_; }
static int offset_;
inline static int & offset() { return offset_; }
inline static hdr_beacon * access(const Packet *p) {
return (hdr_beacon*) p->access(offset_);
}
};


class SBAgent;

class BcastTimer : public TimerHandler {
protected:
SBAgent *agent_;
virtual void expire(Event *e);
public:
BcastTimer(SBAgent *agent):TimerHandler(),agent_(agent) { }
};





class SBAgent : public Tap,public Agent {
protected:
friend class BcastTimer;
private:
BcastTimer btimer_;
PortClassifier *dmux_;
Trace *logtarget_;
nsaddr_t my_addr_;
int seq_num_;
int node_count;
// for obtaining the mac of the node
Mac *mac_;
public:
static int pkt_received[MAX_NODES];
static int pkt_send[MAX_NODES];
static int no_of_nodes;
static int color_count;

SBAgent();
int command(int,const char*const*);
void recv(Packet *,Handler *);
void sendBeacon();
void resetBcastTimer();
inline nsaddr_t & my_addr() { return my_addr_;}
void changeColor();
//Tap to overhear the packets (or) to enter into promiscous mode
void tap(const Packet *);
};

#endif /* SBCAST_H_ */

sbcast.cc

/*
 * sbcast.cc
 * This Protocol perform Simple broad cast
 *  Created on: 19-May-2013
 *      Author: P. RAGHU VAMSI
 *      @ JAYPEE INSTITUTE OF INFORMATION TECHNOLOGY UNIVERSITY, INDIA
 *      @ prvonline@yahoo.co.in
 */

#include "sbcast.h"
#include "mobilenode.h"
// TCL Hooks

int hdr_beacon::offset_;

static class SBcastHeaderClass : public PacketHeaderClass {
public:
SBcastHeaderClass():PacketHeaderClass("PacketHeader/SB",sizeof(hdr_beacon)) {
bind_offset(&hdr_beacon::offset_);
}
}class_hdr_sbcast;

static class SBcastClass : public TclClass {
public:
SBcastClass():TclClass("Agent/SB") { }
TclObject *create(int argc,const char*const* argv) {
return (new SBAgent());
}
virtual void bind();   // for access of static variables
virtual int method(int argc, const char*const* argv);
}class_sbagent;

int SBAgent::pkt_received[MAX_NODES];
int SBAgent::pkt_send[MAX_NODES];
int SBAgent::no_of_nodes;
int SBAgent::color_count;

void SBcastClass::bind() {
TclClass::bind();
add_method("print-stats");
}

int SBcastClass::method(int ac, const char*const* av) {
    int argc = ac - 2;
    const char*const* argv = av + 2;
    if (argc == 2) {
    if(strcmp(argv[1],"print-stats")==0){

for(int i=0;
i          printf("Packets Sent By Node %d : %d \n",i,SBAgent::pkt_send[i]);
          printf("Packets Received By Node %d : %d \n",i,SBAgent::pkt_received[i]);
 

            }
    }
    return TCL_OK;
    }
}


SBAgent::SBAgent():Agent(PT_SB),btimer_(this) {
bind("node_count",&node_count);
no_of_nodes = node_count;
}

int SBAgent::command(int argc,const char*const* argv) {
if(argc==2){
if(strcmp(argv[1],"start")==0){
my_addr_ = addr();
return TCL_OK;
}
if(strcmp(argv[1],"base-station")==0){
btimer_.resched((double)0.1);
my_addr_ = addr();
return TCL_OK;
}
}else if (argc == 3) {
// Obtains corresponding dmux to carry packets to upper layers
if (strcmp(argv[1], "port-dmux") == 0) {
dmux_ = (PortClassifier*)TclObject::lookup(argv[2]);
if (dmux_ == 0) {
fprintf(stderr, "%s: %s lookup of %s failed\n",
__FILE__,
argv[1],
argv[2]);
return TCL_ERROR;
}
return TCL_OK;
}

if (strcmp(argv[1], "log-target") == 0 ||
strcmp(argv[1], "tracetarget") == 0) {
logtarget_ = (Trace*)TclObject::lookup(argv[2]);
if (logtarget_ == 0)
return TCL_ERROR;
return TCL_OK;
}
/* Add a command to install tap on a mac layer of a node */
if (strcmp(argv[1], "install-tap") == 0) {
  mac_ = (Mac*) TclObject::lookup(argv[2]);
  mac_->installTap(this);
  return TCL_OK;
   }
}
return (Agent::command(argc,argv));
}

void BcastTimer::expire(Event *e) {
agent_->sendBeacon();
agent_->changeColor();
agent_->resetBcastTimer();
}

void SBAgent::resetBcastTimer() {
btimer_.resched((double)0.5);

}

void SBAgent::sendBeacon() {
Packet* p = allocpkt();
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_ip* ih = HDR_IP(p);
struct hdr_beacon * ph = HDR_BEACON(p);

ph->addr() = my_addr();
ph->seq_num() = seq_num_++;

ch->ptype() = PT_SB;
ch->direction() = hdr_cmn::DOWN;
ch->size() = IP_HDR_LEN;
ch->error() = 0;
ch->next_hop() = IP_BROADCAST;
ch->addr_type() = NS_AF_INET;

ih->saddr() = my_addr();
ih->daddr() = IP_BROADCAST;
ih->sport() = RT_PORT;
ih->dport() = RT_PORT;
ih->ttl() = IP_DEF_TTL;

pkt_send[my_addr()]++;
send(p,0);
}

void SBAgent::recv(Packet *p,Handler *h) {

struct hdr_cmn *ch = HDR_CMN(p);
if(ch->ptype() == PT_SB) {
pkt_received[my_addr()]++;
}

}

void SBAgent::changeColor() {
char *color[5] = {"blue","brown","red","yellow","purple"};
Tcl& tcl = Tcl::instance();
tcl.evalf("%s set node_", name());
const char *node_object = tcl.result();
 Tcl::instance().evalf("$ns at %f \"%s color %s\"",CURRENT_TIME,
node_object,color[color_count]);

 if(color_count >= 4) color_count=0;
  else color_count++;
}

/* Define the tap function to overhear the packets (or) to enter
 * into promiscuos mode.
 */
void SBAgent::tap(const Packet *p) {
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_beacon * ph = HDR_BEACON(p);

printf("\n Node: %d IN TAP: from %d Seq Number: %d Packet Type: %d",my_addr(),ph->addr_,ph->seq_num_,ch->ptype());


}


bcast.tcl

#===================================
#     Simulation parameters setup
#===================================
set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy            ;# network interface type
set val(mac)    Mac/802_11                 ;# MAC type
set val(ifq)    Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)     LL                         ;# link layer type
set val(ant)    Antenna/OmniAntenna        ;# antenna model
set val(ifqlen) 50                         ;# max packet in ifq
set val(nn)     5                         ;# number of mobilenodes
set val(rp)     SB                      ;# routing protocol
set val(ie)     100     ; # initial energy of a node
set val(em)     EnergyModel     ; # Energy model 
set val(x)      100                      ;# X dimension of topography
set val(y)      100                      ;# Y dimension of topography
set val(stop)   50 

Agent/SB set node_count $val(nn)

#===================================
#  Attaching selected headers    
#===================================

remove-all-packet-headers
add-packet-header Mac LL IP ARP LL SB

#===================================
#        Initialization        
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)


#Open the NS trace file
set tracefile [open bcast.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open bcast.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)

set chan [new $val(chan)];#Create wireless channel

Mac/802_11 set dataRate 512Kbps

#===================================
#     Node parameter setup
#===================================
$ns node-config -adhocRouting  $val(rp) \
                -llType        $val(ll) \
                -macType       $val(mac) \
                -ifqType       $val(ifq) \
                -ifqLen        $val(ifqlen) \
                -antType       $val(ant) \
                -propType      $val(prop) \
                -phyType       $val(netif) \
                -channel       $chan \
                -topoInstance  $topo \
                -agentTrace    ON \
                -routerTrace   ON \
                -macTrace      ON \
                -movementTrace OFF \
-energyModel   $val(em) \
-initialEnergy  $val(ie) \
-rxPower  35.25e-23 \
-txPower 31.21e-23 \
-idlePower 712e-6 \
-sleepPower 144e-9 

#===================================
#        Nodes Definition        
#===================================

for {set i 0} {$i < $val(nn)} {incr i} {
 set node_($i) [$ns node] 
 $node_($i) color blue
}

for {set i 0} {$i < $val(nn)} {incr i} {
 set u_($i) [new Agent/SB]
 $ns attach-agent $node_($i) $u_($i)
}


$node_(0) set X_ 0.0
$node_(0) set Y_ 0.0
$node_(0) set Z_ 0
$node_(1) set X_ 40.0
$node_(1) set Y_ 0.0
$node_(1) set Z_ 0
$node_(2) set X_ 25.0
$node_(2) set Y_ 0.0
$node_(2) set Z_ 0
$node_(3) set X_ 0.0
$node_(3) set Y_ 75.0
$node_(3) set Z_ 0
$node_(4) set X_ 60.0
$node_(4) set Y_ 20.0
$node_(4) set Z_ 0



#$ns at 1.0 "$node_(0) setdest 99.0 99.0 15.0"
for {set i 0} {$i < $val(nn)} {incr i} {
$ns at 0.0 "[$node_($i) set ragent_] base-station"
}


for {set i 0} {$i < $val(nn)} {incr i} {
 $ns initial_node_pos $node_($i) 10  
}

for {set i 0} {$i < $val(nn)} {incr i} {
[$node_($i) set ragent_] install-tap [$node_($i) set mac_(0)]
}


proc finish {} {
    global ns tracefile namfile 
    $ns flush-trace
    close $tracefile
    close $namfile
    Agent/SB print-stats
    exec nam bcast.nam &
    exit 0
}

#===================================
#  Reset the nodes   
#===================================

for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "$node_($i) reset"
}

#===================================
#  Simulation start up  
#===================================

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
puts "before sim run"
$ns run