+
+def check_udp_stream_configs(gen_config, expected):
+ """Verify that the range for each chain have adjacent UDP ports without holes between chains."""
+ config = gen_config.config
+ stream_configs = gen_config.devices[0].get_stream_configs()
+ for index in range(config['service_chain_count']):
+ stream_cfg = stream_configs[index]
+ assert stream_cfg['ip_src_addr'] == expected['ip_src_addr']
+ assert stream_cfg['ip_src_addr_max'] == expected['ip_src_addr_max']
+ assert stream_cfg['ip_dst_addr'] == expected['ip_dst_addr']
+ assert stream_cfg['ip_dst_addr_max'] == expected['ip_dst_addr_max']
+ assert stream_cfg['udp_src_port'] == expected['udp_src_port']
+ assert stream_cfg['udp_src_port_max'] == expected['udp_src_port_max']
+ assert stream_cfg['udp_src_count'] == expected['udp_src_count']
+ assert stream_cfg['udp_dst_port'] == expected['udp_dst_port']
+ assert stream_cfg['udp_dst_port_max'] == expected['udp_dst_port_max']
+ assert stream_cfg['udp_dst_count'] == expected['udp_dst_count']
+
+
+def _check_device_udp_flow_config(param, expected):
+ config = _get_dummy_tg_config('PVP', '1Mpps',
+ ip_src_static=param['ip_src_static'],
+ fc=param['flow_count'],
+ ip0=param['ip_src_addr'],
+ ip1=param['ip_dst_addr'],
+ src_udp=param['udp_src_port'],
+ dst_udp=param['udp_dst_port'])
+ gen_config = GeneratorConfig(config)
+ check_udp_stream_configs(gen_config, expected)
+
+
+def test_device_udp_flow_config():
+ param = {'ip_src_static': True,
+ 'ip_src_addr': '110.0.0.0/32',
+ 'ip_dst_addr': '120.0.0.0/32',
+ 'udp_src_port': 53,
+ 'udp_dst_port': 53,
+ 'flow_count': 2}
+ expected = {'ip_src_addr': '110.0.0.0',
+ 'ip_src_addr_max': '110.0.0.0',
+ 'ip_dst_addr': '120.0.0.0',
+ 'ip_dst_addr_max': '120.0.0.0',
+ 'udp_src_port': 53,
+ 'udp_src_port_max': 53,
+ 'udp_src_count': 1,
+ 'udp_dst_port': 53,
+ 'udp_dst_port_max': 53,
+ 'udp_dst_count': 1}
+ _check_device_udp_flow_config(param, expected)
+ # Overwrite the udp_src_port value to define a large range of ports
+ # instead of a single port, in order to check if the imposed
+ # flow count is respected. Notice that udp range >> flow count.
+ param['udp_src_port'] = [53, 1024]
+ param['flow_count'] = 10
+ expected['udp_src_port_max'] = 57
+ expected['udp_src_count'] = 5
+ _check_device_udp_flow_config(param, expected)
+ # Re affect the default udp_src_port values and
+ # overwrite the ip_dst_addr value to define a large range of addresses
+ # instead of a single one, in order to check if the imposed
+ # flow count is respected. Notice that the netmask allows a very larger
+ # range of possible addresses than the flow count value.
+ param['udp_src_port'] = 53
+ expected['udp_src_port_max'] = 53
+ expected['udp_src_count'] = 1
+ param['ip_src_static'] = False
+ param['ip_dst_addr'] = '120.0.0.0/24'
+ expected['ip_dst_addr'] = '120.0.0.0'
+ expected['ip_dst_addr_max'] = '120.0.0.4'
+ _check_device_udp_flow_config(param, expected)
+
+