/** * Register Sensors */ void onlp_snmp_sensors_init(void) { int rv; AIM_LOG_MSG("%s", __FUNCTION__); /* Register all sensor OIDs */ rv = onlp_oid_iterate(ONLP_OID_SYS, 0, onlp_snmp_sensor_register_oid__, NULL); if (rv != ONLP_STATUS_OK) { AIM_LOG_ERROR("%s error %d", __FUNCTION__, rv); } else { AIM_LOG_MSG("%s succeeded.", __FUNCTION__); } }
static void sighup_callback(int socket_id, void *cookie, int read_ready, int write_ready, int error_seen) { uint64_t x; if (read(sighup_eventfd, &x, sizeof(x)) < 0) { /* silence warn_unused_result */ } AIM_LOG_MSG("Received SIGHUP"); }
int aim_main(int argc, char* argv[]) { int size_min = 1, size_max = 65; int count_min = 1, count_max = 129; int s, c; bigring_config_show(&aim_pvs_stdout); for(s = size_min; s <= size_max; s++) { for(c = count_min; c <= count_max; c++) { AIM_LOG_MSG("IntTest(%d,%d)", s, c); bigring_int_test(s, c); AIM_LOG_MSG("IntTest(%d,%d)", c, s); bigring_int_test(c, s); } } for(s = 1; s <= 10; s++) { AIM_LOG_MSG("StrTest(%d, free_entry__)", s); bigring_str_test(s, free_entry__); AIM_LOG_MSG("StrTest(%d, default)", s); bigring_str_test(s, bigring_aim_free_entry); } bigring_config_show(&aim_pvs_stdout); return 0; }
indigo_error_t indigo_fwd_forwarding_features_get(of_features_reply_t *features_reply) { uint32_t capabilities = 0, actions = 0; of_features_reply_n_tables_set(features_reply, 1); OF_CAPABILITIES_FLAG_FLOW_STATS_SET(capabilities, features_reply->version); OF_CAPABILITIES_FLAG_TABLE_STATS_SET(capabilities, features_reply->version); OF_CAPABILITIES_FLAG_PORT_STATS_SET(capabilities, features_reply->version); of_features_reply_capabilities_set(features_reply, capabilities); if (features_reply->version == OF_VERSION_1_0) { OF_FLAG_ENUM_SET(actions, OF_ACTION_TYPE_OUTPUT_BY_VERSION(features_reply->version)); } of_features_reply_actions_set(features_reply, actions); AIM_LOG_MSG("forwarding_features_get() replied"); return INDIGO_ERROR_NONE; }
int onlp_gpio_export(int gpio, onlp_gpio_direction_t direction) { int fd; int rv; fd = onlp_file_open(O_RDONLY, 0, SYS_CLASS_GPIO_PATH, gpio); if(fd < 0) { /* Not exported yet */ char g[32]; ONLPLIB_SNPRINTF(g, sizeof(g)-1, "%d\n", gpio); rv = onlp_file_write_str(g, "/sys/class/gpio/export"); if(rv < 0) { AIM_LOG_ERROR("Exporting gpio %d failed.", gpio); return -1; } } close(fd); const char* s; switch(direction) { case ONLP_GPIO_DIRECTION_NONE: s = NULL; break; /* Don't set direction */ case ONLP_GPIO_DIRECTION_IN: s = "in\n"; break; case ONLP_GPIO_DIRECTION_OUT: s = "out\n"; break; case ONLP_GPIO_DIRECTION_LOW: s = "low\n"; break; case ONLP_GPIO_DIRECTION_HIGH: s = "high\n"; break; default: return ONLP_STATUS_E_PARAM; } if(s) { rv = onlp_file_write_str(s, SYS_CLASS_GPIO_PATH "/direction", gpio); if(rv < 0) { AIM_LOG_MSG("Failed to set gpio%d direction=%s: %{errno}", gpio, direction, errno); return -1; } } return 0; }
/* * This is the first function the ONLP framework will call * after it has validated the the platform is supported using the mechanisms * described above. * * If this function does not return ONL_STATUS_OK * then platform initialization is aborted. */ int onlp_sysi_init(void) { AIM_LOG_MSG("%s", __func__); return ONLP_STATUS_OK; }
static void bigring_int_test(int size, int count) { bigring_t* br = bigring_create(size, NULL); intptr_t c; intptr_t start; intptr_t max; int i; i = bigring_size(br); if(i != size) { AIM_LOG_ERROR("size not correct -- should be %d, is %d\n", size, i); abort(); } for(c = 0; c < count; c++) { #define ASSERT_COUNT(_bc, _vc, _size) \ do { \ if(_bc != ((_vc < _size) ? _vc : _size)) { \ AIM_LOG_ERROR("size = %d, count is %d, should be %d", _size, _bc, _vc); \ abort(); \ } \ } while(0) ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); bigring_push(br, (void*)c); } /** Make sure the entries are correct (module size) */ start = (count <= size) ? 0 : count - size; max = (count <= size) ? count : size; for(i = 0, c = max-1; i < max; i++, start++, c--) { intptr_t v = (intptr_t)bigring_shift(br); if(v != start) { AIM_LOG_ERROR("entry mismatch @%d - expected %p, got %p", i, start, v); abort(); } /* Count should have decremented */ ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); } /* Make sure additional shifts return null */ if(bigring_count(br) != 0) { AIM_LOG_ERROR("count is %d but should be zero", bigring_count(br)); abort(); } c = (intptr_t)bigring_shift(br); if(c != 0) { AIM_LOG_ERROR("shift returned %p when it should have returned null", c); abort(); } /** Add an entry, pop and entry */ c = 1; bigring_push(br, (void*)c); ASSERT_COUNT(bigring_count(br), 1, bigring_size(br)); c = (intptr_t)bigring_shift(br); if(c != 1) { AIM_LOG_ERROR("shift returned %p when it should have returned 1", c); abort(); } ASSERT_COUNT(bigring_count(br), 0, bigring_size(br)); /* Repopulate and iterate instead of shifting */ for(c = 0; c < count; c++) { #define ASSERT_COUNT(_bc, _vc, _size) \ do { \ if(_bc != ((_vc < _size) ? _vc : _size)) { \ AIM_LOG_ERROR("size = %d, count is %d, should be %d", _size, _bc, _vc); \ abort(); \ } \ } while(0) ASSERT_COUNT(bigring_count(br), c, bigring_size(br)); bigring_push(br, (void*)c); } { int j; /* Iterate twice */ for(j = 0; j < 2; j++) { int iter = -42; bigring_lock(br); bigring_iter_start(br, &iter); /** Make sure the entries are correct (module size) */ start = (count <= size) ? 0 : count - size; max = (count <= size) ? count : size; for(i = 0; i < max; i++, start++) { intptr_t v = (intptr_t)bigring_iter_next(br, &iter); if(v != start) { AIM_LOG_ERROR("entry mismatch @%d - expected %p, got %p", i, start, v); } ASSERT_COUNT(bigring_count_locked(br), max, bigring_size(br)); } c = (intptr_t)bigring_iter_next(br, &iter); if(c != 0) { AIM_LOG_MSG("bigring_iter_next() returned %d when it should have returned NULL", c); } c = (intptr_t)bigring_iter_next(br, &iter); if(c != 0) { AIM_LOG_MSG("bigring_iter_next() returned %d when it should have returned NULL", c); } bigring_unlock(br); } } bigring_destroy(br); }
int aim_main(int argc, char* argv[]) { int i; { const char* tstStrings[] = { "This", "is", "a", "complete", "sentence." }; char* join = aim_strjoin(" ", tstStrings, AIM_ARRAYSIZE(tstStrings)); if(strcmp(join, "This is a complete sentence.")) { printf("fail: join='%s'\n", join); } AIM_FREE(join); } for(i = 0; i < argc; i++) { aim_printf(&aim_pvs_stdout, "arg%d: '%s'\n", i, argv[i]); } { /* Test data */ char data[2500]; memset(data, 0xFF, sizeof(data)); aim_printf(&aim_pvs_stdout, "data is %{data}", data, sizeof(data)); } { char* sdata = "DEADBEEFCAFE"; char* data; int size; aim_sparse(&sdata, &aim_pvs_stdout, "{data}", &data, &size); aim_printf(&aim_pvs_stdout, "data is %{data}\n", data, size); aim_free(data); } utest_list(); AIM_LOG_MSG("Should print 1-27"); AIM_LOG_MSG("%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); aim_printf(&aim_pvs_stdout, "aim_pvs_stdout from %s:%d\n", __FILE__, __LINE__); { char c; aim_pvs_t* pvs = aim_pvs_buffer_create(); aim_printf(pvs, "\nConsider "); aim_printf(pvs, "%s ", "the"); aim_printf(pvs, "alphabet: "); for(c = 'A'; c <= 'Z'; c++) { aim_printf(pvs, "%c", c); } aim_printf(pvs, "\n"); { char* s = aim_pvs_buffer_get(pvs); aim_printf(&aim_pvs_stdout, "first: %s", s); free(s); aim_printf(pvs, "(second)"); s = aim_pvs_buffer_get(pvs); aim_printf(&aim_pvs_stdout, "second: %s", s); free(s); aim_pvs_destroy(pvs); } { aim_ratelimiter_t rl; aim_ratelimiter_init(&rl, 10, 5, NULL); /* 5 (6?) tokens available at t=0 */ assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) == 0); assert(aim_ratelimiter_limit(&rl, 0) < 0); /* Another token at t=10 */ assert(aim_ratelimiter_limit(&rl, 10) == 0); assert(aim_ratelimiter_limit(&rl, 10) < 0); /* Nothing at t=15 */ assert(aim_ratelimiter_limit(&rl, 15) < 0); /* 4 more tokens granted by t=50 */ assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) == 0); assert(aim_ratelimiter_limit(&rl, 50) < 0); } { aim_printf(&aim_pvs_stdout, "valgrind_status=%d\n", aim_valgrind_status()); } AIM_LOG_MSG("%{aim_error}", AIM_ERROR_PARAM); } return 0; }
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++; } }
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; } } }
/* * Front to Back * 1. When (LM75-1 + LM75-4)/2 >= 47.95 C, please set CPLD's registor 0xd from "0x08" to "0x0d". (40% to 65%). * 2. When (LM75-1 + LM75-4)/2 >= 49.65 C, please set CPLD's registor 0xd from "0x0d" to "0x10". (65% to 80%) * 3. When (LM75-1 + LM75-4)/2 >= 54.05C, please set CPLD's registor 0x0d from "0x10" to "0x14". (80% to 100%) * 4. When (LM75-1 + LM75-4)/2 <= 52.05C, please set CPLD's registor 0x0d from "0x14" to "0x10". (100% to 80%) * 5. When (LM75-1 + LM75-4)/2 <= 47.05C, please set CPLD's registor 0x0d from "0x10" to "0x0d". (80% to 65%) * 6. When (LM75-1 + LM75-4)/2 <= 42.05C, please set CPLD's registor 0x0d from "0x0d" to "0x08" (65% to 40%). * 7. If CPLD's (0x60 address) registor 0x0C is not equal "0x0", for example "0x1~0x1f", * please set CPLD's registor 0x0d to "0x14" (direct to 100%) <--- Due to FAN Failed occur. * 8. Default value for FAN speed is 40% which is CPLD's registor 0x0d value is "0x08". * Back to Front * 1. When (LM75-1 + LM75-4)/2 >= 40.85 C, please set CPLD's registor 0xd from "0x08" to "0x0d". (40% to 65%). * 2. When (LM75-1 + LM75-4)/2 >= 44.85 C, please set CPLD's registor 0xd from "0x0d" to "0x10". (65% to 80%) * 3. When (LM75-1 + LM75-4)/2 >= 47.4C, please set CPLD's registor 0x0d from "0x10" to "0x14". (80% to 100%) * 4. When (LM75-1 + LM75-4)/2 <= 45.4C, please set CPLD's registor 0x0d from "0x14" to "0x10". (100% to 80%) * 5. When (LM75-1 + LM75-4)/2 <= 40.4C, please set CPLD's registor 0x0d from "0x10" to "0x0d". (80% to 65%) * 6. When (LM75-1 + LM75-4)/2 <= 35.4C, please set CPLD's registor 0x0d from "0x0d" to "0x08" (65% to 40%). * 7. If CPLD's (0x60 address) registor 0x0C is not equal "0x0", for example "0x1~0x1f", * please set CPLD's registor 0x0d to "0x14" (direct to 100%) <--- Due to FAN Failed occur. * 8. Default value for FAN speed is 40% which is CPLD's registor 0x0d value is "0x08". */ int onlp_sysi_platform_manage_fans(void) { int i = 0, arr_size, avg_temp; fan_ctrl_policy_t *policy; int cur_duty_cycle, new_duty_cycle; onlp_thermal_info_t thermal_1, thermal_4; int fd, len; char buf[10] = {0}; /* Get each fan status */ for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++) { onlp_fan_info_t fan_info; if (onlp_fani_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to get fan(%d) status", i); return ONLP_STATUS_E_INTERNAL; } /* Decision 1: Set fan as full speed if any fan is failed. */ if (!(fan_info.status & ONLP_FAN_STATUS_PRESENT) || fan_info.status & ONLP_FAN_STATUS_FAILED) { AIM_LOG_MSG("Setting max"); return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX); } /* Get fan direction (Only get the first one since all fan direction are the same) */ if (i == 1) { if (fan_info.status & ONLP_FAN_STATUS_F2B) { policy = fan_ctrl_policy_f2b; arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_f2b); } else { policy = fan_ctrl_policy_b2f; arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_b2f); } } } /* Get current fan speed */ fd = open(FAN_SPEED_CTRL_PATH, O_RDONLY); if (fd == -1){ AIM_LOG_ERROR("Unable to open fan speed control node (%s)", FAN_SPEED_CTRL_PATH); return ONLP_STATUS_E_INTERNAL; } len = read(fd, buf, sizeof(buf)); close(fd); if (len <= 0) { AIM_LOG_ERROR("Unable to read fan speed from (%s)", FAN_SPEED_CTRL_PATH); return ONLP_STATUS_E_INTERNAL; } cur_duty_cycle = atoi(buf); /* Decision 2: If no matched fan speed is found from the policy, * use FAN_DUTY_CYCLE_MIN as default speed */ for (i = 0; i < arr_size; i++) { if (policy[i].duty_cycle != cur_duty_cycle) continue; break; } if (i == arr_size) { return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MIN); } /* Get current temperature */ if (onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &thermal_1) != ONLP_STATUS_OK || onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(4), &thermal_4) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read thermal status"); return ONLP_STATUS_E_INTERNAL; } avg_temp = (thermal_1.mcelsius + thermal_4.mcelsius) / 2; /* Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature */ new_duty_cycle = cur_duty_cycle; if ((avg_temp >= policy[i].temp_up_adjust) && (cur_duty_cycle != FAN_DUTY_CYCLE_MAX)) { new_duty_cycle = policy[i+1].duty_cycle; } else if ((avg_temp <= policy[i].temp_down_adjust) && (cur_duty_cycle != FAN_DUTY_CYCLE_MIN)) { new_duty_cycle = policy[i-1].duty_cycle; } if (new_duty_cycle == cur_duty_cycle) { /* Duty cycle does not change, just return */ return ONLP_STATUS_OK; } return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), new_duty_cycle); }
int onlp_sfpi_post_insert(int port, sff_info_t* info) { /* * IF any platform-programming must be performed based * on the actual SFP that was inserted (for example, custom equalizer settings) * then it should be performed by this function. * * If not custom programming must be performed, then do nothing. * This function is optional. */ int front_port=0; sfp_tranceiver_cable_type_t cable_type = SFP_TRANCEIVER_CABLE_TYPE_FIBER; switch(info->media_type) { case SFF_MEDIA_TYPE_FIBER: cable_type = SFP_TRANCEIVER_CABLE_TYPE_FIBER; break; case SFF_MEDIA_TYPE_COPPER: switch(info->length) { case 1: case 2: AIM_LOG_MSG("Port %d EQ 1M", port); cable_type = SFP_TRANCEIVER_CABLE_TYPE_COPPER_1M; break; case 3: case 4: AIM_LOG_MSG("Port %d EQ 3M", port); cable_type = SFP_TRANCEIVER_CABLE_TYPE_COPPER_3M; break; case 5: case 6: AIM_LOG_MSG("Port %d EQ 5M", port); cable_type = SFP_TRANCEIVER_CABLE_TYPE_COPPER_5M; break; case 7: AIM_LOG_MSG("Port %d EQ 7M", port); cable_type = SFP_TRANCEIVER_CABLE_TYPE_COPPER_7M; break; default: AIM_LOG_MSG("Port %d EQ 7M (MAX)", port); /* Nothing beyond 7M is supported. Best we can do is use the 7M settings. */ cable_type = SFP_TRANCEIVER_CABLE_TYPE_COPPER_7M; break; } break; default: AIM_LOG_WARN("port(%d) media_type(%d) length(%d) is not supported\r\n", port, info->media_type, info->length); return ONLP_STATUS_E_INTERNAL; } front_port=SFP_MAP_API_2_FRONT_PORT(port); if (set_active_port(front_port) < 0) { AIM_LOG_ERROR("Unable to set active port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } if (set_equalizer_type(cable_type) < 0) { AIM_LOG_ERROR("Unable to set port(%d) media_type(%d) length(%d)\r\n", port, info->media_type, info->length); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; }
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++; } }
int aim_main(int argc, char *argv[]) { set_crash_handler(crash_handler); AIM_LOG_STRUCT_REGISTER(); loci_logger = ofagent_loci_logger; core_cfg.stats_check_ms = 900; parse_options(argc, argv); /* Setup logging from command line options */ if (loglevel >= LOGLEVEL_DEFAULT) { aim_log_fid_set_all(AIM_LOG_FLAG_MSG, 1); 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("ofagent", LOG_NDELAY, LOG_DAEMON)); } create_pidfile(); AIM_LOG_MSG("Starting ofagent %s (%s %s) pid %d", ofagent_version, ofagent_build_id, ofagent_build_os, getpid()); /* Increase maximum number of file descriptors */ struct rlimit rlim = { .rlim_cur = SOCKETMANAGER_CONFIG_MAX_SOCKETS, .rlim_max = SOCKETMANAGER_CONFIG_MAX_SOCKETS }; if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) { AIM_LOG_WARN("Failed to increase RLIMIT_NOFILE"); } /* 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 (bcm_driver_init() < 0) { AIM_LOG_FATAL("Failed to initialize BCM driver"); 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_VERBOSE("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 (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; } if (bcm_driver_enable_set(1) < 0) { AIM_LOG_FATAL("Failed to enable BCM driver"); return 1; } /* Add controller from command line */ { biglist_t *element; char *str; BIGLIST_FOREACH_DATA(element, controllers, char *, str) { AIM_LOG_VERBOSE("Adding controller %s", str); indigo_cxn_protocol_params_t proto; if (parse_controller(str, &proto, OF_TCP_PORT) < 0) { AIM_LOG_FATAL("Failed to parse controller string '%s'", str); return 1; } indigo_cxn_config_params_t config = { .version = OF_VERSION_1_0, .cxn_priority = 0, .local = 0, .listen = 0, .periodic_echo_ms = 2000, .reset_echo_count = 3, }; indigo_controller_id_t id; if (indigo_controller_add(&proto, &config, &id) < 0) { AIM_LOG_FATAL("Failed to add controller %s", str); return 1; } } } ind_core_mfr_desc_set(mfr_desc); snprintf(sw_desc, sizeof(sw_desc), "ofagent %s %s %s", ofagent_version, ofagent_build_id, ofagent_build_os); ind_core_sw_desc_set(sw_desc); // TODO //read_hardware_version(hw_desc); ind_core_hw_desc_set(hw_desc); char hostname[256]; char domainname[256]; if (gethostname(hostname, sizeof(hostname))) { sprintf(hostname, "(unknown)"); } if (getdomainname(domainname, sizeof(domainname))) { sprintf(domainname, "(unknown)"); } snprintf(dp_desc, sizeof(dp_desc), "%s.%s pid %d", hostname, domainname, getpid()); ind_core_dp_desc_set(dp_desc); AIM_LOG_INFO("Datapath description: %s", dp_desc); ind_core_serial_num_set(serial_num); /* The SIGHUP handler triggers sighup_callback to run in the main loop. */ if ((sighup_eventfd = eventfd(0, 0)) < 0) { AIM_LOG_FATAL("Failed to allocate eventfd"); abort(); } signal(SIGHUP, sighup); if (ind_soc_socket_register(sighup_eventfd, sighup_callback, NULL) < 0) { abort(); } /* The SIGTERM handler triggers sigterm_callback to run in the main loop. */ if ((sigterm_eventfd = eventfd(0, 0)) < 0) { AIM_LOG_FATAL("Failed to allocate eventfd"); abort(); } signal(SIGTERM, sigterm); if (ind_soc_socket_register(sigterm_eventfd, sigterm_callback, NULL) < 0) { abort(); } /* TODO Start handling upcalls */ //ind_ovs_enable(); //packet_trace_init(datapath_name); ind_soc_select_and_run(-1); AIM_LOG_MSG("Stopping ofagent %s", ofagent_version); ind_core_finish(); bcm_driver_finish(); ind_cxn_finish(); ind_soc_finish(); return 0; }