From: Richard Whitehouse Date: Sat, 7 May 2011 17:16:58 +0000 (+0100) Subject: Added ability to output Ethernet state X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=e2f0a754e91d0298ce39675cc2f0b774fb84eac0;p=ns-moose.git Added ability to output Ethernet state --- diff --git a/src/simulation/simulation.cc b/src/simulation/simulation.cc index ae14f48..3e49af2 100644 --- a/src/simulation/simulation.cc +++ b/src/simulation/simulation.cc @@ -30,6 +30,27 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("MooseSimulation"); +void capture_state(std::ostream& file, LinkLayerHelper::Network& n){ + + file << "ns-moose" << std::endl; // MAGIC + file << 3 << std::endl; // Type + file << 1 << std::endl; // Version + + std::map::iterator i; + NetDeviceContainer::Iterator j; + + Ptr bridge; + + for(i = n.bridges.begin(); i != n.bridges.end(); ++i){ + for(j = i->second.Begin(); j != i->second.End(); ++j){ + bridge = (*j)->GetObject(); + if(bridge != NULL){ + file << *bridge << std::endl; + } + } + } +} + void setup(LinkLayerHelper::Network& n, Topology& t, std::istream& file){ uint16_t port = 9; // Discard port (RFC 863) @@ -112,6 +133,7 @@ try { std::string ipTraceFile; std::string networkFile; std::string dataFile; + std::string stateFile; std::string linkLayer = "moose"; CommandLine cmd; // Allow CommandLine args @@ -121,6 +143,7 @@ try { cmd.AddValue("ip", "IPv4 Trace File", ipTraceFile); cmd.AddValue("network", "Network Topology File", networkFile); cmd.AddValue("data", "Network Data File", dataFile); + cmd.AddValue("state", "Bridge State File", stateFile); cmd.Parse (argc, argv); std::ifstream networkStream(networkFile.c_str(), std::ifstream::in); @@ -194,6 +217,11 @@ try { NS_LOG_INFO ("Run Simulation"); Simulator::Run (); + if(stateFile != ""){ + std::ofstream stateStream(stateFile.c_str(), std::ios_base::out | std::ios_base::trunc); + capture_state(stateStream, n); + } + NS_LOG_INFO ("Destroy Simulation"); Simulator::Destroy ();