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

agg-spec.cc

Go to the documentation of this file.
00001 #include "agg-spec.h"
00002 
00003 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00004 /*
00005  * Copyright (c) 2000  International Computer Science Institute
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. All advertising materials mentioning features or use of this software
00017  *    must display the following acknowledgement:
00018  *      This product includes software developed by ACIRI, the AT&T 
00019  *      Center for Internet Research at ICSI (the International Computer
00020  *      Science Institute).
00021  * 4. Neither the name of ACIRI nor of ICSI may be used
00022  *    to endorse or promote products derived from this software without
00023  *    specific prior written permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
00026  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028  * ARE DISCLAIMED.  IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
00029  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00031  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00032  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00034  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00035  * SUCH DAMAGE.
00036  *
00037  * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/pushback/agg-spec.cc,v 1.6 2001/01/20 21:41:45 sfloyd Exp $ (ACIRI)
00038  */
00039 
00040 #include "ip.h"
00041 #include "ident-tree.h"
00042 
00043 AggSpec::AggSpec(int dstON, int dstPrefix, int dstBits) {
00044 
00045   dstON_ = dstON;
00046   dstPrefix_ = dstPrefix;
00047   dstBits_ = dstBits;
00048   
00049   ptype_=-1;
00050   ptypeShare_=0;
00051 }
00052 
00053 AggSpec::AggSpec(AggSpec * orig) {
00054   dstON_ = orig->dstON_;
00055   dstPrefix_ = orig->dstPrefix_;
00056   dstBits_ = orig->dstBits_;
00057 
00058   ptype_ = orig->ptype_;
00059   ptypeShare_=orig->ptypeShare_;
00060 }
00061 
00062 int
00063 AggSpec::member(Packet * pkt) {
00064   
00065   hdr_ip * iph = hdr_ip::access(pkt);
00066   ns_addr_t dst = iph->dst();
00067   int fid = iph->flowid();
00068 
00069   if (dstON_) {
00070     int prefix;
00071     if (AGGREGATE_CLASSIFICATION_MODE_FID) 
00072       prefix = getPrefix(fid);
00073     else 
00074       prefix = getPrefix(dst.addr_);
00075 
00076     if (prefix == dstPrefix_) {
00077       return 1;
00078     }
00079   }
00080 
00081 #ifdef DEBUG_AS
00082   printf("AS: non-member packet with dst %d at %g. Agg: ", dst.addr_, Scheduler::instance().clock());
00083   print();
00084 #endif
00085   return 0;
00086 }
00087 
00088 int 
00089 AggSpec::getPrefix(int addr) {
00090   
00091   int andAgent = ((1 << dstBits_) - 1) << (NO_BITS - dstBits_);
00092   return (addr &  andAgent);
00093 }
00094  
00095 int 
00096 AggSpec::equals(AggSpec * another) {
00097   
00098   return (dstON_ == another->dstON_ && dstPrefix_ == another->dstPrefix_ && 
00099           dstBits_ == another->dstBits_);
00100 }
00101 
00102 int 
00103 AggSpec::contains(AggSpec * another) {
00104   
00105   if (another->dstBits_ < dstBits_) return 0; 
00106   if (dstON_ != another->dstON_) return 0;
00107 
00108   int prefix1 = PrefixTree::getPrefixBits(dstPrefix_, dstBits_);
00109   int prefix2 = PrefixTree::getPrefixBits(another->dstPrefix_, dstBits_);
00110   
00111   return (prefix1 == prefix2);
00112 }
00113 
00114 void 
00115 AggSpec::expand(int prefix, int bits) {
00116   
00117   dstPrefix_ = prefix;
00118   dstBits_ = bits;
00119 }
00120 
00121 int 
00122 AggSpec::subsetOfDst(int prefix, int bits) {
00123   
00124   if (!dstON_ || dstBits_ < bits) return 0;
00125 
00126   int myPrefix = PrefixTree::getPrefixBits(dstPrefix_, bits);
00127   return (prefix==myPrefix);
00128 }
00129 
00130 AggSpec *
00131 AggSpec::clone() {
00132   return new AggSpec(this);
00133 }
00134 
00135 int 
00136 AggSpec::getSampleAddress() {
00137   
00138   //for now, return the prefix itself
00139   if (AGGREGATE_CLASSIFICATION_MODE_FID) 
00140     return 1;
00141   else 
00142     return dstPrefix_;
00143 }
00144 
00145 int 
00146 AggSpec::prefixBitsForMerger(AggSpec * agg1, AggSpec * agg2) {
00147   
00148   int bitsNow = (agg1->dstBits_ < agg2->dstBits_)? agg1->dstBits_: agg2->dstBits_;
00149   for (int i=bitsNow; i>=0; i--) {
00150     int prefix1 = PrefixTree::getPrefixBits(agg1->dstPrefix_, i);
00151     int prefix2 = PrefixTree::getPrefixBits(agg2->dstPrefix_, i);
00152     if (prefix1==prefix2) {
00153       return i;
00154     }
00155   }
00156 
00157   printf("AS: Error: Should never come here\n");
00158   exit(-1);
00159 }
00160 
00161 void 
00162 AggSpec::print() {
00163   //printf("Prefix = %d Bits = %d\n", dstPrefix_, dstBits_);
00164 }
00165   

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