📄 ip_rte_support.ex.c
字号:
Boolean
ip_interface_routing_protocols_contains (List* routing_protocols_lptr, int routing_protocol)
{
Boolean protocol_is_in_this_list;
int* i_th_protocol_ptr;
int i_th_protocol, num_rte_protocols;
/** Checks if the passed in routing protocol is not in the supplied list. **/
FIN (ip_interface_routing_protocols_contains (routing_protocols_lptr, routing_protocol));
/* Check for NIL list */
if (routing_protocols_lptr == OPC_NIL)
FRET (OPC_FALSE);
/* Assume that the passed in routing protocol is not in the supplied list. */
protocol_is_in_this_list = OPC_FALSE;
/* Loop though the different number of routing protocols */
/* running on this interface. */
num_rte_protocols = op_prg_list_size (routing_protocols_lptr);
for (i_th_protocol = 0; i_th_protocol < num_rte_protocols; i_th_protocol++)
{
/* Access the first specification -- this element will */
/* be a pointer to the routing protocol ID. */
i_th_protocol_ptr = (int *) op_prg_list_access (routing_protocols_lptr, i_th_protocol);
/* Check if the supplied protocol is same as this. There is */
/* a special case when a custom routing protocol is used. */
if (routing_protocol == IpC_Rte_Custom &&
*i_th_protocol_ptr >= IPC_INITIAL_CUSTOM_RTE_PROTOCOL_ID)
{
protocol_is_in_this_list = OPC_TRUE;
break;
}
else
{
/* this must be standard routing protocol (e.g., OSPF). */
if (*i_th_protocol_ptr == routing_protocol)
{
protocol_is_in_this_list = OPC_TRUE;
break;
}
}
}
FRET (protocol_is_in_this_list);
}
IpT_Intf_Name_Objid_Table_Handle
ip_rte_proto_intf_attr_objid_table_build (Objid proto_params_objid)
{
PrgT_String_Hash_Table* intf_name_htable_ptr;
Objid intf_info_objid;
Objid subintf_info_objid;
int intf_info_cattr_size;
int subintf_info_cattr_size;
Objid intf_attr_objid;
int intf_type, j, k;
int num_entries = 0;
/** This function creates a lookup table for mapping between **/
/** an Interface name and the objid of the corresponding **/
/** interface under the protocol Parameters of a particular **/
/** protocol e.g. RIP Parameters. The attributes must be in the **/
/** standard form. i.e the given object must have a compound **/
/** attribute named "Interface Information". Each row of this **/
/** attriubte must have an attribute name "Name" whose value **/
/** would be the name of an interface on this node. **/
/** Subinterfaces (if any) must be specified under an attribute **/
/** named "Subinterface Information". But it is not required. **/
/** This funciton also handles Loopback and Tunnel interfaces. **/
/** But it is not required that the given object have attributes**/
/** named "Loopback Interfaces" or "Tunnel Interfaces". **/
/** The function named ip_rte_proto_intf_attr_objid_table_lookup**/
/** can be used to look up the objid of a particular interface **/
/** in the table returned by this function. **/
/** The table thus created must be destroyed by calling **/
/** ip_rte_proto_intf_attr_objid_table_destroy to avoid a **/
/** memory leak. **/
FIN (ip_rte_proto_intf_attr_objid_table_build (proto_params_objid));
/* Initialize the Pool memory object handle if it is not already */
/* initialized. */
if (OPC_FALSE == objid_pmh_initialized)
{
objid_pmh = op_prg_pmo_define ("Interface Objid", sizeof (Objid), 50);
objid_pmh_initialized = OPC_TRUE;
}
/* Create a hash table to store the objid corresponding to */
/* each interface name. */
intf_name_htable_ptr = prg_string_hash_table_create (50, 25);
/* Get the objids of the "Interface Information", */
/* "Loopback Interfaces", "Tunnel Interfaces" and "VLAN */
/* Interfaces" attributes. */
for (intf_type = 0; intf_type < NUM_INTERFACE_TYPES; intf_type++)
{
/* Make sure there is an attribute corresponing to this */
/* interface type under this protocol's parameters. */
if (op_ima_obj_attr_exists (proto_params_objid, intf_types_str_array [intf_type]))
{
op_ima_obj_attr_get (proto_params_objid, intf_types_str_array [intf_type], &(intf_info_objid));
/* Find out the number of rows under this attribute. */
intf_info_cattr_size = op_topo_child_count (intf_info_objid, OPC_OBJTYPE_GENERIC);
/* Loop through all the rows and read in their names */
for (j = 0; j < intf_info_cattr_size; j++)
{
/* Get the object ID of the jth row. */
intf_attr_objid = op_topo_child (intf_info_objid, OPC_OBJTYPE_GENERIC, j);
/* Add this row to the hash table. */
ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_attr_objid);
++num_entries;
/* For physical interfaces we need to go through */
/* the list of Subinterfaces also. */
if ((IpC_Support_Intf_Type_Physical == intf_type) &&
(op_ima_obj_attr_exists (intf_attr_objid, "Subinterface Information")))
{
/* Get the object Id of the subinterface */
/* information attribute. */
op_ima_obj_attr_get (intf_attr_objid, "Subinterface Information", &subintf_info_objid);
/* Get the number of subinterfaces. */
subintf_info_cattr_size = op_topo_child_count (subintf_info_objid, OPC_OBJTYPE_GENERIC);
/* Loop through the subinterfaces and add them */
/* also to the hash table. */
for (k = 0; k < subintf_info_cattr_size; k++)
{
/* Get the object ID of the ith row. */
intf_attr_objid = op_topo_child (subintf_info_objid, OPC_OBJTYPE_GENERIC, k);
/* Add this row to the hash table. */
ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_attr_objid);
++num_entries;
}
}
}
}
}
/* If the hash table is empty, delete it. */
if (0 == num_entries)
{
prg_string_hash_table_free (intf_name_htable_ptr);
intf_name_htable_ptr = IpC_Intf_Name_Objid_Table_Invalid;
}
/* Return the hash table. */
FRET (intf_name_htable_ptr);
}
int
ip_rte_proto_intf_attr_objid_table_size (IpT_Intf_Name_Objid_Table_Handle table_handle)
{
PrgT_List* key_lptr;
int table_size;
/** Return the number of entries in the table. **/
FIN (ip_rte_proto_intf_attr_objid_table_size (table_handle));
/* Currently there is no function that will directly give the */
/* the number of entries in the hash table. So we have to */
/* create the list of keys and get its size. */
/* Get the list of keys. */
key_lptr = prg_string_hash_table_keys_get (table_handle);
/* The size of the table is the number of keys. */
table_size = prg_list_size (key_lptr);
/* Free the memory allocated to the list. */
prg_list_free (key_lptr);
prg_mem_free (key_lptr);
/* Return the number of entries in the table. */
FRET (table_size);
}
Objid
ip_rte_proto_intf_attr_objid_table_lookup_by_name (IpT_Intf_Name_Objid_Table_Handle intf_name_htable_ptr,
const char* interface_name)
{
Objid* intf_objid_ptr;
Objid intf_attr_objid;
/** This function is used to obtain the objid of a row from the **/
/** table created using the **/
/** ip_rte_proto_intf_attr_objid_table_build function. If a **/
/** matching element is not found, OPC_OBJID_INVALID will be **/
/** returned. **/
FIN (ip_rte_proto_intf_attr_objid_table_lookup_by_name (intf_name_htable_ptr, ip_iface_elem_ptr));
/* We do not need to handle the case where the hash table is */
/* NIL, because that case is handled by the */
/* prg_string_hash_table_item_get function. */
/* Look for a matching entry in the hash table. */
intf_objid_ptr = (Objid*) prg_string_hash_table_item_get (intf_name_htable_ptr, interface_name);
/* If no matching entry was found, return OPC_OBJID_INVALID */
if (OPC_NIL == intf_objid_ptr)
{
intf_attr_objid = OPC_OBJID_INVALID;
}
else
{
/* We found a match return the stored value. */
intf_attr_objid = *intf_objid_ptr;
}
FRET (intf_attr_objid);
}
void
ip_rte_proto_intf_attr_objid_table_destroy (IpT_Intf_Name_Objid_Table_Handle intf_name_htable_ptr)
{
/** Frees the memory allocated to a table created using **/
/** ip_rte_proto_intf_attr_objid_table_build. **/
FIN (ip_rte_proto_intf_attr_objid_table_destroy (intf_name_htable_ptr));
prg_string_hash_table_free_proc (intf_name_htable_ptr, op_prg_mem_free);
FOUT;
}
static void
ip_rte_support_intf_objid_add (PrgT_String_Hash_Table* intf_name_htable_ptr, Objid intf_attr_objid)
{
void* old_objid_ptr;
char intf_name [128];
Objid* intf_objid_ptr;
/** This function adds the given interface name to the hash table. **/
FIN (ip_rte_support_intf_objid_add (intf_name_htable_ptr, intf_name_objid));
/* Allocate enough memory to hod the object ID. */
intf_objid_ptr = (Objid*) op_prg_pmo_alloc (objid_pmh);
*intf_objid_ptr = intf_attr_objid;
/* Get the name of this interface. */
op_ima_obj_attr_get (intf_attr_objid, "Name", intf_name);
/* Create a hash table entry corresponding to this interface */
prg_string_hash_table_item_insert (intf_name_htable_ptr, intf_name, intf_objid_ptr, &old_objid_ptr);
if (old_objid_ptr != OPC_NIL)
{
ipnl_dupl_intf_name_error (intf_attr_objid, intf_name);
}
FOUT;
}
IpT_Packet_Format
ip_rte_packet_format_valid (IpT_Rte_Module_Data * iprmd_ptr,Packet * pkptr)
{
static Boolean ip_error_message_printed = OPC_FALSE;
char ip_packet_format [256];
/** Check if the given packet is of a format that can be **/
/** handled by the IP module. **/
FIN (ip_rte_packet_format_valid (pkptr));
/* Obtain the format of the packet. */
op_pk_format (pkptr, ip_packet_format);
/* Check if the packet is an IP datagram. */
if (strcmp (ip_packet_format, "ip_dgram_v4") == 0)
{
/* The packet is an IP datagram. */
FRET (IpC_Packet_Format_Ip_Dgram);
}
/* Check if the packet is an LACP PDU. */
else if (strcmp (ip_packet_format, "lac_pdu") == 0)
{
/* This is an LACP PDU. */
FRET (IpC_Packet_Format_Lacp_Pdu);
}
else
{
/* Invalid packet format. */
/* Print this error message only once. */
if (ip_error_message_printed == OPC_FALSE)
{
/* Print a warning message in the simulation log. */
ipnl_protwarn_pkformat (op_pk_id (pkptr), op_pk_tree_id (pkptr),
ip_packet_format);
ip_error_message_printed = OPC_TRUE;
}
/* Destroy the packet and update statistics. */
ip_rte_dgram_discard (iprmd_ptr, pkptr, OPC_NIL,
"Non IP packet received" /* Reason for drop */);
FRET (IpC_Packet_Format_Invalid);
}
}
Boolean
ip_rte_packet_arrival (IpT_Rte_Module_Data * iprmd_ptr,
Packet ** pkpptr, int instrm,
IpT_Rte_Ind_Ici_Fields ** intf_ici_fdstruct_pptr,
IpT_Interface_Info **rcvd_iface_info_pptr)
{
Boolean ip_rte_trace;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -