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 Daedalus 00017 * Research Group at the University of California, Berkeley. 00018 * 4. Neither the name of the University nor of the Research Group 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: /cvsroot/nsnam/ns-2/queue/semantic-packetqueue.h,v 1.9 2002/05/07 18:28:28 haldar Exp $ (UCB) 00035 */ 00036 00037 #ifndef ns_semantic_packetqueue_h 00038 #define ns_semantic_packetqueue_h 00039 00040 #include "object.h" 00041 #include "connector.h" 00042 #include "packet.h" 00043 #include "queue.h" 00044 #include "flags.h" 00045 #include "random.h" 00046 #include "tcp.h" 00047 00048 class AckReconsController; 00049 00050 /* 00051 * This flavor of PacketQueue includes several buffer management and 00052 * scheduling policies that are based on higher-layer semantics (e.g., 00053 * TCP semantics) of packets. 00054 */ 00055 class SemanticPacketQueue : public PacketQueue { 00056 public: 00057 SemanticPacketQueue(); 00058 int command(int argc, const char*const* argv); 00059 /* deque TCP acks before any other type of packet */ 00060 Packet* deque_acksfirst(); 00061 /* determine whether two packets belong to the same connection */ 00062 inline int compareFlows(hdr_ip *ip1, hdr_ip *ip2) { 00063 return ((ip1->saddr() == ip2->saddr()) && 00064 (ip1->sport() == ip2->sport()) && 00065 (ip1->daddr() == ip2->daddr()) && 00066 (ip1->dport() == ip2->dport())); 00067 } 00068 /* 00069 * When a new ack is enqued, purge older acks (as determined by the 00070 * sequence number of the ack field) from the queue. The enqued ack 00071 * remains at the tail of the queue, unless replace_head is true, in 00072 * which case the new ack takes the place of the old ack closest to 00073 * the head of the queue. 00074 */ 00075 void filterAcks(Packet *pkt, int replace_head); 00076 00077 /* check whether packet is marked */ 00078 int isMarked(Packet *p); 00079 /* pick out the index'th packet of the right kind (marked/unmarked) */ 00080 Packet *lookup(int index, int markedFlag); 00081 /* pick packet for ECN notification (either marking or dropping) */ 00082 Packet *pickPacketForECN(Packet *pkt); 00083 /* pick a packet to drop when the queue is full */ 00084 Packet *pickPacketToDrop(); 00085 00086 /* 00087 * Remove a specific packet given pointers to it and its predecessor 00088 * in the queue. p and/or pp may be NULL. 00089 */ 00090 void remove(Packet* p, Packet* pp); 00091 00092 inline Packet* head() { return head_; } 00093 00094 /* count of packets of various types */ 00095 int ack_count; /* number of TCP acks in the queue */ 00096 int data_count; /* number of non-ack packets in the queue */ 00097 int acks_to_send; /* number of ack to send in current schedule */ 00098 int marked_count_; /* number of marked packets */ 00099 int unmarked_count_; /* number of unmarked packets */ 00100 00101 /* 00102 * These indicator variables are bound in derived objects and 00103 * define queueing/scheduling polcies. 00104 */ 00105 int acksfirst_; /* deque TCP acks before any other data */ 00106 int filteracks_; /* purge old acks when new one arrives */ 00107 int reconsAcks_; /* set up queue as an ack recontructor */ 00108 int replace_head_; /* new ack should take the place of old ack 00109 closest to the head */ 00110 int priority_drop_; /* drop marked (low priority) packets first */ 00111 int random_drop_; /* pick packet to drop at random */ 00112 int random_ecn_; /* pick packet for ECN at random */ 00113 virtual Packet* deque(); 00114 Packet* enque(Packet *); // Returns prev tail 00115 virtual inline void enque_head(Packet *p) { 00116 if (len_ == 0) 00117 PacketQueue::enque(p); 00118 else { 00119 p->next_ = head_; 00120 head_ = p; 00121 ++len_; 00122 } 00123 } 00124 virtual void remove(Packet *); 00125 AckReconsController *reconsCtrl_; 00126 }; 00127 00128 #endif