Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: gosh this code is ugly
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Mar 2016 23:36:12 +0000 (00:36 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Mar 2016 23:36:12 +0000 (00:36 +0100)
src/surf/network_ns3.cpp
src/surf/ns3/ns3_interface.h
src/surf/ns3/ns3_simulator.cc
src/surf/ns3/ns3_simulator.h

index 4d01410..5cb8300 100644 (file)
@@ -462,7 +462,7 @@ int NetworkNS3Action::unref()
 
 
 void ns3_simulator(double min){
-      ns3_sim->simulator_start(min);
+  ns3_sim->simulator_start(min);
 }
 
 simgrid::surf::NetworkNS3Action* ns3_get_socket_action(void *socket){
@@ -477,7 +477,7 @@ double ns3_get_socket_sent(void *socket){
   return ((MySocket *)socket)->sentBytes;
 }
 
-char ns3_get_socket_is_finished(void *socket){
+bool ns3_get_socket_is_finished(void *socket){
   return ((MySocket *)socket)->finished;
 }
 
@@ -492,9 +492,7 @@ int ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalByte
   char* addr = (char*)xbt_dynar_get_as(IPV4addr,node2->node_num,char*);
 
   XBT_DEBUG("ns3_create_flow %d Bytes from %d to %d with Interface %s",TotalBytes, node1->node_num, node2->node_num,addr);
-  ns3_sim->create_flow_NS3(src_node,
-      dst_node,
-      port_number,
+  ns3_sim->create_flow_NS3(src_node, dst_node, port_number,
       start,
       addr,
       TotalBytes,
@@ -506,11 +504,11 @@ int ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalByte
 }
 
 // clean up
-int ns3_finalize(void){
-  if (!ns3_sim) return -1;
+void ns3_finalize(){
+  if (!ns3_sim)
+    return;
   delete ns3_sim;
   ns3_sim = 0;
-  return 0;
 }
 
 // initialize the NS3 interface and environment
index 216eab6..0537b10 100644 (file)
@@ -38,14 +38,14 @@ XBT_PUBLIC_DATA(int) NS3_EXTENSION_ID;
 
 SG_BEGIN_DECL()
 
-XBT_PUBLIC(int)    ns3_finalize(void);
+XBT_PUBLIC(void)   ns3_finalize();
 XBT_PUBLIC(int)    ns3_initialize(const char* TcpProtocol);
 XBT_PUBLIC(int)    ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,simgrid::surf::NetworkNS3Action * action);
 XBT_PUBLIC(void)   ns3_simulator(double min);
 XBT_PUBLIC(simgrid::surf::NetworkNS3Action*)  ns3_get_socket_action(void *socket);
 XBT_PUBLIC(double) ns3_get_socket_remains(void *socket);
 XBT_PUBLIC(double) ns3_get_socket_sent(void *socket);
-XBT_PUBLIC(char)   ns3_get_socket_is_finished(void *socket);
+XBT_PUBLIC(bool)   ns3_get_socket_is_finished(void *socket);
 XBT_PUBLIC(void *) ns3_add_host_cluster(const char * id);
 XBT_PUBLIC(void *) ns3_add_router(const char * id);
 XBT_PUBLIC(void *) ns3_add_AS(const char * id);
index 7b77929..de44c38 100644 (file)
@@ -76,9 +76,6 @@ void NS3Sim::create_flow_NS3(
        MySocket *mysocket = new MySocket();
        mysocket->totalBytes = totalBytes;
        mysocket->remaining = totalBytes;
-       mysocket->bufferedBytes = 0;
-       mysocket->sentBytes = 0;
-       mysocket->finished = 0;
        mysocket->action = action;
 
        transformSocketPtr(sock);
@@ -105,8 +102,8 @@ static MySocket* get_my_socket(Ptr<Socket> localSocket) {
 static void receive_callback(Ptr<Socket> localSocket){
   MySocket* mysocket = get_my_socket(localSocket);
 
-  if (mysocket->finished == 0){
-    mysocket->finished = 1;
+  if (mysocket->finished == false){
+    mysocket->finished = true;
     XBT_DEBUG("recv_cb of F[%p, %p, %d]", mysocket, mysocket->action, mysocket->totalBytes);
     XBT_DEBUG("Stop simulator at %f seconds", Simulator::Now().GetSeconds());
     Simulator::Stop(Seconds(0.0));
index c4e8bf9..6296b11 100644 (file)
 #include "ns3/tcp-socket-factory.h"
 
 struct MySocket{
-  std::uint32_t bufferedBytes;
-  std::uint32_t sentBytes;
+  std::uint32_t bufferedBytes = 0;
+  std::uint32_t sentBytes = 0;
   std::uint32_t remaining;
   std::uint32_t totalBytes;
-  char finished;
+  bool finished = false;
   simgrid::surf::NetworkNS3Action* action;
 };