[Develope]/NetworkSimulator2(NS2)

ns2-tutorial + necessary change

하늘을닮은호수M 2005. 12. 5. 23:22
반응형

새로운 packet type을 정의하여 추가할 때.

물론 나름의 알고리즘은 c++형태로 구현이 되어 있다고 가정하고..

다음과 같은 것을 고려해야 한다.

이는 첨부한 파일에서 발췌한 것^^

VII.3. Necessary changes

You will have to change some things in some of the ns source files if you want to add a new agent, especially if it uses a new packet format. I suggest you always mark your changes with comments, use #ifdef, etc., so you can easily remove your changes or port them to new ns releases.

We're going to need a new packet type for the ping agent, so the first step is to edit the file 'packet.h'. There you can find the definitions for the packet protocol IDs (i.e. PT_TCP, PT_TELNET, etc.). Add a new definition for PT_PING there. In my edited version of packet.h, the last few lines of enum packet_t {} looks like the following code (it might look a bit different in earlier/later releases).

enum packet_t {
 PT_TCP,
 PT_UDP,
 ......
 // insert new packet types here
 PT_TFRC,
 PT_TFRC_ACK,
 PT_PING, // packet protocol ID for our ping-agent
 PT_NTYPE // This MUST be the LAST one
};

You also have to edit the p_info() in the same file to include "Ping".

class p_info {
public:
 p_info() {
 name_[PT_TCP]= "tcp";
 name_[PT_UDP]= "udp";
 ...........
  name_[PT_TFRC]= "tcpFriend";
 name_[PT_TFRC_ACK]= "tcpFriendCtl";
 name_[PT_PING]="Ping";
 name_[PT_NTYPE]= "undefined";
 }
 .....
 }

Remember that you have to do a 'make depend' before you do the 'make', otherwise these two files might not be recompiled.

The file 'tcl/lib/ns-default.tcl' has to be edited too. This is the file where all default values for the Tcl objects are defined. Insert the following line to set the default packet size for Agent/Ping.

Agent/Ping set packetSize_ 64

You also have to add an entry for the new ping packets in the file 'tcl/lib/ns-packet.tcl' in the list at the beginning of the file. It would look like the following piece of code.

 { SRMEXT off_srm_ext_}
 { Ping off_ping_ }} {
set cl PacketHeader/[lindex $pair 0]

The last change is a change that has to be applied to the 'Makefile'. You have to add the file 'ping.o' to the list of object files for ns. In my version the last lines of the edited list look like this:

sessionhelper.o delaymodel.o srm-ssm.o 
srm-topo.o 
ping.o 
$(LIB_DIR)int.Vec.o $(LIB_DIR)int.RVec.o 
$(LIB_DIR)dmalloc_support.o 
You should be able to recompile ns now simply by typing 'make' in the ns directory. If you are having any problems, please email ns-users
반응형

'[Develope] > NetworkSimulator2(NS2)' 카테고리의 다른 글

ns document  (0) 2006.04.28
NS by Example  (0) 2005.12.06
ns2 설치  (0) 2005.10.12