Example #1
0
switch_status_t switch_api_neighbor_print_entry(
    switch_handle_t neighbor_handle) {
  switch_neighbor_info_t *neighbor_info = NULL;
  switch_api_neighbor_t *neighbor = NULL;
  switch_mac_addr_t *mac = NULL;

  neighbor_info = switch_neighbor_info_get(neighbor_handle);
  if (!neighbor_info) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
  neighbor = &neighbor_info->neighbor;
  printf("\n\nneighbor_handle: %x:", (unsigned int)neighbor_handle);
  printf("\n\ttype: %x", neighbor->neigh_type);
  printf("\n\tvrf_handle :%x nhop_handle %x interface_handle %x",
         (unsigned int)neighbor->vrf_handle,
         (unsigned int)neighbor->nhop_handle,
         (unsigned int)neighbor->interface);
  mac = &neighbor->mac_addr;
  printf("\n\trewrite mac %02x:%02x:%02x:%02x:%02x:%02x",
         mac->mac_addr[0],
         mac->mac_addr[1],
         mac->mac_addr[2],
         mac->mac_addr[3],
         mac->mac_addr[4],
         mac->mac_addr[5]);
  printf("\n");
  return SWITCH_STATUS_SUCCESS;
}
Example #2
0
switch_handle_t switch_api_neighbor_entry_add(switch_device_t device,
                                              switch_api_neighbor_t *neighbor) {
  switch_neighbor_info_t *neighbor_info = NULL;
  switch_interface_info_t *intf_info = NULL;
  switch_handle_t handle = SWITCH_API_INVALID_HANDLE;
  switch_status_t status = SWITCH_STATUS_SUCCESS;
  switch_nhop_info_t *nhop_info = NULL;
  switch_spath_info_t *spath_info = NULL;
  switch_handle_t nhop_handle = 0;

  intf_info = switch_api_interface_get(neighbor->interface);
  if (!intf_info) {
    SWITCH_API_ERROR(
        "%s:%d: invalid interface for rewrite!", __FUNCTION__, __LINE__);
    return SWITCH_STATUS_INVALID_INTERFACE;
  }

  handle = switch_neighbor_info_create();
  neighbor_info = switch_neighbor_info_get(handle);
  memcpy(&neighbor_info->neighbor, neighbor, sizeof(switch_api_neighbor_t));

#ifdef SWITCH_PD
  nhop_handle = neighbor->nhop_handle;
  if (neighbor->nhop_handle == SWITCH_API_INVALID_HANDLE) {
    // check for neighbor type
    if (neighbor->neigh_type == SWITCH_API_NEIGHBOR_NONE &&
        neighbor->rw_type == SWITCH_API_NEIGHBOR_RW_TYPE_L3) {
      switch_nhop_key_t nhop_key;
      // allocate nhop and set neighbor handle
      memset(&nhop_key, 0, sizeof(nhop_key));
      nhop_key.ip_addr = neighbor->ip_addr;
      nhop_key.intf_handle = neighbor->interface;
      nhop_key.ip_addr_valid = 1;
      nhop_handle = switch_api_nhop_create(device, &nhop_key);
    }
  }
  if (nhop_handle != SWITCH_API_INVALID_HANDLE && nhop_handle) {
    nhop_info = switch_nhop_get(nhop_handle);
    if (!nhop_info) {
      return SWITCH_API_INVALID_HANDLE;
    }
    spath_info = &(SWITCH_NHOP_SPATH_INFO(nhop_info));
    spath_info->neighbor_handle = handle;
    neighbor_info->neighbor.nhop_handle = nhop_handle;
    status = switch_api_nhop_update(device, nhop_handle);
    status =
        switch_api_neighbor_entry_add_rewrite(device, handle, neighbor_info);
  } else {
    status =
        switch_api_neighbor_entry_add_tunnel_rewrite(device, neighbor_info);
  }
#endif
  if (status != SWITCH_STATUS_SUCCESS) {
    SWITCH_API_ERROR(
        "%s:%d: failed to create neighbor entry!", __FUNCTION__, __LINE__);
  }
  neighbor->nhop_handle = nhop_handle;
  return handle;
}
Example #3
0
switch_status_t switch_api_neighbor_entry_remove(
    switch_device_t device, switch_handle_t neighbor_handle) {
  switch_neighbor_info_t *neighbor_info = NULL;
  switch_api_neighbor_t *neighbor = NULL;
  switch_nhop_info_t *nhop_info = NULL;
  switch_interface_info_t *intf_info = NULL;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  if (!SWITCH_NEIGHBOR_HANDLE_VALID(neighbor_handle)) {
    return SWITCH_STATUS_INVALID_HANDLE;
  }

  neighbor_info = switch_neighbor_info_get(neighbor_handle);
  if (!neighbor_info) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
#ifdef SWITCH_PD
  if (neighbor_info->neighbor.nhop_handle) {
    status = switch_pd_rewrite_table_delete_entry(device,
                                                  neighbor_info->rewrite_entry);
    if (status != SWITCH_STATUS_SUCCESS) {
      return status;
    }
    neighbor = &neighbor_info->neighbor;
    intf_info = switch_api_interface_get(neighbor->interface);
    if (!intf_info) {
      SWITCH_API_ERROR("%s:%d invalid interface!", __FUNCTION__, __LINE__);
      return SWITCH_STATUS_INVALID_INTERFACE;
    }
    switch_neighbor_dmac_delete_hash(
        device, intf_info->bd_handle, &neighbor->mac_addr);
  } else {
    status = switch_dmac_rewrite_delete_hash(device,
                                             &neighbor_info->neighbor.mac_addr);
    if (status != SWITCH_STATUS_SUCCESS) {
      return status;
    }
    status = switch_pd_tunnel_rewrite_table_delete_entry(
        device, neighbor_info->rewrite_entry);
    if (status != SWITCH_STATUS_SUCCESS) {
      return status;
    }
  }
#endif
  switch_neighbor_info_delete(neighbor_handle);
  nhop_info = switch_nhop_get(neighbor_info->neighbor.nhop_handle);
  if (nhop_info) {
    nhop_info->u.spath.neighbor_handle = 0;
    status =
        switch_api_nhop_update(device, neighbor_info->neighbor.nhop_handle);
    if (nhop_info->valid == 0) {
      switch_api_nhop_delete(device, neighbor_info->neighbor.nhop_handle);
    }
  }
  return status;
}
Example #4
0
switch_status_t
switch_nhop_ifindex_get(switch_handle_t nhop_handle,
                        switch_ifindex_t *ifindex,
                        bool *flood,
                        uint32_t *mc_index)
{
    switch_nhop_info_t                *nhop_info = NULL;
    switch_interface_info_t           *intf_info = NULL;
    switch_neighbor_info_t            *neighbor_info = NULL;
    switch_api_neighbor_t             *neighbor = NULL;
    switch_api_mac_entry_t             mac_entry;
    switch_mac_info_t                 *mac_info = NULL;
    switch_handle_t                    neighbor_handle;
    switch_bd_info_t                  *bd_info = NULL;
    switch_port_info_t                *tmp_port_info = NULL;
    switch_lag_info_t                 *tmp_lag_info = NULL;
    switch_interface_info_t           *tmp_intf_info = NULL;
    switch_api_mac_entry_t            *tmp_mac_entry = NULL;
    switch_handle_type_t               handle_type = 0;
    switch_handle_t                    encap_if;
    switch_spath_info_t               *spath_info = NULL;

    nhop_info = switch_nhop_get(nhop_handle);
    if (!nhop_info) {
        return SWITCH_STATUS_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_STATUS_INVALID_HANDLE;
    }

    *ifindex = intf_info->ifindex;
    *flood = FALSE;
    *mc_index = 0;

    if (SWITCH_INTF_TYPE(intf_info) == SWITCH_API_INTERFACE_TUNNEL) {
        encap_if = SWITCH_INTF_TUNNEL_ENCAP_OUT_IF(intf_info);
        intf_info = switch_api_interface_get(encap_if);
        if (!intf_info) {
            return SWITCH_STATUS_INVALID_HANDLE;
        }
        *ifindex = intf_info->ifindex;
        SWITCH_API_TRACE("%s:%d ifindex for tunnel interface: %x",
                         __FUNCTION__, __LINE__, *ifindex);
    }

    if (SWITCH_INTF_TYPE(intf_info) == SWITCH_API_INTERFACE_L3_VLAN) {
        neighbor_handle = spath_info->neighbor_handle;
        if (neighbor_handle == SWITCH_API_INVALID_HANDLE ||
            neighbor_handle == 0) {
            *ifindex = switch_api_cpu_glean_ifindex();
        } else {
            neighbor_info = switch_neighbor_info_get(neighbor_handle);
            if (!neighbor_info) {
                return SWITCH_STATUS_INVALID_HANDLE;
            }
            neighbor = &neighbor_info->neighbor;
            memset(&mac_entry, 0, sizeof(switch_api_mac_entry_t));
            mac_entry.vlan_handle = intf_info->bd_handle;
            memcpy(&mac_entry.mac, &neighbor->mac_addr, ETH_LEN);
            mac_info = switch_mac_table_entry_find(&mac_entry);
            if (!mac_info) {
                bd_info = switch_bd_get(intf_info->bd_handle);
                if (!bd_info) {
                    return SWITCH_STATUS_INVALID_HANDLE;
                }
                *mc_index = handle_to_id(bd_info->uuc_mc_index);
                *flood = TRUE;
            } else {
                tmp_mac_entry = &mac_info->mac_entry;
                handle_type = switch_handle_get_type(tmp_mac_entry->handle);
                switch (handle_type) {
                    case SWITCH_HANDLE_TYPE_PORT:
                        tmp_port_info = switch_api_port_get_internal(tmp_mac_entry->handle);
                        if (!tmp_port_info) {
                            return SWITCH_STATUS_INVALID_HANDLE;
                        }
                        *ifindex = tmp_port_info->ifindex;
                        break;
                    case SWITCH_HANDLE_TYPE_LAG:
                        tmp_lag_info = switch_api_lag_get_internal(tmp_mac_entry->handle);
                        if (!tmp_lag_info) {
                            return SWITCH_STATUS_INVALID_HANDLE;
                        }
                        *ifindex = tmp_lag_info->ifindex;
                        break;
                    case SWITCH_HANDLE_TYPE_INTERFACE:
                        tmp_intf_info = switch_api_interface_get(tmp_mac_entry->handle);
                        if (!tmp_intf_info) {
                            return SWITCH_STATUS_INVALID_HANDLE;
                        }
                        *ifindex = tmp_intf_info->ifindex;
                        break;
                    default:
                        return SWITCH_STATUS_INVALID_HANDLE;
                }
            }
        }
    }
    return SWITCH_STATUS_SUCCESS;
}