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.31 2002/12/18 03:36:37 sundarra 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 int blocked() const { return (blocked_ == 1); } 00130 void unblock() { blocked_ = 0; } 00131 void block() { blocked_ = 1; } 00132 int limit() { return qlim_; } 00133 int length() { return pq_->length(); } /* number of pkts currently in 00134 * underlying packet queue */ 00135 int byteLength() { return pq_->byteLength(); } /* number of bytes * 00136 * currently in packet queue */ 00137 virtual double utilization (void); 00138 protected: 00139 Queue(); 00140 ~Queue(); 00141 void reset(); 00142 int qlim_; /* maximum allowed pkts in queue */ 00143 int blocked_; /* blocked now? */ 00144 int unblock_on_resume_; /* unblock q on idle? */ 00145 QueueHandler qh_; 00146 PacketQueue *pq_; /* pointer to actual packet queue 00147 * (maintained by the individual disciplines 00148 * like DropTail and RED). */ 00149 double true_ave_; /* true long-term average queue size */ 00150 double total_time_; /* total time average queue size compute for */ 00151 00152 00153 void utilUpdate(double int_begin, double int_end, int link_state); 00154 double last_change_; /* time at which state changed/utilization measured */ 00155 double old_util_; /* current utilization */ 00156 double util_weight_; /* decay factor for measuring the link utilization */ 00157 }; 00158 00159 #endif
1.3.3