State analysis analysis
authorRichard Whitehouse <github@richardwhiuk.com>
Wed, 18 May 2011 14:12:11 +0000 (15:12 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Wed, 18 May 2011 14:12:11 +0000 (15:12 +0100)
src/simulation/model/analysis.cc
src/simulation/model/analysis.h

index 4dfab8a03e74e997ea2f856cd49ddb4e5487fbd7..cd1c85f497a3f911ba3f6b2dab4e3865ebb72362 100644 (file)
@@ -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<stateParse*>::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;
index 2902c170a2cf1cb7d91364db45aeca2c24601c60..10d42ce906a4d93f01a10c45153090cc67743c0b 100644 (file)
@@ -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<entryParse> entries;
+       };
+
+       struct mooseStateParse : public stateParse {
+               std::string moose;
+               std::vector<hostParse> hosts;
+               std::vector<switchParse> switches;
+       };
 
        csmaArpAnalysis arp;
        csmaAnalysis udp;
@@ -89,6 +126,8 @@ private:
        csmaAnalysis broadcast;
        csmaAnalysis unicast;
 
+       std::vector<stateParse*> states;
+
        std::vector<csmaParse> traces;
 
        Topology topology;