Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

classifier-addr.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1996-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 MASH Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used 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 
00035 #ifndef lint
00036 static const char rcsid[] =
00037     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-addr.cc,v 1.27 2001/12/20 00:15:32 haldar Exp $";
00038 #endif
00039 
00040 #include "classifier-addr.h"
00041 
00042 int AddressClassifier::classify(Packet *p) {
00043         hdr_ip* iph = hdr_ip::access(p);
00044         return mshift(iph->daddr());
00045 };
00046 
00047 static class AddressClassifierClass : public TclClass {
00048 public:
00049         AddressClassifierClass() : TclClass("Classifier/Addr") {}
00050         TclObject* create(int, const char*const*) {
00051                 return (new AddressClassifier());
00052         }
00053 } class_address_classifier;
00054 
00055 /* added for mobileip code  Ya, 2/99*/
00056  
00057 static class ReserveAddressClassifierClass : public TclClass {
00058 public:
00059         ReserveAddressClassifierClass() : TclClass("Classifier/Addr/Reserve") {}
00060         TclObject* create(int, const char*const*) {
00061                 return (new ReserveAddressClassifier());
00062         }
00063 } class_reserve_address_classifier;
00064  
00065 int ReserveAddressClassifier::command(int argc, const char*const* argv)
00066 {
00067         // Tcl& tcl = Tcl::instance();
00068 
00069         if (argc == 3 && strcmp(argv[1],"reserve-port") == 0) {
00070                 reserved_ = atoi(argv[2]);
00071                 alloc((maxslot_ = reserved_ - 1));
00072                 return(TCL_OK);
00073         }
00074         return (AddressClassifier::command(argc, argv));
00075 }
00076  
00077 void ReserveAddressClassifier::clear(int slot)
00078 {
00079         slot_[slot] = 0;
00080         if (slot == maxslot_) {
00081                 while (--maxslot_ >= reserved_ && slot_[maxslot_] == 0)
00082                         ;
00083         }
00084 }
00085  
00086 int ReserveAddressClassifier::classify(Packet *p) {
00087                 hdr_ip* iph = hdr_ip::access(p);
00088                 return iph->dport();
00089 };
00090 
00091 int ReserveAddressClassifier::getnxt(NsObject *nullagent)
00092 {
00093         int i;
00094         for (i=reserved_; i < nslot_; i++)
00095                 if (slot_[i]==0 || slot_[i]==nullagent)
00096                         return i;
00097         i=nslot_;
00098         alloc(nslot_); 
00099         return i;
00100 }
00101 
00102 static class BcastAddressClassifierClass : public TclClass {
00103 public:
00104         BcastAddressClassifierClass() : TclClass("Classifier/Hash/Dest/Bcast") {}
00105         TclObject* create(int, const char*const*) { 
00106                 return (new BcastAddressClassifier());
00107         }
00108 } class_bcast_address_classifier;
00109  
00110 NsObject* BcastAddressClassifier::find(Packet* p)
00111 {
00112         NsObject* node = NULL;
00113         int cl = classify(p);
00114         if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0) {
00115                 if (cl == BCAST_ADDR_MASK) {
00116                         // limited broadcast; assuming no such packet
00117                         // would be delivered back to sender
00118                         return bcast_recver_;
00119                 }
00120                 if (default_target_) 
00121                         return default_target_;
00122  
00123                 /*
00124                  * Sigh.  Can't pass the pkt out to tcl because it's
00125                  * not an object.
00126                  */
00127                 Tcl::instance().evalf("%s no-slot %d", name(), cl);
00128                 /*
00129                  * Try again.  Maybe callback patched up the table.
00130                  */
00131                 cl = classify(p);
00132                 if (cl < 0 || cl >= nslot_ || (node = slot_[cl]) == 0)
00133                         return (NULL);
00134         }
00135  
00136         return (node);
00137 }
00138  
00139 int BcastAddressClassifier::command(int argc, const char*const* argv)
00140 {
00141         // Tcl& tcl = Tcl::instance();
00142 
00143         if (argc == 3 && strcmp(argv[1],"bcast-receiver") == 0) {
00144                 bcast_recver_ = (NsObject*)TclObject::lookup(argv[2]);
00145                 return(TCL_OK);
00146         }
00147         return (AddressClassifier::command(argc, argv));
00148 }
00149 

Generated on Tue Apr 20 12:14:12 2004 for NS2.26SourcesOriginal by doxygen 1.3.3