/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "ns3/core-module.h"
+
#include "src/surf/network_ns3.hpp"
#include "src/surf/HostImpl.hpp"
else
do {
ns3_simulator(now);
- time_to_next_flow_completion = ns3_time() - surf_get_clock();//FIXME: use now instead ?
+ time_to_next_flow_completion = ns3::Simulator::Now().GetSeconds() - surf_get_clock();//FIXME: use now instead ?
} while(double_equals(time_to_next_flow_completion, 0, sg_surf_precision));
XBT_DEBUG("min : %f", now);
- XBT_DEBUG("ns3 time : %f", ns3_time());
+ XBT_DEBUG("ns3 time : %f", ns3::Simulator::Now().GetSeconds());
XBT_DEBUG("surf time : %f", surf_get_clock());
XBT_DEBUG("Next completion %f :", time_to_next_flow_completion);
/* If there are no running flows, just return */
if (!getRunningActionSet()->size()) {
- while(double_positive(now-ns3_time(), sg_surf_precision)) {
- ns3_simulator(now-ns3_time());
+ while(double_positive(now-ns3::Simulator::Now().GetSeconds(), sg_surf_precision)) {
+ ns3_simulator(now-ns3::Simulator::Now().GetSeconds());
}
return;
}
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
-///> RED Parameters see src/node/red-queue.* for details
-//.AddAttribute ("Mode",
-// "Whether to use Bytes (see MaxBytes) or Packets (see MaxPackets) as the maximum queue size metric.",
-// EnumValue (BYTES), ///> currently supports BYTES only
-// MakeEnumAccessor (&RedQueue::SetMode),
-// MakeEnumChecker (BYTES, "Bytes",
-// PACKETS, "Packets"))
-// .AddAttribute ("MaxPackets",
-// "The maximum number of packets accepted by this RedQueue.",
-// UintegerValue (100),
-// MakeUintegerAccessor (&RedQueue::m_maxPackets),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("MaxBytes",
-// "The maximum number of bytes accepted by this RedQueue.",
-// UintegerValue (100000),
-// MakeUintegerAccessor (&RedQueue::m_maxBytes),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("m_burst",
-// "maximum number of m_burst packets accepted by this queue",
-// UintegerValue (6), ///> bursts must be > minTh/avpkt
-// MakeUintegerAccessor (&RedQueue::m_burst),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("m_avPkt",
-// "In bytes, use with m_burst to determine the time constant for average queue size calculations",
-// UintegerValue (1024), ///> average packet size
-// MakeUintegerAccessor (&RedQueue::m_avPkt),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("m_minTh",
-// "Average queue size at which marking becomes a m_prob",
-// UintegerValue (5120), ///> in bytes 1024x5
-// MakeUintegerAccessor (&RedQueue::m_minTh),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("m_maxTh",
-// "Maximal marking m_prob, should be at least twice min to prevent synchronous retransmits",
-// UintegerValue (15360), ///> in bytes 1024x15
-// MakeUintegerAccessor (&RedQueue::m_maxTh),
-// MakeUintegerChecker<uint32_t> ())
-// .AddAttribute ("m_rate",
-// "this m_rate is used for calculating the average queue size after some idle time.",
-// UintegerValue (1500000), ///> in bps, should be set to bandwidth of interface
-// MakeUintegerAccessor (&RedQueue::m_rate),
-// MakeUintegerChecker<uint64_t> ())
-// .AddAttribute ("m_prob",
-// "Probability for marking, suggested values are 0.01 and 0.02",
-// DoubleValue (0.02),
-// MakeDoubleAccessor (&RedQueue::m_prob),
-// MakeDoubleChecker <double> ())
std::string qMode = "Bytes";
std::string qBurst = "6";
std::string qAvPkt = "1024";
{
m_queueFactory.SetTypeId ("ns3::DropTailQueue");
m_queueFactory_red.SetTypeId ("ns3::RedQueue");
-// m_queueFactory_red.Set ("Mode", StringValue (qMode));
-// m_queueFactory_red.Set ("MaxBytes",StringValue (qLimit));
-// m_queueFactory_red.Set ("m_burst", StringValue (qBurst));
-// m_queueFactory_red.Set ("m_avPkt", StringValue (qAvPkt));
-// m_queueFactory_red.Set ("m_minTh", StringValue (qthMin));
-// m_queueFactory_red.Set ("m_maxTh", StringValue (qthMax));
-// m_queueFactory_red.Set ("m_rate", StringValue (qIdleRate));
-// m_queueFactory_red.Set ("m_prob", StringValue (qProb));
m_deviceFactory.SetTypeId ("ns3::PointToPointNetDevice");
m_channelFactory.SetTypeId ("ns3::PointToPointChannel");
m_remoteChannelFactory.SetTypeId ("ns3::PointToPointRemoteChannel");
uint32_t n2SystemId = b->GetSystemId ();
uint32_t currSystemId = MpiInterface::GetSystemId ();
if (n1SystemId != currSystemId || n2SystemId != currSystemId)
- {
useNormalChannel = false;
- }
}
if (useNormalChannel)
{
uint32_t n2SystemId = b->GetSystemId ();
uint32_t currSystemId = MpiInterface::GetSystemId ();
if (n1SystemId != currSystemId || n2SystemId != currSystemId)
- {
useNormalChannel = false;
- }
}
if (useNormalChannel)
{
}
void* ns3_get_socket_action(void *socket){
- return ns3_sim->get_action_from_socket(socket);
+ return ((MySocket *)socket)->action;
}
double ns3_get_socket_remains(void *socket){
- return ns3_sim->get_remains_from_socket(socket);
+ return ((MySocket *)socket)->remaining;
}
double ns3_get_socket_sent(void *socket){
- return ns3_sim->get_sent_from_socket(socket);
+ return ((MySocket *)socket)->sentBytes;
}
char ns3_get_socket_is_finished(void *socket){
- return ns3_sim->get_finished(socket);
-}
-
-double ns3_time(){
- return Simulator::Now().GetSeconds();
+ return ((MySocket *)socket)->finished;
}
int ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,void * action)
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,void * action);
XBT_PUBLIC(void) ns3_simulator(double min);
-XBT_PUBLIC(double) ns3_time(void);
XBT_PUBLIC(void*) ns3_get_socket_action(void *socket);
XBT_PUBLIC(double) ns3_get_socket_remains(void *socket);
XBT_PUBLIC(double) ns3_get_socket_sent(void *socket);
static void receive_callback(Ptr<Socket> localSocket);
static void send_callback(Ptr<Socket> localSocket, uint32_t txSpace);
static void datasent_callback(Ptr<Socket> localSocket, uint32_t dataSent);
-static void StartFlow(Ptr<Socket> sock,
- const char *to,
- uint16_t port_number);
+static void StartFlow(Ptr<Socket> sock, const char *to, uint16_t port_number);
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
-// Constructor.
NS3Sim::NS3Sim(){
}
-//Destructor.
NS3Sim::~NS3Sim(){
}
-static inline void transformSocketPtr (Ptr<Socket> localSocket){
+static inline void transformSocketPtr (Ptr<Socket> localSocket)
+{
std::stringstream sstream;
sstream << localSocket ;
std::string s = sstream.str();
}
/*
- * This function create a flow from src to dst
+ * This function creates a flow from src to dst
*
* Parameters
* src: node source
uint32_t totalBytes,
void * action)
{
- if(!dict_socket) dict_socket = xbt_dict_new_homogeneous(delete_mysocket);
+ 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());
+ Ptr<Socket> sock = Socket::CreateSocket (src, TcpSocketFactory::GetTypeId());
MySocket *mysocket = new MySocket();
mysocket->totalBytes = totalBytes;
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_time(), ns3_time(), start);
-
- Simulator::Schedule (Seconds(start-ns3_time()),&StartFlow, sock, addr, port_number);
-// Simulator::Schedule (Seconds(0.0),&StartFlow, sock, addr, port_number);
-
-}
-
-void* NS3Sim::get_action_from_socket(void *socket){
- return ((MySocket *)socket)->action;
-}
+ XBT_DEBUG("Create flow starting to %fs + %fs = %fs",start-ns3::Simulator::Now().GetSeconds(), ns3::Simulator::Now().GetSeconds(), start);
-char NS3Sim::get_finished(void *socket){
- return ((MySocket *)socket)->finished;
-}
-
-double NS3Sim::get_remains_from_socket(void *socket){
- return ((MySocket *)socket)->remaining;
-}
-
-double NS3Sim::get_sent_from_socket(void *socket){
- return ((MySocket *)socket)->sentBytes;
+ Simulator::Schedule (Seconds(start-ns3::Simulator::Now().GetSeconds()),&StartFlow, sock, addr, port_number);
}
void NS3Sim::simulator_start(double min){
MySocket* mysocket = get_my_socket(localSocket);
if (mysocket->remaining == 0){
- //all data was already buffered (and socket was already closed), just return
+ // all data was already buffered (and socket was already closed), just return
return;
}
free(data);
- if ((mysocket->bufferedBytes) >= mysocket->totalBytes){
+ if ((mysocket->bufferedBytes) >= mysocket->totalBytes)
localSocket->Close();
- }
}
static void datasent_callback(Ptr<Socket> localSocket, uint32_t dataSent){
xbt_die("NS3: a socket failed to connect");
}
-static void StartFlow(Ptr<Socket> sock,
- const char *to,
- uint16_t port_number)
+static void StartFlow(Ptr<Socket> sock, const char *to, uint16_t port_number)
{
InetSocketAddress serverAddr (to, port_number);
std::uint32_t TotalBytes,
void * action);
void simulator_start(double min);
- void* get_action_from_socket(void *socket);
- double get_remains_from_socket(void *socket);
- double get_sent_from_socket(void *socket);
- char get_finished(void *socket);
};
#endif /* __cplusplus */