14 StatsModule::StatsModule(
int maxStats1,
int maxLnk1,
int maxQ1,
16 : maxStats(maxStats1), maxLnk(maxLnk1), maxQ(maxQ1),
18 stat =
new StatItem[maxStats+1];
19 lnkCnts =
new LinkCounts[maxLnk+1];
20 qCnts =
new QueueCounts[maxQ+1];
21 for (
int i = 1; i <= maxLnk; i++) {
22 lnkCnts[i].inByte = lnkCnts[i].outByte = 0;
23 lnkCnts[i].inPkt = lnkCnts[i].outPkt = 0;
24 lnkCnts[i].numPkt = 0;
26 for (
int i = 1; i <= maxQ; i++) {
27 qCnts[i].bytLen = qCnts[i].pktLen = 0;
30 totInByte = 0; totInPkt = 0; totDiscards = 0;
31 rtrInByte = 0; rtrInPkt = 0;
32 leafInByte = 0; leafInPkt = 0;
33 totOutByte = 0; totOutPkt = 0;
34 rtrOutByte = 0; rtrOutPkt = 0; rtrDiscards = 0;
35 leafOutByte = 0; leafOutPkt = 0; leafDiscards = 0;
38 StatsModule::~StatsModule() {
delete [] stat; }
40 void StatsModule::record(uint64_t now) {
42 int i, val, cLnk, qid;
48 string fname =
"statsSwitch";
49 ifstream sfs; sfs.open(fname.c_str());
51 if (sfs.fail())
return;
56 for (i = 1; i <= n; i++) {
57 StatItem& s = stat[i];
60 if (s.lnk == 0) val = totInPkt;
61 else if (s.lnk == -1) val = rtrInPkt;
62 else if (s.lnk == -2) val = leafInPkt;
63 else val = lnkCnts[s.lnk].inPkt;
66 if (s.lnk == 0) val = totOutPkt;
67 else if (s.lnk == -1) val = rtrOutPkt;
68 else if (s.lnk == -2) val = leafOutPkt;
69 else val = lnkCnts[s.lnk].outPkt;
72 if (s.lnk == 0) val = totInByte;
73 else if (s.lnk == -1) val = rtrInByte;
74 else if (s.lnk == -2) val = leafInByte;
75 else val = lnkCnts[s.lnk].inByte;
78 if (s.lnk == 0) val = totOutByte;
79 else if (s.lnk == -1) val = rtrOutByte;
80 else if (s.lnk == -2) val = leafOutByte;
81 else val = lnkCnts[s.lnk].outByte;
85 val = getLinkQlen(s.lnk);
110 fs << double(now)/1000000000 << endl;
143 cntrTyp typ;
string typStr, fname;
148 if (typStr ==
"inPkt") typ = inPkt;
149 else if (typStr ==
"outPkt") typ = outPkt;
150 else if (typStr ==
"inByt") typ = inByt;
151 else if (typStr ==
"outByt") typ = outByt;
152 else if (typStr ==
"qPkt") typ = qPkt;
153 else if (typStr ==
"qByt") typ = qByt;
154 else if (typStr ==
"disc") typ = disc;
158 case inPkt:
case outPkt:
case inByt:
case outByt:
161 case qPkt:
case qByt:
case disc:
168 if (n >= maxStats)
return false;
171 StatItem& s = stat[n];
179 bool StatsModule::read(istream& in) {
189 if (
readStat(in) == Null)
return false;
191 string fname =
"stats";
192 fs.open(fname.c_str(),fstream::app);
193 if (fs.fail())
return false;
204 StatItem& si = stat[i];
207 ss <<
" inPkt " << setw(2) << si.lnk << endl;
210 ss <<
"outPkt " << setw(2) << si.lnk << endl;
213 ss <<
" inByt " << setw(2) << si.lnk << endl;
216 ss <<
"outByt " << setw(2) << si.lnk << endl;
219 ss <<
" qPkt " << setw(2) << si.lnk
220 <<
" " << setw(2) << si.comt << endl;
223 ss <<
" qByt " << setw(2) << si.lnk
224 <<
" " << setw(2) << si.comt << endl;
227 ss <<
" disc " << setw(2) << si.lnk
228 <<
" " << setw(2) << si.comt << endl;
242 for (
int i = 1; i <= n; i++) s +=
stat2string(i,s1);