Friday, May 22, 2009

Tickling, (Did you hear Tickling) Ouch, Its Pickling :-)

Before using pickling, I had a tough time to have the entire data in a single file. Infact i had more than 1Mib in a file. Gedit used to get stuck and infact it lost syntax highlighting too. Python pickling helped me rule out the problem.

Note: For those who are wondering what is pickling, go through this
PICKLE

I had a file full of dictionary elements in it. It was more than 1Mib and I faced lots of problems. It used to take hours together to do a simple program. Then, python pickling helped me to dump the data in to a file in pickle format, more precisely, in a binary format. And, whenever we need, it can be loaded back to the file. If its in the form of dictionary, it will be loaded in the same manner and we can perform get or update functions on the same datastructure. Here is an example of how to convert the dictionary data in to corresponding pickle format.

Consider the following code:

#!/usr/bin/python
import string
import pickle
data={'1':'chandan','2':'nandan'}
file = open("test.py","w")
pickle.dump(data,file)
file.close()
file = open("test.py", "r")
data = pickle.load(file)
file.close()
print data['1']

After dumping the dictionary set into a file test.py, it will be in pickle format in that file. It looks like this
(dp0
S'1'
p1
S'chandan'
)

/* The above pickle format will be in binary. Here i have used a small dictionary set. If we have a large dictionary set, then it is feasible. You can get ur hands dirt using this on your own*/

    * Coming back to the 1Mib file i was mentioning, I converted the entire dictionary set which I had in 1Mib file into pickle format by using the above stated method, dumping it into a file. Then I deleted the entire dictionary set in the 1Mib file. So, that file size reduced to less than 200Kib.
    * Then, I loaded the pickled file to the 200Kib file, which still remains 200Kib itself. The loaded pickled format will be in dictionary format.
    * Then, I used the get, update operations and thus the overloading of gedit is ruled out
    * I have attached few files which might give you an idea of what of I discussed above

How to install NS2 in intrepid ibex or fedora 8

Download the ns2-allinone package from here This is version 2.31. You can download 2.30-33 versions. The steps are same for everything. It will be in compressed form. Extract them to a specific directory. Say, /home/chandan

How to install NS2 in intrepid ibex or fedora 8

Download the ns2-allinone package from here This is ns-allinone2.31 version. You can download 2.30-33 versions. The steps are same for everything. It will be in compressed form. Extract them to a specific directory. Say, /home/chandan

Follow the below mentioned steps.
sudo apt-get install autoconf automake libxmu-dev xorg
cd ns-2.30
./install

It will configure all the files needed to execute the tcl scripts. It will take ten minutes. Dont interrupt the terminal in between. It will be linked with otcl and c++ libraries. By default ns2 supports, aodv, dsdv, dsr and tora protocols. zrp protocol is still under research.

Once its installed, you will get series of instructions at the terminal itself. Follow those instructions carefully.

If you cant follow that, do this.

cd /etc
sudo gedit ~/.bashrc (Ubuntu 8.10)
or
gedit ~/.bashrc (Fedora 8)

Copy the following things and paste there. Replace /home/chandan with your installed path. For example, if its /usr/local, replace /home/chandan with /usr/local.

# LD_LIBRARY_PATH

OTCL_LIB=/home/chandan/ns-allinone-2.30/otcl-1.12

NS2_LIB=/home/chandan/ns-allinone-2.30/lib

X11_LIB=/usr/X11R6/lib

USR_LOCAL_LIB=/home/chandan/lib

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY

TCL_LIB=/home/chandan/ns-allinone-2.30/tcl8.4.14/library

USR_LIB=/usr/lib

export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH

XGRAPH=/home/chandan/ns-allinone-2.30/bin:/home/chandan/ns-allinone-2.30/tcl8.4.13/unix:/home/chandan/ns-allinone-2.30/tk8.4.13/unix

NS=/home/chandan/ns-allinone-2.30/ns-2.30/

NAM=/home/chandan/ns-allinone-2.30/nam-1.12/

PATH=$PATH:$XGRAPH:$NS:$NAM

Save and close the file.
Now, type this at the terminal

source ~/.bashrc

Then, type this command at the terminal.

$ns
%
You will get a "%" prompt. If not follow the above steps carefully and you can have simulation working on your intrepid ibex or Fedora 8.

NOTE: In case if u get error message in ubuntu, make sure you have not installed "host" package. If its installed, remove it from synaptic package manager.