• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tools/trafgen.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) Xerox Corporation 1997. All rights reserved.
00004  *  
00005  * This program is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU General Public License as published by the
00007  * Free Software Foundation; either version 2 of the License, or (at your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  * Linking this file statically or dynamically with other modules is making
00020  * a combined work based on this file.  Thus, the terms and conditions of
00021  * the GNU General Public License cover the whole combination.
00022  *
00023  * In addition, as a special exception, the copyright holders of this file
00024  * give you permission to combine this file with free software programs or
00025  * libraries that are released under the GNU LGPL and with code included in
00026  * the standard release of ns-2 under the Apache 2.0 license or under
00027  * otherwise-compatible licenses with advertising requirements (or modified
00028  * versions of such code, with unchanged license).  You may copy and
00029  * distribute such a system following the terms of the GNU GPL for this
00030  * file and the licenses of the other code concerned, provided that you
00031  * include the source code of that other code when and as the GNU GPL
00032  * requires distribution of source code.
00033  *
00034  * Note that people who make modified versions of this file are not
00035  * obligated to grant this special exception for their modified versions;
00036  * it is their choice whether to do so.  The GNU General Public License
00037  * gives permission to release a modified version without this exception;
00038  * this exception also makes it possible to release a modified version
00039  * which carries forward this exception.
00040  *
00041  * Changes by the Daedalus group, http://daedalus.cs.berkeley.edu
00042  *      Add Application interface
00043  *
00044  * @(#) $Header: /cvsroot/nsnam/ns-2/tools/trafgen.h,v 1.7 2005/08/26 05:05:31 tomh Exp $ (Xerox)
00045  */
00046 
00047 #ifndef ns_trafgen_h
00048 #define ns_trafgen_h
00049 
00050 #include "app.h"
00051 #include "timer-handler.h"
00052 
00053 class TrafficGenerator;
00054 
00055 class TrafficTimer : public TimerHandler {
00056 public:
00057         TrafficTimer(TrafficGenerator* tg) : tgen_(tg) {}
00058 protected:
00059         void expire(Event*);
00060         TrafficGenerator* tgen_;
00061 };
00062 
00063 
00064 /* abstract class for traffic generation modules.  derived classes
00065  * must define  the next_interval() function.  the traffic generation 
00066  * module schedules an event for a UDP_Agent when it is time to 
00067  * generate a new packet.  it passes the packet size with the event 
00068  * (to accommodate traffic generation modules that may not use fixed 
00069  * size packets).
00070  */
00071 
00072 /* abstract class for traffic generation modules.  derived classes
00073  * must define the next_interva() function that is invoked by
00074  * UDP_Agent.  This function returns the time to the next packet
00075  * is generated and sets the size of the packet (which is passed
00076  * by reference).  The init() method is called from the start()
00077  * method of the UDP_Agent.  It can do any one-time initialization
00078  * needed by the traffic generation process.
00079  */
00080 
00081 class TrafficGenerator : public Application {
00082 public:
00083         TrafficGenerator();
00084         virtual double next_interval(int &) = 0;
00085         virtual void init() {}
00086         virtual double interval() { return 0; }
00087         virtual int on() { return 0; }
00088         virtual void timeout();
00089 
00090         virtual void recv() {}
00091         virtual void resume() {}
00092 
00093 protected:
00094         virtual void start();
00095         virtual void stop();
00096 
00097         double nextPkttime_;
00098         int size_;
00099         int running_;
00100         TrafficTimer timer_;
00101 };
00102 
00103 #endif

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1