00001 00002 /* 00003 * srm-state.h 00004 * Copyright (C) 1997 by the University of Southern California 00005 * $Id: srm-state.h,v 1.8 2005/08/25 18:58:08 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 // Author: Kannan Varadhan <kannan@isi.edu> 00049 // Version Date: Mon Jun 30 15:51:33 PDT 1997 00050 // 00051 // @(#) $Header: /cvsroot/nsnam/ns-2/mcast/srm-state.h,v 1.8 2005/08/25 18:58:08 johnh Exp $ (USC/ISI) 00052 // 00053 00054 #ifndef ns_srm_state_h 00055 #define ns_srm_state_h 00056 00057 #include <assert.h> 00058 00059 class SRMinfo { 00060 public: 00061 SRMinfo* next_; 00062 00063 int sender_; 00064 00065 /* Session messages */ 00066 int lsess_; /* # of last session msg received */ 00067 int sendTime_; /* Time sess. msg. # sent */ 00068 int recvTime_; /* Time sess. msg. # received */ 00069 double distance_; 00070 00071 /* Added for ssm, later check if can do for a derived class */ 00072 /* Can do better with space for these flags */ 00073 int lglbsess_; 00074 int llocsess_; 00075 int lrepsess_; 00076 int repid_; 00077 int senderFlag_; 00078 int scopeFlag_; 00079 #define ACTIVE 1 00080 #define INACTIVE 0 00081 int activeFlag_; 00082 #define SELF_DISTANCE 1 00083 #define REP_DISTANCE 2 00084 #define NO_DISTANCE 0 00085 int distanceFlag_; 00086 00087 /* Data messages */ 00088 int ldata_; /* # of last data msg sent */ 00089 protected: 00090 char *received_; /* Bit vector of msgs received */ 00091 int recvmax_; 00092 00093 #define BITVEC_SIZE_DEFAULT 256 // for (256 * 8) = 2K messages 00094 void resize(int id) { 00095 if (! received_) { 00096 received_ = new char[BITVEC_SIZE_DEFAULT]; 00097 recvmax_ = BITVEC_SIZE_DEFAULT * sizeof(char); 00098 (void) memset(received_, '\0', BITVEC_SIZE_DEFAULT); 00099 } 00100 if (recvmax_ <= id) { 00101 int osize, nsize; 00102 nsize = osize = recvmax_; 00103 while (nsize <= id) 00104 nsize *= 2; 00105 osize /= sizeof(char); 00106 nsize /= sizeof(char); 00107 char* nvec = new char[nsize]; 00108 (void) memcpy(nvec, received_, osize); 00109 (void) memset(nvec + osize, '\0', osize); 00110 delete[] received_; 00111 received_ = nvec; 00112 recvmax_ = nsize; 00113 } 00114 } 00115 00116 public: 00117 SRMinfo(int sender) : next_(0), sender_(sender), 00118 lsess_(-1), sendTime_(0), recvTime_(0), distance_(1.0), 00119 senderFlag_(0), activeFlag_(ACTIVE), distanceFlag_(NO_DISTANCE), 00120 ldata_(-1), received_(0), recvmax_(-1) { 00121 lglbsess_ = -1; 00122 llocsess_ = -1; 00123 lrepsess_ = -1; 00124 } 00125 ~SRMinfo() { delete[] received_; } 00126 00127 char ifReceived(int id) { 00128 assert(id >= 0); 00129 if (id >= recvmax_) 00130 resize(id); 00131 return (received_[id / 8] & (1 << (id % 8))); 00132 } 00133 char setReceived(int id) { 00134 int obit = ifReceived(id); 00135 received_[id / 8] |= (1 << (id % 8)); 00136 return obit; 00137 } 00138 char resetReceived(int id) { 00139 int obit = ifReceived(id); 00140 received_[id / 8] &= ~(1 << (id % 8)); 00141 return obit; 00142 } 00143 }; 00144 00145 #endif /* ns_srm_state_h */