Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
08-13-2011, 02:53 AM
|
#1
|
LQ Newbie
Registered: Jul 2009
Posts: 13
Rep:
|
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:
Code:
/**********************************/
SBC2::SBC2() : Agent(PT_CBR) {
dup_flag_=0;
// set_pkttype(PT_CBR);
puts("SBC2::SBC2\n");
}
/**********************************/
and I defines the recv() function as follow:
Code:
void SBC2::recv(Packet* p, Handler* h) {
puts("\n\nReceived Packet\n\n");
if (ch->ptype() == PT_CBR) {
if (ih->saddr() == Sender() && ih->daddr() == Receiver() ) {
if (dup_flag_ == 1) {
duplicate_data(p);//for destination true next SBC
}
return();
}
void SBC2::duplicate_data(Packet* p) {
//for next sbc
puts("duplicate Packet \n");
struct hdr_cmn* ch = HDR_CMN(p);
struct hdr_ip* ih = HDR_IP(p);
struct hdr_rtp *rh = hdr_rtp::access(p);
Packet *np = allocpkt();
// np=p; copy CBR packet to this new packet
struct hdr_cmn* nch= HDR_CMN(np);
struct hdr_ip* nih= HDR_IP(np);
struct hdr_rtp *nrh = hdr_rtp::access(np);
nch->direction() = ch->direction();
nch->size() = ch->size();
nch->error() = ch->error();
nch->next_hop() = nextSBC_; //Through new SBC
nch->addr_type() = ch->addr_type();
nih->saddr() = ih->saddr();
nih->daddr() = newDest(); // To new IP
nih->sport() = ih->sport();
nih->dport() = ih->dport();
nih->ttl() =ih->ttl();
nih->flowid() = ih->flowid();
nrh->seqno() = rh->seqno();
Scheduler::instance().schedule(target_, p, JITTER);
}
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
with thanks: F.Akbari
|
|
|
08-13-2011, 03:35 AM
|
#2
|
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,520
|
Did you compile the code into the binary 'ns' ?
Assume code.cc : Make a copy of the Makefile, say "Makefile-2".
Add code.o to Makefile-2, at the end of section OBJ_CC.
( Line 330 - 331.)
cd ns-allinone-2.34/ns-2.34/ && make clean && make -f Makefile-2
..
|
|
|
08-15-2011, 01:06 AM
|
#3
|
LQ Newbie
Registered: Jul 2009
Posts: 13
Original Poster
Rep:
|
I solved this problem!
Hi
I could solve the problem. to do that I used from following "SBC" agent definition:
Code:
#ifndef __fa_SBC_h__
#define __fa_SBC_h__
using namespace std;
#include "address.h"
#include <packet.h>
#include <agent.h>
#include <random.h>
#include <trace.h>
#include <map>
#include "ip.h"
#include "rtp.h"
#include "sip.h"
#include "sip-messages.h"
#include "tclcl.h"
#define JITTER (Random::uniform()*0.5)
//only for media stream packets
class SBC2 : public Agent {
nsaddr_t SBC_addr_;
nsaddr_t Sender_;
nsaddr_t Receiver1_; //if duplicate_flag==0 it's the main receiver
nsaddr_t Receiver2_;
int dup_flag_; //0: no duplication, 1: duplicate for new SBC,...
protected:
NsObject* target1_;
NsObject* target2_;
inline nsaddr_t& SBC_addr() { return SBC_addr_; }
inline nsaddr_t& Sender() { return Sender_; }
inline nsaddr_t& Receiver1() { return Receiver1_; }
inline nsaddr_t& Receiver2() { return Receiver2_; }
inline NsObject* target1() { return target1_; }
inline NsObject* target2() { return target2_; }
void forward_data(Packet*);//for reciever1
void duplicate_data(Packet*);//for reciever2
void duplicate(int);//set dup_flag
public:
SBC2(const char* ,const char* ,const char*);//snder,receiver1,receiver2
int command(int, const char*const*);
void recv(Packet*, Handler*);
};
#endif
Code:
//<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.
|
|
|
08-15-2011, 01:53 AM
|
#4
|
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,520
|
Code tags : It's a slash " / " , not a backslash.
Must be : [/code].
P.S. : Good to see, that you found a solution.
..
Last edited by knudfl; 08-15-2011 at 02:01 AM.
|
|
|
08-16-2011, 05:24 AM
|
#5
|
LQ Newbie
Registered: Jul 2009
Posts: 13
Original Poster
Rep:
|
Thank you knudfl.
|
|
|
09-06-2016, 11:12 PM
|
#6
|
LQ Newbie
Registered: Sep 2016
Posts: 1
Rep: 
|
Hi, some question I want to know, thx ^_^
Hi,
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
|
|
|
All times are GMT -5. The time now is 07:09 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|