forked from tungstenfabric/tf-vrouter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConscript
424 lines (358 loc) · 13.8 KB
/
SConscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import subprocess
import sys
import os
import copy
import re
import platform
AddOption('--kernel-dir', dest='kernel-dir', action='store',
help='Linux kernel source directory for vrouter.ko')
AddOption('--dpdk-dir', dest='dpdk-dir', action='store',
help='third party dpdk built library')
AddOption('--dpdk-jobs', dest='dpdk-jobs', action='store', default=1, type=int,
help='Number of jobs passed to DPDK make command')
AddOption('--system-header-path', dest='system-header-path', action='store',
help='Linux kernel headers for applications')
AddOption('--add-opts', dest='add-opts', action='append',
help='Additional options for vrouter compilation')
env = DefaultEnvironment().Clone()
VRouterEnv = env
dpdk_exists = os.path.isdir('../third_party/dpdk')
# Get compile-time machine flags and define vrouter macros.
# Developers can check these compile-time flags to use
# specific CPU features.
compiler = env['CC']
if compiler == 'cl':
env.Append(CCFLAGS='/WX')
# get CPU flag for GCC
if compiler == 'gcc' or compiler == 'clang':
target = env.get('TARGET_MACHINE')
# specify gcc -march flag for x86_64
if target == 'x86_64':
cpu = env.get('CPU_TYPE')
if cpu == 'native':
env.Append(CCFLAGS='-march=' + 'native')
elif cpu == 'snb':
env.Append(CCFLAGS='-march=' + 'corei7-avx')
elif cpu == 'ivb':
env.Append(CCFLAGS='-march=' + 'core-avx-i')
elif cpu == 'hsw':
env.Append(CCFLAGS='-march=' + 'core-avx2')
flags = env['CCFLAGS']
proc = subprocess.Popen(
str(compiler) + ' ' + str(flags) +
' -dM -E - < /dev/null', stdout=subprocess.PIPE, shell=True)
autoflags, _ = proc.communicate()
if isinstance(autoflags, bytes):
autoflags = autoflags.decode()
if autoflags.find('__x86_64__') != -1:
env.Append(CCFLAGS='-D__VR_X86_64__')
if autoflags.find('__AVX2__') != -1:
env.Append(CCFLAGS='-D__VR_AVX2__')
if autoflags.find('__AVX__') != -1:
env.Append(CCFLAGS='-D__VR_AVX__')
if autoflags.find('__SSE__') != -1:
env.Append(CCFLAGS='-D__VR_SSE__')
if autoflags.find('__SSE2__') != -1:
env.Append(CCFLAGS='-D__VR_SSE2__')
if autoflags.find('__SSE3__') != -1:
env.Append(CCFLAGS='-D__VR_SSE3__')
if autoflags.find('__SSSE3__') != -1:
env.Append(CCFLAGS='-D__VR_SSSE3__')
if autoflags.find('__SSE4_1__') != -1:
env.Append(CCFLAGS='-D__VR_SSE4_1__')
if autoflags.find('__SSE4_2__') != -1:
env.Append(CCFLAGS='-D__VR_SSE4_2__')
if autoflags.find('__AES__') != -1:
env.Append(CCFLAGS='-D__VR_AES__')
if autoflags.find('__RDRND__') != -1:
env.Append(CCFLAGS='-D__VR_RDRND__')
if autoflags.find('__PCLMUL__') != -1:
env.Append(CCFLAGS='-D__VR_PCLMUL__')
# DPDK build configuration
DPDK_TARGET = 'x86_64-native-linuxapp-gcc'
DPDK_SRC_DIR = '#third_party/dpdk/'
DPDK_DST_DIR = env['TOP'] + '/vrouter/dpdk/' + DPDK_TARGET
DPDK_INC_DIR = DPDK_DST_DIR + '/include'
DPDK_LIB_DIR = DPDK_DST_DIR + '/lib'
THRD_PRT_DIR = '#third_party/'
ADDNL_OPTION = GetOption('add-opts')
# Save add-opts for nested SConscripts
env['ADD_OPTS'] = ADDNL_OPTION if ADDNL_OPTION else []
# Include paths
env.Replace(CPPPATH='#vrouter/include')
env.Append(CPPPATH=[env['TOP'] + '/vrouter/sandesh/gen-c'])
env.Append(CPPPATH=['#src/contrail-common'])
env.Append(CPPPATH=['#src/contrail-common/sandesh/library/c'])
# Make Sandesh quiet for production
if 'production' in env['OPT']:
DefaultEnvironment().Append(CPPDEFINES='-DSANDESH_QUIET')
vr_root = './'
makefile = vr_root + 'Makefile'
dp_dir = Dir(vr_root).srcnode().abspath + '/'
make_dir = dp_dir
def MakeTestCmdFn(self, env, test_name, test_list, deps):
sources = copy.copy(deps)
sources.append(test_name + '.c')
tgt = env.UnitTest(target=test_name, source=sources)
env.Alias('vrouter:' + test_name, tgt)
test_list.append(tgt)
return tgt
VRouterEnv.AddMethod(MakeTestCmdFn, 'MakeTestCmd')
def shellCommand(cmd):
""" Return the output of a shell command
This wrapper is required since check_output is not supported in
python 2.6
"""
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, _ = proc.communicate()
if isinstance(output, bytes):
output = output.decode()
return output.strip()
def genBuildVersion():
h_code = """
/*
* Autogenerated file. Do not edit
*/
#ifndef __VR_BUILDINFO_H__
#define __VR_BUILDINFO_H__
#define VROUTER_VERSIONID "%(build)s"
#endif /* __VR_BUILDINFO_H__ */
""" % {'build': env.GetBuildVersion()[1]}
with open(os.path.join(dp_dir, 'include/vr_buildinfo.h'), 'w') as c_file:
c_file.write(h_code)
if sys.platform.startswith('freebsd'):
make_dir = make_dir + '/freebsd'
env['ENV']['MAKEOBJDIR'] = make_dir
# XXX Temporary/transitional support for Ubuntu14.04.4 w/ kernel v4.*
#
# The logic here has to handle two different invocation models:
# default 'scons' build model; and build via packager.py build. The
# first is typical for unit-test builds.
#
# The second comes via:
# - common/debian/Makefile in contrail-packaging, which invokes:
# - debian/contrail/debian/rules.modules in contrail-packages
# This approach always uses --kernel-dir, which works for vrouter, but
# libdpdk still defaults to installed version and thus will fail.
#
default_kernel_ver = shellCommand("uname -r").strip()
kernel_build_dir = None
(PLATFORM, VERSION, EXTRA) = platform.linux_distribution()
if (PLATFORM.lower() == 'ubuntu' and VERSION.find('14.') == 0):
if re.search('^4\.', default_kernel_ver):
print("Warn: kernel version %s not supported for vrouter and dpdk" % default_kernel_ver)
kernel_build_dir = '/lib/modules/3.13.0-110-generic/build'
if os.path.isdir(kernel_build_dir):
default_kernel_ver = "3.13.0-110-generic"
print("info: libdpdk will be built against kernel version %s" % default_kernel_ver)
else:
print("*** Error: Cannot find kernel v3.13.0-110, build of vrouter will likely fail")
kernel_build_dir = '/lib/modules/%s/build' % default_kernel_ver
kernel_dir = GetOption('kernel-dir')
if kernel_dir:
kern_version = shellCommand('cat %s/include/config/kernel.release' % kernel_dir)
else:
kern_version = default_kernel_ver
if kernel_build_dir:
kernel_dir = kernel_build_dir
kern_version = kern_version.strip()
if sys.platform != 'darwin':
install_root = GetOption('install_root')
if install_root is None:
install_root = ''
src_root = install_root + '/usr/src/vrouter/'
env.Replace(SRC_INSTALL_TARGET=src_root)
env.Install(src_root, ['LICENSE', 'Makefile', 'GPL-2.0.txt'])
env.Alias('install', src_root)
buildinfo = env.GenerateBuildInfoCCode(
target=['vr_buildinfo.c'],
source=[], path=dp_dir + 'dp-core')
buildversion = genBuildVersion()
exports = ['VRouterEnv']
subdirs = [
'include',
'dp-core',
'sandesh',
'utils',
'host',
'linux',
'uvrouter',
]
skip_dpdk_build = False
link_dpdk = False
dpdk_dir = GetOption('dpdk-dir')
if dpdk_dir:
skip_dpdk_build = True
link_dpdk = True
DPDK_INC_DIR = dpdk_dir + '/include/dpdk'
DPDK_LIB_DIR = dpdk_dir + '/lib'
dpdk_lib = env.Command('dpdk_lib', None, 'echo "*** Skipping DPDK Build, using provided DPDK directory ***"')
if dpdk_exists and not GetOption('without-dpdk') and not skip_dpdk_build:
link_dpdk = True
dpdk_src_dir = Dir(DPDK_SRC_DIR).abspath
if ADDNL_OPTION and 'enableMellanox' in ADDNL_OPTION:
thrd_prt_dir = Dir(THRD_PRT_DIR).abspath
mlnx_patch_cmd = 'patch -N ' + dpdk_src_dir + '/config/common_base ' + thrd_prt_dir + '/dpdk_mlnx.patch'
os.system(mlnx_patch_cmd)
# Pass -g and -O flags if present to DPDK
DPDK_FLAGS = ' '.join(o for o in env['CCFLAGS'] if ('-g' in o or '-O' in o))
env.Append(CCFLAGS='-DPLATFORM_IS_DPDK')
# Make DPDK
dpdk_dst_dir = Dir(DPDK_DST_DIR).abspath
dpdk_jobs = GetOption('dpdk-jobs')
make_cmd = 'make' \
+ ' -j {}'.format(dpdk_jobs) \
+ ' -C {}'.format(dpdk_src_dir) \
+ ' EXTRA_CFLAGS="' + DPDK_FLAGS + '"' \
+ ' ARCH=x86_64' \
+ ' O={}'.format(dpdk_dst_dir) \
+ ' '
# If this var is set, then we need to pass it to make cmd for libdpdk
if kernel_build_dir:
print("info: Adjusting libdpdk build to use RTE_KERNELDIR=%s" % kernel_build_dir)
make_cmd += "RTE_KERNELDIR=%s " % kernel_build_dir
dpdk_lib = env.Command(
'dpdk_lib', None, make_cmd + 'config T=' + DPDK_TARGET +
' && ' + make_cmd +
' && cp ' + dpdk_src_dir + '/usertools/dpdk-devbind.py ' + Dir(env['TOP'] + '/vrouter/dpdk/').abspath)
if GetOption('clean'):
os.system(make_cmd + 'clean')
if link_dpdk:
env.Append(DPDK_TARGET = DPDK_TARGET)
subdirs.append('tests')
subdirs.append('dpdk')
exports.append('dpdk_lib')
rte_libs = [
'-lrte_ethdev',
'-lrte_mempool_ring',
'-lrte_bus_pci',
'-lrte_pci',
'-lrte_bus_vdev',
]
#
# DPDK libraries need to be linked as a whole archive, otherwise some
# callbacks and constructors will not be linked in. Also some of the
# libraries need to be linked as a group for the cross-reference resolving.
#
# That is why we pass DPDK libraries as flags to the linker.
#
# Order is important: from higher level to lower level
# The list is from the rte.app.mk file
DPDK_LIBS = [
'-Wl,--whole-archive',
'-lrte_distributor',
'-lrte_reorder',
'-lrte_kni',
'-lrte_pipeline',
'-lrte_table',
'-lrte_port',
'-lrte_timer',
'-lrte_hash',
'-lrte_net',
'-lrte_jobstats',
'-lrte_lpm',
'-lrte_power',
'-lrte_acl',
'-lrte_meter',
'-lrte_member',
'-lrte_sched',
'-lm',
'-lrt',
'-lrte_vhost',
'-lrte_cryptodev',
'-Wl,--start-group',
'-lrte_kvargs',
'-lrte_mbuf',
'-lrte_ip_frag',
rte_libs,
'-lrte_mempool',
'-lrte_stack',
'-lrte_ring',
'-lrte_eal',
'-lrte_cmdline',
'-lrte_cfgfile',
"-lrte_eventdev",
'-lrte_pmd_bond',
'-lrte_pmd_bnxt',
'-lrte_bus_vmbus',
'-lrte_pmd_ifc',
'-lrte_pmd_enic',
'-lrte_pmd_i40e',
'-lrte_pmd_ixgbe',
'-lrte_pmd_ice',
'-lrte_pmd_nfp',
'-lrte_pmd_e1000',
'-lrte_pmd_ring',
'-lrte_pmd_af_packet'
]
if env['OPT'] == 'coverage':
DPDK_LIBS.append('-lgcov')
if ADDNL_OPTION and 'enableMellanox' in ADDNL_OPTION:
DPDK_LIBS.append('-lrte_pmd_mlx5')
DPDK_LIBS.append('-libverbs')
DPDK_LIBS.append('-lmlx5')
if ADDNL_OPTION and 'enableN3K' in ADDNL_OPTION:
DPDK_LIBS += [
'-lrte_pmd_n3k',
]
env.Append(CCFLAGS = '-DVR_ENABLE_N3K')
DPDK_LIBS.append('-lrte_pmd_virtio')
DPDK_LIBS.append('-Wl,--end-group')
DPDK_LIBS.append('-Wl,--no-whole-archive')
DPDK_LIBS.append('-Wl,-lnuma')
env.Append(CPPPATH=DPDK_INC_DIR)
env.Append(LIBPATH=DPDK_LIB_DIR)
env.Append(DPDK_LINKFLAGS=DPDK_LIBS)
for sdir in subdirs:
env.SConscript(sdir + '/SConscript',
exports=exports,
variant_dir=env['TOP'] + '/vrouter/' + sdir,
duplicate=0)
make_cmd = 'cd ' + make_dir + ' && make'
if kernel_dir:
make_cmd += ' KERNELDIR=' + kernel_dir
make_cmd += ' SANDESH_HEADER_PATH=' + Dir(env['TOP'] + '/vrouter/').abspath
make_cmd += ' SANDESH_SRC_ROOT=' + '../build/kbuild/'
make_cmd += ' SANDESH_EXTRA_HEADER_PATH=' + Dir('#src/contrail-common/').abspath
vrouter_target = 'vrouter.ko'
if 'vrouter' in COMMAND_LINE_TARGETS:
BUILD_TARGETS.append('vrouter/uvrouter')
if dpdk_exists:
BUILD_TARGETS.append('vrouter/dpdk')
BUILD_TARGETS.append('vrouter/utils')
kern = env.Command(vrouter_target, None, make_cmd)
env.Default(kern)
env.AlwaysBuild(kern)
env.Requires(kern, ['#build/lib/cmocka.lib', '#build/include/cmocka.h'])
env.Depends(kern, buildinfo)
env.Depends(kern, buildversion)
env.Depends(kern, env.Install(
'#build/kbuild/sandesh/gen-c',
env['TOP'] + '/vrouter/sandesh/gen-c/vr_types.c'))
sandesh_lib = [
'protocol/thrift_binary_protocol.c',
'protocol/thrift_protocol.c',
'protocol/thrift_xml_protocol.c',
'sandesh.c',
'transport/thrift_fake_transport.c',
'transport/thrift_file_transport.c',
'transport/thrift_memory_buffer.c',
]
for src in sandesh_lib:
dirname = os.path.dirname(src)
env.Depends(
kern,
env.Install(
'#build/kbuild/sandesh/library/c/' + dirname,
env['TOP'] + '/tools/sandesh/library/c/' + src))
if GetOption('clean') and (not COMMAND_LINE_TARGETS or 'vrouter' in COMMAND_LINE_TARGETS):
os.system(make_cmd + ' clean')
libmod_dir = install_root
libmod_dir += '/lib/modules/%s/extra/net/vrouter' % kern_version
env.Alias('build-kmodule', env.Install(libmod_dir, kern))
# Local Variables:
# mode: python
# End: