00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* fsm.h 00003 * Copyright (C) 1999 by USC/ISI 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms are permitted 00007 * provided that the above copyright notice and this paragraph are 00008 * duplicated in all such forms and that any documentation, advertising 00009 * materials, and other materials related to such distribution and use 00010 * acknowledge that the software was developed by the University of 00011 * Southern California, Information Sciences Institute. The name of the 00012 * University may not be used to endorse or promote products derived from 00013 * this software without specific prior written permission. 00014 * 00015 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 00016 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00017 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00018 * 00019 * Contributed by Polly Huang (USC/ISI), http://www-scf.usc.edu/~bhuang 00020 * 00021 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/fsm.h,v 1.3 1999/09/08 20:56:50 heideman Exp $ (LBL) 00022 */ 00023 00024 #include "scheduler.h" 00025 00026 #define RTT 1 00027 #define TIMEOUT 2 00028 00029 class FSMState { 00030 protected: 00031 friend class FSM; 00032 void number_all(); 00033 void print_all(int level); 00034 void print_all_stats(int desired_pkts, int pkts = 0, 00035 int rtts = 0, int timeouts = 0, 00036 int ps = 0, int qs = 0, 00037 int num_states = 0, 00038 int num_state_names = 0); 00039 void reset_all_processed(); 00040 bool processed() { return print_i_ < 0; } 00041 public: 00042 FSMState() : print_i_(0) {}; 00043 /* number of packets in this batch of transmission */ 00044 int batch_size_; 00045 /* time to make transition from previous state to this one 00046 * (either RTT or TIMEOUT) */ 00047 int transition_[17]; 00048 /* next states if dropping packet #1-16, 0 for none */ 00049 FSMState* drop_[17]; 00050 int print_i_; // printing index (processed if negative) 00051 }; 00052 00053 00054 class FSM : public TclObject { 00055 public: 00056 FSM() {}; 00057 inline FSMState* start_state() { // starting state 00058 return (start_state_); 00059 } 00060 static FSM& instance() { 00061 return (*instance_); // general access to scheduler 00062 } 00063 static void print_FSM(FSMState* state); 00064 static void print_FSM_stats(FSMState* state, int n); 00065 protected: 00066 FSMState* start_state_; 00067 static FSM* instance_; 00068 }; 00069 00070 00071 00072 class TahoeAckFSM : public FSM { 00073 public: 00074 TahoeAckFSM(); 00075 inline FSMState* start_state() { // starting state 00076 return (start_state_); 00077 } 00078 static TahoeAckFSM& instance() { 00079 return (*instance_); // general access to TahoeAckFSM 00080 } 00081 protected: 00082 FSMState* start_state_; 00083 static TahoeAckFSM* instance_; 00084 00085 }; 00086 00087 class RenoAckFSM : public FSM { 00088 public: 00089 RenoAckFSM(); 00090 inline FSMState* start_state() { // starting state 00091 return (start_state_); 00092 } 00093 static RenoAckFSM& instance() { 00094 return (*instance_); // general access to TahoeAckFSM 00095 } 00096 protected: 00097 FSMState* start_state_; 00098 static RenoAckFSM* instance_; 00099 }; 00100 00101 00102 class TahoeDelAckFSM : public FSM { 00103 public: 00104 TahoeDelAckFSM(); 00105 inline FSMState* start_state() { // starting state 00106 return (start_state_); 00107 } 00108 static TahoeDelAckFSM& instance() { 00109 return (*instance_); // general access to TahoeAckFSM 00110 } 00111 protected: 00112 FSMState* start_state_; 00113 static TahoeDelAckFSM* instance_; 00114 }; 00115 00116 class RenoDelAckFSM : public FSM { 00117 public: 00118 RenoDelAckFSM(); 00119 inline FSMState* start_state() { // starting state 00120 return (start_state_); 00121 } 00122 static RenoDelAckFSM& instance() { 00123 return (*instance_); // general access to TahoeAckFSM 00124 } 00125 protected: 00126 FSMState* start_state_; 00127 static RenoDelAckFSM* instance_; 00128 };
1.3.3