[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] Implementation of VBR MPEG-1 traffic source in ns

Hello Dirk

I've just made a simple VBR application that randomly change rate or bursts depending on parameters set. I've attached the code.

In order to use it in ns you have to:
1. include vbr_traffic.o in Makefile.in
2. preferrably set the default values in ~/ns-2.1xx/tcl/ns-default.tcl (see my default values below)
3. run ./configure in your ~/ns-2.1xx directory
4. run make depend in ~/ns-2.1xx
5. run make

and you're ready to use the application in the same way you use the CBR application.

My default values in ns-default.tcl:
Application/Traffic/VBR set rate_ 448Kb ;# corresponds to interval of 3.75ms
Application/Traffic/VBR set rate_dev_ 0.25;
Application/Traffic/VBR set rate_time_ 2.0;
Application/Traffic/VBR set burst_time_ 1.0;
Application/Traffic/VBR set n_o_changes_ 10;
Application/Traffic/VBR set time_dev_ 0.5;
Application/Traffic/VBR set constant_ false;
Application/Traffic/VBR set maxrate_ 648Kb;
Application/Traffic/VBR set packetSize_ 210;
Application/Traffic/VBR set maxpkts_ 268435456; # 0x10000000

If you're willing to share your VBR/MPEG application when you're done I'd really appreciate a copy of the code. I actually had decided to keep my simulation simple and general, but it would be interesting to see your code.

Don't hesitate to ask about the implementation if something is unclear. I've tried to write alot of comments. You're also welcome to comment code and come with suggestions of improvement. If anything is unclear about how to include it in ns you're also welcome to ask.


Dirk Deschrijver wrote

Hi people,

I am trying to implement a VBR (variable bitrate) MPEG-1 traffic generator
in NS, rather than using trace files (they are too short for running
I already have an algorithm, but I'm not sure how to implement it in NS.

Can anyone give me some hints how I can do this, or some url's where I can
find some documentation. The ns-manual is rather vague about extending ns,
and the code isn't very documented either ...

Thx in advance,

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

Håkan Byström, Operax
+46 920 755 07, office
+46 70 374 03 24, cellular
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
 * Copyright (c) Xerox Corporation 1997. All rights reserved.
 * License is granted to copy, to use, and to make and to use derivative
 * works for research and evaluation purposes, provided that Xerox is
 * acknowledged in all documentation pertaining to any such copy or derivative
 * work. Xerox grants no other licenses expressed or implied. The Xerox trade
 * name should not be used in any advertising without its written permission.
 * FOR ANY PARTICULAR PURPOSE.  The software is provided "as is" without
 * express or implied warranty of any kind.
 * These notices must be retained in any copies of any part of this software.

#include <stdlib.h>
#include "random.h"
#include "trafgen.h"
#include "ranvar.h"

 * The VBR_Traffic class represents a variable bit rate traffic source.
 * Parameterized by rate, deviation of rate in percent, time periods of no
 * burst, time period of burst, number of rate changes during burst,
 * deviation of time periods in percent and constant rate variation or not.
class VBR_Traffic : public TrafficGenerator {
	virtual double next_interval(int&);
	//HACK so that udp agent knows interpacket arrival time within a burst
	inline double interval() { return (interval_); }
	virtual void start();
	void init();
	double rate_;       /* Send rate during on time (bps). */
	double rate_dev_;   /* Size of random variation on rate. */
	double rate_time_;  /* Mean time of ordinary rate period. */
	double burst_time_; /* Mean time of burst rate period. */
	double n_o_changes_;/* Number of changes during burst time. */
	double time_dev_;   /* Deviation from time periods. */
	int constant_;      /* Perform constant bit rate variation?
			     * NOTICE: burst_time_ controls time between
			     * rate variation. */
	double maxrate_;    /* Maximum rate of burst / constant variation. */
	int maxpkts_;
	int seqno_;
	double next_change; /* Time for next rate change. */
	double next_burst;  /* Time for next burst. */
	double next_rate;   /* Time for next ordinare rate. */
	double curr_rate;
	double interval_;   /* Packet inter-arrival time during burst (sec) */

static class VBRTrafficClass : public TclClass {
	VBRTrafficClass() : TclClass("Application/Traffic/VBR") {}
	TclObject* create(int, const char*const*) {
		return (new VBR_Traffic());
} class_vbr_traffic;

VBR_Traffic::VBR_Traffic() : seqno_(0) {
	/* See comments in class definition above. */
	bind_bw("rate_", &rate_);               //default 448Kb
	bind("rate_dev_", &rate_dev_);          //default 0.25
	bind_time("rate_time_", &rate_time_);   //default 2.0
	bind_time("burst_time_", &burst_time_); //default 1.0
	bind("n_o_changes_", &n_o_changes_);    //default 10
	bind("time_dev_", &time_dev_);          //default 0.5
	bind_bool("constant_", &constant_);     //default false
	bind_bw("maxrate_", &maxrate_);         //default 648Kb
	bind("packetSize_", &size_);            //default 210
	bind("maxpkts_", &maxpkts_);            //default 268435456

void VBR_Traffic::init() {
        double now = Scheduler::instance().clock();
	//Start with burst.
	next_change = now;
	next_burst = now;
	next_rate = now + burst_time_ * (1 - Random::
					uniform(-time_dev_, time_dev_));
	curr_rate = rate_;

        // compute inter-packet interval 
	interval_ = (double)(size_ << 3)/(double)rate_;
	if (agent_) {
		//Use same packet type as for CBR.

void VBR_Traffic::start()
        running_ = 1;

 * Returns the time until the next packet is created (and also sets the size
 * in bytes of the next packet if it has changed in the tcl script).
double VBR_Traffic::next_interval(int& size) {
        double now = Scheduler::instance().clock();

	if (next_change <= now) {
		// Randomize rate and deviation from desired time.
		double rand_time = Random::uniform(-time_dev_, time_dev_);
		double rand = Random::uniform(-(rate_dev_), rate_dev_);
		curr_rate = curr_rate + (maxrate_ - rate_) * rand;
		if (constant_) {
			// Set time for next rate change.
			next_change = now + burst_time_ * (1 - rand_time);
		} else if (next_burst <= next_rate) {
			// Set time for next rate change within burst.
			next_burst = now + burst_time_ * (1 - rand_time) /
		} else {
			/* End of burst period. Set times for next burst
			 * period. */
			next_change = now + rate_time_ * (1 - rand_time);
			next_burst = next_change;
			rand_time = Random::uniform(-time_dev_, time_dev_);
			next_rate = next_change + burst_time_ *
				(1 - rand_time);
			curr_rate = rate_;
		// Limit the result.
		if (curr_rate > maxrate_)
			curr_rate = maxrate_;
		if (curr_rate < rate_)
			curr_rate = rate_;
	interval_ = (double)(size_ << 3)/(double)curr_rate;
	double t = interval_;

	size = size_;
	if (++seqno_ < maxpkts_)