Exemple #1
0
switch_status_t switch_api_lib_init(switch_device_t device) {
  switch_log_init();
  SWITCH_API_TRACE("Initializing switch api!!");
  switch_pd_client_init(device);
  switch_router_mac_init(device);
  switch_port_init(device);
  switch_bd_init(device);
  switch_lag_init(device);
  switch_interface_init(device);
  switch_mac_table_init(device);
  switch_l3_init(device);
  switch_vrf_init(device);
  switch_neighbor_init(device);
  switch_nhop_init(device);
  switch_mcast_init(device);
  switch_acl_init(device);
  switch_nat_init(device);
  switch_stp_init(device);
  switch_tunnel_init(device);
  switch_mirror_init(device);
  switch_hostif_init(device);
  switch_capability_init(device);
  switch_meter_init(device);
  switch_packet_init(device);
  switch_sflow_init(device);
  switch_qos_init(device);
  switch_buffer_init(device);
  switch_queue_init(device);
  switch_scheduler_init(device);
  switch_packet_init(device);

  return SWITCH_STATUS_SUCCESS;
}
Exemple #2
0
void switch_packet_tx_from_host(int intf_fd) {
  switch_hostif_info_t *hostif_info = NULL;
  int packet_size = 0;
  int in_packet_size = 0;
  static char in_packet[SWITCH_PACKET_MAX_BUFFER_SIZE];
  static char packet[SWITCH_PACKET_MAX_BUFFER_SIZE];
  void *temp = NULL;
  switch_packet_header_t packet_header;
  switch_fabric_header_t *fabric_header = NULL;
  switch_cpu_header_t *cpu_header = NULL;
  switch_ethernet_header_t *eth_header = NULL;
  switch_vlan_header_t *vlan_header = NULL;
  switch_vlan_t vlan_id1 = 0;
  switch_packet_tx_entry_t tx_entry;
  switch_packet_tx_info_t *tx_info = NULL;
  switch_device_t device = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  memset(in_packet, 0x0, SWITCH_PACKET_MAX_BUFFER_SIZE);
  memset(packet, 0x0, SWITCH_PACKET_MAX_BUFFER_SIZE);

  while ((in_packet_size = read(intf_fd, in_packet, sizeof(in_packet))) > 0) {
    JLG(temp, switch_intf_fd_array, intf_fd);
    hostif_info = (switch_hostif_info_t *)(*(unsigned long *)temp);
    if (!hostif_info) {
      perror("invalid hostif fd");
      return;
    }
    SWITCH_API_TRACE("Received packet from host port %s through netdev\n",
                     hostif_info->hostif.intf_name);

    eth_header = (switch_ethernet_header_t *)in_packet;
    if (ntohs(eth_header->ether_type) == SWITCH_ETHERTYPE_DOT1Q) {
      vlan_header = (switch_vlan_header_t *)(in_packet + 2 * ETH_LEN);
      uint16_t *vlan_h = (uint16_t *)(vlan_header) + 1;
      vlan_id1 = ntohs(*vlan_h);
    }

    tx_entry.intf_fd = intf_fd;
    tx_entry.vlan_id = vlan_id1;
    status = switch_packet_tx_info_get(&tx_entry, &tx_info);
    if (status != SWITCH_STATUS_SUCCESS) {
      SWITCH_API_ERROR("net filter tx not found. dropping packet");
      continue;
    }

    memset(&packet_header, 0x0, sizeof(packet_header));
    cpu_header = &packet_header.cpu_header;
    fabric_header = &packet_header.fabric_header;

    if (tx_info->bypass_flags == SWITCH_BYPASS_ALL) {
      cpu_header->tx_bypass = TRUE;
      cpu_header->reason_code = tx_info->bypass_flags;
      fabric_header->dst_port_or_group = tx_info->port;
      memcpy(packet, in_packet, in_packet_size);
      packet_size = in_packet_size;
    } else {
      cpu_header->tx_bypass = FALSE;
      cpu_header->reason_code = tx_info->bypass_flags;
      switch_packet_tx_bd_transform(
          in_packet, in_packet_size, packet, &packet_size, tx_info);
    }

    fabric_header = &packet_header.fabric_header;
    cpu_header = &packet_header.cpu_header;
    fabric_header->dst_device = device;
    fabric_header->packet_type = SWITCH_FABRIC_HEADER_TYPE_CPU;
    fabric_header->ether_type = SWITCH_FABRIC_HEADER_ETHTYPE;

    switch_packet_tx_to_hw(&packet_header, packet, packet_size);
  }
}
Exemple #3
0
switch_status_t switch_api_init_default_entries(switch_device_t device) {
  // Default Entries
  SWITCH_API_TRACE("Programming default entries!!");
  switch_pd_validate_outer_ethernet_add_default_entry(device);
  switch_pd_validate_outer_ip_add_default_entry(device);
  switch_pd_storm_control_table_add_default_entry(device);
  switch_pd_outer_rmac_table_add_default_entry(device);
  switch_pd_src_vtep_table_add_default_entry(device);
  switch_pd_dest_vtep_table_add_default_entry(device);
  switch_pd_validate_packet_table_add_default_entry(device);
  switch_pd_port_vlan_mapping_table_add_default_entry(device);
  switch_pd_acl_table_add_default_entry(device);
  switch_pd_inner_rmac_table_add_default_entry(device);
  switch_pd_fwd_result_table_add_default_entry(device);
  switch_pd_nexthop_table_add_default_entry(device);
  switch_pd_lag_table_add_default_entry(device);
  switch_pd_egress_filter_table_add_default_entry(device);
  switch_pd_rid_table_add_default_entry(device);
  switch_pd_replica_type_table_add_default_entry(device);
  switch_pd_mac_table_add_default_entry(device);
  switch_pd_egress_bd_map_table_add_default_entry(device);
  switch_pd_egress_vni_table_add_default_entry(device);
  switch_pd_ip_fib_add_default_entry(device);
  switch_pd_ip_urpf_add_default_entry(device);
  switch_pd_ip_mcast_add_default_entry(device);
  switch_pd_rewrite_table_add_default_entry(device);
  switch_pd_rewrite_multicast_table_add_default_entry(device);
  switch_pd_egress_vlan_xlate_table_add_default_entry(device);
  switch_pd_egress_acl_add_default_entry(device);
  switch_pd_vlan_decap_table_add_default_entry(device);
  switch_pd_tunnel_smac_rewrite_table_add_default_entry(device);
  switch_pd_tunnel_dmac_rewrite_table_add_default_entry(device);
  switch_pd_tunnel_rewrite_table_add_default_entry(device);
  switch_pd_tunnel_src_rewrite_table_add_default_entry(device);
  switch_pd_tunnel_dst_rewrite_table_add_default_entry(device);
  switch_pd_tunnel_table_add_default_entry(device);
  switch_pd_bd_stats_table_add_default_entry(device);
  switch_pd_bd_flood_table_add_default_entry(device);
  switch_pd_mirror_table_add_default_entry(device);
  switch_pd_mtu_table_add_default_entry(device);
  switch_pd_storm_control_table_add_default_entry(device);
  switch_pd_meter_index_table_add_default_entry(device);
  switch_pd_meter_action_table_add_default_entry(device);
  switch_pd_l3_rewrite_table_add_default_entry(device);
  switch_pd_adjust_lkp_fields_table_add_default_entry(device);
  switch_pd_qos_default_entry_add(device);
  switch_pd_l4port_default_entry_add(device);

  SWITCH_API_TRACE("Programming init entries!!");
  switch_pd_learn_notify_table_add_init_entry(device);
  switch_pd_tunnel_decap_tables_init_entry(device);
  switch_pd_tunnel_encap_tables_init_entry(device);
  switch_pd_validate_outer_ethernet_table_init_entry(device);
  switch_pd_vlan_decap_table_init_entry(device);
  switch_pd_fwd_result_table_add_init_entry(device);
  switch_pd_validate_mpls_packet_table_init_entry(device);
  switch_pd_fabric_header_table_init_entry(device);
  switch_pd_egress_port_mapping_table_init_entry(device);
  switch_pd_compute_hashes_init_entry(device);
  switch_pd_switch_config_params_table_init(device);
  switch_pd_replica_type_table_init_entry(device);
  switch_pd_rewrite_multicast_table_init_entry(device);
  switch_pd_l3_rewrite_table_init_entry(device);
  switch_pd_egress_l4port_fields_init_entry(device);
  switch_pd_nat_init(device);

#ifdef P4_INT_ENABLE
  switch_pd_int_tables_init(device);
#endif
  switch_pd_sflow_tables_init(device);

  return SWITCH_STATUS_SUCCESS;
}
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;
}