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

http agent





I am a new NS user and I tried to run the echo agent example given in NS
documentation. But when i start the echoagent from the ns shell, it given
segmentation fault. I found that the Scheduler::instance_ variable had a
value of 0 and so when i do Scheduler::Instance().clock() it core dumps.

Has anybody faced this problem before or could give some pointers where
the problem can be. I am not sure if there is something wrong with the
simulation setup script or with the echoagent code.

thanks in advance,
anshul


the script i am using is 
-----------------------------

set ns [new Simulator]

set n0 [$ns node]
set n1 [$ns node]

$ns duplex-link $n0 $n1 5Mb 2ms DropTail

set echo [new Agent/ECHO]
set sink [new Agent/Null]

$ns attach-agent $n0 $echo
$ns attach-agent $n1 $sink

$ns connect $echo $sink

$echo set interval_ 1
$echo start


I am also attaching the echo.cc which has code for ECHO_Agent.
I think I have taken care of the other modifications that have to be made
for echo packet header to come into effect etc.


/*
 * Copyright (c) 1997 Regents of the University of California.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 * 	This product includes software developed by the MASH Research
 * 	Group at the University of California Berkeley.
 * 4. Neither the name of the University nor of the Research Group may be
 *    used to endorse or promote products derived from this software without
 *    specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef lint
static const char rcsid[] =
    "@(#) $Header: /usr/src/mash/repository/vint/ns-2/echo.cc,v 1.12 1997/08/14 00:07:35 tomh Exp $";
#endif


#include <stdlib.h>
#include <string.h>

#include "tclcl.h"
#include "agent.h"
#include "packet.h"
#include "echo.h"

#include <iostream.h>

class ECHOHeaderClass : public PacketHeaderClass {
public: 
        ECHOHeaderClass() : PacketHeaderClass("PacketHeader/ECHO",
					     sizeof(hdr_echo)) {}
} class_echohdr;


class ECHO_Agent;
// class ECHO_Timer;

class ECHO_Timer : public TimerHandler {
public:
    ECHO_Timer(ECHO_Agent *a) : TimerHandler() { a_ = a; }
protected:
    virtual void expire(Event *e);
    ECHO_Agent *a_;
};


class ECHO_Agent : public Agent {
public:
	ECHO_Agent();
	int command(int argc, const char*const* argv);
	void timeout(int);
protected:
	double interval_;
	void sendit();
    int off_echo_;
	ECHO_Timer echo_timer_;
};

static class ECHOAgentClass : public TclClass {
public:
	ECHOAgentClass() : TclClass("Agent/ECHO") {}
	TclObject* create(int, const char*const*) {
		return (new ECHO_Agent());
	}
} class_echo_agent;

ECHO_Agent::ECHO_Agent() : Agent(PT_ECHO), echo_timer_(this)
{
	bind_time("interval_", &interval_);
	bind("packetSize_", &size_);
    bind("off_echo_", &off_echo_);
}


void ECHO_Agent::timeout(int) 
{
	sendit();
    cout << "Sending the packet " <<  endl ; 
    // core dumps at the next statement
    echo_timer_.resched(interval_);
}

void ECHO_Agent::sendit() 
{
    double junk;
    Tcl& tcl = Tcl::instance();
    Scheduler& s = Scheduler::instance();
    tcl.resultf("Value of interval_ is %g and off_echo_ is %d and off_ip_ is %d", interval_, off_echo_, off_ip_);
    Packet* p = allocpkt();
    hdr_echo *eh = (hdr_echo*)p->access(off_echo_);
    // core dumps at the next statement
    junk = s.clock(); 
     printf (" The value is \n") ;
     fflush(stdout) ;
     printf (" The value is %f\n", s.clock()) ;
/*     tcl.resultf("Value of time is %g ", s.clock()); */
/*     eh->timestamp() = Scheduler::instance().clock(); */
    send(p,0);
}

void ECHO_Timer::expire(Event *e)
{
    a_->timeout(0);
}

int ECHO_Agent::command(int argc, const char*const* argv)
{
    Tcl& tcl = Tcl::instance();
	if (argc == 2) {
		if (strcmp(argv[1], "start") == 0) {
            tcl.result("Before Calling timeout");
			timeout(0);
/*             tcl.result("After Calling timeout"); */
			return (TCL_OK);
		}
	} 
	return (Agent::command(argc, argv));
}
/*
 * Copyright (c) 1997 Regents of the University of California.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 * 	This product includes software developed by the MASH Research
 * 	Group at the University of California Berkeley.
 * 4. Neither the name of the University nor of the Research Group may be
 *    used to endorse or promote products derived from this software without
 *    specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#) $Header: /usr/src/mash/repository/vint/ns-2/echo.h,v 1.6 1997/08/12 22:27:46 gnguyen Exp $
 */


#ifndef ns_echo_h
#define ns_echo_h

#include "config.h"
#include "object.h"

/* echo packet.  For now, just has timestamp */
struct hdr_echo { 
	double ts_;

	double& timestamp() {
		return (ts_);
	}
};   

#endif