教大家拷贝ns2 已经有的模块文件,但改成别的名字,这样就可以轻松且很明确知道该如何增加模块。
(1) 打开 cygwin 的命令窗口,把路径切换到queue 的目录下。
cd ns-allinone-2.27/ns-2.27/queue
(2) 拷贝 drop-tail.[cc, h]到myfifo.[cc.h]。
cp drop-tail.cc myfifo.cc
cp drop-tail.h myfifo.h
(3) 使用文字编辑软件去修改 myfifo.h 和myfifo.cc。(因为我们的环境是在windows 下,所以建议可以使用ultra-edit 来修改。
a. 先修改 myfifo.h,使用取代的功能把所有DropTail 改成myfifo,另外,把drop_tail改成myfifo。
#ifndef ns_myfifo_h
#define ns_myfifo_h
#include <string.h>
#include "queue.h"
#include "config.h"
/*
* A bounded, drop-tail queue
*/
class myfifo : public Queue {
public:
myfifo() {
q_ = new PacketQueue;
pq_ = q_;
bind_bool("drop_front_", &drop_front_);
bind_bool("summarystats_", &summarystats);
bind_bool("queue_in_bytes_", &qib_); // boolean: q in bytes?
bind("mean_pktsize_", &mean_pktsize_);
// _RENAMED("drop-front_", "drop_front_");
}
~myfifo() {
delete q_;
}
protected:
void reset();
int command(int argc, const char*const* argv);
void enque(Packet*);
Packet* deque();
void shrink_queue(); // To shrink queue and drop excessive packets.
Packet