轉載自:http://sunreset.blogbus.com/logs/7633086.html
ns2的安裝過程非常簡單,只用下載相應的allinone壓縮包,然後直接解壓再./install就可以了。但由於gcc編譯器版本的問題,在
目前通用的linux上安裝低版本的ns2也成了一種麻煩。由於工作的需要,我要搭建一個ns2.1b9a的環境。最開始我以爲只要半天功夫就能搞定,卻
沒料到花了我三天的時間。。。
問題最終是解決了,現在才發現google的搜索引擎是如此強大,也要感謝網上很多人默默的將自己的經驗奉獻出來。我在這裏也將我的解決方案拿出來和大家共享。
環境:ubuntu6.10
目標:安裝ns2.1b9a
步驟:
1.安裝build-essential
sudo apt-get install build-essential
2.安裝libxmu-dev
sudo apt-get install libxmu-dev
3.安裝gcc-3.3,g++-3.3;直接使用ubuntu自帶的新立得就可以
4.設置環境變量
export CC=/usr/bin/gcc-3.3
export CCC=g++-3.3
export CXX=/usr/bin/g++-3.3
5.下載ns2.1b9a並解壓
ns2.1b9a下載地址:http://www.isi.edu/nsnam/dist/ns-allinone-2.1b9a-gcc32.tar.gz
tar xzvf ns-allinone-2.1b9a-gcc32.tar.gz
6.touch ns-allinone-2.1b9a/tcl8.3.2/generic/tclStubInit.c
7.安裝補丁ns21b9a-gcc33.patch(download)
cd ns-allinone-2.1b9a;patch -p0 < ../ns21b9a-gcc33.patch
8.開始安裝ns2
./install
9.配置ns2環境變量
vi /home/wl/.bash_profile
add following lines to the end
-------->
export NS_HOME=/home/wl/ns-allinone-2.1b9a
export PATH=$PATH:$NS_HOME/bin:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NS_HOME/otcl-1.0a8:$NS_HOME/lib:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix
export TCL_LIBRARY=$NS_HOME/tcl8.3.2/library/
--------<
source .bash_profile 使剛纔添加的環境變量生效
10.校驗
cd ns-2.1b9a; ./validate
至此ns2.1b9a安裝成功,但校驗沒有全部通過(test-all-red failed)
在解決問題的過程中也學到了一些東西,如patch文件的結構。Patch 文件中常見的@@ -45,7 +45,7
@@表示爲一個塊HUNK的開始,其中-45,7表示原來該塊從第45開始共7行,+45,7表示打過補丁之後從45行開始共7行。具體的可以參考:How to create and use a patch in Linux
-----------------------------------------------------------------------------
下面給出安裝過程中出現的錯誤,希望對於也正在爲安裝而煩惱的同胞有些幫助:)
Description-------->
./tclsh ./../tools/genStubs.tcl ./../generic /
./../generic/tcl.decls ./../generic/tclInt.decls
make: ./tclsh: Command not found
Solution-----------<
touch ../tcl8.3.2/generic/tclStubInit.c
reference<-------->
http://www.isi.edu/nsnam/ns/ns-problems.html
Description-------->
tclcl-mappings.h: In static member function `static int TclObjectHelper::dispatch_(void*, Tcl_Interp*, int, char**)':
tclcl-mappings.h:51: error: incomplete type `Tcl' used in nested name specifier
tclcl-mappings.h:52: error: invalid use of undefined type `struct Tcl'
tclcl-mappings.h:41: error: forward declaration of `struct Tcl'
tclcl-mappings.h:57: error: invalid use of undefined type `struct Tcl'
tclcl-mappings.h:41: error: forward declaration of `struct Tcl'
make: *** [Tcl.o] Error 1
tclcl-1.15 make failed! Exiting ...
Solution-----------<
--- tclcl-1.0b12/tclcl.h 2004-01-12 19:52:09.000000000 -0500
+++ tclcl-1.0b12/tclcl.h 2004-12-16 08:43:45.838930336 -0500
@@ -45,7 +45,7 @@
}
#include "tclcl-config.h"
-#include "tclcl-mappings.h"
+// #include "tclcl-mappings.h"
#include "tracedvar.h"
struct Tk_Window_;
@@ -157,6 +157,8 @@
Tcl_HashTable objs_;
};
+#include "tclcl-mappings.h"
+
class InstVar;
class TclObject {
reference<-------->
http://www.ececs.uc.edu/~cdmc/ucbt/src/ns227-gcc34.patch
http://blog.tianya.cn/blogger/post_show.asp?idWriter=0&Key=0&BlogID=78856&PostID=9333930
Description-------->
./mobile/god.h:88: error: extra qualification 'vector::' on member
'operator='
./mobile/god.h:93: error: extra qualification 'vector::' on member
'operator+='
./mobile/god.h:98: error: extra qualification 'vector::' on member
'operator=='
./mobile/god.h:101: error: extra qualification 'vector::' on member
'operator!='make: *** [src_rtg/sragent.o] Error 1
Solution-----------<
--- ns-2.1b9a/mobile/god.h 2005-10-19 21:45:22.000000000 -0700
+++ ns-2.1b9a/mobile/god.h 2006-05-02 19:33:57.000000000 -0700
@@ -85,20 +85,20 @@
return sqrt(X*X + Y*Y + Z*Z);
}
- inline void vector::operator=(const vector a) {
+ inline void operator=(const vector a) {
X = a.X;
Y = a.Y;
Z = a.Z;
}
- inline void vector::operator+=(const vector a) {
+ inline void operator+=(const vector a) {
X += a.X;
Y += a.Y;
Z += a.Z;
}
- inline int vector::operator==(const vector a) {
+ inline int operator==(const vector a) {
return (X == a.X && Y == a.Y && Z == a.Z);
}
- inline int vector::operator!=(const vector a) {
+ inline int operator!=(const vector a) {
return (X != a.X || Y != a.Y || Z != a.Z);
}
inline vector operator-(const vector a) {
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
queue/cbq.cc:112: error: ISO C++ forbids declaration of ‘CBQueue’ with no type
queue/cbq.cc:112: error: expected ‘;’ before ‘*’ token
queue/cbq.cc: In member function ‘virtual int CBQueue::insert_class(CBQClass*)’:
queue/cbq.cc:488: error: ‘class CBQClass’ has no member named ‘cbq_’
queue/cbq.cc: In constructor ‘CBQClass::CBQClass()’:
queue/cbq.cc:805: error: class ‘CBQClass’ does not have any field named ‘cbq_’
queue/cbq.cc: In member function ‘virtual void CBQClass::recv(Packet*, Handler*)’:
queue/cbq.cc:850: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc:856: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘void CBQClass::update(Packet*, double)’:
queue/cbq.cc:873: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘int CBQClass::desc_with_demand()’:
queue/cbq.cc:928: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘void CBQClass::newallot(double)’:
queue/cbq.cc:975: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘virtual int CBQClass::command(int, const char* const*)’:
queue/cbq.cc:1002: error: ‘cbq_’ was not declared in this scope
make: *** [queue/cbq.o] Error 1
Solution-----------<
--- ns-2.1b9a/queue/cbq.cc 2006-08-31 11:42:09.000000000 -0300
+++ ns-2.1b9a/queue/cbq.cc 2006-08-31 11:43:31.000000000 -0300
@@ -87,6 +87,8 @@
#define LEAF_LEVEL 1 /* level# for leaves */
#define POWEROFTWO 16
+class CBQueue;
+
class CBQClass : public Connector {
public:
friend class CBQueue;
reference<-------->
http://blog.tianya.cn/blogger/post_show.asp?idWriter=0&Key=0&BlogID=78856&PostID=9333930
http://larsis.inf.ufpr.br/maverson/
Description-------->
webcache/webtraf.cc: In member function ‘virtual int WebTrafPool::command(int, const char* const*)’:
webcache/webtraf.cc:415: error: ISO C++ forbids initialization in array new
make: *** [webcache/webtraf.o] Error 1
Solution-----------<
--- ns-2.1b9a/webcache/webtraf.cc 2006-08-31 11:48:37.000000000 -0300
+++ ns-2.1b9a/webcache/webtraf.cc 2006-08-31 11:50:54.000000000 -0300
@@ -362,10 +362,12 @@
return (TCL_OK);
} else if (strcmp(argv[1], "set-num-server") == 0) {
nServer_ = atoi(argv[2]);
- if (server_ != NULL)
- delete []server_;
- server_ = new WebServer[nServer_](this);
-
+ if (server_ != NULL)
+ free(server_);
+ server_ = (WebServer*)malloc(nServer_ * sizeof(WebServer));
+ for (int i = 0; i < nServer_; i++) {
+ server_[i] = WebServer(this);
+ }
return (TCL_OK);
} else if (strcmp(argv[1], "set-num-client") == 0) {
reference<-------->
http://www.ececs.uc.edu/~cdmc/ucbt/src/ns227-gcc34.patch
http://larsis.inf.ufpr.br/maverson/
Description-------->
./tora/tora_neighbor.h:72: error: ISO C++ forbids declaration of ‘toraAgent’ with no type
./tora/tora_neighbor.h:72: error: expected ‘;’ before ‘*’ token
make: *** [tora/tora.o] Error 1
Solution-----------<
--- ns-2.1b9a/tora/tora_neighbor.h 2006-08-31 11:42:09.000000000 -0300
+++ ns-2.1b9a/tora/tora_neighbor.h 2006-08-31 11:43:31.000000000 -0300
@@ -41,6 +41,8 @@
#ifndef __tora_neighbor_h__
#define __tora_neighbor_h__
+class toraAgent;
+
enum LinkStatus {
LINK_UP = 0x0001, // upstream
LINK_DN = 0x0002, // downstream
reference<-------->
http://blog.tianya.cn/blogger/post_show.asp?idWriter=0&Key=0&BlogID=78856&PostID=9333930
http://larsis.inf.ufpr.br/maverson/
Description-------->
diffusion/omni_mcast.cc:388: error: ‘OmniMcastXmitFailedCallback’ was not declared in this scope
make: *** [diffusion/omni_mcast.o] Error 1
Solution-----------<
--- ns-2.1b9a/diffusion/omni_mcast.cc 2005-10-19 21:45:22.000000000 -0700
+++ ns-2.1b9a/diffusion/omni_mcast.cc 2006-05-02 19:33:57.000000000 -0700
@@ -59,6 +59,8 @@
#include "dsr/path.h"
#include "god.h"
+void OmniMcastXmitFailedCallback(Packet *pkt, void *data);
+
static class OmniMcastClass : public TclClass {
public:
OmniMcastClass() : TclClass("Agent/OmniMcast") {}
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
dsr/dsragent.cc: In method `DSRAgent::DSRAgent()':
dsr/dsragent.cc:313: stray '/' in program
make: *** [dsr/dsragent.o] Error 1
Solution-----------<
--- ns-2.1b9a/dsr/dsragent.cc 2005-10-19 21:45:22.000000000 -0700
+++ ns-2.1b9a/dsr/dsragent.cc 2006-05-02 19:33:57.000000000 -0700
@@ -188,6 +188,9 @@
*/
+void XmitFlowFailureCallback(Packet *pkt, void *data);
+void XmitFailureCallback(Packet *pkt, void *data);
+
/*===========================================================================
SendBuf management and helpers
---------------------------------------------------------------------------*/
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
diffusion/diffusion.h:152: error: type specifier
omitted for parameter
diffusion/diffusion.h:152: error: syntax error before
numeric constant
diffusion/diffusion.cc:406: error: type specifier
omitted for parameter
diffusion/diffusion.cc:406: error: syntax error before
numeric constant
diffusion/diffusion.cc: In member function `void
DiffusionAgent::MACsend(...)':
diffusion/diffusion.cc:408: error: `pkt' undeclared
(first use this function)
diffusion/diffusion.cc:408: error: (Each undeclared
identifier is reported only
once for each function it appears in.)
diffusion/diffusion.cc:432: error: `delay' undeclared
(first use this function)
make: *** [diffusion/diffusion.o] Error 1
Solution-----------<
--- ns-2.1b9a/diffusion/diffusion.cc 2005-10-19 21:45:22.000000000 -0700
+++ ns-2.1b9a/diffusion/diffusion.cc 2006-05-02 19:33:57.000000000 -0700
@@ -58,6 +58,8 @@
#include "god.h"
#include "routing_table.h"
+void XmitFailedCallback(Packet *pkt, void *data);
+
char *MsgStr[]= {"", "INTEREST", "DATA", "DATA_READY", "DATA_REQUEST",
"POS_REINFORCE", "NEG_REINFORCE", "INHIBIT", "TX_FAILED",
"DATA_STOP" };
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
tcp/tcp-sack-rh.cc:68: error: extra qualification ‘SackRHTcpAgent::’ on member ‘newack’
make: *** [tcp/tcp-sack-rh.o] Error 1
Solution-----------<
--- ns-2.1b9a/tcp/tcp-sack-rh.cc 2005-10-19 21:45:25.000000000 -0700
+++ ns-2.1b9a/tcp/tcp-sack-rh.cc 2006-05-02 19:33:57.000000000 -0700
@@ -65,7 +65,7 @@
virtual void estadjust();
virtual void rhclear();
virtual void computefack();
- virtual void SackRHTcpAgent::newack(Packet* pkt);
+ virtual void newack(Packet* pkt);
protected:
int fack_; /* the FACK state variable */
int retran_data_; /* the number of retransmitted packets in the pipe */
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
linkstate/ls.h: In member function ‘void LsList<_Tp>::eraseAll()’:
linkstate/ls.h:89:
error: there are no arguments to ‘begin’ that depend on a template
parameter, so a declaration of ‘begin’ must be available
linkstate/ls.h:89:
error: (if you use ‘-fpermissive’, G++ will accept your code, but
allowing the use of an undeclared name is deprecated)
linkstate/ls.h:89:
error: there are no arguments to ‘end’ that depend on a template
parameter, so a declaration of ‘end’ must be available
linkstate/ls.h: In member function ‘void LsMap<Key, T>::eraseAll()’:
linkstate/ls.h:112:
error: there are no arguments to ‘begin’ that depend on a template
parameter, so a declaration of ‘begin’ must be available
linkstate/ls.h:112:
error: there are no arguments to ‘end’ that depend on a template
parameter, so a declaration of ‘end’ must be available
make: *** [linkstate/ls.o] Error 1
Solution-----------<
--- ns-2.1b9a/linkstate/ls.h 2006-08-31 12:08:42.000000000 -0300
+++ ns-2.1b9a/linkstate/ls.h 2006-08-31 12:10:16.000000000 -0300
@@ -86,7 +86,7 @@
LsList() : baseList() {}
LsList(const _Tp& x) : baseList(1, x) {}
void eraseAll() {
- baseList::erase(begin(), end());
+ baseList::erase(baseList::begin(), baseList::end());
}
LsList<_Tp>& operator= (const LsList<_Tp> & x) {
return (LsList<_Tp> &)baseList::operator= (x);
@@ -109,7 +109,7 @@
return ib.second ? ib.first : baseMap::end();
}
- void eraseAll() { erase(begin(), end()); }
+ void eraseAll() { baseMap::erase(baseMap::begin(), baseMap::end()); }
T* findPtr(Key key) {
iterator it = baseMap::find(key);
return (it == baseMap::end()) ? (T *)NULL : &((*it).second);
reference<-------->
http://larsis.inf.ufpr.br/maverson/
Description-------->
pgm/pgm-agent.cc:275: error: extra qualification ‘PgmAgent::’ on member ‘trace_event’
make: *** [pgm/pgm-agent.o] Error 1
Solution-----------<
--- ns-2.1b9a/pgm/pgm-agent.cc 2005-10-19 21:45:23.000000000 -0700
+++ ns-2.1b9a/pgm/pgm-agent.cc 2006-05-02 19:33:57.000000000 -0700
@@ -275,7 +275,7 @@
void print_stats();
- void PgmAgent::trace_event(char *evType, double evTime);
+ void trace_event(char *evType, double evTime);
#ifdef PGM_DEBUG
void display_packet(Packet *pkt);
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
pgm/pgm-receiver.cc:157: error: extra qualification ‘PgmAgent::’ on member ‘trace_event’
make: *** [pgm/pgm-receiver.o] Error 1
Solution-----------<
--- ns-2.1b9a/pgm/pgm-receiver.cc 2005-10-19 21:45:23.000000000 -0700
+++ ns-2.1b9a/pgm/pgm-receiver.cc 2006-05-02 19:33:57.000000000 -0700
@@ -154,7 +154,7 @@
void print_stats();
void display_packet(Packet *pkt); // For debugging.
- void PgmReceiver::trace_event(char *evType, double evTime);
+ void trace_event(char *evType, double evTime);
EventTrace * et_; //Trace Object for Custom Event Trace
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
pgm/pgm-sender.cc:161: error: extra qualification ‘PgmAgent::’ on member ‘trace_event’
make: *** [pgm/pgm-sender.o] Error 1
Solution-----------<
--- ns-2.1b9a/pgm/pgm-sender.cc 2005-10-19 21:45:23.000000000 -0700
+++ ns-2.1b9a/pgm/pgm-sender.cc 2006-05-02 19:33:57.000000000 -0700
@@ -157,7 +157,7 @@
void display_packet(Packet *pkt); // For debugging.
- void PgmSender::trace_event(char *evType, nsaddr_t daddr, double evTime);
+ void trace_event(char *evType, nsaddr_t daddr, double evTime);
EventTrace * et_; //Trace Object for custom Event Traces
reference<-------->
https://www.ececs.uc.edu/~cdmc/ucbt/src/ns2292-gcc410.patch
Description-------->
diffusion3/lib/nr/nr.hh:224: error: an explicit specialization must be preceded by ‘template <>’
diffusion3/lib/nr/nr.hh:239: error: an explicit specialization must be preceded by ‘template <>’
make: *** [diffusion3/lib/nr/nr.o] Error 1
Solution-----------<
--- ns-2.1b9a/diffusion3/lib/nr/nr.hh 2006-08-31 12:12:51.000000000 -0300
+++ ns-2.1b9a/diffusion3/lib/nr/nr.hh 2006-08-31 12:13:53.000000000 -0300
@@ -203,6 +203,7 @@
};
// string specialization
+template <>
class NRSimpleAttribute<char *>: public NRAttribute {
public:
NRSimpleAttribute(int key, int type, int op, char *val, int size = 0);
@@ -218,6 +218,7 @@
};
// blob specialization
+template <>
class NRSimpleAttribute<void *>: public NRAttribute {
public:
NRSimpleAttribute(int key, int type, int op, void *val, int size);
reference<-------->
http://larsis.inf.ufpr.br/maverson/
Description-------->
./diffusion3/diffusion/diffusion.hh:97: error: expected `)' before '*' token
Solution-----------<
--- ns-2.1b9a/diffusion3/diffusion/diffusion.hh 2006-08-31 11:48:37.000000000 -0300
+++ ns-2.1b9a/diffusion3/diffusion/diffusion.hh 2006-08-31 11:50:54.000000000 -0300
@@ -87,1 +87,2 @@
class HashEntry;
+class DiffRoutingAgent;
reference<-------->
http://blog.tianya.cn/blogger/post_show.asp?idWriter=0&Key=0&BlogID=78856&PostID=9333930
Description-------->
usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/stl_deque.h: In member function ‘void std::_Deque_base<_Tp,
_Alloc>::_M_initialize_map(size_t)’:
/usr/lib/gcc/i486-linux-gnu
/4.1.1/../../../../include/c++/4.1.1/bits/stl_deque.h:469: error:
expected unqualified-id before ‘(’ token
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/deque.tcc: In member function ‘void std::deque<_Tp,
_Alloc>::_M_reallocate_map(size_t, bool)’:
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4
.1.1/bits/deque.tcc:747: error: expected unqualified-id before ‘(’ token
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/stl_bvector.h: In member function ‘void
std::vector::_M_insert_range(std::_Bit_iterator, _ForwardIterator,
_ForwardIterator, std::forward_iterator_tag)’:
/usr/lib/gcc/i486-linux-gnu/4.1.1/../.
./../../include/c++/4.1.1/bits/stl_bvector.h:542: error: expected
unqualified-id before ‘(’ token
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/stl_bvector.h: In member function ‘void
std::vector::_M_fill_insert(std::_Bit_iterator, size_t, bool)’:
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4
.1.1/bits/stl_bvector.h:897: error: expected unqualified-id before ‘(’
token
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/vector.tcc: In member function ‘void std::vector<_Tp,
_Alloc>::_M_fill_insert(__gnu_cxx::__normal_iterator<_Tp,
_Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc>
>, size_t, const _Tp&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c
++/4.1.1/bits/vector.tcc:353: error: expected unqualified-id before ‘(’
token
/usr/lib/gcc/i486-linux-gnu/4.1.1/../../../../include/c++/4.1
.1/bits/vector.tcc: In member function ‘void std::vector<_Tp,
_Alloc>::_M_range_insert(__gnu_cxx::__normal_iterator<_Tp,
_Alloc>::_Tp_alloc_type:
Solution-----------<
install gcc-3.3 and g++-3.3
then set CC=/usr/bin/gcc-3.3;CXX=/usr/bin/g++-3.3