Esempio n. 1
0
def install_switch_bsp():
    set_sde_env()
    aps_bsp_installation_file = get_aps_bsp_pkg_abs_path()
    if (get_switch_model() == constants.bf6064x_t and (
            'BF2556' in aps_bsp_installation_file or 'bf2556' in aps_bsp_installation_file)) \
            or (get_switch_model() == constants.bf2556x_1t and (
            'BF6064' in aps_bsp_installation_file or 'bf6064' in aps_bsp_installation_file)):
        print("ERROR: Incompatible BSP provided in settings.yaml,"
              " Switch model is {model} but BSP is {bsp}".format(
                  model=get_switch_model(), bsp=aps_bsp_installation_file))
        exit(0)

    print("Installing {}".format(aps_bsp_installation_file))

    os.environ['BSP_INSTALL'] = get_env_var('SDE_INSTALL')
    print("BSP_INSTALL directory set to {}".format(os.environ['BSP_INSTALL']))

    install_bsp_deps()
    cmake_cmd = 'cmake -DCMAKE_INSTALL_PREFIX={}'.format(
        get_env_var('SDE_INSTALL'))
    cmake_cmd += ' -B ' + aps_bsp_installation_file
    cmake_cmd += ' -S ' + aps_bsp_installation_file
    execute_cmd(cmake_cmd)
    os.system("make -C {0}".format(aps_bsp_installation_file))
    os.system("make -C {0} install".format(aps_bsp_installation_file))

    return True
Esempio n. 2
0
def start_bf_switchd():
    # os.chdir(common.dname)
    print('Starting BF switchd.')
    set_sde_env_n_load_drivers()

    p4_prog_name = get_env_var(p4_prog_env_var_name)

    # LD_LIBRARY_PATH is set for ONLPv2 case, libs in install/lib folder are
    # not found there but this does not cause any harm for Ubuntu case either.
    # set_env('LD_LIBRARY_PATH', "/{0}/install/lib".format(get_env_var('SDE')))
    # print("LD_LIBRARY_PATH : ")
    # os.system("echo $LD_LIBRARY_PATH")

    if not p4_prog_name:
        print("Starting switchd without p4 program")
        start_switchd_cmd = "sudo -E {0}/run_switchd.sh -c {0}/pkgsrc/p4-examples/tofino/tofino_skip_p4.conf.in " \
                            "--skip-p4".format(get_env_var('SDE'))
    else:
        print("Starting switchd with P4 prog:{}".format(p4_prog_name))
        start_switchd_cmd = 'sudo -E {0}/run_switchd.sh -p {1}'.format(
            get_env_var('SDE'), p4_prog_name.replace(".p4", ""))
    username = getpass.getuser()

    if username == "root":
        start_switchd_cmd = start_switchd_cmd.replace("sudo -E", "")
    alloc_dma()
    print("Starting switchd with command : {}".format(start_switchd_cmd))
    os.system(start_switchd_cmd)
Esempio n. 3
0
def set_sal_test_env():
    set_env_var(constants.sal_home_env_var_name, get_sal_home_absolute())
    append_to_env_var(pythonpath_env_var_name,
                      get_env_var(constants.sal_home_env_var_name))
    append_to_env_var(pythonpath_env_var_name,
                      get_env_var(constants.sal_home_env_var_name) + "/test")
    print("%s = %s" %
          (pythonpath_env_var_name, get_env_var(pythonpath_env_var_name)))
Esempio n. 4
0
def build_sal():
    print('Building SAL...')
    os.chdir(get_env_var(constants.sal_home_env_var_name))
    cmake_cmd = 'cmake '

    cmake_cmd += get_env_var(constants.sal_home_env_var_name)
    print('Executing cmake command {}.'.format(cmake_cmd))
    os.system(cmake_cmd)
    os.system('make -C {}'.format(get_env_var(constants.sal_home_env_var_name)))
Esempio n. 5
0
def clean_sal():
    print('Cleaning SAL...')
    
    to_delete = [get_env_var(constants.sal_home_env_var_name)+f for f in ['/bin', '/build', '/logs/', '/CMakeCache.txt', '/Makefile',
                                                                          '/CMakeFiles', '/cmake-build-debug']]
    os.system(
        'make -C {} clean'.format(get_env_var(constants.sal_home_env_var_name)))
    for file in to_delete:
        print('Deteling {}'.format(file))
        delete_files(file)
Esempio n. 6
0
def set_sal_env():
    print("Setting environment for SAL.")
    if not set_sde_env_n_load_drivers():
        return False
    rc = set_env_var(constants.sal_home_env_var_name, get_sal_repo_absolute())
    print('SAL_HOME: {}'.format(get_env_var(constants.sal_home_env_var_name)))
    rc &= set_env_var(
        constants.sde_include_env_var_name,
        get_env_var(constants.sde_install_env_var_name) + '/include')
    rc &= set_env_var(constants.gb_src_home_env_var_name,
                      get_gb_src_home_absolute())
    rc &= set_env_var(constants.gb_lib_home_env_var_name,
                      get_gb_lib_home_absolute())
    rc &= set_env_var(constants.tp_install_env_var_name,
                      get_tp_install_path_absolute())
    print('SAL_HOME: %s \
    \n SDE: %s \
    \n SDE_INSTALL: %s \
    \n SDE_INCLUDE: %s \
    \n GB_SRC_HOME: %s \
    \n GB_LIB_HOME: %s \
    \n TP_INSTALL: %s' % (get_env_var(constants.sal_home_env_var_name),
                          get_env_var(constants.sde_env_var_name),
                          get_env_var(constants.sde_install_env_var_name),
                          get_env_var(constants.sde_include_env_var_name),
                          get_env_var(constants.gb_src_home_env_var_name),
                          get_env_var(constants.gb_lib_home_env_var_name),
                          get_env_var(constants.tp_install_env_var_name)))
    return rc
Esempio n. 7
0
def build_sal():
    print('Building SAL...')
    os.chdir(get_env_var(constants.sal_home_env_var_name))
    cmake_cmd = 'cmake '

    cmake_cmd += get_env_var(constants.sal_home_env_var_name)
    print('Executing cmake command {}.'.format(cmake_cmd))
    os.system(cmake_cmd)
    os.system('LD_LIBRARY_PATH={0}/lib:$LD_LIBRARY_PATH make -C {1}'.format(
        get_env_var(constants.tp_install_env_var_name),
        get_env_var(constants.sal_home_env_var_name)))
Esempio n. 8
0
def set_sal_runtime_env():
    print("Setting environment for SAL runtime.")
    if not set_sde_env_n_load_drivers():
        return False
    set_env_var(constants.sal_home_env_var_name, get_sal_home_absolute())
    set_env_var(constants.tp_install_env_var_name,
                get_tp_install_path_absolute())
    print('SAL_HOME: {}'.format(get_env_var(constants.sal_home_env_var_name)))
    print('TP_INSTALL: {}'.format(
        get_env_var(constants.tp_install_env_var_name)))
    return True
Esempio n. 9
0
def set_sde_env():
    print("Setting environment for BF_SDE.")
    sde_home_absolute = get_sde_home_absolute()
    if validate_path_existence(sde_home_absolute, 'SDE'):
        set_env_var(constants.sde_env_var_name, sde_home_absolute)
        set_env_var(constants.sde_install_env_var_name,
                    get_env_var(constants.sde_env_var_name) + '/install')
        print('Environment variables set: \n SDE: {0} \n SDE_INSTALL: {1}'.
              format(get_env_var(constants.sde_env_var_name),
                     get_env_var(constants.sde_install_env_var_name)))
        return True
    return False
Esempio n. 10
0
def set_sal_env():
    print("Setting environment for SAL.")
    if not set_sde_env():
        return False
        exit()
    #os.environ['TCMALLOC_LARGE_ALLOC_REPORT_THRESHOLD'] = '64077925800531312640'
    set_env_var(constants.sal_home_env_var_name, get_sal_home_absolute())
    set_env_var(constants.pythonpath_env_var_name, get_sal_home_absolute())
    set_env_var(constants.sde_include_env_var_name,
                get_env_var(constants.sde_install_env_var_name) + '/include')
    set_env_var(constants.gb_src_home_env_var_name, get_gb_src_home_absolute())
    set_env_var(constants.gb_lib_home_env_var_name, get_gb_lib_home_absolute())

    print('SAL_HOME: {0} \
    \n PYTHONPATH: {1} \
    \n SDE: {2} \
    \n SDE_INSTALL: {3} \
    \n SDE_INCLUDE: {4} \
    \n GB_SRC_HOME: {5} \
    \n GB_LIB_HOME: {6} '.format(
        get_env_var(constants.sal_home_env_var_name),
        get_env_var(constants.pythonpath_env_var_name),
        get_env_var(constants.sde_env_var_name),
        get_env_var(constants.sde_install_env_var_name),
        get_env_var(constants.sde_include_env_var_name),
        get_env_var(constants.gb_src_home_env_var_name),
        get_env_var(constants.gb_lib_home_env_var_name)))
    return True
Esempio n. 11
0
def start_stratum():
    print("Starting Stratum....")
    stratum_start_cmd_bsp_less = 'sudo {0}/bazel-bin/stratum/hal/bin/barefoot/stratum_bf \
    --external_stratum_urls=0.0.0.0:28000 \
    --grpc_max_recv_msg_size=256 \
    --bf_sde_install={1} \
    --persistent_config_dir={2} \
    --forwarding_pipeline_configs_file={2}/p4_pipeline.pb.txt \
    --chassis_config_file={2}/chassis_config.pb.txt \
    --write_req_log_file={2}/p4_writes.pb.txt \
    --bf_switchd_cfg={0}/stratum/hal/bin/barefoot/tofino_skip_p4_no_bsp.conf'.format(
        get_env_var(constants.stratum_home_env_var_name),
        get_env_var(constants.bf_sde_install_env_var_name),
        get_env_var(constants.stratum_config_env_var_name))

    append_to_env_var(constants.ld_lib_path_env_var_name,
                      common.get_gb_home_absolute() + '/compilation_root')

    stratum_start_cmd_bsp = 'sudo LD_LIBRARY_PATH={3} {0}/bazel-bin/stratum/hal/bin/barefoot/stratum_bf \
        --external_stratum_urls=0.0.0.0:28000 \
        --grpc_max_recv_msg_size=256 \
        --bf_sde_install={1} \
        --persistent_config_dir={2} \
        --forwarding_pipeline_configs_file={2}/p4_pipeline.pb.txt \
        --chassis_config_file={2}/chassis_config.pb.txt \
        --write_req_log_file={2}/p4_writes.pb.txt \
        --bf_sim'.format(get_env_var(constants.stratum_home_env_var_name),
                         get_env_var(constants.bf_sde_install_env_var_name),
                         get_env_var(constants.stratum_config_env_var_name),
                         get_env_var(constants.ld_lib_path_env_var_name))

    if not load_and_verify_kernel_modules():
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)

    shutil.copyfile(
        get_env_var(constants.stratum_home_env_var_name) +
        '/stratum/hal/bin/barefoot/platforms/x86-64-stordis-bf2556x-1t-r0.json',
        get_env_var(constants.bf_sde_install_env_var_name) +
        '/share/port_map.json')
    os.chdir(get_env_var(constants.stratum_home_env_var_name))
    print('Current dir: {}'.format(os.getcwd()))
    if get_stratum_mode() == 'bsp-less':
        print("Starting Stratum in bsp-less mode...")
        print("Executing command {}".format(stratum_start_cmd_bsp_less))
        os.system(stratum_start_cmd_bsp_less)
    else:
        print("Starting Stratum in bsp mode...")
        print("Executing command {}".format(stratum_start_cmd_bsp))
        os.system(stratum_start_cmd_bsp)
Esempio n. 12
0
def run_sal(debug):
    print('Starting SAL reference application...')
    load_drivers()
    sal_home = get_env_var(constants.sal_home_env_var_name)
    sal_executable = sal_home + '/build/salRefApp'
    sal_run_cmd = 'sudo -E LD_LIBRARY_PATH={0}:{1}:{2}:{3}:{4} {6} {5}'.format(
        sal_home + '/build', sal_home + '/lib',
        get_env_var(constants.tp_install_env_var_name) + '/lib',
        get_env_var(constants.sal_home_env_var_name) + '/install/lib',
        get_env_var(constants.sde_install_env_var_name) + '/lib',
        sal_executable, 'gdb' if debug else '')
    print('Running SAL with command: {}'.format(sal_run_cmd))
    execute_cmd(sal_run_cmd)
    return True
Esempio n. 13
0
def build_sal():
    print('Building SAL...')

    cmake_cmd = 'cmake '
    cmake_cmd += ' -B ' + get_env_var(constants.sal_home_env_var_name)
    cmake_cmd += ' -S ' + get_env_var(constants.sal_home_env_var_name)

    print('Executing cmake command {}.'.format(cmake_cmd))

    execute_cmd(cmake_cmd)
    execute_cmd('LD_LIBRARY_PATH={0}/lib:$LD_LIBRARY_PATH make -C {1}'.format(
        get_env_var(constants.tp_install_env_var_name),
        get_env_var(constants.sal_home_env_var_name)))

    return True
Esempio n. 14
0
def install_switch_bsp():
    set_sde_env()
    bsp_installation_file = get_path_relative_to_user_home(
        get_from_setting_dict('BSP', 'bsp_pkg'))

    if zipfile.is_zipfile(bsp_installation_file):
        print("Installing {}".format(bsp_installation_file))
        zip_ref = zipfile.ZipFile(bsp_installation_file)
        zip_ref.extractall()
        extracted_dir_name = zip_ref.namelist()[0]
        zip_ref.close()
        os.chdir(extracted_dir_name)
        os.environ['BSP'] = os.getcwd()
        print("BSP home directory set to {}".format(os.environ['BSP']))
        os.environ['BSP_INSTALL'] = get_env_var('SDE_INSTALL')
        print("BSP_INSTALL directory set to {}".format(
            os.environ['BSP_INSTALL']))
        for pltfm in glob.glob('./bf-platforms*'):
            os.chdir(pltfm)
        pltfm_dir = os.getcwd()
        os.system("autoreconf && autoconf")
        os.system("chmod +x ./autogen.sh")
        os.system("chmod +x ./configure")
        os.system(
            "./configure --prefix={} --enable-thrift --with-tof-brgup-plat".
            format(os.environ['BSP_INSTALL']))
        os.system("make")
        os.system("sudo make install")
        shutil.rmtree(os.environ['BSP'])
    else:
        print("You choose not to install BSP.")
Esempio n. 15
0
def clean_stratum():
    print('Cleaning stratum...')
    stratum_clean_cmd = 'bazel clean'
    os.chdir(get_env_var(constants.stratum_home_env_var_name))
    print('Executing : {}'.format(stratum_clean_cmd))
    os.system(stratum_clean_cmd)
    return True
Esempio n. 16
0
def install_switch_bsp():
    set_sde_env_n_load_drivers()
    aps_bsp_installation_file = get_aps_bsp_pkg_abs_path()
    print("Installing {}".format(aps_bsp_installation_file))
    aps_zip = zipfile.ZipFile(aps_bsp_installation_file)
    aps_zip.extractall(Path(aps_bsp_installation_file).parent)
    aps_bsp_dir = aps_zip.namelist()[0] + '/apsn/'
    aps_bsp_dir_absolute = str(
        Path(aps_bsp_installation_file).parent) + '/' + aps_bsp_dir
    aps_zip.close()

    ref_bsp_tar = tarfile.open(get_ref_bsp_abs_path())
    ref_bsp_tar.extractall(Path(get_ref_bsp_abs_path()).parent)
    ref_bsp_dir = ref_bsp_tar.getnames()[0]
    os.chdir(
        str(Path(get_ref_bsp_abs_path()).parent) + '/' + ref_bsp_dir +
        '/packages')
    pltfm_tar_name = ''
    for f in os.listdir('./'):
        if f.endswith('.tgz'):
            pltfm_tar_name = f
    pltfm_tar = tarfile.open(pltfm_tar_name)
    pltfm_tar.extractall()
    bf_pltfm_dir = str(Path(
        get_ref_bsp_abs_path()).parent) + '/' + ref_bsp_dir + '/packages/' + \
                   pltfm_tar.getnames()[0]

    aps_pltfm_dir = bf_pltfm_dir + '/platforms/apsn/'
    if os.path.exists(aps_pltfm_dir):
        shutil.rmtree(aps_pltfm_dir)

    shutil.copytree(aps_bsp_dir_absolute, aps_pltfm_dir)

    pltfm_tar.close()
    ref_bsp_tar.close()
    os.chdir(bf_pltfm_dir)
    os.system('patch -p1 < {0}/{1}'.format(
        str(Path(aps_bsp_installation_file).parent), get_diff_file_name()))
    # os.environ['BSP'] = os.getcwd()
    # print("BSP home directory set to {}".format(os.environ['BSP']))
    os.environ['BSP_INSTALL'] = get_env_var('SDE_INSTALL')
    print("BSP_INSTALL directory set to {}".format(os.environ['BSP_INSTALL']))

    install_bsp_deps()
    os.system("autoreconf && autoconf")
    os.system("chmod +x ./autogen.sh")
    thrift_flag = ''
    if get_p4_studio_build_profile_name() != stratum_profile:
        thrift_flag = '--enable-thrift'
    if get_switch_model() == constants.bf2556x_1t:
        execute_cmd("CFLAGS=-Wno-error ./configure --prefix={0} {1} "
                    "--with-tof-brgup-plat".format(os.environ['BSP_INSTALL'],
                                                   thrift_flag))
    else:
        execute_cmd("CFLAGS=-Wno-error ./configure --prefix={0} {1}".format(
            os.environ['BSP_INSTALL'], thrift_flag))
    os.system("make")
    os.system("sudo make install")
    os.chdir(dname)
    return True
Esempio n. 17
0
def install_sal_thirdparty_deps():
    print('Installing SAL 3rdparty dependencies.')

    if not os.path.exists(sal_3rdparty_build_path):
        os.makedirs(sal_3rdparty_build_path)

    i = input('Install boost y/[n] ?')
    if not i or i not in ['y', 'n']:
        i = 'n'
    if i == 'y' and not install_boost():
        return False

    i = input('Install protobuf y/[n] ?')
    if not i or i not in ['y', 'n']:
        i = 'n'
    if i == 'y' and not install_protobuf():
        return False

    append_to_env_var(constants.path_env_var_name,
                      sal_3rdparty_build_path + '/bin/')
    print(get_env_var(path_env_var_name))

    i = input('Install gRPC y/[n] ?')
    if not i or i not in ['y', 'n']:
        i = 'n'
    if i == 'y' and not install_grpc():
        return False
    return True
Esempio n. 18
0
def alloc_dma():
    output = get_cmd_output('cat /etc/sysctl.conf')
    if 'vm.nr_hugepages = 128' not in output:
        print('Setting up huge pages...')
        dma_alloc_cmd = 'sudo /{}/pkgsrc/ptf-modules/ptf-utils/dma_setup.sh'.format(
            get_env_var('SDE'))
        os.system(dma_alloc_cmd)
Esempio n. 19
0
def set_sal_runtime_env():
    print("Setting environment for SAL runtime.")
    if not set_sde_env_n_load_drivers():
        return False
    set_env_var(constants.sal_home_env_var_name, sal_rel_dir)
    print('SAL_HOME: {}'.format(get_env_var(constants.sal_home_env_var_name)))
    return True
Esempio n. 20
0
def clean_stratum():
    print('Cleaning stratum...')
    print('Current working dir {}'.format(os.getcwd()))
    stratum_clean_cmd = 'bezel clean'
    os.chdir(get_env_var(constants.stratum_home_env_var_name))
    print('Executing : {}'.format(stratum_clean_cmd))
    os.system(stratum_clean_cmd)
Esempio n. 21
0
def run_sal():
    print('Starting SAL reference application...')
    if get_selected_profile_name(
    ) == constants.sal_hw_profile_name and not load_and_verify_kernel_modules(
    ):
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)
    sal_home = get_env_var(constants.sal_home_env_var_name)
    sal_executable = sal_home + '/build/salRefApp'
    sal_run_cmd = 'sudo -E LD_LIBRARY_PATH={0}:{1}:{2}:{3} {4}'.format(
        sal_home + '/build', sal_home + '/lib',
        get_env_var(constants.tp_install_env_var_name) + '/lib',
        get_env_var(constants.sal_home_env_var_name) + '/install/lib',
        sal_executable)
    print('Running SAL with command: {}'.format(sal_run_cmd))
    execute_cmd(sal_run_cmd)
    return True
Esempio n. 22
0
def set_stratum_env():
    if not set_sal_env():
        exit(0)
    print('Setting environment for stratum.')
    append_to_env_var(
        constants.ld_lib_path_env_var_name,
        "/{0}/lib:/lib/x86_64-linux-gnu".format(
            get_env_var(constants.sde_install_env_var_name)))
    set_env_var(constants.pi_install_env_var_name,
                get_sde_install_dir_absolute())
    set_env_var(constants.stratum_config_env_var_name,
                get_stratum_config_dir_absolute())
    set_env_var(constants.stratum_home_env_var_name,
                get_stratum_home_absolute())
    # set_env_relative_to_user_home('ONLP_INSTALL', "/onlp-dev_1.0.1_amd64" )
    # required to compile stratum
    set_env_var(constants.bf_sde_install_env_var_name,
                get_sde_install_dir_absolute())

    print('Env for starting Stratum :\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}'.format(
        '{} {}'.format(constants.bf_sde_install_env_var_name,
                       get_env_var(constants.bf_sde_install_env_var_name)),
        '{} {}'.format(constants.ld_lib_path_env_var_name,
                       get_env_var(constants.ld_lib_path_env_var_name)),
        '{} {}'.format(constants.pi_install_env_var_name,
                       get_env_var(constants.pi_install_env_var_name)),
        '{} {}'.format(constants.stratum_config_env_var_name,
                       get_env_var(constants.stratum_config_env_var_name)),
        '{} {}'.format(constants.stratum_home_env_var_name,
                       get_env_var(constants.stratum_home_env_var_name)),
        '{} {}'.format(constants.sal_home_env_var_name,
                       get_env_var(constants.sal_home_env_var_name))))
Esempio n. 23
0
def start_bf_switchd():
    # os.chdir(common.dname)
    print('Starting BF switchd.')
    set_sde_env()
    profile_name = get_sde_profile_name()

    # Check this is an HW and all drivers are loaded
    if profile_name == constants.sde_hw_profile_name and not load_and_verify_kernel_modules(
    ):
        print("ERROR:Some kernel modules are not loaded.")
        exit(0)

    if profile_name == constants.sde_sim_profile_name:
        # TODO Do something meaningful, Possibly launch tofino model in separate shell,
        # Currently This just an interrupt for user to start tofino model.
        input('Make sure that tofino-model is running?')

    p4_prog_name = get_from_setting_dict('BF SDE', 'p4_name')

    # LD_LIBRARY_PATH is set for ONLPv2 case, libs in install/lib folder are
    # not found there but this does not cause any harm for Ubuntu case either.
    # set_env('LD_LIBRARY_PATH', "/{0}/install/lib".format(get_env_var('SDE')))
    # print("LD_LIBRARY_PATH : ")
    # os.system("echo $LD_LIBRARY_PATH")

    if not p4_prog_name:
        print("Starting switchd without p4 program")
        start_switchd_cmd = "sudo {0}/install/bin/bf_switchd --install-dir {" \
                            "0}/install --conf-file {" \
                            "0}/pkgsrc/p4-examples/tofino/tofino_skip_p4.conf" \
                            ".in --skip-p4".format(get_env_var('SDE'))
        if profile_name == constants.sde_hw_profile_name:
            start_switchd_cmd = "sudo -E {0}/run_switchd.sh -c {0}/pkgsrc/p4-examples/tofino/tofino_skip_p4.conf.in --skip-p4".format(
                get_env_var('SDE'))
    else:
        print("Starting switchd with P4 prog:{}".format(p4_prog_name))
        start_switchd_cmd = 'sudo -E {0} /run_switchd.sh -p {1}'.format(
            get_env_var('SDE'), p4_prog_name.replace(".p4", ""))
    username = getpass.getuser()

    if username == "root":
        start_switchd_cmd = start_switchd_cmd.replace("sudo -E", "")
    alloc_dma()
    print("Starting switchd with command : {}".format(start_switchd_cmd))
    os.system(start_switchd_cmd)
Esempio n. 24
0
def set_sde_env():
    print("Setting environment for BF_SDE.")
    sde_home_absolute = get_sde_home_absolute()
    if validate_path_existence(sde_home_absolute, 'SDE'):
        set_env_var(constants.sde_env_var_name, sde_home_absolute)
        set_env_var(constants.sde_install_env_var_name,
                    get_env_var(constants.sde_env_var_name) + '/install/')
        append_to_env_var(
            constants.path_env_var_name,
            get_env_var(constants.sde_install_env_var_name) + '/bin/')
        print(
            'Environment variables set: \n SDE: {0} \n SDE_INSTALL: {1} \n PATH: {2}'
            .format(get_env_var(constants.sde_env_var_name),
                    get_env_var(constants.sde_install_env_var_name),
                    get_env_var(constants.path_env_var_name)))
        return True
    else:
        print('ERROR: SDE directory couldnt be found, exiting .')
        exit(0)
Esempio n. 25
0
def build_sal():
    print('Building SAL...')
    try:
        # TODO Need to fix this in SAL, to use dedicated boost libs.
        os.system('sudo rm -rf {}'.format('/usr/local/include/boost'))
    except FileNotFoundError:
        pass
    os.chdir(get_env_var(constants.sal_home_env_var_name))
    cmake_cmd = 'cmake '

    cmake_cmd += get_env_var(constants.sal_home_env_var_name)
    print('Executing cmake command {}.'.format(cmake_cmd))

    execute_cmd(cmake_cmd)
    execute_cmd(
        'LD_LIBRARY_PATH={0}/lib:$LD_LIBRARY_PATH make -j -C {1}'.format(
            get_env_var(constants.tp_install_env_var_name),
            get_env_var(constants.sal_home_env_var_name)))

    return True
Esempio n. 26
0
def set_sal_runtime_env():
    print("Setting environment for SAL runtime.")
    if not set_sde_env():
        return False
        exit()
    set_env_var(constants.sal_home_env_var_name, sal_rel_dir)
    print('SAL_HOME: {}'.format(get_env_var(constants.sal_home_env_var_name)))
    # set_env_var(constants.gb_src_home_env_var_name, sal_rel_dir)
    # set_env_var(constants.gb_lib_home_env_var_name, sal_rel_dir+'/lib')
    # print('SAL_SRC_HOME: {}'.format(get_env_var(constants.sal_src_home_env_var_name)))
    # print('SAL_LIB_HOME: {}'.format(get_env_var(constants.sal_lib_home_env_var_name)))
    return True
Esempio n. 27
0
def prepare_sal_pkg():
    # TODO - Should clone the code first then prepare release (dev and main)
    #  Build is prepared based on what is present on build machine currently.
    rel_notes_file = 'ReleaseNotes.txt'
    rel_tag_latest = execute_cmd_n_get_output_2(
        'git --git-dir {0}/.git describe --abbrev=0 --tags'.format(
            get_env_var(constants.sal_home_env_var_name))).strip()

    # If only one tag exists then second last release tag refers to previous
    # commit hash to latest release tag.
    release_tag_secondlast = execute_cmd_n_get_output_2(
        'git --git-dir {0}/.git '
        'describe --abbrev=0 '
        '--tags `git rev-list '
        '--tags --skip=1 --max-count=1` --always'.format(
            get_env_var(constants.sal_home_env_var_name))).strip()

    hash_rel_tag_latest = execute_cmd_n_get_output_2(
        'git --git-dir {0}/.git rev-list -n 1 {1}'.format(
            get_env_var(constants.sal_home_env_var_name), rel_tag_latest))

    hash_latest = execute_cmd_n_get_output_2(
        'git --git-dir {0}/.git rev-parse HEAD'.format(
            get_env_var(constants.sal_home_env_var_name)))

    arch_name = None
    start_hash_for_RN = None
    end_hash_for_RN = None

    if hash_latest == hash_rel_tag_latest:
        print('Preparing main release {}'.format(rel_tag_latest))
        print('Preparing release notes since release tag {}'.format(
            release_tag_secondlast))
        start_hash_for_RN = release_tag_secondlast
        end_hash_for_RN = rel_tag_latest
        arch_name = common.release_dir + '/sal_{}'.format(rel_tag_latest)
    else:
        print('Preparing development release.')
        start_hash_for_RN = rel_tag_latest
        end_hash_for_RN = hash_latest
        suffix = execute_cmd_n_get_output_2(
            'git --git-dir {0}/.git describe --tags'.format(
                get_env_var(constants.sal_home_env_var_name))).strip()
        arch_name = common.release_dir + '/sal_{}'.format(suffix)

    os.system(
        'git --git-dir {0}/.git log --pretty=format:%s {2}..{3} > {0}/{1}'.
        format(get_env_var(constants.sal_home_env_var_name), rel_notes_file,
               start_hash_for_RN, end_hash_for_RN))
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) + '/' + rel_notes_file,
        sal_rel_dir + '/' + rel_notes_file)
    shutil.make_archive(arch_name, 'zip', sal_rel_dir)
    print('SAL release is available at {}'.format(common.release_dir))
Esempio n. 28
0
def install_switch_bsp():
    set_sde_env()
    aps_bsp_installation_file = get_aps_bsp_pkg_abs_path()
    if (get_switch_model() == constants.bf6064x_t and (
            'BF2556' in aps_bsp_installation_file or 'bf2556' in aps_bsp_installation_file)) \
            or (get_switch_model() == constants.bf2556x_1t and (
            'BF6064' in aps_bsp_installation_file or 'bf6064' in aps_bsp_installation_file)):
        print("ERROR: Incompatible BSP provided in settings.yaml,"
              " Switch model is {model} but BSP is {bsp}".format(
                  model=get_switch_model(), bsp=aps_bsp_installation_file))
        exit(0)

    print("Installing {}".format(aps_bsp_installation_file))

    os.environ['BSP_INSTALL'] = get_env_var('SDE_INSTALL')
    print("BSP_INSTALL directory set to {}".format(os.environ['BSP_INSTALL']))

    install_bsp_deps()

    import subprocess
    import re
    out = subprocess.check_output("cmake --version", shell=True)
    res = re.search(r'version\s*([\d.]+)', str(out)).group(1)
    if res >= '3.13':
        cmake_cmd = 'cmake -DCMAKE_INSTALL_PREFIX={}'.format(
            get_env_var('SDE_INSTALL'))
        cmake_cmd += ' -B ' + aps_bsp_installation_file
        cmake_cmd += ' -S ' + aps_bsp_installation_file
    else:
        cmake_cmd = 'cmake -DCMAKE_INSTALL_PREFIX={}'.format(
            get_env_var('SDE_INSTALL'))
        cmake_cmd += ' -B' + aps_bsp_installation_file
        cmake_cmd += ' -H' + aps_bsp_installation_file
    execute_cmd(cmake_cmd)
    os.system("make -C {0}".format(aps_bsp_installation_file))
    os.system("make -C {0} install".format(aps_bsp_installation_file))

    return True
Esempio n. 29
0
def execute_sal_tests():
    print("Executing tests from %s." %
          get_env_var(constants.sal_home_env_var_name))

    for dev_ip, sal_grpc_port in get_sal_ip_port_dict().items():
        t = Thread(target=execute_test_cmd,
                   name='SAL Tests thread for device %s ' % dev_ip,
                   args=(
                       dev_ip,
                       sal_grpc_port,
                   ))
        print("Starting %s" % t.name)
        t.start()
    return True
Esempio n. 30
0
def set_sde_env():
    print("Setting environment for BF_SDE.")
    sde_home_absolute = get_sde_home_absolute()
    if validate_path_existence(sde_home_absolute, 'SDE'):
        set_env_var(constants.sde_env_var_name, sde_home_absolute)
        set_env_var(constants.sde_install_env_var_name,
                    get_env_var(constants.sde_env_var_name) + '/install')
        print('Environment variables set: \n SDE: {0} \n SDE_INSTALL: {1}'.
              format(get_env_var(constants.sde_env_var_name),
                     get_env_var(constants.sde_install_env_var_name)))
    else:
        print('ERROR: SDE directory couldnt be found, exiting .')
        exit(0)

    if get_sde_profile_name() == constants.sde_hw_profile_name:
        print('Loading kernel modules.')
        if not load_and_verify_kernel_modules():
            print("ERROR:Some kernel modules are not loaded.")
            exit(0)
    else:
        print('Running simulation, No need to load kernel modules.')

    return True