ws_main.py revision df1d83a3
1#!/usr/bin/env python
2# encoding: utf-8
3#
4# Hanoh Haim
5# Cisco Systems, Inc.
6
7VERSION='0.0.1'
8APPNAME='cxx_test'
9import os;
10import shutil;
11import copy;
12import re
13import uuid
14import subprocess
15import platform
16from waflib import Logs
17from waflib.Configure import conf
18from waflib import Build
19
20# use hostname as part of cache filename
21Build.CACHE_SUFFIX = '_%s_cache.py' % platform.node()
22
23# these variables are mandatory ('/' are converted automatically)
24top = '../'
25out = 'build_dpdk'
26
27
28b_path ="./build/linux_dpdk/"
29
30C_VER_FILE      = "version.c"
31H_VER_FILE      = "version.h"
32
33BUILD_NUM_FILE  = "../VERSION"
34USERS_ALLOWED_TO_RELEASE = ['hhaim']
35
36
37#######################################
38# utility for group source code
39###################################
40
41orig_system = os.system
42
43def verify_system(cmd):
44    ret = orig_system(cmd)
45    if ret:
46        raise Exception('Return code %s on command: system("%s")' % (ret, cmd))
47
48os.system = verify_system
49
50
51class SrcGroup:
52    ' group of source by directory '
53
54    def __init__(self,dir,src_list):
55      self.dir = dir;
56      self.src_list = src_list;
57      self.group_list = None;
58      assert (type(src_list)==list)
59      assert (type(dir)==str)
60
61
62
63    def file_list (self,top):
64        ' return  the long list of the files '
65        res=''
66        for file in self.src_list:
67            res= res + top+'/'+self.dir+'/'+file+'  ';
68
69        return res;
70
71    def __str__ (self):
72        return (self.file_list(''));
73
74    def __repr__ (self):
75        return (self.file_list(''));
76
77
78
79class SrcGroups:
80    ' group of source groups '
81
82    def __init__(self,list_group):
83      self.list_group = list_group;
84      assert (type(list_group)==list)
85
86
87    def file_list (self,top):
88          ' return  the long list of the files '
89          res=''
90          for o in self.list_group:
91              res += o.file_list(top);
92          return res;
93
94    def __str__ (self):
95          return (self.file_list(''));
96
97    def __repr__ (self):
98          return (self.file_list(''));
99
100
101def options(opt):
102    opt.load('compiler_cxx')
103    opt.load('compiler_c')
104    opt.add_option('--pkg-dir', '--pkg_dir', dest='pkg_dir', default=False, action='store', help="Destination folder for 'pkg' option.")
105    opt.add_option('--pkg-file', '--pkg_file', dest='pkg_file', default=False, action='store', help="Destination filename for 'pkg' option.")
106    opt.add_option('--publish-commit', '--publish_commit', dest='publish_commit', default=False, action='store', help="Specify commit id for 'publish_both' option (Please make sure it's good!)")
107
108
109def check_ibverbs_deps(bld):
110    if 'LDD' not in bld.env or not len(bld.env['LDD']):
111        bld.fatal('Please run configure. Missing key LDD.')
112    cmd = '%s %s/external_libs/ibverbs/libibverbs.so' % (bld.env['LDD'][0], top)
113    ret, out = getstatusoutput(cmd)
114    if ret or not out:
115        bld.fatal("Command of checking libraries '%s' failed.\nReturn status: %s\nOutput: %s" % (cmd, ret, out))
116    if '=> not found' in out:
117        Logs.pprint('YELLOW', 'Could not find dependency libraries of libibverbs.so:')
118        for line in out.splitlines():
119            if '=> not found' in line:
120                Logs.pprint('YELLOW', line)
121        dumy_libs_path = os.path.abspath(top + 'scripts/dumy_libs')
122        Logs.pprint('YELLOW', 'Adding rpath of %s' % dumy_libs_path)
123        rpath_linkage.append(dumy_libs_path)
124
125
126def missing_pkg_msg(fedora, ubuntu):
127    msg = 'not found\n'
128    fedora_install = 'Fedora install:\nsudo yum install %s\n' % fedora
129    ubuntu_install = 'Ubuntu install:\nsudo apt install %s\n' % ubuntu
130    try:
131        if platform.linux_distribution()[0].capitalize() == 'Ubuntu':
132            msg += ubuntu_install
133        elif platform.linux_distribution()[0].capitalize() == 'Fedora':
134            msg += fedora_install
135        else:
136            raise
137    except:
138        msg += 'Could not determine Linux distribution.\n%s\n%s' % (ubuntu_install, fedora_install)
139    return msg
140
141
142@conf
143def check_ofed(ctx):
144    ctx.start_msg('Checking for OFED')
145    ofed_info='/usr/bin/ofed_info'
146    ofed_ver= '-3.4-'
147    ofed_ver_show= 'v3.4'
148
149    if not os.path.isfile(ofed_info):
150        ctx.end_msg('not found', 'YELLOW')
151        return False
152
153    ret, out = getstatusoutput(ofed_info)
154    if ret:
155        ctx.end_msg("Can't run %s to verify version:\n%s" % (ofed_info, out), 'YELLOW')
156        return False
157
158    lines = out.splitlines()
159    if len(lines) < 2:
160        ctx.end_msg('Expected several output lines from %s, got:\n%s' % (ofed_info, out), 'YELLOW')
161        return False
162
163    if ofed_ver not in lines[0]:
164        ctx.end_msg('Expected version: %s, got: %s.' % (ofed_ver, lines[0]), 'YELLOW')
165        return False
166
167    ctx.end_msg('Found needed version %s' % ofed_ver_show)
168    return True
169
170
171def configure(conf):
172    conf.load('g++')
173    conf.load('gcc')
174    conf.find_program('ldd')
175    conf.check_cxx(lib = 'z', errmsg = missing_pkg_msg(fedora = 'zlib-devel', ubuntu = 'zlib1g-dev'))
176    ofed_ok = conf.check_ofed(mandatory = False)
177    if ofed_ok:
178        conf.check_cxx(lib = 'ibverbs', errmsg = 'Could not find library ibverbs, will use internal version.', mandatory = False)
179    else:
180        Logs.pprint('YELLOW', 'Warning: will use internal version of ibverbs. If you need to use Mellanox NICs, install OFED:\n' +
181                              'https://trex-tgn.cisco.com/trex/doc/trex_manual.html#_mellanox_connectx_4_support')
182
183
184def getstatusoutput(cmd):
185    """    Return (status, output) of executing cmd in a shell. Taken from Python3 subprocess.getstatusoutput"""
186    try:
187        data = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
188        status = 0
189    except subprocess.CalledProcessError as ex:
190        data = ex.output
191        status = ex.returncode
192    if data[-1:] == '\n':
193        data = data[:-1]
194    return status, data
195
196main_src = SrcGroup(dir='src',
197        src_list=[
198             'bp_sim.cpp',
199             'utl_term_io.cpp',
200             'global_io_mode.cpp',
201             'main_dpdk.cpp',
202             'trex_watchdog.cpp',
203             'trex_client_config.cpp',
204             'debug.cpp',
205             'flow_stat.cpp',
206             'flow_stat_parser.cpp',
207             'inet_pton.cpp',
208             'pkt_gen.cpp',
209             'tw_cfg.cpp',
210             'platform_cfg.cpp',
211             'pre_test.cpp',
212             'tuple_gen.cpp',
213             'rx_check.cpp',
214             'rx_check_header.cpp',
215             'stateful_rx_core.cpp',
216             'timer_wheel_pq.cpp',
217             'time_histogram.cpp',
218             'os_time.cpp',
219             'utl_cpuu.cpp',
220             'utl_ip.cpp',
221             'utl_json.cpp',
222             'utl_yaml.cpp',
223             'nat_check.cpp',
224             'nat_check_flow_table.cpp',
225             'msg_manager.cpp',
226             'trex_port_attr.cpp',
227             'publisher/trex_publisher.cpp',
228             'pal/linux_dpdk/pal_utl.cpp',
229             'pal/linux_dpdk/mbuf.cpp',
230             'pal/common/common_mbuf.cpp',
231             'h_timer.cpp'
232
233             ]);
234
235cmn_src = SrcGroup(dir='src/common',
236    src_list=[
237        'basic_utils.cpp',
238        'captureFile.cpp',
239        'erf.cpp',
240        'pcap.cpp',
241        'base64.cpp'
242        ]);
243
244net_src = SrcGroup(dir='src/common/Network/Packet',
245        src_list=[
246           'CPktCmn.cpp',
247           'EthernetHeader.cpp',
248           'IPHeader.cpp',
249           'IPv6Header.cpp',
250           'TCPHeader.cpp',
251           'TCPOptions.cpp',
252           'UDPHeader.cpp',
253           'MacAddress.cpp',
254           'VLANHeader.cpp']);
255
256# JSON package
257json_src = SrcGroup(dir='external_libs/json',
258        src_list=[
259            'jsoncpp.cpp'
260           ])
261
262# RPC code
263rpc_server_src = SrcGroup(dir='src/rpc-server/',
264                          src_list=[
265                              'trex_rpc_server.cpp',
266                              'trex_rpc_req_resp_server.cpp',
267                              'trex_rpc_async_server.cpp',
268                              'trex_rpc_jsonrpc_v2_parser.cpp',
269                              'trex_rpc_cmds_table.cpp',
270                              'trex_rpc_cmd.cpp',
271                              'trex_rpc_zip.cpp',
272
273                              'commands/trex_rpc_cmd_test.cpp',
274                              'commands/trex_rpc_cmd_general.cpp',
275                              'commands/trex_rpc_cmd_stream.cpp',
276
277                          ])
278
279
280ef_src = SrcGroup(dir='src/common',
281    src_list=[
282        'ef/efence.cpp',
283        'ef/page.cpp',
284        'ef/print.cpp'
285        ]);
286
287
288# stateless code
289stateless_src = SrcGroup(dir='src/stateless/',
290                          src_list=['cp/trex_stream.cpp',
291                                    'cp/trex_stream_vm.cpp',
292                                    'cp/trex_stateless.cpp',
293                                    'cp/trex_stateless_port.cpp',
294                                    'cp/trex_streams_compiler.cpp',
295                                    'cp/trex_vm_splitter.cpp',
296                                    'cp/trex_dp_port_events.cpp',
297                                    'dp/trex_stateless_dp_core.cpp',
298                                    'messaging/trex_stateless_messaging.cpp',
299                                    'rx/trex_stateless_rx_core.cpp',
300                                    'rx/trex_stateless_rx_port_mngr.cpp',
301                                    'rx/trex_stateless_capture.cpp',
302                                    'common/trex_stateless_pkt.cpp',
303                                    ])
304# JSON package
305json_src = SrcGroup(dir='external_libs/json',
306                    src_list=[
307                        'jsoncpp.cpp'
308                        ])
309
310yaml_src = SrcGroup(dir='external_libs/yaml-cpp/src/',
311        src_list=[
312            'aliasmanager.cpp',
313            'binary.cpp',
314            'contrib/graphbuilder.cpp',
315            'contrib/graphbuilderadapter.cpp',
316            'conversion.cpp',
317            'directives.cpp',
318            'emitfromevents.cpp',
319            'emitter.cpp',
320            'emitterstate.cpp',
321            'emitterutils.cpp',
322            'exp.cpp',
323            'iterator.cpp',
324            'node.cpp',
325            'nodebuilder.cpp',
326            'nodeownership.cpp',
327            'null.cpp',
328            'ostream.cpp',
329            'parser.cpp',
330            'regex.cpp',
331            'scanner.cpp',
332            'scanscalar.cpp',
333            'scantag.cpp',
334            'scantoken.cpp',
335            'simplekey.cpp',
336            'singledocparser.cpp',
337            'stream.cpp',
338            'tag.cpp']);
339
340
341version_src = SrcGroup(
342    dir='linux_dpdk',
343    src_list=[
344        'version.c',
345    ])
346
347
348dpdk_src = SrcGroup(dir='src/dpdk/',
349                src_list=[
350                 '../dpdk_funcs.c',
351                 'drivers/net/af_packet/rte_eth_af_packet.c',
352                 'drivers/net/cxgbe/base/t4_hw.c',
353                 'drivers/net/cxgbe/cxgbe_ethdev.c',
354                 'drivers/net/cxgbe/cxgbe_main.c',
355                 'drivers/net/cxgbe/sge.c',
356                 'drivers/net/e1000/base/e1000_80003es2lan.c',
357                 'drivers/net/e1000/base/e1000_82540.c',
358                 'drivers/net/e1000/base/e1000_82541.c',
359                 'drivers/net/e1000/base/e1000_82542.c',
360                 'drivers/net/e1000/base/e1000_82543.c',
361                 'drivers/net/e1000/base/e1000_82571.c',
362                 'drivers/net/e1000/base/e1000_82575.c',
363                 'drivers/net/e1000/base/e1000_api.c',
364                 'drivers/net/e1000/base/e1000_i210.c',
365                 'drivers/net/e1000/base/e1000_ich8lan.c',
366                 'drivers/net/e1000/base/e1000_mac.c',
367                 'drivers/net/e1000/base/e1000_manage.c',
368                 'drivers/net/e1000/base/e1000_mbx.c',
369                 'drivers/net/e1000/base/e1000_nvm.c',
370                 'drivers/net/e1000/base/e1000_osdep.c',
371                 'drivers/net/e1000/base/e1000_phy.c',
372                 'drivers/net/e1000/base/e1000_vf.c',
373                 'drivers/net/e1000/em_ethdev.c',
374                 'drivers/net/e1000/em_rxtx.c',
375                 'drivers/net/e1000/igb_ethdev.c',
376                 'drivers/net/e1000/igb_pf.c',
377                 'drivers/net/e1000/igb_rxtx.c',
378                 'drivers/net/enic/base/vnic_cq.c',
379                 'drivers/net/enic/base/vnic_dev.c',
380                 'drivers/net/enic/base/vnic_intr.c',
381                 'drivers/net/enic/base/vnic_rq.c',
382                 'drivers/net/enic/base/vnic_rss.c',
383                 'drivers/net/enic/base/vnic_wq.c',
384                 'drivers/net/enic/enic_clsf.c',
385                 'drivers/net/enic/enic_ethdev.c',
386                 'drivers/net/enic/enic_main.c',
387                 'drivers/net/enic/enic_res.c',
388                 'drivers/net/enic/enic_rxtx.c',
389                 'drivers/net/fm10k/base/fm10k_api.c',
390                 'drivers/net/fm10k/base/fm10k_common.c',
391                 'drivers/net/fm10k/base/fm10k_mbx.c',
392                 'drivers/net/fm10k/base/fm10k_pf.c',
393                 'drivers/net/fm10k/base/fm10k_tlv.c',
394                 'drivers/net/fm10k/base/fm10k_vf.c',
395                 'drivers/net/fm10k/fm10k_ethdev.c',
396                 'drivers/net/fm10k/fm10k_rxtx.c',
397                 'drivers/net/fm10k/fm10k_rxtx_vec.c',
398                 'drivers/net/ixgbe/base/ixgbe_82598.c',
399                 'drivers/net/ixgbe/base/ixgbe_82599.c',
400                 'drivers/net/ixgbe/base/ixgbe_api.c',
401                 'drivers/net/ixgbe/base/ixgbe_common.c',
402                 'drivers/net/ixgbe/base/ixgbe_dcb.c',
403                 'drivers/net/ixgbe/base/ixgbe_dcb_82598.c',
404                 'drivers/net/ixgbe/base/ixgbe_dcb_82599.c',
405                 'drivers/net/ixgbe/base/ixgbe_hv_vf.c',
406                 'drivers/net/ixgbe/base/ixgbe_mbx.c',
407                 'drivers/net/ixgbe/base/ixgbe_phy.c',
408                 'drivers/net/ixgbe/base/ixgbe_vf.c',
409                 'drivers/net/ixgbe/base/ixgbe_x540.c',
410                 'drivers/net/ixgbe/base/ixgbe_x550.c',
411                 'drivers/net/ixgbe/ixgbe_ethdev.c',
412                 'drivers/net/ixgbe/ixgbe_fdir.c',
413                 'drivers/net/ixgbe/ixgbe_flow.c',
414                 'drivers/net/ixgbe/ixgbe_pf.c',
415                 'drivers/net/ixgbe/ixgbe_rxtx.c',
416                 'drivers/net/ixgbe/ixgbe_rxtx_vec_sse.c',
417
418                 'drivers/net/i40e/base/i40e_adminq.c',
419                 'drivers/net/i40e/base/i40e_common.c',
420                 'drivers/net/i40e/base/i40e_dcb.c',
421                 'drivers/net/i40e/base/i40e_diag.c',
422                 'drivers/net/i40e/base/i40e_hmc.c',
423                 'drivers/net/i40e/base/i40e_lan_hmc.c',
424                 'drivers/net/i40e/base/i40e_nvm.c',
425                 'drivers/net/i40e/i40e_ethdev_vf.c',
426                 'drivers/net/i40e/i40e_pf.c',
427                 'drivers/net/i40e/i40e_rxtx.c',
428                 'drivers/net/i40e/i40e_flow.c',
429                 'drivers/net/i40e/i40e_rxtx_vec_sse.c',
430                 'drivers/net/i40e/i40e_fdir.c',
431                 'drivers/net/i40e/i40e_ethdev.c',
432                 'drivers/net/null/rte_eth_null.c',
433                 'drivers/net/ring/rte_eth_ring.c',
434                 'drivers/net/virtio/virtio_ethdev.c',
435                 'drivers/net/virtio/virtio_pci.c',
436                 'drivers/net/virtio/virtio_rxtx.c',
437                 'drivers/net/virtio/virtio_rxtx_simple.c',
438                 'drivers/net/virtio/virtqueue.c',
439                 'drivers/net/virtio/virtio_rxtx_simple_sse.c',
440                 'drivers/net/virtio/virtio_user_ethdev.c',
441                 'drivers/net/virtio/virtio_user/vhost_kernel.c',
442                 'drivers/net/virtio/virtio_user/vhost_kernel_tap.c',
443                 'drivers/net/virtio/virtio_user/vhost_user.c',
444                 'drivers/net/virtio/virtio_user/virtio_user_dev.c',
445                 'drivers/net/vmxnet3/vmxnet3_ethdev.c',
446                 'drivers/net/vmxnet3/vmxnet3_rxtx.c',
447                 'lib/librte_cfgfile/rte_cfgfile.c',
448                 'lib/librte_eal/common/arch/x86/rte_cpuflags.c',
449                 'lib/librte_eal/common/arch/x86/rte_spinlock.c',
450                 'lib/librte_eal/common/eal_common_bus.c',
451                 'lib/librte_eal/common/eal_common_cpuflags.c',
452                 'lib/librte_eal/common/eal_common_dev.c',
453                 'lib/librte_eal/common/eal_common_devargs.c',
454                 'lib/librte_eal/common/eal_common_errno.c',
455                 'lib/librte_eal/common/eal_common_hexdump.c',
456                 'lib/librte_eal/common/eal_common_launch.c',
457                 'lib/librte_eal/common/eal_common_lcore.c',
458                 'lib/librte_eal/common/eal_common_log.c',
459                 'lib/librte_eal/common/eal_common_memory.c',
460                 'lib/librte_eal/common/eal_common_memzone.c',
461                 'lib/librte_eal/common/eal_common_options.c',
462                 'lib/librte_eal/common/eal_common_pci.c',
463                 'lib/librte_eal/common/eal_common_pci_uio.c',
464                 'lib/librte_eal/common/eal_common_string_fns.c',
465                 'lib/librte_eal/common/eal_common_tailqs.c',
466                 'lib/librte_eal/common/eal_common_thread.c',
467                 'lib/librte_eal/common/eal_common_timer.c',
468                 'lib/librte_eal/common/eal_common_vdev.c',
469                 'lib/librte_eal/common/malloc_elem.c',
470                 'lib/librte_eal/common/malloc_heap.c',
471                 'lib/librte_eal/common/rte_keepalive.c',
472                 'lib/librte_eal/common/rte_malloc.c',
473                 'lib/librte_eal/linuxapp/eal/eal.c',
474                 'lib/librte_eal/linuxapp/eal/eal_alarm.c',
475                 'lib/librte_eal/linuxapp/eal/eal_debug.c',
476                 'lib/librte_eal/linuxapp/eal/eal_hugepage_info.c',
477                 'lib/librte_eal/linuxapp/eal/eal_interrupts.c',
478                 'lib/librte_eal/linuxapp/eal/eal_lcore.c',
479                 'lib/librte_eal/linuxapp/eal/eal_log.c',
480                 'lib/librte_eal/linuxapp/eal/eal_memory.c',
481                 'lib/librte_eal/linuxapp/eal/eal_pci.c',
482                 'lib/librte_eal/linuxapp/eal/eal_pci_uio.c',
483                 'lib/librte_eal/linuxapp/eal/eal_pci_vfio.c',
484                 'lib/librte_eal/linuxapp/eal/eal_thread.c',
485                 'lib/librte_eal/linuxapp/eal/eal_timer.c',
486                 'lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c',
487                 'lib/librte_eal/linuxapp/eal/eal_vfio.c',
488                 'lib/librte_ether/rte_ethdev.c',
489                 'lib/librte_ether/rte_flow.c',
490                 'lib/librte_hash/rte_cuckoo_hash.c',
491                 'lib/librte_kvargs/rte_kvargs.c',
492                 'lib/librte_mbuf/rte_mbuf.c',
493                 'lib/librte_mbuf/rte_mbuf_ptype.c',
494                 'lib/librte_mempool/rte_mempool.c',
495                 'lib/librte_mempool/rte_mempool_ops.c',
496                 'lib/librte_mempool/rte_mempool_ring.c',
497                 'lib/librte_net/rte_net.c',
498                 'lib/librte_pipeline/rte_pipeline.c',
499                 'lib/librte_ring/rte_ring.c',
500            ]);
501
502mlx5_dpdk_src = SrcGroup(dir='src/dpdk/',
503                src_list=[
504
505                 'drivers/net/mlx5/mlx5_mr.c',
506                 'drivers/net/mlx5/mlx5_ethdev.c',
507                 'drivers/net/mlx5/mlx5_mac.c',
508                 'drivers/net/mlx5/mlx5_rxmode.c',
509                 'drivers/net/mlx5/mlx5_rxtx.c',
510                 'drivers/net/mlx5/mlx5_stats.c',
511                 'drivers/net/mlx5/mlx5_txq.c',
512                 'drivers/net/mlx5/mlx5.c',
513                 'drivers/net/mlx5/mlx5_fdir.c',
514                 'drivers/net/mlx5/mlx5_flow.c',
515                 'drivers/net/mlx5/mlx5_rss.c',
516                 'drivers/net/mlx5/mlx5_rxq.c',
517                 'drivers/net/mlx5/mlx5_trigger.c',
518                 'drivers/net/mlx5/mlx5_vlan.c',
519            ]);
520
521bp_dpdk =SrcGroups([
522                dpdk_src
523                ]);
524
525mlx5_dpdk =SrcGroups([
526                mlx5_dpdk_src
527                ]);
528
529
530# this is the library dp going to falcon (and maybe other platforms)
531bp =SrcGroups([
532                main_src,
533                cmn_src ,
534                net_src ,
535                yaml_src,
536                rpc_server_src,
537                json_src,
538                stateless_src,
539                version_src
540                ]);
541
542l2fwd_main_src = SrcGroup(dir='src',
543        src_list=[
544             'l2fwd/main.c'
545             ]);
546
547
548l2fwd =SrcGroups([
549                l2fwd_main_src]);
550
551
552# common flags for both new and old configurations
553common_flags = ['-DWIN_UCODE_SIM',
554                '-D_BYTE_ORDER',
555                '-D_LITTLE_ENDIAN',
556                '-DLINUX',
557                '-g',
558                '-Wno-format',
559                '-Wno-deprecated-declarations',
560                '-DRTE_DPDK',
561                '-D__STDC_LIMIT_MACROS',
562                '-D__STDC_FORMAT_MACROS',
563                '-include','../src/pal/linux_dpdk/dpdk1702/rte_config.h'
564               ]
565
566common_flags_new = common_flags + [
567                    '-march=native',
568                    '-DRTE_MACHINE_CPUFLAG_SSE',
569                    '-DRTE_MACHINE_CPUFLAG_SSE2',
570                    '-DRTE_MACHINE_CPUFLAG_SSE3',
571                    '-DRTE_MACHINE_CPUFLAG_SSSE3',
572                    '-DRTE_MACHINE_CPUFLAG_SSE4_1',
573                    '-DRTE_MACHINE_CPUFLAG_SSE4_2',
574                    '-DRTE_MACHINE_CPUFLAG_AES',
575                    '-DRTE_MACHINE_CPUFLAG_PCLMULQDQ',
576                    '-DRTE_MACHINE_CPUFLAG_AVX',
577                    '-DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE3,RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSSE3,RTE_CPUFLAG_SSE4_1,RTE_CPUFLAG_SSE4_2,RTE_CPUFLAG_AES,RTE_CPUFLAG_PCLMULQDQ,RTE_CPUFLAG_AVX',
578                   ]
579
580common_flags_old = common_flags + [
581                      '-march=corei7',
582                      '-DUCS_210',
583                      '-mtune=generic',
584                      '-DRTE_MACHINE_CPUFLAG_SSE',
585                      '-DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE',
586                      ];
587
588
589
590
591includes_path =''' ../src/pal/linux_dpdk/
592                   ../src/pal/linux_dpdk/dpdk1702/
593                   ../src/pal/common/
594                   ../src/
595
596                   ../src/rpc-server/
597                   ../src/stateless/cp/
598                   ../src/stateless/dp/
599                   ../src/stateless/rx/
600                   ../src/stateless/common/
601                   ../src/stateless/messaging/
602
603                   ../external_libs/yaml-cpp/include/
604                   ../external_libs/zmq/include/
605                   ../external_libs/json/
606
607../src/dpdk/drivers/net/af_packet/
608../src/dpdk/drivers/net/bnx2x/
609../src/dpdk/drivers/net/bonding/
610../src/dpdk/drivers/net/cxgbe/
611../src/dpdk/drivers/net/cxgbe/base/
612../src/dpdk/drivers/net/e1000/
613../src/dpdk/drivers/net/e1000/base/
614../src/dpdk/drivers/net/fm10k/
615../src/dpdk/drivers/net/fm10k/base/
616../src/dpdk/drivers/net/i40e/
617../src/dpdk/drivers/net/i40e/base/
618../src/dpdk/drivers/net/ixgbe/
619../src/dpdk/drivers/net/ixgbe/base/
620../src/dpdk/drivers/net/mlx4/
621../src/dpdk/drivers/net/mlx5/
622../src/dpdk/drivers/net/mpipe/
623../src/dpdk/drivers/net/null/
624../src/dpdk/drivers/net/pcap/
625../src/dpdk/drivers/net/ring/
626../src/dpdk/drivers/net/szedata2/
627../src/dpdk/drivers/net/virtio/
628../src/dpdk/drivers/net/xenvirt/
629../src/dpdk/lib/librte_acl/
630../src/dpdk/lib/librte_cfgfile/
631../src/dpdk/lib/librte_compat/
632../src/dpdk/lib/librte_distributor/
633../src/dpdk/lib/librte_eal/
634../src/dpdk/lib/librte_eal/common/
635../src/dpdk/lib/librte_eal/common/include/
636../src/dpdk/lib/librte_eal/common/include/arch/
637../src/dpdk/lib/librte_eal/common/include/arch/x86/
638../src/dpdk/lib/librte_eal/common/include/generic/
639../src/dpdk/lib/librte_eal/linuxapp/
640../src/dpdk/lib/librte_eal/linuxapp/eal/
641../src/dpdk/lib/librte_eal/linuxapp/eal/include/
642../src/dpdk/lib/librte_eal/linuxapp/eal/include/exec-env/
643../src/dpdk/lib/librte_eal/linuxapp/igb_uio/
644../src/dpdk/lib/librte_eal/linuxapp/xen_dom0/
645../src/dpdk/lib/librte_ether/
646../src/dpdk/lib/librte_hash/
647../src/dpdk/lib/librte_kvargs/
648../src/dpdk/lib/librte_mbuf/
649../src/dpdk/lib/librte_mempool/
650../src/dpdk/lib/librte_net/
651../src/dpdk/lib/librte_pipeline/
652../src/dpdk/lib/librte_ring/
653              ''';
654
655
656dpdk_includes_verb_path =''
657
658dpdk_includes_path =''' ../src/
659                        ../src/pal/linux_dpdk/
660                        ../src/pal/linux_dpdk/dpdk1702/
661../src/dpdk/drivers/
662../src/dpdk/drivers/net/
663../src/dpdk/drivers/net/af_packet/
664../src/dpdk/drivers/net/bnx2x/
665../src/dpdk/drivers/net/bonding/
666../src/dpdk/drivers/net/cxgbe/
667../src/dpdk/drivers/net/cxgbe/base/
668../src/dpdk/drivers/net/e1000/
669../src/dpdk/drivers/net/e1000/base/
670../src/dpdk/drivers/net/enic/
671../src/dpdk/drivers/net/enic/base/
672../src/dpdk/drivers/net/fm10k/
673../src/dpdk/drivers/net/fm10k/base/
674../src/dpdk/drivers/net/i40e/
675../src/dpdk/drivers/net/i40e/base/
676../src/dpdk/drivers/net/ixgbe/
677../src/dpdk/drivers/net/ixgbe/base/
678../src/dpdk/drivers/net/mlx4/
679../src/dpdk/drivers/net/mlx5/
680../src/dpdk/drivers/net/mpipe/
681../src/dpdk/drivers/net/null/
682../src/dpdk/drivers/net/pcap/
683../src/dpdk/drivers/net/ring/
684../src/dpdk/drivers/net/virtio/
685../src/dpdk/drivers/net/virtio/virtio_user/
686../src/dpdk/drivers/net/vmxnet3/
687../src/dpdk/drivers/net/vmxnet3/base
688../src/dpdk/drivers/net/xenvirt/
689../src/dpdk/lib/
690../src/dpdk/lib/librte_acl/
691../src/dpdk/lib/librte_cfgfile/
692../src/dpdk/lib/librte_compat/
693../src/dpdk/lib/librte_distributor/
694../src/dpdk/lib/librte_eal/
695../src/dpdk/lib/librte_eal/common/
696../src/dpdk/lib/librte_eal/common/include/
697../src/dpdk/lib/librte_eal/common/include/arch/
698../src/dpdk/lib/librte_eal/common/include/arch/x86/
699../src/dpdk/lib/librte_eal/common/include/generic/
700../src/dpdk/lib/librte_eal/linuxapp/
701../src/dpdk/lib/librte_eal/linuxapp/eal/
702../src/dpdk/lib/librte_eal/linuxapp/eal/include/
703../src/dpdk/lib/librte_eal/linuxapp/eal/include/exec-env/
704../src/dpdk/lib/librte_eal/linuxapp/igb_uio/
705../src/dpdk/lib/librte_eal/linuxapp/xen_dom0/
706../src/dpdk/lib/librte_ether/
707../src/dpdk/lib/librte_hash/
708../src/dpdk/lib/librte_kvargs/
709../src/dpdk/lib/librte_mbuf/
710../src/dpdk/lib/librte_mempool/
711../src/dpdk/lib/librte_pipeline/
712../src/dpdk/lib/librte_ring/
713../src/dpdk/lib/librte_net/
714../src/dpdk/lib/librte_port/
715../src/dpdk/lib/librte_pipeline/
716../src/dpdk/lib/librte_table/
717../src/dpdk/
718''';
719
720
721
722
723DPDK_FLAGS=['-D_GNU_SOURCE', '-DPF_DRIVER', '-DX722_SUPPORT', '-DX722_A0_SUPPORT', '-DVF_DRIVER', '-DINTEGRATED_VF'];
724
725client_external_libs = [
726        'enum34-1.0.4',
727        'jsonrpclib-pelix-0.2.5',
728        'pyyaml-3.11',
729        'pyzmq-14.5.0',
730        'scapy-2.3.1',
731        'texttable-0.8.4',
732        ]
733
734rpath_linkage = []
735
736RELEASE_    = "release"
737DEBUG_      = "debug"
738PLATFORM_64 = "64"
739PLATFORM_32 = "32"
740
741
742class build_option:
743
744    def __init__(self,platform,debug_mode,is_pie):
745      self.mode     = debug_mode;   ##debug,release
746      self.platform = platform; #['32','64']
747      self.is_pie = is_pie
748
749    def __str__(self):
750       s=self.mode+","+self.platform;
751       return (s);
752
753    def lib_name(self,lib_name_p,full_path):
754        if full_path:
755            return b_path+lib_name_p;
756        else:
757            return lib_name_p;
758    #private functions
759    def toLib (self,name,full_path = True):
760        lib_n = "lib"+name+".a";
761        return (self.lib_name(lib_n,full_path));
762
763    def toExe(self,name,full_path = True):
764        return (self.lib_name(name,full_path));
765
766    def is64Platform (self):
767        return ( self.platform == PLATFORM_64);
768
769    def isRelease (self):
770        return ( self.mode  == RELEASE_);
771
772    def isPIE (self):
773        return self.is_pie
774
775    def update_executable_name (self,name):
776        return self.update_name(name,"-")
777
778    def update_non_exe_name (self,name):
779        return self.update_name(name,"_")
780
781    def update_name (self,name,delimiter):
782        trg = copy.copy(name);
783        if self.is64Platform():
784            trg += delimiter + "64";
785        else:
786            trg += delimiter + "32";
787
788        if self.isRelease () :
789            trg += "";
790        else:
791            trg +=  delimiter + "debug";
792
793        if self.isPIE():
794            trg += delimiter + "o"
795        return trg;
796
797    def get_target (self):
798        return self.update_executable_name("_t-rex");
799
800    def get_target_l2fwd (self):
801        return self.update_executable_name("l2fwd");
802
803    def get_dpdk_target (self):
804        return self.update_executable_name("dpdk");
805
806    def get_mlx5_target (self):
807        return self.update_executable_name("mlx5");
808
809    def get_mlx5so_target (self):
810        return self.update_executable_name("libmlx5")+'.so';
811
812    def get_common_flags (self):
813        if self.isPIE():
814            flags = copy.copy(common_flags_old)
815        else:
816            flags = copy.copy(common_flags_new);
817
818        if self.is64Platform () :
819            flags += ['-m64'];
820        else:
821            flags += ['-m32'];
822
823        if self.isRelease () :
824            flags += ['-O3'];
825        else:
826            flags += ['-O0','-D_DEBUG'];
827
828        return (flags)
829
830    def get_cxx_flags (self):
831        flags = self.get_common_flags()
832
833        # support c++ 2011
834        flags += ['-std=c++0x']
835
836        flags += ['-Wall',
837                  '-Werror',
838                  '-Wno-literal-suffix',
839                  '-Wno-sign-compare',
840                  '-Wno-strict-aliasing']
841
842        return (flags)
843
844    def get_c_flags (self):
845        flags = self.get_common_flags()
846        if  self.isRelease () :
847            flags += ['-DNDEBUG'];
848
849        # for C no special flags yet
850        return (flags)
851
852    def get_link_flags(self):
853        base_flags = ['-rdynamic'];
854        if self.is64Platform():
855            base_flags += ['-m64'];
856            base_flags += ['-lrt'];
857        else:
858            base_flags += ['-lrt'];
859
860        return base_flags;
861
862
863
864build_types = [
865               build_option(debug_mode= DEBUG_, platform = PLATFORM_64, is_pie = False),
866               build_option(debug_mode= RELEASE_,platform = PLATFORM_64, is_pie = False),
867               build_option(debug_mode= DEBUG_, platform = PLATFORM_64, is_pie = True),
868               build_option(debug_mode= RELEASE_,platform = PLATFORM_64, is_pie = True),
869              ]
870
871
872def build_prog (bld, build_obj):
873
874    #rte_libs =[
875    #         'dpdk'];
876
877    #rte_libs1 = rte_libs+rte_libs+rte_libs;
878
879    #for obj in rte_libs:
880    #    bld.read_shlib( name=obj , paths=[top+rte_lib_path] )
881
882    # add electric fence only for debug image
883    debug_file_list='';
884    if not build_obj.isRelease ():
885        debug_file_list +=ef_src.file_list(top)
886
887    bld.objects(
888      features='c ',
889      includes = dpdk_includes_path,
890
891      cflags   = (build_obj.get_c_flags()+DPDK_FLAGS ),
892      source   = bp_dpdk.file_list(top),
893      target=build_obj.get_dpdk_target()
894      );
895
896    bld.shlib(
897      features='c',
898      includes = dpdk_includes_path+dpdk_includes_verb_path,
899      cflags   = (build_obj.get_c_flags()+DPDK_FLAGS ),
900      use =['ibverbs'],
901
902      source   = mlx5_dpdk.file_list(top),
903      target   = build_obj.get_mlx5_target()
904   )
905
906    bld.program(features='cxx cxxprogram',
907                includes =includes_path,
908                cxxflags =(build_obj.get_cxx_flags()+['-std=gnu++11',]),
909                linkflags = build_obj.get_link_flags() ,
910                lib=['pthread','dl', 'z'],
911                use =[build_obj.get_dpdk_target(),'zmq'],
912                source = bp.file_list(top) + debug_file_list,
913                rpath = rpath_linkage,
914                target = build_obj.get_target())
915
916
917
918def build_type(bld,build_obj):
919    build_prog(bld, build_obj);
920
921
922def post_build(bld):
923    print("copy objects")
924    exec_p ="../scripts/"
925    for obj in build_types:
926        install_single_system(bld, exec_p, obj);
927
928def build(bld):
929    global dpdk_includes_verb_path;
930    bld.add_pre_fun(pre_build)
931    bld.add_post_fun(post_build);
932
933    zmq_lib_path='external_libs/zmq/'
934    bld.read_shlib( name='zmq' , paths=[top+zmq_lib_path] )
935    if bld.env['LIB_IBVERBS']:
936        Logs.pprint('GREEN', 'Info: Using external libverbs.')
937        bld.read_shlib(name='ibverbs')
938    else:
939        Logs.pprint('GREEN', 'Info: Using internal libverbs.')
940        ibverbs_lib_path='external_libs/ibverbs/'
941        dpdk_includes_verb_path =' \n ../external_libs/ibverbs/include/ \n'
942        bld.read_shlib( name='ibverbs' , paths=[top+ibverbs_lib_path] )
943        check_ibverbs_deps(bld)
944
945    for obj in build_types:
946        build_type(bld,obj);
947
948
949def build_info(bld):
950    pass;
951
952def do_create_link (src,dst,exec_p):
953    if os.path.exists(src):
954        dest_file = exec_p +dst
955        if not os.path.lexists(dest_file):
956            print(dest_file)
957            relative_path = os.path.relpath(src, exec_p)
958            os.symlink(relative_path, dest_file);
959
960def install_single_system (bld, exec_p, build_obj):
961    o='build_dpdk/linux_dpdk/';
962
963    src_file =  os.path.realpath(o+build_obj.get_target())
964    dest_file = exec_p +build_obj.get_target()
965    do_create_link(src_file,dest_file,exec_p);
966
967    src_mlx_file =  os.path.realpath(o+build_obj.get_mlx5so_target())
968    dest_mlx_file = exec_p + build_obj.get_mlx5so_target()
969    do_create_link(src_mlx_file,dest_mlx_file,exec_p);
970
971
972
973def pre_build(bld):
974    print("update version files")
975    create_version_files ()
976
977
978def write_file (file_name,s):
979    f=open(file_name,'w')
980    f.write(s)
981    f.close()
982
983
984def get_build_num ():
985    s='';
986    if os.path.isfile(BUILD_NUM_FILE):
987        f=open(BUILD_NUM_FILE,'r');
988        s+=f.readline().rstrip();
989        f.close();
990    return s;
991
992def create_version_files ():
993    git_sha="N/A"
994    try:
995      r=getstatusoutput("git log --pretty=format:'%H' -n 1")
996      if r[0]==0:
997          git_sha=r[1]
998    except :
999        pass;
1000
1001
1002    s =''
1003    s +="#ifndef __TREX_VER_FILE__           \n"
1004    s +="#define __TREX_VER_FILE__           \n"
1005    s +="#ifdef __cplusplus                  \n"
1006    s +=" extern \"C\" {                        \n"
1007    s +=" #endif                             \n";
1008    s +='#define  VERSION_USER  "%s"          \n' % os.environ.get('USER', 'unknown')
1009    s +='extern const char * get_build_date(void);  \n'
1010    s +='extern const char * get_build_time(void);  \n'
1011    s +='#define VERSION_UIID      "%s"       \n' % uuid.uuid1()
1012    s +='#define VERSION_GIT_SHA   "%s"       \n' % git_sha
1013    s +='#define VERSION_BUILD_NUM "%s"       \n' % get_build_num()
1014    s +="#ifdef __cplusplus                  \n"
1015    s +=" }                        \n"
1016    s +=" #endif                             \n";
1017    s +="#endif \n"
1018
1019    write_file (H_VER_FILE ,s)
1020
1021    s ='#include "version.h"          \n'
1022    s +='#define VERSION_UIID1      "%s"       \n' % uuid.uuid1()
1023    s +="const char * get_build_date(void){ \n"
1024    s +="    return (__DATE__);       \n"
1025    s +="}      \n"
1026    s +=" \n"
1027    s +="const char * get_build_time(void){ \n"
1028    s +="    return (__TIME__ );       \n"
1029    s +="}      \n"
1030
1031    write_file (C_VER_FILE,s)
1032
1033def build_test(bld):
1034    create_version_files ()
1035
1036def _copy_single_system (bld, exec_p, build_obj):
1037    o='build_dpdk/linux_dpdk/';
1038    src_file =  os.path.realpath(o+build_obj.get_target())
1039    print(src_file)
1040    if os.path.exists(src_file):
1041        dest_file = exec_p +build_obj.get_target()
1042        print(dest_file)
1043        os.system("cp %s %s " %(src_file,dest_file));
1044        os.system("chmod +x %s " %(dest_file));
1045
1046def _copy_single_system1 (bld, exec_p, build_obj):
1047    o='../scripts/';
1048    src_file =  os.path.realpath(o+build_obj.get_target()[1:])
1049    print(src_file)
1050    if os.path.exists(src_file):
1051        dest_file = exec_p +build_obj.get_target()[1:]
1052        os.system("cp %s %s " %(src_file,dest_file));
1053        os.system("chmod +x %s " %(dest_file));
1054
1055def _copy_single_system2 (bld, exec_p, build_obj):
1056    o='../scripts/';
1057    src_file =  os.path.realpath(o+build_obj.get_mlx5so_target()[1:])
1058    print(src_file)
1059    if os.path.exists(src_file):
1060        dest_file = exec_p +build_obj.get_mlx5so_target()[1:]
1061        os.system("cp %s %s " %(src_file,dest_file));
1062        os.system("chmod +x %s " %(dest_file));
1063
1064
1065def copy_single_system (bld, exec_p, build_obj):
1066    _copy_single_system (bld, exec_p, build_obj)
1067
1068def copy_single_system1 (bld, exec_p, build_obj):
1069    _copy_single_system1 (bld, exec_p, build_obj)
1070
1071def copy_single_system2 (bld, exec_p, build_obj):
1072    _copy_single_system2 (bld, exec_p, build_obj)
1073
1074
1075files_list=[
1076            'libzmq.so.3',
1077            'trex-cfg',
1078            'bp-sim-64',
1079            'bp-sim-64-debug',
1080            't-rex-64-debug-gdb',
1081            'stl-sim',
1082            'find_python.sh',
1083            'run_regression',
1084            'run_functional_tests',
1085            'dpdk_nic_bind.py',
1086            'dpdk_setup_ports.py',
1087            'doc_process.py',
1088            'trex_daemon_server',
1089            'scapy_daemon_server',
1090            'master_daemon.py',
1091            'trex-console',
1092            'daemon_server'
1093            ];
1094
1095files_dir=['cap2','avl','cfg','ko','automation', 'external_libs', 'python-lib','stl','exp','dumy_libs']
1096
1097
1098class Env(object):
1099    @staticmethod
1100    def get_env(name) :
1101        s= os.environ.get(name);
1102        if s == None:
1103            print("You should define $ %s" % name)
1104            raise Exception("Env error");
1105        return (s);
1106
1107    @staticmethod
1108    def get_release_path () :
1109        s= Env().get_env('TREX_LOCAL_PUBLISH_PATH');
1110        s +=get_build_num ()+"/"
1111        return  s;
1112
1113    @staticmethod
1114    def get_remote_release_path () :
1115        s= Env().get_env('TREX_REMOTE_PUBLISH_PATH');
1116        return  s;
1117
1118    @staticmethod
1119    def get_local_web_server () :
1120        s= Env().get_env('TREX_WEB_SERVER');
1121        return  s;
1122
1123    # extral web
1124    @staticmethod
1125    def get_trex_ex_web_key() :
1126        s= Env().get_env('TREX_EX_WEB_KEY');
1127        return  s;
1128
1129    @staticmethod
1130    def get_trex_ex_web_path() :
1131        s= Env().get_env('TREX_EX_WEB_PATH');
1132        return  s;
1133
1134    @staticmethod
1135    def get_trex_ex_web_user() :
1136        s= Env().get_env('TREX_EX_WEB_USER');
1137        return  s;
1138
1139    @staticmethod
1140    def get_trex_ex_web_srv() :
1141        s= Env().get_env('TREX_EX_WEB_SRV');
1142        return  s;
1143
1144    @staticmethod
1145    def get_trex_regression_workspace():
1146        return Env().get_env('TREX_REGRESSION_WORKSPACE')
1147
1148
1149def check_release_permission():
1150    if os.getenv('USER') not in USERS_ALLOWED_TO_RELEASE:
1151        raise Exception('You are not allowed to release TRex. Please contact Hanoch.')
1152
1153# build package in parent dir. can provide custom name and folder with --pkg-dir and --pkg-file
1154def pkg(self):
1155    build_num = get_build_num()
1156    pkg_dir = self.options.pkg_dir
1157    if not pkg_dir:
1158        pkg_dir = os.pardir
1159    pkg_file = self.options.pkg_file
1160    if not pkg_file:
1161        pkg_file = '%s.tar.gz' % build_num
1162    tmp_path = os.path.join(pkg_dir, '_%s' % pkg_file)
1163    dst_path = os.path.join(pkg_dir, pkg_file)
1164    build_path = os.path.join(os.pardir, build_num)
1165
1166    # clean old dir if exists
1167    os.system('rm -rf %s' % build_path)
1168    release(self, build_path + '/')
1169    os.system("cp %s/%s.tar.gz %s" % (build_path, build_num, tmp_path))
1170    os.system("mv %s %s" % (tmp_path, dst_path))
1171
1172    # clean new dir
1173    os.system('rm -rf %s' % build_path)
1174
1175
1176def release(bld, custom_dir = None):
1177    """ release to local folder  """
1178    if custom_dir:
1179        exec_p = custom_dir
1180    else:
1181        check_release_permission()
1182        exec_p = Env().get_release_path()
1183    print("copy images and libs")
1184    os.system(' mkdir -p '+exec_p);
1185
1186    for obj in build_types:
1187        copy_single_system(bld,exec_p,obj)
1188        copy_single_system1(bld,exec_p,obj)
1189        copy_single_system2(bld,exec_p,obj)
1190
1191    for obj in files_list:
1192        src_file =  '../scripts/'+obj
1193        dest_file = exec_p +'/'+obj
1194        os.system("cp %s %s " %(src_file,dest_file));
1195
1196    for obj in files_dir:
1197        src_file =  '../scripts/'+obj+'/'
1198        dest_file = exec_p +'/'+obj+'/'
1199        os.system("cp -rv %s %s " %(src_file,dest_file));
1200        os.system("chmod 755 %s " %(dest_file));
1201
1202    rel=get_build_num ()
1203
1204    # create client package
1205    os.system('mkdir -p %s/trex_client/external_libs' % exec_p)
1206    for ext_lib in client_external_libs:
1207        os.system('cp ../scripts/external_libs/%s %s/trex_client/external_libs/ -r' % (ext_lib, exec_p))
1208    os.system('cp ../scripts/automation/trex_control_plane/stf %s/trex_client/ -r' % exec_p)
1209    os.system('cp ../scripts/automation/trex_control_plane/stl %s/trex_client/ -r' % exec_p)
1210    with open('%s/trex_client/stl/examples/stl_path.py' % exec_p) as f:
1211        stl_path_content = f.read()
1212    if 'STL_PROFILES_PATH' not in stl_path_content:
1213        raise Exception('Could not find STL_PROFILES_PATH in stl/examples/stl_path.py')
1214    stl_path_content = re.sub('STL_PROFILES_PATH.*?\n', "STL_PROFILES_PATH = os.path.join(os.pardir, 'profiles')\n", stl_path_content)
1215    with open('%s/trex_client/stl/examples/stl_path.py' % exec_p, 'w') as f:
1216        f.write(stl_path_content)
1217    os.system('cp ../scripts/stl %s/trex_client/stl/profiles -r' % exec_p)
1218    shutil.make_archive(os.path.join(exec_p, 'trex_client_%s' % rel), 'gztar', exec_p, 'trex_client')
1219    os.system('rm -r %s/trex_client' % exec_p)
1220
1221    os.system('cd %s/..;tar --exclude="*.pyc" -zcvf %s/%s.tar.gz %s' %(exec_p,os.getcwd(),rel,rel))
1222    os.system("mv %s/%s.tar.gz %s" % (os.getcwd(),rel,exec_p));
1223
1224
1225def publish(bld, custom_source = None):
1226    check_release_permission()
1227    exec_p = Env().get_release_path()
1228    rel=get_build_num ()
1229
1230    release_name ='%s.tar.gz' % (rel);
1231    if custom_source:
1232        from_ = custom_source
1233    else:
1234        from_ = exec_p+'/'+release_name;
1235    os.system("rsync -av %s %s:%s/%s " %(from_,Env().get_local_web_server(),Env().get_remote_release_path (), release_name))
1236    os.system("ssh %s 'cd %s;rm be_latest; ln -P %s be_latest'  " %(Env().get_local_web_server(),Env().get_remote_release_path (),release_name))
1237    os.system("ssh %s 'cd %s;rm latest; ln -P %s latest'  " %(Env().get_local_web_server(),Env().get_remote_release_path (),release_name))
1238
1239
1240def publish_ext(bld, custom_source = None):
1241    check_release_permission()
1242    exec_p = Env().get_release_path()
1243    rel=get_build_num ()
1244
1245    release_name ='%s.tar.gz' % (rel);
1246    if custom_source:
1247        from_ = custom_source
1248    else:
1249        from_ = exec_p+'/'+release_name;
1250    cmd='rsync -avz --progress -e "ssh -i %s" --rsync-path=/usr/bin/rsync %s %s@%s:%s/release/%s' % (Env().get_trex_ex_web_key(),from_, Env().get_trex_ex_web_user(),Env().get_trex_ex_web_srv(),Env().get_trex_ex_web_path() ,release_name)
1251    print(cmd)
1252    os.system( cmd )
1253    os.system("ssh -i %s -l %s %s 'cd %s/release/;rm be_latest; ln -P %s be_latest'  " %(Env().get_trex_ex_web_key(),Env().get_trex_ex_web_user(),Env().get_trex_ex_web_srv(),Env().get_trex_ex_web_path(),release_name))
1254    os.system("ssh -i %s -l %s %s 'cd %s/release/;rm latest; ln -P %s latest'  " %(Env().get_trex_ex_web_key(),Env().get_trex_ex_web_user(),Env().get_trex_ex_web_srv(),Env().get_trex_ex_web_path(),release_name))
1255
1256# publish latest passed regression package (or custom commit from  --publish_commit option) as be_latest to trex-tgn.cisco.com and internal wiki
1257def publish_both(self):
1258    check_release_permission()
1259    packages_dir = Env().get_env('TREX_LOCAL_PUBLISH_PATH') + '/experiment/packages'
1260    publish_commit = self.options.publish_commit
1261    if publish_commit:
1262        package_file = '%s/%s.tar.gz' % (packages_dir, publish_commit)
1263    else:
1264        last_passed_commit_file = Env().get_trex_regression_workspace() + '/reports/last_passed_commit'
1265        with open(last_passed_commit_file) as f:
1266            last_passed_commit = f.read().strip()
1267        package_file = '%s/%s.tar.gz' % (packages_dir, last_passed_commit)
1268    publish(self, custom_source = package_file)
1269    publish_ext(self, custom_source = package_file)
1270
1271# print detailed latest passed regression commit + brief info of 5 commits before it
1272def show(bld):
1273    last_passed_commit_file = Env().get_trex_regression_workspace() + '/reports/last_passed_commit'
1274    with open(last_passed_commit_file) as f:
1275        last_passed_commit = f.read().strip()
1276
1277    # last passed nightly
1278    command = 'timeout 10 git show %s --quiet' % last_passed_commit
1279    result, output = getstatusoutput(command)
1280    if result == 0:
1281        print('Last passed regression commit:\n%s\n' % output)
1282    else:
1283        raise Exception('Error getting commit info with command: %s' % command)
1284
1285    # brief list of 5 commits before passed
1286    result, output = getstatusoutput('git --version')
1287    if result != 0 or output.startswith('git version 1'):
1288        # old format, no color etc.
1289        command = "timeout 10 git log --no-merges -n 5 --pretty=format:'%%h  %%an  %%ci  %%s' %s^@" % last_passed_commit
1290    else:
1291        # new format, with color, padding, truncating etc.
1292        command = "timeout 10 git log --no-merges -n 5 --pretty=format:'%%C(auto)%%h%%Creset  %%<(10,trunc)%%an  %%ci  %%<(100,trunc)%%s' %s^@ " % last_passed_commit
1293    result, output = getstatusoutput(command)
1294    if result == 0:
1295        print(output)
1296    else:
1297        raise Exception('Error getting commits info with command: %s' % command)
1298
1299def test (bld):
1300    r=getstatusoutput("git log --pretty=format:'%H' -n 1")
1301    if r[0]==0:
1302        print(r[1])
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316