[SOLVED] NS2: How receive CBR packets at my own agent and duplicate them for new destination??
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
NS2: How receive CBR packets at my own agent and duplicate them for new destination??
Hi
I created a new agent called SBC, and attach it to a node at the middle of CBR-source and sink. I want to receive every CBR packets in my own agent and after duplicating it for a new destination, forward the original message to it's destination.
So in my agent constructor definition, I used from following code:
but It doesn't work and doesn't receive any packet. I tested "PT_UDP" and "PT_RTP" as my agent packet type, too. what I must to do. Please help me. I have so little time and it'sso urgent for me
//<fahimeh Akbari>
#include <iostream>
#include "fa_SBC.h"
#include "address.h"
#include "sip-proxy.h"
#include "SBC_Pkt.h"
int hdr_sbc_pkt::offset_;
static class SbcHeaderClass : public PacketHeaderClass {
public:
SbcHeaderClass() : PacketHeaderClass("PacketHeader/SBC",sizeof(hdr_sbc_pkt)) {
bind_offset(&hdr_sbc_pkt::offset_); }
} class_rtProtoSbc_hdr;
static class SBC2Class : public TclClass {
public:
SBC2Class() : TclClass("Agent/fa_SBC") {}
TclObject* create(int argc, const char*const* argv) {
return (new SBC2(argv[4],argv[5],argv[6]/*,argv[7]*/));
}
} class_sipSBC;
SBC2::SBC2(const char* CBRsource,const char* CBRdest_main,const char* CBRdest_dup /*,const char* nextSBC*/) : Agent(PT_CBR) {
Sender_= atoi(const_cast<char *>(CBRsource));
Receiver1_= atoi(const_cast<char *>(CBRdest_main));
Receiver2_= atoi(const_cast<char *>(CBRdest_dup));
dup_flag_=0;
puts("SBC2::SBC2 created successfully\n");
}
int SBC2::command(int argc, const char*const* argv) {
if (argc == 2) {
if (strcasecmp(argv[1], "start-duplication") == 0) {
duplicate(1);
return TCL_OK;
}
if (strcasecmp(argv[1], "stop-duplication") == 0) {
duplicate(0);
return TCL_OK;
}
}
else if (argc == 3) {
if(strcmp(argv[1], "target-node1") == 0) {
target1_= (NsObject*) TclObject::lookup(argv[2]);
if (!target1_){
puts("Scheduler(target1): attempt to schedule an event with a NULL handler.");
puts("COMMAND !!!! \n");
return TCL_ERROR;
}
return TCL_OK;
}
if(strcmp(argv[1], "target-node2") == 0) {
target2_= (NsObject*) TclObject::lookup(argv[2]);
if (!target2_){
puts("Scheduler(target1): attempt to schedule an event with a NULL handler.");
puts("COMMAND !!!! \n");
return TCL_ERROR;
}
return TCL_OK;
}
}
// Pass the command to the base class
return Agent::command(argc, argv);
}
void SBC2::duplicate(int flag) {
dup_flag_=flag;
return;
}
void SBC2::recv(Packet* p, Handler* h) {
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_ip* ih = HDR_IP(p);
puts("Recv ");
if (ch->ptype() == PT_CBR) {
if (dup_flag_ == 1) {
duplicate_data(p->copy()); //for destination 2 true next SBC
forward_data(p); //for destination
return;
}
else {
forward_data(p);//for destination 1
return;
}
}
}
void SBC2::forward_data(Packet* p) {
puts("forward ");
struct hdr_ip* ih= HDR_IP(p);
ih->daddr() = Receiver1();
Scheduler::instance().schedule(target_, p, 0.0);
}
void SBC2::duplicate_data(Packet* p) {
struct hdr_ip* ih= HDR_IP(p);
ih->daddr() = Receiver2();
Scheduler::instance().schedule(target_, p, 0.0);
}
and filally in my tcl script, I did something like this:
in my code the SBC1 must receive data and forward them for MH. If the command " #$ns_ at 40 "$SBC1 start-duplication" " is used, It duplicates data for MH2.
Code:
set MH1null [new Agent/Null]
set MH2null [new Agent/Null]
set SBC1 [new Agent/fa_SBC [AddrParams addr2id [$W(0) node-addr]] [AddrParams addr2id [$MH node-addr]] [AddrParams addr2id [$MH2 node-addr]] ]
$SBC1 target-node1 $MH #the main target for sending data packets
$SBC1 target-node2 $MH2 ##the target for duplicating data packets
#$ns_ attach-agent $W(7) $SBC1 #node that must receive data and duplicate them for dup_destination
#$ns_ attach-agent $MH $MH1null #main receiver
#$ns_ attach-agent $MH2 $MH2null #duplicated data receiver
Last edited by fahimeh_ak; 08-16-2011 at 05:23 AM.
I'm doing a simulation now, its function is a little like this program.
I want to know how do you use .h files sip.h, sip-messages.h and sip_proxy.h ?
What's their functions? Thanks
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.