Beispiel #1
0
gint master_run(Master* master) {
    MAGIC_ASSERT(master);

    message("loading and initializing simulation data");

    /* start loading and initializing simulation data */
    _master_loadConfiguration(master);
    gboolean isSuccess = _master_loadTopology(master);
    if(!isSuccess) {
        return 1;
    }

    _master_initializeTimeWindows(master);

    /* the master will be responsible for distributing the actions to the slaves so that
     * they all have a consistent view of the simulation, topology, etc.
     * For now we only have one slave so send it everything. */
    guint slaveSeed = random_nextUInt(master->random);
    master->slave = slave_new(master, master->options, master->endTime, slaveSeed);

    message("registering plugins and hosts");

    /* register the components needed by each slave.
     * this must be done after slaves are available so we can send them messages */
    _master_registerPlugins(master);
    _master_registerHosts(master);

    message("running simulation");

    /* dont buffer log messages in debug mode */
    if(options_getLogLevel(master->options) != LOGLEVEL_DEBUG) {
        message("log message buffering is enabled for efficiency");
        logger_setEnableBuffering(logger_getDefault(), TRUE);
    }

    /* start running each slave */
    slave_run(master->slave);

    /* only need to disable buffering if it was enabled, otherwise
     * don't log the message as it may confuse the user. */
    if(options_getLogLevel(master->options) != LOGLEVEL_DEBUG) {
        message("log message buffering is disabled during cleanup");
        logger_setEnableBuffering(logger_getDefault(), FALSE);
    }

    message("simulation finished, cleaning up now");

    return slave_free(master->slave);
}
Beispiel #2
0
static void _master_registerHostCallback(ConfigurationHostElement* he, Master* master) {
    MAGIC_ASSERT(master);
    utility_assert(he);
    utility_assert(he->id.isSet && he->id.string);

    guint64 quantity = he->quantity.isSet ? he->quantity.integer : 1;

    for(guint64 i = 0; i < quantity; i++) {
        HostParameters* params = g_new0(HostParameters, 1);

        /* hostname and id params */
        const gchar* hostNameBase = he->id.string->str;

        GString* hostnameBuffer = g_string_new(hostNameBase);
        if(quantity > 1) {
            g_string_append_printf(hostnameBuffer, "%"G_GUINT64_FORMAT, i+1);
        }
        params->hostname = hostnameBuffer->str;

        /* cpu params - if they didnt specify a CPU frequency, use the slave machine frequency */
        gint slaveCPUFreq = slave_getRawCPUFrequency(master->slave);
        params->cpuFrequency = he->cpufrequency.isSet ? he->cpufrequency.integer : (slaveCPUFreq > 0) ? (guint64)slaveCPUFreq : 0;
        if(params->cpuFrequency == 0) {
            params->cpuFrequency = 2500000; // 2.5 GHz
            debug("both configured and raw slave cpu frequencies unavailable, using 2500000 KHz");
        }

        gint defaultCPUThreshold = options_getCPUThreshold(master->options);
        params->cpuThreshold = defaultCPUThreshold > 0 ? defaultCPUThreshold : 0;
        gint defaultCPUPrecision = options_getCPUPrecision(master->options);
        params->cpuPrecision = defaultCPUPrecision > 0 ? defaultCPUPrecision : 0;

        params->logLevel = he->loglevel.isSet ?
                loglevel_fromStr(he->loglevel.string->str) :
                options_getLogLevel(master->options);

        params->heartbeatLogLevel = he->heartbeatloglevel.isSet ?
                loglevel_fromStr(he->heartbeatloglevel.string->str) :
                options_getHeartbeatLogLevel(master->options);

        params->heartbeatInterval = he->heartbeatfrequency.isSet ?
                (SimulationTime)(he->heartbeatfrequency.integer * SIMTIME_ONE_SECOND) :
                options_getHeartbeatInterval(master->options);

        params->heartbeatLogInfo = he->heartbeatloginfo.isSet ?
                options_toHeartbeatLogInfo(master->options, he->heartbeatloginfo.string->str) :
                options_getHeartbeatLogInfo(master->options);

        params->logPcap = (he->logpcap.isSet && !g_ascii_strcasecmp(he->logpcap.string->str, "true")) ? TRUE : FALSE;
        params->pcapDir = he->pcapdir.isSet ? he->pcapdir.string->str : NULL;

        /* socket buffer settings - if size is set manually, turn off autotuning */
        params->recvBufSize = he->socketrecvbuffer.isSet ? he->socketrecvbuffer.integer :
                options_getSocketReceiveBufferSize(master->options);
        params->autotuneRecvBuf = he->socketrecvbuffer.isSet ? FALSE :
                options_doAutotuneReceiveBuffer(master->options);

        params->sendBufSize = he->socketsendbuffer.isSet ? he->socketsendbuffer.integer :
                options_getSocketSendBufferSize(master->options);
        params->autotuneSendBuf = he->socketsendbuffer.isSet ? FALSE :
                options_doAutotuneSendBuffer(master->options);

        params->interfaceBufSize = he->interfacebuffer.isSet ? he->interfacebuffer.integer :
                options_getInterfaceBufferSize(master->options);
        params->qdisc = options_getQueuingDiscipline(master->options);

        /* requested attributes from shadow config */
        params->ipHint = he->ipHint.isSet ? he->ipHint.string->str : NULL;
        params->countrycodeHint = he->countrycodeHint.isSet ? he->countrycodeHint.string->str : NULL;
        params->citycodeHint = he->citycodeHint.isSet ? he->citycodeHint.string->str : NULL;
        params->geocodeHint = he->geocodeHint.isSet ? he->geocodeHint.string->str : NULL;
        params->typeHint = he->typeHint.isSet ? he->typeHint.string->str : NULL;
        params->requestedBWDownKiBps = he->bandwidthdown.isSet ? he->bandwidthdown.integer : 0;
        params->requestedBWUpKiBps = he->bandwidthup.isSet ? he->bandwidthup.integer : 0;

        slave_addNewVirtualHost(master->slave, params);

        ProcessCallbackArgs processArgs;
        processArgs.master = master;
        processArgs.hostParams = params;

        /* now handle each virtual process the host will run */
        g_queue_foreach(he->processes, (GFunc)_master_registerProcessCallback, &processArgs);

        /* cleanup for next pass through the loop */
        g_string_free(hostnameBuffer, TRUE);
        g_free(params);
    }
}
Beispiel #3
0
gint main_runShadow(gint argc, gchar* argv[]) {
    /* check the compiled GLib version */
    if (!GLIB_CHECK_VERSION(2, 32, 0)) {
        g_printerr("** GLib version 2.32.0 or above is required but Shadow was compiled against version %u.%u.%u\n",
            (guint)GLIB_MAJOR_VERSION, (guint)GLIB_MINOR_VERSION, (guint)GLIB_MICRO_VERSION);
        return EXIT_FAILURE;
    }

    if(GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION == 40) {
        g_printerr("** You compiled against GLib version %u.%u.%u, which has bugs known to break Shadow. Please update to a newer version of GLib.\n",
                    (guint)GLIB_MAJOR_VERSION, (guint)GLIB_MINOR_VERSION, (guint)GLIB_MICRO_VERSION);
        return EXIT_FAILURE;
    }

    /* check the that run-time GLib matches the compiled version */
    const gchar* mismatch = glib_check_version(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
    if(mismatch) {
        g_printerr("** The version of the run-time GLib library (%u.%u.%u) is not compatible with the version against which Shadow was compiled (%u.%u.%u). GLib message: '%s'\n",
        glib_major_version, glib_minor_version, glib_micro_version,
        (guint)GLIB_MAJOR_VERSION, (guint)GLIB_MINOR_VERSION, (guint)GLIB_MICRO_VERSION,
        mismatch);
        return EXIT_FAILURE;
    }

    /* parse the options from the command line */
    gchar* cmds = g_strjoinv(" ", argv);
    gchar** cmdv = g_strsplit(cmds, " ", 0);
    g_free(cmds);
    Options* options = options_new(argc, cmdv);
    g_strfreev(cmdv);
    if(!options) {
        return EXIT_FAILURE;
    }

    /* if they just want the shadow version, print it and exit */
    if(options_doRunPrintVersion(options)) {
        g_printerr("%s running GLib v%u.%u.%u and IGraph v%s\n%s\n",
                SHADOW_VERSION_STRING,
                (guint)GLIB_MAJOR_VERSION, (guint)GLIB_MINOR_VERSION, (guint)GLIB_MICRO_VERSION,
#if defined(IGRAPH_VERSION)
                IGRAPH_VERSION,
#else
                "(n/a)",
#endif
                SHADOW_INFO_STRING);
        options_free(options);
        return EXIT_SUCCESS;
    }

    /* start up the logging subsystem to handle all future messages */
    Logger* shadowLogger = logger_new(options_getLogLevel(options));
    logger_setDefault(shadowLogger);

    /* disable buffering during startup so that we see every message immediately in the terminal */
    logger_setEnableBuffering(shadowLogger, FALSE);

    gint returnCode = _main_helper(options);

    options_free(options);
    Logger* logger = logger_getDefault();
    if(logger) {
        logger_setDefault(NULL);
        logger_unref(logger);
    }

    g_printerr("** Stopping Shadow, returning code %i (%s)\n", returnCode, (returnCode == 0) ? "success" : "error");
    return returnCode;
}