Creating Configurable Environments with Hierarchical and Global Options (vmm_opts) in VMM

Verification environments need to accommodate changing specifications and at 
the same time cater to the requirements of different clusters and subsystems.
vmm_opts provides the ability to provide a high level of configurability so 
that environments can work for different DUTs. This article shows how to use 
vmm_opts not just to set the switches globally and hierarchically, but also to 
specify the address ranges in scenarios from the test cases and the 
command-line.


First, you need to create a list of controls/switches that should be 
provided as global options (like simulation timeout, scoreboard/coverage enable,
etc.) and then another set of hierarchical options to control instance specific
behavior (like number of transactions to be generated, burst enables, 
transaction speed, address ranges to be generated by a specific instance, etc.)


Global options:
Step 1:
Declare an integer, say simulation_timeout in the environment class or wherever
it is required and use vmm_opts::get_int(..) method as shown below. Specify a 
default value as well just in case, if the variable is not set anywhere.


simulation_timeout = vmm_opts::get_int("TIMEOUT", 10000);


Step 2:
Then either at the test case or at the command-line, this can be overridden
using vmm_opts::set_int or +vmm_opts+ runtime option.


Overridding from the test case:


vmm_opts::set_int("%*:TIMEOUT", 50000); 


In the examples above, "%*" specified any hierarchy and hence this will apply
to all classes wherever there is a TIMEOUT variable.
Overridding from the command-line.


./simv +vmm_opts+TIMEOUT=80000


Options can also be overridden from a command file. Also, options can be a 
string or Boolean variable as well.


Hierarchical options:
In order to use hierarchical options, the parent child hierarchy should be 
established across components while creating the verification environment. This
is possible by passing the parent handle to any component during construction
or through the set_parent_object() method. Since all VMM base classes extend
from vmm_object, all derived classes can thus use this method. This is required
since the hierarchy specified externally (from test case/command line) will be
used to map the hierarchy in the environment. The following steps shows how 
hierarchical options are used.


Step 1:
Declare options, say burst_enable and num_of_trans in a subenv class and use 
vmm_opts::get_object_bit(..) and vmm_opts::get_object_int(..) to retrieve 
appropriate values. This is done by passing the current hierarchy and default 
values as arguments. Also, for setting ranges, declare min_addr and max_addr,
 and use get_object_range().


class master_subenv extends vmm_subenv;
    bit burst_enable;
    int num_of_trans;
    int min_addr;
    int max_addr;
    function void configure();
          bit is_set; //to determine if the default value is overridden
          burst_enable = vmm_opts::get_object_bit(is_set, this, "BURST_ENABLE");
          num_of_trans = vmm_opts::get_object_int(is_set, this, "NUM_TRANS", 100);
          vmm_opts::get_object_range(is_set, this, "ADDR_RANGE", 0, 32'hFFFF_FFFF);
          ....
    endfunction
 endclass


Step 2:
Build the environment with parent/child hierarchy either by passing the parent
handle through the constructor to every child, or using 
vmm_object::set_parent_object() method. This is easy as almost all base classes
 are extended from vmm_object by default.


class  dut_env extends vmm_env;
       virtual function build();
         .....
         mst0 = new("MST0", ....);
         mst0.set_parent_object(this);
         mst1 = new("MST1", ...);
         mst1.set_parent_object(this);
        ....
       endfunction
endclass


Step 3:
From the test case, you can override the default value using vmm_opts::set_bit 
or vmm_opts::set_int(..) specifying the hierarchy. You can also use pattern 
matching as well to avoid specifying the overrides only for specific instances
as in the patterns mentioned.  


vmm_opts::set_int("%*:MST0:NUM_TRANS", 50);
This will only override the NUM_TRANS value in MST0 instance to 50.


vmm_opts::set_int("%*:MST1:NUM_TRANS", 100); 
This will only override the NUM_TRANS value in MST1 instance.


vmm_opts::set_bit("%*:burst_enable);
This will override the burst_enable variable and set it to 1 in all instances.


vmm_opts::set_range("%*:MST1:ADDR_RANGE", 32'h1000_0000, 32'h1000_FFFF);
This will override the ADDR_RANGE in MST1 instance.


The default value can be overriden from the command-line as well.
./simv +vmm_opts+NUM_TRANS=50@%*:MST0+NUM_TRANS=100@%*:MST1+burst_enable@%*


In summary, vmm_opts provides a powerful and user friendly way of configuring 
the environment from the command-line or the test case. 
There is also a possibility to auto-document these options. You can provide the 
explanation of each of the options in the get_object_*() and get_*() methods 
and this will be displayed when vmm_opts::get_help() is called or 
+vmm+help is passed at runtime. The details of the override from different
hierarchies including the line numbers and the file numbers will also be 
displayed. For more details on these classes, please refer to the VMM User Guide.
<think>我们被要求解释设备必须能够配置其通过DHCPv6请求哪些DHCPv6选项。 关键点:设备应允许管理员自定义在DHCPv6交互中请求的选项列表。 回答结构: 1. 背景:DHCPv6用于IPv6地址分配和其他网络配置,客户端通过请求特定选项来获取配置信息。 2. 要求:设备必须提供配置接口,让用户指定需要请求的DHCPv6选项(如DNS服务器、域名等)。 3. 实现方式:通过CLI、配置文件或管理界面设置选项列表。 4. 技术细节:在DHCPv6请求报文(如Solicit, Request, Renew)中,客户端通过Option Request Option (ORO, 选项代码6)携带请求的选项列表。 5. 示例:配置设备请求选项23(DNS服务器)和选项24(域名搜索列表)。 伪代码示例:展示如何构建包含配置选项的DHCPv6请求。 最后,按照要求提出3-5个相关问题。</think>设备必须支持通过配置指定其在 DHCPv6 交互中请求的具体选项。该功能允许管理员根据网络需求定制 DHCPv6 客户端行为,是 RFC 8415(DHCPv6 协议)的关键实现要求。以下是技术解析和实现方案: ### 核心配置机制 1. **选项请求列表(Option Request Option, ORO)** - 客户端在 `Solicit`、`Request`、`Renew` 报文中必须包含 ORO(选项代码6) - ORO 携带客户端需要服务器返回的选项列表 - 设备需提供接口配置 ORO 内容 2. **配置接口实现** ```python # DHCPv6 客户端配置模型示例 class DHCPv6ClientConfig: def __init__(self): self.requested_options = [] # 可配置的选项列表 def add_option(self, option_code): """添加需请求的选项代码""" if option_code not in self.requested_options: self.requested_options.append(option_code) def remove_option(self, option_code): """移除不再需要的选项""" self.requested_options = [opt for opt in self.requested_options if opt != option_code] # 在报文生成模块中使用配置 def build_dhcpv6_packet(config): # 创建选项请求选项(ORO) oro_option = { 'code': 6, # ORO 选项代码 'data': config.requested_options # 配置的选项列表 } # 将ORO加入报文选项字段 return { 'msg_type': 1, # Solicit类型 'options': [oro_option] + other_options } ``` ### 关键配置选项示例 | 选项代码 | 选项名称 | 典型用途 | 是否必需 | |---------|---------|---------|---------| | 23 | DNS 递归名称服务器 | 获取DNS服务器地址 | ✓ | | 24 | 域名搜索列表 | 域名解析配置 | ✓ | | 31 | SNTP 服务器 | 时间同步 | △ | | 56 | NTP 服务器 | 精确时间同步 | △ | | 17 | 无状态地址自动配置 | IPv6地址分配 | ✗ | ### 实现注意事项 1. **默认行为** - 未配置时:应请求基础选项(代码23、24等) - 空配置:显式空列表应发送ORO但不请求任何选项 2. **动态更新** - 支持运行时修改配置(无需重启服务) - 在 `Renew` 报文中反映更新后的选项列表 3. **安全约束** - 验证选项代码有效性(1-65535) - 禁止请求冲突选项(如同时请求31和56) - 限制单次请求选项数量(建议≤50个) 4. **日志与监控** ```python # 配置变更日志记录 def log_option_change(old_list, new_list): added = set(new_list) - set(old_list) removed = set(old_list) - set(new_list) if added: print(f"新增请求选项: {added}") if removed: print(f"移除请求选项: {removed}") ``` ### 网络场景应用 - **精简网络**:仅请求DNS选项(23,24)减少开销 - **物联网环境**:添加SNTP(31)实现时间同步 - **禁用冗余功能**:空配置避免获取不必要参数 - **合规性网络**:按安全策略排除特定选项 该实现确保设备在各类IPv6部署环境中保持灵活性和可控性,同时满足RFC 8415第18.2.1节对ORO处理的强制要求。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值