Skip to content

Instantly share code, notes, and snippets.

@thehajime
Created November 14, 2013 06:50
Show Gist options
  • Save thehajime/7462523 to your computer and use it in GitHub Desktop.
Save thehajime/7462523 to your computer and use it in GitHub Desktop.
diff -r 68675e7a5435 example/dce-quagga-bgpd-caida.cc
--- a/example/dce-quagga-bgpd-caida.cc Wed Nov 13 00:52:30 2013 +0900
+++ b/example/dce-quagga-bgpd-caida.cc Thu Nov 14 15:49:36 2013 +0900
@@ -166,6 +166,7 @@
quagga.BgpAddNeighbor (nc[i].Get (0), link_base + ".2", quagga.GetAsn (nc[i].Get (1)));
quagga.BgpAddNeighbor (nc[i].Get (1), link_base + ".1", quagga.GetAsn (nc[i].Get (0)));
+ quagga.BgpAddNetwork (nc[i].Get (0), "1.2.3.4/32");
// peer link
iter = inFile->LinksBegin ();
diff -r 68675e7a5435 example/dce-quagga-ospfd.cc
--- a/example/dce-quagga-ospfd.cc Wed Nov 13 00:52:30 2013 +0900
+++ b/example/dce-quagga-ospfd.cc Thu Nov 14 15:49:36 2013 +0900
@@ -23,7 +23,8 @@
#include "ns3/internet-module.h"
#include "ns3/dce-module.h"
#include "ns3/quagga-helper.h"
-#include "ns3/point-to-point-helper.h"
+#include "ns3/csma-helper.h"
+#include "ns3/tap-bridge-module.h"
using namespace ns3;
@@ -52,7 +53,9 @@
uint32_t nNodes = 2;
uint32_t stopTime = 600;
std::string netStack = "ns3";
-
+std::string mode = "ConfigureLocal";
+std::string tapName = "thetap";
+bool tapEnabled = false;
int main (int argc, char *argv[])
{
@@ -60,8 +63,16 @@
cmd.AddValue ("nNodes", "Number of Router nodes", nNodes);
cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime);
cmd.AddValue ("netStack", "What network stack", netStack);
+ cmd.AddValue ("tapEnabled", "Whether tap device is enabled or not (default: disable)", tapEnabled);
cmd.Parse (argc,argv);
+ if (tapEnabled)
+ {
+ GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
+ GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
+ }
+
+
//
// Step 1
// Node Basic Configuration
@@ -69,12 +80,12 @@
NodeContainer nodes;
nodes.Create (nNodes);
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
+ csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
- devices = pointToPoint.Install (nodes);
+ devices = csma.Install (nodes);
DceManagerHelper processManager;
//
@@ -84,29 +95,18 @@
//
if (netStack == "ns3")
{
- Ipv4AddressHelper ipv4AddrHelper;
- Ipv6AddressHelper ipv6AddrHelper;
// Internet stack install
InternetStackHelper stack; // IPv4 is required for GlobalRouteMan
Ipv4DceRoutingHelper ipv4RoutingHelper;
stack.SetRoutingHelper (ipv4RoutingHelper);
stack.Install (nodes);
-
- ipv4AddrHelper.SetBase ("10.0.0.0", "255.255.255.0");
- Ipv4InterfaceContainer interfaces = ipv4AddrHelper.Assign (devices);
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
processManager.SetNetworkStack ("ns3::Ns3SocketFdFactory");
processManager.Install (nodes);
-
- QuaggaHelper quagga;
- quagga.EnableOspf (nodes, "10.0.0.0/24");
- quagga.EnableOspfDebug (nodes);
- quagga.EnableZebraDebug (nodes);
- quagga.Install (nodes);
}
else if (netStack == "linux")
{
+ LinuxStackHelper stack;
+ stack.Install (nodes);
// processManager.SetLoader ("ns3::DlmLoaderFactory");
processManager.SetTaskManagerAttribute ("FiberManagerType",
EnumValue (0));
@@ -114,26 +114,32 @@
"Library", StringValue ("liblinux.so"));
processManager.Install (nodes);
- // 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");
- RunIp (nodes.Get (0), Seconds (0.2), "link show");
- RunIp (nodes.Get (0), Seconds (0.3), "route show table all");
- RunIp (nodes.Get (0), Seconds (0.4), "addr list");
-
- QuaggaHelper quagga;
- quagga.EnableOspf (nodes, "10.0.0.0/24");
- quagga.EnableOspfDebug (nodes);
- quagga.EnableZebraDebug (nodes);
- quagga.Install (nodes);
}
- pointToPoint.EnablePcapAll ("dce-quagga-ospfd");
+ // IP address configuration
+ Ipv4AddressHelper ipv4AddrHelper;
+ ipv4AddrHelper.SetBase ("10.0.0.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfaces = ipv4AddrHelper.Assign (devices);
+ //Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ QuaggaHelper quagga;
+ quagga.EnableOspf (nodes, "10.0.0.0/24");
+ quagga.EnableOspfDebug (nodes);
+ quagga.EnableZebraDebug (nodes);
+ quagga.Install (nodes);
+
+ csma.EnablePcapAll ("dce-quagga-ospfd");
+
+ if (tapEnabled)
+ {
+ TapBridgeHelper tapBridge;
+ tapBridge.SetAttribute ("Mode", StringValue (mode));
+ tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
+ // tapBridge.SetAttribute ("MacAddress", Mac48AddressValue ("00:00:00:00:00:03"));
+ // tapBridge.SetAttribute ("IpAddress", Ipv4AddressValue ("10.0.0.3"));
+ // tapBridge.SetAttribute ("Netmask", Ipv4MaskValue ("255.255.255.0"));
+ tapBridge.Install (nodes.Get (0), devices.Get (0));
+ }
//
// Step 9
diff -r 68675e7a5435 helper/quagga-helper.cc
--- a/helper/quagga-helper.cc Wed Nov 13 00:52:30 2013 +0900
+++ b/helper/quagga-helper.cc Thu Nov 14 15:49:36 2013 +0900
@@ -255,7 +255,7 @@
{
peer_links->push_back (n);
}
- void addNetwork (std::string n)
+ void AddNetwork (std::string n)
{
networks->push_back (n);
}
@@ -293,7 +293,6 @@
os << " neighbor " << *it << " remote-as " << (*neighbor_asn)[*it] << std::endl;
os << " neighbor " << *it << " advertisement-interval 5" << std::endl;
}
- os << " redistribute connected" << std::endl;
// IPv4
os << " address-family ipv4 unicast" << std::endl;
for (std::vector<std::string>::iterator it = neighbors->begin (); it != neighbors->end (); it++)
@@ -349,7 +348,6 @@
{
os << " network " << *it << std::endl;
}
- os << " redistribute connected" << std::endl;
os << " exit-address-family" << std::endl;
// access-list and route-map for peer-link filter-out
@@ -778,13 +776,25 @@
if (!bgp_conf)
{
bgp_conf = CreateObject<BgpConfig> ();
- bgp_conf->SetAsn (node->GetId ());
node->AggregateObject (bgp_conf);
}
bgp_conf->AddPeerLink (neighbor);
return;
}
+void
+QuaggaHelper::BgpAddNetwork (Ptr<Node> node, std::string network)
+{
+ Ptr<BgpConfig> bgp_conf = node->GetObject<BgpConfig> ();
+ if (!bgp_conf)
+ {
+ bgp_conf = CreateObject<BgpConfig> ();
+ node->AggregateObject (bgp_conf);
+ }
+ bgp_conf->AddNetwork (network);
+ return;
+}
+
// OSPF6
void
QuaggaHelper::EnableOspf6 (NodeContainer nodes, const char *ifname)
diff -r 68675e7a5435 helper/quagga-helper.h
--- a/helper/quagga-helper.h Wed Nov 13 00:52:30 2013 +0900
+++ b/helper/quagga-helper.h Thu Nov 14 15:49:36 2013 +0900
@@ -161,6 +161,8 @@
*/
void BgpAddPeerLink (Ptr<Node> node, std::string neighbor);
+ void BgpAddNetwork (Ptr<Node> node, std::string network);
+
/**
* \brief Enable the ospf6d daemon (OSPFv3) to the nodes.
*
diff -r 68675e7a5435 wscript
--- a/wscript Wed Nov 13 00:52:30 2013 +0900
+++ b/wscript Thu Nov 14 15:49:36 2013 +0900
@@ -63,7 +63,7 @@
target='bin/dce-quagga-ripngd',
source=['example/dce-quagga-ripngd.cc'])
- module.add_example(needed = ['core', 'internet', 'dce-quagga', 'point-to-point'],
+ module.add_example(needed = ['core', 'internet', 'dce-quagga', 'csma', 'tap-bridge'],
target='bin/dce-quagga-ospfd',
source=['example/dce-quagga-ospfd.cc'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment