Dealing with Compound Attributes
All attribute "get", "set", and "exist" functions in the Ets_Obj package support the use of hierarchical attribute names. This provides a simple way of interacting with nested compound attributes. For example, you can call:
Ets_Obj_Attr_Get (router_obj_hndl,
"IP Router Parameters [0].Interface Information [3].Address", &address_str);
This example gets the "Address" string attribute from the 3rd row of the "Interface Information" attribute, which is a nested compound attribute of "IP Router Parameters".
As a convenience, you can omit the "[0]" if the compound attribute is constrained to have exactly one row. For example:
"IP Router Parameters.Interface Information [3].Address"
The example in Figure 9 demonstrates how to use hierarchical names to set the value of a compound attribute. Two important points are illustrated:
- Getting the count attribute to determine the number of rows in the compound attribute.
- Using an
sprintfto create an attribute name string with the proper index.
Figure 9: Setting Compound Attribute Values—Using Hierarchical Names
/** Loop through all interfaces, setting the cost of all OSPF interfaces to 1. **/
/* Get the number of rows in the OSPF Parameters' Interface Information */
/* compound attribute. */
num_intfs = 0;
Ets_Obj_Attr_Get (router_obj_hndl,
"OSPF Parameters.Interface Information.count",
&num_intfs);
for (intf_index = 0; intf_index < num_intfs; intf_index++)
{
/* prepare the cost attribute name. */
sprintf (attr_name_str,
"OSPF Parameters.Interface Information [%d].Interface Cost",
intf_index);
/* set this cost to 1. */
Ets_Obj_Attr_Set (router_obj_hndl, attr_name_str, 1);
}
In most cases, hierarchical names are the most efficient way of accessing the sub-attributes of a compound attribute. However, if you are repeatedly setting many sub-attributes on the same compound attribute, the following alternative method may be more efficient.
- Obtain a handle to the top-level attribute using Ets_Obj_Attr_Get().
- Call Ets_Topo_Child_Get() with the handle obtained in step 1 and obtain a list of sub-attributes. Use additional calls to Ets_Topo_Child_Get() to further "drill down" into a compound attribute.
The following code fragment illustrates this procedure.
Figure 10: Setting Compound Attribute Values—Alternate Method
// get handle for top-level "PBX Parameters" attribute, copy into pbx_parameters_list
Ets_Obj_Attr_Get (pbx_obj_hndl, "PBX Parameters", &pbx_parameters);
// Get list of "PBX Parameters" attributes
pbx_parameters_list = Ets_Topo_Child_Get (pbx_parameters, EtsC_Obj_Mtype_All, 0);
if (Ets_Obj_Attr_Exists (pbx_parameters, "Call Generation")
{
// Get list of "PBX Parameters.Call Generation" attributes
call_parameters = Ets_Topo_Child_Get (pbx_parameters_list,
EtsC_Obj_Mtype_All, 0);
....
}