plugins.topology: Adding basic error handling
diff --git a/plugins/topology/annotated-topology-reader.cc b/plugins/topology/annotated-topology-reader.cc
index 334d81a..d62c6b5 100644
--- a/plugins/topology/annotated-topology-reader.cc
+++ b/plugins/topology/annotated-topology-reader.cc
@@ -132,9 +132,9 @@
ifstream topgen;
topgen.open (GetFileName ().c_str ());
- if ( !topgen.is_open () )
+ if ( !topgen.is_open () || !topgen.good () )
{
- NS_LOG_ERROR ("Cannot open file " << GetFileName () << " for reading");
+ NS_FATAL_ERROR ("Cannot open file " << GetFileName () << " for reading");
return m_nodes;
}
@@ -146,6 +146,12 @@
if (line == "router") break;
}
+ if (topgen.eof ())
+ {
+ NS_FATAL_ERROR ("Topology file " << GetFileName () << " does not have \"router\" section");
+ return m_nodes;
+ }
+
while (!topgen.eof ())
{
string line;
@@ -166,6 +172,12 @@
map<string, set<string> > processedLinks; // to eliminate duplications
+ if (topgen.eof ())
+ {
+ NS_FATAL_ERROR ("Topology file " << GetFileName () << " does not have \"link\" section");
+ return m_nodes;
+ }
+
// SeekToSection ("link");
while (!topgen.eof ())
{