コード例 #1
0
ファイル: expiration.c プロジェクト: heecheolsong/indigo
void
ind_core_expiration_timer(void *cookie)
{
    int rv;
    (void) cookie;

    if (task_running) {
        AIM_LOG_VERBOSE("Not starting expiration task because it is already running");
        return;
    }

    if ((rv = ind_soc_task_register(expiration_task, NULL,
                                    IND_SOC_NORMAL_PRIORITY)) < 0) {
        AIM_LOG_ERROR("Failed to start flow expiration task: %s",
                      indigo_strerror(rv));
    } else {
        task_running = true;
    }
}
コード例 #2
0
ファイル: sfpi.c プロジェクト: carlroth/OpenNetworkLinux
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
    char* path;
    int len = 0;
    /*
     * Read the SFP eeprom into data[]
     *
     * Return MISSING if SFP is missing.
     * Return OK if eeprom is read
     */
    memset(data, 0, 256);
    path = sfp_get_port_path(port, "eeprom");
    if (onlp_file_read(&data[0], 256, &len, path) < 0) {
        AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
        return ONLP_STATUS_E_INTERNAL;
    }
    return ONLP_STATUS_OK;
}
コード例 #3
0
ファイル: flowtable.c プロジェクト: capveg/ivs
/* Documented in flowtable.h */
void
flowtable_insert(struct flowtable *ft, struct flowtable_entry *fte)
{
    struct list_links *cur;
    struct list_head *ft_bucket = flowtable_bucket(ft, &fte->mask);

    /* Check if flow table entry is present for the new flow entry mask */
    LIST_FOREACH(ft_bucket, cur) {
        struct flowtable_specific *cur_fts =
            container_of(cur, links, struct flowtable_specific);
        if (memcmp(&cur_fts->flow_mask, &fte->mask, sizeof(struct flowtable_key)) == 0) {
            /* If present, insert the new flow entry */
            flowtable_specific_insert(cur_fts, fte);
            cur_fts->flow_cnt++;

            if(fte->priority > cur_fts->max_priority)
                cur_fts->max_priority = fte->priority;
            return;
        }
    }

    /* If not present, then create a specific flowtable */
    struct flowtable_specific *new_fts = calloc(1, sizeof(*new_fts));
    if(new_fts == NULL) {
        AIM_LOG_ERROR("Failed to allocate specific flowtable");
        return;
    }

    int i;
    for (i = 0; i < FLOWTABLE_SPECIFIC_BUCKETS; i++) {
        list_init(&new_fts->buckets[i]);
    }

    new_fts->max_priority = fte->priority;
    new_fts->flow_mask = fte->mask;
    flowtable_specific_insert(new_fts, fte);
    new_fts->flow_cnt = 1;
    flowtable_specific_list_add(ft, new_fts);

    list_push(ft_bucket, &new_fts->links);
    return;
}
コード例 #4
0
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
    char* path = msn2100_sfp_get_port_path(port, "");

    /*
     * Read the SFP eeprom into data[]
     *
     * Return MISSING if SFP is missing.
     * Return OK if eeprom is read
     */
    memset(data, 0, 256);

    if (onlplib_sfp_eeprom_read_file(path, data) != 0) {
        AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
        return ONLP_STATUS_E_INTERNAL;
    }

    return ONLP_STATUS_OK;
}
コード例 #5
0
ファイル: sfpi.c プロジェクト: Lewis-Kang/OpenNetworkLinux
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
    char* path = as7512_32x_sfp_get_port_path(port, "sfp_eeprom");

    /*
     * Read the SFP eeprom into data[]
     *
     * Return MISSING if SFP is missing.
     * Return OK if eeprom is read
     */
    memset(data, 0, 256);

    if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) {
        AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port);
        return ONLP_STATUS_E_INTERNAL;
    }

    return ONLP_STATUS_OK;
}
コード例 #6
0
int
onlp_i2c_dev_readb(onlp_i2c_dev_t* dev, uint8_t offset, uint32_t flags)
{
    int error, rv;

    if( (error = dev_mux_channels_select__(dev, flags)) < 0) {
        return error;
    }

    if( (rv = onlp_i2c_readb(dev->bus, dev->addr, offset, flags)) < 0) {
        AIM_LOG_ERROR("Device %s: readb() failed: %d",
                      dev->name, rv);
        return rv;
    }

    if( (error = dev_mux_channels_deselect__(dev, flags)) < 0) {
        return error;
    }

    return rv;
}
コード例 #7
0
ファイル: sfpi.c プロジェクト: carlroth/OpenNetworkLinux
int
onlp_sfpi_is_present(int port)
{
    /*
     * Return 1 if present.
     * Return 0 if not present.
     * Return < 0 if error.
     */
    int present;
    int bus, addr;

    addr = (port < 29) ? 61 : 62;
    bus  = (addr == 61) ? 10 : 11;
    
	if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) {
        AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port);
        return ONLP_STATUS_E_INTERNAL;
    }

    return present;
}
コード例 #8
0
int psu_ym2651y_pmbus_info_get(int id, char *node, int *value)
{
    int  ret = 0;
    char path[PSU_NODE_MAX_PATH_LEN] = {0};
    
    *value = 0;

    if (PSU1_ID == id) {
        sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
    }
    else {
        sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
    }
   
    if (onlp_file_read_int(value, path) < 0) {
        AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
        return ONLP_STATUS_E_INTERNAL;
    }

    return ret;
}
コード例 #9
0
ファイル: pipeline_lua.c プロジェクト: kenchiang/ivs
static void
handle_lua_command_request(indigo_cxn_id_t cxn_id, of_object_t *msg)
{
    const int max_reply_size = UINT16_MAX -
                               of_object_fixed_len[msg->version][OF_BSN_LUA_COMMAND_REPLY];
    uint32_t xid;
    of_octets_t request_data;
    of_bsn_lua_command_request_xid_get(msg, &xid);
    of_bsn_lua_command_request_data_get(msg, &request_data);

    pipeline_lua_allocator_reset();
    void *request_buf = pipeline_lua_allocator_dup(request_data.data, request_data.bytes);
    void *reply_buf = pipeline_lua_allocator_alloc(max_reply_size);

    lua_rawgeti(lua, LUA_REGISTRYINDEX, command_ref);
    lua_pushlightuserdata(lua, request_buf);
    lua_pushinteger(lua, request_data.bytes);
    lua_pushlightuserdata(lua, reply_buf);
    lua_pushinteger(lua, max_reply_size);

    if (lua_pcall(lua, 4, 1, 0) != 0) {
        AIM_LOG_ERROR("Failed to execute command xid=%#x: %s", xid, lua_tostring(lua, -1));
        indigo_cxn_send_error_reply(
            cxn_id, msg, OF_ERROR_TYPE_BAD_REQUEST, OF_REQUEST_FAILED_EPERM);
        return;
    }

    int reply_size = lua_tointeger(lua, 0);
    AIM_TRUE_OR_DIE(reply_size >= 0 && reply_size < max_reply_size);
    lua_settop(lua, 0);

    of_object_t *reply = of_bsn_lua_command_reply_new(msg->version);
    of_bsn_lua_command_reply_xid_set(reply, xid);
    of_octets_t reply_data = { .data = reply_buf, .bytes = reply_size };
    if (of_bsn_lua_command_reply_data_set(reply, &reply_data) < 0) {
        AIM_DIE("Unexpectedly failed to set data in of_bsn_lua_command_reply");
    }

    indigo_cxn_send_controller_message(cxn_id, reply);
}
コード例 #10
0
ファイル: gpio.c プロジェクト: XianliangJ/OpenNetworkLinux
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;
}
コード例 #11
0
/*
 * lacpa_start_current_while_timer
 */
void
lacpa_start_current_while_timer (lacpa_port_t *port)
{
    if (!port) return;

    AIM_LOG_TRACE("Start current_while timer for port: %d", 
                  port->actor.port_no);

    if (port->lacp_state == LACPA_MACHINE_AGENT_DEFAULTED) {
        AIM_LOG_TRACE("Failed to Start current_while timer since Agent State: "
                      "%{lacpa_machine}", port->lacp_state);
        return;
    }

    if (ind_soc_timer_event_register(lacpa_current_while_expiration_timer_cb,
                                     port, LACPA_IS_STATE_LACP_TIMEOUT(
                                     port->actor.state)? LACP_SHORT_TIMEOUT_MS: 
                                     LACP_LONG_TIMEOUT_MS) < 0) {
        AIM_LOG_ERROR("Failed to register timer for port %d", 
                      port->actor.port_no);
    }
}
コード例 #12
0
/*
 * icmp_send_packet_out
 *
 * Send the ICMP message out
 */
indigo_error_t
icmpa_send_packet_out (of_octets_t *octets)
{
    of_packet_out_t    *obj;
    of_list_action_t   *list;
    of_action_output_t *action;
    indigo_error_t     rv;

    if (!octets) return INDIGO_ERROR_PARAM;

    obj = of_packet_out_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(obj != NULL);

    list = of_list_action_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(list != NULL);

    action = of_action_output_new(OF_VERSION_1_3);
    AIM_TRUE_OR_DIE(action != NULL);

    of_packet_out_buffer_id_set(obj, -1);
    of_packet_out_in_port_set(obj, OF_PORT_DEST_CONTROLLER);
    of_action_output_port_set(action, OF_PORT_DEST_USE_TABLE);
    of_list_append(list, action);
    of_object_delete(action);
    rv = of_packet_out_actions_set(obj, list);
    AIM_ASSERT(rv == 0);
    of_object_delete(list);

    rv = of_packet_out_data_set(obj, octets);
    if (rv < 0) {
        AIM_LOG_ERROR("ICMPA: Failed to set data on packet out");
        of_packet_out_delete(obj);
        return rv;
    }

    rv = indigo_fwd_packet_out(obj);
    of_packet_out_delete(obj);
    return rv;
}
コード例 #13
0
ファイル: psui.c プロジェクト: carlroth/OpenNetworkLinux
static int 
psu_status_info_get(int id, char *node, int *value)
{
    int ret = 0;
    char path[PSU_NODE_MAX_PATH_LEN] = {0};
    
    *value = 0;

    if (PSU1_ID == id) {
        ret = onlp_file_read_int(value, "%s%s", PSU1_AC_HWMON_PREFIX, node);
    }
    else if (PSU2_ID == id) {
        ret = onlp_file_read_int(value, "%s%s", PSU2_AC_HWMON_PREFIX, node);
    }

    if (ret < 0) {
        AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path);
        return ONLP_STATUS_E_INTERNAL;
    }

    return ret;
}
コード例 #14
0
ファイル: pipeline_lua.c プロジェクト: kenchiang/ivs
static void
process_pktin(uint8_t *data, unsigned int len,
              uint8_t reason, uint64_t metadata,
              struct ind_ovs_parsed_key *pkey)
{
    lua_rawgeti(lua, LUA_REGISTRYINDEX, pktin_ref);
    lua_pushlightuserdata(lua, data);
    lua_pushinteger(lua, len);
    lua_pushinteger(lua, reason);
    lua_pushinteger(lua, metadata);

    if (lua_pcall(lua, 4, 1, 0) != 0) {
        AIM_LOG_ERROR("Failed to execute script: %s", lua_tostring(lua, -1));
    }

    bool send_to_controller = lua_toboolean(lua, 0);
    lua_settop(lua, 0);

    if (send_to_controller) {
        ind_ovs_pktin(pkey->in_port, data, len, reason, metadata, pkey);
    }
}
コード例 #15
0
int psu_ym2651y_pmbus_info_set(int id, char *node, int value)
{
    char path[PSU_NODE_MAX_PATH_LEN] = {0};

	switch (id) {
	case PSU1_ID:
		sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node);
		break;
	case PSU2_ID:
		sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node);
		break;
	default:
		return ONLP_STATUS_E_UNSUPPORTED;
	};

    if (onlp_file_write_integer(path, value) < 0) {
        AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path);
        return ONLP_STATUS_E_INTERNAL;
    }

    return ONLP_STATUS_OK;
}
コード例 #16
0
int
onlp_i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size,
                    uint8_t* rdata, uint32_t flags)
{
    int fd;

    fd = onlp_i2c_open(bus, addr, flags);

    if(fd < 0) {
        return fd;
    }

    int count = size;
    uint8_t* p = rdata;
    while(count > 0) {
        int rsize = (count >= ONLPLIB_CONFIG_I2C_BLOCK_SIZE) ? ONLPLIB_CONFIG_I2C_BLOCK_SIZE : count;
        int rv = i2c_smbus_read_i2c_block_data(fd,
                                               p - rdata,
                                               rsize,
                                               p);

        if(rv != rsize) {
            AIM_LOG_ERROR("i2c-%d: reading address 0x%x, offset %d, size=%d failed: %{errno}",
                          bus, addr, p - rdata, rsize, errno);
            goto error;
        }

        p += rsize;
        count -= rsize;
    }

    close(fd);
    return 0;

 error:
    close(fd);
    return -1;
}
コード例 #17
0
ファイル: psui.c プロジェクト: carlroth/OpenNetworkLinux
static int 
psu_status_info_get(int id, char *node, int *value)
{
    int ret = 0;
    char node_path[ONLP_NODE_MAX_PATH_LEN] = {0};
    
    *value = 0;
    if (PSU1_ID == id) {
	sprintf(node_path, status_devfiles__[id]);
    }
    else if (PSU2_ID == id) {
	sprintf(node_path, status_devfiles__[id]);
    }
    
    ret = onlp_file_read_int(value, node_path);

    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", node_path);
	return ONLP_STATUS_E_INTERNAL;
    }

    return ONLP_STATUS_OK;
}
コード例 #18
0
/*
 * lacpa_start_churn_detection_timer
 *
 * Churn Detection Timer
 */
void
lacpa_start_churn_detection_timer (lacpa_port_t *port)
{
    if (!port) return;

    AIM_LOG_TRACE("Start Churn Detection timer for port: %d", 
                  port->actor.port_no);

    if (port->lacp_state == LACPA_MACHINE_AGENT_DEFAULTED) {
        AIM_LOG_TRACE("Failed to Start Churn Detection timer since Agent State:"
                      " %{lacpa_machine}", port->lacp_state);
        return; 
    }
 
    if (ind_soc_timer_event_register(lacpa_churn_expiration_timer_cb, port,
                                     LACP_CHURN_DETECTION_TIMEOUT_MS) < 0) {
        AIM_LOG_ERROR("Failed to register timer for port %d",   
                      port->actor.port_no);
        return;
    }
    
    port->churn_detection_running = true;
}
コード例 #19
0
ファイル: file.c プロジェクト: brandonchuang/OpenNetworkLinux
/**
 * @brief Connects to a unix domain socket.
 * @param path The socket path.
 */
static int
ds_connect__(const char* path)
{
    int fd;
    struct sockaddr_un addr;

    if( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
        AIM_LOG_ERROR("socket: %{errno}", errno);
        return -1;
    }

    /*
     * UDS connects must be non-blocking.
     */
    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1);

    if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) {

        /*
         * Set blocking with a 5 second timeout on all domain socket read/write operations.
         */
        struct timeval tv;

        fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
        tv.tv_sec = 5;
        tv.tv_usec = 0;
        setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
        return fd;
    }
    else {
        return ONLP_STATUS_E_MISSING;
    }
}
コード例 #20
0
ファイル: file.c プロジェクト: brandonchuang/OpenNetworkLinux
int
onlp_file_vwrite(uint8_t* data, int len, const char* fmt, va_list vargs)
{
    int fd;
    char* fname = NULL;
    int rv;
    int wlen;

    if ((fd = vopen__(&fname, O_WRONLY, fmt, vargs)) < 0) {
        rv = fd;
    }
    else {
        if ((wlen = write(fd, data, len)) != len) {
            AIM_LOG_ERROR("Failed to write output file '%s'", fname);
            rv = ONLP_STATUS_E_INTERNAL;
        }
        else {
            rv = ONLP_STATUS_OK;
        }
        close(fd);
    }
    aim_free(fname);
    return rv;
}
コード例 #21
0
ファイル: file.c プロジェクト: brandonchuang/OpenNetworkLinux
int
onlp_file_vread(uint8_t* data, int max, int* len, const char* fmt, va_list vargs)
{
    int fd;
    char* fname = NULL;
    int rv;

    if ((fd = vopen__(&fname, O_RDONLY, fmt, vargs)) < 0) {
        rv = fd;
    }
    else {
        memset(data, 0, max);
        if ((*len = read(fd, data, max)) <= 0) {
            AIM_LOG_ERROR("Failed to read input file '%s'", fname);
            rv = ONLP_STATUS_E_INTERNAL;
        }
        else {
            rv = ONLP_STATUS_OK;
        }
        close(fd);
    }
    aim_free(fname);
    return rv;
}
コード例 #22
0
ファイル: file.c プロジェクト: jnealtowns/ONLP
int
onlp_file_vread(uint8_t* data, int max, int* len, const char* fmt, va_list vargs)
{
    int fd;
    char fname[PATH_MAX];
    int rv;

    ONLPLIB_VSNPRINTF(fname, sizeof(fname)-1, fmt, vargs);

    if ((fd = open(fname, O_RDONLY)) == -1) {
        rv = ONLP_STATUS_E_MISSING;
    }
    else {
        if ((*len = read(fd, data, max)) <= 0) {
            AIM_LOG_ERROR("Failed to read input file '%s'", fname);
            rv = ONLP_STATUS_E_INTERNAL;
        }
        else {
            rv = ONLP_STATUS_OK;
        }
        close(fd);
    }
    return rv;
}
コード例 #23
0
static indigo_error_t
router_ip_parse_value(of_list_bsn_tlv_t *value, uint32_t *ip, of_mac_addr_t *mac)
{
    of_bsn_tlv_t tlv;

    if (of_list_bsn_tlv_first(value, &tlv) < 0) {
        AIM_LOG_ERROR("empty value list");
        return INDIGO_ERROR_PARAM;
    }

    if (tlv.header.object_id == OF_BSN_TLV_IPV4) {
        of_bsn_tlv_ipv4_value_get(&tlv.ipv4, ip);
    } else {
        AIM_LOG_ERROR("expected ipv4 key TLV, instead got %s", of_object_id_str[tlv.header.object_id]);
        return INDIGO_ERROR_PARAM;
    }

    if (*ip == INVALID_IP) {
        AIM_LOG_ERROR("IP invalid (%u)", *ip);
        return INDIGO_ERROR_PARAM;
    }

    if (of_list_bsn_tlv_next(value, &tlv) < 0) {
        AIM_LOG_ERROR("unexpected end of value list");
        return INDIGO_ERROR_PARAM;
    }

    if (tlv.header.object_id == OF_BSN_TLV_MAC) {
        of_bsn_tlv_mac_value_get(&tlv.mac, mac);
    } else {
        AIM_LOG_ERROR("expected mac value TLV, instead got %s", of_object_id_str[tlv.header.object_id]);
        return INDIGO_ERROR_PARAM;
    }

    if (of_list_bsn_tlv_next(value, &tlv) == 0) {
        AIM_LOG_ERROR("expected end of value list, instead got %s", of_object_id_str[tlv.header.object_id]);
        return INDIGO_ERROR_PARAM;
    }

    return INDIGO_ERROR_NONE;
}
コード例 #24
0
/*
 * lacpa_transmit
 *
 * Construct an LACPDU for the given port and transmit it out
 */
extern bool
lacpa_transmit (lacpa_port_t *port)
{
    ppe_packet_t ppep;
    uint8_t      data[LACP_PKT_BUF_SIZE];

	if (!port) return FALSE;

    if (!port->lacp_enabled) {
        AIM_LOG_ERROR("LACPDU-Tx-FAILED - Agent is Disabled on port: %d",
                      port->actor.port_no);
        return FALSE;
    }

    LACPA_MEMSET(data, DEFAULT_ZERO, LACP_PKT_BUF_SIZE);
    AIM_LOG_TRACE("Transmit Packet for port: %d, reason: %{lacpa_transmit}",
                  port->actor.port_no, port->ntt_reason);

    lacpa_dump_port(port);

	ppe_packet_init(&ppep, data, LACP_PKT_BUF_SIZE);

    /*
     * Set ethertype as slow-protocols and Set LACP subtype
     * Parse to recognize LACP packet.
     */
	data[12] = PPE_ETHERTYPE_SLOW_PROTOCOLS >> 8;
    data[13] = PPE_ETHERTYPE_SLOW_PROTOCOLS & 0xFF;
    data[14] = PPE_SLOW_PROTOCOL_LACP;

	if (ppe_parse(&ppep) < 0) {
        AIM_LOG_ERROR("Packet parsing failed after ethertype. packet=%{data}",
                      data, LACP_PKT_BUF_SIZE);
        return FALSE;
    }

    /*
     * Set the Src and Dest Mac.
     * Src Mac is provided to us and Dest Mac is the slow-protocols-mac-address
     */
    ppe_wide_field_set(&ppep, PPE_FIELD_ETHERNET_SRC_MAC, port->src_mac);
    ppe_wide_field_set(&ppep, PPE_FIELD_ETHERNET_DST_MAC,
                       slow_protocols_address);

    /*
     * Build the rest of the LCAP packet
     */
    if (!lacpa_build_pdu(&ppep, port)) {
        AIM_LOG_ERROR("Packet sending failed.");
        return FALSE;
    }

    /*
     *  Dump out the packet to verify all the fields are set properly
     */
    ppe_packet_dump(&ppep, &aim_pvs_stdout);

    lacpa_send(port, data, LACP_PKT_BUF_SIZE);

    return TRUE;

}
コード例 #25
0
/*
 * lacpa_update_convergence
 *
 * Decide Protocol Converged/Unconverged based on following:
 * 1. If Partner aggregation state = FALSE; Unconverged
 * 2. If Partner sync state = FALSE; Unconverged
 * 3. If Partner collecting state = FALSE; Unconverged
 * 4. If Partner distributing state = FALSE; Unconverged
 * Else, Converged
 */
static void
lacpa_update_convergence (lacpa_port_t *port, bool *ntt)
{
    lacpa_error_t prev_error = port->error;

	if (!port || !ntt) return;

    if (!LACPA_IS_STATE_AGGREGATION(port->partner.state)) {
        if (prev_error != LACPA_ERROR_PARTNER_AGGREGATION_OFF) {
        	AIM_LOG_ERROR("Setting unconverged, Mis-match in aggregation state");
        	port->error = LACPA_ERROR_PARTNER_AGGREGATION_OFF;
        	port->lacp_event = LACPA_EVENT_PROTOCOL_UNCONVERGED;
        	lacpa_machine(port, NULL);
        } else {
			AIM_LOG_ERROR("Protocol Already Unconverged..No action required");
        }
        return;
    }

    if (!LACPA_IS_STATE_SYNCHRONIZATION(port->actor.state)) {
        AIM_LOG_TRACE("Setting Actor sync state for Port: %d",
                      port->actor.port_no);
        LACPA_SET_STATE_SYNCHRONIZATION(port->actor.state);
        port->ntt_reason = LACPA_TRANSMIT_SYNCHRONIZATION_SET;
        *ntt = TRUE;
    }

	if (!LACPA_IS_STATE_SYNCHRONIZATION(port->partner.state)) {
        port->error = LACPA_ERROR_PARTNER_INSYNC;
        goto unconverged;
    }

    if (!LACPA_IS_STATE_COLLECTING(port->actor.state)) {
		AIM_LOG_TRACE("Setting Actor collection state for Port: %d",
                      port->actor.port_no);
        LACPA_SET_STATE_COLLECTING(port->actor.state);
        port->ntt_reason = LACPA_TRANSMIT_COLLECTING_SET;
        *ntt = TRUE;
    }

    if (!LACPA_IS_STATE_COLLECTING(port->partner.state)) {
        port->error = LACPA_ERROR_PARTNER_COLLECTION_OFF;
        goto unconverged;
    }

    if (!LACPA_IS_STATE_DISTRIBUTING(port->actor.state)) {
        AIM_LOG_TRACE("Setting Actor distribution state Port: %d",
                      port->actor.port_no);
		LACPA_SET_STATE_DISTRIBUTING(port->actor.state);
        port->ntt_reason = LACPA_TRANSMIT_DISTRIBUTING_SET;
        *ntt = TRUE;
    }

    if (!LACPA_IS_STATE_DISTRIBUTING(port->partner.state)) {
        port->error = LACPA_ERROR_PARTNER_DISTRIBUTION_OFF;
        goto unconverged;
    }

    AIM_LOG_TRACE("Setting Port: %d to Converged, ntt_reason: %{lacpa_transmit}",
                  port->actor.port_no, port->ntt_reason);
    port->error = LACPA_ERROR_NONE;
    port->is_converged = TRUE;
    return;

unconverged:
    AIM_LOG_TRACE("Setting Port: %d to Unconverged, reason: %{lacpa_error}, "
                  "ntt_reason: %{lacpa_transmit}", port->actor.port_no,
                  port->error, port->ntt_reason);
	port->is_converged = FALSE;
}
コード例 #26
0
ファイル: ft.c プロジェクト: amertahir/indigo
int
ft_flow_meta_match(of_meta_match_t *query, ft_entry_t *entry)
{
    uint64_t mask;
    int rv = 0; /* Default is no match */

    if (FT_FLOW_STATE_IS_DELETED(entry->state)) return (rv);

    if ((mask = query->cookie_mask)) {
        if ((query->cookie & mask) != (entry->cookie & mask)) {
            return rv;
        }
    }

    if (query->check_priority) {
        if (entry->priority != query->priority) {
            return rv;
        }
    }

    switch (query->mode) {
    case OF_MATCH_NON_STRICT:
        /* Check if the entry's match is more specific than the query's */
        if (!of_match_more_specific(&entry->match, &query->match)) {
            break;
        }
        if (query->out_port != OF_PORT_DEST_WILDCARD) {
            if (!entry_has_out_port(entry, query->out_port)) {
                break;
            }
        }
        rv = 1;
        break;
    case OF_MATCH_STRICT:
        if (!of_match_eq(&entry->match, &query->match)) {
            break;
        }
        if (query->out_port != OF_PORT_DEST_WILDCARD) {
            if (!entry_has_out_port(entry, query->out_port)) {
                break;
            }
        }
        rv = 1;
        break;
    case OF_MATCH_COOKIE_ONLY:
        /* Checked cookie above */
        rv = 1;
        break;
    case OF_MATCH_OVERLAP:
        if (!of_match_overlap(&entry->match, &query->match)) {
            break;
        }
        rv = 1;
        break;
    default:
        /* Internal error */
        AIM_LOG_ERROR("Internal error: unknown query mode %d", query->mode);
        break;
    }

    return rv;
}
コード例 #27
0
static indigo_error_t
ind_core_cfg_stage(cJSON *config)
{
    char *str;
    indigo_error_t err;

    err = ind_cfg_parse_loglevel(config, "logging.flowtable",
                                 OFSTATEMANAGER_CONFIG_LOG_BITS_DEFAULT,
                                 &staged_config.log_flags);
    if (err != INDIGO_ERROR_NONE) {
        return err;
    }

    /* Not supporting setting log options yet */

    err = 0;
    err |= get_fixed_len_string(staged_config.hw_desc, OF_DESC_STR_LEN,
                                config, "of_hw_desc");
    err |= get_fixed_len_string(staged_config.sw_desc, OF_DESC_STR_LEN,
                                config, "of_sw_desc");
    err |= get_fixed_len_string(staged_config.mfr_desc, OF_DESC_STR_LEN,
                                config, "of_mfr_desc");
    err |= get_fixed_len_string(staged_config.dp_desc, OF_DESC_STR_LEN,
                                config, "of_dp_desc");
    err |= get_fixed_len_string(staged_config.serial_num, OF_SERIAL_NUM_LEN,
                                config, "of_serial_num");
    if (err != 0) {
        /* Error message logged by get_fixed_len_string */
        return INDIGO_ERROR_PARAM;
    }

    err = ind_cfg_lookup_string(config, "of_datapath_id", &str);
    if (err == INDIGO_ERROR_NONE) {
        char *endptr;
        staged_config.dpid = strtoull(str, &endptr, 16);
        if (*endptr) { /* Did not parse string */
            AIM_LOG_ERROR("Config: Could not parse of_datapath_id; "
                          "must be hex digit string");
            return INDIGO_ERROR_PARAM;
        }
    } else {
        if (err == INDIGO_ERROR_PARAM) {
            AIM_LOG_ERROR("Config: Could not parse of_datapath_id");
        } else if (err == INDIGO_ERROR_NOT_FOUND) {
            AIM_LOG_ERROR("Config: Missing required key of_datapath_id");
        }
        return err;
    }

    err = ind_cfg_lookup_string(config, "disconnected_mode", &str);
    if (err == INDIGO_ERROR_NONE) {
        int disconnected_mode = parse_disconnected_mode(str);
        if (disconnected_mode == -1) {
            AIM_LOG_ERROR("Config: Could not parse disconnected_mode");
            return INDIGO_ERROR_PARAM;
        }
        staged_config.disconnected_mode = disconnected_mode;
    } else if (err == INDIGO_ERROR_NOT_FOUND) {
        staged_config.disconnected_mode = INDIGO_CORE_DISCONNECTED_MODE_STICKY;
    } else {
        if (err == INDIGO_ERROR_PARAM) {
            AIM_LOG_ERROR("Config: Could not parse disconnected_mode");
        }
        return err;
    }

    return INDIGO_ERROR_NONE;
}
コード例 #28
0
ファイル: sfpi.c プロジェクト: carlroth/OpenNetworkLinux
int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[7];
    uint32_t *ptr = bytes;
    FILE* fp;

    /* Read present status of port 0~23 */
    int addr, i = 0;

    for (addr = 61; addr <= 62; addr++) {
        int count;

        if (addr == 61) {
            fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r");
        }
        else {
            fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD3, "r");
        }

        if(fp == NULL) {
            AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr);
            return ONLP_STATUS_E_INTERNAL;
        }

        if (addr == 61) {
            count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3);
            fclose(fp);
            if(count != 4) {
                /* Likely a CPLD read timeout. */
                AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr);
                return ONLP_STATUS_E_INTERNAL;
            }
        }
        else {
            count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
            fclose(fp);
            if(count != 3) {
                /* Likely a CPLD read timeout. */
                AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr);
                return ONLP_STATUS_E_INTERNAL;
            }
        }

        ptr += count;
    }

    /* Convert to 64 bit integer in port order */
    uint64_t rx_los_all = 0 ;
    bytes[3] &= 0x1F;
    bytes[6] &= 0x7;
    for(i = 6; i >= 4; i--) {
        rx_los_all <<= 8;
        rx_los_all |= bytes[i];
    }

    rx_los_all <<= 5;
    rx_los_all |= bytes[3];

    for(i = 2; i >= 0; i--) {
        rx_los_all <<= 8;
        rx_los_all |= bytes[i];
    }


    /* Populate bitmap */
    for(i = 0; rx_los_all; i++) {
        AIM_BITMAP_MOD(dst, i, (rx_los_all & 1));
        rx_los_all >>= 1;
    }

    return ONLP_STATUS_OK;
}
コード例 #29
0
ファイル: pipeline_lua.c プロジェクト: kenchiang/ivs
static void
commit_lua_upload(indigo_cxn_id_t cxn_id, of_object_t *msg)
{
    uint16_t flags;
    of_bsn_lua_upload_flags_get(msg, &flags);

    /* TODO use stronger hash function */
    uint32_t new_checksum = murmur_hash(xbuf_data(&upload_chunks),
                                        xbuf_length(&upload_chunks),
                                        0);
    if (!(flags & OFP_BSN_LUA_UPLOAD_FORCE) && checksum == new_checksum) {
        AIM_LOG_VERBOSE("Skipping Lua commit, checksums match");
        goto cleanup;
    }

    checksum = 0;

    reset_lua();

    uint32_t offset = 0;
    while (offset < xbuf_length(&upload_chunks)) {
        struct upload_chunk *chunk = xbuf_data(&upload_chunks) + offset;
        offset += sizeof(*chunk) + chunk->size;

        AIM_LOG_VERBOSE("Loading Lua chunk %s, %u bytes", chunk->filename, chunk->size);

        char name[64];
        snprintf(name, sizeof(name), "=%s", chunk->filename);

        if (luaL_loadbuffer(lua, chunk->data, chunk->size, name) != 0) {
            AIM_LOG_ERROR("Failed to load code: %s", lua_tostring(lua, -1));
            indigo_cxn_send_error_reply(
                cxn_id, msg, OF_ERROR_TYPE_BAD_REQUEST, OF_REQUEST_FAILED_EPERM);
            goto cleanup;
        }

        /* Set the environment of the new chunk to the sandbox */
        lua_getglobal(lua, "sandbox");
        lua_setfenv(lua, -2);

        if (lua_pcall(lua, 0, 1, 0) != 0) {
            AIM_LOG_ERROR("Failed to execute code %s: %s", chunk->filename, lua_tostring(lua, -1));
            indigo_cxn_send_error_reply(
                cxn_id, msg, OF_ERROR_TYPE_BAD_REQUEST, OF_REQUEST_FAILED_EPERM);
            goto cleanup;
        }

        /* Save the return value in the "modules" table, used by require */
        char *module_name = aim_strdup(chunk->filename);
        char *dot = strrchr(module_name, '.');
        if (dot) *dot = 0; /* strip file extension */
        lua_getglobal(lua, "modules");
        lua_pushstring(lua, module_name);
        lua_pushvalue(lua, -3); /* return value from pcall */
        lua_rawset(lua, -3); /* modules[filename] = return_value */
        lua_pop(lua, 2); /* pop modules and return value */
        free(module_name);
    }

    checksum = new_checksum;

cleanup:
    cleanup_lua_upload();
    return;
}
コード例 #30
0
ファイル: psui.c プロジェクト: carlroth/OpenNetworkLinux
static int
psu_module_info_get(int id, onlp_psu_info_t* info)
{
    int ret = 0;
    char node_path[ONLP_NODE_MAX_PATH_LEN] = {0};
    int value = 0;

    info->caps |= ONLP_PSU_CAPS_DC12;

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "vout");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read vout from file(%s)\r\n", node_path);
    }
    else {
	info->mvout = value;
	info->caps |= ONLP_PSU_CAPS_VOUT;
    }

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "iout");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read iout from file(%s)\r\n", node_path);
    }
    else {
	info->miout = value;
	info->caps |= ONLP_PSU_CAPS_IOUT;
    }

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "pout");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read pout from file(%s)\r\n", node_path);
    }
    else {
	info->mpout = value;
	info->caps |= ONLP_PSU_CAPS_POUT;
    }

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "vin");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read vin from file(%s)\r\n", node_path);
    }
    else {
	info->mvin = value;
	info->caps |= ONLP_PSU_CAPS_VIN;
    }

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "iin");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read iin from file(%s)\r\n", node_path);
    }
    else {
	info->miin = value;
	info->caps |= ONLP_PSU_CAPS_IIN;
    }

    memset(node_path, 0, ONLP_NODE_MAX_PATH_LEN);
    sprintf(node_path, module_devfiles__[id], "pin");
    ret = onlp_file_read_int(&value, node_path);
    if (ret < 0) {
	AIM_LOG_ERROR("Unable to read pin from file(%s)\r\n", node_path);
    }
    else {
	info->mpin = value;
	info->caps |= ONLP_PSU_CAPS_PIN;
    }

    psu_module_name_get(id, info);
    return ONLP_STATUS_OK;
}