void tcpCongestion_init(TCPCongestion* congestion, TCPCongestionFunctionTable* funcTable,TCPCongestionType type, gint window, gint threshold) { MAGIC_INIT(congestion); MAGIC_INIT(funcTable); congestion->funcTable = funcTable; congestion->type = type; congestion->window = window; congestion->threshold = threshold; congestion->state = TCP_CCS_SLOWSTART; }
void transport_init(Transport* transport, TransportFunctionTable* vtable, enum DescriptorType type, gint handle) { g_assert(transport && vtable); descriptor_init(&(transport->super), type, &transport_functions, handle); MAGIC_INIT(transport); MAGIC_INIT(vtable); transport->vtable = vtable; }
void descriptor_init(Descriptor* descriptor, DescriptorType type, DescriptorFunctionTable* funcTable, gint handle) { utility_assert(descriptor && funcTable); MAGIC_INIT(descriptor); MAGIC_INIT(funcTable); descriptor->funcTable = funcTable; descriptor->handle = handle; descriptor->type = type; descriptor->readyListeners = NULL; descriptor->referenceCount = 1; }
Master* master_new(Options* options) { utility_assert(options); /* Don't do anything in this function that will cause a log message. The * global engine is still NULL since we are creating it now, and logging * here will cause an assertion error. */ Master* master = g_new0(Master, 1); MAGIC_INIT(master); master->options = options; master->random = random_new(options_getRandomSeed(options)); gint minRunAhead = (SimulationTime)options_getMinRunAhead(options); master->minJumpTimeConfig = ((SimulationTime)minRunAhead) * SIMTIME_ONE_MILLISECOND; /* these are only avail in glib >= 2.30 * setup signal handlers for gracefully handling shutdowns */ // TODO // g_unix_signal_add(SIGTERM, (GSourceFunc)_master_handleInterruptSignal, master); // g_unix_signal_add(SIGHUP, (GSourceFunc)_master_handleInterruptSignal, master); // g_unix_signal_add(SIGINT, (GSourceFunc)_master_handleInterruptSignal, master); message("simulation master created"); return master; }
TCP* tcp_new(gint handle) { TCP* tcp = g_new0(TCP, 1); MAGIC_INIT(tcp); socket_init(&(tcp->super), &tcp_functions, DT_TCPSOCKET, handle); guint32 initial_window = worker_getConfig()->initialTCPWindow; tcp->congestion.window = (gdouble)initial_window; tcp->congestion.lastWindow = initial_window; tcp->send.window = initial_window; tcp->send.lastWindow = initial_window; tcp->receive.window = initial_window; /* 0 is saved for representing control packets */ guint32 initialSequenceNumber = 1; tcp->congestion.lastSequence = initialSequenceNumber; tcp->congestion.lastAcknowledgement = initialSequenceNumber; tcp->send.unacked = initialSequenceNumber; tcp->send.next = initialSequenceNumber; tcp->send.end = initialSequenceNumber; tcp->send.lastAcknowledgement = initialSequenceNumber; tcp->receive.end = initialSequenceNumber; tcp->receive.next = initialSequenceNumber; tcp->receive.start = initialSequenceNumber; tcp->isSlowStart = TRUE; tcp->throttledOutput = g_queue_new(); tcp->unorderedInput = g_queue_new(); tcp->retransmission = g_hash_table_new(g_direct_hash, g_direct_equal); return tcp; }
static TCPChild* _tcpchild_new(TCP* tcp, TCP* parent, in_addr_t peerIP, in_port_t peerPort) { MAGIC_ASSERT(tcp); MAGIC_ASSERT(parent); TCPChild* child = g_new0(TCPChild, 1); MAGIC_INIT(child); /* my parent can find me by my key */ child->key = utility_ipPortHash(peerIP, peerPort); descriptor_ref(tcp); child->tcp = tcp; descriptor_ref(parent); child->parent = parent; child->state = TCPCS_INCOMPLETE; socket_setPeerName(&(child->tcp->super), peerIP, peerPort); /* the child is bound to the parent server's address, because all packets * coming from the child should appear to be coming from the server itself */ socket_setSocketName(&(child->tcp->super), socket_getBinding(&(parent->super)), parent->super.boundPort); return child; }
Master* master_new(Configuration* config) { MAGIC_ASSERT(config); /* Don't do anything in this function that will cause a log message. The * global engine is still NULL since we are creating it now, and logging * here will cause an assertion error. */ Master* master = g_new0(Master, 1); MAGIC_INIT(master); master->config = config; master->random = random_new(config->randomSeed); master->runTimer = g_timer_new(); master->minJumpTimeConfig = ((SimulationTime)config->minRunAhead) * SIMTIME_ONE_MILLISECOND; /* these are only avail in glib >= 2.30 * setup signal handlers for gracefully handling shutdowns */ // TODO // g_unix_signal_add(SIGTERM, (GSourceFunc)_master_handleInterruptSignal, master); // g_unix_signal_add(SIGHUP, (GSourceFunc)_master_handleInterruptSignal, master); // g_unix_signal_add(SIGINT, (GSourceFunc)_master_handleInterruptSignal, master); return master; }
Cubic* cubic_new(gint window, gint threshold) { Cubic *cubic = g_new0(Cubic, 1); MAGIC_INIT(cubic); if(!threshold) { threshold = 0x7FFFFFFF; } tcpCongestion_init(&(cubic->super), &CubicFunctions, TCP_CC_CUBIC, window, threshold); cubic->super.fastRetransmit = TCP_FR_SACK; /* cubic parameters */ cubic->beta = 819; cubic->scalingFactor = 41; /* constants used in calculations */ cubic->betaScale = 8 * (BETA_SCALE + cubic->beta) / 3 / (BETA_SCALE - cubic->beta); cubic->rttScale = cubic->scalingFactor * 10; cubic->cubeFactor = (gint64)(1ull << (10+3*BICTCP_HZ)) / (gint64)cubic->rttScale; cubic->hystart.found = FALSE; cubic->hystart.lowThreshold = 16; cubic->hystart.nSampling = 8; cubic->hystart.samplingCount = 8; return cubic; }
Worker* worker_new(Slave* slave) { /* make sure this isnt called twice on the same thread! */ utility_assert(!worker_isAlive()); Worker* worker = g_new0(Worker, 1); MAGIC_INIT(worker); worker->slave = slave; worker->thread_id = slave_generateWorkerID(slave); worker->clock_now = SIMTIME_INVALID; worker->clock_last = SIMTIME_INVALID; worker->clock_barrier = SIMTIME_INVALID; /* each worker needs a private copy of each plug-in library */ worker->privatePrograms = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify)program_free); if(slave_getWorkerCount(slave) <= 1) { /* this will cause events to get pushed to this queue instead of host queues */ worker->serialEventQueue = eventqueue_new(); } g_private_replace(&workerKey, worker); return worker; }
Epoll* epoll_new(gint handle) { g_assert(handle >= MIN_DESCRIPTOR); Epoll* epoll = g_new0(Epoll, 1); MAGIC_INIT(epoll); descriptor_init(&(epoll->super), DT_EPOLL, &epollFunctions, handle); /* allocate backend needed for managing events for this descriptor */ epoll->watches = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, _epollwatch_free); epoll->reports = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL); /* the application may want us to watch some system files, so we need a * real OS epoll fd so we can offload that task. */ epoll->osEpollDescriptor = epoll_create(1000); if(epoll->osEpollDescriptor == -1) { warning("error in epoll_create for OS events, errno=%i", errno); } /* keep track of which virtual application we need to notify of events */ Worker* worker = worker_getPrivate(); /* epoll_new should be called as a result of an application syscall */ g_assert(worker->cached_application); epoll->ownerApplication = worker->cached_application; return epoll; }
NotifyPluginEvent* notifyplugin_new(gint epollHandle) { NotifyPluginEvent* event = g_new0(NotifyPluginEvent, 1); MAGIC_INIT(event); shadowevent_init(&(event->super), ¬ifyplugin_functions); event->epollHandle = epollHandle; return event; }
Tracker* tracker_new(SimulationTime interval, GLogLevelFlags loglevel) { Tracker* tracker = g_new0(Tracker, 1); MAGIC_INIT(tracker); tracker->interval = interval; tracker->loglevel = loglevel; tracker->allocatedLocations = g_hash_table_new(g_direct_hash, g_direct_equal); return tracker; }
Process* process_new(GQuark programID, SimulationTime startTime, SimulationTime stopTime, gchar* arguments) { Process* proc = g_new0(Process, 1); MAGIC_INIT(proc); proc->programID = programID; proc->startTime = startTime; proc->arguments = g_string_new(arguments); return proc; }
static TCPServer* _tcpserver_new(gint backlog) { TCPServer* server = g_new0(TCPServer, 1); MAGIC_INIT(server); server->children = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify) _tcpchild_free); server->pending = g_queue_new(); server->pendingMaxLength = backlog; return server; }
TCPRetransmitTimerExpiredEvent* tcpretransmittimerexpired_new(TCP* tcp) { TCPRetransmitTimerExpiredEvent* event = g_new0(TCPRetransmitTimerExpiredEvent, 1); MAGIC_INIT(event); shadowevent_init(&(event->super), &tcpretransmittimerexpired_functions); descriptor_ref(tcp); event->tcp = tcp; return event; }
StopApplicationEvent* stopapplication_new(Application* application) { StopApplicationEvent* event = g_new0(StopApplicationEvent, 1); MAGIC_INIT(event); shadowevent_init(&(event->super), &stopapplication_functions); event->application = application; return event; }
StartApplicationEvent* startapplication_new(Application* application) { StartApplicationEvent* event = g_new0(StartApplicationEvent, 1); MAGIC_INIT(event); shadowevent_init((Event*) event, &startapplication_functions); event->application = application; return event; }
StopApplicationEvent* stopapplication_new(Process* application) { StopApplicationEvent* event = g_new0(StopApplicationEvent, 1); MAGIC_INIT(event); shadowevent_init((Event*) event, &stopapplication_functions); event->application = application; return event; }
InterfaceSentEvent* interfacesent_new(NetworkInterface* interface) { InterfaceSentEvent* event = g_new0(InterfaceSentEvent, 1); MAGIC_INIT(event); shadowevent_init(&(event->super), &interfacesent_functions); event->interface = interface; return event; }
Application* application_new(GQuark pluginID, gchar* pluginPath, SimulationTime startTime, gchar* arguments) { Application* application = g_new0(Application, 1); MAGIC_INIT(application); application->pluginID = pluginID; application->pluginPath = g_string_new(pluginPath); application->startTime = startTime; application->arguments = g_string_new(arguments); return application; }
UDP* udp_new(gint handle, guint receiveBufferSize, guint sendBufferSize) { UDP* udp = g_new0(UDP, 1); MAGIC_INIT(udp); socket_init(&(udp->super), &udp_functions, DT_UDPSOCKET, handle, receiveBufferSize, sendBufferSize); /* we are immediately active because UDP doesnt wait for accept or connect */ descriptor_adjustStatus((Descriptor*) udp, DS_ACTIVE|DS_WRITABLE, TRUE); return udp; }
void socket_init(Socket* socket, SocketFunctionTable* vtable, DescriptorType type, gint handle, guint receiveBufferSize, guint sendBufferSize) { utility_assert(socket && vtable); transport_init(&(socket->super), &socket_functions, type, handle); MAGIC_INIT(socket); MAGIC_INIT(vtable); socket->vtable = vtable; socket->protocol = type == DT_TCPSOCKET ? PTCP : type == DT_UDPSOCKET ? PUDP : PLOCAL; socket->inputBuffer = g_queue_new(); socket->inputBufferSize = receiveBufferSize; socket->outputBuffer = g_queue_new(); socket->outputBufferSize = sendBufferSize; Tracker* tracker = host_getTracker(worker_getCurrentHost()); Descriptor* descriptor = (Descriptor *)socket; tracker_addSocket(tracker, descriptor->handle, socket->protocol, socket->inputBufferSize, socket->outputBufferSize); }
Software* software_new(GQuark id, gchar* arguments, GQuark pluginID, gchar* pluginPath, SimulationTime startTime) { Software* software = g_new0(Software, 1); MAGIC_INIT(software); software->id = id; software->arguments = g_string_new(arguments); software->pluginID = pluginID; software->pluginPath = g_string_new(pluginPath); software->startTime = startTime; return software; }
Tracker* tracker_new(SimulationTime interval, GLogLevelFlags loglevel, gchar* flagString) { Tracker* tracker = g_new0(Tracker, 1); MAGIC_INIT(tracker); tracker->interval = interval; tracker->loglevel = loglevel; tracker->privateFlags = _tracker_parseFlagString(flagString); tracker->globalFlags = _tracker_parseGlobalFlags(); tracker->allocatedLocations = g_hash_table_new(g_direct_hash, g_direct_equal); tracker->socketStats = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify)_socketstats_free); return tracker; }
Internetwork* internetwork_new() { Internetwork* internet = g_new0(Internetwork, 1); MAGIC_INIT(internet); /* create our data structures, with the correct destructors */ internet->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); internet->networks = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, network_free); internet->networksByIP = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL); internet->ipByName = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); internet->nameByIp = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free); return internet; }
Engine* engine_new(Configuration* config) { MAGIC_ASSERT(config); /* Don't do anything in this function that will cause a log message. The * global engine is still NULL since we are creating it now, and logging * here will cause an assertion error. */ Engine* engine = g_new0(Engine, 1); MAGIC_INIT(engine); engine->config = config; engine->random = random_new(config->randomSeed); engine->runTimer = g_timer_new(); /* initialize the singleton-per-thread worker class */ engine->workerKey.index = 0; engine->preloadKey.index = 0; /* holds all events if single-threaded, and non-node events otherwise. */ engine->masterEventQueue = asyncpriorityqueue_new((GCompareDataFunc)shadowevent_compare, NULL, (GDestroyNotify)shadowevent_free); engine->workersIdle = g_cond_new(); engine->engineIdle = g_mutex_new(); engine->registry = registry_new(); registry_register(engine->registry, SOFTWARE, NULL, software_free); registry_register(engine->registry, CDFS, NULL, cdf_free); registry_register(engine->registry, PLUGINPATHS, g_free, g_free); engine->minTimeJump = config->minRunAhead * SIMTIME_ONE_MILLISECOND; engine->internet = internetwork_new(); engine->lock = g_mutex_new(); /* get the raw speed of the experiment machine */ gchar* contents = NULL; gsize length = 0; GError* error = NULL; if(!g_file_get_contents(CONFIG_CPU_MAX_FREQ_FILE, &contents, &length, &error)) { engine->rawFrequencyKHz = 0; } else { engine->rawFrequencyKHz = (guint)atoi(contents); } return engine; }
CreateNetworkAction* createnetwork_new(GString* name, guint64 bandwidthdown, guint64 bandwidthup, gdouble packetloss) { g_assert(name); CreateNetworkAction* action = g_new0(CreateNetworkAction, 1); MAGIC_INIT(action); action_init(&(action->super), &createnetwork_functions); action->id = g_quark_from_string((const gchar*)name->str); action->bandwidthdown = bandwidthdown; action->bandwidthup = bandwidthup; action->packetloss = packetloss; return action; }
static Worker* _worker_new(Engine* engine) { Worker* worker = g_new0(Worker, 1); MAGIC_INIT(worker); worker->cached_engine = engine; worker->thread_id = engine_generateWorkerID(engine); worker->clock_now = SIMTIME_INVALID; worker->clock_last = SIMTIME_INVALID; worker->clock_barrier = SIMTIME_INVALID; /* each worker needs a private copy of each plug-in library */ worker->plugins = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, plugin_free); return worker; }
Listener* listener_new(CallbackFunc callback, gpointer data, gpointer callbackArgument) { /* better have a non-null callback if we are going to execute it */ g_assert(callback); Listener* listener = g_new0(Listener, 1); MAGIC_INIT(listener); runnable_init(&(listener->super), &listener_functions); listener->callback = callback; listener->data = data; listener->callbackArgument = callbackArgument; return listener; }
CallbackEvent* callback_new(CallbackFunc callback, gpointer data, gpointer callbackArgument) { /* better have a non-null callback if we are going to execute it */ g_assert(callback); CallbackEvent* event = g_new0(CallbackEvent, 1); MAGIC_INIT(event); shadowevent_init(&(event->super), &callback_functions); event->callback = callback; event->data = data; event->callbackArgument = callbackArgument; return event; }