00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1996-1997 The Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Network Research 00017 * Group at Lawrence Berkeley National Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/queue/queue.h,v 1.35 2005/01/13 18:33:48 haldar Exp $ (LBL) 00035 */ 00036 00037 #ifndef ns_queue_h 00038 #define ns_queue_h 00039 00040 #include "connector.h" 00041 #include "packet.h" 00042 #include "ip.h" 00043 class Packet; 00044 00045 class PacketQueue : public TclObject { 00046 public: 00047 PacketQueue() : head_(0), tail_(0), len_(0), bytes_(0) {} 00048 virtual int length() const { return (len_); } 00049 virtual int byteLength() const { return (bytes_); } 00050 virtual Packet* enque(Packet* p) { // Returns previous tail 00051 Packet* pt = tail_; 00052 if (!tail_) head_= tail_= p; 00053 else { 00054 tail_->next_= p; 00055 tail_= p; 00056 } 00057 tail_->next_= 0; 00058 ++len_; 00059 bytes_ += hdr_cmn::access(p)->size(); 00060 return pt; 00061 } 00062 virtual Packet* deque() { 00063 if (!head_) return 0; 00064 Packet* p = head_; 00065 head_= p->next_; // 0 if p == tail_ 00066 if (p == tail_) head_= tail_= 0; 00067 --len_; 00068 bytes_ -= hdr_cmn::access(p)->size(); 00069 return p; 00070 } 00071 Packet* lookup(int n) { 00072 for (Packet* p = head_; p != 0; p = p->next_) { 00073 if (--n < 0) 00074 return (p); 00075 } 00076 return (0); 00077 } 00078 /* remove a specific packet, which must be in the queue */ 00079 virtual void remove(Packet*); 00080 /* Remove a packet, located after a given packet. Either could be 0. */ 00081 void remove(Packet *, Packet *); 00082 Packet* head() { return head_; } 00083 Packet* tail() { return tail_; } 00084 // MONARCH EXTNS 00085 virtual inline void enqueHead(Packet* p) { 00086 if (!head_) tail_ = p; 00087 p->next_ = head_; 00088 head_ = p; 00089 ++len_; 00090 bytes_ += hdr_cmn::access(p)->size(); 00091 } 00092 void resetIterator() {iter = head_;} 00093 Packet* getNext() { 00094 if (!iter) return 0; 00095 Packet *tmp = iter; iter = iter->next_; 00096 return tmp; 00097 } 00098 00099 protected: 00100 Packet* head_; 00101 Packet* tail_; 00102 int len_; // packet count 00103 int bytes_; // queue size in bytes 00104 00105 00106 // MONARCH EXTNS 00107 private: 00108 Packet *iter; 00109 }; 00110 00111 class Queue; 00112 00113 class QueueHandler : public Handler { 00114 public: 00115 inline QueueHandler(Queue& q) : queue_(q) {} 00116 void handle(Event*); 00117 private: 00118 Queue& queue_; 00119 }; 00120 00121 00122 class Queue : public Connector { 00123 public: 00124 virtual void enque(Packet*) = 0; 00125 virtual Packet* deque() = 0; 00126 virtual void recv(Packet*, Handler*); 00127 virtual void updateStats(int queuesize); 00128 void resume(); 00129 00130 int blocked() const { return (blocked_ == 1); } 00131 void unblock() { blocked_ = 0; } 00132 void block() { blocked_ = 1; } 00133 int limit() { return qlim_; } 00134 int length() { return pq_->length(); } /* number of pkts currently in 00135 * underlying packet queue */ 00136 int byteLength() { return pq_->byteLength(); } /* number of bytes * 00137 * currently in packet queue */ 00138 /* mean utilization, decaying based on util_weight */ 00139 virtual double utilization (void); 00140 00141 /* max utilization over recent time period. 00142 Returns the maximum of recent measurements stored in util_buf_*/ 00143 double peak_utilization(void); 00144 virtual ~Queue(); 00145 protected: 00146 Queue(); 00147 void reset(); 00148 int qlim_; /* maximum allowed pkts in queue */ 00149 int blocked_; /* blocked now? */ 00150 int unblock_on_resume_; /* unblock q on idle? */ 00151 QueueHandler qh_; 00152 PacketQueue *pq_; /* pointer to actual packet queue 00153 * (maintained by the individual disciplines 00154 * like DropTail and RED). */ 00155 double true_ave_; /* true long-term average queue size */ 00156 double total_time_; /* total time average queue size compute for */ 00157 00158 00159 void utilUpdate(double int_begin, double int_end, int link_state); 00160 double last_change_; /* time at which state changed/utilization measured */ 00161 double old_util_; /* current utilization */ 00162 double util_weight_; /* decay factor for measuring the link utilization */ 00163 double util_check_intv_; /* interval for reseting the current 00164 utilization measurements (seconds) */ 00165 double period_begin_; /* time of starting the current utilization 00166 measurement */ 00167 double cur_util_; /* utilization during current time period */ 00168 int buf_slot_; /* Currently active utilization buffer */ 00169 double *util_buf_; /* Buffer for recent utilization measurements */ 00170 int util_records_; /* Number of recent utilization measurements 00171 stored in memory. One slot in buffer holds 00172 period of util_check_intv_ seconds. */ 00173 // measuring #drops 00174 00175 }; 00176 00177 #endif
1.4.6