1.以太网中,如果一个帧是VLAN帧,那么就会有vlan_id 字段。直观想法是使用动态数组实现:
2. 随机化普通以太网帧是,使用如下方式:
3.协议规定vlan 字段固定为4个字节,所以随机化VLAN 帧时,使用如下方式:
协议中规定vlan 的4个字节(4段不一样大)各自有其不同的含义。如果使用上面的方式,问题虽然解决了,但是4个字段的含义不太明确。
4.解决方法:
`ifndef MY_TRANSACTION__SV
`define MY_TRANSACTION__SV
class my_transaction extends uvm_sequence_item;
rand bit[47:0] dmac;
rand bit[47:0] smac;
rand bit[15:0] vlan_info1;
rand bit[2:0] vlan_info2;
rand bit vlan_info3;
rand bit[11:0] vlan_info4;
rand bit[15:0] ether_type;
rand byte pload[];
rand bit[31:0] crc;
rand bit is_vlan;
constraint pload_cons{
pload.size >= 46;
pload.size <= 1500;
}
function bit[31:0] calc_crc();
return 32'h0;
endfunction
function void post_randomize();
crc = calc_crc;
endfunction
`uvm_object_utils_begin(my_transaction)
`uvm_field_int(dmac, UVM_ALL_ON)
`uvm_field_int(smac, UVM_ALL_ON)
if(is_vlan)begin
`uvm_field_int(vlan_info1, UVM_ALL_ON)
`uvm_field_int(vlan_info2, UVM_ALL_ON)
`uvm_field_int(vlan_info3, UVM_ALL_ON)
`uvm_field_int(vlan_info4, UVM_ALL_ON)
end
`uvm_field_int(ether_type, UVM_ALL_ON)
`uvm_field_array_int(pload, UVM_ALL_ON)
`uvm_field_int(crc, UVM_ALL_ON | UVM_NOPACK)
`uvm_field_int(is_vlan, UVM_ALL_ON | UVM_NOPACK)
`uvm_object_utils_end
function new(string name = "my_transaction");
super.new();
endfunction
endclass
`endif
随机化普通以太网帧是,如下:
随机化VLAN帧是,如下:
1)使用print 操作时,4个字段的信息非常明显。
2)调用compare是,如果两个transaction不同,将会明确指明哪个字段不一样。