00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * classifier-port.cc 00004 * Copyright (C) 1999 by USC/ISI 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms are permitted 00008 * provided that the above copyright notice and this paragraph are 00009 * duplicated in all such forms and that any documentation, advertising 00010 * materials, and other materials related to such distribution and use 00011 * acknowledge that the software was developed by the University of 00012 * Southern California, Information Sciences Institute. The name of the 00013 * University may not be used to endorse or promote products derived from 00014 * this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00019 * 00020 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-port.cc,v 1.7 2001/12/20 00:15:33 haldar Exp $ (USC/ISI) 00021 */ 00022 00023 #ifndef lint 00024 static const char rcsid[] = 00025 "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/classifier/classifier-port.cc,v 1.7 2001/12/20 00:15:33 haldar Exp $"; 00026 #endif 00027 00028 #include "classifier-port.h" 00029 00030 int PortClassifier::classify(Packet *p) 00031 { 00032 // Port classifier returns the destination port. No shifting 00033 // or masking is required since in the 32-bit addressing, 00034 // ports are stored in a seperate variable. 00035 hdr_ip* iph = hdr_ip::access(p); 00036 return iph->dport(); 00037 }; 00038 00039 static class PortClassifierClass : public TclClass { 00040 public: 00041 PortClassifierClass() : TclClass("Classifier/Port") {} 00042 TclObject* create(int, const char*const*) { 00043 return (new PortClassifier()); 00044 } 00045 } class_address_classifier; 00046 00047 static class ReservePortClassifierClass : public TclClass { 00048 public: 00049 ReservePortClassifierClass() : TclClass("Classifier/Port/Reserve") {} 00050 TclObject* create(int, const char*const*) { 00051 return (new ReservePortClassifier()); 00052 } 00053 } class_reserve_port_classifier; 00054 00055 int ReservePortClassifier::command(int argc, const char*const* argv) 00056 { 00057 if (argc == 3 && strcmp(argv[1],"reserve-port") == 0) { 00058 reserved_ = atoi(argv[2]); 00059 alloc((maxslot_ = reserved_ - 1)); 00060 return(TCL_OK); 00061 } 00062 return (Classifier::command(argc, argv)); 00063 } 00064 00065 void ReservePortClassifier::clear(int slot) 00066 { 00067 slot_[slot] = 0; 00068 if (slot == maxslot_) { 00069 while (--maxslot_ >= reserved_ && slot_[maxslot_] == 0) 00070 ; 00071 } 00072 } 00073 00074 int ReservePortClassifier::getnxt(NsObject *nullagent) 00075 { 00076 int i; 00077 for (i=reserved_; i < nslot_; i++) 00078 if (slot_[i]==0 || slot_[i]==nullagent) 00079 return i; 00080 i=nslot_; 00081 alloc(nslot_); 00082 return i; 00083 } 00084
1.3.3