# A Better Way For Accessing And Maintaining Configs At Multi-Level Environment?

**URL:** <https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028>\
**Category:** UVM\
**Tags:** UVM, uvm-uvm\_config\_db\
**Created:** [September 12, 2018, 7:19pm UTC](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028 "2018-09-12T19:19:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![desperadorocks](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/ecc23a/32.png) [@desperadorocks](https://verificationacademy.com/forums/u/desperadorocks)\
**Post date:** [September 12, 2018, 7:19pm UTC](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028/1 "2018-09-12T19:19:58Z")

</div>

Hello All,

Have a scenario where I wanted to create muti-level environment and wanted a cleaner/better way of sharing the configs using the uvm\_config\_db.

a. Say have a top level environment eatable\_env and a top level environment configs say eatable\_env\_cfg.

b. The top level environment has multiple sub-level environments, say rice\_env, fruits\_env, etc. and each has their corresponding env configs like rice\_env\_cfg , fruits\_env\_cfg etc.

c. The top level eatable\_env\_cfg has the hooks for the sub level envs.

```verilog
  class eatable_env_cfg extends uvm_object;
    rice_env_cfg rice_cfg;
    fruits_env_cfg fruits_cfg; 
   endclass

```

d. And at each sub level env configs, have the required configs to control the environment creation, for eg:

```verilog
 class fruits_env_cfg;
     rand uvm_active_passive_enum fruits_env_is_active = UVM_ACTIVE;
     rand bit enable_fruits_scb;
     rand bit num_fruit_agent;
     ...
   endclass

```

e. So at the base test we create the top level eatable\_env and the required eatable\_env\_cfg. So at the top level base test if I wanted to configure and access the leaf level variable one way is to hierarchical access them, for eg: to assign the interface.

```verilog
  for (int i = 0; i < eatable_cfg.fruits_cfg.num_fruit_agent; i++) begin
    if (!uvm_config_db#(virtual eatable_fruit_apple_if)::get(this, "*", "eatable_fruit_apple_vif", eatable_fruit_apple_vif)) `uvm_error ("error...")
    else eatable_cfg.fruits_cfg.apple_ecfg[i].eatable_fruit_apple_vif = eatable_Fruit_apple_vif;
   end

```

f. So its like hierarchically can access the leaf level variables and do the configs or access for other purpose [eg:eatable\_cfg.fruits\_cfg.num\_fruit\_agent].

BUT, is there a better approach to use rather than hierarchically use/access them ? Like creating hooks/variables used in the leaf level at the top level configs and assign them values from the leaf level configs, so that i can do like eatable\_cfg.num\_fruit\_agent ? rather than hierarchically access them ? OR any other better approach ? share your comments please ! Thanks !

---

<div class="post-metadata">

**Author:** ![desperadorocks](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/ecc23a/32.png) [@desperadorocks](https://verificationacademy.com/forums/u/desperadorocks)\
**Post date:** [September 13, 2018, 11:10pm UTC](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028/2 "2018-09-13T23:10:35Z")

</div>

_In reply to [desperadorocks](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028):_

Hello Mentors ! Can anyone give some or suggest some gud practices ? @Dave, @Cgales, @TomFitz ? Please let me know the same.

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [September 15, 2018, 3:19pm UTC](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028/3 "2018-09-15T15:19:29Z")

</div>

_In reply to [desperadorocks](https://verificationacademy.com/forums/t/a-better-way-for-accessing-and-maintaining-configs-at-multi-level-environment/35028/2):_

There is no easier way (that I have seen) to automate the environment/agent configurations. The test needs to know how to map the top-level interfaces to the individual agents. If you have multiple interfaces of the same type, you need to use a different string for each one when you store it in the config\_db(). The test\_top needs to know which interface to get and assign to the appropriate environment/agent config. The easiest way is to use hierarchical accesses to the configuration objects.
