Exemplo n.º 1
0
Arquivo: main.c Projeto: kwang-bsn/ivs
int
aim_main(int argc, char* argv[])
{
    AIM_LOG_STRUCT_REGISTER();

    /*
     * We queue many (up to 20) 64KB messages before sending them on the socket
     * with a single writev(). After we free all the messages the malloc
     * implementation would see we have more than 128KB (the default trim value)
     * free and return it to the OS with a call to brk(). Every time we
     * allocate a new message we have to get the memory with brk() all over
     * again.
     *
     * Increasing the trim threshold above the size of our working set
     * eliminates this churn.
     */
    mallopt(M_TRIM_THRESHOLD, 2*1024*1024);

    loci_logger = ivs_loci_logger;

    core_cfg.expire_flows = 1;
    core_cfg.stats_check_ms = 900;
    core_cfg.disconnected_mode = INDIGO_CORE_DISCONNECTED_MODE_STICKY;

    parse_options(argc, argv);

    /* Setup logging from command line options */

    if (loglevel >= LOGLEVEL_DEFAULT) {
        aim_log_fid_set_all(AIM_LOG_FLAG_FATAL, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_ERROR, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_WARN, 1);
    }

    if (loglevel >= LOGLEVEL_VERBOSE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_VERBOSE, 1);
    }

    if (loglevel >= LOGLEVEL_TRACE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_TRACE, 1);
    }

    if (use_syslog) {
        aim_log_pvs_set_all(aim_pvs_syslog_open("ivs", LOG_NDELAY, LOG_DAEMON));
    }

    AIM_LOG_MSG("Starting %s (%s) pid %d", program_version, AIM_STRINGIFY(BUILD_ID), getpid());

    /* Initialize all modules */

    if (ind_soc_init(&soc_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo socket manager");
        return 1;
    }

    if (ind_cxn_init(&cxn_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo connection manager");
        return 1;
    }

    if (ind_core_init(&core_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo core module");
        return 1;
    }

    if (ind_ovs_init(datapath_name, max_flows) < 0) {
        AIM_LOG_FATAL("Failed to initialize OVSDriver module");
        return 1;
    }

    if (lacpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize LACP Agent module");
        return 1;
    }

    if (lldpa_system_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize LLDP Agent module");
        return 1;
    }

    if (arpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize ARP Agent module");
        return 1;
    }

    if (router_ip_table_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize Router IP table module");
        return 1;
    }

    if (icmpa_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize ICMP Agent module");
        return 1;
    }

    if (dhcpra_system_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize DHCP relay table and agent module");
        return 1;
    }

    if (enable_tunnel) {
        if (ind_ovs_tunnel_init() < 0) {
            AIM_LOG_FATAL("Failed to initialize tunneling");
            return 1;
        }
    }

    if (pipeline == NULL) {
        if (openflow_version == NULL || !strcmp(openflow_version, "1.0")) {
            pipeline = "standard-1.0";
        } else if (!strcmp(openflow_version, "1.3")) {
            pipeline = "standard-1.3";
        } else {
            AIM_DIE("unexpected OpenFlow version");
        }
    }

    AIM_LOG_INFO("Initializing forwarding pipeline '%s'", pipeline);
    indigo_error_t rv = pipeline_set(pipeline);
    if (rv < 0) {
        AIM_LOG_FATAL("Failed to set pipeline: %s", indigo_strerror(rv));
        return 1;
    }

#if 0
    /* TODO Configuration module installs its own SIGHUP handler. */
    if (ind_cfg_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo configuration module");
        return 1;
    }
#endif

    if (config_filename) {
        ind_cfg_filename_set(config_filename);
        if (ind_cfg_load() < 0) {
            AIM_LOG_FATAL("Failed to load configuration file");
            return 1;
        }
    }

    if (dpid) {
        indigo_core_dpid_set(dpid);
    }

    /* Enable all modules */

    if (ind_soc_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo socket manager");
        return 1;
    }

    if (ind_cxn_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo connection manager");
        return 1;
    }

    if (ind_core_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo core module");
        return 1;
    }

    /* Add interfaces from command line */
    {
        biglist_t *element;
        char *str;
        int index = 1;
        BIGLIST_FOREACH_DATA(element, interfaces, char *, str) {
            AIM_LOG_MSG("Adding interface %s (port %d)", str, index);
            if (indigo_port_interface_add(str, index, NULL)) {
                AIM_LOG_FATAL("Failed to add interface %s", str);
                return 1;
            }
            index++;
        }
    }
Exemplo n.º 2
0
int
aim_main(int argc, char* argv[])
{
    AIM_LOG_STRUCT_REGISTER();

    core_cfg.expire_flows = 1;
    core_cfg.stats_check_ms = 900;
    core_cfg.disconnected_mode = INDIGO_CORE_DISCONNECTED_MODE_STICKY;

    parse_options(argc, argv);

    /* Setup logging from command line options */

    if (loglevel >= LOGLEVEL_DEFAULT) {
        aim_log_fid_set_all(AIM_LOG_FLAG_FATAL, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_ERROR, 1);
        aim_log_fid_set_all(AIM_LOG_FLAG_WARN, 1);
    }

    if (loglevel >= LOGLEVEL_VERBOSE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_VERBOSE, 1);
    }

    if (loglevel >= LOGLEVEL_TRACE) {
        aim_log_fid_set_all(AIM_LOG_FLAG_TRACE, 1);
    }

    if (use_syslog) {
        aim_log_pvs_set_all(aim_pvs_syslog_open("ivs", LOG_NDELAY, LOG_DAEMON));
    }

    AIM_LOG_MSG("Starting %s (%s)", program_version, AIM_STRINGIFY(BUILD_ID));

    /* Initialize all modules */

    if (ind_soc_init(&soc_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo socket manager");
        return 1;
    }

    if (ind_cxn_init(&cxn_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo connection manager");
        return 1;
    }

    if (ind_core_init(&core_cfg) < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo core module");
        return 1;
    }

    if (ind_ovs_init(datapath_name) < 0) {
        AIM_LOG_FATAL("Failed to initialize OVSDriver module");
        return 1;
    }

    if (enable_tunnel) {
        if (ind_ovs_tunnel_init() < 0) {
            AIM_LOG_FATAL("Failed to initialize tunneling");
            return 1;
        }
    }

#if 0
    /* TODO Configuration module installs its own SIGHUP handler. */
    if (ind_cfg_init() < 0) {
        AIM_LOG_FATAL("Failed to initialize Indigo configuration module");
        return 1;
    }
#endif

    if (config_filename) {
        ind_cfg_filename_set(config_filename);
        if (ind_cfg_load() < 0) {
            AIM_LOG_FATAL("Failed to load configuration file");
            return 1;
        }
    }

    if (dpid) {
        indigo_core_dpid_set(dpid);
    }

    /* Enable all modules */

    if (ind_soc_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo socket manager");
        return 1;
    }

    if (ind_cxn_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo connection manager");
        return 1;
    }

    if (ind_core_enable_set(1) < 0) {
        AIM_LOG_FATAL("Failed to enable Indigo core module");
        return 1;
    }

    /* Add interfaces from command line */
    {
        biglist_t *element;
        char *str;
        int index = 1;
        BIGLIST_FOREACH_DATA(element, interfaces, char *, str) {
            AIM_LOG_MSG("Adding interface %s (port %d)", str, index);
            if (indigo_port_interface_add(str, index, NULL)) {
                AIM_LOG_FATAL("Failed to add interface %s", str);
                return 1;
            }
            index++;
        }
    }
Exemplo n.º 3
0
Arquivo: main.c Projeto: kwang-bsn/ivs
static void
parse_options(int argc, char **argv)
{
    while (1) {
        int option_index = 0;

        /* Options without short equivalents */
        enum long_opts {
            OPT_START = 256,
            OPT_NAME,
            OPT_DPID,
            OPT_SYSLOG,
            OPT_TUNNEL,
            OPT_VERSION,
            OPT_MAX_FLOWS,
            OPT_PIPELINE,
        };

        static struct option long_options[] = {
            {"verbose",     no_argument,       0,  'v' },
            {"trace",       no_argument,       0,  't' },
            {"interface",   required_argument, 0,  'i' },
            {"controller",  required_argument, 0,  'c' },
            {"listen",      required_argument, 0,  'l' },
            {"pipeline",    optional_argument, 0,  OPT_PIPELINE },
            {"dpid",        required_argument, 0,  OPT_DPID },
            {"syslog",      no_argument,       0,  OPT_SYSLOG },
            {"tunnel",      no_argument,       0,  OPT_TUNNEL },
            {"help",        no_argument,       0,  'h' },
            {"version",     no_argument,       0,  OPT_VERSION },
            /* Undocumented options */
            {"name",        required_argument, 0,  OPT_NAME },
            {"max-flows",   required_argument, 0,  OPT_MAX_FLOWS },
            {"config-file", required_argument, 0,  'f' },
            {"openflow-version", required_argument, 0, 'V' },
            {0,             0,                 0,  0 }
        };

        int c = getopt_long(argc, argv, "vtl:i:c:f:hV:",
                            long_options, &option_index);
        if (c == -1) {
            break;
        }

        switch (c) {
        case 'v':
            loglevel = LOGLEVEL_VERBOSE;
            break;

        case 't':
            loglevel = LOGLEVEL_TRACE;
            break;

        case 'c':
            controllers = biglist_append(controllers, optarg);
            break;

        case 'l':
            listeners = biglist_append(listeners, optarg);
            break;

        case 'i':
            interfaces = biglist_append(interfaces, optarg);
            break;

        case 'f':
            config_filename = optarg;
            break;

        case 'V':
            openflow_version = optarg;
            break;

        case OPT_NAME:
            datapath_name = strdup(optarg);
            break;

        case OPT_DPID:
            dpid = strtoll(optarg, NULL, 16);
            break;

        case OPT_SYSLOG:
            use_syslog = 1;
            break;

        case OPT_TUNNEL:
            enable_tunnel = 1;
            break;

        case OPT_VERSION:
            printf("%s (%s)\n", program_version, AIM_STRINGIFY(BUILD_ID));
            exit(0);
            break;

        case OPT_MAX_FLOWS:
            max_flows = strtoll(optarg, NULL, 0);
            core_cfg.max_flowtable_entries = max_flows;
            AIM_LOG_MSG("Setting max flows to %d", max_flows);
            break;

        case OPT_PIPELINE:
            pipeline = optarg ? optarg : "experimental";
            break;

        case 'h':
        case '?':
            printf("ivs: Indigo Virtual Switch\n");
            printf("Usage: ivs [OPTION]...\n");
            printf("\n");
            printf("  -v, --verbose               Verbose logging\n");
            printf("  -t, --trace                 Very verbose logging\n");
            printf("  -c, --controller=IP:PORT    Connect to a controller at startup\n");
            printf("  -l, --listen=IP:PORT        Listen for dpctl connections\n");
            printf("  -i, --interface=INTERFACE   Attach a network interface at startup\n");
            printf("  --pipeline=NAME             Set the default forwarding pipeline (standard-1.0 or standard-1.3)\n");
            //printf("  -f, --config-file=FILE      Read a configuration file\n");
            //printf("  --name=NAME                 Set the name of the kernel datapath (default indigo)\n");
            printf("  --dpid=DPID                 Set datapath ID (default autogenerated)\n");
            printf("  --syslog                    Log to syslog instead of stderr\n");
            printf("  --tunnel                    Enable flow-based GRE tunneling (requires controller support)\n");
            printf("  -h,--help                   Display this help message and exit\n");
            printf("  --version                   Display version information and exit\n");
            exit(c == 'h' ? 0 : 1);
            break;
        }
    }
}
Exemplo n.º 4
0
#include <OFStateManager/ofstatemanager.h>
#include <Configuration/configuration.h>
#include <pipeline/pipeline.h>

#include <bcm_driver/bcm_driver.h>

#ifndef BUILD_ID
#define BUILD_ID dev
#endif

#ifndef BUILD_OS
#define BUILD_OS ubuntu 14.04
#endif

const char *ofagent_version = "0.1";
const char *ofagent_build_id = AIM_STRINGIFY(BUILD_ID);
const char *ofagent_build_os = AIM_STRINGIFY(BUILD_OS);

of_desc_str_t mfr_desc = "SK Telecom";
of_desc_str_t sw_desc = "OFAgent";
of_desc_str_t hw_desc = "Facebook Wedge";
of_desc_str_t dp_desc = "";
of_serial_num_t serial_num = "";

static ind_soc_config_t soc_cfg;
static ind_cxn_config_t cxn_cfg;
static ind_core_config_t core_cfg;

static int sighup_eventfd;
static int sigterm_eventfd;