📄 ip_cmn_rte_table.ex.c
字号:
/****************************************/
/* Copyright (c) 1986 - 2002 */
/* by OPNET Technologies, Inc. */
/* (A Delaware Corporation) */
/* 7255 Woodmont Av., Suite 250 */
/* Bethesda, MD 20814, U.S.A. */
/* All Rights Reserved. */
/****************************************/
#include <opnet.h>
#include <ip_addr_v4.h>
#include <ip_rte_v4.h>
#include <ip_cmn_rte_table.h>
#include <ip_rte_table_v4.h>
#include <string.h>
#include <oms_tan.h>
#include <stdlib.h>
#include <ip_notif_log_support.h>
#include <ip_rte_support.h>
#include <ip_sim_attr_cache.h>
#include <eigrp_metric_support.h>
#include <ctype.h>
#include <oms_string_support.h>
#include <ip_vrf_table.h>
#include <mpls_support.h>
#include <mpls_path_support.h>
/* Globals. */
/** Define a array of strings that contain **/
/** the names of the supported standard **/
/** routing protocols. **/
const char* IpC_Dyn_Rte_Prot_Names[IPC_DYN_RTE_NUM] =
{"Direct", "OSPF", "RIP", "IGRP", "BGP", "EIGRP", "IS-IS",
"Static", "EXT_EIGRP", "IBGP", "Default", "RIPng", "TORA",
"AODV", "OLSR", "Mobile IP", "LDP", "Custom", "DYMO"};
/* Maximum length of a dest_src_key string. */
#define IPC_DEST_SRC_KEY_LEN 32
/* Global variables for "IP Routing Table Export/Import": */
/* Selection of the simulation attribute "IP Routing */
/* Table Export/Import" */
int routing_table_import_export_flag = IP_RTE_TABLE_NON_DET;
/* Static variable used for custom routing protocol registration. */
static List* Custom_Rte_Protocol_Id_Table = OPC_NIL;
/* Static variabele used to keep number of keys for hash table */
static int IpC_Cmn_Rte_Table_Key_Length = 0;
static int IpC_Cmn_Rte_Table_Hash_Size = 0;
static Boolean IpC_Cmn_Rte_Table_Hash_Size_Estimated = OPC_FALSE;
int ip_num_gateway_demands = 0;
int ip_num_host_nodes = 0;
int ip_num_bgp_neighbors = 0;
/* Pool memory object handles. */
static Pmohandle ip_cmn_rte_table_entry_pmh;
static Pmohandle ip_cmn_rte_table_next_hop_entry_pmh;
static Pmohandle ip_cmn_rte_table_dest_src_table_entry_pmh;
/* Structures internal to the IP common route table. */
typedef struct IpT_Cmn_Rte_Dest_Src_Table_Entry
{
float creation_time;
IpT_Cmn_Rte_Table_Entry* route_entry_ptr;
IpT_Next_Hop_Entry* next_hop_ptr;
} IpT_Cmn_Rte_Dest_Src_Table_Entry;
static void
ip_cmn_rte_table_entry_print (IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_gateway_of_last_resort_print (IpT_Cmn_Rte_Table* route_table);
static void
ip_cmn_rte_table_backup_print (IpT_Cmn_Rte_Table_Entry* route_entry);
static Compcode
ip_cmn_rte_table_backup_entry_src_obj_ptr_update (IpT_Cmn_Rte_Table_Entry* route_entry,
IpT_Rte_Proc_Id proto, void* src_obj_ptr);
static void
ip_cmn_rte_table_last_update_time_set (IpT_Cmn_Rte_Table* route_table, char* convergence_reason);
static IpT_Cmn_Rte_Table_Entry*
ip_cmn_rte_table_entry_create (IpT_Dest_Prefix dest_prefix, IpT_Rte_Proc_Id src_proto,
int admin_distance, void* src_obj_ptr);
static void
ip_cmn_rte_table_entry_next_hop_key_lists_clear (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
EXTERN_C_BEGIN
static void
ip_cmn_rte_table_dest_src_tbl_entry_free (void* entry_ptr);
EXTERN_C_END
static void
ip_cmn_rte_table_next_hop_free (IpT_Next_Hop_Entry* next_hop_ptr, IpT_Cmn_Rte_Table* route_table);
static void
ip_cmn_rte_table_port_info_free (IpT_Port_Info* port_info_ptr, IpT_Cmn_Rte_Table* route_table);
static IpT_Next_Hop_Entry*
ip_cmn_rte_table_next_hop_pick (IpT_Cmn_Rte_Table* route_table_ptr, IpT_Cmn_Rte_Table_Entry* route_entry_ptr);
static IpT_Cmn_Rte_Table_Entry*
ip_cmn_route_table_ptree_lookup (IpT_Cmn_Rte_Table* route_table, InetT_Address dest);
static void
ip_cmn_rte_table_dest_src_key_list_entry_remove (IpT_Next_Hop_Entry* next_hop_ptr,
IpT_Cmn_Rte_Dest_Src_Table_Key key);
static IpT_Cmn_Rte_Dest_Src_Table_Entry*
ip_cmn_rte_table_dest_src_table_entry_create (IpT_Cmn_Rte_Table_Entry* rte_entry_ptr,
IpT_Next_Hop_Entry* next_hop_ptr);
static void
ip_cmn_rte_table_dest_src_table_entry_add (IpT_Cmn_Rte_Table* route_table_ptr, IpT_Cmn_Rte_Dest_Src_Table_Key key,
IpT_Cmn_Rte_Dest_Src_Table_Entry* dest_src_table_entry);
static void
ip_cmn_rte_table_dest_src_table_entries_remove (IpT_Cmn_Rte_Table* route_table_ptr, IpT_Next_Hop_Entry* next_hop_ptr);
EXTERN_C_BEGIN
int
ip_cmn_rte_table_dest_src_table_entry_remove (void* route_table_void_ptr, void* key_ptr);
EXTERN_C_END
static void
ip_cmn_rte_table_dest_src_key_list_entry_add (IpT_Next_Hop_Entry* next_hop_ptr, IpT_Cmn_Rte_Dest_Src_Table_Key key);
static void
ip_cmn_rte_table_entry_redistribute (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry, int redist_type, IpT_Rte_Proc_Id removed_proto);
static int
ip_cmn_rte_table_prune_backups_for_redistribution (IpT_Cmn_Rte_Table *cmn_rte_table,
IpT_Cmn_Rte_Table_Entry *route_ptr, IpT_Rte_Proc_Id routeproc_id,
IpT_Redist_Matrix_Entry *route_matrix_entry, char *message_str);
static List *
ip_cmn_rte_table_redist_matrix_entries_combine (IpT_Redist_Matrix_Entry *in_table_redist_matrix_entry,
IpT_Redist_Matrix_Entry *removed_redist_matrix_entry);
static void
ip_cmn_rte_next_hop_add (IpT_Cmn_Rte_Table_Entry* route_entry,
InetT_Address next_hop, int metric, IpT_Port_Info* port_info_ptr);
static IpT_Cmn_Rte_Table_Entry*
ip_cmn_rte_default_route_add (IpT_Cmn_Rte_Table* cmn_rte_table,
void* src_obj_ptr, InetT_Address next_hop, IpT_Port_Info port_info, int metric,
IpT_Rte_Proc_Id proto, int admin_distance);
static Compcode
ip_cmn_rte_default_route_delete (IpT_Cmn_Rte_Table* cmn_rte_table,
IpT_Rte_Proc_Id proto, int* admin_dist_ptr);
static Compcode
ip_cmn_rte_table_default_route_update (IpT_Cmn_Rte_Table* route_table,
InetT_Address next_hop, IpT_Rte_Proc_Id proto, InetT_Address new_next_hop,
IpT_Port_Info new_port_info, int new_metric, void* src_obj_ptr);
static Compcode
ip_cmn_rte_default_route_next_hop_delete (IpT_Cmn_Rte_Table* cmn_rte_table,
InetT_Address next_hop, IpT_Rte_Proc_Id proto);
static void
ip_cmn_rte_default_route_list_add (IpT_Cmn_Rte_Table* cmn_rte_table, List* route_lptr,
IpT_Cmn_Rte_Table_Entry** new_entry_pptr);
static Compcode
ip_cmn_rte_table_default_entry_exists (IpT_Cmn_Rte_Table* route_table, IpT_Rte_Proc_Id proto,
IpT_Cmn_Rte_Table_Entry** rte_entry_pptr);
static IpT_Cmn_Rte_Table_Entry*
ip_cmn_rte_default_route_list_find (List* route_lptr, IpT_Rte_Proc_Id proto, int* index_ptr);
static int
ip_cmn_rte_default_route_compare (IpT_Cmn_Rte_Table_Entry* entry1, IpT_Cmn_Rte_Table_Entry* entry2);
static void
ip_cmn_rte_gateway_of_last_resort_update (IpT_Cmn_Rte_Table* cmn_rte_table);
static Boolean
ip_cmn_rte_table_classful_entry_exists (IpT_Cmn_Rte_Table* route_table, InetT_Address network_address,
IpT_Cmn_Rte_Table_Entry** curr_entry_pptr);
static void
ip_cmn_rte_table_new_default_route_handle (IpT_Cmn_Rte_Table* cmn_rte_table,
IpT_Cmn_Rte_Table_Entry* new_default_route);
static void
ip_cmn_rte_table_default_network_route_update (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_unresolved_routes_check (IpT_Cmn_Rte_Table* route_table,
InetT_Addr_Family addr_family, IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_unresolved_static_routes_check (IpT_Cmn_Rte_Table* route_table,
InetT_Addr_Family addr_family, IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_unresolved_default_routes_check (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_default_network_route_resolve (IpT_Cmn_Rte_Table* route_table,
int route_index, IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_resolved_routes_check (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_resolved_static_routes_check (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_resolved_default_routes_check (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry);
static IpT_Next_Hop_Entry*
ip_cmn_rte_table_next_hop_copy (IpT_Next_Hop_Entry* next_hop_ptr);
static IpT_Port_Info
ip_cmn_rte_table_port_info_copy (IpT_Port_Info* port_info_ptr);
static Boolean
ip_cmn_rte_enter_backup (IpT_Cmn_Rte_Table_Entry* route_entry, IpT_Rte_Proc_Id proto,
int admin_distance, void *src_obj_ptr);
static IpT_Backup_Entry*
ip_cmn_rte_table_backup_entry_copy (IpT_Backup_Entry* backup_entry_ptr);
static void
ip_cmn_rte_delete_backup (IpT_Cmn_Rte_Table* cmn_rte_table, IpT_Rte_Proc_Id proto,
IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_entry_replace (IpT_Cmn_Rte_Table* cmn_rte_table, void* src_obj_ptr,
IpT_Dest_Prefix dest_prefix, InetT_Address next_hop, IpT_Port_Info port_info,
int metric, IpT_Rte_Proc_Id proto, int admin_distance, IpT_Cmn_Rte_Table_Entry* route_entry);
static void
ip_cmn_rte_table_next_hop_list_update (IpT_Cmn_Rte_Table* route_table,
IpT_Cmn_Rte_Table_Entry* route_entry, InetT_Address next_hop);
static int
ip_cmn_rte_next_hop_update (IpT_Cmn_Rte_Table_Entry* route_entry, InetT_Address next_hop,
InetT_Address new_next_hop, IpT_Port_Info new_port_info, int new_metric, IpT_Cmn_Rte_Table* rte_table_ptr);
static int
ip_cmn_rte_next_hop_delete (IpT_Cmn_Rte_Table* cmn_rte_table, IpT_Cmn_Rte_Table_Entry* route_entry,
InetT_Address next_hop);
static Compcode
ip_cmn_rte_table_rte_list_entry_delete (IpT_Cmn_Rte_Table* route_table, IpT_Cmn_Rte_Table_Entry* route_entry,
OmsT_Ptree_Entry_Index index, IpT_Rte_Proc_Id proto, IpT_Dest_Prefix dest_prefix);
EXTERN_C_BEGIN
static void
ip_cmn_rte_table_entry_free_proc (void* entry_ptr, void* state_ptr);
static void
ip_cmn_route_table_optimal_dest_src_values_print (void* state_ptr, int code);
EXTERN_C_END
char *
ip_cmn_rte_global_exp_file_create (void);
static void
ip_cmn_rte_table_dest_src_table_gbl_variables_init (void);
static IpT_Route_Proc_Info *
ip_cmn_rte_table_route_proc_info_create (IpT_Rte_Proc_Id routeproc_id, Prohandle routeproc_handle);
static IpT_Redist_Info*
ip_cmn_rte_table_redist_info_create (IpT_Rte_Proc_Id routeproc_id, void *redist_metric, int bgp_redist_type);
static IpT_Redist_Matrix_Entry *
ip_cmn_rte_table_redist_matrix_entry_create (IpT_Rte_Proc_Id routeproc_id);
static IpT_Redist_Matrix_Entry *
ip_cmn_rte_table_redist_matrix_entry_search (IpT_Cmn_Rte_Table *ip_route_table, IpT_Rte_Proc_Id routeproc_id);
static IpT_Redist_Info *
ip_cmn_rte_table_redist_info_search (IpT_Redist_Matrix_Entry *redist_matrix_entry, IpT_Rte_Proc_Id routeproc_id);
static IpT_Route_Proc_Info *
ip_cmn_rte_table_route_proc_info_search (IpT_Cmn_Rte_Table *ip_route_table, IpT_Rte_Proc_Id routeproc_id);
static void
ip_cmn_rte_table_rte_inject (int redist_type, Prohandle proc_handle, IpT_Cmn_Rte_Table_Entry* route_ptr, IpT_Cmn_Rte_Table* route_table_ptr);
static void
ip_cmn_rte_table_hash_key_create (char* key_str, int src_fast_addr, int dest_fast_addr, int lookup_index);
static int
ip_cmn_rte_fast_addr_to_hex_str (char* key_str, int fast_addr);
static int
ip_cmn_rte_hex_str_to_fast_addr (char* key_str);
static Compcode
ip_cmn_rte_table_fast_addrs_from_hash_key_get (char* key_str,
int* src_fast_addr_ptr, int* dest_fast_addr_ptr, int* lookup_index_ptr);
static void
ip_cmn_rte_table_dest_src_table_entry_print (char* key, IpT_Cmn_Rte_Dest_Src_Table_Entry* dest_src_entry_ptr);
#define ip_cmn_rte_table_dest_prefix_addr_get_fast(dest_prefix) inet_address_range_addr_get_fast (&(dest_prefix))
#define ip_cmn_rte_table_dest_prefix_addr_check(_addr,_pre) inet_address_range_check(_addr, &(_pre))
#define ip_cmn_rte_table_ipv4_dest_prefix_addr_check(_addr,_pre) inet_ipv4_ntwk_address_range_check(_addr, &(_pre))
#define ip_cmn_rte_table_dest_prefix_addr_ptr_get(_pre) (inet_address_range_addr_ptr_get(&(_pre)))
#define ip_cmn_rte_table_entry_from_ptree_entry_get(_ptree_entry) ((IpT_Cmn_Rte_Table_Entry*) oms_ptree_entry_src_obj_get (_ptree_entry))
#define ip_cmn_rte_table_entry_mem_alloc() ((IpT_Cmn_Rte_Table_Entry*) op_prg_pmo_alloc (ip_cmn_rte_table_entry_pmh))
#define ip_cmn_rte_table_next_hop_entry_mem_alloc() ((IpT_Next_Hop_Entry*) op_prg_pmo_alloc (ip_cmn_rte_table_next_hop_entry_pmh))
#define ip_cmn_rte_table_dest_src_table_lookup(_dst_src_tbl, _key) ((IpT_Cmn_Rte_Dest_Src_Table_Entry*) prg_string_hash_table_item_get ((_dst_src_tbl), (_key)))
#define ip_cmn_rte_table_dest_src_table_create(_rte_table) (prg_string_hash_table_create (IpC_Cmn_Rte_Table_Hash_Size, IpC_Cmn_Rte_Table_Key_Length))
#define ip_cmn_rte_table_entry_is_default(_entry) (0 == ip_cmn_rte_table_entry_mask_len_get (_entry))
#define ip_cmn_rte_table_entry_is_default_network(_entry) (IPC_DYN_RTE_DEFAULT == IP_CMN_RTE_TABLE_ROUTEPROC_PROTOCOL ((_entry)->route_src_proto))
IpT_Cmn_Rte_Table*
ip_cmn_rte_table_create (Objid node_objid, IpT_Rte_Module_Data* ip_rmd_ptr,
struct IpT_Vrf_Table* vrf_table_ptr)
{
IpT_Cmn_Rte_Table* route_table;
static Boolean pmo_handles_init = OPC_FALSE;
/** Allocate memory for an IpT_Cmn_Rte_Table object **/
/** and return a pointer to it. **/
/** NOTE: The responsibility of calling this **/
/** function just once per (routing) node **/
/** belongs in the client side of this **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -