dpdk/makefile: add librte_pmd_pcap support for unit tests
[tldk.git] / examples / udpfwd / gen_fe_cfg.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2016 Intel Corporation.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 #
17 # generate FE config script
18 #
19
20 import sys, optparse, math
21
22 def print_usage ():
23         print "Usage: " + sys.argv[0] + " [-f fe_lcore_list] [-b be_lcore_list]"
24         print "          [-p start_port] [-n number_of_streams]"
25         print "          [-m mode] [-q local_address] [-r remote_address]"
26         print "          [-s fwd_local_address] [-t fwd_remote_address]"
27         print "          [-l txlen] [-4/-6] [-H]"
28         print
29         print "Options"
30         print "   -f, --fe_lcore_list: list of lcores used for FE. Multiple " \
31                         "lcores are comma-separated, within double quote"
32         print "   -b, --be_lcore_list: list of lcores used for BE. Multiple " \
33                         "lcores are comma-separated, within double quote"
34         print "   -p, --start_port: starting UDP port number"
35         print "   -n, --number_of_streams: number of streams to be generated"
36         print "   -m, --mode: mode of the application. [echo, rx, tx, fwd]"
37         print "   -q, --local_address: local address of the stream"
38         print "   -r, --remote_address: remote address of the stream"
39         print "   -s, --fwd_local_address: forwarding local address of the stream"
40         print "   -t, --fwd_remote_address: forwarding remote address of the " \
41                         "stream"
42         print "   -l, --txlen: transmission length for rx/tx mode"
43         print "   -H: if port number to printed in hex format"
44         print "   -4/-6: if default ip addresses to be printed in ipv4/ipv6 format"
45
46 def align_power_of_2(x):
47         return 2**(x-1).bit_length()
48
49 def print_stream(mode, la, ra, fwd_la, fwd_ra, lcore, belcore, lport,
50                 fwrport, txlen):
51         if support_hex != 0:
52                 lport_str = str(format(lport, '#x'))
53                 fwrport_str = str(format(fwrport, '#x'))
54         else:
55                 lport_str = str(lport)
56                 fwrport_str = str(fwrport)
57
58         stream = "lcore=" + str(lcore) + ",belcore=" + str(belcore) + ",op=" + mode
59         stream += ",laddr=" + la + ",lport=" + lport_str
60         stream += ",raddr=" + ra + ",rport=0"
61
62         if mode == 'fwd':
63                 stream += ",fwladdr=" + fwd_la + ",fwlport=0,fwraddr=" + fwd_ra
64                 stream += ",fwrport=" + fwrport_str
65
66         if mode == 'rx' or mode == 'tx':
67                 stream += ",txlen=" + str(txlen)
68
69         print stream
70
71 parser = optparse.OptionParser()
72 parser.add_option("-b", "--be_lcore_list", dest = "be_lcore_list",
73         help = "BE lcore lists.")
74 parser.add_option("-f", "--fe_lcore_list", dest = "fe_lcore_list",
75         help = "FE lcore lists.")
76 parser.add_option("-p", "--start_port", dest = "start_port",
77         help = "start port.")
78 parser.add_option("-n", "--number_of_streams", dest = "number_of_streams",
79         help = "number of streams.")
80 parser.add_option("-m", "--mode", dest = "mode",
81         help = "mode (op, rx, tx, fwd).")
82 parser.add_option("-q", "--local_address", dest = "local_address",
83         help = "local_address.")
84 parser.add_option("-r", "--remote_address", dest = "remote_address",
85         help = "remote_address.")
86 parser.add_option("-s", "--fwd_local_address", dest = "fwd_local_address",
87         help = "fwd_local_address.")
88 parser.add_option("-t", "--fwd_remote_address", dest = "fwd_remote_address",
89         help = "fwd_remote_address.")
90 parser.add_option("-l", "--txlen", dest = "txlen", help = "txlen.")
91 parser.add_option("-4", action = "store_false", dest = "ipv6",
92         help = "IPv4/IPv6")
93 parser.add_option("-6", action = "store_true", dest = "ipv6",
94         help = "IPv4/IPv6")
95 parser.add_option("-H", action = "store_true", dest = "support_hex",
96         help = "print ports in hexa format")
97
98 (options, args) = parser.parse_args()
99
100 if len(sys.argv) == 1:
101         print
102         print_usage()
103         print
104         sys.exit()
105
106 supported_modes = ['echo', 'rx', 'tx', 'fwd']
107 support_hex = 0
108 txlen = 72
109
110 if options.ipv6 == True:
111         la = '::'
112         ra = '::'
113         fwd_la = '::'
114         fwd_ra = '::'
115 else:
116         la = '0.0.0.0'
117         ra = '0.0.0.0'
118         fwd_la = '0.0.0.0'
119         fwd_ra = '0.0.0.0'
120
121 if options.support_hex == True:
122         support_hex = 1
123
124 if options.txlen != None:
125         txlen = options.txlen
126
127 if options.fe_lcore_list != None:
128         felcore_list = list(map(int, options.fe_lcore_list.split(",")))
129         felcore_list.sort()
130 else:
131         felcore_list = []
132
133 if options.be_lcore_list != None:
134         belcore_list = list(map(int, options.be_lcore_list.split(",")))
135         belcore_list.sort()
136 else:
137         print "default BE lcore list = [ 1 ]"
138         belcore_list = [1]
139
140 if options.mode != None:
141         mode = options.mode
142         if mode not in supported_modes:
143                 print "Supported modes: " + str(supported_modes)
144                 print "Provided mode \"" + mode + "\" is not supported. Terminating..."
145                 sys.exit()
146 else:
147         print "default mode = echo"
148         mode = "echo"
149
150 if options.start_port != None:
151         start_port = int(options.start_port)
152 else:
153         print "default start_port = 32768"
154         start_port = 32768
155
156 if options.number_of_streams != None:
157         number_of_streams = int(options.number_of_streams)
158 else:
159         print "default number_of_streams = 1"
160         number_of_streams = 1
161
162 fwd_start_port = 53248
163
164 if options.local_address != None:
165         la = options.local_address
166
167 if options.remote_address != None:
168         ra = options.remote_address
169
170 if options.fwd_local_address != None:
171         fwd_la = options.fwd_local_address
172
173 if options.fwd_remote_address != None:
174         fwd_ra = options.fwd_remote_address
175
176 belcore_count = len(belcore_list)
177 align_belcore_count = align_power_of_2(belcore_count)
178 nb_bits = int(math.log(align_belcore_count, 2))
179
180 felcore_count = len(felcore_list)
181 if felcore_count != 0:
182         if number_of_streams % felcore_count == 0:
183                 nb_stream_per_flc = number_of_streams / felcore_count
184         else:
185                 nb_stream_per_flc = (number_of_streams / felcore_count) + 1
186
187 for i in range(start_port, start_port + number_of_streams):
188         k = i - start_port
189         align_belcore_count = align_power_of_2(belcore_count)
190         blc_indx = (i % align_belcore_count) % belcore_count
191         belcore = belcore_list[blc_indx]
192         if felcore_count != 0:
193                 flc_indx = k / nb_stream_per_flc
194                 felcore = felcore_list[flc_indx]
195         else:
196                 felcore = belcore
197
198         print_stream(mode, la, ra, fwd_la, fwd_ra, felcore, belcore, i,
199                 fwd_start_port + k, txlen)