00001 /* 00002 * (c) 1997-98 StarBurst Communications Inc. 00003 * 00004 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND 00005 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00006 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00007 * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE 00008 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00009 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00010 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00011 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00012 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00013 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00014 * SUCH DAMAGE. 00015 * 00016 * Author: Christoph Haenle, chris@cs.vu.nl 00017 * File: mftp.h 00018 * Last change: Dec 07, 1998 00019 * 00020 * This software may freely be used only for non-commercial purposes 00021 * 00022 * $Header: /nfs/jade/vint/CVSROOT/ns-2/apps/mftp.h,v 1.4 2000/09/01 03:04:06 haoboy Exp $ 00023 */ 00024 00025 // This file contains functionality common to both MFTP sender and receivers. 00026 00027 #ifndef mftp_h 00028 #define mftp_h 00029 00030 #include "codeword.h" // due to definition of CW_PATTERN_t 00031 #include "agent.h" // due to class Agent 00032 #include "assert.h" // due to assert() 00033 00034 struct hdr_mftp { 00035 enum { PDU_DATA_TRANSFER, PDU_STATUS_REQUEST, PDU_NAK }; // allowed types of PDU's 00036 00037 int type; // field for PDU-type 00038 // instead of "class Spec", should use "union Spec", but doesn't work 00039 // since CW_PATTERN_t is a class. 00040 class Spec { // specific part of the PDU (different for different types) 00041 public: 00042 class Data { // PDU_DATA_TRANSFER: 00043 public: 00044 unsigned long pass_nb; 00045 unsigned long group_nb; 00046 CW_PATTERN_t cw_pat; 00047 } data; 00048 class StatReq { // PDU_STATUS_REQUEST: 00049 public: 00050 unsigned long pass_nb; // pass number the status request belongs to 00051 unsigned long block_lo; // lowest block number requested for NAK-feedback 00052 unsigned long block_hi; // highest block number requested 00053 double RspBackoffWindow; // length of backoff-interval that receivers 00054 // are supposed to use when generating a random time (from a uniform 00055 // distribution) before (potentially) sending NACKs. 00056 } statReq; 00057 class Nak { // PDU_NAK: 00058 public: 00059 unsigned long pass_nb; 00060 unsigned long block_nb; 00061 unsigned long nak_count; 00062 // the actual nak-bitmap will be found in a variable length field that 00063 // is dynamically allocated. 00064 } nak; 00065 } spec; 00066 00067 // Header access methods 00068 static int offset_; // required by PacketHeaderManager 00069 inline static int& offset() { return offset_; } 00070 inline static hdr_mftp* access(const Packet* p) { 00071 return (hdr_mftp*) p->access(offset_); 00072 } 00073 }; 00074 00075 class MFTPAgent : public Agent { 00076 protected: 00077 MFTPAgent(); 00078 int init(); 00079 00080 // the following variables are read/write from within a tcl-script: 00081 int dtuSize_; 00082 int fileSize_; 00083 int dtusPerBlock_; 00084 int dtusPerGroup_; 00085 int seekCount_; 00086 00087 // the following variables are not accessible from tcl-scripts: 00088 unsigned long FileSize; // size of file of this transfer 00089 unsigned long FileDGrams; // number of datagrams in this transfer 00090 unsigned long dtu_size; // number of data bytes in a DTU 00091 unsigned long dtus_per_block; // number of DTUs per block 00092 unsigned long dtus_per_group; // number of DTUs per group 00093 unsigned long nb_groups; // number of groups the file consists of 00094 00095 unsigned long nb_blocks() const; 00096 unsigned long get_dtus_per_group(unsigned long group_nb) const; 00097 }; 00098 00099 inline unsigned long MFTPAgent::nb_blocks() const 00100 { 00101 return (nb_groups+dtus_per_block-1)/dtus_per_block; 00102 } 00103 00104 inline unsigned long MFTPAgent::get_dtus_per_group(unsigned long group_nb) const 00105 { 00106 assert(0 <= group_nb && group_nb < nb_groups); 00107 assert(nb_groups > 0); 00108 00109 unsigned long res = FileDGrams / nb_groups; 00110 00111 if(group_nb < FileDGrams % nb_groups) { 00112 res++; 00113 } 00114 assert(0 <= res && res <= dtus_per_group); 00115 assert(res == 0 || FileDGrams > 0); 00116 return res; 00117 } 00118 00119 #endif
1.3.3