Example #1
0
def get_tp_install_path_from_settings():
    if not get_from_setting_dict(constants.sal_sw_attr_node,
                                 constants.tp_install_node_name):
        return get_sal_home_from_config() + '/sal_tp_install/'
    else:
        return get_from_setting_dict(constants.sal_sw_attr_node,
                                     constants.tp_install_node_name)
Example #2
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.")
Example #3
0
def take_user_input():
    sal_input = input(
        "SAL : build(b),clean(c),run(r),test(t),install_deps(i),[do_nothing(n)], "
        "Enter one or more action chars in appropriate order i.e. cbr?")

    if 'n' in sal_input or not sal_input:
        # In case user give nasty input like cbrn
        # User meant do nothing in such cases
        return

    for action_char in sal_input:
        if action_char == 'c':
            set_sal_env()
            clean_sal()
        elif action_char == 'r':
            run_sal()
        elif action_char == 't':
            test_sal()
        elif action_char == 'b':
            set_sal_env()
            build_sal()
            prepare_sal_release()
        elif action_char == 'i':
            if get_from_setting_dict(constants.sal_sw_attr_node,
                                     constants.build_third_party_node):
                install_sal_thirdparty_deps()
            else:
                print(
                    'But choose not to build thirdparty SW. Check settings.yaml'
                )
        else:
            print(
                "Invalid action {0} or action doesn't fit with selected profile {1}."
                .format(action_char, get_selected_profile_name()))
Example #4
0
def build_sde():
    sde_tar = tarfile.open(get_sde_pkg_abs_path())
    sde_home_absolute = get_sde_home_absolute()
    sde_build_flags = get_sde_build_flags()

    # Deletion is required otherwise moving the directories
    # in further steps might create issues.
    # And delete only when user have opted for not to resume build
    if sde_build_flags is not None and '-rb' not in sde_build_flags:
        try:
            print("Deleting previous installation at {}.".format(
                sde_home_absolute))
            os.system('sudo rm -rf {}'.format(sde_home_absolute))
        except FileNotFoundError:
            print('{} already deleted.'.format(sde_home_absolute))

    # Extract tar here i.e. in APS one touch directory
    sde_tar.extractall()
    # In case SDE home is configured in yaml other than this directory,
    # If both paths are same following line doesn't cause any problem.
    if not os.path.exists(sde_home_absolute):
        shutil.move(get_sde_dir_name_in_tar(), sde_home_absolute)
    sde_tar.close()
    os.chdir(sde_home_absolute)
    build_opt = "-up"
    p4studio_build_profile = get_from_setting_dict('BF SDE',
                                                   'p4studio_build_profile')

    if get_selected_profile_name() in [
            constants.stratum_hw_profile_name,
            constants.stratum_sim_profile_name
    ]:
        p4studio_build_profile = 'stratum_profile'

    if p4studio_build_profile == "" or p4studio_build_profile is None:
        build_opt = ""
        p4studio_build_profile = ""

    sde_install_cmd = "./p4studio_build/p4studio_build.py {} {}".format(
        build_opt, p4studio_build_profile)

    if sde_build_flags is not None:
        for flag in sde_build_flags:
            if flag:
                sde_install_cmd += ' ' + flag
    else:
        print('No build flag will be used for BF_SDE build.')
    os.environ[
        constants.path_env_var_name] += os.pathsep + sde_home_absolute + \
                                        '/install/bin/'
    print('Building sde with command {}'.format(sde_install_cmd))
    os.system(sde_install_cmd)
    return True
Example #5
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)
Example #6
0
def set_sal_env():
    print("Setting environment for SAL.")
    if not set_sde_env_n_load_drivers():
        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())
    set_env_var(constants.sal_install_env_var_name,
                get_sal_home_absolute() + '/install/')
    if get_from_setting_dict(constants.sal_sw_attr_node,
                             constants.build_third_party_node):
        set_env_var(constants.tp_install_env_var_name,
                    get_env_var(constants.sal_install_env_var_name))
    else:
        set_env_var(constants.tp_install_env_var_name,
                    get_env_var(constants.sde_install_env_var_name))

    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} \
    \n TP_INSTALL: {7}'.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),
                               get_env_var(constants.tp_install_env_var_name)))
    return True
Example #7
0
def get_p4_studio_build_profile_name():
    return get_from_setting_dict('BF SDE', 'p4studio_build_profile')
Example #8
0
def get_sde_modules():
    return get_from_setting_dict(constants.sde_details_node,
                                 constants.sde_modules_node)
Example #9
0
def get_sde_build_flags():
    return get_from_setting_dict(constants.sde_details_node,
                                 constants.sde_build_flags_node)
Example #10
0
def prepare_sal_release():

    try:
        os.mkdir(sal_rel_dir)
        print('SAL release directory {} created.'.format(sal_rel_dir))
    except FileExistsError:
        print('SAL Release directory {} already exists, recreated.'.format(
            sal_rel_dir))
        delete_files(sal_rel_dir)
        os.mkdir(sal_rel_dir)

    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/include/',
        sal_rel_dir + '/include')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/src/include/',
        sal_rel_dir + '/src/include')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/build',
        sal_rel_dir + '/build')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/lib',
        sal_rel_dir + '/lib')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/scripts',
        sal_rel_dir + '/scripts')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/config',
        sal_rel_dir + '/config')
    shutil.copytree(
        get_env_var(constants.sal_home_env_var_name) + '/proto',
        sal_rel_dir + '/proto')
    if get_from_setting_dict(constants.sal_sw_attr_node,
                             constants.build_third_party_node):
        shutil.copytree(
            get_env_var(constants.sal_home_env_var_name) + '/install/lib',
            sal_rel_dir + '/install/lib')
        shutil.copytree(
            get_env_var(constants.sal_home_env_var_name) + '/install/include',
            sal_rel_dir + '/install/include')
        shutil.copytree(
            get_env_var(constants.sal_home_env_var_name) + '/install/bin',
            sal_rel_dir + '/install/bin')
        shutil.copytree(
            get_env_var(constants.sal_home_env_var_name) + '/install/share',
            sal_rel_dir + '/install/share')

    os.mkdir(sal_rel_dir + '/test')
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) + '/README.md',
        sal_rel_dir + '/README.md')
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) +
        '/test/sal_service_test_BF6064.py',
        sal_rel_dir + '/test/sal_service_test_BF6064.py')
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) +
        '/test/sal_service_test_BF2556.py',
        sal_rel_dir + '/test/sal_service_test_BF2556.py')
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) + '/sal_services_pb2.py',
        sal_rel_dir + '/sal_services_pb2.py')
    shutil.copyfile(
        get_env_var(constants.sal_home_env_var_name) +
        '/sal_services_pb2_grpc.py', sal_rel_dir + '/sal_services_pb2_grpc.py')

    print('SAL release is available at {}'.format(sal_rel_dir))
Example #11
0
def get_dut_ips():
    return get_from_setting_dict(constants.sal_sw_attr_node,
                                 constants.dut_ips_node_name)