--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cradle-bulk.patch Thu Jun 20 09:56:26 2013 +0900
@@ -0,0 +1,251 @@
+diff --git a/example/dce-cradle-simple.cc b/example/dce-cradle-simple.cc
+--- a/example/dce-cradle-simple.cc
++++ b/example/dce-cradle-simple.cc
+@@ -34,6 +34,8 @@
+ std::string m_rate = "100Bps";
+ bool m_dual = false;
+ std::string m_ccid = "2";
++bool m_bulk = false;
++
+ int
+ main (int argc, char *argv[])
+ {
+@@ -57,6 +59,7 @@
+ cmd.AddValue ("rate", "tx rate", m_rate);
+ cmd.AddValue ("dual", "dual flow or not (default: uni-directional)", m_dual);
+ cmd.AddValue ("ccid", "CCID if dccp (default: 2)", m_ccid);
++ cmd.AddValue ("bulk", "use BulkSendApp instead of OnOffApp", m_bulk);
+ cmd.Parse (argc, argv);
+
+ NodeContainer nodes;
+@@ -89,17 +92,35 @@
+ ApplicationContainer apps;
+ OnOffHelper onoff = OnOffHelper (proto_sw[m_proto],
+ InetSocketAddress (interfaces.GetAddress (1), 9));
+- onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
+- onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
+- onoff.SetAttribute ("PacketSize", StringValue ("1024"));
+- onoff.SetAttribute ("DataRate", StringValue (m_rate));
+- apps = onoff.Install (nodes.Get (0));
+- apps.Start (Seconds (4.0));
+- if (m_dual)
++ if (!m_bulk)
+ {
+- onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (interfaces.GetAddress (0), 9)));
+- apps = onoff.Install (nodes.Get (1));
+- apps.Start (Seconds (4.1));
++ onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
++ onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
++ onoff.SetAttribute ("PacketSize", StringValue ("1024"));
++ onoff.SetAttribute ("DataRate", StringValue (m_rate));
++ apps = onoff.Install (nodes.Get (0));
++ apps.Start (Seconds (4.0));
++ if (m_dual)
++ {
++ onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (interfaces.GetAddress (0), 9)));
++ apps = onoff.Install (nodes.Get (1));
++ apps.Start (Seconds (4.1));
++ }
++ }
++ else
++ {
++ BulkSendHelper bulk (proto_sw[m_proto],
++ InetSocketAddress (interfaces.GetAddress (1), 9));
++ // Set the amount of data to send in bytes. Zero is unlimited.
++ bulk.SetAttribute ("MaxBytes", UintegerValue (1024));
++ apps = bulk.Install (nodes.Get (0));
++ apps.Start (Seconds (4.0));
++ if (m_dual)
++ {
++ bulk.SetAttribute ("Remote", AddressValue (InetSocketAddress (interfaces.GetAddress (0), 9)));
++ apps = bulk.Install (nodes.Get (1));
++ apps.Start (Seconds (4.1));
++ }
+ }
+
+ PacketSinkHelper sink = PacketSinkHelper (proto_sw[m_proto],
+diff --git a/example/dce-tcp-ns3-nsc-comparison.cc b/example/dce-tcp-ns3-nsc-comparison.cc
+--- a/example/dce-tcp-ns3-nsc-comparison.cc
++++ b/example/dce-tcp-ns3-nsc-comparison.cc
+@@ -40,6 +40,7 @@
+ bool enablePcap = false;
+ std::string m_pktSize = "1024";
+ bool m_frag = false;
++bool m_bulk = false;
+
+ int
+ main (int argc, char *argv[])
+@@ -55,6 +56,7 @@
+ cmd.AddValue ("enablePcap", "pcap", enablePcap);
+ cmd.AddValue ("pktSize", "packet size", m_pktSize);
+ cmd.AddValue ("frag", "fragment", m_frag);
++ cmd.AddValue ("bulk", "use BulkSendApp instead of OnOffApp", m_bulk);
+ cmd.Parse (argc, argv);
+
+ SeedManager::SetSeed (m_seed);
+@@ -91,10 +93,10 @@
+ }
+ else if (m_stack == "dce-dccp")
+ {
+- internetStack.Install (routers);
+ dceManager.SetNetworkStack ("ns3::LinuxSocketFdFactory",
+ "Library", StringValue ("liblinux.so"));
+ sock_factory = "ns3::LinuxDccpSocketFactory";
++ stack.Install (routers);
+ stack.Install (lefts);
+ stack.Install (rights);
+ }
+@@ -215,17 +217,34 @@
+ InetSocketAddress (Ipv4Address ("10.2.0.2"), 2000));
+ onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
+ onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
++ onoff.SetAttribute ("PacketSize", StringValue (m_pktSize));
++ onoff.SetAttribute ("DataRate", StringValue ("1Mbps"));
++
++ BulkSendHelper bulk = BulkSendHelper (sock_factory,
++ InetSocketAddress ("10.2.0.2", 2000));
++ // Set the amount of data to send in bytes. Zero is unlimited.
++ bulk.SetAttribute ("MaxBytes", UintegerValue (0));
++ bulk.SetAttribute ("SendSize", UintegerValue (atoi (m_pktSize.c_str ())));
+
+ // Flow 1 - n
+ for (uint32_t i = 0; i < m_nNodes; i++)
+ {
+ std::ostringstream oss;
+ oss << "10.2." << i << ".2";
+- onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
+- onoff.SetAttribute ("PacketSize", StringValue (m_pktSize));
+- onoff.SetAttribute ("DataRate", StringValue ("1Mbps"));
+- onoff.SetAttribute ("StartTime", TimeValue (Seconds (startTime)));
+- apps = onoff.Install (lefts.Get (i));
++ if (!m_bulk)
++ {
++ onoff.SetAttribute ("Remote",
++ AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
++ onoff.SetAttribute ("StartTime", TimeValue (Seconds (startTime)));
++ apps = onoff.Install (lefts.Get (i));
++ }
++ else
++ {
++ bulk.SetAttribute ("Remote",
++ AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
++ apps = bulk.Install (lefts.Get (i));
++ apps.Start (Seconds (startTime));
++ }
+ }
+
+ PacketSinkHelper sink = PacketSinkHelper (sock_factory,
+diff --git a/example/examples-to-run.py b/example/examples-to-run.py
+--- a/example/examples-to-run.py
++++ b/example/examples-to-run.py
+@@ -30,8 +30,15 @@
+ ("dce-cradle-simple --rate=10kbps --proto=tcp", "True", "True"),
+ ("dce-cradle-simple --rate=10kbps --proto=dccp", "True", "True"),
+ ("dce-cradle-simple --rate=10kbps --proto=dccp -ccid=3", "True", "True"),
++ ("dce-cradle-simple --bulk=1 --rate=10kbps --proto=tcp", "True", "True"),
++ ("dce-cradle-simple --bulk=1 --rate=10kbps --proto=dccp", "True", "True"),
++ ("dce-cradle-simple --bulk=1 --rate=10kbps --proto=dccp -ccid=3", "True", "True"),
+ ("dce-tcp-ns3-nsc-comparison", "True", "True"),
+ ("dce-tcp-ns3-nsc-comparison --stack=dce", "True", "True"),
++ ("dce-tcp-ns3-nsc-comparison --bulk=1", "True", "True"),
++ ("dce-tcp-ns3-nsc-comparison --stack=dce --bulk=1", "True", "True"),
++ ("dce-tcp-ns3-nsc-comparison --stack=dce-dccp", "True", "True"),
++ ("dce-tcp-ns3-nsc-comparison --stack=dce-dccp --bulk=1", "True", "True"),
+ ("dce-ping-mt1 --kernel=1", "True", "True"),
+ ("dce-mt2 --kernel=1", "True", "True"),
+ ("dce-mt3 --kernel=1", "True", "True"),
+diff --git a/model/linux/linux-socket-impl.cc b/model/linux/linux-socket-impl.cc
+--- a/model/linux/linux-socket-impl.cc
++++ b/model/linux/linux-socket-impl.cc
+@@ -138,11 +138,11 @@
+ return tid;
+ }
+
+-bool m_conn_inprogress = false;
+ LinuxSocketImpl::LinuxSocketImpl ()
+ {
+ NS_LOG_FUNCTION_NOARGS ();
+ m_listening = false;
++ m_conn_inprogress = false;
+ m_pid = -1;
+ SetNs3ToPosixConverter (MakeCallback (&LinuxSocketImpl::Ns3AddressToPosixAddress, this));
+ SetPosixToNs3Converter (MakeCallback (&LinuxSocketImpl::PosixAddressToNs3Address, this));
+@@ -197,7 +197,27 @@
+ enum Socket::SocketType
+ LinuxSocketImpl::GetSocketType (void) const
+ {
+- return NS3_SOCK_DGRAM;
++ switch (m_socktype)
++ {
++ case SOCK_STREAM:
++ case SOCK_DCCP:
++ {
++ return NS3_SOCK_STREAM;
++ break;
++ }
++ case SOCK_DGRAM:
++ {
++ return NS3_SOCK_DGRAM;
++ break;
++ }
++ case SOCK_RAW:
++ {
++ return NS3_SOCK_RAW;
++ break;
++ }
++ default:
++ break;
++ }
+ }
+
+ uint16_t
+@@ -514,7 +534,7 @@
+ LeaveFakeTask (pid);
+
+ // Notify the data
+- mask &= (POLLIN | POLLERR | POLLHUP | POLLRDHUP);
++ mask &= (POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDHUP);
+ if (mask)
+ {
+ Ptr<LinuxSocketFdFactory> factory = 0;
+@@ -577,14 +597,27 @@
+ Current ()->process->manager->Wait ();
+ }
+
+- NS_LOG_INFO ("notify recv");
+- NotifyDataRecv ();
++ else if (mask & POLLIN || mask & POLLERR)
++ {
++ NS_LOG_INFO ("notify recv");
++ NotifyDataRecv ();
++ }
++ else if (mask & POLLOUT)
++ {
++ Simulator::ScheduleWithContext (m_node->GetId (), Seconds (0.0),
++ MakeEvent (&LinuxSocketImpl::NotifySend, this, 0));
++ NS_LOG_INFO ("wait send for next poll event");
++ table->Wait (Seconds (0));
++ NS_LOG_INFO ("awaken");
++ }
+ }
+ }
+ // if not masked
+ else
+ {
++ NS_LOG_INFO ("wait for next poll event");
+ table->Wait (Seconds (0));
++ NS_LOG_INFO ("awaken");
+ }
+
+ // next loop
+diff --git a/model/linux/linux-socket-impl.h b/model/linux/linux-socket-impl.h
+--- a/model/linux/linux-socket-impl.h
++++ b/model/linux/linux-socket-impl.h
+@@ -109,6 +109,7 @@
+ uint16_t m_socktype;
+ uint16_t m_protocol;
+ bool m_listening;
++ bool m_conn_inprogress;
+ uint16_t m_pid;
+ EventId m_poll;
+