import brite conf file example
authorJosh Pelkey <jpelkey@gatech.edu>
Wed, 10 Nov 2010 16:20:09 -0500
changeset 6656 e146ec678777
parent 6655 8f1b123b853c
child 6657 f603b44d3020
import brite conf file example
src/contrib/brite/brite-topology-helper.cc
src/contrib/brite/brite-topology-helper.h
src/contrib/brite/examples/brite.cc
--- a/src/contrib/brite/brite-topology-helper.cc	Wed Nov 10 15:10:52 2010 -0500
+++ b/src/contrib/brite/brite-topology-helper.cc	Wed Nov 10 16:20:09 2010 -0500
@@ -19,28 +19,298 @@
 #include "ns3/log.h"
 #include "ns3/abort.h"
 
-#include "Brite.h"
 #include "brite-topology-helper.h"
+using namespace std;
 
 namespace ns3 {
 
 BriteTopologyHelper::BriteTopologyHelper ()
-  : m_member (0)
+{
+}
+
+void 
+BriteTopologyHelper::InitSeeds(char *file_name) 
 {
+
+  ofstream last_seed_file;
+
+  /* Create Parse object */
+  Parse p(file_name);
+
+  /* Parse configuration file */
+  p.ParseSeed("PLACES", Model::s_places);
+  p.ParseSeed("CONNECT", Model::s_connect);
+  p.ParseSeed("EDGE_CONN", Model::s_edgeconn);
+  p.ParseSeed("GROUPING", Model::s_grouping);
+  p.ParseSeed("ASSIGNMENT", Model::s_assignment);
+  p.ParseSeed("BANDWIDTH", Model::s_bandwidth);
+
+  cout << "Place seed used: "  
+       << Model::s_places[0] << " "
+       << Model::s_places[1] << " "
+       << Model::s_places[2] << "\n";
+  cout << "Connect seed used: " 
+       << Model::s_connect[0] << " "
+       << Model::s_connect[1] << " "
+       << Model::s_connect[2] << "\n";
+  cout << "Edge conn seed used: " 
+       << Model::s_edgeconn[0] << " "
+       << Model::s_edgeconn[1] << " "
+       << Model::s_edgeconn[2] << "\n";
+  cout << "Grouping seed used: " 
+       << Model::s_grouping[0] << " "
+       << Model::s_grouping[1] << " "
+       << Model::s_grouping[2] << "\n";
+  cout << "Assigment seed used: " 
+       << Model::s_assignment[0] << " "
+       << Model::s_assignment[1] << " "
+       << Model::s_assignment[2] << "\n";
+  cout << "Bandwidth seed used: " 
+       << Model::s_bandwidth[0] << " "
+       << Model::s_bandwidth[1] << " "
+       << Model::s_bandwidth[2] << "\n" << flush;
+
+
+  last_seed_file.open("last_seed_file", ios::out);
+
+  if (last_seed_file.fail()) {
+    cerr << "Cannot open seed files for input/output...\n";
+    exit(0);
+  }
+  
+  last_seed_file << "PLACES"
+		 << " " << Model::s_places[0] 
+		 << " " << Model::s_places[1] 
+		 << " " << Model::s_places[2] << "\n";
+
+  last_seed_file << "CONNECT"
+		 << " " << Model::s_connect[0] 
+		 << " " << Model::s_connect[1] 
+		 << " " << Model::s_connect[2] << "\n";
+
+  last_seed_file << "EDGE_CONN"
+		 << " " << Model::s_edgeconn[0] 
+		 << " " << Model::s_edgeconn[1] 
+		 << " " << Model::s_edgeconn[2] << "\n";
+
+  last_seed_file << "GROUPING"
+		 << " " << Model::s_grouping[0] 
+		 << " " << Model::s_grouping[1] 
+		 << " " << Model::s_grouping[2] << "\n";
+
+  last_seed_file << "ASSIGNMENT"
+		 << " " << Model::s_assignment[0] 
+		 << " " << Model::s_assignment[1] 
+		 << " " << Model::s_assignment[2] << "\n";
+
+  last_seed_file << "BANDWIDTH"
+		 << " " << Model::s_bandwidth[0] 
+		 << " " << Model::s_bandwidth[1] 
+		 << " " << Model::s_bandwidth[2] << "\n";
+
+  last_seed_file.close();
+  
+}
+
+void 
+BriteTopologyHelper::OutputSeeds(char *file_name) 
+{
+
+  ofstream seed_file;
+  seed_file.open(file_name, ios::out);
+  
+  if (seed_file.fail()) {
+    cerr << "Cannot open seed files for input/output...\n";
+    exit(0);
+  }
+  
+  seed_file << "PLACES"
+	    << " " << Model::s_places[0] 
+	    << " " << Model::s_places[1] 
+	    << " " << Model::s_places[2] << "\n";
+
+  seed_file << "CONNECT"
+	    << " " << Model::s_connect[0] 
+	    << " " << Model::s_connect[1] 
+	    << " " << Model::s_connect[2] << "\n";
+
+  seed_file << "EDGE_CONN"
+	    << " " << Model::s_edgeconn[0] 
+	    << " " << Model::s_edgeconn[1] 
+	    << " " << Model::s_edgeconn[2] << "\n";
+  
+  seed_file << "GROUPING"
+	    << " " << Model::s_grouping[0] 
+	    << " " << Model::s_grouping[1] 
+	    << " " << Model::s_grouping[2] << "\n";
+
+  seed_file << "ASSIGNMENT"
+	    << " " << Model::s_assignment[0] 
+	    << " " << Model::s_assignment[1] 
+	    << " " << Model::s_assignment[2] << "\n";
+
+  seed_file << "BANDWIDTH"
+	    << " " << Model::s_bandwidth[0] 
+	    << " " << Model::s_bandwidth[1] 
+	    << " " << Model::s_bandwidth[2] << "\n";
+
+  cout << "Place seed stored: " 
+       << Model::s_places[0] << " "
+       << Model::s_places[1] << " "
+       << Model::s_places[2] << "\n";
+  cout << "Connect seed stored: " 
+       << Model::s_connect[0] << " "
+       << Model::s_connect[1] << " "
+       << Model::s_connect[2] << "\n";
+  cout << "Edge Connect seed stored: " 
+       << Model::s_edgeconn[0] << " "
+       << Model::s_edgeconn[1] << " "
+       << Model::s_edgeconn[2] << "\n";
+  cout << "Grouping seed used: " 
+       << Model::s_grouping[0] << " "
+       << Model::s_grouping[1] << " "
+       << Model::s_grouping[2] << "\n";
+  cout << "Assignment seed stored: " 
+       << Model::s_assignment[0] << " "
+       << Model::s_assignment[1] << " "
+       << Model::s_assignment[2] << "\n";
+  cout << "Bandwidth seed stored: " 
+       << Model::s_bandwidth[0] << " "
+       << Model::s_bandwidth[1] << " "
+       << Model::s_bandwidth[2] << "\n" << flush;
+  seed_file.close();
+
 }
 
 void
-BriteTopologyHelper::TestMethod (void)
+BriteTopologyHelper::ImportFile (std::string confFile, std::string outFile, std::string seedFile) 
 {
-  Topology *topology;
-  Model *model;
+  Topology* topology;
+  RouterWaxman* rt_wax_model;
+  RouterBarabasiAlbert* rt_bar_model;
+  ASWaxman* as_wax_model;
+  ASBarabasiAlbert* as_bar_model;
+  TopDownHierModel* td_model;
+  BottomUpHierModel* bu_model;
+  ImportedBriteTopologyModel* if_brite_model;
+  ImportedGTitmTopologyModel* if_gtitm_model;  
+  ImportedNLANRTopologyModel* if_nlanr_model;
+  ImportedInetTopologyModel* if_inet_model;
+
+  ModelPar* par;
+
+  /* Init seed used in generation */
+  InitSeeds(const_cast<char *>(seedFile.c_str ()));
+
+  /* Create Parse object */
+  Parse p(const_cast<char *>(confFile.c_str()));
+
+  /* Parse configuration file */
+  par = p.ParseConfigFile();
+  assert(par != NULL);
+
+  switch (par->GetModelType()) {
+  case RT_WAXMAN:
+    rt_wax_model = new RouterWaxman((RouterWaxPar*)par);
+    topology = new Topology(rt_wax_model);
+    break;
+
+  case RT_BARABASI:
+    rt_bar_model = new RouterBarabasiAlbert((RouterBarabasiAlbertPar*)par);
+    topology = new Topology(rt_bar_model);
+    break;
+
+  case AS_WAXMAN:
+    as_wax_model = new ASWaxman((ASWaxPar*)par);
+    topology = new Topology(as_wax_model);
+    break;
+
+  case AS_BARABASI:
+    as_bar_model = new ASBarabasiAlbert((ASBarabasiAlbertPar*)par);
+    topology = new Topology(as_bar_model);
+    break;
+  
+  case TD_HIER:
+    td_model = new TopDownHierModel((TopDownPar*)par);
+    topology = new Topology(td_model);
+    break;
+
+  case BU_HIER:
+    bu_model = new BottomUpHierModel((BottUpPar*)par);
+    topology = new Topology(bu_model);
+    break;
+
+  case IF_ROUTER:
+  case IF_AS:
 
-  topology = 0;
-  model = 0;
+    switch (((ImportedFilePar*)par)->GetFormat()) {
+    case ImportedFileModel::IF_BRITE:
+      cout << "Importing brite...\n" << flush;
+      if_brite_model = new ImportedBriteTopologyModel((ImportedFilePar*)par);
+      topology = new Topology(if_brite_model);
+      break;
+
+    case ImportedFileModel::IF_GTITM:
+    case ImportedFileModel::IF_GTITM_TS:
+      cout << "Importing gtitm...\n" << flush;
+      if_gtitm_model = new ImportedGTitmTopologyModel((ImportedFilePar*)par);
+      topology = new Topology(if_gtitm_model);
+      break;
+
+    case ImportedFileModel::IF_NLANR:
+      cout << "Importing nlanr..\n" << flush;
+      cout.flush();
+      if_nlanr_model = new ImportedNLANRTopologyModel((ImportedFilePar*)par);
+      topology = new Topology(if_nlanr_model);
+      break;
+
+    case ImportedFileModel::IF_INET:
+      cout << "Importing Inet..\n" << flush;
+      if_inet_model = new ImportedInetTopologyModel((ImportedFilePar*)par);
+      topology = new Topology(if_inet_model);
+      break;
 
-  std::string filename = "test.txt";
-  Parse p (filename);
+    case ImportedFileModel::IF_SKITTER:
+    default:
+      cerr << "BriteMaiin(): Invalid file format for ImportedFileModel...\n";
+      exit(0);
+    }
+    break;
+
+  default:
+    cerr << "Parsing error: invalid parameter structure returned...\n";
+    exit(0);
+
+  }
+
+  // Check connectivity of topology
+  if (!topology->IsConnected()) {
+    cout << "Topology is not connected...\n" << flush;
+  }else {
+    cout << "Topology is connected!!!\n" << flush;
+  }
+
+  // Run classification algorithm
+  // topology->Classify();
+
+  // Output topology into file(s)
+  if (p.OutputBrite()) {
+    cout << "Outputing topology into BRITE's format...\n" << flush;
+    topology->BriteOutput(const_cast<char *>(outFile.c_str ()));
+  };
+
+  if (p.OutputOtter()) {
+    cout << "Outputing topology into Otter's format...\n" << flush;
+    topology->OtterOutput(const_cast<char *>(outFile.c_str ()));
+  }
+  delete topology;
+
+  OutputSeeds(const_cast<char *>(seedFile.c_str ()));
   
+  cout << "Done!\n";
+
 }
 
+
+
 } // namespace ns3
--- a/src/contrib/brite/brite-topology-helper.h	Wed Nov 10 15:10:52 2010 -0500
+++ b/src/contrib/brite/brite-topology-helper.h	Wed Nov 10 16:20:09 2010 -0500
@@ -19,10 +19,14 @@
 #ifndef BRITE_TOPOLOGY_HELPER_H
 #define BRITE_TOPOLOGY_HELPER_H
 
+#include <iostream>
+#include <string>
+
 #include "ns3/channel.h"
 #include "ns3/node-container.h"
 #include "ns3/node-list.h"
 #include "ns3/net-device-container.h"
+#include "Brite.h"
 
 namespace ns3 {
 
@@ -31,10 +35,16 @@
   public:
     BriteTopologyHelper ();
     ~BriteTopologyHelper () {};
-    void TestMethod ();
+
+    void InitSeeds(char *);
+    void OutputSeeds(char *);
+    void ImportFile (std::string confFile, 
+                    std::string outFile, 
+                    std::string seedFile);
 
   private:
-    int m_member;
+    Topology* m_topology;
+    Model* m_model;
 };
 
 } // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/brite/examples/brite.cc	Wed Nov 10 16:20:09 2010 -0500
@@ -0,0 +1,45 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <string>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/brite-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("BriteExample");
+
+int 
+main (int argc, char *argv[])
+{
+  std::string confFile = "../BRITE/conf_files/ASBarabasi.conf";
+  std::string seedFile = "../BRITE/seed_file";
+  std::string outFile = "briteTopolgy";
+
+  CommandLine cmd;
+  cmd.AddValue ("confFile", "BRITE conf file", confFile);
+  cmd.AddValue ("seedFile", "BRITE seed file", seedFile);
+  cmd.AddValue ("outFile", "BRITE outFile", outFile);
+
+  cmd.Parse (argc,argv);
+
+  BriteTopologyHelper bth;
+  bth.ImportFile (confFile, outFile, seedFile);
+  return 0;
+}