sir,
when i am running tcl file it give the below error :
"Segmentation fault (core dumped)"
now, below .cc,.h and .tcl file is:--
-----------------blue.cc-----------------------------------------------------------------------------------------------
#include <math.h>
#include <stdlib.h>
#include <sys/types.h>
#include "blue.h"
#include "random.h"
#include "delay.h"
#include "flags.h"
static class BlueClass : public TclClass {
public:
BlueClass() : TclClass("Queue/Blue") {}
TclObject* create(int argc, const char*const* argv) {
return (new Blue);
}
} class_blue;
Blue::Blue() {
q_ = new PacketQueue();
pq_ = q_;
bind_bool("drop_front_", &drop_front_);
bind_bool("bytes", &bytes_ );
bind_bool("setbit", &setbit_);
bind("decrement", &decrement_);
bind("increment", &increment_);
bind_time("dhold-time", &dholdtime_);
bind_time("ihold-time", &iholdtime_);
bind("dalgorithm", &dalgorithm_);
bind("ialgorithm", &ialgorithm_);
bind("pmark", &pmark_);
bind("pktsize", &mean_pktsize_);
bind_bool("queue_in_bytes_", &qib_);
bind("blue_l_", &blue_l_);
bind("curq_", &curq_);
bind("marking_prob_trace_", &marking_prob_trace_);
}
Blue::~Blue() {
{
delete q_;
}
}
int Blue::command(int argc, const char*const* argv) {
Tcl& tcl = Tcl::instance();
if (argc == 3) {
//attach a file for variable tracing
if (strcmp(argv[1], "attach") == 0) {
int mode;
const char* id = argv[2];
tchan_ = Tcl_GetChannel(tcl.interp(), (char*)id, &mode);
if (tchan_ == 0) {
tcl.resultf("BLUE: trace: can't attach %s for
writing", id);
return (TCL_ERROR);
}
return (TCL_OK);
}
if (strcmp(argv[1], "link") == 0) {
LinkDelay* link_ =
(LinkDelay*)TclObject::lookup(argv[2]);
if (link_ == 0) {
tcl.resultf("Blue : No link delay Object %s\n",
argv[2]);
return(TCL_ERROR);
}
bandwidth_ = link_->bandwidth();
return(TCL_OK);
}
if (!strcmp(argv[1], "packetqueue-attach")) {
delete q_;
if (!(q_ = (PacketQueue*) TclObject::lookup(argv[2])))
return (TCL_ERROR);
else {
pq_ = q_;
return (TCL_OK);
}
}
}
return Queue::command(argc, argv);
}
void
Blue::reset()
{
Queue::reset();
ptc_ = (bandwidth_ / (8 * mean_pktsize_));
idle_ = 1;
idletime_ = Scheduler::instance().clock();
pmark_ = 0;
marking_prob_trace_ = pmark_;
ifreezetime_ = 0;
dfreezetime_ = 0;
}
void
Blue::decrement_pmark(int how)
{
double now = Scheduler::instance().clock();
if (now - dfreezetime_ > dholdtime_) {
pmark_ -= decrement_;
if (pmark_ < 0)
pmark_ = 0.0;
marking_prob_trace_ = pmark_;
}
/*if (now - dfreezetime_ > dholdtime_) {
dfreezetime_ = now;
switch (dalgorithm_) {
case 0:
case 2:
switch (how) {
case 0:
pmark_ -= decrement_;
break;
case 1:
default:
break;
}
break;
default:
case 1:
switch (how) {
case 0:
pmark_ -= decrement_;
break;
case 1:
default:
pmark_ -= decrement_/10;
break;
}
}
if (pmark_ < 0)
pmark_ = 0.0;
}*/
}
void Blue::increment_pmark(int how)
{
double now = Scheduler::instance().clock();
int qlen = qib_ ? q_->byteLength() : q_->length();
curq_ = qlen;
if ((now - ifreezetime_ > iholdtime_) || (curq_ > blue_l_))
{
iholdtime_ = now;
pmark_ += increment_;
if (pmark_ > 1.0)
pmark_ = 1.00;
marking_prob_trace_ = pmark_;
}
/* if (now - ifreezetime_ > iholdtime_) {
ifreezetime_ = now;
switch (ialgorithm_) {
case 0:
switch (how) {
case 0:
pmark_ += increment_;
break;
case 1:
default:
break;
}
break;
case 2:
switch (how) {
case 0:
pmark_ = 2*pmark_ + increment_;
break;
case 1:
default:
break;
}
default:
case 1:
switch (how) {
case 0:
pmark_ += increment_;
break;
case 1:
default:
pmark_ += increment_/10;
break;
}
}
if (pmark_ > 1.0)
pmark_ = 1.00;
}*/
}
void Blue::enque(Packet* p)
{
double now = Scheduler::instance().clock();
int m;
bool dropped = false;
bool setbit_ = false;
hdr_flags* hf = hdr_flags::access(p);
double u = Random::uniform();
/* Find whether to drop or not */
if (u <= pmark_) {
if (setbit_ && hf->ect()) { /* if ECN enabled */
hf->ce() = 1; /*set ECN bit */
setbit_ = true;
}
else {
drop(p); /* drop packet */
dropped = true;
}
increment_pmark(0);
}
if (!dropped)
{
int qlim = qib_ ? (qlim_ * mean_pktsize_) : qlim_;
q_->enque(p);
if (q_->length() >= qlim) {
if (!setbit_) increment_pmark(0);
q_->remove(p);
drop(p);
}
}
int qlen = qib_ ? q_->byteLength() : q_->length();
curq_ = qlen; // for tracing purposes
/*if (idle_) {
idle_ = 0;
m = int(ptc_ * (now - idletime_));
}
else
m = 0;
if (drop_early(p)) {
drop(p);
//return;
}
else {
q_->enque(p);
if (q_->length() >= qlim_) {
increment_pmark(0);
q_->remove(p);
drop(p);
}
}*/
}
Packet* Blue::deque()
{
Packet* p = q_->deque();
if (p != 0) {
idle_ = 0;
}
else {
decrement_pmark(0);
idle_ = 1;
idletime_ = Scheduler::instance().clock();
}
int qlen = qib_ ? q_->byteLength() : q_->length();
curq_ = qlen; // for tracing purposes
return (p);
}
int Blue::drop_early(Packet *p)
{
hdr_flags* hf = hdr_flags::access(p);
double u = Random::uniform();
if (u <= pmark_) {
if (setbit_ && hf->ect()) {
hf->ce() = 1; /*set ECN bit here*/
}
else return (1);
}
return(0);
}
void Blue::trace(TracedVar* v)
{
char wrk[500];
const char *p;
if (((p = strstr(v->name(), "curq")) == NULL) &&
((p = strstr(v->name(), "marking_prob_trace")) == NULL) ) {
fprintf(stderr, "BLUE:unknown trace var %s\n",
v->name());
return;
}
if (tchan_) {
int n;
double t = Scheduler::instance().clock();
// XXX: be compatible with nsv1 RED trace entries
if (strstr(v->name(), "curq") != NULL) {
sprintf(wrk, "A %g %d", t, int(*((TracedInt*) v)));
} else {
sprintf(wrk, "P %g %g", t, double(*((TracedDouble*) v)));
}
n = strlen(wrk);
wrk[n] = '\n';
wrk[n+1] = 0;
(void)Tcl_Write(tchan_, wrk, n+1);
}
return;
}
---------------------------blue.h-------------------------------------------------------------------------
#ifndef ns_blue_h
#define ns_blue_h
#include <string.h>
#include "queue.h"
#include "config.h"
#include "trace.h"
class Blue : public Queue {
public:
Blue();
~Blue();
protected:
int command(int argc, const char*const* argv);
void enque(Packet*);
Packet* deque();
PacketQueue *q_; /* underlying FIFO queue */
int drop_front_; /* drop-from-front (rather than from tail) */
void reset();
void plot();
void plot1(int qlen);
void pmark_plot(int method);
int drop_early(Packet*);
void increment_pmark(int how);
void decrement_pmark(int how);
int bytes_ ;
int dummy_;
int setbit_;
int mean_pktsize_;
double decrement_;
double increment_;
double iholdtime_;
double dholdtime_;
int dalgorithm_;
int ialgorithm_;
double bandwidth_;
int idle_;
double idletime_;
double ptc_;
double ifreezetime_;
double dfreezetime_;
double pmark_;
int qib_; /* queue measured in bytes? */
double blue_l_; /* For allowing transient bursts and
controlling queing delay */
Tcl_Channel tchan_; /* place to write trace records */
TracedInt curq_; /* current qlen seen by arrivals */
TracedDouble marking_prob_trace_; /* for trace purposes */
void trace(TracedVar*); /* routine to write trace records */
};
#endif
---------------------------------------------blue.tcl---------------------------------------------------
#script illustrating the BLUE algorithm
#Senders are TCP-SACK senders, and receivers are TCP-SACK sinks
set ns [new Simulator]
# turn on ns and nam tracing
set f [open outb.tr w]
$ns trace-all $f
$ns namtrace-all [open outb.nam w]
#set the no of TCP flows here
set nodenum 5
set start_time 1.0
set finish_time 100
# create the nodes
#First create TCP senders and receivers
for {set i 0} {$i < $nodenum} {incr i} {
set s($i) [$ns node]
set r($i) [$ns node]
}
#Then create the 2 back-bone routers
set n1 [$ns node]
set n2 [$ns node]
# create the links
#betwwen the senders and n1, receivers and n2
for {set i 0} {$i < $nodenum} {incr i} {
$ns duplex-link $s($i) $n1 10Mb 1ms DropTail
$ns duplex-link $r($i) $n2 10Mb 1ms DropTail
}
#Bottle neck link between between n1 and n2
$ns simplex-link $n1 $n2 1Mbps 100ms Blue
$ns simplex-link $n2 $n1 1Mbps 100ms DropTail
#Configure BLUE queue parameters here
set blueq [[$ns link $n1 $n2] queue]
$blueq set decrement 0.00025
$blueq set increment 0.0025
$blueq set dhold-time 100ms
$blueq set ihold-time 100ms
#Enable ECN here
$blueq set setbit_ true
set tchan_ [open blueq.tr w]
$blueq trace curq_
$blueq trace marking_prob_trace_
$blueq attach $tchan_
#set the queue-limit between n1 and n2
$ns queue-limit $n1 $n2 50
#set up queue monitor, sample every 0.5 seconds
#set qfile [open "test-blue-qsize.out" w]
#set qm [$ns monitor-queue $n1 $n2 $qfile 0.5]
#[$ns link $n1 $n2] queue-sample-timeout
#create the random number generator
#set rng [new RNG]
# create TCP agents
for {set i 0} {$i < $nodenum} {incr i} {
set tcp($i) [new Agent/TCP/Sack1]
$tcp($i) set fid_ [expr ($i + 1)]
$tcp($i) set ecn_ 1
set sink($i) [new Agent/TCPSink/Sack1/DelAck]
$sink($i) set ecn_ 1
$ns attach-agent $s($i) $tcp($i)
$ns attach-agent $r($i) $sink($i)
$ns connect $tcp($i) $sink($i)
#set ftp($i) [new Application/FTP]
#$ftp($i) attach-agent $tcp($i)
#set p($i) [new Application/Traffic/Pareto]
#$p($i) set packetSize_ 1000
#$p($i) set burst_time_ 200ms
#$p($i) set idle_time_ 200ms
#$p($i) set shape_ 1.5
#$p($i) set rate_ 10000K
#$p($i) attach-agent $tcp($i)
#set start_time [$rng uniform 0 1]
#$ns at $start_time "$ftp($i) start"
#$ns at $start_time "$p($i) start"
}
set srcnum 0
for {set j 0} {$j < $finish_time} {set j [expr ($j + 20.0)]} {
for {set num 0} {$num < $nodenum} {incr num} {
for {set k $srcnum} {$k < [expr ($srcnum + 50)]} {incr k} {
set p($k) [new Application/Traffic/Pareto]
$p($k) set packetSize_ 1000
$p($k) set burst_time_ 200ms
$p($k) set idle_time_ 200ms
$p($k) set shape_ 1.5
$p($k) set rate_ 10000K
$p($k) attach-agent $tcp($num)
$ns at $j "$p($k) start"
}
set srcnum [expr ($srcnum + 50)]
}
}
$ns at $finish_time "finish"
proc finish {} {
global ns sink nodenum qfile srcnum tchan_
set awkCode {
{
if ($1 == "A" && NF>2) {
print $2, $3 >> "aq.tr";
set end $2
}
else if ($1 == "P" && NF>2)
print $2, $3 >> "prob.tr";
}
}
$ns flush-trace
if { [info exists tchan_] } {
close $tchan_
}
#close $qfile
exec awk $awkCode blueq.tr &
puts "running nam..."
exec nam outb.nam &
exit 0
}
$ns run
plz kindly check above sourcce file and tcl why error
"Segmentation fault (core dumped)" occur.
thank you.