Exemple #1
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;
}
Exemple #2
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;
}
switch_status_t
switch_api_nhop_set(switch_device_t device, switch_handle_t handle,
                    switch_nhop_key_t *nhop_key)
{
    switch_nhop_info_t *info = switch_nhop_get(handle);
    switch (info->type) {
        case SWITCH_NHOP_INDEX_TYPE_ONE_PATH:
            // need to check each field in key diff?
            memcpy(&info->u.spath.nhop_key, nhop_key, sizeof(switch_nhop_key_t));
            break;
        case SWITCH_NHOP_INDEX_TYPE_ECMP:
        case SWITCH_NHOP_INDEX_TYPE_NONE:
            return SWITCH_STATUS_NOT_SUPPORTED;
    }

    return switch_api_nhop_update(device, handle);
}