Skip to content

Instantly share code, notes, and snippets.

@thehajime
Created May 3, 2015 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehajime/26be8606ddbb924f357c to your computer and use it in GitHub Desktop.
Save thehajime/26be8606ddbb924f357c to your computer and use it in GitHub Desktop.
#include "ns3/network-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/dce-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"
#include "ns3/applications-module.h"
using namespace ns3;
// ===========================================================================
//
// node 0 node 1
// +----------------+ +----------------+
// | | | |
// +----------------+ +----------------+
// | 2001:1::1 | | 2001:1::2 |
// +----------------+ +----------------+
// | point-to-point | | point-to-point |
// +----------------+ +----------------+
// | |
// +---------------------+
// 5 Mbps, 1 ms
//
// Just a ping !
// ===========================================================================
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
Ptr<Node> node1 = CreateObject<Node> (0);
Ptr<Node> node2 = CreateObject<Node> (1);
nodes.Add (node1);
nodes.Add (node2);
PointToPointHelper pointToPoint;
CsmaHelper csma;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
DceManagerHelper dceManager;
dceManager.SetNetworkStack ("ns3::LinuxSocketFdFactory", "Library", StringValue ("liblinux.so"));
LinuxStackHelper::RunIp (nodes.Get (0), Seconds (0.2), "-6 addr add 2001:1::1/64 dev sim0");
LinuxStackHelper::RunIp (nodes.Get (0), Seconds (0.2), "link set sim0 up arp off");
LinuxStackHelper::RunIp (nodes.Get (1), Seconds (0.2), "-6 addr add 2001:1::2/64 dev sim0");
LinuxStackHelper::RunIp (nodes.Get (1), Seconds (0.4), "link set sim0 up arp off");
dceManager.Install (nodes);
DceApplicationHelper dce;
ApplicationContainer apps;
dce.SetStackSize (1 << 20);
// Launch ping on node 0
dce.SetBinary ("ping6");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("-c 10");
dce.AddArgument ("-s 1000");
dce.AddArgument ("2001:1::2");
apps = dce.Install (node1);
apps.Start (Seconds (1.0));
pointToPoint.EnablePcapAll ("dce-ping6");
LinuxStackHelper::RunIp (nodes.Get (0), Seconds (2.0), "link");
LinuxStackHelper::RunIp (nodes.Get (0), Seconds (2.0), "-6 a");
LinuxStackHelper::RunIp (nodes.Get (0), Seconds (2.0), "-6 r show");
LinuxStackHelper::RunIp (nodes.Get (1), Seconds (2.0), "link");
LinuxStackHelper::RunIp (nodes.Get (1), Seconds (2.0), "-6 a");
LinuxStackHelper::RunIp (nodes.Get (1), Seconds (2.0), "-6 r show");
Simulator::Stop (Seconds (40.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment