VAT-to-PAPI: Fix HTTP/TCP tests
[csit.git] / resources / libraries / python / tcp.py
1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """TCP util library.
15 """
16
17 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
18 from resources.libraries.python.Constants import Constants
19
20
21 class TCPUtils(object):
22     """Implementation of the TCP utilities.
23     """
24     www_root_dir = '{rmt_fw_dir}/{wrk_www}'\
25         .format(rmt_fw_dir=Constants.REMOTE_FW_DIR,
26                 wrk_www=Constants.RESOURCES_TP_WRK_WWW)
27
28     def __init__(self):
29         pass
30
31     @classmethod
32     def start_vpp_http_server_params(cls, node, http_static_plugin,
33                                      prealloc_fifos, fifo_size,
34                                      private_segment_size):
35         """Start the test HTTP server internal application or
36            the HTTP static server plugin internal applicatoin on the given node.
37
38         http static server www-root <www-root-dir> prealloc-fifos <N>
39         fifo-size <size in kB>
40         private-segment-size <seg_size expressed as number + unit, e.g. 100m>
41                                 -- or --
42         test http server static prealloc-fifos <N> fifo-size <size in kB>
43         private-segment-size <seg_size expressed as number + unit, e.g. 100m>
44
45
46         Where N is the max number of connections you expect to handle at one
47         time and <size> should be small if you test for CPS and exchange few
48         bytes, say 4, if each connection just exchanges few packets. Or it
49         should be much larger, up to 1024/4096 (i.e. 1-4MB) if you have only
50         one connection and exchange a lot of packets, i.e., when you test for
51         RPS. If you need to allocate lots of FIFOs, so you test for CPS, make
52         private-segment-size something like 4g.
53
54         Example:
55
56         For CPS
57         http static server www-root <www-root-dir> prealloc-fifos 10000
58         fifo-size 64 private-segment-size 4000m
59
60         For RPS
61         test http server static prealloc-fifos 500000 fifo-size 4
62         private-segment-size 4000m
63
64         :param node: Node to start HTTP server on.
65         :param http_static_plugin: Run HTTP static server plugin
66         :param prealloc_fifos: Max number of connections you expect to handle at
67             one time.
68         :param fifo_size: FIFO size in kB.
69         :param private_segment_size: Private segment size. Number + unit.
70         :type node: dict
71         :type http_static_plugin: boolean
72         :type prealloc_fifos: str
73         :type fifo_size: str
74         :type private_segment_size: str
75         """
76         if http_static_plugin == True:
77             cmd='http static server www-root {www_root} '\
78                 'prealloc-fifos {prealloc_fifos} fifo-size {fifo_size}'\
79                 ' private-segment-size {pvt_seg_size}'\
80                 .format(www_root=cls.www_root_dir,
81                         prealloc_fifos=prealloc_fifos, fifo_size=fifo_size,
82                         pvt_seg_size=private_segment_size)
83         else:
84             cmd='test http server static prealloc-fifos {prealloc_fifos} '\
85                 'fifo-size {fifo_size} private-segment-size {pvt_seg_size}'\
86                 .format(prealloc_fifos=prealloc_fifos, fifo_size=fifo_size,
87                         pvt_seg_size=private_segment_size)
88         PapiSocketExecutor.run_cli_cmd(node, cmd)
89