Esempio n. 1
0
void cheap_tcam_insert(cheap_tcam_t *tcam,
		       uint8_t *mask,
		       uint8_t *key,
		       cheap_tcam_node *node,
		       void *data) {
  tommy_list *hashmaps = &tcam->hashmaps;
  tcam_hashmap_t *tcam_hashmap;
  uint32_t hash = hashlittle(key, tcam->key_size, 0);
  tommy_node* elem = tommy_list_head(hashmaps);
  
  while(elem) {
    tcam_hashmap = (tcam_hashmap_t *) elem->data;
    if(!memcmp(mask, tcam_hashmap->mask, tcam->key_size)) {
      tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash);
      return;
    }
    elem = elem->next;
  }

  tcam_hashmap = malloc(sizeof(tcam_hashmap_t));
  tommy_hashlin_init(&tcam_hashmap->hashmap);
  tcam_hashmap->mask = malloc(tcam->key_size);
  memcpy(tcam_hashmap->mask, mask, tcam->key_size);
  tommy_list_insert_head(hashmaps, &tcam_hashmap->node, tcam_hashmap);
  tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash);
}
Esempio n. 2
0
switch_status_t switch_api_l3_interface_address_add(
    switch_device_t device,
    switch_handle_t interface_handle,
    switch_handle_t vrf_handle,
    switch_ip_addr_t *ip_addr) {
  switch_interface_info_t *info = NULL;
  switch_ip_addr_info_t *ip_info = NULL;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  UNUSED(device);
  info = switch_api_interface_get(interface_handle);
  if (!info) {
    return SWITCH_STATUS_INVALID_INTERFACE;
  }

  ip_info = switch_malloc(sizeof(switch_ip_addr_info_t), 1);
  if (!ip_info) {
    return SWITCH_STATUS_NO_MEMORY;
  }

  ip_info->vrf_handle = vrf_handle;
  ip_info->default_ip = TRUE;
  ip_info->ip = *ip_addr;

  // append to list and increment member count
  tommy_list_insert_head(&(info->ip_addr), &(ip_info->node), ip_info);
  info->ip_addr_count++;

  return status;
}
Esempio n. 3
0
//:: for name, vs_info in value_sets.items():
//::   byte_width = vs_info["byte_width"]
void *value_set_${name}_add(uint8_t *value, uint8_t *mask) {
  value_set_${name}_entry_t *entry = malloc(sizeof(value_set_${name}_entry_t));
  memcpy(entry->value, value, sizeof(entry->value));
  memcpy(entry->mask, mask, sizeof(entry->mask));
  tommy_list_insert_head(&value_set_${name}, &entry->node, entry);
  return &entry->node;
}
Esempio n. 4
0
/*
 * @function: switch_api_router_mac_add
 * Add Router mac to rmac group
 * @param device - Device to be programmed
 * @param rmac_handle - ID of the RMAC group
 * @param mac - Router mac address to be added to the group
 * @return: Returns success if mac is added successfully
 */
switch_status_t
switch_api_router_mac_add(switch_device_t device, switch_handle_t rmac_handle, switch_mac_addr_t *mac)
{
    switch_rmac_info_t                *rmac_info = NULL;
    switch_rmac_entry_t               *rmac_entry = NULL;
    tommy_node                        *node = NULL;
    switch_status_t                    status = SWITCH_STATUS_SUCCESS;

    if (!SWITCH_RMAC_HANDLE_VALID(rmac_handle)) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    rmac_info = switch_api_rmac_info_get_internal(rmac_handle);
    if (!rmac_info) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }
    node = tommy_list_head(&(rmac_info->rmac_list));
    while (node) {
        rmac_entry = node->data;
        if (memcmp(&(rmac_entry->mac), mac, sizeof(switch_mac_addr_t)) == 0) {
            return SWITCH_STATUS_SUCCESS;
        }
        node = node->next;
    }
    rmac_entry = switch_malloc(sizeof(switch_rmac_entry_t), 1);
    if (!rmac_entry) {
        return SWITCH_STATUS_NO_MEMORY;
    }
    memcpy(&rmac_entry->mac, mac, sizeof(switch_mac_addr_t));
    tommy_list_insert_head(&(rmac_info->rmac_list), &(rmac_entry->node), rmac_entry);
    status = switch_smac_rewrite_add_entry(mac);
    if (status != SWITCH_STATUS_SUCCESS) {
        printf("MAC rewrite table add failed with error code %d\n", status);
        return status;
    }
#ifdef SWITCH_PD
    
    status = switch_pd_inner_rmac_table_add_entry(device,
                                              handle_to_id(rmac_handle), mac,
                                              &rmac_entry->inner_rmac_entry);
    if(status != SWITCH_STATUS_SUCCESS) {
        printf("Inner RMAC table add failed with error code %d\n", status);
        return status;
    }

    status = switch_pd_outer_rmac_table_add_entry(device,
                                              handle_to_id(rmac_handle), mac,
                                              &rmac_entry->outer_rmac_entry);
    if(status != SWITCH_STATUS_SUCCESS) {
        printf("Outer RMAC table add failed with error code %d\n", status);
    }
#endif
    return status; 
}
Esempio n. 5
0
switch_status_t
switch_api_stp_group_vlans_add(switch_device_t device,
                              switch_handle_t stg_handle,
                              uint16_t vlan_count,
                              switch_handle_t *vlan_handle)
{
    switch_stp_info_t                 *stp_info = NULL;
    switch_bd_info_t                  *bd_info = NULL;
    switch_stp_vlan_entry_t           *vlan_entry = NULL;
    switch_handle_t                    bd_handle;
    int                                count = 0;

    if (!SWITCH_STP_HANDLE_VALID(stg_handle)) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    stp_info = switch_api_stp_get_internal(stg_handle);
    if (!stp_info) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    for (count = 0; count < vlan_count; count++) {
        bd_handle = vlan_handle[count];
        bd_info = switch_bd_get(bd_handle);
        if (!bd_info) {
            return SWITCH_STATUS_INVALID_VLAN_ID;
        }

        vlan_entry = switch_malloc(sizeof(switch_stp_vlan_entry_t), 1);
        if (!vlan_entry) {
            return SWITCH_STATUS_NO_MEMORY;
        }
        memset(vlan_entry, 0 , sizeof(switch_stp_vlan_entry_t));

        vlan_entry->bd_handle = bd_handle;
        bd_info->stp_handle = stg_handle;

        switch_pd_bd_table_update_entry(device, handle_to_id(bd_handle),
                                        bd_info);

        tommy_list_insert_head(&(stp_info->vlan_list),
                        &(vlan_entry->node), vlan_entry);
    }
    return SWITCH_STATUS_SUCCESS;
}
Esempio n. 6
0
switch_status_t
switch_api_stp_port_state_set(switch_device_t device, switch_handle_t stg_handle,
                              switch_handle_t handle, switch_stp_state_t state)
{
    switch_stp_info_t                 *stp_info = NULL;
    switch_interface_info_t           *intf_info = NULL;
    switch_stp_port_entry_t           *port_entry = NULL;
    tommy_node                        *node = NULL;
    switch_status_t                    status = SWITCH_STATUS_SUCCESS;
    switch_handle_t                    intf_handle; 
    switch_handle_type_t               handle_type = 0;
    bool                               new_entry = FALSE;

    if (!SWITCH_STP_HANDLE_VALID(stg_handle)) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    if ((!SWITCH_PORT_HANDLE_VALID(handle)) &&
        (!SWITCH_LAG_HANDLE_VALID(handle)) &&
        (!SWITCH_INTERFACE_HANDLE_VALID(handle))) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    stp_info = switch_api_stp_get_internal(stg_handle);
    if (!stp_info) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    handle_type = switch_handle_get_type(handle);
    intf_handle = handle;
    if (handle_type == SWITCH_HANDLE_TYPE_PORT ||
        handle_type == SWITCH_HANDLE_TYPE_LAG) {
        status = switch_interface_handle_get(
                             handle,
                             0x0,
                             &intf_handle);
        if (status != SWITCH_STATUS_SUCCESS) {
            SWITCH_API_ERROR("stp port state set failed");
            return status;
        }
    }

    intf_info = switch_api_interface_get(intf_handle);
    if (!intf_info) {
        return SWITCH_STATUS_INVALID_INTERFACE;
    }

    if (SWITCH_INTF_IS_PORT_L3(intf_info)) {
        return SWITCH_STATUS_INVALID_INTERFACE;
    }

    node = tommy_list_head(&stp_info->port_list);
    while (node) {
        port_entry = node->data;
        if (port_entry->intf_handle == intf_handle) {
            port_entry->intf_state = state;
            break;
        }
        node = node->next;
    }

    if (state == SWITCH_PORT_STP_STATE_NONE) {
        if (!node) {
            return SWITCH_STATUS_ITEM_NOT_FOUND;
        }
        status = switch_stp_update_flood_list(device, stg_handle, intf_handle, state);
        status = switch_pd_spanning_tree_table_delete_entry(device, port_entry->hw_entry);
        tommy_list_remove_existing(&(stp_info->port_list), &(port_entry->node));
        switch_free(port_entry);
    } else {
        if (!node) {
            new_entry = TRUE;
            port_entry = switch_malloc(sizeof(switch_stp_port_entry_t), 1);
            if (!port_entry) {
                return SWITCH_STATUS_NO_MEMORY;
            }
            memset(port_entry, 0, sizeof(switch_stp_port_entry_t));
            port_entry->intf_handle = intf_handle;
            port_entry->intf_state = state;
            tommy_list_insert_head(&(stp_info->port_list),
                                   &(port_entry->node), port_entry);
        }

        status = switch_stp_update_flood_list(device, stg_handle, intf_handle, state);

        if (new_entry) {
            status = switch_pd_spanning_tree_table_add_entry(device,
                                        handle_to_id(stg_handle),
                                        intf_info->ifindex,
                                        port_entry->intf_state,
                                        &port_entry->hw_entry);
        } else {
            status = switch_pd_spanning_tree_table_update_entry(device,
                                        handle_to_id(stg_handle),
                                        intf_info->ifindex,
                                        port_entry->intf_state,
                                        port_entry->hw_entry);
        }
    }
    return status;
}
Esempio n. 7
0
switch_status_t switch_api_packet_net_filter_rx_create(
    switch_device_t device,
    switch_packet_rx_key_t *rx_key,
    switch_packet_rx_action_t *rx_action) {
  switch_hostif_info_t *hostif_info = NULL;
  switch_lag_info_t *lag_info = NULL;
  switch_port_info_t *port_info = NULL;
  switch_packet_rx_entry_t rx_entry;
  switch_packet_rx_info_t *rx_info = NULL;
  switch_handle_type_t handle_type = 0;
  switch_interface_info_t *intf_info = NULL;
  switch_handle_t bd_handle = 0;
  switch_bd_info_t *bd_info = NULL;
  switch_ifindex_t ifindex = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  if (!rx_key || !rx_action) {
    SWITCH_API_ERROR("filter rx create failed. invalid params");
    return SWITCH_STATUS_INVALID_PARAMETER;
  }

  memset(&rx_entry, 0x0, sizeof(rx_entry));

  if (rx_key->port_lag_valid) {
    handle_type = switch_handle_get_type(rx_key->port_lag_handle);
    if (handle_type == SWITCH_HANDLE_TYPE_LAG) {
      lag_info = switch_api_lag_get_internal(rx_key->port_lag_handle);
      if (!lag_info) {
        SWITCH_API_ERROR("invalid lag handle");
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      ifindex = lag_info->ifindex;
    } else {
      port_info = switch_api_port_get_internal(rx_key->port_lag_handle);
      if (!port_info) {
        SWITCH_API_ERROR("invalid port handle");
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      ifindex = port_info->ifindex;
    }
    rx_entry.ifindex_valid = TRUE;
  }

  if (rx_key->handle_valid) {
    bd_handle = rx_key->handle;
    handle_type = switch_handle_get_type(rx_key->handle);
    if (handle_type == SWITCH_HANDLE_TYPE_INTERFACE) {
      intf_info = switch_api_interface_get(rx_key->handle);
      if (!intf_info) {
        SWITCH_API_ERROR("intf_handle %lx is invalid", rx_key->handle);
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      if (!SWITCH_INTF_IS_PORT_L3(intf_info)) {
        SWITCH_API_ERROR("intf_handle %lx is not l3", rx_key->handle);
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      bd_handle = intf_info->bd_handle;
    }

    bd_info = switch_bd_get(bd_handle);
    if (!bd_info) {
      SWITCH_API_ERROR("bd derivation failed %lx", rx_key->handle);
      return SWITCH_STATUS_INVALID_HANDLE;
    }
    rx_entry.bd_valid = TRUE;
  }

  if (rx_action->hostif_handle) {
    hostif_info = switch_hostif_get(rx_action->hostif_handle);
    if (!hostif_info) {
      SWITCH_API_ERROR("invalid hostif handle");
      return SWITCH_STATUS_INVALID_HANDLE;
    }
  }

  rx_entry.bd = handle_to_id(bd_handle);
  rx_entry.ifindex = ifindex;
  rx_entry.port_valid = rx_key->port_valid;
  rx_entry.port = handle_to_id(rx_key->port_handle);
  rx_entry.reason_code_valid = rx_key->reason_code_valid;
  rx_entry.reason_code = rx_key->reason_code;
  rx_entry.reason_code_mask = rx_key->reason_code_mask;
  rx_entry.priority = rx_key->priority;

  rx_info = switch_malloc(sizeof(switch_packet_rx_info_t), 0x1);
  if (!rx_info) {
    SWITCH_API_ERROR("port %lx port_lag %lx handle %lx malloc failed",
                     rx_key->port_handle,
                     rx_key->port_lag_handle,
                     rx_key->handle);
    return SWITCH_STATUS_NO_MEMORY;
  }

  memset(rx_info, 0x0, sizeof(switch_packet_rx_info_t));
  memcpy(&rx_info->rx_entry, &rx_entry, sizeof(rx_entry));
  rx_info->vlan_id = rx_action->vlan_id;
  rx_info->vlan_action = rx_action->vlan_action;
  if (hostif_info) {
    rx_info->intf_fd = hostif_info->intf_fd;
  }

  SWITCH_API_INFO(
      "net_filter_rx_create: port 0x%lx, port_lag_hdl = 0x%lx, "
      "if_bd_hdl 0x%lx, rcode 0x%x, rcode_mask 0x%x "
      "vlan_id %d, fd %d, action %d\n",
      rx_key->port_valid ? rx_key->port_handle : 0,
      rx_key->port_lag_valid ? rx_key->port_lag_handle : 0,
      rx_key->handle_valid ? rx_key->handle : 0,
      rx_key->reason_code_valid ? rx_key->reason_code : 0,
      rx_key->reason_code_mask,
      rx_info->vlan_id,
      rx_info->vlan_action,
      rx_info->intf_fd);
  /*
   * Adding an element to the list results in sorting the list.
   * tommy does not have a way to compare and insert the elements
   */
  tommy_list_insert_head(&packet_rx_filter_list, &(rx_info->node), rx_info);
  tommy_list_sort(&packet_rx_filter_list,
                  switch_packet_rx_filter_priority_compare);
  return status;
}
Esempio n. 8
0
switch_status_t switch_api_packet_net_filter_tx_create(
    switch_device_t device,
    switch_packet_tx_key_t *tx_key,
    switch_packet_tx_action_t *tx_action) {
  switch_packet_tx_entry_t tx_entry;
  switch_packet_tx_info_t *tx_info = NULL;
  switch_hostif_info_t *hostif_info = NULL;
  switch_handle_t bd_handle = 0;
  switch_interface_info_t *intf_info = NULL;
  switch_handle_type_t handle_type = 0;
  switch_bd_info_t *bd_info = NULL;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  if (!tx_key || !tx_action) {
    SWITCH_API_ERROR("filter tx create failed. invalid params");
    return SWITCH_STATUS_INVALID_PARAMETER;
  }

  if (tx_key->handle_valid) {
    hostif_info = switch_hostif_get(tx_key->hostif_handle);
    if (!hostif_info) {
      SWITCH_API_ERROR("invalid hostif handle");
      return SWITCH_STATUS_INVALID_HANDLE;
    }
  }

  memset(&tx_entry, 0x0, sizeof(tx_entry));
  if (tx_key->handle_valid) {
    tx_entry.intf_fd = hostif_info->intf_fd;
  }
  tx_entry.fd_valid = tx_key->handle_valid;
  tx_entry.vlan_id = tx_key->vlan_id;
  tx_entry.vlan_valid = tx_key->vlan_valid;
  tx_entry.priority = tx_key->priority;

  tx_info = switch_malloc(sizeof(switch_packet_tx_info_t), 0x1);
  if (!tx_info) {
    SWITCH_API_ERROR("hif %lx vlan %x malloc failure",
                     tx_key->hostif_handle,
                     tx_key->vlan_id);
    return SWITCH_STATUS_NO_MEMORY;
  }

  if (tx_action->bypass_flags != SWITCH_BYPASS_ALL) {
    bd_handle = tx_action->handle;

    handle_type = switch_handle_get_type(tx_action->handle);
    if (handle_type == SWITCH_HANDLE_TYPE_INTERFACE) {
      intf_info = switch_api_interface_get(tx_action->handle);
      if (!intf_info) {
        SWITCH_API_ERROR("intf_handle %lx is invalid", tx_action->handle);
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      if (!SWITCH_INTF_IS_PORT_L3(intf_info)) {
        SWITCH_API_ERROR("intf_handle %lx is not l3", tx_action->handle);
        return SWITCH_STATUS_INVALID_HANDLE;
      }
      bd_handle = intf_info->bd_handle;
    }

    bd_info = switch_bd_get(bd_handle);
    if (!bd_info) {
      SWITCH_API_ERROR(
          "hif %lx vlan %x invalid bd", tx_key->hostif_handle, tx_key->vlan_id);
      return SWITCH_STATUS_INVALID_HANDLE;
    }
  }

  memcpy(&tx_info->tx_entry, &tx_entry, sizeof(tx_entry));
  tx_info->bd = handle_to_id(bd_handle);
  tx_info->bypass_flags = tx_action->bypass_flags;
  tx_info->port = handle_to_id(tx_action->port_handle);

  SWITCH_API_INFO(
      "net_filter_tx_create: hostif 0x%lx, vlan_id = %d, fd 0x%x, bypass "
      "0x%x\n",
      tx_key->hostif_handle,
      tx_key->vlan_valid ? tx_key->vlan_id : 0xFFF,
      tx_entry.intf_fd,
      tx_info->bypass_flags);

  tommy_list_insert_head(&packet_tx_filter_list, &(tx_info->node), tx_info);
  tommy_list_sort(&packet_tx_filter_list,
                  switch_packet_tx_filter_priority_compare);
  return status;
}
Esempio n. 9
0
switch_status_t
switch_api_ecmp_member_add(switch_device_t device, switch_handle_t ecmp_handle,
                           uint16_t nhop_count, switch_handle_t *nhop_handle_list)
{
    switch_nhop_info_t                *e_nhop_info = NULL;
    switch_nhop_info_t                *nhop_info = NULL;
    switch_ecmp_info_t                *ecmp_info = NULL;
    switch_ecmp_member_t              *ecmp_member = NULL;
    switch_interface_info_t           *intf_info = NULL;
    switch_spath_info_t               *spath_info = NULL;
    switch_handle_t                    nhop_handle;
    switch_status_t                    status = SWITCH_STATUS_SUCCESS;
    int                                count = 0;

    if (!SWITCH_NHOP_HANDLE_VALID(ecmp_handle)) {
        return SWITCH_STATUS_INVALID_HANDLE;
    }

    e_nhop_info = switch_nhop_get(ecmp_handle);
    if (!e_nhop_info) {
        return SWITCH_STATUS_INVALID_NHOP;
    }
    ecmp_info = &(SWITCH_NHOP_ECMP_INFO(e_nhop_info));

    for (count = 0; count < nhop_count; count++) {
        nhop_handle = nhop_handle_list[count];
        if (!SWITCH_NHOP_HANDLE_VALID(nhop_handle)) {
            return SWITCH_STATUS_INVALID_HANDLE;
        }
        nhop_info = switch_nhop_get(nhop_handle);
        if (!nhop_info) {
            return SWITCH_STATUS_INVALID_NHOP;
        }
        spath_info = &(SWITCH_NHOP_SPATH_INFO(nhop_info));

        ecmp_member = switch_malloc(sizeof(switch_ecmp_member_t), 1);
        if (!ecmp_member) {
            return SWITCH_STATUS_NO_MEMORY;
        }
        ecmp_member->nhop_handle = nhop_handle;
        intf_info = switch_api_interface_get(spath_info->nhop_key.intf_handle);
        if (!intf_info) {
            return SWITCH_STATUS_INVALID_INTERFACE;
        }

        nhop_info->ref_count++;
#ifdef SWITCH_PD
        status = switch_pd_ecmp_member_add(device, ecmp_info->pd_group_hdl, 
                    handle_to_id(ecmp_member->nhop_handle), intf_info,
                    &(ecmp_member->mbr_hdl));
        if (status != SWITCH_STATUS_SUCCESS) {
            return status;
        }
        if (ecmp_info->count == 0) {
            status = switch_pd_ecmp_group_table_add_entry_with_selector(device, 
                    handle_to_id(ecmp_handle),
                    ecmp_info->pd_group_hdl, 
                    &(ecmp_info->hw_entry)); 
            if (status != SWITCH_STATUS_SUCCESS) {
                return status;
            }
        }
        if (SWITCH_INTF_IS_PORT_L3(intf_info) && intf_info->bd_handle) {
            status = switch_pd_urpf_bd_table_add_entry(device, handle_to_id(ecmp_handle),
                                     handle_to_id(intf_info->bd_handle),
                                     &(ecmp_member->urpf_hw_entry));
            if (status != SWITCH_STATUS_SUCCESS) {
                return status;
            }
        }
#endif
        ecmp_info->count++;
        tommy_list_insert_head(&ecmp_info->members, &(ecmp_member->node), ecmp_member);
    }
    return status;
}
Esempio n. 10
0
switch_handle_t
switch_api_ecmp_create_with_members(switch_device_t device,
                                    uint32_t member_count,
                                    switch_handle_t *nhop_handle)
{
    switch_nhop_info_t                *nhop_info = NULL;
    switch_spath_info_t               *spath_info = NULL;
    switch_interface_info_t           *intf_info = NULL;
    switch_ecmp_info_t                *ecmp_info = NULL;
    switch_ecmp_member_t              *ecmp_member = NULL;
    switch_handle_t                    ecmp_handle;
    switch_status_t                    status = SWITCH_STATUS_SUCCESS;
    uint32_t                           index = 0;

    ecmp_handle = switch_api_ecmp_create(device);
    nhop_info = switch_nhop_get(ecmp_handle);
    if (!nhop_info) {
        return SWITCH_API_INVALID_HANDLE;
    }

    ecmp_info = &(SWITCH_NHOP_ECMP_INFO(nhop_info));
    tommy_list_init(&ecmp_info->members);

#ifdef SWITCH_PD
    status = switch_pd_ecmp_group_create(device, &(ecmp_info->pd_group_hdl));
    if (status != SWITCH_STATUS_SUCCESS) {
        return SWITCH_API_INVALID_HANDLE;
    }
#endif

    for (index = 0; index < member_count; index++) {
        if (!SWITCH_NHOP_HANDLE_VALID(nhop_handle[index])) {
            return SWITCH_STATUS_INVALID_HANDLE;
        }

        ecmp_member = switch_malloc(sizeof(switch_ecmp_member_t), 1);
        if (!ecmp_member) {
            // TODO: Cleanup memory
            return SWITCH_API_INVALID_HANDLE;
        }
        ecmp_member->nhop_handle = nhop_handle[index];
        ecmp_member->mbr_hdl = 0;

        nhop_info = switch_nhop_get(ecmp_member->nhop_handle);
        if (!nhop_info) {
            return SWITCH_API_INVALID_HANDLE;
        }

        spath_info = &(SWITCH_NHOP_SPATH_INFO(nhop_info));
        intf_info = switch_api_interface_get(spath_info->nhop_key.intf_handle);
        if (!intf_info) {
            return SWITCH_API_INVALID_HANDLE;
        }
        nhop_info->ref_count++;

#ifdef SWITCH_PD
        status = switch_pd_ecmp_member_add(device, ecmp_info->pd_group_hdl, 
                    handle_to_id(ecmp_member->nhop_handle), intf_info,
                    &(ecmp_member->mbr_hdl));
        if (status != SWITCH_STATUS_SUCCESS) {
            return SWITCH_API_INVALID_HANDLE;
        }

        if (SWITCH_INTF_IS_PORT_L3(intf_info) && intf_info->bd_handle) {
            status = switch_pd_urpf_bd_table_add_entry(device, handle_to_id(ecmp_handle),
                                                  handle_to_id(intf_info->bd_handle),
                                                  &(ecmp_member->urpf_hw_entry));
            if (status != SWITCH_STATUS_SUCCESS) {
                return SWITCH_API_INVALID_HANDLE;
            }
        }
#endif
        tommy_list_insert_head(&ecmp_info->members, &(ecmp_member->node), ecmp_member);
    }

#ifdef SWITCH_PD
    status = switch_pd_ecmp_group_table_add_entry_with_selector(device, handle_to_id(ecmp_handle), 
                    ecmp_info->pd_group_hdl, &(ecmp_info->hw_entry));
    if (status != SWITCH_STATUS_SUCCESS) {
        return SWITCH_API_INVALID_HANDLE;
    }
#endif
    ecmp_info->count = member_count;
    if (status != SWITCH_STATUS_SUCCESS) {
        return SWITCH_API_INVALID_HANDLE;
    }
    return ecmp_handle;
}
Esempio n. 11
0
void test_hashlin(void)
{
	tommy_list list;
	tommy_hashlin hashlin;
	struct object_hash* HASH;
	unsigned i, n;
	tommy_node* p;
	unsigned limit;
	unsigned count;

	HASH = malloc(MAX * sizeof(struct object_hash));

	for(i=0;i<MAX;++i) {
		HASH[i].value = i;
	}

	START("hashlin stack");
	limit = 10 * sqrt(MAX);
	for(n=0;n<limit;++n) {
		tommy_list_init(&list);
		tommy_hashlin_init(&hashlin);

		/* insert */
		for(i=0;i<n;++i) {
			tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]);
			tommy_hashlin_insert(&hashlin, &HASH[i].hashnode, &HASH[i], HASH[i].value);
		}

		count = 0;
		tommy_hashlin_foreach_arg(&hashlin, count_arg, &count);
		if (count != n)
			abort();

		/* remove */
		p = tommy_list_head(&list);
		while (p) {
			struct object_hash* obj = p->data;
			p = p->next;
			tommy_hashlin_remove_existing(&hashlin, &obj->hashnode);
		}

		tommy_hashlin_done(&hashlin);
	}
	STOP();

	START("hashlin queue");
	limit = sqrt(MAX) / 8;
	for(n=0;n<limit;++n) {
		tommy_list_init(&list);
		tommy_hashlin_init(&hashlin);

		/* insert first run */
		for(i=0;i<n;++i) {
			tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]);
			tommy_hashlin_insert(&hashlin, &HASH[i].hashnode, &HASH[i], HASH[i].value);
		}

		count = 0;
		tommy_hashlin_foreach_arg(&hashlin, count_arg, &count);
		if (count != n)
			abort();

		/* insert all the others */
		for(;i<MAX;++i) {
			struct object_hash* obj;

			/* insert one */
			tommy_list_insert_head(&list, &HASH[i].node, &HASH[i]);
			tommy_hashlin_insert(&hashlin, &HASH[i].hashnode, &HASH[i], HASH[i].value);

			/* remove one */
			p = tommy_list_head(&list);
			obj = p->data;
			tommy_list_remove_existing(&list, p);
			tommy_hashlin_remove_existing(&hashlin, &obj->hashnode);
		}

		/* remove remaining */
		p = tommy_list_head(&list);
		while (p) {
			struct object_hash* obj = p->data;
			p = p->next;
			tommy_hashlin_remove_existing(&hashlin, &obj->hashnode);
		}

		tommy_hashlin_done(&hashlin);
	}
	STOP();
}