Skip to content

Commit f3692e0

Browse files
committed
Merge branch 'marushchenko-feat-packet_generators-packet_size_configuration' into 'devel'
Add packet size configuration to the packet generators See merge request ndk/ndk-fpga!243
2 parents d4658d1 + 25f0cc3 commit f3692e0

9 files changed

Lines changed: 97 additions & 59 deletions

File tree

apps/minimal/uvm/test_pkg.sv

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@
1010

1111
package test_pkg;
1212

13-
parameter time CLK_PERIOD = 10ns;
13+
parameter time CLK_PERIOD = 10ns;
1414

15-
parameter int unsigned ETH_PORTS = 2;
16-
parameter int unsigned ETH_STREAMS = 2;
17-
parameter int unsigned ETH_CHANNELS = 4;
18-
parameter int unsigned ETH_PKT_MTU = 2**12;
19-
parameter int unsigned ETH_RX_HDR_WIDTH = 102;
20-
parameter int unsigned ETH_TX_HDR_WIDTH = 25;
21-
parameter int unsigned PCIE_ENDPOINTS = 2;
22-
parameter int unsigned DMA_STREAMS = 2;
23-
parameter int unsigned DMA_RX_CHANNELS = 8; //10;
24-
parameter int unsigned DMA_TX_CHANNELS = 8;
25-
parameter int unsigned DMA_HDR_META_WIDTH = 12;
26-
parameter int unsigned DMA_PKT_MTU = 2**12;
27-
parameter int unsigned REGIONS = 4;
28-
parameter int unsigned MFB_REG_SIZE = 8;
29-
parameter int unsigned MFB_BLOCK_SIZE = 8;
30-
parameter int unsigned MFB_ITEM_WIDTH = 8;
31-
parameter int unsigned MEM_PORTS = 1;
32-
parameter time MEM_CLK_PERIOD [MEM_PORTS-1:0] = '{MEM_PORTS{10ns}};
33-
parameter int unsigned MEM_ADDR_WIDTH = 26;
34-
parameter int unsigned MEM_BURST_WIDTH = 7;
35-
parameter int unsigned MEM_DATA_WIDTH = 512;
36-
parameter int unsigned MEM_REFR_PERIOD_WIDTH = 32;
37-
parameter logic [MEM_REFR_PERIOD_WIDTH-1:0] MEM_DEF_REFR_PERIOD[MEM_PORTS-1:0] = '{MEM_PORTS{128}};
38-
parameter int unsigned MI_DATA_WIDTH = 32;
39-
parameter int unsigned MI_ADDR_WIDTH = 32;
40-
parameter int unsigned RESET_WIDTH = 4;
41-
parameter string BOARD = "400G1";
42-
parameter string DEVICE = "ULTRASCALE";
15+
parameter ETH_PORTS = 2;
16+
parameter ETH_STREAMS = 2;
17+
parameter ETH_CHANNELS = 4;
18+
parameter ETH_PKT_MTU = 4096;
19+
parameter ETH_RX_HDR_WIDTH = 102;
20+
parameter ETH_TX_HDR_WIDTH = 25;
21+
parameter PCIE_ENDPOINTS = 2;
22+
parameter DMA_STREAMS = 2;
23+
parameter DMA_RX_CHANNELS = 8;
24+
parameter DMA_TX_CHANNELS = 8;
25+
parameter DMA_HDR_META_WIDTH = 12;
26+
parameter DMA_PKT_MTU = 4096;
27+
parameter REGIONS = 4;
28+
parameter MFB_REG_SIZE = 8;
29+
parameter MFB_BLOCK_SIZE = 8;
30+
parameter MFB_ITEM_WIDTH = 8;
31+
parameter MEM_PORTS = 1;
32+
parameter time MEM_CLK_PERIOD [MEM_PORTS-1:0] = '{MEM_PORTS{10ns}};
33+
parameter MEM_ADDR_WIDTH = 26;
34+
parameter MEM_BURST_WIDTH = 7;
35+
parameter MEM_DATA_WIDTH = 512;
36+
parameter MEM_REFR_PERIOD_WIDTH = 32;
37+
parameter [MEM_REFR_PERIOD_WIDTH-1:0] MEM_DEF_REFR_PERIOD[MEM_PORTS-1:0] = '{MEM_PORTS{128}};
38+
parameter MI_DATA_WIDTH = 32;
39+
parameter MI_ADDR_WIDTH = 32;
40+
parameter RESET_WIDTH = 4;
41+
parameter BOARD = "400G1";
42+
parameter DEVICE = "ULTRASCALE";
4343

4444
endpackage

comp/uvm/packet_generators/flowtest/tools/config_generator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ def add_mac_from_arguments(config: dict, mac_string: str) -> None:
299299
mac_addresses_from_arguments = mac_string.split(';')
300300
extend_list_attribute(config, 'MANDATORY_MAC_ADDRESS_RANGES', mac_addresses_from_arguments)
301301

302+
### PACKET SIZE PROCESSING ###
303+
304+
305+
def set_packet_min_size_from_arguments(config: dict, packet_min_size: int):
306+
config['PACKET_MIN_SIZE'] = packet_min_size
307+
308+
309+
def set_packet_max_size_from_arguments(config: dict, packet_max_size: int):
310+
config['PACKET_MAX_SIZE'] = packet_max_size
311+
302312
### ARGUMENT PARSING ###
303313

304314

@@ -311,6 +321,8 @@ def parse_arguments() -> argparse.Namespace:
311321
argument_parser.add_argument('--ipv4', type=str, help='IPv4 addresses in format \"addr1/mask1;addr2/mask2;addr3/mask3\".', default=None)
312322
argument_parser.add_argument('--ipv6', type=str, help='IPv6 addresses in format \"addr1/mask1;addr2/mask2;addr3/mask3\".', default=None)
313323
argument_parser.add_argument('--mac', type=str, help='MAC addresses in format \"addr1/mask1;addr2/mask2;addr3/mask3\".', default=None)
324+
argument_parser.add_argument('--packet-min-size', type=int, help='Minimum size of packets.', default=None)
325+
argument_parser.add_argument('--packet-max-size', type=int, help='Maximum size of packets.', default=None)
314326

315327
arguments = argument_parser.parse_args()
316328
return arguments
@@ -336,6 +348,11 @@ def main() -> None:
336348
if arguments.mac is not None:
337349
add_mac_from_arguments(generator_config, arguments.mac)
338350

351+
if arguments.packet_min_size is not None:
352+
set_packet_min_size_from_arguments(generator_config, arguments.packet_min_size)
353+
if arguments.packet_max_size is not None:
354+
set_packet_max_size_from_arguments(generator_config, arguments.packet_max_size)
355+
339356
config_generator = ConfigGenerator(generator_config)
340357
config = config_generator.generate()
341358

comp/uvm/packet_generators/search/parser.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, name):
2929
def name_get(self):
3030
return self.name
3131

32-
def protocol_add(self, config):
32+
def protocol_add(self, config, packet):
3333
return None
3434

3535
def protocol_next(self, config):
@@ -49,15 +49,26 @@ class Payload(base_node):
4949
def __init__(self):
5050
super().__init__("Payload")
5151

52-
def protocol_add(self, config):
53-
return scapy.all.Raw()
52+
def protocol_add(self, config, packet):
53+
min_size = config.object_get(["packet", "size_min"])
54+
max_size = config.object_get(["packet", "size_max"])
55+
56+
if not min_size:
57+
min_size = 60
58+
if not max_size:
59+
max_size = 1500
60+
61+
enlarged_size = random.randint(min_size, max_size)
62+
if len(packet) < enlarged_size:
63+
payload_size = enlarged_size-len(packet)
64+
return scapy.all.Raw(random.randbytes(payload_size))
5465

5566

5667
class TRILL(base_node):
5768
def __init__(self):
5869
super().__init__("TRILL")
5970

60-
def protocol_add(self, config):
71+
def protocol_add(self, config, packet):
6172
return trill.Trill(version=0, res=0)
6273

6374
def protocol_next(self, config):
@@ -71,7 +82,7 @@ class VXLAN(base_node):
7182
def __init__(self):
7283
super().__init__("VXLAN")
7384

74-
def protocol_add(self, config):
85+
def protocol_add(self, config, packet):
7586
return scapy.all.VXLAN()
7687

7788
def protocol_next(self, config):
@@ -91,7 +102,7 @@ class UDP(base_node):
91102
def __init__(self):
92103
super().__init__("UDP")
93104

94-
def protocol_add(self, config):
105+
def protocol_add(self, config, packet):
95106
return scapy.all.UDP()
96107

97108
def protocol_next(self, config):
@@ -110,7 +121,7 @@ class TCP(base_node):
110121
def __init__(self):
111122
super().__init__("TCP")
112123

113-
def protocol_add(self, config):
124+
def protocol_add(self, config, packet):
114125
return scapy.all.TCP()
115126

116127
def protocol_next(self, config):
@@ -125,7 +136,7 @@ class SCTP(base_node):
125136
def __init__(self):
126137
super().__init__("SCTP")
127138

128-
def protocol_add(self, config):
139+
def protocol_add(self, config, packet):
129140
return scapy.all.SCTP()
130141

131142
def protocol_next(self, config):
@@ -140,7 +151,7 @@ class GRE(base_node):
140151
def __init__(self):
141152
super().__init__("GRE")
142153

143-
def protocol_add(self, config):
154+
def protocol_add(self, config, packet):
144155
return scapy.all.GRE(routing_present=0)
145156

146157
def protocol_next(self, config):
@@ -163,7 +174,7 @@ class IPv4(base_node):
163174
def __init__(self):
164175
super().__init__("IPv4")
165176

166-
def protocol_add(self, config):
177+
def protocol_add(self, config, packet):
167178
src = None
168179
dst = None
169180

@@ -199,7 +210,7 @@ class IPv6Ext(base_node):
199210
def __init__(self):
200211
super().__init__("IPv6Ext")
201212

202-
def protocol_add(self, config):
213+
def protocol_add(self, config, packet):
203214
possible_protocols = [scapy.all.IPv6ExtHdrDestOpt(), scapy.all.IPv6ExtHdrFragment(id=random.randint(0, 2**32 - 1)), scapy.all.IPv6ExtHdrHopByHop(), scapy.all.IPv6ExtHdrRouting()]
204215
return random.choice(possible_protocols)
205216

@@ -224,7 +235,7 @@ class IPv6(base_node):
224235
def __init__(self):
225236
super().__init__("IPv6")
226237

227-
def protocol_add(self, config):
238+
def protocol_add(self, config, packet):
228239
src = None
229240
dst = None
230241

@@ -260,15 +271,15 @@ class ICMPv4(base_node):
260271
def __init__(self):
261272
super().__init__("ICMPv4")
262273

263-
def protocol_add(self, config):
274+
def protocol_add(self, config, packet):
264275
return scapy.all.ICMP()
265276

266277

267278
class ICMPv6(base_node):
268279
def __init__(self):
269280
super().__init__("ICMPv6")
270281

271-
def protocol_add(self, config):
282+
def protocol_add(self, config, packet):
272283
return scapy.all.ICMPv6Unknown()
273284

274285

@@ -280,7 +291,7 @@ class MPLS(base_node):
280291
def __init__(self):
281292
super().__init__("MPLS")
282293

283-
def protocol_add(self, config):
294+
def protocol_add(self, config, packet):
284295
return scapy.contrib.mpls.MPLS()
285296

286297
def protocol_next(self, config):
@@ -305,7 +316,7 @@ class PPP(base_node):
305316
def __init__(self):
306317
super().__init__("PPP")
307318

308-
def protocol_add(self, config):
319+
def protocol_add(self, config, packet):
309320
return scapy.all.PPPoE() / scapy.all.PPP()
310321

311322
def protocol_next(self, config):
@@ -321,7 +332,7 @@ class VLAN(base_node):
321332
def __init__(self):
322333
super().__init__("VLAN")
323334

324-
def protocol_add(self, config):
335+
def protocol_add(self, config, packet):
325336
possible_protocols = [scapy.all.Dot1Q(), scapy.all.Dot1AD()]
326337
return random.choice(possible_protocols)
327338

@@ -345,7 +356,7 @@ class ETH(base_node):
345356
def __init__(self):
346357
super().__init__("ETH")
347358

348-
def protocol_add(self, config):
359+
def protocol_add(self, config, packet):
349360
return scapy.all.Ether(src=scapy.volatile.RandMAC(), dst=scapy.volatile.RandMAC())
350361

351362
def protocol_next(self, config):

comp/uvm/packet_generators/search/parser_dfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def gen(self):
7474
packet = scapy.packet.Packet()
7575

7676
for it in next_items:
77-
pkt_proto = it.protocol.protocol_add(it.cfg)
77+
pkt_proto = it.protocol.protocol_add(it.cfg, packet)
7878
if pkt_proto is not None:
7979
packet = packet / pkt_proto
8080

comp/uvm/packet_generators/search/parser_rand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def gen(self):
2828
packet = scapy.packet.Packet()
2929

3030
while proto_act is not None:
31-
pkt_proto = proto_act.protocol_add(cfg)
31+
pkt_proto = proto_act.protocol_add(cfg, packet)
3232
if pkt_proto is not None:
3333
packet = packet / pkt_proto
3434
proto_next = proto_act.protocol_next(cfg)

comp/uvm/packet_generators/sequence_flowtest.sv

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ class sequence_flowtest #(int unsigned ITEM_WIDTH) extends uvm_common::sequence_
196196
std::randomize(mac[mac.size()-1].address);
197197
std::randomize(mac[mac.size()-1].mask) with { mac[mac.size()-1].mask <= 128;};
198198
end
199+
200+
// Set the packet sizes
201+
packet_size_min = cfg.array_size_min;
202+
packet_size_max = cfg.array_size_max;
199203
endfunction
200204

201205
function string get_ipv4_addresses();
@@ -277,13 +281,16 @@ class sequence_flowtest #(int unsigned ITEM_WIDTH) extends uvm_common::sequence_
277281
string ipv6_addresses = get_ipv6_addresses();
278282
string mac_addresses = get_mac_addresses();
279283

280-
config_generator_parameters = $sformatf("-o \"%s\" --seed %0d %s %s %s %s", // Creating string of the options
284+
config_generator_parameters = $sformatf("-o \"%s\" --seed %0d %s %s %s %s %s %s", // Creating string of the options
281285
config_filepath,
282286
seed,
283287
(config_generator_config_filepath != "") ? { "--config \"", config_generator_config_filepath, "\"" } : "",
284288
(ipv4_addresses != "") ? { "--ipv4 \"", ipv4_addresses, "\"" } : "",
285289
(ipv6_addresses != "") ? { "--ipv6 \"", ipv6_addresses, "\"" } : "",
286-
(mac_addresses != "") ? { "--mac \"", mac_addresses, "\"" } : "");
290+
(mac_addresses != "") ? { "--mac \"", mac_addresses, "\"" } : "",
291+
$sformatf("--packet-min-size %0d", packet_size_min),
292+
$sformatf("--packet-max-size %0d", packet_size_max)
293+
);
287294
config_generator_execute_command = { CONFIG_GENERATOR_EXECUTE_PATH, " ", config_generator_parameters }; // Creating string of the config generator call command
288295

289296
// Try generate config file

comp/uvm/packet_generators/sequence_search.sv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class sequence_search #(int unsigned ITEM_WIDTH) extends uvm_common::sequence_ba
1414
`uvm_object_param_utils(uvm_packet_generators::sequence_search#(ITEM_WIDTH))
1515

1616
int unsigned pkt_size_min = 60;
17-
int unsigned pkt_size_max = 0;
17+
int unsigned pkt_size_max = 1500;
1818
string config_json = "./filter.json";
1919
rand int unsigned transaction_count;
2020
rand int unsigned pkt_gen_seed;
@@ -158,7 +158,7 @@ class sequence_search #(int unsigned ITEM_WIDTH) extends uvm_common::sequence_ba
158158
end
159159
$fwrite(file, "{\n");
160160
//ETH
161-
$fwrite(file, "\"packet\" : { \"err_probability\" : %0d},\n", packet_err_prob);
161+
$fwrite(file, "\"packet\" : { \"err_probability\" : %0d, \"size_min\" : %0d, \"size_max\" : %0d},\n", packet_err_prob, pkt_size_min, pkt_size_max);
162162
$fwrite(file, "\"ETH\" : { \"weight\" : %s},\n", proto_dist_gen(eth_next_prot, {"IPv4", "IPv6", "VLAN", "TRILL", "MPLS", "Empty", "PPP"}));
163163
$fwrite(file, "\"VLAN\" : { \"weight\" : %s},\n", proto_dist_gen(vlan_next_prot, {"IPv4", "IPv6", "VLAN", "TRILL", "MPLS", "Empty", "PPP"}));
164164
$fwrite(file, "\"PPP\" : { \"weight\" : %s},\n", proto_dist_gen(ppp_next_prot, {"IPv4", "IPv6", "MPLS", "Empty"}));
@@ -252,7 +252,7 @@ class sequence_search #(int unsigned ITEM_WIDTH) extends uvm_common::sequence_ba
252252
if (data.size() < pkt_size_min) begin
253253
data = new[pkt_size_min](data);
254254
end
255-
if (pkt_size_max > 0 && data.size() > pkt_size_max) begin
255+
if (data.size() > pkt_size_max) begin
256256
data = new[pkt_size_max](data);
257257
end
258258
req.data = {>>{data}};

core/comp/app/app_uvm/env/sequence.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class sequence_main#(
5858
min_random_count = 50;
5959
max_random_count = 150;
6060
pkt_size_min = 60;
61-
pkt_size_max = 1500;
61+
pkt_size_max = DMA_PKT_MTU;
6262

6363
endfunction
6464

core/comp/app/app_uvm/env/sequence_eth.sv

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,16 @@ class sequence_flowtest_eth #(
301301
string ipv6_addresses = get_ipv6_addresses();
302302
string mac_addresses = get_mac_addresses();
303303

304-
config_generator_parameters = $sformatf("-o \"%s\" --seed %0d %s %s %s %s", // Creating string of the options
304+
config_generator_parameters = $sformatf("-o \"%s\" --seed %0d %s %s %s %s %s %s", // Creating string of the options
305305
config_filepath,
306306
seed,
307307
(config_generator_config_filepath != "") ? { "--config \"", config_generator_config_filepath, "\"" } : "",
308308
(ipv4_addresses != "") ? { "--ipv4 \"", ipv4_addresses, "\"" } : "",
309309
(ipv6_addresses != "") ? { "--ipv6 \"", ipv6_addresses, "\"" } : "",
310-
(mac_addresses != "") ? { "--mac \"", mac_addresses, "\"" } : "");
310+
(mac_addresses != "") ? { "--mac \"", mac_addresses, "\"" } : "",
311+
$sformatf("--packet-min-size %0d", cfg.array_size_min),
312+
$sformatf("--packet-max-size %0d", cfg.array_size_max)
313+
);
311314
config_generator_execute_command = { uvm_packet_generators::CONFIG_GENERATOR_EXECUTE_PATH, " ", config_generator_parameters }; // Creating string of the config generator call command
312315

313316
// Try generate config file
@@ -574,7 +577,7 @@ class sequence_search_eth #(
574577
end
575578
$fwrite(file, "{\n");
576579
//ETH
577-
$fwrite(file, "\"packet\" : { \"err_probability\" : %0d},\n", packet_err_prob);
580+
$fwrite(file, "\"packet\" : { \"err_probability\" : %0d, \"size_min\" : %0d, \"size_max\" : %0d},\n", packet_err_prob, cfg.array_size_min, cfg.array_size_max);
578581
$fwrite(file, "\"ETH\" : { \"weight\" : %s},\n", proto_dist_gen(eth_next_prot, {"IPv4", "IPv6", "VLAN", "TRILL", "MPLS", "Empty", "PPP"}));
579582
$fwrite(file, "\"VLAN\" : { \"weight\" : %s},\n", proto_dist_gen(vlan_next_prot, {"IPv4", "IPv6", "VLAN", "TRILL", "MPLS", "Empty", "PPP"}));
580583
$fwrite(file, "\"PPP\" : { \"weight\" : %s},\n", proto_dist_gen(ppp_next_prot, {"IPv4", "IPv6", "MPLS", "Empty"}));
@@ -687,7 +690,7 @@ class sequence_search_eth #(
687690
if (data.size() < cfg.array_size_min) begin
688691
data = new[cfg.array_size_min](data);
689692
end
690-
if (cfg.array_size_max > 0 && data.size() > cfg.array_size_max) begin
693+
if (data.size() > cfg.array_size_max) begin
691694
data = new[cfg.array_size_max](data);
692695
end
693696
req.data = {>>{data}};

0 commit comments

Comments
 (0)