From: Richard Whitehouse Date: Wed, 18 May 2011 14:12:11 +0000 (+0100) Subject: State analysis X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=7ae3870e061812142cd3e9549e838a84d6ce09ad;p=ns-moose.git State analysis --- diff --git a/src/simulation/model/analysis.cc b/src/simulation/model/analysis.cc index 4dfab8a..cd1c85f 100644 --- a/src/simulation/model/analysis.cc +++ b/src/simulation/model/analysis.cc @@ -34,8 +34,12 @@ Analysis::Analysis(std::istream& topology, std::istream& data, std::istream& csm parseCsma(); + parseState(); + analyseCsma(); + analyseState(); + generateDot(); } @@ -93,6 +97,126 @@ void Analysis::parseCsma(){ } } +void Analysis::parseState(){ + std::string line; + long size; + + getline(state, line); + assert(line == "ns-moose"); // MAGIC + + getline(state, line); + assert(line == "3"); // TYPE + + getline(state, line); + assert(line == "1"); // VERSION + + do { + getline(state, line); // LINK TYPE + } while(line == ""); + + while(!state.eof()){ + + assert( (line == "1" && !moose) || (line == "2" && moose) ); + + stateParse *sp; + + if(moose){ + mooseStateParse *msp = new mooseStateParse; + + getline(state, msp->mac); + getline(state, msp->moose); + + getline(state, line); // Size + + { + std::stringstream sline(line); + sline >> size; + } + + for(; size > 0; size --){ + switchParse sp; + getline(state, sp.prefix); + getline(state, sp.port); + getline(state, sp.time); + msp->switches.push_back(sp); + } + + getline(state, line); // Size + + { + std::stringstream sline(line); + sline >> size; + } + + + for(; size > 0; size --){ + hostParse hp; + getline(state, hp.mac); + getline(state, hp.suffix); + getline(state, hp.port); + getline(state, hp.time); + msp->hosts.push_back(hp); + } + + sp = msp; + + } else { + ethStateParse *esp = new ethStateParse; + + getline(state, esp->mac); // MAC + + getline(state, line); // Size + + { + std::stringstream sline(line); + sline >> size; + } + + for(; size > 0; size --){ + entryParse ep; + getline(state, ep.mac); + getline(state, ep.port); + getline(state, ep.time); + esp->entries.push_back(ep); + } + + sp = esp; + } + + states.push_back(sp); + + do { + getline(state, line); // LINK TYPE + } while(line == "" && !state.eof()); + } +} + +void Analysis::analyseState(){ + + output << "State Table " << std::endl; + + for(std::vector::iterator it = states.begin(); it != states.end(); ++it){ + + if(moose){ + mooseStateParse *msp = (mooseStateParse *) *it; + output << "\t" << msp->moose << std::endl + << "\t\t Hosts \t" << msp->hosts.size() << std::endl + << "\t\t Switches \t" << msp->switches.size() << std::endl + << "\t\t Total \t" << (msp->hosts.size() + msp->switches.size()) << std::endl + << std::endl; + } else { + ethStateParse *esp = (ethStateParse *)*it; + output << "\t" << esp->mac << std::endl + << "\t\t Entries \t" << esp->entries.size() << std::endl + << std::endl; + } + + } + + output << std::endl; + +} + void Analysis::analyseCsmaType(csmaParse& parse, csmaAnalysis& analysis){ if(parse.type == "+"){ ++(analysis.added); @@ -164,6 +288,7 @@ std::ostream& operator<<(std::ostream& file, Analysis::csmaAnalysis& analysis){ return file; } + void Analysis::parseCsmaLine(std::string& line){ csmaParse parse; size_t spaa, spab, spac, spad; diff --git a/src/simulation/model/analysis.h b/src/simulation/model/analysis.h index 2902c17..10d42ce 100644 --- a/src/simulation/model/analysis.h +++ b/src/simulation/model/analysis.h @@ -45,9 +45,14 @@ public: protected: void generateDot(); + void analyseCsma(); + void analyseState(); + void printCsma(); + void parseCsma(); + void parseState(); private: @@ -81,6 +86,38 @@ private: csmaAnalysis total; }; + struct stateParse { + std::string mac; + }; + + struct entryParse { + std::string mac; + std::string port; + std::string time; + }; + + struct switchParse { + std::string prefix; + std::string port; + std::string time; + }; + + struct hostParse { + std::string mac; + std::string suffix; + std::string port; + std::string time; + }; + + struct ethStateParse : public stateParse { + std::vector entries; + }; + + struct mooseStateParse : public stateParse { + std::string moose; + std::vector hosts; + std::vector switches; + }; csmaArpAnalysis arp; csmaAnalysis udp; @@ -89,6 +126,8 @@ private: csmaAnalysis broadcast; csmaAnalysis unicast; + std::vector states; + std::vector traces; Topology topology;