fsm.h

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * Copyright (C) 1999 by the University of Southern California
00005  * $Id: fsm.h,v 1.4 2005/08/25 18:58:02 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 /* 
00048  * Contributed by Polly Huang (USC/ISI), http://www-scf.usc.edu/~bhuang
00049  * 
00050  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/fsm.h,v 1.4 2005/08/25 18:58:02 johnh Exp $ (LBL)
00051  */
00052 
00053 #include "scheduler.h"
00054 
00055 #define RTT 1
00056 #define TIMEOUT 2
00057 
00058 class FSMState {
00059 protected:
00060     friend class FSM;
00061     void number_all();
00062     void print_all(int level);
00063     void print_all_stats(int desired_pkts, int pkts = 0,
00064                  int rtts = 0, int timeouts = 0, 
00065                  int ps = 0, int qs = 0,
00066                  int num_states = 0,
00067                  int num_state_names = 0);
00068     void reset_all_processed();
00069     bool processed() { return print_i_ < 0; }
00070 public:
00071     FSMState() : print_i_(0) {};
00072     /* number of packets in this batch of transmission */
00073     int batch_size_; 
00074     /* time to make transition from previous state to this one
00075     * (either RTT or TIMEOUT) */
00076     int transition_[17];
00077     /* next states if dropping packet #1-16, 0 for none */
00078     FSMState* drop_[17];
00079     int print_i_;  // printing index (processed if negative)
00080 };
00081 
00082 
00083 class FSM : public TclObject {
00084 public:
00085     FSM() {};
00086     inline FSMState* start_state() {    // starting state
00087         return (start_state_);
00088     }
00089     static FSM& instance() {
00090         return (*instance_);        // general access to scheduler
00091     }
00092     static void print_FSM(FSMState* state);
00093     static void print_FSM_stats(FSMState* state, int n);
00094 protected:
00095     FSMState* start_state_;
00096     static FSM* instance_;
00097 };
00098 
00099 
00100 
00101 class TahoeAckFSM : public FSM {
00102 public:
00103     TahoeAckFSM();
00104     inline FSMState* start_state() {    // starting state
00105         return (start_state_);
00106     }
00107     static TahoeAckFSM& instance() {
00108         return (*instance_);           // general access to TahoeAckFSM
00109     }
00110 protected:
00111     FSMState* start_state_;
00112     static TahoeAckFSM* instance_;
00113 
00114 };
00115 
00116 class RenoAckFSM : public FSM {
00117 public:
00118     RenoAckFSM();
00119     inline FSMState* start_state() {    // starting state
00120         return (start_state_);
00121     }
00122     static RenoAckFSM& instance() {
00123         return (*instance_);           // general access to TahoeAckFSM
00124     }
00125 protected:
00126     FSMState* start_state_;
00127     static RenoAckFSM* instance_;
00128 };
00129 
00130 
00131 class TahoeDelAckFSM : public FSM {
00132 public:
00133     TahoeDelAckFSM();
00134     inline FSMState* start_state() {    // starting state
00135         return (start_state_);
00136     }
00137     static TahoeDelAckFSM& instance() {
00138         return (*instance_);           // general access to TahoeAckFSM
00139     }
00140 protected:
00141     FSMState* start_state_;
00142     static TahoeDelAckFSM* instance_;
00143 };
00144 
00145 class RenoDelAckFSM : public FSM {
00146 public:
00147     RenoDelAckFSM();
00148     inline FSMState* start_state() {    // starting state
00149         return (start_state_);
00150     }
00151     static RenoDelAckFSM& instance() {
00152         return (*instance_);           // general access to TahoeAckFSM
00153     }
00154 protected:
00155     FSMState* start_state_;
00156     static RenoDelAckFSM* instance_;
00157 };

Generated on Tue Mar 6 16:47:45 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6