- if(!dict_socket)
- dict_socket = xbt_dict_new_homogeneous(delete_mysocket);
-
- PacketSinkHelper sink ("ns3::TcpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny(),
- port_number));
- sink.Install (dst);
-
- Ptr<Socket> sock = Socket::CreateSocket (src, TcpSocketFactory::GetTypeId());
-
- MySocket *mysocket = new MySocket();
- mysocket->totalBytes = totalBytes;
- mysocket->remaining = totalBytes;
- mysocket->bufferedBytes = 0;
- mysocket->sentBytes = 0;
- mysocket->finished = 0;
- mysocket->action = action;
-
- transformSocketPtr(sock);
- xbt_dict_set(dict_socket,socket_key, mysocket,NULL);
-
- sock->Bind(InetSocketAddress(port_number));
- XBT_DEBUG("Create flow starting to %fs + %fs = %fs",start-ns3::Simulator::Now().GetSeconds(), ns3::Simulator::Now().GetSeconds(), start);
-
- Simulator::Schedule (Seconds(start-ns3::Simulator::Now().GetSeconds()),&StartFlow, sock, addr, port_number);
-}
-
-void NS3Sim::simulator_start(double min){
- if(min > 0.0)
- Simulator::Stop(Seconds(min));
- XBT_DEBUG("Start simulator '%f'",min);
- Simulator::Run ();
-}
-
-static MySocket* get_my_socket(Ptr<Socket> localSocket) {
- transformSocketPtr(localSocket);
- return (MySocket*)xbt_dict_get_or_null(dict_socket,socket_key);
-}
-
-static void receive_callback(Ptr<Socket> localSocket){
- MySocket* mysocket = get_my_socket(localSocket);
-
- if (mysocket->finished == 0){
- mysocket->finished = 1;
- 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));
- Simulator::Run();
+ SgFlow* flow = getFlowFromSocket(socket);
+
+ 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());
+ ns3::Simulator::Stop(ns3::Seconds(0.0));
+ ns3::Simulator::Run();