* Crude globals *
*****************/
-extern std::map<std::string, SgFlow*> flowFromSock;
+extern std::map<std::string, SgFlow*> flow_from_sock;
static ns3::InternetStackHelper stack;
static ns3::NodeContainer nodes;
NetPointNs3::NetPointNs3()
{
- ns3Node_ = ns3::CreateObject<ns3::Node>(0);
- stack.Install(ns3Node_);
- nodes.Add(ns3Node_);
+ ns3_node_ = ns3::CreateObject<ns3::Node>(0);
+ stack.Install(ns3_node_);
+ nodes.Add(ns3_node_);
node_num = number_of_nodes++;
}
return;
}
- std::string ns3Socket;
- for (auto elm : flowFromSock) {
- ns3Socket = elm.first;
+ std::string ns3_socket;
+ for (auto elm : flow_from_sock) {
+ ns3_socket = elm.first;
SgFlow* sgFlow = elm.second;
NetworkNS3Action * action = sgFlow->action_;
XBT_DEBUG("Processing socket %p (action %p)",sgFlow,action);
- action->set_remains(action->get_cost() - sgFlow->sentBytes_);
+ action->set_remains(action->get_cost() - sgFlow->sent_bytes_);
if (TRACE_is_enabled() && action->get_state() == kernel::resource::Action::State::STARTED) {
- double data_delta_sent = sgFlow->sentBytes_ - action->lastSent_;
+ double data_delta_sent = sgFlow->sent_bytes_ - action->last_sent_;
std::vector<LinkImpl*> route = std::vector<LinkImpl*>();
TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action->get_category(),
(data_delta_sent) / delta, now - delta, delta);
- action->lastSent_ = sgFlow->sentBytes_;
+ action->last_sent_ = sgFlow->sent_bytes_;
}
if(sgFlow->finished_){
- socket_to_destroy.push_back(ns3Socket);
- XBT_DEBUG("Destroy socket %p of action %p", ns3Socket.c_str(), action);
+ socket_to_destroy.push_back(ns3_socket);
+ XBT_DEBUG("Destroy socket %p of action %p", ns3_socket.c_str(), action);
action->finish(kernel::resource::Action::State::FINISHED);
} else {
- XBT_DEBUG("Socket %p sent %u bytes out of %u (%u remaining)", ns3Socket.c_str(), sgFlow->sentBytes_,
- sgFlow->totalBytes_, sgFlow->remaining_);
+ XBT_DEBUG("Socket %p sent %u bytes out of %u (%u remaining)", ns3_socket.c_str(), sgFlow->sent_bytes_,
+ sgFlow->total_bytes_, sgFlow->remaining_);
}
}
while (not socket_to_destroy.empty()) {
- ns3Socket = socket_to_destroy.back();
+ ns3_socket = socket_to_destroy.back();
socket_to_destroy.pop_back();
- SgFlow* flow = flowFromSock.at(ns3Socket);
+ SgFlow* flow = flow_from_sock.at(ns3_socket);
if (XBT_LOG_ISENABLED(ns3, xbt_log_priority_debug)) {
- XBT_DEBUG("Removing socket %p of action %p", ns3Socket.c_str(), flow->action_);
+ XBT_DEBUG("Removing socket %p of action %p", ns3_socket.c_str(), flow->action_);
}
delete flow;
- flowFromSock.erase(ns3Socket);
+ flow_from_sock.erase(ns3_socket);
}
}
unsigned int node1 = src->pimpl_netpoint->extension<NetPointNs3>()->node_num;
unsigned int node2 = dst->pimpl_netpoint->extension<NetPointNs3>()->node_num;
- ns3::Ptr<ns3::Node> src_node = src->pimpl_netpoint->extension<NetPointNs3>()->ns3Node_;
- ns3::Ptr<ns3::Node> dst_node = dst->pimpl_netpoint->extension<NetPointNs3>()->ns3Node_;
+ ns3::Ptr<ns3::Node> src_node = src->pimpl_netpoint->extension<NetPointNs3>()->ns3_node_;
+ ns3::Ptr<ns3::Node> dst_node = dst->pimpl_netpoint->extension<NetPointNs3>()->ns3_node_;
xbt_assert(node2 < IPV4addr.size(), "Element %s is unknown to NS3. Is it connected to any one-hop link?",
dst->pimpl_netpoint->get_cname());
ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket(src_node, ns3::TcpSocketFactory::GetTypeId());
- flowFromSock.insert({transformSocketPtr(sock), new SgFlow(totalBytes, this)});
+ flow_from_sock.insert({transform_socket_ptr(sock), new SgFlow(totalBytes, this)});
sock->Bind(ns3::InetSocketAddress(port_number));
- ns3::Simulator::ScheduleNow(&StartFlow, sock, addr.c_str(), port_number);
+ ns3::Simulator::ScheduleNow(&start_flow, sock, addr.c_str(), port_number);
port_number++;
xbt_assert(port_number <= 65000, "Too many connections! Port number is saturated.");
int srcNum = src->node_num;
int dstNum = dst->node_num;
- ns3::Ptr<ns3::Node> a = src->ns3Node_;
- ns3::Ptr<ns3::Node> b = dst->ns3Node_;
+ ns3::Ptr<ns3::Node> a = src->ns3_node_;
+ ns3::Ptr<ns3::Node> b = dst->ns3_node_;
XBT_DEBUG("\tAdd PTP from %d to %d bw:'%f Bps' lat:'%fs'", srcNum, dstNum, bw, lat);
pointToPoint.SetDeviceAttribute("DataRate",
#include <algorithm>
-std::map<std::string, SgFlow*> flowFromSock; // ns3::sock -> SgFlow
+std::map<std::string, SgFlow*> flow_from_sock; // ns3::sock -> SgFlow
static void receive_callback(ns3::Ptr<ns3::Socket> socket);
static void datasent_cb(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent);
SgFlow::SgFlow(uint32_t totalBytes, simgrid::kernel::resource::NetworkNS3Action* action)
{
- totalBytes_ = totalBytes;
+ total_bytes_ = totalBytes;
remaining_ = totalBytes;
action_ = action;
}
static SgFlow* getFlowFromSocket(ns3::Ptr<ns3::Socket> socket)
{
- auto it = flowFromSock.find(transformSocketPtr(socket));
- return (it == flowFromSock.end()) ? nullptr : it->second;
+ auto it = flow_from_sock.find(transform_socket_ptr(socket));
+ return (it == flow_from_sock.end()) ? nullptr : it->second;
}
static void receive_callback(ns3::Ptr<ns3::Socket> socket)
{
SgFlow* flow = getFlowFromSocket(socket);
- XBT_DEBUG("received on F[%p, total: %u, remain: %u]", flow, flow->totalBytes_, flow->remaining_);
+ XBT_DEBUG("received on F[%p, total: %u, remain: %u]", flow, flow->total_bytes_, flow->remaining_);
if (flow->finished_ == false) {
flow->finished_ = true;
- XBT_DEBUG("recv_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+ XBT_DEBUG("recv_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
XBT_DEBUG("Stop simulator at %f seconds", ns3::Simulator::Now().GetSeconds());
ns3::Simulator::Stop(ns3::Seconds(0.0));
ns3::Simulator::Run();
static void send_cb(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace)
{
SgFlow* flow = getFlowFromSocket(sock);
- XBT_DEBUG("Asked to write on F[%p, total: %u, remain: %u]", flow, flow->totalBytes_, flow->remaining_);
+ XBT_DEBUG("Asked to write on F[%p, total: %u, remain: %u]", flow, flow->total_bytes_, flow->remaining_);
if (flow->remaining_ == 0) // all data was already buffered (and socket was already closed)
return;
/* While not all is buffered and there remain space in the buffers */
- while (flow->bufferedBytes_ < flow->totalBytes_ && sock->GetTxAvailable() > 0) {
+ while (flow->buffered_bytes_ < flow->total_bytes_ && sock->GetTxAvailable() > 0) {
// Send at most 1040 bytes (data size in a TCP packet), as NS3 seems to not split correctly by itself
uint32_t toWrite = std::min({flow->remaining_, sock->GetTxAvailable(), std::uint32_t(1040)});
int amountSent = sock->Send(0, toWrite, 0);
xbt_assert(amountSent > 0, "Since TxAvailable>0, amountSent should also >0");
- flow->bufferedBytes_ += amountSent;
+ flow->buffered_bytes_ += amountSent;
flow->remaining_ -= amountSent;
XBT_DEBUG("%f: sent %d bytes over flow %p (still %u to go)", ns3::Simulator::Now().GetSeconds(), amountSent, flow,
flow->remaining_);
}
- if (flow->bufferedBytes_ >= flow->totalBytes_)
+ if (flow->buffered_bytes_ >= flow->total_bytes_)
sock->Close();
}
{
/* The tracing wants to know */
SgFlow* flow = getFlowFromSocket(socket);
- flow->sentBytes_ += dataSent;
- XBT_DEBUG("datasent_cb of F[%p, %p, %u] %u sent (%u total)", flow, flow->action_, flow->totalBytes_, dataSent,
- flow->sentBytes_);
+ flow->sent_bytes_ += dataSent;
+ XBT_DEBUG("datasent_cb of F[%p, %p, %u] %u sent (%u total)", flow, flow->action_, flow->total_bytes_, dataSent,
+ flow->sent_bytes_);
}
static void normalClose_callback(ns3::Ptr<ns3::Socket> socket)
{
SgFlow* flow = getFlowFromSocket(socket);
- XBT_DEBUG("normalClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+ XBT_DEBUG("normalClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
receive_callback(socket);
}
static void errorClose_callback(ns3::Ptr<ns3::Socket> socket)
{
SgFlow* flow = getFlowFromSocket(socket);
- XBT_DEBUG("errorClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+ XBT_DEBUG("errorClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
xbt_die("NS3: a socket was closed anormally");
}
static void succeededConnect_callback(ns3::Ptr<ns3::Socket> socket)
{
SgFlow* flow = getFlowFromSocket(socket);
- XBT_DEBUG("succeededConnect_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+ XBT_DEBUG("succeededConnect_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
}
static void failedConnect_callback(ns3::Ptr<ns3::Socket> socket)
{
SgFlow* mysocket = getFlowFromSocket(socket);
- XBT_DEBUG("failedConnect_cb of F[%p, %p, %u]", mysocket, mysocket->action_, mysocket->totalBytes_);
+ XBT_DEBUG("failedConnect_cb of F[%p, %p, %u]", mysocket, mysocket->action_, mysocket->total_bytes_);
xbt_die("NS3: a socket failed to connect");
}
-void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
+void start_flow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
{
SgFlow* flow = getFlowFromSocket(sock);
ns3::InetSocketAddress serverAddr(to, port_number);
// Notice when we actually sent some data (mostly for the TRACING module)
sock->SetDataSentCallback(MakeCallback(&datasent_cb));
- XBT_DEBUG("startFlow of F[%p, %p, %u] dest=%s port=%d", flow, flow->action_, flow->totalBytes_, to, port_number);
+ XBT_DEBUG("startFlow of F[%p, %p, %u] dest=%s port=%d", flow, flow->action_, flow->total_bytes_, to, port_number);
sock->SetConnectCallback(MakeCallback(&succeededConnect_callback), MakeCallback(&failedConnect_callback));
sock->SetCloseCallbacks(MakeCallback(&normalClose_callback), MakeCallback(&errorClose_callback));