static void clusterCreation_cb(sg_platf_cluster_cbarg_t cluster)
{
- char* lat = bprintf("%fs", cluster->lat);
- char* bw = bprintf("%fbps", cluster->bw * 8);
-
for (int i : *cluster->radicals) {
// Routers don't create a router on the other end of the private link by themselves.
// We just need this router to be given an ID so we create a temporary NetPointNS3 so that it gets one
xbt_assert(host_src, "Cannot find a NS3 host of name %s", host_id);
// Any NS3 route is symmetrical
- ns3_add_link(host_src, host_dst, bw, lat);
+ ns3_add_link(host_src, host_dst, cluster->bw, cluster->lat);
delete host_dst;
free(host_id);
}
- xbt_free(lat);
- xbt_free(bw);
//Create link backbone
- lat = bprintf("%fs", cluster->bb_lat);
- bw = bprintf("%fBps", cluster->bb_bw);
- ns3_add_cluster(cluster->id, bw, lat);
- xbt_free(lat);
- xbt_free(bw);
+ ns3_add_cluster(cluster->id, cluster->bb_bw, cluster->bb_lat);
}
static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoint* src,
XBT_DEBUG("Route from '%s' to '%s' with link '%s' %s", src->cname(), dst->cname(), link->cname(),
(symmetrical ? "(symmetrical)" : "(not symmetrical)"));
- char* link_bdw = bprintf("%fbps", link->bandwidth() * 8);
- char* link_lat = bprintf("%fs", link->latency());
// XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id);
- XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->cname(), link_bdw, link_lat);
+ XBT_DEBUG("\tLink (%s) bw:%fbps lat:%fs", link->cname(), link->bandwidth(),
+ link->latency());
// create link ns3
NetPointNs3* host_src = src->extension<NetPointNs3>();
xbt_assert(host_src != nullptr, "Network element %s does not seem to be NS3-ready", src->cname());
xbt_assert(host_dst != nullptr, "Network element %s does not seem to be NS3-ready", dst->cname());
- // Any NS3 route is symmetrical
- ns3_add_link(host_src, host_dst, link_bdw, link_lat);
-
- xbt_free(link_bdw);
- xbt_free(link_lat);
+ ns3_add_link(host_src, host_dst, link->bandwidth(), link->latency());
} else {
static bool warned_about_long_routes = false;
}
static simgrid::config::Flag<std::string> ns3_tcp_model("ns3/TcpModel",
- "The ns3 tcp model can be : NewReno or Reno or Tahoe",
- "default");
+ "The ns3 tcp model can be : NewReno or Reno or Tahoe", "NewReno");
namespace simgrid {
namespace surf {
simgrid::s4u::onPlatformCreated.connect(&postparse_cb);
simgrid::s4u::NetZone::onRouteCreation.connect(&routeCreation_cb);
+ LogComponentEnable("PacketSink", ns3::LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoClientApplication", ns3::LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", ns3::LOG_LEVEL_INFO);
}
src_ = src;
dst_ = dst;
- ns3_create_flow(src, dst, surf_get_clock(), size, this);
+ ns3_create_flow(src, dst, size, this);
s4u::Link::onCommunicate(this, src, dst);
}
ns3::Simulator::Run ();
}
-void ns3_create_flow(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double startTime, u_int32_t TotalBytes,
- simgrid::surf::NetworkNS3Action* action)
-{
+void ns3_create_flow(simgrid::s4u::Host* src, simgrid::s4u::Host* dst,
+ u_int32_t TotalBytes,
+ simgrid::surf::NetworkNS3Action* action) {
unsigned int node1 = src->pimpl_netpoint->extension<NetPointNs3>()->node_num;
unsigned int node2 = dst->pimpl_netpoint->extension<NetPointNs3>()->node_num;
ns3::PacketSinkHelper sink("ns3::TcpSocketFactory", ns3::InetSocketAddress (ns3::Ipv4Address::GetAny(), port_number));
sink.Install (dst_node);
- ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket (src_node, ns3::TcpSocketFactory::GetTypeId());
+ ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket(src_node, ns3::TcpSocketFactory::GetTypeId());
xbt_dict_set(flowFromSock, transformSocketPtr(sock), new SgFlow(TotalBytes, action), nullptr);
sock->Bind(ns3::InetSocketAddress(port_number));
- XBT_DEBUG("Create flow starting to %fs + %fs = %fs",
- startTime-ns3::Simulator::Now().GetSeconds(), ns3::Simulator::Now().GetSeconds(), startTime);
-
- ns3::Simulator::Schedule (ns3::Seconds(startTime-ns3::Simulator::Now().GetSeconds()),
- &StartFlow, sock, addr, port_number);
+
+ ns3::Simulator::ScheduleNow(&StartFlow, sock, addr, port_number);
port_number++;
xbt_assert(port_number <= 65000, "Too many connections! Port number is saturated.");
// "ns3::TcpReno"
// "ns3::TcpTahoe"
- ns3::Config::SetDefault ("ns3::TcpSocket::SegmentSize", ns3::UintegerValue (1024)); // 1024-byte packet for easier reading
+ ns3::Config::SetDefault ("ns3::TcpSocket::SegmentSize", ns3::UintegerValue (1000));
ns3::Config::SetDefault ("ns3::TcpSocket::DelAckCount", ns3::UintegerValue (1));
+ ns3::Config::SetDefault ("ns3::TcpSocketBase::Timestamp", ns3::BooleanValue (false));
if (not strcmp(TcpProtocol, "default"))
return;
xbt_die("The ns3/TcpModel must be : NewReno or Reno or Tahoe");
}
-void ns3_add_cluster(const char* id, char* bw, char* lat)
-{
+void ns3_add_cluster(const char* id, double bw, double lat) {
ns3::NodeContainer Nodes;
for (unsigned int i = number_of_clusters_nodes; i < Cluster_nodes.GetN(); i++) {
xbt_assert(Nodes.GetN() <= 65000, "Cluster with NS3 is limited to 65000 nodes");
ns3::CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", ns3::StringValue (bw));
- csma.SetChannelAttribute ("Delay", ns3::StringValue (lat));
- ns3::NetDeviceContainer devices = csma.Install (Nodes);
+ csma.SetDeviceAttribute("DataRate", ns3::DataRateValue(ns3::DataRate(bw*8)));// NS3 takes bps, but we provide Bps
+ csma.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
+ ns3::NetDeviceContainer devices = csma.Install(Nodes);
XBT_DEBUG("Create CSMA");
char * adr = bprintf("%d.%d.0.0",number_of_networks,number_of_links);
return bprintf("%s",s.c_str());
}
-void ns3_add_link(NetPointNs3* src, NetPointNs3* dst, char* bw, char* lat)
-{
+void ns3_add_link(NetPointNs3* src, NetPointNs3* dst, double bw, double lat) {
ns3::PointToPointHelper pointToPoint;
ns3::Ipv4AddressHelper address;
ns3::Ptr<ns3::Node> a = nodes.Get(srcNum);
ns3::Ptr<ns3::Node> b = nodes.Get(dstNum);
- XBT_DEBUG("\tAdd PTP from %d to %d bw:'%s' lat:'%s'", srcNum, dstNum, bw, lat);
- pointToPoint.SetDeviceAttribute ("DataRate", ns3::StringValue (bw));
- pointToPoint.SetChannelAttribute ("Delay", ns3::StringValue (lat));
+ XBT_DEBUG("\tAdd PTP from %d to %d bw:'%f Bps' lat:'%fs'", srcNum, dstNum, bw, lat);
+ pointToPoint.SetDeviceAttribute("DataRate", ns3::DataRateValue(ns3::DataRate(bw*8)));// NS3 takes bps, but we provide Bps
+ pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
+
+ char *filename = bprintf("link-%d-%d.tr", srcNum, dstNum);
+ ns3::AsciiTraceHelper ascii;
+ pointToPoint.EnableAsciiAll (ascii.CreateFileStream (filename));
+ pointToPoint.EnablePcapAll ("tcp-bulk-send", false);
+ xbt_free(filename);
ns3::NetDeviceContainer netA;
netA.Add(pointToPoint.Install (a, b));
}); // ns3::sock -> SgFlow
static void receive_callback(ns3::Ptr<ns3::Socket> socket);
-static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace);
static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent);
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
}
}
-static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace)
+static void WriteUntilBufferFull(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace)
{
SgFlow* flow = getFlowFromSocket(sock);
if (flow->remaining_ == 0) // all data was already buffered (and socket was already closed)
return;
- uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * txSpace);
-
+ /* While not all is buffered and there remain space in the buffers */
while (flow->bufferedBytes_ < flow->totalBytes_ && sock->GetTxAvailable() > 0) {
- uint32_t toWrite = std::min({flow->remaining_, txSpace, sock->GetTxAvailable()});
- int amountSent = sock->Send(data, toWrite, 0);
-
- if (amountSent < 0)
+ uint32_t toWrite = std::min({flow->remaining_, sock->GetTxAvailable()});
+ if (toWrite == 0) // buffer full
return;
+ int amountSent = sock->Send(0, toWrite, 0);
+
+ xbt_assert(amountSent > 0, "Since TxAvailable>0, amountSent should also >0");
flow->bufferedBytes_ += amountSent;
flow->remaining_ -= amountSent;
- XBT_DEBUG("send_cb of F[%p, %p, %d] (%d/%d) %d buffered", flow, flow->action_, flow->totalBytes_, flow->remaining_,
- flow->totalBytes_, amountSent);
+ XBT_DEBUG("%f: sent %d bytes over flow %p (still %d to go)",
+ ns3::Simulator::Now().GetSeconds(), amountSent, flow, flow->remaining_);
}
- free(data);
- if ((flow->bufferedBytes_) >= flow->totalBytes_)
+ if (flow->bufferedBytes_ >= flow->totalBytes_)
sock->Close();
}
static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent)
{
+ /* The tracing wants to know */
SgFlow* flow = getFlowFromSocket(socket);
flow->sentBytes_ += dataSent;
- XBT_DEBUG("datasent_cb of F[%p, %p, %d] %d sent", flow, flow->action_, flow->totalBytes_, dataSent);
+ XBT_DEBUG("datasent_cb of F[%p, %p, %d] %d sent (%d total)",
+ flow, flow->action_, flow->totalBytes_, dataSent, flow->sentBytes_);
}
static void normalClose_callback(ns3::Ptr<ns3::Socket> socket)
void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
{
+ SgFlow* flow = getFlowFromSocket(sock);
ns3::InetSocketAddress serverAddr(to, port_number);
sock->Connect(serverAddr);
- sock->SetSendCallback(MakeCallback(&send_callback));
+ // tell the tcp implementation to call WriteUntilBufferFull again
+ // if we blocked and new tx buffer space becomes available
+ sock->SetSendCallback (MakeCallback(&WriteUntilBufferFull));
+ // Note when the send is over
sock->SetRecvCallback(MakeCallback(&receive_callback));
+ // Keep track of what was used (for the TRACING module)
sock->SetDataSentCallback(MakeCallback(&datasent_callback));
+ XBT_DEBUG("startFlow of F[%p, %p, %d] dest=%s port=%d", flow, flow->action_, flow->totalBytes_, to, port_number);
+
+ //WriteUntilBufferFull (sock, sock->GetTxAvailable ());
+ /*
+ sock->SetSendCallback(MakeCallback(&send_callback));
sock->SetConnectCallback(MakeCallback(&succeededConnect_callback), MakeCallback(&failedConnect_callback));
sock->SetCloseCallbacks(MakeCallback(&normalClose_callback), MakeCallback(&errorClose_callback));
+ send_callback(sock, sock->GetTxAvailable ());
+ */
- SgFlow* flow = getFlowFromSocket(sock);
- XBT_DEBUG("startFlow_cb of F[%p, %p, %d] dest=%s port=%d", flow, flow->action_, flow->totalBytes_, to, port_number);
}