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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # generate FE config script
20 import sys, optparse, math
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]"
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 " \
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"
46 def align_power_of_2(x):
47 return 2**(x-1).bit_length()
49 def print_stream(mode, la, ra, fwd_la, fwd_ra, lcore, belcore, lport,
52 lport_str = str(format(lport, '#x'))
53 fwrport_str = str(format(fwrport, '#x'))
55 lport_str = str(lport)
56 fwrport_str = str(fwrport)
58 stream = "lcore=" + str(lcore) + ",belcore=" + str(belcore) + ",op=" + mode
59 stream += ",laddr=" + la + ",lport=" + lport_str
60 stream += ",raddr=" + ra + ",rport=0"
63 stream += ",fwladdr=" + fwd_la + ",fwlport=0,fwraddr=" + fwd_ra
64 stream += ",fwrport=" + fwrport_str
66 if mode == 'rx' or mode == 'tx':
67 stream += ",txlen=" + str(txlen)
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",
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",
93 parser.add_option("-6", action = "store_true", dest = "ipv6",
95 parser.add_option("-H", action = "store_true", dest = "support_hex",
96 help = "print ports in hexa format")
98 (options, args) = parser.parse_args()
100 if len(sys.argv) == 1:
106 supported_modes = ['echo', 'rx', 'tx', 'fwd']
110 if options.ipv6 == True:
121 if options.support_hex == True:
124 if options.txlen != None:
125 txlen = options.txlen
127 if options.fe_lcore_list != None:
128 felcore_list = list(map(int, options.fe_lcore_list.split(",")))
133 if options.be_lcore_list != None:
134 belcore_list = list(map(int, options.be_lcore_list.split(",")))
137 print "default BE lcore list = [ 1 ]"
140 if options.mode != None:
142 if mode not in supported_modes:
143 print "Supported modes: " + str(supported_modes)
144 print "Provided mode \"" + mode + "\" is not supported. Terminating..."
147 print "default mode = echo"
150 if options.start_port != None:
151 start_port = int(options.start_port)
153 print "default start_port = 32768"
156 if options.number_of_streams != None:
157 number_of_streams = int(options.number_of_streams)
159 print "default number_of_streams = 1"
160 number_of_streams = 1
162 fwd_start_port = 53248
164 if options.local_address != None:
165 la = options.local_address
167 if options.remote_address != None:
168 ra = options.remote_address
170 if options.fwd_local_address != None:
171 fwd_la = options.fwd_local_address
173 if options.fwd_remote_address != None:
174 fwd_ra = options.fwd_remote_address
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))
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
185 nb_stream_per_flc = (number_of_streams / felcore_count) + 1
187 for i in range(start_port, start_port + number_of_streams):
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]
198 print_stream(mode, la, ra, fwd_la, fwd_ra, felcore, belcore, i,
199 fwd_start_port + k, txlen)