bgp-caida.patch
author Hajime Tazaki <tazaki@nict.go.jp>
Sat, 02 Jun 2012 00:29:00 +0900
changeset 22 ed0d8cc18421
parent 4 b419180b3d13
permissions -rw-r--r--
merge with HEAD of ns-3-dce

diff -r 137184880c3b example/dce-quagga-bgpd-caida.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/dce-quagga-bgpd-caida.cc	Tue Jan 24 17:31:19 2012 +0900
@@ -0,0 +1,159 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+
+#include "ns3/network-module.h"
+#include "ns3/core-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/dce-module.h"
+#include "ns3/quagga-helper.h"
+#include "ns3/point-to-point-helper.h"
+#include "../helper/ipv4-dce-routing-helper.h"
+#include "ns3/topology-read-module.h"
+#include <sys/resource.h>
+
+using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("DceQuaggaBgpd");
+
+// Parameters
+uint32_t nNodes = 2;
+uint32_t stopTime = 6000;
+
+static void
+SetRlimit ()
+{
+  int ret;
+  struct rlimit limit;
+  limit.rlim_cur = 1000000;
+  limit.rlim_max = 1000000;
+
+  ret = setrlimit(RLIMIT_NOFILE, &limit);
+  if (ret == -1)
+    {
+       perror ("setrlimit");
+    }
+  return;
+}
+
+static void RunIp (Ptr<Node> node, Time at, std::string str)
+{
+  DceApplicationHelper process;
+  ApplicationContainer apps;
+  process.SetBinary ("ip");
+  process.SetStackSize (1<<16);
+  process.ResetArguments();
+  process.ParseArguments(str.c_str ());
+  apps = process.Install (node);
+  apps.Start (at);
+}
+
+static void AddAddress (Ptr<Node> node, Time at, const char *name, const char *address)
+{
+  std::ostringstream oss;
+  oss << "-f inet addr add " << address << " dev " << name;
+  RunIp (node, at, oss.str ());
+}
+
+int main (int argc, char *argv[]) {
+  // 
+  //  Step 0
+  //  Node Basic Configuration
+  // 
+
+  CommandLine cmd;
+  cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime);
+  cmd.Parse (argc,argv);
+
+  // 
+  //  Step 1
+  //  Node Basic Configuration
+  // 
+  Ptr<TopologyReader> inFile = 0;
+  TopologyReaderHelper topoHelp;
+  NodeContainer nodes;
+  
+  std::string format ("Caida");
+  std::string input ("./asrel-as2500.txt");
+
+  topoHelp.SetFileName(input);
+  topoHelp.SetFileType(format);
+  inFile = topoHelp.GetTopologyReader();
+
+  if (inFile != 0)
+    {
+      nodes = inFile->Read ();
+    }
+
+  if (nodes.GetN () == 0)
+    {
+      NS_LOG_ERROR ("Problems reading node information the topology file. Failing.");
+      return -1;
+    }
+  if (inFile->LinksSize () == 0)
+    {
+      NS_LOG_ERROR ("Problems reading the topology file. Failing.");
+      return -1;
+    }
+  NS_LOG_INFO ("Caida topology created with " << nodes.GetN () << " nodes and " << 
+               inFile->LinksSize () << " links (from " << input << ")");
+
+  // Address conf In virtual topology
+  PointToPointHelper p2p;
+  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+  int totlinks = inFile->LinksSize ();
+  NS_LOG_INFO ("creating node containers");
+  NodeContainer nc[totlinks];
+  TopologyReader::ConstLinksIterator iter;
+  int i = 0;
+  for ( iter = inFile->LinksBegin (); iter != inFile->LinksEnd (); iter++, i++ )
+    {
+      nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ());
+    }
+
+  DceManagerHelper processManager;
+  processManager.SetLoader ("ns3::DlmLoaderFactory");
+  processManager.SetTaskManagerAttribute ("FiberManagerType", 
+                                          EnumValue (0));
+  processManager.SetNetworkStack("ns3::LinuxSocketFdFactory",
+                                 "Library", StringValue ("libnet-next-2.6.so"));
+  processManager.Install (nodes);
+  QuaggaHelper quagga;
+  quagga.EnableBgp (nodes);
+
+  NS_LOG_INFO ("creating net device containers");
+  NetDeviceContainer ndc[totlinks];
+  for (int i = 0; i < totlinks; i++)
+    {
+      ndc[i] = p2p.Install (nc[i]);
+
+#if 0
+      // IP address configuration
+      AddAddress (nodes.Get (0), Seconds (0.1), "sim0", "10.0.0.1/24");
+      RunIp (nodes.Get (0), Seconds (0.11), "link set lo up");
+      RunIp (nodes.Get (0), Seconds (0.11), "link set sim0 up");
+
+      AddAddress (nodes.Get (1), Seconds (0.1), "sim0", "10.0.0.2/24");
+      RunIp (nodes.Get (1), Seconds (0.11), "link set lo up");
+      RunIp (nodes.Get (1), Seconds (0.11), "link set sim0 up");
+
+      quagga.BgpAddNeighbor (nodes.Get (0), "10.0.0.2", quagga.GetAsn(nodes.Get (1)));
+      quagga.BgpAddNeighbor (nodes.Get (1), "10.0.0.1", quagga.GetAsn(nodes.Get (0)));
+      quagga.Install (nodes);  
+#endif
+    }
+
+
+  //  p2p.EnablePcapAll ("dce-quagga-bgpd-caida");
+
+  // 
+  // Now It's ready to GO!
+  // 
+  if (stopTime != 0)
+    {
+      Simulator::Stop (Seconds (stopTime));
+    }
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff -r 137184880c3b wscript
--- a/wscript	Tue Jan 24 16:33:26 2012 +0900
+++ b/wscript	Tue Jan 24 17:31:19 2012 +0900
@@ -266,6 +266,10 @@
                        target='bin/dce-quagga-ospfd',
                        source=['example/dce-quagga-ospfd.cc'])
 
+    module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point', 'visualizer', 'topology-read'],
+                       target='bin/dce-quagga-bgpd-caida',
+                       source=['example/dce-quagga-bgpd-caida.cc'])
+
     module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point'],
                        target='bin/dce-quagga-bgpd',
                        source=['example/dce-quagga-bgpd.cc'])