Exemple #1
0
static switch_l3_hash_t *switch_l3_insert_hash(switch_handle_t vrf,
                                               switch_ip_addr_t *ip_addr,
                                               switch_handle_t interface) {
  switch_l3_hash_t *hash_entry = NULL;
  unsigned char key[SWITCH_L3_HASH_KEY_SIZE];
  unsigned int len = 0;
  uint32_t hash;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  switch_l3_hash_key_init(key, vrf, ip_addr, &len, &hash);
  hash_entry = switch_malloc(sizeof(switch_l3_hash_t), 1);
  if (!hash_entry) {
    return NULL;
  }
  memcpy(hash_entry->key, key, SWITCH_L3_HASH_KEY_SIZE);
  hash_entry->path_count = 1;

  if (!switch_l3_host_entry(ip_addr)) {
    status = switch_l3_insert_into_lpm_trie(vrf, ip_addr, hash_entry);
    if (status != SWITCH_STATUS_SUCCESS) {
      switch_free(hash_entry);
      return NULL;
    }
  }

  tommy_hashtable_insert(
      &switch_l3_hash_table, &(hash_entry->node), hash_entry, hash);
  switch_l3_insert_into_vrf_list(hash_entry);
  return hash_entry;
}
Exemple #2
0
static switch_status_t switch_dmac_rewrite_delete_hash(switch_device_t device,
                                                       switch_mac_addr_t *mac) {
  switch_dmac_rewrite_t *dmac_rewrite = NULL;
  unsigned char key[SWITCH_DMAC_REWRITE_HASH_KEY_SIZE];
  unsigned int len = 0;
  uint32_t hash = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  dmac_rewrite = switch_dmac_rewrite_search_hash(mac);
  if (!dmac_rewrite) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
  dmac_rewrite->ref_count--;
  if (dmac_rewrite->ref_count == 0) {
    switch_dmac_rewrite_hash_key_init(key, mac, &len, &hash);
    dmac_rewrite = tommy_hashtable_remove(
        &switch_dmac_rewrite_table, switch_dmac_rewrite_hash_cmp, key, hash);
    status = switch_pd_tunnel_dmac_rewrite_table_delete_entry(
        device, dmac_rewrite->rewrite_entry);
    if (status != SWITCH_STATUS_SUCCESS) {
      SWITCH_API_ERROR(
          "%s:%d unabl to delete tunnel dmac entry!", __FUNCTION__, __LINE__);
      return status;
    }
    switch_api_id_allocator_release(dmac_rewrite_index_allocator,
                                    dmac_rewrite->index);
    switch_free(dmac_rewrite);
  }
  return status;
}
Exemple #3
0
static void destroy_node(node_t *node) {
  Word_t index = 0;
  Word_t *pnode;
  Word_t rc_word;
  JLF(pnode, node->PJLarray_branches, index);
  while (pnode != NULL) {
    destroy_node((node_t *)*pnode);
    JLN(pnode, node->PJLarray_branches, index);
  }
  JLFA(rc_word, node->PJLarray_branches);
  JLFA(rc_word, node->PJLarray_prefixes);
  switch_free(node);
}
switch_status_t
switch_api_stp_group_vlans_remove(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;
    tommy_node                        *node = 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;
        }

        node = tommy_list_head(&(stp_info->vlan_list));
        while (node) {
            vlan_entry = node->data;
            if (vlan_entry->bd_handle == bd_handle) {
                break;
            }
            node = node->next;
        }

        if (!node) {
            return SWITCH_STATUS_ITEM_NOT_FOUND;
        }

        bd_info->stp_handle = 0;
        switch_pd_bd_table_update_entry(device, handle_to_id(bd_handle),
                                        bd_info);

        vlan_entry = tommy_list_remove_existing(&(stp_info->vlan_list), node);
        switch_free(vlan_entry);
    }
    return SWITCH_STATUS_SUCCESS;
}
Exemple #5
0
switch_status_t switch_api_packet_net_filter_tx_delete(
    switch_device_t device, switch_packet_tx_key_t *tx_key) {
  switch_packet_tx_entry_t *tmp_tx_entry = NULL;
  switch_packet_tx_info_t *tmp_tx_info = NULL;
  switch_packet_tx_entry_t tx_entry;
  tommy_node *node = NULL;
  switch_hostif_info_t *hostif_info = NULL;
  bool node_found = FALSE;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

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

  memset(&tx_entry, 0x0, sizeof(tx_entry));
  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;
    }
    tx_entry.intf_fd = hostif_info->intf_fd;
  }

  if (tx_key->vlan_valid) {
    tx_entry.vlan_id = tx_key->vlan_id;
  }

  node = tommy_list_head(&packet_tx_filter_list);
  while (node) {
    tmp_tx_info = (switch_packet_tx_info_t *)node->data;
    tmp_tx_entry = &tmp_tx_info->tx_entry;

    if (switch_packet_tx_filter_match(tmp_tx_entry, &tx_entry)) {
      node_found = TRUE;
      break;
    }
    node = node->next;
  }

  if (!node_found) {
    SWITCH_API_ERROR("tx filter delete failed. node find failed");
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }

  tommy_list_remove_existing(&packet_tx_filter_list, node);
  switch_free(tmp_tx_info);
  return status;
}
Exemple #6
0
static switch_status_t switch_neighbor_dmac_delete_hash(
    switch_device_t device, switch_handle_t bd_handle, switch_mac_addr_t *mac) {
  switch_neighbor_dmac_t *neighbor_dmac = NULL;
  unsigned char key[SWITCH_NEIGHBOR_DMAC_HASH_KEY_SIZE];
  unsigned int len = 0;
  uint32_t hash = 0;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  neighbor_dmac = switch_neighbor_dmac_search_hash(bd_handle, mac);
  if (!neighbor_dmac) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }
  switch_neighbor_dmac_hash_key_init(key, bd_handle, mac, &len, &hash);
  neighbor_dmac = tommy_hashtable_remove(
      &switch_neighbor_dmac_table, switch_neighbor_dmac_hash_cmp, key, hash);
  switch_free(neighbor_dmac);
  return status;
}
Exemple #7
0
static switch_status_t switch_l3_delete_hash(switch_handle_t vrf,
                                             switch_ip_addr_t *ip_addr) {
  switch_l3_hash_t *hash_entry = NULL;
  unsigned char key[SWITCH_L3_HASH_KEY_SIZE];
  unsigned int len = 0;
  uint32_t hash;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

  if (!switch_l3_host_entry(ip_addr)) {
    switch_l3_remove_from_lpm_trie(vrf, ip_addr);
  }

  switch_l3_hash_key_init(key, vrf, ip_addr, &len, &hash);
  hash_entry = tommy_hashtable_remove(
      &switch_l3_hash_table, switch_l3_hash_cmp, key, hash);
  switch_l3_remove_from_vrf_list(hash_entry);
  switch_free(hash_entry);
  return status;
}
Exemple #8
0
bool switch_lpm_trie_delete(switch_lpm_trie_t *trie,
                            const char *prefix,
                            int prefix_length) {
  node_t *current_node = trie->root;
  byte_t byte;
  unsigned short prefix_key;
  value_t *pdata = NULL;

  while (prefix_length >= 8) {
    byte = (byte_t)*prefix;
    node_t *node = get_next_node(current_node, byte);
    if (!node) return NULL;

    prefix++;
    prefix_length -= 8;
    current_node = node;
  }

  if (prefix_length == 0)
    prefix_key = 0;
  else
    prefix_key = get_prefix_key((unsigned)prefix_length, (byte_t)*prefix);

  pdata = get_prefix_ptr(current_node, prefix_key);
  if (!pdata) return false;

  if (trie->release_memory) {
    assert(delete_prefix(current_node, prefix_key) == 1);
    current_node->pref_num--;
    while (current_node->pref_num == 0 && current_node->branch_num == 0) {
      node_t *tmp = current_node;
      current_node = current_node->parent;
      if (!current_node) break;
      assert(delete_branch(current_node, tmp->child_id) == 1);
      switch_free(tmp);
      current_node->branch_num--;
    }
  }

  trie->num_entries--;
  return true;
}
Exemple #9
0
switch_status_t switch_api_l3_interface_address_delete(
    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;
  tommy_node *node = NULL;

  UNUSED(device);
  UNUSED(vrf_handle);
  info = switch_api_interface_get(interface_handle);
  if (!info) {
    return SWITCH_STATUS_INVALID_INTERFACE;
  }
  // delete from list and decrement member count
  node = tommy_list_head(&(info->ip_addr));
  while (node) {
    ip_info = node->data;
    if (SWITCH_L3_IP_TYPE(ip_info) == ip_addr->type &&
        SWITCH_L3_IP_IPV4_ADDRESS(ip_info) == ip_addr->ip.v4addr) {
      break;
    }
    node = node->next;
  }

  if (!node) {
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }

  // remove from list
  ip_info = tommy_list_remove_existing(&(info->ip_addr), node);
  info->ip_addr_count--;

  switch_free(ip_info);
  return SWITCH_STATUS_SUCCESS;
}
Exemple #10
0
static switch_handle_t sai_ipmc_tree_create(
    _In_ switch_handle_t vrf_handle,
    _In_ switch_ip_addr_t *src_addr,
    _In_ switch_ip_addr_t *grp_addr,
    _In_ int oif_list_count,
    _In_ switch_handle_t *oif_list_handle) {
  switch_handle_t mcast_handle;
  switch_status_t status;

  uint16_t mbr_count_max = oif_list_count;
  uint16_t mbr_count = 0;
  switch_vlan_interface_t *mbrs = NULL;
  mbrs = switch_malloc(sizeof(switch_vlan_interface_t), oif_list_count);

  mcast_handle = switch_api_multicast_tree_create(device);
  int i = 0;
  for (i = 0; i < oif_list_count; i++) {
    switch_handle_t intf_handle = oif_list_handle[i];
    switch_interface_type_t type;
    status = switch_api_interface_get_type(intf_handle, &type);
    assert(status == SWITCH_STATUS_SUCCESS);
    if (type == SWITCH_API_INTERFACE_L3) {
      mbrs[mbr_count].vlan_handle = 0;
      mbrs[mbr_count].intf_handle = intf_handle;
      mbr_count++;
    } else {
      uint64_t snooping_enabled = true;
      switch_handle_t vlan_handle;
      status = switch_api_interface_get_vlan_handle(intf_handle, &vlan_handle);
      assert(status == SWITCH_STATUS_SUCCESS);
      if (grp_addr->type == SWITCH_API_IP_ADDR_V4) {
        status = switch_api_vlan_igmp_snooping_enabled_get(vlan_handle,
                                                           &snooping_enabled);
        assert(status == SWITCH_STATUS_SUCCESS);
      } else {
        status = switch_api_vlan_mld_snooping_enabled_get(vlan_handle,
                                                          &snooping_enabled);
        assert(status == SWITCH_STATUS_SUCCESS);
      }
      if (snooping_enabled) {
        switch_handle_t l2mcast_handle;
        status = switch_api_multicast_l2route_tree_get(
            device, vlan_handle, src_addr, grp_addr, &l2mcast_handle);
        if (status != SWITCH_STATUS_SUCCESS) {
          continue;
        }
        uint16_t l2mbr_count = 0;
        switch_vlan_interface_t *l2mbrs = NULL;
        status = switch_api_multicast_member_get(
            device, l2mcast_handle, &l2mbr_count, &l2mbrs);
        if (status != SWITCH_STATUS_SUCCESS) {
          continue;
        }
        mbr_count_max += l2mbr_count;
        mbrs = switch_realloc(
            mbrs, (sizeof(switch_vlan_interface_t) * mbr_count_max));
        memcpy(mbrs + mbr_count,
               l2mbrs,
               (sizeof(switch_vlan_interface_t) * l2mbr_count));
        mbr_count += l2mbr_count;

        switch_free(l2mbrs);
      } else {
        uint16_t l2mbr_count = 0;
        switch_vlan_interface_t *l2mbrs = NULL;
        status = switch_api_vlan_interfaces_get(
            device, vlan_handle, &l2mbr_count, &l2mbrs);
        if (status != SWITCH_STATUS_SUCCESS) {
          continue;
        }

        mbr_count_max += l2mbr_count;
        mbrs = switch_realloc(
            mbrs, (sizeof(switch_vlan_interface_t) * mbr_count_max));
        memcpy(mbrs + mbr_count,
               l2mbrs,
               (sizeof(switch_vlan_interface_t) * l2mbr_count));
        mbr_count += l2mbr_count;
      }
    }
  }
  status =
      switch_api_multicast_member_add(device, mcast_handle, mbr_count, mbrs);
  assert(status == SWITCH_STATUS_SUCCESS);

  switch_free(mbrs);
  return mcast_handle;
}
Exemple #11
0
main()
{
    int i,status;
    pthread_t switch_thread_id;
    pthread_t harness_thread_id;

    printf("Initializing ports\n");

    for(i=0; i<4; i++) {
        port_init( &(in_port[i]));
        port_init( &(out_port[i]));
    }

    printf("Initializing switch\n");

    switch_init();

    printf("Initializing harness\n");

    harness_init();

    die = FALSE;

    printf("Starting switch thread\n");
    status = pthread_create(&switch_thread_id,
                            NULL,
                            switch_thread_routine,
                            NULL);

    if (status != 0) {
        printf("Error creating switch thread\n");
        exit(0);
    }

    status = pthread_detach(switch_thread_id);
    if (status != 0) {
        printf("Error detaching switch thread\n");
        exit(0);
    }


    printf("Starting harness thread\n");
    status = pthread_create(&harness_thread_id,
                            NULL,
                            harness_thread_routine,
                            NULL);

    if (status != 0) {
        printf("Error creating harness thread\n");
        exit(0);
    }

    status = pthread_detach(harness_thread_id);
    if (status != 0) {
        printf("Error detaching harness thread\n");
        exit(0);
    }

    while (!die) {
        sleep(1);
    }

    printf("Main program is now done\n");

    harness_end();
    switch_free();
}
switch_status_t
switch_api_ecmp_member_delete(switch_device_t device, switch_handle_t ecmp_handle,
                              uint16_t nhop_count, switch_handle_t *nhop_handle_list)
{
    switch_nhop_info_t                *nhop_info = NULL;
    switch_nhop_info_t                *e_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;
    tommy_node                        *node = 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;
    }
    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_info = &(SWITCH_NHOP_ECMP_INFO(e_nhop_info));
        node = tommy_list_head(&(ecmp_info->members));
        while (node) {
            ecmp_member = (switch_ecmp_member_t *) node->data;
            if (ecmp_member->nhop_handle == nhop_handle) {
                break;
            }
            node = node->next;
        }

        if (!node) {
            return SWITCH_STATUS_ITEM_NOT_FOUND;
        }
        intf_info = switch_api_interface_get(spath_info->nhop_key.intf_handle);
        if (!intf_info) {
            return SWITCH_STATUS_INVALID_INTERFACE;
        }

        nhop_info->ref_count--;
#if SWITCH_PD
        if (ecmp_info->count == 1) {
            status = switch_pd_ecmp_group_table_delete_entry(device, ecmp_info->hw_entry);
            if (status != SWITCH_STATUS_SUCCESS) {
                return status;
            }
        }
        status = switch_pd_ecmp_member_delete(device, ecmp_info->pd_group_hdl, 
                                              ecmp_member->mbr_hdl);
        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_delete_entry(device, ecmp_member->urpf_hw_entry);
            if (status != SWITCH_STATUS_SUCCESS) {
                return status;
            }
        }
#endif
        ecmp_info->count--;
        ecmp_member = tommy_list_remove_existing(&(ecmp_info->members), node);
        switch_free(ecmp_member);
    }
    return status;
}
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;
}
Exemple #14
0
switch_status_t switch_api_packet_net_filter_rx_delete(
    switch_device_t device, switch_packet_rx_key_t *rx_key) {
  switch_lag_info_t *lag_info = NULL;
  switch_port_info_t *port_info = NULL;
  switch_packet_rx_entry_t *tmp_rx_entry = NULL;
  switch_packet_rx_entry_t rx_entry;
  switch_packet_rx_info_t *tmp_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;
  tommy_node *node = NULL;
  bool node_found = FALSE;
  switch_status_t status = SWITCH_STATUS_SUCCESS;

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

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

  if (rx_key->port_lag_valid && rx_key->port_lag_handle) {
    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;
      }
      rx_entry.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;
      }
      rx_entry.ifindex = port_info->ifindex;
    }
  }

  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 = handle_to_id(bd_handle);
  }

  if (rx_entry.port_valid) {
    rx_entry.port = handle_to_id(rx_key->port_handle);
  }
  rx_entry.bd_valid = rx_key->handle_valid;
  rx_entry.reason_code = rx_key->reason_code;

  node = tommy_list_head(&packet_rx_filter_list);
  while (node) {
    tmp_rx_info = (switch_packet_rx_info_t *)node->data;
    tmp_rx_entry = &tmp_rx_info->rx_entry;
    if (switch_packet_rx_filter_match(tmp_rx_entry, &rx_entry)) {
      node_found = TRUE;
      break;
    }
    node = node->next;
  }

  if (!node_found) {
    SWITCH_API_ERROR("tx filter delete failed. node find failed");
    return SWITCH_STATUS_ITEM_NOT_FOUND;
  }

  tommy_list_remove_existing(&packet_rx_filter_list, node);

  switch_free(tmp_rx_info);
  return status;
}
switch_status_t
switch_api_stp_port_state_clear(switch_device_t device, switch_handle_t stg_handle,
                                switch_handle_t handle)
{
    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 = 0; 
    switch_handle_type_t               handle_type = 0;

    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 clear 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) {
            break;
        }
        node = node->next;
    }
    if (!node) {
        return SWITCH_STATUS_ITEM_NOT_FOUND;
    }

    tommy_list_remove_existing(&(stp_info->port_list), &(port_entry->node));
    switch_free(port_entry);
    return status;
}
Exemple #16
0
void switch_lpm_trie_destroy(switch_lpm_trie_t *t) {
  destroy_node(t->root);
  switch_free(t);
}
Exemple #17
0
main()
{
   int i,status;
   pthread_t switch_thread_id;
   pthread_t harness_thread_id;

   printf("Initializing ports\n");

   for(i=0;i<4;i++) {
      port_init( &(in_port[i]));
      port_init( &(out_port[i]));
   }

   printf("Initializing switch\n");

   switch_init();

   printf("Initializing harness\n");
  
   harness_init();

   die = FALSE;

   printf("Starting switch thread\n");
   status = pthread_create(&switch_thread_id,
                           NULL,
                           switch_thread_routine,
                           NULL);

   if (status != 0) {
      printf("Error creating switch thread\n");
      exit(0);
   }

   status = pthread_detach(switch_thread_id);
   if (status != 0) {
      printf("Error detaching switch thread\n");
      exit(0);
   }


   printf("Starting harness thread\n");
   status = pthread_create(&harness_thread_id,
                           NULL,
                           harness_thread_routine,
                           NULL);

   if (status != 0) {
      printf("Error creating harness thread\n");
      exit(0);
   }

   status = pthread_detach(harness_thread_id);
   if (status != 0) {
      printf("Error detaching harness thread\n");
      exit(0);
   }

   while (!die) {
      sleep(1);
   }

   printf("Main program is now done\n");
	sleepDelay = countPackets*HARNESS_SPEED*2 / 1000000000.0;
	printf("Total accumulated packet delays: %f seconds\n",accum);
	printf("Total packets: %f packets\n",countPackets);
	printf("Total sleep delay: %f nano seconds \n",sleepDelay);
	printf("Average Delay without sleep: %f seconds per packet \n",(accum - sleepDelay/1000000000) /countPackets);
	

   harness_end();   
   switch_free();   
}