00001 #include "agg-spec.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
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
00164 }
00165