[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
No Subject
The following way to do it is rather involved, and it requires
modification of UDP agent and deriving your own cbr class from
CBR_Traffic. If you do not follow things below, wait a couple of weeks and
I'll set up a web page as how to pass app-level data in ns.
Basically, there are 3 steps and you need the AppData stuff:
(1) Derive a class from AppData (defined in ns-process.h) which contains,
say, sequence number. In this derived class, you should define method
pack() and a constructor so that it "marshalls" data into/from a packet.
class MyData : public AppData {
private:
int num_; // my number
public:
// used to extract data from a byte stream
struct hdr : AppData::hdr {
int num_;
};
public:
MyData(int d) : AppData(MYDATA) {
num_ = d;
}
MyData(char *b) : AppData(b) {
hdr* h = (hdr *)b;
num_ = h->num_;
}
inline int& num() { return num_; }
virtual int size() const { return hdrlen(); }
virtual int hdrlen() const { return sizeof(hdr); }
virtual void pack(char* buf) const {
AppData::pack(buf);
((hdr*)buf)->num_ = num_;
}
};
(2) Remember to put MYDATA in the enum AppDataType in ns-process.h
(3) Derive your own cbr class from CBR_Traffic in cbr_traffic.cc, override
its timeout() function (defined in trafgen.cc) to pass your own data into
a packet:
* construct send(appdata, size_) construct your own AppData:
void MyCBR::timeout()
{
if (! running_)
return;
//-----
/* send a packet */
// send(size_);
// Construct our own appdata, assuming the number magicall appears
// as NUM_
MyData data(NUM_);
// Instead of send(size_), call send(size_, data)
send(size_, &data);
//-----
/* figure out when to send the next one */
nextPkttime_ = next_interval(size_);
/* schedule it */
if (nextPkttime_ > 0)
timer_.resched(nextPkttime_);
}
void MyCBR::process_data(int size, char *data)
{
if (data == NULL)
return;
if (AppData::type(data) != MYDATA)
// ERROR
abort();
AppData d(data);
// Process your number here...
}
* Modify UDP agent to pack your own number into packets and pass your own
data to your own CBR:
- Copy UdpAgent::sendmsg(int, const char*) to UdpAgent::send(int size,
const AppData *data). Then change the two allocpkt() to
allocpkt(data->size()), and add the following line before the two
"target_->recv(p)":
data->pack((char *)pkt->accessdata());
- Add:
UdpAgent::recv(Packet *pkt, Handler *)
{
if (app_ == 0)
return;
hdr_inval *ih = (hdr_inval *)pkt->access(off_inv_);
((MyCBR*)app_)->process_data(ih->size(),(char*)pkt->accessdata());
Packet::free(pkt);
}
That's about it.
- Haobo
> Subject: cbr packets
>
> Hi,
> How to put a number in a CBR packet at the source, and read this number
> at the receiver?
>
> Arnaud.
> - --
> - ----------------------------------------------------------------------
> Arnaud Legout
>
> Institut Eurecom Phone : 00.33.4.93.00.26.61
> 2229, route des Cretes Fax : 00.33.4.93.00.26.27
> BP 193 E-mail: [email protected]
> 06904 Sophia Antipolis cedex Web : http://www.eurecom.fr/~legout
> FRANCE
> - ----------------------------------------------------------------------