00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) Xerox Corporation 1997. All rights reserved. 00004 * 00005 * This program is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU General Public License as published by the 00007 * Free Software Foundation; either version 2 of the License, or (at your 00008 * option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * Linking this file statically or dynamically with other modules is making 00020 * a combined work based on this file. Thus, the terms and conditions of 00021 * the GNU General Public License cover the whole combination. 00022 * 00023 * In addition, as a special exception, the copyright holders of this file 00024 * give you permission to combine this file with free software programs or 00025 * libraries that are released under the GNU LGPL and with code included in 00026 * the standard release of ns-2 under the Apache 2.0 license or under 00027 * otherwise-compatible licenses with advertising requirements (or modified 00028 * versions of such code, with unchanged license). You may copy and 00029 * distribute such a system following the terms of the GNU GPL for this 00030 * file and the licenses of the other code concerned, provided that you 00031 * include the source code of that other code when and as the GNU GPL 00032 * requires distribution of source code. 00033 * 00034 * Note that people who make modified versions of this file are not 00035 * obligated to grant this special exception for their modified versions; 00036 * it is their choice whether to do so. The GNU General Public License 00037 * gives permission to release a modified version without this exception; 00038 * this exception also makes it possible to release a modified version 00039 * which carries forward this exception. 00040 */ 00041 00042 /* 00043 * Copyright (c) 1994 Regents of the University of California. 00044 * All rights reserved. 00045 * 00046 * Redistribution and use in source and binary forms, with or without 00047 * modification, are permitted provided that the following conditions 00048 * are met: 00049 * 1. Redistributions of source code must retain the above copyright 00050 * notice, this list of conditions and the following disclaimer. 00051 * 2. Redistributions in binary form must reproduce the above copyright 00052 * notice, this list of conditions and the following disclaimer in the 00053 * documentation and/or other materials provided with the distribution. 00054 * 3. All advertising materials mentioning features or use of this software 00055 * must display the following acknowledgement: 00056 * This product includes software developed by the Computer Systems 00057 * Engineering Group at Lawrence Berkeley Laboratory. 00058 * 4. Neither the name of the University nor of the Laboratory may be used 00059 * to endorse or promote products derived from this software without 00060 * specific prior written permission. 00061 * 00062 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00063 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00064 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00065 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00066 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00067 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00068 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00069 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00070 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00071 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00072 * SUCH DAMAGE. 00073 */ 00074 00075 #ifndef lint 00076 static const char rcsid[] = 00077 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/adc/simple-intserv-sched.cc,v 1.7 2005/08/26 05:05:28 tomh Exp $ (LBL)"; 00078 #endif 00079 00080 00081 //Simple scheduler with 2 service priority levels and protects signalling 00082 //ctrl packets 00083 00084 00085 #include "config.h" 00086 #include "queue.h" 00087 00088 #define CLASSES 2 00089 00090 class SimpleIntServ : public Queue { 00091 public: 00092 SimpleIntServ() { 00093 int i; 00094 char buf[10]; 00095 for (i=0;i<CLASSES;i++) { 00096 q_[i] = new PacketQueue; 00097 qlimit_[i] = 0; 00098 sprintf(buf,"qlimit%d_",i); 00099 bind(buf,&qlimit_[i]); 00100 } 00101 } 00102 protected : 00103 void enque(Packet *); 00104 Packet *deque(); 00105 PacketQueue *q_[CLASSES]; 00106 int qlimit_[CLASSES]; 00107 }; 00108 00109 00110 static class SimpleIntServClass : public TclClass { 00111 public: 00112 SimpleIntServClass() : TclClass("Queue/SimpleIntServ") {} 00113 TclObject* create(int, const char*const*) { 00114 return (new SimpleIntServ); 00115 } 00116 } class_simple_intserv; 00117 00118 void SimpleIntServ::enque(Packet* p) 00119 { 00120 00121 hdr_ip* iph=hdr_ip::access(p); 00122 int cl=(iph->flowid()) ? 1:0; 00123 00124 if (q_[cl]->length() >= (qlimit_[cl]-1)) { 00125 hdr_cmn* ch=hdr_cmn::access(p); 00126 packet_t ptype = ch->ptype(); 00127 if ( (ptype != PT_REQUEST) && (ptype != PT_REJECT) && (ptype != PT_ACCEPT) && (ptype != PT_CONFIRM) && (ptype != PT_TEARDOWN) ) { 00128 drop(p); 00129 } 00130 else { 00131 q_[cl]->enque(p); 00132 } 00133 } 00134 else { 00135 q_[cl]->enque(p); 00136 } 00137 } 00138 00139 00140 Packet *SimpleIntServ::deque() 00141 { 00142 int i; 00143 for (i=CLASSES-1;i>=0;i--) 00144 if (q_[i]->length()) 00145 return q_[i]->deque(); 00146 return 0; 00147 } 00148
1.4.6