C++ 如何寄回包裹?
我正在编写一个新的代理,它可以在一个主机上使用,该主机至少连接四个节点。 带有流量生成器的主机将在延迟后向客户端发送数据包 它将再次发送到主机。信息计算将在主机中进行。 然而,在我的test.tcl中,只有两个节点的数据包在客户机中接收到,似乎没有 发送回主机 谁能帮我一下吗? 发送功能是否有明显错误? 我应该分配ip头、目标或任何变量来发回我的数据包吗 AgentCPU.hC++ 如何寄回包裹?,c++,ns2,C++,Ns2,我正在编写一个新的代理,它可以在一个主机上使用,该主机至少连接四个节点。 带有流量生成器的主机将在延迟后向客户端发送数据包 它将再次发送到主机。信息计算将在主机中进行。 然而,在我的test.tcl中,只有两个节点的数据包在客户机中接收到,似乎没有 发送回主机 谁能帮我一下吗? 发送功能是否有明显错误? 我应该分配ip头、目标或任何变量来发回我的数据包吗 AgentCPU.h #ifndef ns_cpu_h #define ns_cpu_h #include <tclcl.h>
#ifndef ns_cpu_h
#define ns_cpu_h
#include <tclcl.h>
#include "agent.h"
#include "config.h"
#include "packet.h"
#include "trafgen.h"
#define SAMPLERATE 8000
struct hdr_task {
int total_time;
int size_;
int number;
int& size() { return size_;}
static int offset_;
inline static int& offset() { return offset_; }
inline static hdr_task* access (const Packet* p) {
return (hdr_task*) p->access(offset_);
}
};
class AgentCPU : public Agent {
public:
AgentCPU();
virtual void recv(Packet *, Handler *);
virtual void sendmsg(int nbytes, const char *flags = 0);
private:
double busy_time_;
float execute_time_;
float execute_time_exp;
double record_packet_Time_;
int npkts_;
};
#endif
我试图修改ip头中的saddr和daddr字段
当我跟踪recv数据包时,有两个字段,值是0和1
我认为它们代表了两个节点
所以我交换这两个值,这样src地址和dest地址就会交换
数据包将被发送回主机
但是它会导致Seg故障。我已经解决了这个问题 我为收到的数据包添加了ip头
hdr_ip* ip=hdr_ip::access(pkt);
ip.daddr()=1; // this int represent the node in your tcl script
然而,我还有一个问题
当使用我的tcl脚本时,它将崩溃
使用valgrind后,该程序可以帮助您检测内存泄漏
我知道这个问题有多愚蠢
我想是跟踪格式导致了这个错误
例如,我没有为我的新数据包类型提供正确的Trace::格式
我没有像这样在我的tcl脚本中注释跟踪文件代码
set nf [open out.nam w]
$nf nametrace-all $nf
...
...
当我对这些代码进行注释时,包括程序finish
万事如意!数据包可以发送到指定的节点,并且没有段故障
希望这能帮助像我一样有同样问题的人可能重复mm。。。这是我的最后一个问题,我有了新的bug。。
set nf [open out.nam w]
$nf nametrace-all $nf
...
...