Skip to content

Instantly share code, notes, and snippets.

@thehajime
Last active December 27, 2015 11:09
Show Gist options
  • Save thehajime/7316467 to your computer and use it in GitHub Desktop.
Save thehajime/7316467 to your computer and use it in GitHub Desktop.
# HG changeset patch
# Parent 827b1d133aebf6259594cf1f379ee693e568cdca
diff -r 827b1d133aeb example/tcp-client.cc
--- a/example/tcp-client.cc Wed Oct 30 17:18:51 2013 +0900
+++ b/example/tcp-client.cc Thu Jan 30 16:55:28 2014 +0900
@@ -47,7 +47,7 @@
}
// std::cout << "write: " << n << std::endl;
- // sleep (1);
+ sleep (1);
}
std::cout << "did write all buffers total:" << tot << std::endl;
diff -r 827b1d133aeb example/tcp-server.cc
--- a/example/tcp-server.cc Wed Oct 30 17:18:51 2013 +0900
+++ b/example/tcp-server.cc Thu Jan 30 16:55:28 2014 +0900
@@ -4,6 +4,8 @@
#include <netdb.h>
#include <string.h>
#include <iostream>
+#include <stdio.h>
+#include <errno.h>
#define SERVER_PORT 2000
@@ -23,6 +25,15 @@
status = listen (sock, 1);
int fd = accept (sock, 0, 0);
+ while ((fd == -1) && (errno == 35))
+ {
+ std::cout << " accept -> " << fd << " errno " << errno <<std::endl;
+ perror ("retry");
+ sleep (1);
+ fd = accept (sock, 0, 0);
+ if (fd == -1)
+ perror ("damn");
+ }
std::cout << " accept -> " << fd << std::endl;
uint8_t buf[10240];
diff -r 827b1d133aeb model/linux-socket-fd-factory.cc
--- a/model/linux-socket-fd-factory.cc Wed Oct 30 17:18:51 2013 +0900
+++ b/model/linux-socket-fd-factory.cc Thu Jan 30 16:55:28 2014 +0900
@@ -13,7 +13,7 @@
#include "sys/dce-stat.h"
#include "dce-fcntl.h"
#include "dce-stdio.h"
-#include "sim/include/sim-init.h"
+#include "include/sim-init.h"
#include "ns3/log.h"
#include "ns3/string.h"
#include "ns3/double.h"
@@ -429,6 +429,7 @@
uint16_t protocol, const Address & from,
const Address &to, NetDevice::PacketType type)
{
+ NS_LOG_FUNCTION (device << p << ntohs (protocol) << from << to << type);
struct SimDevice *dev = DevToDev (device);
if (dev == 0)
{
@@ -528,6 +529,8 @@
{
flags |= SIM_DEV_NOARP;
}
+ (GetObject<Node> ()->GetId () == 0) ? (flags |= (1<<4)) : (flags |= 0);
+
m_loader->NotifyStartExecute (); // Restore the memory of the kernel before access it !
struct SimDevice *dev = m_exported->dev_create (PeekPointer (device), (enum SimDevFlags)flags);
m_loader->NotifyEndExecute ();
diff -r 827b1d133aeb myscripts/dce-freebsd.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/myscripts/dce-freebsd.cc Thu Jan 30 16:55:28 2014 +0900
@@ -0,0 +1,151 @@
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/dce-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/csma-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/internet-module.h"
+#include <fstream>
+
+using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("DceLinux");
+
+void
+PrintTcpFlags (std::string key, std::string value)
+{
+ NS_LOG_INFO (key << "=" << value);
+}
+
+int main (int argc, char *argv[])
+{
+ CommandLine cmd;
+ char linkType = 'p'; // P2P
+ bool reliable = true;
+
+ cmd.AddValue ("linkType", "Link type: ie : C for CSMA, P for Point to Point and w for Wifi, default to P2P", linkType);
+ cmd.AddValue ("reliable", "If true use TCP transport else UDP, default is TCP", reliable);
+ cmd.Parse (argc, argv);
+ linkType = tolower (linkType);
+ switch (linkType)
+ {
+ case 'c':
+ case 'p':
+ case 'w':
+ break;
+ default:
+ std::cout << "Unknown link type : " << linkType << " ?" << std::endl;
+ return 1;
+ }
+
+ NodeContainer nodes;
+ nodes.Create (2);
+
+ NetDeviceContainer devices;
+
+ switch (linkType)
+ {
+ case 'c':
+ {
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
+ csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ devices = csma.Install (nodes);
+ csma.EnablePcapAll ("process-freebsd");
+ }
+ break;
+
+ case 'p':
+ {
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Gbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
+ devices = p2p.Install (nodes);
+ p2p.EnablePcapAll ("process-freebsd");
+ }
+ break;
+
+ case 'w':
+ {
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (5.0, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (nodes);
+
+ WifiHelper wifi = WifiHelper::Default ();
+ YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper phyChannel = YansWifiChannelHelper::Default ();
+ NqosWifiMacHelper mac;
+ phy.SetChannel (phyChannel.Create ());
+ mac.SetType ("ns3::AdhocWifiMac");
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
+ devices = wifi.Install (phy, mac, nodes);
+ phy.EnablePcapAll ("process-freebsd");
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ DceManagerHelper processManager;
+ // processManager.SetLoader ("ns3::DlmLoaderFactory");
+ processManager.SetNetworkStack ("ns3::LinuxSocketFdFactory", "Library", StringValue ("libfreebsd.so"));
+ processManager.Install (nodes);
+ LinuxStackHelper stack;
+ stack.Install (nodes);
+
+#ifdef LINUX_SIM
+ Ipv4AddressHelper address;
+ address.SetBase ("10.0.0.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfaces = address.Assign (devices);
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+ LinuxStackHelper::PopulateRoutingTables ();
+#endif /* LINUX_SIM */
+
+ DceApplicationHelper process;
+ ApplicationContainer apps;
+
+ if (reliable)
+ {
+ process.SetBinary ("tcp-server");
+ process.ResetArguments ();
+ process.SetStackSize (1 << 31);
+ apps = process.Install (nodes.Get (0));
+ apps.Start (Seconds (1.0));
+
+ process.SetBinary ("tcp-client");
+ process.ResetArguments ();
+ process.ParseArguments ("10.0.0.1");
+ apps = process.Install (nodes.Get (1));
+ apps.Start (Seconds (1.5));
+ }
+ else
+ {
+ process.SetBinary ("udp-server");
+ process.ResetArguments ();
+ process.SetStackSize (1 << 16);
+ apps = process.Install (nodes.Get (0));
+ apps.Start (Seconds (1.0));
+
+ process.SetBinary ("udp-client");
+ process.ResetArguments ();
+ process.ParseArguments ("10.0.0.1");
+ apps = process.Install (nodes.Get (1));
+ apps.Start (Seconds (1.5));
+ }
+
+ // print tcp sysctl value
+ LinuxStackHelper::SysctlGet (nodes.Get (0), Seconds (1.0),
+ ".net.ipv4.tcp_available_congestion_control", &PrintTcpFlags);
+
+ Simulator::Stop (Seconds (200.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
diff -r 827b1d133aeb wscript
--- a/wscript Wed Oct 30 17:18:51 2013 +0900
+++ b/wscript Thu Jan 30 16:55:28 2014 +0900
@@ -111,7 +111,7 @@
conf.check(header_name='sim.h',
includes=os.path.join(Options.options.kernel_stack, 'sim/include'))
# conf.check()
- conf.env['KERNEL_STACK'] = Options.options.kernel_stack
+ conf.env['KERNEL_STACK'] = Options.options.kernel_stack + '/sim'
conf.env.append_value ('DEFINES', 'KERNEL_STACK=Y')
conf.env['ENABLE_PYTHON_BINDINGS'] = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment