00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1997 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 Computer Systems 00017 * Engineering Group at Lawrence Berkeley 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 /* Ported from CMU/Monarch's code*/ 00035 00036 /* -*- c++ -*- 00037 rexmit_queue.h 00038 $Id: dest_queue.h,v 1.3 2000/08/17 00:03:38 haoboy Exp $ 00039 */ 00040 00041 #ifndef __dest_queue_h__ 00042 #define __dest_queue_h__ 00043 00044 #include <packet.h> 00045 #include "lib/bsd-list.h" 00046 00047 #define ILLEGAL_SEQ 257 00048 00049 typedef double Time; 00050 00051 class txent; 00052 class dstent; 00053 class imepAgent; 00054 00056 // Transmit Queue Entry 00057 class txent { 00058 friend class dstent; 00059 friend class dstQueue; 00060 protected: 00061 txent(double e, u_int32_t s, Packet *p); 00062 00063 LIST_ENTRY(txent) link; 00064 // public so that I can use the list macros 00065 00066 double expire() { return expire_; } 00067 u_int32_t seqno() { return seqno_; } 00068 Packet *pkt() { return pkt_; } 00069 00070 private: 00071 double expire_; // time "p" expires and must be sent 00072 u_int32_t seqno_; // sequence number of the packet "p". 00073 Packet *pkt_; 00074 }; 00075 00076 LIST_HEAD(txent_head, txent); 00077 00079 // Destination Queue Entry 00080 class dstent { 00081 friend class dstQueue; 00082 protected: 00083 dstent(nsaddr_t index); 00084 00085 LIST_ENTRY(dstent) link; 00086 00087 void addEntry(double e, u_int32_t s, Packet *p); 00088 // add's a packet to the txentHead list. 00089 00090 void delEntry(txent *t); 00091 // remove's a packet (transmit entry) from the txentHead list. 00092 00093 txent* findEntry(u_int32_t s); 00094 // locates a packet with sequence "s" in the txentHead list. 00095 txent* findFirstEntry(void); 00096 00097 nsaddr_t ipaddr() { return ipaddr_; } 00098 u_int32_t& seqno() { return seqno_; } 00099 00100 inline double expire() { 00101 txent *t; 00102 double min = 0.0; 00103 00104 for(t = txentHead.lh_first; t; t = t->link.le_next) { 00105 if(min == 0.0 || (t->expire() && t->expire() < min)) 00106 min = t->expire(); 00107 } 00108 return min; 00109 } 00110 private: 00111 nsaddr_t ipaddr_; // ip address of this destination 00112 txent_head txentHead; // sorted by sequence number 00113 u_int32_t seqno_; // last sequence number sent up the stack 00114 }; 00115 00116 LIST_HEAD(dstend_head, dstent); 00117 00119 // Destination Queue 00120 class dstQueue { 00121 public: 00122 dstQueue(imepAgent *a, nsaddr_t index); 00123 00124 void addEntry(nsaddr_t dst, double e, u_int32_t s, Packet *p); 00125 // add's a packet to the list. 00126 00127 Packet* getPacket(nsaddr_t dst, u_int32_t seqno); 00128 // returns the packet with the following sequence nubmer "seqno".` 00129 // removes packet from queue 00130 00131 Time getNextExpire(); 00132 // returns the time that the next packet will expire. 00133 00134 Packet* getNextPacket(u_int32_t& seqno); 00135 // returns "expired" packets (in sequence order, if any). 00136 00137 void deleteDst(nsaddr_t dst); 00138 // remove and free all packets from dst 00139 00140 void dumpAll(void); 00141 00142 private: 00143 dstent* findEntry(nsaddr_t dst); 00144 00145 dstend_head dstentHead; // head of the destination list 00146 imepAgent *agent_; 00147 nsaddr_t ipaddr_; 00148 }; 00149 00150 #endif // __dest_queue_h__