Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
clang-format these files, no change
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 23 Dec 2016 21:08:44 +0000 (22:08 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 24 Dec 2016 21:44:44 +0000 (22:44 +0100)
src/surf/ns3/ns3_interface.h
src/surf/ns3/ns3_simulator.cc
src/surf/ns3/ns3_simulator.h

index 215d6d8..b9270f9 100644 (file)
@@ -8,10 +8,10 @@
 
 #include <simgrid/s4u/host.hpp>
 
 
 #include <simgrid/s4u/host.hpp>
 
-namespace simgrid{
-  namespace surf{
-    class NetworkNS3Action;
-  }
+namespace simgrid {
+namespace surf {
+class NetworkNS3Action;
+}
 }
 
 class NetCardNs3 {
 }
 
 class NetCardNs3 {
@@ -24,13 +24,13 @@ public:
 
 SG_BEGIN_DECL()
 
 
 SG_BEGIN_DECL()
 
-XBT_PUBLIC(void)   ns3_initialize(const char* TcpProtocol);
+XBT_PUBLIC(void) ns3_initialize(const char* TcpProtocol);
 XBT_PUBLIC(void)
 ns3_create_flow(sg_host_t src, sg_host_t dst, double start, u_int32_t TotalBytes,
                 simgrid::surf::NetworkNS3Action* action);
 XBT_PUBLIC(void)
 ns3_create_flow(sg_host_t src, sg_host_t dst, double start, u_int32_t TotalBytes,
                 simgrid::surf::NetworkNS3Action* action);
-XBT_PUBLIC(void)   ns3_simulator(double maxSeconds);
-XBT_PUBLIC(void *) ns3_add_router(const char * id);
-XBT_PUBLIC(void)   ns3_add_link(int src, int dst, char * bw,char * lat);
+XBT_PUBLIC(void) ns3_simulator(double maxSeconds);
+XBT_PUBLIC(void*) ns3_add_router(const char* id);
+XBT_PUBLIC(void) ns3_add_link(int src, int dst, char* bw, char* lat);
 XBT_PUBLIC(void) ns3_add_cluster(const char* id, char* bw, char* lat);
 
 SG_END_DECL()
 XBT_PUBLIC(void) ns3_add_cluster(const char* id, char* bw, char* lat);
 
 SG_END_DECL()
index e7b3382..06bd569 100644 (file)
@@ -9,11 +9,12 @@
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
 
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
 
-static void delete_mysocket(void *p)
+static void delete_mysocket(voidp)
 {
 {
-  delete (SgFlow *)p;
+  delete (SgFlow*)p;
 }
 }
-xbt_dict_t flowFromSock = xbt_dict_new_homogeneous(delete_mysocket);; // ns3::sock -> SgFlow
+xbt_dict_t flowFromSock = xbt_dict_new_homogeneous(delete_mysocket);
+; // 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 receive_callback(ns3::Ptr<ns3::Socket> socket);
 static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace);
@@ -21,20 +22,23 @@ static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent);
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
 
-SgFlow::SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action * action) {
+SgFlow::SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action* action)
+{
   totalBytes_ = totalBytes;
   totalBytes_ = totalBytes;
-  remaining_ = totalBytes;
-  action_ = action;
+  remaining_  = totalBytes;
+  action_     = action;
 }
 
 }
 
-static SgFlow* getFlowFromSocket(ns3::Ptr<ns3::Socket> socket) {
-       return (SgFlow*)xbt_dict_get_or_null(flowFromSock, transformSocketPtr(socket));
+static SgFlow* getFlowFromSocket(ns3::Ptr<ns3::Socket> socket)
+{
+  return (SgFlow*)xbt_dict_get_or_null(flowFromSock, transformSocketPtr(socket));
 }
 
 }
 
-static void receive_callback(ns3::Ptr<ns3::Socket> socket){
+static void receive_callback(ns3::Ptr<ns3::Socket> socket)
+{
   SgFlow* flow = getFlowFromSocket(socket);
 
   SgFlow* flow = getFlowFromSocket(socket);
 
-  if (flow->finished_ == false){
+  if (flow->finished_ == false) {
     flow->finished_ = true;
     XBT_DEBUG("recv_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
     XBT_DEBUG("Stop simulator at %f seconds", ns3::Simulator::Now().GetSeconds());
     flow->finished_ = true;
     XBT_DEBUG("recv_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
     XBT_DEBUG("Stop simulator at %f seconds", ns3::Simulator::Now().GetSeconds());
@@ -43,72 +47,78 @@ static void receive_callback(ns3::Ptr<ns3::Socket> socket){
   }
 }
 
   }
 }
 
-static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace){
-       SgFlow* flow = getFlowFromSocket(sock);
+static void send_callback(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;
+  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);
+  uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * txSpace);
 
 
-       while (flow->bufferedBytes_ < flow->totalBytes_ && sock->GetTxAvailable () > 0) {
+  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);
+    uint32_t toWrite = std::min({flow->remaining_, txSpace, sock->GetTxAvailable()});
+    int amountSent   = sock->Send(data, toWrite, 0);
 
 
-      if(amountSent < 0)
-         return;
-      flow->bufferedBytes_ += amountSent;
-      flow->remaining_ -= amountSent;
+    if (amountSent < 0)
+      return;
+    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);
-    }
-       free(data);
+    XBT_DEBUG("send_cb of F[%p, %p, %d] (%d/%d) %d buffered", flow, flow->action_, flow->totalBytes_, flow->remaining_,
+              flow->totalBytes_, amountSent);
+  }
+  free(data);
 
 
-       if ((flow->bufferedBytes_) >= flow->totalBytes_)
-               sock->Close();
+  if ((flow->bufferedBytes_) >= flow->totalBytes_)
+    sock->Close();
 }
 
 }
 
-static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent){
+static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent)
+{
   SgFlow* flow = getFlowFromSocket(socket);
   flow->sentBytes_ += dataSent;
   XBT_DEBUG("datasent_cb of F[%p, %p, %d] %d sent", flow, flow->action_, flow->totalBytes_, dataSent);
 }
 
   SgFlow* flow = getFlowFromSocket(socket);
   flow->sentBytes_ += dataSent;
   XBT_DEBUG("datasent_cb of F[%p, %p, %d] %d sent", flow, flow->action_, flow->totalBytes_, dataSent);
 }
 
-static void normalClose_callback(ns3::Ptr<ns3::Socket> socket){
+static void normalClose_callback(ns3::Ptr<ns3::Socket> socket)
+{
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("normalClose_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("normalClose_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
-  receive_callback (socket);
+  receive_callback(socket);
 }
 
 }
 
-static void errorClose_callback(ns3::Ptr<ns3::Socket> socket){
+static void errorClose_callback(ns3::Ptr<ns3::Socket> socket)
+{
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("errorClose_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
   xbt_die("NS3: a socket was closed anormally");
 }
 
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("errorClose_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
   xbt_die("NS3: a socket was closed anormally");
 }
 
-static void succeededConnect_callback(ns3::Ptr<ns3::Socket> socket){
+static void succeededConnect_callback(ns3::Ptr<ns3::Socket> socket)
+{
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("succeededConnect_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
 }
 
   SgFlow* flow = getFlowFromSocket(socket);
   XBT_DEBUG("succeededConnect_cb of F[%p, %p, %d]", flow, flow->action_, flow->totalBytes_);
 }
 
-static void failedConnect_callback(ns3::Ptr<ns3::Socket> socket){
+static void failedConnect_callback(ns3::Ptr<ns3::Socket> socket)
+{
   SgFlow* mysocket = getFlowFromSocket(socket);
   XBT_DEBUG("failedConnect_cb of F[%p, %p, %d]", mysocket, mysocket->action_, mysocket->totalBytes_);
   xbt_die("NS3: a socket failed to connect");
 }
 
   SgFlow* mysocket = getFlowFromSocket(socket);
   XBT_DEBUG("failedConnect_cb of F[%p, %p, %d]", mysocket, mysocket->action_, mysocket->totalBytes_);
   xbt_die("NS3: a socket failed to connect");
 }
 
-void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number)
+void StartFlow(ns3::Ptr<ns3::Socket> sock, const charto, uint16_t port_number)
 {
 {
-  ns3::InetSocketAddress serverAddr (to, port_number);
+  ns3::InetSocketAddress serverAddr(to, port_number);
 
   sock->Connect(serverAddr);
 
   sock->Connect(serverAddr);
-  sock->SetSendCallback (MakeCallback (&send_callback));
-  sock->SetRecvCallback (MakeCallback (&receive_callback));
-  sock->SetDataSentCallback (MakeCallback (&datasent_callback));
-  sock->SetConnectCallback (MakeCallback (&succeededConnect_callback), MakeCallback (&failedConnect_callback));
-  sock->SetCloseCallbacks (MakeCallback (&normalClose_callback), MakeCallback (&errorClose_callback));
+  sock->SetSendCallback(MakeCallback(&send_callback));
+  sock->SetRecvCallback(MakeCallback(&receive_callback));
+  sock->SetDataSentCallback(MakeCallback(&datasent_callback));
+  sock->SetConnectCallback(MakeCallback(&succeededConnect_callback), MakeCallback(&failedConnect_callback));
+  sock->SetCloseCallbacks(MakeCallback(&normalClose_callback), MakeCallback(&errorClose_callback));
 
   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);
 
   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);
index 8048638..2847a60 100644 (file)
 
 #include "ns3_interface.h"
 
 
 #include "ns3_interface.h"
 
-#include <ns3/global-route-manager.h>
 #include <ns3/csma-helper.h>
 #include <ns3/csma-helper.h>
+#include <ns3/global-route-manager.h>
 #include <ns3/internet-stack-helper.h>
 #include <ns3/ipv4-address-helper.h>
 #include <ns3/internet-stack-helper.h>
 #include <ns3/ipv4-address-helper.h>
-#include <ns3/point-to-point-helper.h>
 #include <ns3/packet-sink-helper.h>
 #include <ns3/packet-sink-helper.h>
+#include <ns3/point-to-point-helper.h>
 #include <ns3/tcp-socket-factory.h>
 
 class SgFlow {
 public:
 #include <ns3/tcp-socket-factory.h>
 
 class SgFlow {
 public:
-  SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action * action);
+  SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action* action);
 
 
-//private:
+  // private:
   std::uint32_t bufferedBytes_ = 0;
   std::uint32_t bufferedBytes_ = 0;
-  std::uint32_t sentBytes_ = 0;
+  std::uint32_t sentBytes_     = 0;
   std::uint32_t remaining_;
   std::uint32_t totalBytes_;
   bool finished_ = false;
   simgrid::surf::NetworkNS3Action* action_;
 };
 
   std::uint32_t remaining_;
   std::uint32_t totalBytes_;
   bool finished_ = false;
   simgrid::surf::NetworkNS3Action* action_;
 };
 
-void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number);
+void StartFlow(ns3::Ptr<ns3::Socket> sock, const charto, uint16_t port_number);
 
 
-static inline const char *transformSocketPtr (ns3::Ptr<ns3::Socket> localSocket)
+static inline const char* transformSocketPtr(ns3::Ptr<ns3::Socket> localSocket)
 {
   static char key[24];
   std::stringstream sstream;
 {
   static char key[24];
   std::stringstream sstream;
-  sstream << localSocket ;
-  snprintf(key,24,"%s",sstream.str().c_str());
+  sstream << localSocket;
+  snprintf(key, 24, "%s", sstream.str().c_str());
 
   return key;
 }
 
   return key;
 }