├── CLI ├── .gitkeep ├── renderer │ ├── scripts │ │ ├── __init__.py │ │ └── acl_jinja2.py │ ├── Makefile │ └── templates │ │ ├── acl_show.j2 │ │ ├── platform_show.j2 │ │ ├── system_show.j2 │ │ ├── system_cpu_show.j2 │ │ ├── show_mclag_iface.j2 │ │ ├── system_processes_show.j2 │ │ ├── lldp_show.j2 │ │ ├── lldp_neighbor_show.j2 │ │ ├── show_interface_status.j2 │ │ ├── show_access_group.j2 │ │ ├── show_interface_counters.j2 │ │ ├── show_mclag_brief.j2 │ │ └── show_access_list.j2 ├── klish │ ├── patches │ │ └── klish-2.1.4 │ │ │ ├── configure.ac.diff │ │ │ ├── clish │ │ │ ├── pargv.h.diff │ │ │ ├── nspace.h.diff │ │ │ ├── command │ │ │ │ ├── private.h.diff │ │ │ │ └── command.c.diff │ │ │ ├── param │ │ │ │ ├── private.h.diff │ │ │ │ ├── paramv.c.diff │ │ │ │ ├── module.am.diff │ │ │ │ └── mgmt_clish_extn_param.c │ │ │ ├── plugin │ │ │ │ ├── module.am.diff │ │ │ │ ├── clish_api.h │ │ │ │ └── mgmt_clish_utils.h │ │ │ ├── shell │ │ │ │ ├── shell_wdog.c.diff │ │ │ │ ├── shell_ptype.c.diff │ │ │ │ ├── shell_new.c.diff │ │ │ │ ├── private.h.diff │ │ │ │ ├── shell_libxml2.c.diff │ │ │ │ └── shell_help.c.diff │ │ │ ├── command.h.diff │ │ │ ├── shell.h.diff │ │ │ ├── ptype │ │ │ │ └── private.h.diff │ │ │ └── ptype.h.diff │ │ │ ├── lub │ │ │ ├── argv.h.diff │ │ │ ├── string.h.diff │ │ │ ├── string │ │ │ │ └── string.c.diff │ │ │ └── argv │ │ │ │ └── argv.c.diff │ │ │ ├── plugins │ │ │ └── clish │ │ │ │ ├── module.am.diff │ │ │ │ ├── private.h.diff │ │ │ │ ├── builtin_init.c.diff │ │ │ │ ├── logging.h │ │ │ │ ├── nos_extn.h │ │ │ │ ├── hook_log.c.diff │ │ │ │ ├── sym_script.c.diff │ │ │ │ └── nos_extn.c │ │ │ ├── tinyrl │ │ │ ├── tinyrl.h.diff │ │ │ ├── history │ │ │ │ └── history.c.diff │ │ │ └── tinyrl.c.diff │ │ │ ├── bin │ │ │ └── clish.c.diff │ │ │ └── mgmt_clish_extn_param.h │ ├── klish-2.1.4.tgz │ ├── clish_start │ └── Makefile ├── clitree │ ├── cli-xml │ │ ├── startup.xml │ │ ├── configure_mode.xml │ │ ├── ip.xml │ │ ├── platform.xml │ │ ├── lldp.xml │ │ ├── ipv6.xml │ │ ├── show_techsupport.xml │ │ ├── system.xml │ │ ├── ipv4.xml │ │ └── enable_mode.xml │ ├── scripts │ │ ├── platform_dummy.xml │ │ ├── klish_preproc_cmdtree.py │ │ └── klish_platform_features_process.sh │ └── Makefile ├── clicfg │ ├── mgmt_clish_entities.xsl │ ├── mgmt_clish_entities_macro.xsl │ ├── mgmt_clish_platform.xml │ ├── mgmt_clish_features.xsl │ └── mgmt_clish_feature_master.xsd ├── Makefile └── actioner │ ├── sonic-cli-lldp.py │ ├── sonic-cli-pfm.py │ ├── cli_log.py │ ├── sonic-cli-show-techsupport.py │ ├── README_cli_client.md │ └── sonic-cli-sys.py ├── models ├── .gitkeep ├── Makefile ├── codegen.config └── yang_to_openapi.mk ├── debian ├── compat ├── .gitignore ├── changelog ├── sonic-mgmt-framework.install ├── rules └── control ├── tools ├── test │ ├── python3_requirements.txt │ ├── apt_requirements.txt │ ├── rest-server.sh │ ├── rest-gotest.sh │ ├── cli.sh │ └── pylint.sh ├── swagger_codegen │ ├── .gitignore │ ├── go-server │ │ ├── templates-nonyang │ │ │ ├── swagger.mustache │ │ │ ├── partial_header.mustache │ │ │ ├── routers.mustache │ │ │ ├── logger.mustache │ │ │ ├── controller-api.mustache │ │ │ ├── main.mustache │ │ │ ├── README.mustache │ │ │ └── model.mustache │ │ ├── templates-yang │ │ │ ├── swagger.mustache │ │ │ ├── routers.mustache │ │ │ └── controller-api.mustache │ │ └── src │ │ │ ├── openapi │ │ │ └── routes.go │ │ │ └── swagger │ │ │ └── routes.go │ └── ui-dist │ │ ├── swagger-ui.css.map │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── index.html_notused │ │ └── oauth2-redirect.html ├── codegen │ └── go-server │ │ ├── templates-yang │ │ ├── routers.j2 │ │ └── controllers-api.j2 │ │ └── src │ │ └── openapi │ │ └── routes.go ├── restconf_doc_tools │ ├── utils │ │ └── json_delta │ │ │ ├── README.md │ │ │ ├── LICENSE │ │ │ └── _patch.py │ └── index.py ├── ui_gen │ ├── templates │ │ ├── landing_html.template │ │ └── swagger_index_html.template │ └── src │ │ └── uigen.py └── openapi_tests │ ├── Makefile │ ├── ietf-snmp.yang │ └── test-rpc.yang ├── .github ├── codeql │ └── codeql-config.yml └── workflows │ ├── semgrep.yml │ └── codeql-analysis.yml ├── .gitignore ├── LICENSE ├── rest ├── main │ └── main_test.go ├── server │ └── req_validate.go └── Makefile ├── go.mod ├── Makefile ├── README.md └── azure-pipelines.yml /CLI/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /CLI/renderer/scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/test/python3_requirements.txt: -------------------------------------------------------------------------------- 1 | mmh3 2 | -------------------------------------------------------------------------------- /tools/swagger_codegen/.gitignore: -------------------------------------------------------------------------------- 1 | openapi-generator-cli-* 2 | -------------------------------------------------------------------------------- /tools/test/apt_requirements.txt: -------------------------------------------------------------------------------- 1 | libcurl4-openssl-dev 2 | libcjson-dev 3 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/configure.ac.diff: -------------------------------------------------------------------------------- 1 | 27a28,29 2 | > AC_PROG_CXX 3 | > 4 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/swagger.mustache: -------------------------------------------------------------------------------- 1 | {{{swagger-yaml}}} -------------------------------------------------------------------------------- /CLI/klish/klish-2.1.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-framework/HEAD/CLI/klish/klish-2.1.4.tgz -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/pargv.h.diff: -------------------------------------------------------------------------------- 1 | 16a17 2 | > typedef clish_pargv_status_e clish_pargv_status_t; 3 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/nspace.h.diff: -------------------------------------------------------------------------------- 1 | 17a18 2 | > typedef clish_nspace_visibility_e clish_nspace_visibility_t; 3 | -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL config" 2 | queries: 3 | - uses: security-and-quality 4 | - uses: security-extended 5 | -------------------------------------------------------------------------------- /tools/swagger_codegen/ui-dist/swagger-ui.css.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":[],"names":[],"mappings":"","file":"swagger-ui.css","sourceRoot":""} -------------------------------------------------------------------------------- /CLI/renderer/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: install 2 | all: 3 | @echo "nothing to install for now" 4 | 5 | clean: 6 | @echo "nothing to clean for now" 7 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/command/private.h.diff: -------------------------------------------------------------------------------- 1 | 26a27,29 2 | > char *test; 3 | > bool_t hidden; 4 | > bool_t enabled; 5 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/lub/argv.h.diff: -------------------------------------------------------------------------------- 1 | 75a76 2 | > bool_t lub_argv__swap_arg(const lub_argv_t * instance,unsigned index1, unsigned index2); 3 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/param/private.h.diff: -------------------------------------------------------------------------------- 1 | 29a30,33 2 | > char *viewname; 3 | > char *viewid; 4 | > bool_t recursive; 5 | > bool_t enabled; 6 | -------------------------------------------------------------------------------- /debian/.gitignore: -------------------------------------------------------------------------------- 1 | .debhelper/ 2 | *.debhelper 3 | *.debhelper.log 4 | *.substvars 5 | sonic-mgmt-framework/ 6 | sonic-mgmt-framework-dbg/ 7 | tmp/ 8 | files 9 | -------------------------------------------------------------------------------- /tools/swagger_codegen/ui-dist/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-framework/HEAD/tools/swagger_codegen/ui-dist/favicon-16x16.png -------------------------------------------------------------------------------- /tools/swagger_codegen/ui-dist/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-framework/HEAD/tools/swagger_codegen/ui-dist/favicon-32x32.png -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/param/paramv.c.diff: -------------------------------------------------------------------------------- 1 | 137c137 2 | < return clish_param__get_defval(res); 3 | --- 4 | > return clish_param__get_default(res); 5 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/lub/string.h.diff: -------------------------------------------------------------------------------- 1 | 272a273,274 2 | > unsigned int lub_string_equal_part_nocase(const char *str1, const char *str2, 3 | > bool_t utf8); 4 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/param/module.am.diff: -------------------------------------------------------------------------------- 1 | 5c5,6 2 | < clish/param/private.h 3 | --- 4 | > clish/param/private.h \ 5 | > clish/param/mgmt_clish_extn_param.c 6 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/plugin/module.am.diff: -------------------------------------------------------------------------------- 1 | 5c5,6 2 | < clish/plugin/private.h 3 | --- 4 | > clish/plugin/private.h \ 5 | > clish/plugin/mgmt_clish_utils.c 6 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/shell_wdog.c.diff: -------------------------------------------------------------------------------- 1 | 5a6 2 | > #include 3 | 20a22 4 | > syslog(LOG_WARNING, "Idle timeout. The session will be closed."); 5 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/module.am.diff: -------------------------------------------------------------------------------- 1 | 20a21,23 2 | > plugins/clish/rest_cl.cpp \ 3 | > plugins/clish/call_pyobj.c \ 4 | > plugins/clish/nos_extn.c \ 5 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/private.h.diff: -------------------------------------------------------------------------------- 1 | 23a24,26 2 | > CLISH_PLUGIN_SYM(clish_restcl); 3 | > CLISH_PLUGIN_SYM(clish_pyobj); 4 | > CLISH_PLUGIN_SYM(clish_setenv); 5 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-yang/swagger.mustache: -------------------------------------------------------------------------------- 1 | {{{ nosemgrepgrep javascript.express.security.audit.xss.mustache.explicit-unescape.template }}} 2 | {{{openapi-yaml}}} 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .vscode 3 | *.code-workspace 4 | pkg/* 5 | build 6 | gopkgs 7 | __pycache__ 8 | *.pyc 9 | *.rdb 10 | *.swp 11 | 12 | *.yin 13 | *.tree 14 | 15 | vendor 16 | models/yangs 17 | 18 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | sonic-mgmt-framework (1.0-01) UNRELEASED; urgency=low 2 | 3 | * Initial release. 4 | 5 | -- Prabhu Sreenivasan Tue, 18 Jun 2019 00:25:19 +0000 6 | -------------------------------------------------------------------------------- /CLI/renderer/templates/acl_show.j2: -------------------------------------------------------------------------------- 1 | {% set acl_sets = acl_out['openconfig_aclacl']['acl_sets']['acl_set'] %} 2 | {% for acl_set in acl_sets %} 3 | Name: {{ acl_set['state']['description'] }} 4 | {% endfor %} 5 | -------------------------------------------------------------------------------- /debian/sonic-mgmt-framework.install: -------------------------------------------------------------------------------- 1 | build/rest_server/rest_server usr/sbin 2 | build/rest_server/generate_cert usr/sbin 3 | build/rest_server/dist/ui etc/rest_server 4 | build/cli usr/sbin 5 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ --with systemd --parallel 4 | 5 | 6 | override_dh_shlibdeps: 7 | dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info -l$(shell pwd)/build/cli/target/.libs/:$(shell pwd)/build/cli/.libs/ 8 | -------------------------------------------------------------------------------- /CLI/renderer/templates/platform_show.j2: -------------------------------------------------------------------------------- 1 | {{'-----------------------------------------------------------'}} 2 | {{'Attribute'.ljust(20)}} {{'Value/State'}} 3 | {{'-----------------------------------------------------------'}} 4 | {% for key,value in json_output.items() %} 5 | {{key.ljust(20)}}:{{value}} 6 | {% endfor %} 7 | 8 | -------------------------------------------------------------------------------- /CLI/renderer/templates/system_show.j2: -------------------------------------------------------------------------------- 1 | {{'-----------------------------------------------------------'}} 2 | {{'Attribute'.ljust(20)}} {{'Value/State'}} 3 | {{'-----------------------------------------------------------'}} 4 | {% for key,value in json_output.items() %} 5 | {{key.ljust(20)}}:{{value}} 6 | {% endfor %} 7 | 8 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/builtin_init.c.diff: -------------------------------------------------------------------------------- 1 | 9a10 2 | > #include "nos_extn.h" 3 | 32a34,38 4 | > clish_plugin_add_psym(plugin, clish_restcl, "clish_restcl"); 5 | > clish_plugin_add_psym(plugin, clish_pyobj, "clish_pyobj"); 6 | > clish_plugin_add_psym(plugin, clish_setenv, "clish_setenv"); 7 | > 8 | > nos_extn_init(); 9 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/command.h.diff: -------------------------------------------------------------------------------- 1 | 78a79,83 2 | > char *clish_command__get_test(const clish_command_t *instance); 3 | > void clish_command__set_hidden(clish_command_t * instance, bool_t hidden); 4 | > bool_t clish_command__get_hidden(const clish_command_t * instance); 5 | > void clish_command__set_enabled(clish_command_t * instance, bool_t enabled); 6 | > bool_t clish_command__get_enabled(const clish_command_t * instance); 7 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/tinyrl/tinyrl.h.diff: -------------------------------------------------------------------------------- 1 | 224a225,236 2 | > extern void tinyrl_complete_ignore_error(tinyrl_t * instance); 3 | > /** 4 | > * Indicate whether the cursor is in middle or not 5 | > */ 6 | > extern bool_t 7 | > tinyrl_is_cursor_in_middle( 8 | > /** 9 | > * The instance on which to operate 10 | > */ 11 | > const tinyrl_t *instance 12 | > ); 13 | > 14 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/logging.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOGGING_H__ 2 | #define __LOGGING_H__ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef SYSLOG_TO_STDOUT 8 | 9 | #define syslog(LEVEL, FMT, ARGS...) \ 10 | do { \ 11 | if (LEVEL < LOG_DEBUG || getenv("DEBUG")) { \ 12 | printf("[%s] " FMT "\n", #LEVEL, ##ARGS); \ 13 | } \ 14 | } while(0) 15 | 16 | #endif 17 | 18 | #endif // __LOGGING_H__ 19 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/partial_header.mustache: -------------------------------------------------------------------------------- 1 | /* 2 | {{#appName}} 3 | * {{{appName}}} 4 | * 5 | {{/appName}} 6 | {{#appDescription}} 7 | * {{{appDescription}}} 8 | * 9 | {{/appDescription}} 10 | {{#version}} 11 | * API version: {{{version}}} 12 | {{/version}} 13 | {{#infoEmail}} 14 | * Contact: {{{infoEmail}}} 15 | {{/infoEmail}} 16 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 17 | */ 18 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/shell_ptype.c.diff: -------------------------------------------------------------------------------- 1 | 37c37,39 2 | < clish_ptype_method_e method, clish_ptype_preprocess_e preprocess) 3 | --- 4 | > clish_ptype_method_e method, clish_ptype_preprocess_e preprocess, 5 | > const char *ext_pattern, const char *ext_help, const char *alt_ext_pattern, 6 | > const char *alt_pattern) 7 | 44c46,47 8 | < method, preprocess); 9 | --- 10 | > method, preprocess, ext_pattern, ext_help, 11 | > alt_ext_pattern, alt_pattern); 12 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/shell_new.c.diff: -------------------------------------------------------------------------------- 1 | 24a25 2 | > char lock_file[PATH_MAX]; 3 | 51a53,58 4 | > /* Create lock file */ 5 | > snprintf(lock_file, sizeof(lock_file), 6 | > "%s.%u", CLISH_LOCK_PATH, getpid()); 7 | > lock_file[sizeof(lock_file) - 1] = '\0'; 8 | > this->lockfile = lub_string_dup(lock_file); 9 | > 10 | 67d73 11 | < this->lockfile = lub_string_dup(CLISH_LOCK_PATH); 12 | 89c95 13 | < CLISH_PTYPE_PRE_NONE); 14 | --- 15 | > CLISH_PTYPE_PRE_NONE, NULL, NULL, NULL, NULL); 16 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | name: Semgrep 2 | 3 | on: 4 | pull_request: {} 5 | push: 6 | branches: 7 | - master 8 | - '201[7-9][0-1][0-9]' 9 | - '202[0-9][0-1][0-9]' 10 | 11 | jobs: 12 | semgrep: 13 | if: github.repository_owner == 'sonic-net' 14 | name: Semgrep 15 | runs-on: ubuntu-latest 16 | container: 17 | image: returntocorp/semgrep 18 | steps: 19 | - uses: actions/checkout@v3 20 | - run: semgrep ci 21 | env: 22 | SEMGREP_RULES: p/default 23 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/bin/clish.c.diff: -------------------------------------------------------------------------------- 1 | 41a42,43 2 | > #include 3 | > 4 | 48a51,56 5 | > bool _nos_use_alt_name = false; 6 | > 7 | > bool nos_use_alt_name() { 8 | > return _nos_use_alt_name; 9 | > } 10 | > 11 | 88a97,101 12 | > char *mode = getenv("SONIC_CLI_IFACE_MODE"); 13 | > if (mode) { 14 | > _nos_use_alt_name = (strcmp(mode, "standard") == 0); 15 | > } 16 | > 17 | 307c320 18 | < clish_shell__set_idle_timeout(shell, timeout); 19 | --- 20 | > clish_shell__set_timeout(shell, timeout); 21 | -------------------------------------------------------------------------------- /tools/codegen/go-server/templates-yang/routers.j2: -------------------------------------------------------------------------------- 1 | 2 | package openapi 3 | 4 | import ( 5 | "github.com/Azure/sonic-mgmt-framework/rest/server" 6 | ) 7 | 8 | func init() { 9 | 10 | {% for operationId in OpIds %} 11 | {% set path = OpIdDict[operationId]["path"] %} 12 | {% set pathEntry = OpIdDict[operationId]["obj"] %} 13 | {% set method = OpIdDict[operationId]["method"] %} 14 | server.AddRoute( 15 | "{{ operationId }}", 16 | "{{ method|capitalize }}", 17 | "{{ path }}", 18 | {{ operationId }}, 19 | ) 20 | 21 | {% endfor %} 22 | } -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell.h.diff: -------------------------------------------------------------------------------- 1 | 100c100,102 2 | < clish_ptype_preprocess_e preprocess); 3 | --- 4 | > clish_ptype_preprocess_e preprocess, 5 | > const char *ext_pattern, const char *ext_help, 6 | > const char *alt_ext_pattern, const char *alt_pattern); 7 | 103c105 8 | < void clish_shell_help(clish_shell_t * instance, const char *line); 9 | --- 10 | > void clish_shell_help(clish_shell_t * instance, const char *line, clish_context_t *context); 11 | 190a193 12 | > void clish_shell__set_timeout(clish_shell_t *instance, int timeout); 13 | -------------------------------------------------------------------------------- /tools/restconf_doc_tools/utils/json_delta/README.md: -------------------------------------------------------------------------------- 1 | 2 | Credits to Philip J. Roberts(himself@phil-roberts.name) 3 | 4 | JSON Delta(json_delta) has been taken from below link 5 | https://files.pythonhosted.org/packages/aa/b6/cdc4ccf3923651cb42797b4c703b77a626014f3ebe3fdee7858a38e0a82e/json_delta-2.0.2.tar.gz 6 | 7 | Open-source base Version: 2.0.2 8 | 9 | Change log: 10 | 11 | Date|Author|Description| 12 | ----|------|-----------| 13 | 25-JUNE-2021 | Mohammed Faraaz C | Fixed invalid JSON rendering, when output format is udiff. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/plugin/clish_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * filename: clish_api.h 3 | * (c) Copyright 2020 Dell EMC All Rights Reserved. 4 | * 5 | * Dell EMC extension over klish to implement an API for parsing XML input 6 | * CLISH library extension header file 7 | */ 8 | #ifndef __clish_api_H__ 9 | #define __clish_api_H__ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define HOSTNAME_STR_LEN 65 16 | #define PROMPT_STR_LEN 150 17 | #define CLISH_DO_CMD "do" 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-yang/routers.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "github.com/Azure/sonic-mgmt-framework/rest/server" 6 | ) 7 | 8 | func init() { 9 | {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} 10 | server.AddRoute( 11 | "{{operationId}}", 12 | "{{httpMethod}}", 13 | {{{ nosemgrepgrep javascript.express.security.audit.xss.mustache.explicit-unescape.template }}} 14 | "{{{path}}}", 15 | {{operationId}}, 16 | ) 17 | {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} 18 | } 19 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/routers.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "github.com/Azure/sonic-mgmt-framework/rest/server" 6 | ) 7 | 8 | func init() { 9 | {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} 10 | server.AddRoute( 11 | "{{operationId}}", 12 | "{{httpMethod}}", 13 | {{{ nosemgrepgrep javascript.express.security.audit.xss.mustache.explicit-unescape.template }}} 14 | "{{{path}}}", 15 | {{operationId}}, 16 | ) 17 | {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Microsoft, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/logger.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | import ( 5 | "log" 6 | "net/http" 7 | "time" 8 | ) 9 | 10 | func Logger(inner http.Handler, name string) http.Handler { 11 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 12 | start := time.Now() 13 | 14 | inner.ServeHTTP(w, r) 15 | 16 | log.Printf( 17 | "%s %s %s %s", 18 | r.Method, 19 | r.RequestURI, 20 | name, 21 | time.Since(start), 22 | ) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /CLI/klish/clish_start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export SONIC_MGMT_ROOT=/usr/sbin 4 | export SONIC_CLI_ROOT=$SONIC_MGMT_ROOT/cli 5 | if [ -z $SYSTEM_NAME ] 6 | then 7 | export SYSTEM_NAME="${HOSTNAME%%.*}" 8 | fi 9 | 10 | export PYTHONPATH=/usr/sbin/cli:/usr/sbin/cli/scripts:/usr/sbin 11 | export RENDERER_TEMPLATE_PATH=$SONIC_CLI_ROOT/render-templates 12 | export CLISH_PATH=$SONIC_CLI_ROOT/command-tree 13 | export LD_LIBRARY_PATH=/usr/local/lib:$SONIC_CLI_ROOT/.libs:$LD_LIBRARY_PATH 14 | export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin:$SONIC_CLI_ROOT 15 | 16 | export KLISH_CLI_USER=$CLI_USER 17 | 18 | $SONIC_CLI_ROOT/clish -o "$@" 19 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/nos_extn.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __NOS_EXTN_H__ 3 | #define __NOS_EXTN_H__ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void pyobj_init(); 10 | extern void nos_extn_init(); 11 | 12 | extern int call_pyobj(char *cmd, const char *buff, char **out); 13 | extern int pyobj_set_rest_token(const char*); 14 | extern int pyobj_update_environ(const char *key, const char *val); 15 | 16 | extern void rest_client_init(); 17 | extern int rest_token_fetch(int *interval); 18 | extern int rest_cl(char *cmd, const char *buff); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: sonic-mgmt-framework 2 | Maintainer: Prabhu Sreenivasan 3 | Build-Depends: debhelper (>= 8.0.0), 4 | debhelper (>= 10~) | dh-systemd, 5 | Standards-Version: 3.9.3 6 | Section: net 7 | 8 | Package: sonic-mgmt-framework 9 | Priority: extra 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Description: SONiC Management Framework 13 | 14 | Package: sonic-mgmt-framework-dbg 15 | Priority: extra 16 | Architecture: any 17 | Section: debug 18 | Depends: sonic-mgmt-framework (=${binary:Version}) 19 | Description: debugging symbols for SONiC Management Framework 20 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/hook_log.c.diff: -------------------------------------------------------------------------------- 1 | diff --git a/plugins/clish/hook_log.c b/plugins/clish/hook_log.c 2 | index cafd29e..da59419 100644 3 | --- a/plugins/clish/hook_log.c 4 | +++ b/plugins/clish/hook_log.c 5 | @@ -37,8 +37,9 @@ CLISH_HOOK_LOG(clish_hook_log) 6 | if (!(uname = getenv("LOGNAME"))) 7 | uname = user ? user->pw_name : "unknown"; 8 | } 9 | - syslog(LOG_INFO, "%u(%s) %s : %d", 10 | - user ? user->pw_uid : getuid(), uname, line, retcode); 11 | + 12 | + int facility = LOG_LOCAL4; 13 | + syslog(LOG_INFO|facility, "User \"%s\" command \"%s\" status - %s", uname, line, retcode ? "failure" : "success"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/lub/string/string.c.diff: -------------------------------------------------------------------------------- 1 | 236a237,261 2 | > unsigned int lub_string_equal_part_nocase(const char *str1, const char *str2, 3 | > bool_t utf8) 4 | > { 5 | > unsigned int cnt = 0; 6 | > 7 | > if (!str1 || !str2) 8 | > return cnt; 9 | > while (*str1 && *str2) { 10 | > if (tolower(*str1) != tolower(*str2)) 11 | > break; 12 | > cnt++; 13 | > str1++; 14 | > str2++; 15 | > } 16 | > if (!utf8) 17 | > return cnt; 18 | > 19 | > /* UTF8 features */ 20 | > if (cnt && (UTF8_11 == (*(str1 - 1) & UTF8_MASK))) 21 | > cnt--; 22 | > 23 | > return cnt; 24 | > } 25 | > 26 | > /*--------------------------------------------------------- */ 27 | 260d284 28 | < 29 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/ptype/private.h.diff: -------------------------------------------------------------------------------- 1 | 5a6 2 | > #include "clish/ptype.h" 3 | 18a20 4 | > lub_argv_t *ext_help; 5 | 26a29,37 6 | > typedef struct clish_ptype_regexp_select_s clish_ptype_regexp_select_t; 7 | > struct clish_ptype_regexp_select_s { 8 | > regex_t regexp; 9 | > regex_t alt_regexp; 10 | > lub_argv_t *items; 11 | > lub_argv_t *ext_help; 12 | > lub_argv_t *alt_items; 13 | > }; 14 | > 15 | 30a42,47 16 | > 17 | > char *ext_pattern; 18 | > char *ext_help; 19 | > char *alt_ext_pattern; 20 | > char *alt_pattern; 21 | > help_type_t usename; 22 | 38a56 23 | > clish_ptype_regexp_select_t regexp_select; 24 | -------------------------------------------------------------------------------- /CLI/renderer/templates/system_cpu_show.j2: -------------------------------------------------------------------------------- 1 | {{'----------------------------------------------------------------------'}} 2 | {{'CPU'.ljust(20)}}{{'%KERNEL'.ljust(20)}}{{'%USER'.ljust(20)}}{{'%IDLE'}} 3 | {{'----------------------------------------------------------------------'}} 4 | {% for cpu in json_output %} 5 | {% if (cpu['index'] != '0') %} 6 | {% set index = (cpu['index'] | string) %} 7 | {% else %} 8 | {% set index = (('total') | string) %} 9 | {% endif %} 10 | {{('CPU-'+ index).ljust(20)}} {{(cpu['state']['kernel']['instant'] | string).ljust(20)}} {{(cpu['state']['user']['instant'] | string).ljust(20)}} {{(cpu['state']['idle']['instant'] | string)}} 11 | {% endfor %} 12 | 13 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/controller-api.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | {{#operations}} 5 | import ( 6 | "net/http" 7 | 8 | "github.com/Azure/sonic-mgmt-framework/rest/server" 9 | ){{#operation}} 10 | 11 | func {{nickname}}(w http.ResponseWriter, r *http.Request) { 12 | rc, r := server.GetContext(r) 13 | rc.Name = "{{operationId}}" 14 | {{#consumes}} 15 | rc.Consumes.Add("{{mediaType}}") 16 | {{/consumes}} 17 | {{#produces}} 18 | rc.Produces.Add("{{mediaType}}") 19 | {{/produces}} 20 | {{#bodyParam.required}} 21 | rc.Model = &{{bodyParam.dataType}}{} 22 | {{/bodyParam.required}} 23 | server.Process(w, r) 24 | }{{/operation}}{{/operations}} 25 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/main.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package main 3 | 4 | import ( 5 | "flag" 6 | "fmt" 7 | "log" 8 | "net/http" 9 | 10 | // WARNING! 11 | // Change this to a fully-qualified import path 12 | // once you place this file into your project. 13 | // For example, 14 | // 15 | // sw "github.com/myname/myrepo/{{apiPath}}" 16 | // 17 | sw "./{{apiPath}}" 18 | ) 19 | 20 | func main() { 21 | var port int 22 | 23 | flag.IntVar(&port, "port", {{serverPort}}, "Listen port") 24 | flag.Parse() 25 | 26 | address := fmt.Sprintf(":%d", port) 27 | 28 | log.Printf("Server started on %s", address) 29 | 30 | router := sw.NewRouter() 31 | 32 | log.Fatal(http.ListenAndServe(address, router)) 33 | } 34 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/private.h.diff: -------------------------------------------------------------------------------- 1 | 13a14 2 | > #define IFACE_CMD "interface" 3 | 44a46 4 | > char *commandstr; 5 | 121c123,124 6 | < const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv); 7 | --- 8 | > const char *line, const clish_command_t ** cmd, clish_pargv_t ** pargv, 9 | > clish_context_t *orig_context, unsigned *err_len); 10 | 127c130,131 11 | < unsigned *idx, clish_pargv_t *last, unsigned need_index); 12 | --- 13 | > unsigned *idx, clish_pargv_t *last, unsigned need_index, 14 | > unsigned *err_index, unsigned *strmatchLen); 15 | 131c135 16 | < instance, const char *line); 17 | --- 18 | > instance, const char *line, clish_context_t *context); 19 | 147a152 20 | > bool_t clish_shell_command_test(const clish_command_t *cmd, void *context); 21 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-yang/controller-api.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | 4 | {{#operations}} 5 | import ( 6 | "net/http" 7 | 8 | "github.com/Azure/sonic-mgmt-framework/rest/server" 9 | ){{#operation}} 10 | 11 | func {{nickname}}(w http.ResponseWriter, r *http.Request) { 12 | rc, r := server.GetContext(r) 13 | rc.Name = "{{operationId}}" 14 | {{#consumes}} 15 | rc.Consumes.Add("{{mediaType}}") 16 | {{/consumes}} 17 | {{#produces}} 18 | rc.Produces.Add("{{mediaType}}") 19 | {{/produces}} 20 | {{#vendorExtensions}} 21 | {{#x-params}} 22 | rc.PMap = server.NameMap{ {{#varMapping}}"{{uriName}}":"{{yangName}}", {{/varMapping}} } 23 | {{/x-params}} 24 | {{/vendorExtensions}} 25 | server.Process(w, r) 26 | }{{/operation}}{{/operations}} 27 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/mgmt_clish_extn_param.h: -------------------------------------------------------------------------------- 1 | /* 2 | * filename: mgmt_clish_extn_param.h 3 | * (c) Copyright 2020 Dell EMC All Rights Reserved. 4 | * 5 | * APIs to set and get the new attributes added to the klish PARAM option 6 | */ 7 | 8 | /** OPENSOURCELICENSE */ 9 | 10 | #ifndef _mgmt_clish_extn_param_h 11 | #define _mgmt_clish_extn_param_h 12 | 13 | /* SET */ 14 | void clish_param__set_viewname(clish_param_t * instance, char *viewname); 15 | void clish_param__set_viewid(clish_param_t * instance, char *viewid); 16 | void clish_param__set_recursive(clish_param_t * instance, bool_t recursive); 17 | 18 | /* GET */ 19 | const char *clish_param__get_viewname(const clish_param_t * instance); 20 | const char *clish_param__get_viewid(const clish_param_t * instance); 21 | bool_t clish_param__get_recursive(const clish_param_t * instance); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_mclag_iface.j2: -------------------------------------------------------------------------------- 1 | {% set vars = {'if_name': ""} %} 2 | {% set mclag_iface_info = json_output %} 3 | 4 | {% if mclag_iface_info -%} 5 | {% for key in mclag_iface_info %} 6 | {{ ' ' }} 7 | {% if vars.update({'if_name':mclag_iface_info[key]["if_name"]}) %}{% endif %} 8 | {% if vars.update({'local_if_status':mclag_iface_info[key]["local_if_status"]}) %}{% endif %} 9 | {% if vars.update({'remote_if_status':mclag_iface_info[key]["remote_if_status"]}) %}{% endif %} 10 | {% if vars.update({'traffic_disable':mclag_iface_info[key]["traffic_disable"]}) %}{% endif %} 11 | {% if vars.update({'port_isolate':mclag_iface_info[key]["port_isolate"]}) %}{% endif %} 12 | 13 | {{'Local/Remote Status'.ljust(20)}} : {{vars.local_if_status}}{{'/'}}{{vars.remote_if_status}} 14 | {{'TrafficDisable'.ljust(20)}} : {{ vars.traffic_disable}} 15 | {{'IsolateWithPeerLink'.ljust(20)}} : {{ vars.port_isolate}} 16 | {% endfor %} 17 | {% endif %} 18 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/tinyrl/history/history.c.diff: -------------------------------------------------------------------------------- 1 | 14a15 2 | > #include "clish/plugin/mgmt_clish_utils.h" 3 | 138,146c139,140 4 | < for (i = 0; i < this->length; i++) { 5 | < tinyrl_history_entry_t *entry = this->entries[i]; 6 | < if (0 == strcmp(line, tinyrl_history_entry__get_line(entry))) { 7 | < free_entries(this, i, i); 8 | < remove_entries(this, i, i); 9 | < result = BOOL_TRUE; 10 | < break; 11 | < } 12 | < } 13 | --- 14 | > /* We don't want to remove duplicates from the history, 15 | > hence returning false immediately*/ 16 | 203a198,200 17 | > char *masked_line = NULL; 18 | > mask_password(line, &masked_line); 19 | > if (!masked_line) return; 20 | 205c202 21 | < add_n_replace(this, line); 22 | --- 23 | > add_n_replace(this, (const char*)masked_line); 24 | 207c204 25 | < add_n_grow(this, line); 26 | --- 27 | > add_n_grow(this, (const char*)masked_line); 28 | 208a206 29 | > if(masked_line) free(masked_line); 30 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/README.mustache: -------------------------------------------------------------------------------- 1 | # Go API Server for {{packageName}} 2 | 3 | {{#appDescription}} 4 | {{{appDescription}}} 5 | {{/appDescription}} 6 | 7 | ## Overview 8 | This server was generated by the [swagger-codegen] 9 | (https://github.com/swagger-api/swagger-codegen) project. 10 | By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. 11 | - 12 | 13 | To see how to make this your own, look here: 14 | 15 | [README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) 16 | 17 | - API version: {{appVersion}}{{^hideGenerationTimestamp}} 18 | - Build date: {{generatedDate}}{{/hideGenerationTimestamp}} 19 | {{#infoUrl}} 20 | For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) 21 | {{/infoUrl}} 22 | 23 | 24 | ### Running the server 25 | To run the server, follow these simple steps: 26 | 27 | ``` 28 | go run main.go 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/sym_script.c.diff: -------------------------------------------------------------------------------- 1 | diff --git a/plugins/clish/sym_script.c b/plugins/clish/sym_script.c 2 | index 93cc88f..7dee09b 100644 3 | --- a/plugins/clish/sym_script.c 4 | +++ b/plugins/clish/sym_script.c 5 | @@ -37,6 +37,10 @@ CLISH_PLUGIN_OSYM(clish_script) 6 | if (!script) /* Nothing to do */ 7 | return 0; 8 | 9 | + char *cmd = clish_shell__get_full_line(clish_context); 10 | + setenv("USER_COMMAND", cmd, 1); 11 | + lub_string_free(cmd); 12 | + 13 | /* Find out shebang */ 14 | if (action) 15 | shebang = clish_action__get_shebang(action); 16 | @@ -80,6 +84,12 @@ CLISH_PLUGIN_OSYM(clish_script) 17 | lub_string_cat(&command, shebang); 18 | lub_string_cat(&command, " "); 19 | lub_string_cat(&command, fifo_name); 20 | + lub_string_cat(&command, " 2> /dev/stdout"); 21 | + 22 | + sigset_t sigs; 23 | + sigemptyset(&sigs); 24 | + sigaddset(&sigs, SIGINT); 25 | + sigprocmask(SIG_UNBLOCK, &sigs, NULL); 26 | 27 | res = system(command); 28 | 29 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/startup.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CLI/clicfg/mgmt_clish_entities.xsl: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | <!ENTITY ""> 25 | 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For more infomation, please visit: https://github.com/github/codeql-action 2 | 3 | name: "CodeQL" 4 | 5 | on: 6 | push: 7 | branches: 8 | - 'master' 9 | - '202[0-9][0-9][0-9]' 10 | pull_request_target: 11 | branches: 12 | - 'master' 13 | - '202[0-9][0-9][0-9]' 14 | 15 | jobs: 16 | analyze: 17 | name: Analyze 18 | runs-on: ubuntu-latest 19 | permissions: 20 | actions: read 21 | contents: read 22 | security-events: write 23 | 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | language: [ 'python','go' ] 28 | 29 | steps: 30 | - name: Checkout repository 31 | uses: actions/checkout@v3 32 | 33 | # Initializes the CodeQL tools for scanning. 34 | - name: Initialize CodeQL 35 | uses: github/codeql-action/init@v2 36 | with: 37 | config-file: ./.github/codeql/codeql-config.yml 38 | languages: ${{ matrix.language }} 39 | 40 | - name: Perform CodeQL Analysis 41 | uses: github/codeql-action/analyze@v2 42 | with: 43 | category: "/language:${{matrix.language}}" 44 | -------------------------------------------------------------------------------- /CLI/renderer/templates/system_processes_show.j2: -------------------------------------------------------------------------------- 1 | {% set just_var = 10 %} 2 | {{'--------------------------------------------------------------------------'}} 3 | {{'PID'.ljust(just_var)}}{{'%CPU'.ljust(just_var)}}{#{{'CPU-TICKS-USER'.ljust(just_var)}}{{'CPU-TICKS-SYSTEM'.ljust(just_var)}}#}{{'%MEMORY'.ljust(just_var)}}{{'MEM-USAGE(Bytes)'.ljust(just_var)}}{#{{'START-TIME'.ljust(just_var)}}{{'UP-TIME'.ljust(just_var)}}#}{{'NAME'.rjust(just_var)}} 4 | {{'--------------------------------------------------------------------------'}} 5 | {% for process in json_output %} 6 | {%set name = (process['state']['name'] | string).split(' ')%} 7 | {{(process['pid'] | string).ljust(just_var)}} {{(process['state']['cpu-utilization'] | string).ljust(just_var)}} {#{{(process['state']['cpu-usage-user'] | string).ljust(just_var)}} {{(process['state']['cpu-usage-system'] | string).ljust(just_var)}}#} {{(process['state']['memory-utilization'] | string).ljust(just_var)}} {{(process['state']['memory-usage'] | string).ljust(just_var)}} {#{{(process['state']['start-time'] | string).ljust(10)}} {{(process['state']['uptime'] | string).ljust(just_var)}}#} {{name[0]}} 8 | {% endfor %} 9 | 10 | -------------------------------------------------------------------------------- /CLI/renderer/templates/lldp_show.j2: -------------------------------------------------------------------------------- 1 | {{'------------------------------------------------------------------------------------------------------'}} 2 | {{'LocalPort'.ljust(20)}}{{'RemoteDevice'.ljust(20)}}{{'RemotePortID'.ljust(20)}}{{'Capability'.ljust(20)}} {{'RemotePortDescr'}} 3 | {{'-------------------------------------------------------------------------------------------------------'}} 4 | {% set cap_dict = {'openconfig-lldp-types:REPEATER' : 'O','openconfig-lldp-types:MAC_BRIDGE' : 'B' , 'openconfig-lldp-types:ROUTER' : 'R'} %} 5 | {% for neigh in json_output %} 6 | {% set capabilities = neigh['neighbors']['neighbor'][0]['capabilities']['capability'] %} 7 | {% set cap_list = [] %} 8 | {% for cap in capabilities %} 9 | {% if cap['state']['name'] in cap_dict %} 10 | {% if cap['state']['enabled'] == true %} 11 | {% do cap_list.append(cap_dict[cap['state']['name']]) %} 12 | {% endif %} 13 | {% endif %} 14 | {% endfor %} 15 | {% set value = neigh['neighbors']['neighbor'][0] %} 16 | {{value['id'].ljust(20)}}{{value['state']['system-name'].ljust(20)}}{{value['state']['port-id'].ljust(20)}}{{(cap_list | join() | string).ljust(20)}}{{value['state']['port-description'].ljust(20)}} 17 | {% endfor %} 18 | 19 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/command/command.c.diff: -------------------------------------------------------------------------------- 1 | 43a44,46 2 | > this->test = NULL; 3 | > this->hidden = BOOL_FALSE; 4 | > this->enabled = BOOL_FALSE; 5 | 305a309,340 6 | > 7 | > /*--------------------------------------------------------- */ 8 | > char *clish_command__get_test(const clish_command_t *this) 9 | > { 10 | > return this->test; 11 | > } 12 | > 13 | > /*--------------------------------------------------------- */ 14 | > void clish_command__set_hidden(clish_command_t * this, bool_t hidden) 15 | > { 16 | > this->hidden = hidden; 17 | > } 18 | > 19 | > /*--------------------------------------------------------- */ 20 | > bool_t clish_command__get_hidden(const clish_command_t * this) 21 | > { 22 | > return this->hidden; 23 | > } 24 | > 25 | > 26 | > /*--------------------------------------------------------- */ 27 | > void clish_command__set_enabled(clish_command_t * this, bool_t enabled) 28 | > { 29 | > this->enabled = enabled; 30 | > } 31 | > 32 | > /*--------------------------------------------------------- */ 33 | > bool_t clish_command__get_enabled(const clish_command_t * this) 34 | > { 35 | > return BOOL_TRUE; 36 | > } 37 | > 38 | -------------------------------------------------------------------------------- /CLI/clicfg/mgmt_clish_entities_macro.xsl: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /CLI/renderer/templates/lldp_neighbor_show.j2: -------------------------------------------------------------------------------- 1 | {{'-----------------------------------------------------------'}} 2 | {{'LLDP Neighbors'.ljust(20)}} 3 | {{'-----------------------------------------------------------'}} 4 | {% for neigh in json_output %} 5 | {% set value = neigh['neighbors']['neighbor'][0] %} 6 | {{'Interface:'}}{{' '}}{{value['id']}}{{',via:'}}{{' LLDP'}} 7 | {{' Chassis:'}} 8 | {{' ChassisID: '}}{{value['state']['chassis-id']}} 9 | {{' SysName: '}}{{value['state']['system-name']}} 10 | {% set desc = value['state']['system-description'].split('\r\n')[1:] %} 11 | {{' SysDescr: '}}{{value['state']['system-description'].split('\r\n')[0]}} 12 | {% for v in desc %} 13 | {{' '}}{{v}} 14 | {% endfor %} 15 | {% for cap in value['capabilities']['capability'] %} 16 | {% if cap['state']['enabled'] == true %} 17 | {% set en = 'ON' %} 18 | {% endif %} 19 | {% if cap['state']['enabled'] == false %} 20 | {% set en = 'OFF' %} 21 | {% endif %} 22 | {{' Capability: '}}{{cap['name'].split(':')[1]}}{{', '}}{{en}} 23 | {% endfor %} 24 | {{' Port'}} 25 | {{' PortID: '}}{{value['state']['port-id']}} 26 | {{' PortDescr: '}}{{value['state']['port-description']}} 27 | {{'-----------------------------------------------------------'}} 28 | {% endfor %} 29 | 30 | -------------------------------------------------------------------------------- /tools/ui_gen/templates/landing_html.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SONiC REST UI 7 | 8 | 9 | 29 | 30 | 31 |
32 |

SONiC REST API explorer

33 |

Please click on any of the links below to explore its corresponding REST APIs 34 | 35 | 36 | 37 | 38 | 39 | {% for yaml in yamlList %} 40 | 41 | 42 | 43 | 44 | {% endfor %} 45 |
ModelDescription
{{yaml}}REST APIs for {{yaml}}
46 |

47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /tools/ui_gen/src/uigen.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | import os 3 | import glob 4 | from jinja2 import Environment, FileSystemLoader 5 | 6 | currentDir = os.path.dirname(os.path.realpath(__file__)) 7 | templateEnv = Environment(loader=FileSystemLoader(os.path.join(currentDir,'../templates')),trim_blocks=True,lstrip_blocks=True) 8 | yamlDir = os.path.join(currentDir, '../../../build/rest_server/dist/ui') 9 | yamlFilesList = glob.glob(os.path.join(yamlDir,'*.yaml')) 10 | yamlList = sorted(list(map(lambda x: os.path.splitext(os.path.basename(x))[0], yamlFilesList))) 11 | 12 | #Generate Swagger index.html file 13 | swaggerIndexHtmlStr = templateEnv.\ 14 | get_template('swagger_index_html.template').\ 15 | render(yamlList=yamlList) 16 | 17 | #Generate landing page landing.html file 18 | landingHtmlStr = templateEnv.\ 19 | get_template('landing_html.template').\ 20 | render(yamlList=yamlList) 21 | 22 | swaggerIndexHtmlFilePath = os.path.join(currentDir, '../../../build/rest_server/dist/ui/model.html') 23 | landingHtmlFilePath = os.path.join(currentDir, '../../../build/rest_server/dist/ui/index.html') 24 | 25 | #write swagger index html file 26 | with open(swaggerIndexHtmlFilePath, "w") as swaggerIndexFh: 27 | swaggerIndexFh.write(swaggerIndexHtmlStr) 28 | 29 | #write landing html file 30 | with open(landingHtmlFilePath, "w") as landingFh: 31 | landingFh.write(landingHtmlStr) 32 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/configure_mode.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 32 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tools/restconf_doc_tools/utils/json_delta/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2020 Philip J. Roberts 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/ip.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 30 | 34 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/lub/argv/argv.c.diff: -------------------------------------------------------------------------------- 1 | diff --git a/lub/argv/argv.c b/lub/argv/argv.c 2 | index 14e81fc..0eb95a4 100644 3 | --- a/lub/argv/argv.c 4 | +++ b/lub/argv/argv.c 5 | @@ -88,6 +88,9 @@ static void lub_argv_fini(lub_argv_t * this) 6 | /*--------------------------------------------------------- */ 7 | void lub_argv_delete(lub_argv_t * this) 8 | { 9 | + if (!this) 10 | + return; 11 | + 12 | lub_argv_fini(this); 13 | free(this); 14 | } 15 | @@ -171,6 +174,9 @@ const char *lub_argv__get_arg(const lub_argv_t *this, unsigned int index) 16 | /*--------------------------------------------------------- */ 17 | unsigned lub_argv__get_count(const lub_argv_t * this) 18 | { 19 | + if (!this) 20 | + return 0; 21 | + 22 | return this->argc; 23 | } 24 | 25 | @@ -197,3 +203,18 @@ bool_t lub_argv__get_quoted(const lub_argv_t * this, unsigned index) 26 | } 27 | 28 | /*--------------------------------------------------------- */ 29 | +bool_t lub_argv__swap_arg (const lub_argv_t *this, unsigned int index1, unsigned int index2) { 30 | + char *temp = NULL; 31 | + bool_t result = BOOL_FALSE; 32 | + if (!this) 33 | + return result; 34 | + if ((this->argc > index1) && (this->argc > index2)) { 35 | + temp = this->argv[index1].arg; 36 | + this->argv[index1].arg = this->argv[index2].arg; 37 | + this->argv[index2].arg = temp; 38 | + result = BOOL_TRUE; 39 | + } 40 | + return result; 41 | +} 42 | + 43 | +/*--------------------------------------------------------- */ 44 | -------------------------------------------------------------------------------- /tools/openapi_tests/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all test-rpc test-data-nodes 2 | 3 | TOPDIR := ../.. 4 | PYANG_PLUGINS_DIR := $(TOPDIR)/tools/pyang/pyang_plugins 5 | PYANG ?= pyang 6 | 7 | all: test-rpc test-data-nodes test-complex-model test-complex-model-no-oneof 8 | 9 | # This will cover RPC statements with only input, only output and with 10 | # both input and output 11 | test-rpc: 12 | $(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) test-rpc.yang | diff test-rpc.yang.expect - 13 | 14 | # This will cover container, list, leaf and leaf-lists with both 15 | # simple and nested hierarchies. 16 | # Also this will cover data type testing such as leafref, enum and string with pattern 17 | # simple string, integer types, leaf with default values, mandatory statements etc. 18 | test-data-nodes: 19 | $(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) test-data-nodes.yang | diff test-data-nodes.yang.expect - 20 | 21 | # This will cover some complex YANGs, with many nested hierarchies 22 | # Also with choice-case statements, Union data types, range with min,max etc 23 | # Test with one-oneof 24 | test-complex-model: 25 | $(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) --with-oneof ietf-snmp.yang ietf-snmp-community.yang | diff ietf-snmp.yang.expect - 26 | 27 | # Test without one-oneof 28 | test-complex-model-no-oneof: 29 | $(PYANG) -f swaggerapi --plugindir $(PYANG_PLUGINS_DIR) ietf-snmp.yang ietf-snmp-community.yang | diff ietf-snmp.no-oneof.yang.expect - 30 | -------------------------------------------------------------------------------- /CLI/clicfg/mgmt_clish_platform.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 28 | 29 | 30 | 31 | 32 | START_PORT_ID 33 | MAX_PORT_ID 34 | START_SUB_PORT_ID 35 | MAX_SUB_PORT_ID 36 | MAX_MTU 37 | 38 | 39 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/shell_libxml2.c.diff: -------------------------------------------------------------------------------- 1 | 5c5 2 | < * This file implements the means to read an XML encoded file 3 | --- 4 | > * This file implements the means to read an XML encoded file 5 | 19a20 6 | > #include 7 | 72c73 8 | < /* The XSLT example contain these settings but I doubt 9 | --- 10 | > /* The XSLT example contain these settings but I doubt 11 | 94c95,96 12 | < doc = xmlReadFile(filename, NULL, 0); 13 | --- 14 | > doc = xmlReadFile(filename, NULL, 1026); 15 | > xmlXIncludeProcess(doc); 16 | 134c136 17 | < case XML_ELEMENT_NODE: 18 | --- 19 | > case XML_ELEMENT_NODE: 20 | 136c138 21 | < case XML_TEXT_NODE: 22 | --- 23 | > case XML_TEXT_NODE: 24 | 138c140 25 | < case XML_COMMENT_NODE: 26 | --- 27 | > case XML_COMMENT_NODE: 28 | 140c142 29 | < case XML_PI_NODE: 30 | --- 31 | > case XML_PI_NODE: 32 | 142c144 33 | < case XML_ATTRIBUTE_NODE: 34 | --- 35 | > case XML_ATTRIBUTE_NODE: 36 | 172c174 37 | < clish_xmlnode_t *clish_xmlnode_next_child(clish_xmlnode_t *parent, 38 | --- 39 | > clish_xmlnode_t *clish_xmlnode_next_child(clish_xmlnode_t *parent, 40 | 211c213 41 | < 42 | --- 43 | > 44 | 215c217 45 | < int clish_xmlnode_get_content(clish_xmlnode_t *node, char *content, 46 | --- 47 | > int clish_xmlnode_get_content(clish_xmlnode_t *node, char *content, 48 | 261c263 49 | < int clish_xmlnode_get_name(clish_xmlnode_t *node, char *name, 50 | --- 51 | > int clish_xmlnode_get_name(clish_xmlnode_t *node, char *name, 52 | 279c281 53 | < 54 | --- 55 | > 56 | -------------------------------------------------------------------------------- /tools/codegen/go-server/templates-yang/controllers-api.j2: -------------------------------------------------------------------------------- 1 | 2 | package openapi 3 | 4 | import ( 5 | "net/http" 6 | 7 | "github.com/Azure/sonic-mgmt-framework/rest/server" 8 | ) 9 | 10 | {% for operationId in OpIds %} 11 | {% set path = OpIdDict[operationId]["path"] %} 12 | {% set pathEntry = OpIdDict[operationId]["obj"] %} 13 | {% set method = OpIdDict[operationId]["method"] %} 14 | func {{ operationId }}(w http.ResponseWriter, r *http.Request) { 15 | rc, r := server.GetContext(r) 16 | rc.Name = "{{ operationId }}" 17 | {% if method in ["post", "put", "patch"] and "requestBody" in pathEntry %} 18 | {% for consume in pathEntry["requestBody"]["content"].keys() %} 19 | rc.Consumes.Add("{{ consume }}") 20 | {% endfor %} 21 | {% endif %} 22 | {% set content = dict() %} 23 | {% if method == "get" %} 24 | {% set content = pathEntry["responses"]["200"]["content"] %} 25 | {% endif %} 26 | {% if 'x-rpc' in pathEntry and 'content' in pathEntry["responses"]["204"] %} 27 | {% set content = pathEntry["responses"]["204"]["content"] %} 28 | {% endif %} 29 | {% for produce in content.keys() %} 30 | rc.Produces.Add("{{ produce }}") 31 | {% endfor %} 32 | {% if 'x-params' in pathEntry.keys() %} 33 | {% set varMappings = pathEntry['x-params']['varMapping'] %} 34 | rc.PMap = server.NameMap{ {% for varMapping in varMappings %}"{{ varMapping['uriName'] }}":"{{ varMapping['yangName'] }}", {% endfor %} } 35 | {% endif %} 36 | server.Process(w, r) 37 | } 38 | {% if not loop.last %} 39 | 40 | {% endif %} 41 | {% endfor %} -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/plugin/mgmt_clish_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * filename: mgmt_clish_utils.h 3 | * (c) Copyright 2020 Dell EMC All Rights Reserved. 4 | */ 5 | #ifndef __mgmt_clish_utils_H__ 6 | #define __mgmt_clish_utils_H__ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "clish/shell.h" 13 | #include "clish/shell/private.h" 14 | 15 | #include "time.h" 16 | extern int interruptRecvd; 17 | 18 | /** 19 | * @brief Sugnal handler for clish 20 | * 21 | * @param signum signal number received 22 | */ 23 | void clish_interrupt_handler(int signum); 24 | 25 | /** 26 | * @brief This function returns status of whether Ctrl-C is pressed or not 27 | * 28 | * @return - true(Ctrl-C occurred), false(Ctrl-C not occurred) 29 | */ 30 | bool_t is_ctrlc_pressed(void); 31 | 32 | /** 33 | * @brief This function empties the Ctrl-C pipe 34 | * 35 | * @return - None 36 | */ 37 | void flush_ctrlc_pipe(void); 38 | 39 | /** 40 | * @brief This function masks password/key value with ***** 41 | * Commands which have password/keysupport-assist : 42 | * username password role } 43 | * radius-server key 44 | * tacacs-server key 45 | * snmp-server user [encrypted] auth [md5|sha] auth-password priv [aes-128 | 46 | * des] priv-password 47 | * 48 | * @param [in] command line : CLI command string 49 | * @param [out] masked line : CLI command string with masked password/key 50 | * 51 | */ 52 | 53 | void mask_password(const char *line, char **masked_line); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /models/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # # 3 | # Copyright 2020 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 4 | # its subsidiaries. # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ################################################################################ 19 | 20 | all: 21 | %: 22 | $(MAKE) -f yang_to_openapi.mk $@ 23 | $(MAKE) -f openapi_codegen.mk $@ 24 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/param/mgmt_clish_extn_param.c: -------------------------------------------------------------------------------- 1 | /* 2 | * filename: mgmt_clish_extn_param.c 3 | * (c) Copyright 2020 Dell EMC All Rights Reserved. 4 | * 5 | * APIs to set and get the new attributes added to the klish PARAM option 6 | */ 7 | 8 | /** OPENSOURCELICENSE */ 9 | #include "clish/param/private.h" 10 | #include "lub/string.h" 11 | #include "assert.h" 12 | #include "string.h" 13 | 14 | /*--------------------------------------------------------- */ 15 | void clish_param__set_recursive(clish_param_t *this, 16 | bool_t recursive) 17 | { 18 | this->recursive = recursive; 19 | } 20 | 21 | /*--------------------------------------------------------- */ 22 | bool_t clish_param__get_recursive(const clish_param_t *this) 23 | { 24 | return this->recursive; 25 | } 26 | 27 | /*--------------------------------------------------------- */ 28 | void clish_param__set_viewname(clish_param_t * this, char *viewname) 29 | { 30 | assert(this); 31 | this->viewname = lub_string_dup(viewname); 32 | } 33 | 34 | /*--------------------------------------------------------- */ 35 | const char *clish_param__get_viewname(const clish_param_t * this) 36 | { 37 | return this->viewname; 38 | } 39 | 40 | /*--------------------------------------------------------- */ 41 | void clish_param__set_viewid(clish_param_t * this, char *viewid) 42 | { 43 | assert(this); 44 | this->viewid = lub_string_dup(viewid); 45 | } 46 | 47 | /*--------------------------------------------------------- */ 48 | const char *clish_param__get_viewid(const clish_param_t * this) 49 | { 50 | return this->viewid; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tools/codegen/go-server/src/openapi/routes.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // 4 | // its subsidiaries. // 5 | // // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); // 7 | // you may not use this file except in compliance with the License. // 8 | // You may obtain a copy of the License at // 9 | // // 10 | // http://www.apache.org/licenses/LICENSE-2.0 // 11 | // // 12 | // Unless required by applicable law or agreed to in writing, software // 13 | // distributed under the License is distributed on an "AS IS" BASIS, // 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 15 | // See the License for the specific language governing permissions and // 16 | // limitations under the License. // 17 | // // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | package openapi 21 | 22 | // Load function loads OpenAPI generated routes into REST server. 23 | func Load() { 24 | } 25 | -------------------------------------------------------------------------------- /CLI/clitree/scripts/platform_dummy.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 29 | 30 | 31 | NOT_SUPPORTED 32 | 33 | 34 | START_PORT_ID 35 | MAX_PORT_ID 36 | START_SUB_PORT_ID 37 | MAX_SUB_PORT_ID 38 | MAX_MTU 39 | 40 | 41 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/src/openapi/routes.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // 4 | // its subsidiaries. // 5 | // // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); // 7 | // you may not use this file except in compliance with the License. // 8 | // You may obtain a copy of the License at // 9 | // // 10 | // http://www.apache.org/licenses/LICENSE-2.0 // 11 | // // 12 | // Unless required by applicable law or agreed to in writing, software // 13 | // distributed under the License is distributed on an "AS IS" BASIS, // 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 15 | // See the License for the specific language governing permissions and // 16 | // limitations under the License. // 17 | // // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | package openapi 21 | 22 | // Load function loads OpenAPI generated routes into REST server. 23 | func Load() { 24 | } 25 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/src/swagger/routes.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // 4 | // its subsidiaries. // 5 | // // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); // 7 | // you may not use this file except in compliance with the License. // 8 | // You may obtain a copy of the License at // 9 | // // 10 | // http://www.apache.org/licenses/LICENSE-2.0 // 11 | // // 12 | // Unless required by applicable law or agreed to in writing, software // 13 | // distributed under the License is distributed on an "AS IS" BASIS, // 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 15 | // See the License for the specific language governing permissions and // 16 | // limitations under the License. // 17 | // // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | package swagger 21 | 22 | // Load function logs swagger generated routes into REST server. 23 | func Load() { 24 | } 25 | -------------------------------------------------------------------------------- /tools/swagger_codegen/go-server/templates-nonyang/model.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | {{#models}}{{#imports}} 4 | import ({{/imports}}{{#imports}} 5 | "{{import}}"{{/imports}}{{#imports}} 6 | ) 7 | {{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}} 8 | type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}} 9 | 10 | // List of {{{name}}} 11 | const ( 12 | {{#allowableValues}} 13 | {{#enumVars}} 14 | {{name}} {{{classname}}} = "{{{value}}}" 15 | {{/enumVars}} 16 | {{/allowableValues}} 17 | ){{/isEnum}}{{^isEnum}}{{#description}} 18 | // {{{description}}}{{/description}} 19 | type {{classname}} struct { 20 | {{#requiredVars}} 21 | {{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `validate:"required" json:"{{baseName}}{{^required}},omitempty{{/required}}"` 22 | {{/requiredVars}} 23 | {{#vars}}{{#description}} 24 | // {{{description}}}{{/description}} 25 | {{^required}}{{#isContainer}} 26 | {{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `validate:"dive" json:"{{baseName}}{{^required}},omitempty{{/required}}"` 27 | {{/isContainer}}{{/required}} 28 | {{^required}}{{^isContainer}} 29 | {{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"` 30 | {{/isContainer}}{{/required}} 31 | {{/vars}} 32 | }{{/isEnum}}{{/model}}{{/models}} 33 | -------------------------------------------------------------------------------- /tools/swagger_codegen/ui-dist/index.html_notused: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Swagger UI 7 | 8 | 9 | 10 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | 38 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/platform.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 28 | 32 | 33 | python3 $SONIC_CLI_ROOT/sonic-cli-pfm.py get_openconfig_platform_components platform_show.j2 ${__full_line} 34 | 35 | 36 | 37 | 38 | 42 | 43 | python3 $SONIC_CLI_ROOT/sonic-cli-pfm.py get_openconfig_platform_components platform_show.j2 ${__full_line} 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /tools/ui_gen/templates/swagger_index_html.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Swagger UI 7 | 8 | 9 | 10 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | 38 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /CLI/klish/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = /bin/bash 2 | .ONESHELL: 3 | .SHELLFLAGS += -e 4 | 5 | KLISH_VERSION = 2.1.4 6 | 7 | KLISH_SRC = $(SONIC_CLI_ROOT)/klish-$(KLISH_VERSION) 8 | 9 | # Python changed how to link against Python for embedding purposes in 3.8 10 | # which means that in order to support both Debian 10 and Debian >=11 11 | # we need to try two alternatives. 12 | CFLAGS_PYTHON := $(shell pkg-config --silence-errors --cflags python3-embed || pkg-config --cflags python3) 13 | LDFLAGS_PYTHON := $(shell pkg-config --silence-errors --libs python3-embed || pkg-config --libs python3) 14 | LDFLAGS_CURL := $(shell pkg-config --libs libcurl) 15 | 16 | ifeq ($(CROSS_BUILD_ENVIRON),y) 17 | CROSS_CONFIGURE_OPTS = --host=$(CROSS_HOST_TYPE) 18 | LIB_PATH = $(CROSS_PKGS_LIB_PATH) 19 | else 20 | LIB_PATH = /usr/lib/x86_64-linux-gnu 21 | endif 22 | 23 | SRC_REPLACEMENTS:=$(shell find patches -type f) 24 | all : $(SRC_REPLACEMENTS) 25 | tar xzvf klish-$(KLISH_VERSION).tgz -C $(SONIC_CLI_ROOT) 26 | ./patches/scripts/patchmake.sh -p VER=${KLISH_VERSION} TSP=${SONIC_CLI_ROOT} DSP=${CURDIR}/patches TWP=${SONIC_CLI_ROOT} 27 | 28 | cd ${KLISH_SRC} && \ 29 | sh autogen.sh && \ 30 | ./configure \ 31 | --with-libxml2=/usr \ 32 | $(CROSS_CONFIGURE_OPTS) \ 33 | --enable-debug=no \ 34 | LIBS='$(LDFLAGS_CURL) -L$(LIB_PATH) $(LDFLAGS_PYTHON) -Wl,-rpath=$(LIB_PATH) -lcjson' \ 35 | CFLAGS='${CFLAGS} -g $(CFLAGS_PYTHON)' \ 36 | CPPFLAGS='${CPPFLAGS} -I/usr/include/cjson' && \ 37 | make 38 | 39 | mkdir -p $(SONIC_CLI_ROOT)/target/.libs 40 | cp $(CURDIR)/clish_start $(SONIC_CLI_ROOT)/target/. 41 | 42 | cp -r ${KLISH_SRC}/bin/.libs/clish ${SONIC_CLI_ROOT}/target/. 43 | cp -r ${KLISH_SRC}/.libs/*.so* ${SONIC_CLI_ROOT}/target/.libs 44 | cp -r ${KLISH_SRC}/.libs/*.a ${SONIC_CLI_ROOT}/target/.libs 45 | @echo "complete klish build" 46 | 47 | .PHONY: clean 48 | clean: 49 | rm -rf ${KLISH_SRC} 50 | -------------------------------------------------------------------------------- /tools/openapi_tests/ietf-snmp.yang: -------------------------------------------------------------------------------- 1 | module ietf-snmp { 2 | 3 | namespace "urn:ietf:params:xml:ns:yang:ietf-snmp"; 4 | prefix snmp; 5 | 6 | include ietf-snmp-common { 7 | revision-date 2014-12-10; 8 | } 9 | include ietf-snmp-target { 10 | revision-date 2014-12-10; 11 | } 12 | include ietf-snmp-proxy { 13 | revision-date 2014-12-10; 14 | } 15 | 16 | 17 | organization 18 | "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; 19 | 20 | contact 21 | "WG Web: 22 | WG List: 23 | 24 | WG Chair: Thomas Nadeau 25 | 26 | 27 | WG Chair: Juergen Schoenwaelder 28 | 29 | 30 | Editor: Martin Bjorklund 31 | 32 | 33 | Editor: Juergen Schoenwaelder 34 | "; 35 | description 36 | "This module contains a collection of YANG definitions for 37 | configuring SNMP engines. 38 | 39 | Copyright (c) 2014 IETF Trust and the persons identified as 40 | authors of the code. All rights reserved. 41 | 42 | Redistribution and use in source and binary forms, with or 43 | without modification, is permitted pursuant to, and subject 44 | to the license terms contained in, the Simplified BSD License 45 | set forth in Section 4.c of the IETF Trust's Legal Provisions 46 | Relating to IETF Documents 47 | (http://trustee.ietf.org/license-info). 48 | 49 | This version of this YANG module is part of RFC 7407; see 50 | the RFC itself for full legal notices."; 51 | 52 | revision 2014-12-10 { 53 | description 54 | "Initial revision."; 55 | reference 56 | "RFC 7407: A YANG Data Model for SNMP Configuration"; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /rest/main/main_test.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // 4 | // its subsidiaries. // 5 | // // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); // 7 | // you may not use this file except in compliance with the License. // 8 | // You may obtain a copy of the License at // 9 | // // 10 | // http://www.apache.org/licenses/LICENSE-2.0 // 11 | // // 12 | // Unless required by applicable law or agreed to in writing, software // 13 | // distributed under the License is distributed on an "AS IS" BASIS, // 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 15 | // See the License for the specific language governing permissions and // 16 | // limitations under the License. // 17 | // // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | package main 21 | 22 | import ( 23 | "fmt" 24 | "os" 25 | "os/signal" 26 | "syscall" 27 | "testing" 28 | ) 29 | 30 | func TestMain(t *testing.T) { 31 | go main() 32 | sigs := make(chan os.Signal, 1) 33 | signal.Notify(sigs, syscall.SIGUSR1) 34 | fmt.Println("Listening on sig kill from TestMain") 35 | <-sigs 36 | fmt.Println("Returning from TestMain on sig kill") 37 | } 38 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_interface_status.j2: -------------------------------------------------------------------------------- 1 | {% set vars = {'name': ""} %} 2 | {% set vars = {'admin_state': ""} %} 3 | {% set vars = {'oper_state': ""} %} 4 | {% set vars = {'description': ""} %} 5 | {% set vars = {'mtu': ""} %} 6 | {% set vars = {'speed': ""} %} 7 | {% if json_output -%} 8 | ------------------------------------------------------------------------------------------ 9 | {{'%-20s'|format("Name")}}{{'%-20s'|format("Description")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("Oper")}}{{'%-15s'|format("Speed")}}{{'%-15s'|format("MTU")}} 10 | ------------------------------------------------------------------------------------------ 11 | {% for key_json in json_output %} 12 | {% set interface_list = json_output[key_json]["interface"] %} 13 | {% for interface in interface_list %} 14 | {% for key in interface %} 15 | {% if "ethernet" in key %} 16 | {% if vars.update({'speed':interface[key]["state"]["port-speed"]|replace("openconfig-if-ethernet:SPEED_", "")}) %}{% endif %} 17 | {% endif %} 18 | {% if "state" in key %} 19 | {% if vars.update({'name':interface[key]["name"]}) %}{% endif %} 20 | {% if vars.update({'admin_state':interface[key]["admin-status"]}) %}{% endif %} 21 | {% if vars.update({'oper_state':interface[key]["oper-status"]}) %}{% endif %} 22 | {% if vars.update({'mtu':interface[key]["mtu"]}) %}{% endif %} 23 | {% if interface[key]["description"] != "" %} 24 | {% if vars.update({'description':interface[key]["description"]}) %}{% endif %} 25 | {%else %} 26 | {% if vars.update({'description':"-"}) %}{% endif %} 27 | {% endif %} 28 | {% endif %} 29 | {% endfor %} 30 | {% if 'Ethernet' in vars.name %} 31 | {{'%-20s'|format(vars.name)}}{{'%-20s'|format(vars.description)}}{{'%-15s'|format(vars.admin_state|lower())}}{{'%-15s'|format(vars.oper_state|lower())}}{{'%-15s'|format(vars.speed)}}{{'%-15s'|format(vars.mtu)}} 32 | {% endif %} 33 | {% endfor %} 34 | {% endfor %} 35 | {% endif %} 36 | 37 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_access_group.j2: -------------------------------------------------------------------------------- 1 | {% if json_output %} 2 | {% for key in json_output %} 3 | {# This condition checks if the JSON response has data from the acl/interface list #} 4 | {% if "interface" in key %} 5 | {% for interface in json_output[key] %} 6 | {% set if_id = interface["id"] %} 7 | {% if interface["ingress-acl-sets"] %} 8 | {% set idirection = "ingress" %} 9 | {% endif %} 10 | {% if interface["egress-acl-sets"] %} 11 | {% set edirection = "egress" %} 12 | {% endif %} 13 | {% if idirection %} 14 | {% set ing_acl_sets = idirection + "-acl-sets" %} 15 | {% set ing_acl_set = idirection + "-acl-set" %} 16 | {% set ing_acl_set_list = interface[ing_acl_sets][ing_acl_set] %} 17 | {% for ing_acl_set in ing_acl_set_list %} 18 | {% set i_acl_name = ing_acl_set["set-name"] %} 19 | {% if idirection == "ingress" %} 20 | {% set idirection = "Ingress" %} 21 | {% endif %} 22 | {{- idirection }} IP access-list {{ i_acl_name }} on {{ if_id }} 23 | {% endfor %} 24 | {% endif %} 25 | {% if edirection %} 26 | {% set eg_acl_sets = edirection + "-acl-sets" %} 27 | {% set eg_acl_set = edirection + "-acl-set" %} 28 | {% set eg_acl_set_list = interface[eg_acl_sets][eg_acl_set] %} 29 | {% for eg_acl_set in eg_acl_set_list %} 30 | {% set e_acl_name = eg_acl_set["set-name"] %} 31 | {% if edirection == "egress" %} 32 | {% set edirection = "Egress" %} 33 | {% endif %} 34 | {{- edirection }} IP access-list {{ e_acl_name }} on {{ if_id }} 35 | {% endfor %} 36 | {% endif %} 37 | {% endfor %} 38 | {% endif %} 39 | {% endfor %} 40 | {% endif %} 41 | -------------------------------------------------------------------------------- /CLI/renderer/scripts/acl_jinja2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from jinja2 import Template 3 | import os 4 | acl_out = {'openconfig_aclacl': {'acl_sets': {'acl_set': [{'acl_entries': {'acl_entry': [{'actions': {'config': {'forwarding_action': 'DROP', 5 | 'log_action': None}, 6 | 'state': {'forwarding_action': 'DROP', 7 | 'log_action': None}}, 8 | 'config': {'description': None, 9 | 'sequence_id': 66}, 10 | 'input_interface': None, 11 | 'ipv4': {'config': {'destination_address': '2.2.2.0/24', 12 | 'dscp': None, 13 | 'hop_limit': None, 14 | 'protocol': '6', 15 | 'source_address': '1.1.1.0/24'}, 16 | 'state': {'destination_address': '2.2.2.0/24', 17 | 'dscp': None, 18 | 'hop_limit': None, 19 | 'protocol': '6', 20 | 'source_address': '1.1.1.0/24'}}, 21 | 'ipv6': None, 22 | 'l2': None, 23 | 'sequence_id': 66, 24 | 'state': {'description': None, 25 | 'matched_octets': 0, 26 | 'matched_packets': 0, 27 | 'sequence_id': 66}, 28 | 'transport': {'config': {'destination_port': '200', 29 | 'source_port': '100', 30 | 'tcp_flags': None}, 31 | 'state': {'destination_port': '200', 32 | 'source_port': '100', 33 | 'tcp_flags': None}}}]}, 34 | 'config': {'description': None, 35 | 'name': 'TEST', 36 | 'type': 'ACL_IPV4'}, 37 | 'name': 'TEST', 38 | 'state': {'description': None, 39 | 'name': 'TEST', 40 | 'type': 'ACL_IPV4'}, 41 | 'type': 'ACL_IPV4'}]}, 42 | 'interfaces': None, 43 | 'state': None}} 44 | 45 | 46 | 47 | 48 | #!/usr/bin/env/python3 49 | 50 | from jinja2 import Environment, FileSystemLoader 51 | 52 | # Capture our current directory 53 | THIS_DIR = os.path.dirname(os.path.abspath(__file__)) 54 | 55 | def acl_show(): 56 | # Create the jinja2 environment. 57 | # Notice the use of trim_blocks, which greatly helps control whitespace. 58 | j2_env = Environment(loader=FileSystemLoader(THIS_DIR), 59 | trim_blocks=True) 60 | print((j2_env.get_template('acl_show.j2').render(acl_out=acl_out))) 61 | 62 | if __name__ == '__main__': 63 | acl_show() 64 | -------------------------------------------------------------------------------- /tools/openapi_tests/test-rpc.yang: -------------------------------------------------------------------------------- 1 | module test-rpc { 2 | namespace "https://example.com/ns/example-ops"; 3 | prefix "ops"; 4 | 5 | organization "Example, Inc."; 6 | contact "support at example.com"; 7 | description "Example Operations Data Model Module."; 8 | revision "2016-07-07" { 9 | description "Initial version."; 10 | reference "example.com document 3-3373."; 11 | } 12 | 13 | rpc reboot { 14 | description "Reboot operation."; 15 | input { 16 | leaf delay { 17 | type uint32; 18 | units "seconds"; 19 | default 0; 20 | description 21 | "Number of seconds to wait before initiating the 22 | reboot operation."; 23 | } 24 | leaf message { 25 | type string; 26 | description 27 | "Log message to display when reboot is started."; 28 | } 29 | leaf language { 30 | type string; 31 | description "Language identifier string."; 32 | reference "RFC 5646."; 33 | } 34 | } 35 | } 36 | 37 | rpc get-reboot-info { 38 | description 39 | "Retrieve parameters used in the last reboot operation."; 40 | output { 41 | leaf reboot-time { 42 | type uint32; 43 | description 44 | "The 'delay' parameter used in the last reboot 45 | operation."; 46 | } 47 | leaf message { 48 | type string; 49 | description 50 | "The 'message' parameter used in the last reboot 51 | operation."; 52 | } 53 | leaf language { 54 | type string; 55 | description 56 | "The 'language' parameter used in the last reboot 57 | operation."; 58 | } 59 | } 60 | } 61 | 62 | rpc activate-software-image { 63 | input { 64 | leaf image-name { 65 | type string; 66 | } 67 | } 68 | output { 69 | leaf status { 70 | type string; 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/lldp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 26 | 27 | 28 | 29 | python3 $SONIC_CLI_ROOT/sonic-cli-lldp.py get_openconfig_lldp_lldp_interfaces lldp_show.j2 ${__full_line} 30 | 31 | 32 | python3 $SONIC_CLI_ROOT/sonic-cli-lldp.py get_openconfig_lldp_lldp_interfaces lldp_show.j2 ${__full_line} 33 | 34 | 35 | 41 | 42 | 43 | if test "${ifname}" = ""; then 44 | python3 $SONIC_CLI_ROOT/sonic-cli-lldp.py get_openconfig_lldp_lldp_interfaces lldp_neighbor_show.j2 ${__full_line} 45 | else 46 | python3 $SONIC_CLI_ROOT/sonic-cli-lldp.py get_openconfig_lldp_lldp_interfaces_interface lldp_neighbor_show.j2 ${ifname} ${__full_line} 47 | fi 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /CLI/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = /bin/bash 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | .ONESHELL: 21 | .SHELLFLAGS += -e 22 | 23 | TOPDIR ?= $(abspath ..) 24 | SUBDIRS := clitree renderer klish 25 | export SONIC_CLI_ROOT=$(TOPDIR)/build 26 | TGT_DIR := $(SONIC_CLI_ROOT)/target 27 | 28 | CLI_DIR := $(TOPDIR)/CLI 29 | PY_FILES := $(shell find $(CLI_DIR)/actioner -name '*.py') 30 | PY_FILES += $(shell find $(CLI_DIR)/renderer/scripts -name '*.py') 31 | PY_FILES += $(shell find $(CLI_DIR)/clitree/scripts -name '*.py') 32 | PYLINT_DONE := $(SONIC_CLI_ROOT)/pylint/.pylint_done 33 | TOOLS_DIR := $(TOPDIR)/tools 34 | LINTER := $(TOOLS_DIR)/test/pylint.sh 35 | 36 | .PHONY: clean 37 | 38 | all: $(PYLINT_DONE) 39 | for dir in $(SUBDIRS); do \ 40 | $(MAKE) -C $$dir -f Makefile $@; \ 41 | done 42 | 43 | rm -rf $(TOPDIR)/build/cli 44 | mv -f $(TGT_DIR) $(TOPDIR)/build/cli 45 | 46 | .SECONDEXPANSION: 47 | 48 | #====================================================================== 49 | # Common rule for directories. Use "." suffix, like "xyz/." 50 | #====================================================================== 51 | .PRECIOUS: %/. 52 | %/.: 53 | mkdir -p $@ 54 | 55 | pylint: $(PYLINT_DONE) 56 | 57 | $(PYLINT_DONE): $(PY_FILES) | $$(@D)/. 58 | $(LINTER) $? 59 | touch $@ 60 | 61 | pylint-clean: 62 | $(RM) -r $(PYLINT_DONE) 63 | $(RM) -r $(SONIC_CLI_ROOT)/cli/pylint.log* 64 | 65 | clean: pylint-clean 66 | make --directory=klish clean 67 | rm -rf $(TOPDIR)/build/cli 68 | rm -rf $(TGT_DIR) 69 | 70 | 71 | -------------------------------------------------------------------------------- /CLI/clitree/scripts/klish_preproc_cmdtree.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | ''' CLI parser tree preprocessing script before the parser xml-s are copied 21 | to sysroot. These are the steps performed: 22 | a. Macro replacement 23 | b. Platform specific feature xml and feature-val xml creation 24 | c. Insert the |' for post processing support of show commands 25 | d. Insert the default default end and exit command for all config modes 26 | 27 | The Script Usage: 28 | python3 klish_preproc_cmdtree.py buildpath macros-dir depth 29 | ''' 30 | import sys 31 | import os 32 | import re 33 | from lxml import etree 34 | import klish_replace_macro, klish_insert_pipe, klish_ins_def_cmd 35 | 36 | if __name__ == "__main__": 37 | 38 | if len(sys.argv) == 1 or sys.argv[1] == "--help": 39 | print("Usage:", sys.argv[0], "working-dir macrodir nested-macro-levels [--debug]") 40 | sys.exit(0) 41 | 42 | dirpath = sys.argv[1] 43 | macro_dir_path = sys.argv[2] 44 | nested_levels = sys.argv[3] 45 | 46 | if len(sys.argv) == 5 and sys.argv[4] == "--debug": 47 | debug = True 48 | else: 49 | debug = False 50 | 51 | print("Replacing the macros ...") 52 | klish_replace_macro.replace_macros (dirpath, macro_dir_path, nested_levels, debug) 53 | print("Inserting the pipe parameters ...") 54 | klish_insert_pipe.insert_pipe (dirpath, debug) 55 | print("Insert the end, exit commands ...") 56 | klish_ins_def_cmd.ins_def_cmd (dirpath, dirpath, debug) 57 | 58 | 59 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Azure/sonic-mgmt-framework 2 | 3 | require ( 4 | github.com/Azure/sonic-mgmt-common v0.0.0-00010101000000-000000000000 5 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b 6 | github.com/gorilla/mux v1.7.4 7 | github.com/pkg/profile v1.7.0 8 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 9 | gopkg.in/go-playground/validator.v9 v9.31.0 10 | ) 11 | 12 | require ( 13 | github.com/Workiva/go-datastructures v1.0.50 // indirect 14 | github.com/antchfx/jsonquery v1.1.4 // indirect 15 | github.com/antchfx/xmlquery v1.3.1 // indirect 16 | github.com/antchfx/xpath v1.1.10 // indirect 17 | github.com/felixge/fgprof v0.9.3 // indirect 18 | github.com/go-playground/locales v0.13.0 // indirect 19 | github.com/go-playground/universal-translator v0.17.0 // indirect 20 | github.com/go-redis/redis/v7 v7.0.0-beta.3.0.20190824101152-d19aba07b476 // indirect 21 | github.com/godbus/dbus/v5 v5.1.0 // indirect 22 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect 23 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 // indirect 24 | github.com/google/go-cmp v0.4.0 // indirect 25 | github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect 26 | github.com/kylelemons/godebug v1.1.0 // indirect 27 | github.com/leodido/go-urn v1.2.0 // indirect 28 | github.com/maruel/natural v1.1.1 // indirect 29 | github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 // indirect 30 | github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc // indirect 31 | github.com/openconfig/ygot v0.7.1 // indirect 32 | github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f // indirect 33 | go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect 34 | go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect 35 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 36 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect 37 | golang.org/x/text v0.3.3 // indirect 38 | google.golang.org/genproto v0.0.0-20200319113533-08878b785e9c // indirect 39 | google.golang.org/grpc v1.28.0 // indirect 40 | google.golang.org/protobuf v1.21.0 // indirect 41 | gopkg.in/go-playground/assert.v1 v1.2.1 // indirect 42 | inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect 43 | ) 44 | 45 | replace github.com/Azure/sonic-mgmt-common => ../sonic-mgmt-common 46 | 47 | go 1.19 48 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/ipv6.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 36 | 40 | 43 | 47 | python3 $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv6_addresses_address_config ${iface} ${addr} 48 | 49 | 50 | 53 | 57 | python3 $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv6_addresses_address_config_prefix_length ${iface} ${addr} 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /CLI/clitree/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################### 2 | # 3 | # Copyright 2019 Dell, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | ########################################################################### 18 | 19 | .PHONY: install 20 | 21 | TOPDIR := ../.. 22 | # TGT_DIR is the directory wher all prepreocssed cli model, actioner and 23 | # renderer scripts and temlates will be dumped. Can be overidden from caller. 24 | TGT_DIR ?= $(SONIC_CLI_ROOT)/target 25 | CLI_XML_FILES := $(shell find $(TOPDIR)/CLI/clitree/cli-xml -name '*.xml' | sort) 26 | CLI_XML_MACRO_FILES := $(shell find $(TOPDIR)/CLI/clitree/macro -name '*.xml' | sort) 27 | cli_done := ${TGT_DIR}/command-tree/.done 28 | cli_guide := ${TGT_DIR}/command-tree/industry_standard_cli_reference_guide.md 29 | 30 | all: $(cli_done) 31 | 32 | $(cli_done): $(CLI_XML_FILES) $(CLI_XML_MACRO_FILES) 33 | mkdir -p ${TGT_DIR}/command-tree ${TGT_DIR}/cli-macro ${TGT_DIR}/render-templates ${TGT_DIR}/scripts 34 | cp -r cli-xml/include ${TGT_DIR}/command-tree 35 | cp cli-xml/*.xml ${TGT_DIR}/command-tree 36 | cp macro/*.xml ${TGT_DIR}/cli-macro 37 | (cd scripts;./klish_platform_features_process.sh ../../clicfg ${TGT_DIR}) 38 | python scripts/klish_preproc_cmdtree.py ${TGT_DIR}/command-tree ${TGT_DIR}/cli-macro 6 39 | cp ./../actioner/*.py ${TGT_DIR}/. 40 | cp ../renderer/scripts/*.py ${TGT_DIR}/scripts 41 | cp -r ../renderer/templates/* ${TGT_DIR}/render-templates 42 | cp scripts/sonic-clish.xsd ${TGT_DIR}/command-tree 43 | (cd ${TGT_DIR}/command-tree ; xmllint --noout --schema sonic-clish.xsd ${TGT_DIR}/command-tree/*.xml && \ 44 | xmllint --noout --schema sonic-clish.xsd ${TGT_DIR}/command-tree/include/*.xml) || exit 1 45 | rm -rf {TGT_DIR}/cli-macro 46 | rm -rf scripts/*.pyc 47 | touch $@ 48 | 49 | clean: 50 | rm -rf ${TGT_DIR} 51 | @echo "Clitree Cleaned" 52 | 53 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_interface_counters.j2: -------------------------------------------------------------------------------- 1 | {% set vars = {'name': ""} %} 2 | {% set vars = {'oper_state': ""} %} 3 | {% set vars = {'in_packets': ""} %} 4 | {% set vars = {'in_errors': ""} %} 5 | {% set vars = {'in_discards': ""} %} 6 | {% set vars = {'out_packets': ""} %} 7 | {% set vars = {'out_errors': ""} %} 8 | {% set vars = {'out_discards': ""} %} 9 | {% if json_output -%} 10 | ------------------------------------------------------------------------------------------------ 11 | {{'%-15s'|format("Interface")}}{{'%-10s'|format("State")}}{{'%-10s'|format("RX_OK")}}{{'%-10s'|format("RX_ERR")}}{{'%-10s'|format("RX_DRP")}}{{'%-10s'|format("TX_OK")}}{{'%-10s'|format("TX_ERR")}}{{'%-10s'|format("TX_DRP")}} 12 | ------------------------------------------------------------------------------------------------ 13 | {% for key_json in json_output %} 14 | {% set interface_list = json_output[key_json]["interface"] %} 15 | {% for interface in interface_list %} 16 | {% for key in interface %} 17 | {% if "state" in key %} 18 | {% if vars.update({'name':interface[key]["name"]}) %}{% endif %} 19 | {% if interface[key]["oper-status"] =='DOWN' %} 20 | {% if vars.update({'oper_state':'D'}) %}{% endif %} 21 | {% else %} 22 | {% if vars.update({'oper_state':'U'}) %}{% endif %} 23 | {% endif %} 24 | {% endif %} 25 | {% if "counters" in interface["state"] %} 26 | {% if vars.update({'in_packets':interface["state"]["counters"]["in-pkts"]}) %}{% endif %} 27 | {% if vars.update({'in_errors':interface["state"]["counters"]["in-errors"]}) %}{% endif %} 28 | {% if vars.update({'in_discards':interface["state"]["counters"]["in-discards"]}) %}{% endif %} 29 | {% if vars.update({'out_packets':interface["state"]["counters"]["out-pkts"]}) %}{% endif %} 30 | {% if vars.update({'out_errors':interface["state"]["counters"]["out-errors"]}) %}{% endif %} 31 | {% if vars.update({'out_discards':interface["state"]["counters"]["out-discards"]}) %}{% endif %} 32 | {% endif %} 33 | {% endfor %} 34 | {% if 'Ethernet' in vars.name %} 35 | {{'%-15s'|format(vars.name)}}{{'%-10s'|format(vars.oper_state)}}{{'%-10s'|format(vars.in_packets)}}{{'%-10s'|format(vars.in_errors)}}{{'%-10s'|format(vars.in_discards)}}{{'%-10s'|format(vars.out_packets)}}{{'%-10s'|format(vars.out_errors)}}{{'%-10s'|format(vars.out_discards)}} 36 | {% endif %} 37 | {% endfor %} 38 | {% endfor %} 39 | {% endif %} 40 | -------------------------------------------------------------------------------- /CLI/actioner/sonic-cli-lldp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | import sys 21 | from natsort import natsorted 22 | 23 | from cli_client import ApiClient, Path 24 | from rpipe_utils import pipestr 25 | from scripts.render_cli import show_cli_output 26 | 27 | 28 | def show_lldp_interface(path, template): 29 | resp = ApiClient().get(path, ignore404=False) 30 | if not resp.ok(): 31 | print(resp.error_message()) 32 | return 1 33 | if "openconfig-lldp:interfaces" in resp.content: 34 | data = resp.content["openconfig-lldp:interfaces"].get("interface", []) 35 | else: 36 | data = resp.content.get("openconfig-lldp:interface", []) 37 | # Server returns junk value for not found case!! Identify valid resp here 38 | neigh = data[0].get("neighbors", {}).get("neighbor", []) if data else None 39 | if neigh and "state" in neigh[0]: 40 | sorted_data = natsorted(data, key=lambda x: x["name"]) 41 | show_cli_output(template, sorted_data) 42 | return 0 43 | 44 | 45 | class Handlers: 46 | @staticmethod 47 | def get_openconfig_lldp_lldp_interfaces(template, *args): 48 | allif_path = Path("/restconf/data/openconfig-lldp:lldp/interfaces") 49 | return show_lldp_interface(allif_path, template) 50 | 51 | @staticmethod 52 | def get_openconfig_lldp_lldp_interfaces_interface(template, ifname, *args): 53 | oneif_path = Path("/restconf/data/openconfig-lldp:lldp/interfaces/interface={name}", name=ifname) 54 | return show_lldp_interface(oneif_path, template) 55 | 56 | 57 | def run(func, args): 58 | return getattr(Handlers, func)(*args) 59 | 60 | 61 | if __name__ == '__main__': 62 | pipestr().write(sys.argv) 63 | func = sys.argv[1] 64 | run(func, sys.argv[2:]) 65 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/show_techsupport.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 25 | 26 | 27 | 29 | 35 | 36 | 49 | 50 | 51 | 52 | python3 $SONIC_CLI_ROOT/sonic-cli-show-techsupport.py 53 | rpc_sonic_show_techsupport_sonic_show_techsupport_info 54 | ${date} 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /tools/restconf_doc_tools/index.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | ################################################################################ 3 | # # 4 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 5 | # its subsidiaries. # 6 | # # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); # 8 | # you may not use this file except in compliance with the License. # 9 | # You may obtain a copy of the License at # 10 | # # 11 | # http://www.apache.org/licenses/LICENSE-2.0 # 12 | # # 13 | # Unless required by applicable law or agreed to in writing, software # 14 | # distributed under the License is distributed on an "AS IS" BASIS, # 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 16 | # See the License for the specific language governing permissions and # 17 | # limitations under the License. # 18 | # # 19 | ################################################################################ 20 | import glob 21 | import argparse 22 | from jinja2 import Environment, FileSystemLoader 23 | import os 24 | import pdb 25 | 26 | parser = argparse.ArgumentParser() 27 | parser.add_argument('--mdDir', dest='mdDir', help='OpenAPI docs directory') 28 | 29 | args = parser.parse_args() 30 | currentDir = os.path.dirname(os.path.realpath(__file__)) 31 | # nosemgrep: python.flask.security.xss.audit.direct-use-of-jinja2.direct-use-of-jinja2 32 | templateEnv = Environment(loader=FileSystemLoader(currentDir),trim_blocks=True,lstrip_blocks=True) 33 | 34 | if args.mdDir and os.path.exists(args.mdDir): 35 | files = glob.glob(args.mdDir+'/*.md') 36 | files = list(map(lambda name: os.path.basename(name).split('.')[0], files)) 37 | template = templateEnv.get_template('index.template') 38 | # nosemgrep: python.flask.security.xss.audit.direct-use-of-jinja2.direct-use-of-jinja2 39 | content = template.render(mdfiles=files) 40 | with open(args.mdDir+"/index.md", "w") as fp: 41 | fp.write(content) 42 | 43 | -------------------------------------------------------------------------------- /CLI/clicfg/mgmt_clish_features.xsl: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /CLI/actioner/sonic-cli-pfm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | import sys 21 | import cli_client as cc 22 | from rpipe_utils import pipestr 23 | from scripts.render_cli import show_cli_output 24 | 25 | 26 | blocked_fields = {'parent':0, 'used_power':0, 'allocated_power':0, 'temperature':0} 27 | 28 | def filter_json_value(value): 29 | for key,val in list(value.items()): 30 | if key in blocked_fields: 31 | del value[key] 32 | else: 33 | temp = key.split('_') 34 | alt_key = '' 35 | for i in temp: 36 | alt_key = alt_key + i.capitalize() + ' ' 37 | value[alt_key]=value.pop(key) 38 | 39 | return value 40 | 41 | def get_openconfig_platform_components(*args): 42 | path = cc.Path('/restconf/data/openconfig-platform:components') 43 | return cc.ApiClient().get(path) 44 | 45 | def run(func, args): 46 | # lookup and invoke the function name passed by CLI 47 | response = globals()[func](*args) 48 | 49 | if response.ok(): 50 | api_response = response.content 51 | if api_response is None: 52 | return 53 | else: 54 | value = api_response['openconfig-platform:components']['component'][0]['state'] 55 | if value is None: 56 | return 57 | if 'oper-status' in value: 58 | temp = value['oper-status'].split(':') 59 | if temp[len(temp) - 1] is not None: 60 | value['oper-status'] = temp[len(temp) - 1] 61 | show_cli_output(sys.argv[2],filter_json_value(value)) 62 | 63 | else: 64 | print((response.error_message())) 65 | return 1 66 | 67 | if __name__ == '__main__': 68 | 69 | pipestr().write(sys.argv) 70 | #pdb.set_trace() 71 | func = sys.argv[1] 72 | run(func, sys.argv[2:]) 73 | 74 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/ptype.h.diff: -------------------------------------------------------------------------------- 1 | 9d8 2 | < typedef struct clish_ptype_s clish_ptype_t; 3 | 15c14 4 | < 5 | --- 6 | > #include "types.h" 7 | 16a16,18 8 | > #include 9 | > 10 | > typedef struct clish_ptype_s clish_ptype_t; 11 | 33a36 12 | > CLISH_PTYPE_METHOD_REGEXP_SELECT, /* dell-emc */ 13 | 45a49,50 14 | > /* for checking the mode attribute */ 15 | > CLISH_PTYPE_PRE_MODE, 16 | 49a55,61 17 | > enum help_type_s { 18 | > USE_NAME, 19 | > USE_VALUE, 20 | > USE_RANGE 21 | > }; 22 | > typedef enum help_type_s help_type_t; 23 | > 24 | 57c69,70 25 | < clish_ptype_preprocess_e preprocess); 26 | --- 27 | > clish_ptype_preprocess_e preprocess, const char *ext_pattern, const char *ext_help, 28 | > const char *alt_ext_pattern, const char *alt_pattern); 29 | 68c81 30 | < char *clish_ptype_validate(clish_ptype_t * instance, const char *text); 31 | --- 32 | > char *clish_ptype_validate(clish_ptype_t * instance, const char *text, bool_t isHelp); 33 | 84c97 34 | < lub_argv_t *matches, const char *text); 35 | --- 36 | > lub_argv_t *matches, const char *text, const char *penultimate_text); 37 | 95c108,126 38 | < const char *pattern, clish_ptype_method_e method); 39 | --- 40 | > const char *pattern, clish_ptype_method_e method, const char *alt_pattern); 41 | > 42 | > int get_index(char *str); 43 | > help_type_t clish_ptype__get_usename(const clish_ptype_t * instance); 44 | > clish_ptype_method_e clish_ptype__get_method(const clish_ptype_t * instance); 45 | > void clish_ptype__set_extpattern(clish_ptype_t * instance, 46 | > const char *ext_pattern, clish_ptype_method_e method, const char *ext_help, 47 | > const char *alt_ext_pattern); 48 | > char *clish_ptype_regexp_select__get_value(const clish_ptype_t * instance, unsigned index); 49 | > char *clish_ptype_regexp_select__get_ext_help(const clish_ptype_t * instance, unsigned index); 50 | > lub_argv_t *clish_ptype_regexp_select__get_argv(const clish_ptype_t * instance); 51 | > char *clish_ptype_regexp_select__get_argname(const clish_ptype_t * instance, unsigned index); 52 | > char *clish_ptype_regexp_select__get_name(const clish_ptype_t * instance, unsigned index); 53 | > int clish_ptype_regexp_select__get_argv_count(const clish_ptype_t * instance); 54 | > char *clish_ptype_regexp_select__get_ext_help(const clish_ptype_t * instance, unsigned index); 55 | > int clish_ptype_select__get_help(const clish_ptype_t *instance, clish_help_t *help, const char *pval); 56 | > void clish_ptype__set_usename(clish_ptype_t * instance, help_type_t val); 57 | > extern bool nos_use_alt_name(void); 58 | > char *clish_ptype_method_select__get_name(const clish_ptype_t *instance,unsigned int index); 59 | -------------------------------------------------------------------------------- /tools/swagger_codegen/ui-dist/oauth2-redirect.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 68 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_mclag_brief.j2: -------------------------------------------------------------------------------- 1 | {% if json_output %} 2 | 3 | {% set vars = {'domain_id': ""} %} 4 | 5 | {% set number_of_mclag_ifaces = 0 %} 6 | 7 | {% if "domain_info" is in json_output %} 8 | {% set domain_info = json_output["domain_info"] %} 9 | {% set number_of_mclag_ifaces = json_output["domain_info"]["number_of_mclag_ifaces"] %} 10 | {% endif %} 11 | 12 | {% if "mclag_iface_info" in json_output %} 13 | {% set mclag_iface_info = json_output["mclag_iface_info"] %} 14 | {% endif %} 15 | 16 | {{ ' ' }} 17 | 18 | {% if domain_info -%} 19 | 20 | {% if vars.update({'domain_id':domain_info["domain_id"]}) %}{% endif %} 21 | {% if vars.update({'role':domain_info["role"]}) %}{% endif %} 22 | {% if vars.update({'session_status':domain_info["oper_status"]}) %}{% endif %} 23 | {% if vars.update({'peer_link_status':domain_info["peer_link_status"]}) %}{% endif %} 24 | {% if vars.update({'source_ip':domain_info["source_ip"]}) %}{% endif %} 25 | {% if vars.update({'peer_ip':domain_info["peer_ip"]}) %}{% endif %} 26 | {% if vars.update({'peer_link':domain_info["peer_link"]}) %}{% endif %} 27 | {% if vars.update({'keepalive_interval':domain_info["keepalive_interval"]}) %} {% endif %} 28 | {% if vars.update({'session_timeout':domain_info["session_timeout"]}) %}{% endif %} 29 | {% if vars.update({'system_mac':domain_info["system_mac"]}) %}{% endif %} 30 | 31 | 32 | {{'Domain ID'.ljust(20)}} : {{ vars.domain_id }} 33 | {{'Role'.ljust(20)}} : {{ vars.role}} 34 | {{'Session Status'.ljust(20)}} : {{ vars.session_status}} 35 | {{'Peer Link Status'.ljust(20)}} : {{ vars.peer_link_status}} 36 | {{'Source Address'.ljust(20)}} : {{ vars.source_ip}} 37 | {{'Peer Address'.ljust(20)}} : {{ vars.peer_ip}} 38 | {{'Peer Link'.ljust(20)}} : {{ vars.peer_link}} 39 | {{'Keepalive Interval'.ljust(20)}} : {{ vars.keepalive_interval}} {{'secs'}} 40 | {{'Session Timeout'.ljust(20)}} : {{ vars.session_timeout}} {{'secs'}} 41 | {{'System Mac'.ljust(20)}} : {{ vars.system_mac}} 42 | 43 | {{ ' \n ' }} 44 | Number of MLAG Interfaces:{{ number_of_mclag_ifaces }} 45 | 46 | {% if mclag_iface_info -%} 47 | {{'-----------------------------------------------------------'}} 48 | {{'MLAG Interface'.ljust(20)}} {{'Local/Remote Status'.ljust(20)}} 49 | {{'-----------------------------------------------------------'}} 50 | {% for key in mclag_iface_info %} 51 | {% if vars.update({'if_name':mclag_iface_info[key]["if_name"]}) %}{% endif %} 52 | {% if vars.update({'local_if_status':mclag_iface_info[key]["local_if_status"]}) %}{% endif %} 53 | {% if vars.update({'remote_if_status':mclag_iface_info[key]["remote_if_status"]}) %}{% endif %} 54 | 55 | {{(vars.if_name).ljust(25)}}{{vars.local_if_status}}{{'/'}}{{vars.remote_if_status}} 56 | {% endfor %} 57 | {% endif %} 58 | 59 | {% endif %} 60 | 61 | {% endif %} 62 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | ]> 25 | 26 | 27 | 28 | python3 $SONIC_CLI_ROOT/sonic-cli-sys.py get_openconfig_system_system_state system_show.j2 ${__full_line} 29 | 30 | 31 | 32 | python3 $SONIC_CLI_ROOT/sonic-cli-sys.py get_openconfig_system_system_memory system_show.j2 ${__full_line} 33 | 34 | 35 | 36 | python3 $SONIC_CLI_ROOT/sonic-cli-sys.py get_openconfig_system_system_cpus system_cpu_show.j2 ${__full_line} 37 | 38 | 39 | 40 | python3 $SONIC_CLI_ROOT/sonic-cli-sys.py get_openconfig_system_system_processes system_processes_show.j2 ${__full_line} 41 | 42 | 43 | 44 | 49 | 50 | python3 $SONIC_CLI_ROOT/sonic-cli-sys.py get_openconfig_system_system_processes system_show.j2 ${pid-no} ${__full_line} 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /tools/restconf_doc_tools/utils/json_delta/_patch.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | # json_delta: a library for computing deltas between JSON-serializable 3 | # structures. 4 | # json_delta/_patch.py 5 | # 6 | # Copyright 2012‒2015 Philip J. Roberts . 7 | # BSD License applies; see the LICENSE file, or 8 | # http://opensource.org/licenses/BSD-2-Clause 9 | '''Functions for applying JSON-format patches.''' 10 | from __future__ import unicode_literals, print_function 11 | import copy 12 | 13 | 14 | def patch(struc, diff, in_place=True): 15 | '''Apply the sequence of diff stanzas ``diff`` to the structure 16 | ``struc``. 17 | 18 | By default, this function modifies ``struc`` in place; set 19 | ``in_place`` to ``False`` to return a patched copy of struc 20 | instead: 21 | 22 | >>> will_change = [16] 23 | >>> wont_change = [16] 24 | >>> patch(will_change, [[[0]]]) 25 | [] 26 | >>> will_change 27 | [] 28 | >>> patch(wont_change, [[[0]]], False) 29 | [] 30 | >>> wont_change 31 | [16] 32 | ''' 33 | if not in_place: 34 | struc = copy.deepcopy(struc) 35 | for stanza in diff: 36 | struc = patch_stanza(struc, stanza) 37 | return struc 38 | 39 | 40 | def patch_stanza(struc, stanza): 41 | '''Applies the stanza ``stanza`` to the structure ``struc`` as 42 | a patch. 43 | 44 | Note that this function modifies ``struc`` in-place into the 45 | target of ``stanza``. If ``struc`` is a :func:`tuple`, you get a 46 | new tuple with the appropriate modification made: 47 | 48 | >>> patch_stanza((17, 3.141593, None), [[1], 3.14159265]) 49 | (17, 3.14159265, None) 50 | 51 | ''' 52 | changeback = False 53 | if type(struc) is tuple: 54 | changeback = True 55 | struc = list(struc)[:] 56 | key = stanza[0] 57 | if not key: 58 | struc = stanza[1] 59 | changeback = False 60 | elif len(key) == 1: 61 | if len(stanza) == 1: 62 | del struc[key[0]] 63 | elif len(stanza) == 3: 64 | assert stanza[2] == 'i', stanza 65 | if isinstance(struc, list): 66 | struc.insert(key[0], stanza[1]) 67 | else: 68 | assert isinstance(struc, dict) 69 | struc[key[0]] = stanza[1] 70 | elif isinstance(struc, list) and key[0] == len(struc): 71 | struc.append(stanza[1]) 72 | else: 73 | struc[key[0]] = stanza[1] 74 | else: 75 | pass_key = key[:] 76 | pass_struc_key = pass_key.pop(0) 77 | pass_struc = struc[pass_struc_key] 78 | pass_diff = [pass_key] + stanza[1:] 79 | struc[pass_struc_key] = patch_stanza(pass_struc, pass_diff) 80 | if changeback: 81 | struc = tuple(struc) 82 | return struc 83 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/ipv4.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 26 | 27 | 28 | 31 | 32 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 58 | 59 | 60 | 63 | 67 | python3 $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config ${iface} ${addr} 68 | 69 | 70 | 74 | 78 | 79 | python3 $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv4_addresses_address_config_prefix_length ${iface} ${addr} 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /CLI/clitree/cli-xml/enable_mode.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 42 | 47 | 50 | 51 | 55 | 60 | 61 | 62 | 66 | 67 | 71 | 76 | 77 | 78 | ${cmd} 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /CLI/actioner/cli_log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | ################################################################################ 3 | # # 4 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 5 | # its subsidiaries. # 6 | # # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); # 8 | # you may not use this file except in compliance with the License. # 9 | # You may obtain a copy of the License at # 10 | # # 11 | # http://www.apache.org/licenses/LICENSE-2.0 # 12 | # # 13 | # Unless required by applicable law or agreed to in writing, software # 14 | # distributed under the License is distributed on an "AS IS" BASIS, # 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 16 | # See the License for the specific language governing permissions and # 17 | # limitations under the License. # 18 | # # 19 | ################################################################################ 20 | 21 | import os 22 | import syslog 23 | import inspect 24 | 25 | syslog.openlog('sonic-cli') 26 | __enable_debug = (os.getenv("DEBUG") is not None) 27 | __enable_print = (os.getenv("LOGTOSCREEN") is not None) 28 | __severity_str = [ 'EMERG', 'ALERT', 'CRIT', 'ERROR', 'WARN', 'NOTICE', 'INFO', 'DEBUG' ] 29 | 30 | 31 | def log_debug(msg, *args, **kwargs): 32 | if __enable_debug: 33 | __write_log(syslog.LOG_DEBUG, msg, *args, **kwargs) 34 | 35 | def log_info(msg, *args, **kwargs): 36 | __write_log(syslog.LOG_INFO, msg, *args, **kwargs) 37 | 38 | def log_warning(msg, *args, **kwargs): 39 | __write_log(syslog.LOG_WARNING, msg, *args, **kwargs) 40 | 41 | def log_error(msg, *args, **kwargs): 42 | __write_log(syslog.LOG_ERR, msg, *args, **kwargs) 43 | 44 | 45 | def __write_log(severity, msg, *args, **kwargs): 46 | if not isinstance(msg, str): 47 | msg = str(msg) 48 | else: 49 | msg = msg.format(*args, **kwargs) 50 | 51 | syslog.syslog(severity, msg) 52 | 53 | if __enable_print: 54 | caller_frame = inspect.stack()[2][0] 55 | frame_info = inspect.getframeinfo(caller_frame) 56 | for line in msg.split('\n'): 57 | print(('[{}:{}/{}] {}:: {}'.format( 58 | os.path.basename(frame_info.filename), 59 | frame_info.lineno, 60 | frame_info.function, 61 | __severity_str[severity], 62 | line))) 63 | -------------------------------------------------------------------------------- /tools/test/rest-server.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # # 5 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 6 | # its subsidiaries. # 7 | # # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); # 9 | # you may not use this file except in compliance with the License. # 10 | # You may obtain a copy of the License at # 11 | # # 12 | # http://www.apache.org/licenses/LICENSE-2.0 # 13 | # # 14 | # Unless required by applicable law or agreed to in writing, software # 15 | # distributed under the License is distributed on an "AS IS" BASIS, # 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 17 | # See the License for the specific language governing permissions and # 18 | # limitations under the License. # 19 | # # 20 | ################################################################################ 21 | 22 | set -e 23 | 24 | TOPDIR=$(git rev-parse --show-toplevel || echo ${PWD}) 25 | BUILD_DIR=$TOPDIR/build 26 | SERVER_DIR=$TOPDIR/build/rest_server 27 | MGMT_COMMON_DIR=$(realpath $TOPDIR/../sonic-mgmt-common) 28 | 29 | if [[ ! -f $SERVER_DIR/rest_server ]]; then 30 | echo "error: REST server not compiled" 31 | echo "Please run 'make rest-server' and try again" 32 | exit 1 33 | fi 34 | 35 | source ${MGMT_COMMON_DIR}/tools/test/env.sh --dest=${SERVER_DIR} 36 | 37 | EXTRA_ARGS="-rest_ui $SERVER_DIR/dist/ui -logtostderr" 38 | 39 | for V in $@; do 40 | case $V in 41 | -cert|--cert|-cert=*|--cert=*) HAS_CRTFILE=1;; 42 | -key|--key|-key=*|--key=*) HAS_KEYFILE=1;; 43 | -v|--v|-v=*|--v=*) HAS_V=1;; 44 | -client_auth|--client_auth) HAS_AUTH=1;; 45 | -client_auth=*|--client_auth=*) HAS_AUTH=1;; 46 | esac 47 | done 48 | 49 | [[ -z ${HAS_V} ]] && EXTRA_ARGS+=" -v 1" 50 | [[ -z ${HAS_AUTH} ]] && EXTRA_ARGS+=" -client_auth none" 51 | 52 | cd $SERVER_DIR 53 | 54 | ## 55 | # Setup TLS server cert/key pair 56 | if [ -z $HAS_CRTFILE ] && [ -z $HAS_KEYFILE ]; then 57 | if [ -f cert.pem ] && [ -f key.pem ]; then 58 | echo "Reusing existing cert.pem and key.pem ..." 59 | else 60 | echo "Generating temporary server certificate ..." 61 | ./generate_cert --host localhost 62 | fi 63 | 64 | EXTRA_ARGS+=" -cert cert.pem -key key.pem" 65 | fi 66 | 67 | ## 68 | # Start server 69 | ./rest_server $EXTRA_ARGS $* 70 | 71 | -------------------------------------------------------------------------------- /models/codegen.config: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # # 3 | # Copyright 2020 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 4 | # its subsidiaries. # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ################################################################################ 19 | 20 | # Build time configurations for swagger codegen 21 | # Use makefile syntax 22 | 23 | ## 24 | # YANGAPI_EXCLUDES indicates the yang modules to be excluded from codegen. 25 | # Server and client code will not be generated for these yangs modules. 26 | # By default server code will be generated for all yangs under models/yang 27 | # and models/yang/sonic directories. Note that each entry should be yang 28 | # module name which is used for generated yaml file name. 29 | YANGAPI_EXCLUDES += 30 | 31 | ## 32 | # PY_YANGAPI_CLIENTS indicates the yang modules for which python client 33 | # sdk code should be generated. By default client sdk code will not be 34 | # generated to save build time and space. YANGAPI_EXCLUDES has priority 35 | # over this list. Note that the entry should be the yang module name 36 | # which is used for generated yaml file name. 37 | PY_YANGAPI_CLIENTS += 38 | 39 | ## 40 | # OPENAPI_EXCLUDES indicates the OpenAPI specs to be excluded from codegen. 41 | # By default all yaml files under models/openapi directory are considered 42 | # for codegen. Items should be the yaml file name without the .yaml extension. 43 | # Eg: vlan.yaml should be specified as "OPENAPI_EXCLUDES += vlan" 44 | OPENAPI_EXCLUDES += 45 | 46 | ## 47 | # PY_OPENAPI_CLIENTS indicates the OpenAPI specs for which python client 48 | # sdk code should be generated. By default client sdk code is not generated. 49 | # Items should be the yaml file name without the .yaml extension. Note 50 | # that OPENAPI_EXCLUDES has priority over this list. 51 | PY_OPENAPI_CLIENTS += 52 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # # 3 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 4 | # its subsidiaries. # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ################################################################################ 19 | 20 | TOPDIR := $(abspath .) 21 | BUILD_DIR := $(TOPDIR)/build 22 | MGMT_COMMON_DIR := $(abspath ../sonic-mgmt-common) 23 | 24 | GO ?= /usr/local/go/bin/go 25 | GOPATH ?= /tmp/go 26 | 27 | GO_MOD = go.mod 28 | GO_DEPS = vendor/.done 29 | GO_CODEGEN_INIT := $(BUILD_DIR)/rest_server/dist/.init_done 30 | 31 | export TOPDIR MGMT_COMMON_DIR GO GOPATH 32 | 33 | .PHONY: all 34 | all: rest cli 35 | 36 | $(GO_MOD): 37 | $(GO) mod init github.com/Azure/sonic-mgmt-framework 38 | 39 | $(GO_DEPS): $(GO_MOD) $(GO_CODEGEN_INIT) 40 | $(GO) mod vendor 41 | $(MGMT_COMMON_DIR)/patches/apply.sh vendor 42 | touch $@ 43 | 44 | go-deps: $(GO_DEPS) 45 | 46 | go-deps-clean: 47 | $(RM) -r vendor 48 | 49 | cli: 50 | $(MAKE) -C CLI 51 | 52 | clitree: 53 | TGT_DIR=$(BUILD_DIR)/cli $(MAKE) -C CLI/clitree 54 | 55 | clish: 56 | SONIC_CLI_ROOT=$(BUILD_DIR) $(MAKE) -C CLI/klish 57 | 58 | .PHONY: rest 59 | rest: $(GO_DEPS) models 60 | $(MAKE) -C rest 61 | 62 | # Special target for local compilation of REST server binary. 63 | # Compiles models, translib and cvl schema from sonic-mgmt-common 64 | rest-server: go-deps-clean 65 | NO_TEST_BINS=1 $(MAKE) -C $(MGMT_COMMON_DIR) 66 | NO_TEST_BINS=1 $(MAKE) rest 67 | 68 | rest-clean: go-deps-clean models-clean 69 | $(MAKE) -C rest clean 70 | 71 | $(GO_CODEGEN_INIT): 72 | $(MAKE) -C models -f openapi_codegen.mk go-server-init 73 | 74 | .PHONY: models 75 | models: | $(GO_CODEGEN_INIT) 76 | $(MAKE) -C models 77 | 78 | models-clean: 79 | $(MAKE) -C models clean 80 | 81 | clean: rest-clean models-clean 82 | git check-ignore debian/* | xargs -r $(RM) -r 83 | $(RM) -r debian/.debhelper 84 | $(RM) -r $(BUILD_DIR) 85 | 86 | cleanall: clean 87 | 88 | -------------------------------------------------------------------------------- /CLI/actioner/sonic-cli-show-techsupport.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | import cli_client as cc 5 | import re 6 | 7 | def invoke(func, args): 8 | body = None 9 | aa = cc.ApiClient() 10 | 11 | # Gather tech support information into a compressed file 12 | if func == 'rpc_sonic_show_techsupport_sonic_show_techsupport_info': 13 | keypath = cc.Path('/restconf/operations/sonic-show-techsupport:sonic-show-techsupport-info') 14 | if args is None: 15 | body = {"sonic-show-techsupport:input":{"date": None}} 16 | else: 17 | body = {"sonic-show-techsupport:input":{"date": args[0]}} 18 | return aa.post(keypath, body) 19 | else: 20 | print("%Error: not implemented") 21 | exit(1) 22 | 23 | 24 | def run(func, args): 25 | 26 | if func != 'rpc_sonic_show_techsupport_sonic_show_techsupport_info': 27 | print("%Error: Show Techsupport parsing Failed: Invalid " 28 | "function") 29 | return 30 | 31 | try: 32 | api_response = invoke(func, args) 33 | 34 | except ValueError as err_msg: 35 | print("%Error: An exception occurred while attempting to gather " 36 | "the requested information via a remote procedure " 37 | "call: {}".format(err_msg)) 38 | 39 | if not api_response.ok(): 40 | # Print the message for a failing return code 41 | print("CLI transformer error: ") 42 | print(" status code: {}".format(response.status_code)) 43 | return 44 | 45 | response = api_response.content 46 | if ((response is None) or 47 | (not ('sonic-show-techsupport:output' in response)) or 48 | (response['sonic-show-techsupport:output'] is None)): 49 | if ('ietf-restconf:errors' in response): 50 | print(response['ietf-restconf:errors']['error'][0]['error-message']) 51 | else: 52 | print("%Error: Command Failure: Unknown failure type") 53 | return 54 | 55 | output_msg_object = response['sonic-show-techsupport:output'] 56 | 57 | if ((output_msg_object['output-status'] is None) or 58 | (len(output_msg_object['output-status']) is 0)): 59 | print("%Error: Command Failure: Unknown failure type") 60 | return 61 | 62 | if not (output_msg_object['output-status'] == "Success"): 63 | print("%Error: {}".format(output_msg_object['output-status'])) 64 | return 65 | 66 | if ((output_msg_object['output-filename'] is None) or 67 | (len(output_msg_object['output-filename']) is 0)): 68 | print("%Error: Command Failure: Unknown failure type") 69 | return 70 | 71 | # No error code flagged: Normal case handling 72 | output_message = output_msg_object['output-filename'] 73 | output_file_match = re.search('\/var\/.*dump.*\.gz', 74 | output_message) 75 | if output_file_match is not None: 76 | output_filename = output_file_match.group() 77 | print("Output stored in: " + output_filename) 78 | else: 79 | # Error message with non-error return code 80 | print(output_message) 81 | 82 | 83 | 84 | if __name__ == '__main__': 85 | if len(sys.argv) == 3: 86 | run(sys.argv[1], sys.argv[2:]) 87 | else: 88 | run(sys.argv[1], None) 89 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/tinyrl/tinyrl.c.diff: -------------------------------------------------------------------------------- 1 | 1414a1415,1430 2 | > int indexi,indexj; 3 | > char * temp = NULL; 4 | > for (indexi=1;indexi 6 | > for (indexj=indexi+1;indexj<=len-1;indexj++) { 7 | > if ((matches[indexi] == NULL) || (matches[indexj] == NULL)) 8 | > continue; 9 | > 10 | > if(lub_string_nocasecmp(matches[indexi],matches[indexj]) > 0) { 11 | > temp = matches[indexi]; 12 | > matches[indexi] = matches[indexj]; 13 | > matches[indexj] = temp; 14 | > } 15 | > } 16 | > } 17 | > 18 | 1435a1452,1496 19 | > static void 20 | > tinyrl_do_complete_ignore_error(tinyrl_t * this, bool_t with_extensions) 21 | > { 22 | > char **matches = NULL; 23 | > unsigned int start, end; 24 | > 25 | > /* find the start and end of the current word */ 26 | > start = end = this->point; 27 | > while (start && !isspace(this->line[start - 1])) 28 | > start--; 29 | > 30 | > if (this->attempted_completion_function) { 31 | > this->completion_over = BOOL_FALSE; 32 | > this->completion_error_over = BOOL_FALSE; 33 | > /* try and complete the current line buffer */ 34 | > matches = this->attempted_completion_function(this, 35 | > this->line, start, end); 36 | > } 37 | > if (!matches && (BOOL_FALSE == this->completion_over)) { 38 | > /* insert default completion call here... */ 39 | > } 40 | > if (!matches) 41 | > return; 42 | > 43 | > /* Check if user entered value is a substring of match returned. 44 | > If true, replace the line with the matched value */ 45 | > if ((end - start > 0) && (0 == strncasecmp(matches[0], &this->line[start], 46 | > (end - start)))) { 47 | > /* 48 | > * delete the original text not including 49 | > * the current insertion point character 50 | > */ 51 | > if (this->end != end) 52 | > end--; 53 | > tinyrl_delete_text(this, start, end); 54 | > tinyrl_insert_text(this, matches[0]); 55 | > } 56 | > 57 | > tinyrl_delete_matches(matches); 58 | > /* redisplay the line */ 59 | > tinyrl_redisplay(this); 60 | > return; 61 | > } 62 | > 63 | > /*-------------------------------------------------------- */ 64 | 1447a1509,1514 65 | > void tinyrl_complete_ignore_error(tinyrl_t * this) 66 | > { 67 | > return tinyrl_do_complete_ignore_error(this, BOOL_FALSE); 68 | > } 69 | > 70 | > /*-------------------------------------------------------- */ 71 | 1656a1724,1730 72 | > 73 | > /*-------------------------------------------------------- */ 74 | > bool_t tinyrl_is_cursor_in_middle(const tinyrl_t *this) 75 | > { 76 | > return (this->point < this->end) ? BOOL_TRUE : BOOL_FALSE; 77 | > } 78 | > 79 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/plugins/clish/nos_extn.c: -------------------------------------------------------------------------------- 1 | /* 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | */ 20 | 21 | #include "private.h" 22 | #include "nos_extn.h" 23 | #include "lub/string.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | pthread_mutex_t lock; 34 | 35 | void *rest_token_refresh(void *vargp){ 36 | int expiry = (intptr_t)vargp; 37 | int interval; 38 | while(1) { 39 | interval = 0.8 * expiry; 40 | syslog(LOG_DEBUG, "Token update - sleeping for %d of %d", interval, expiry); 41 | 42 | /* Sleep for 80% of the interval */ 43 | sleep(interval); 44 | 45 | pthread_mutex_lock(&lock); 46 | 47 | rest_token_fetch(&expiry); 48 | 49 | pthread_mutex_unlock(&lock); 50 | } 51 | } 52 | 53 | int clish_rest_thread_init() { 54 | pthread_t thread_id; 55 | 56 | 57 | int expiry = 30; 58 | rest_token_fetch(&expiry); 59 | 60 | pthread_create(&thread_id, NULL, rest_token_refresh, (void*)(long)expiry); 61 | return 0; 62 | } 63 | 64 | CLISH_PLUGIN_SYM(clish_restcl) 65 | { 66 | char *cmd = clish_shell__get_full_line(clish_context); 67 | 68 | pthread_mutex_lock(&lock); 69 | 70 | int ret = rest_cl(cmd, script); 71 | 72 | pthread_mutex_unlock(&lock); 73 | 74 | lub_string_free(cmd); 75 | 76 | return ret; 77 | } 78 | 79 | CLISH_PLUGIN_SYM(clish_pyobj) 80 | { 81 | char *cmd = clish_shell__get_full_line(clish_context); 82 | 83 | sigset_t sigs; 84 | sigemptyset(&sigs); 85 | sigaddset(&sigs, SIGINT); 86 | sigprocmask(SIG_UNBLOCK, &sigs, NULL); 87 | 88 | pthread_mutex_lock(&lock); 89 | int ret = call_pyobj(cmd, script, out); 90 | pthread_mutex_unlock(&lock); 91 | 92 | return ret; 93 | } 94 | 95 | CLISH_PLUGIN_SYM(clish_setenv) 96 | { 97 | char *key, *value; 98 | key = strtok_r((char*)script, "=", &value); 99 | 100 | if (key) { 101 | pyobj_update_environ(key,value); 102 | 103 | setenv(key, value, 1); 104 | } 105 | 106 | return 0; 107 | } 108 | 109 | void nos_extn_init() { 110 | 111 | pthread_mutex_init(&lock, NULL); 112 | 113 | int auth_ena = (getenv("CLISH_NOAUTH") == NULL); 114 | 115 | rest_client_init(); 116 | pyobj_init(); 117 | 118 | if (auth_ena) { 119 | clish_rest_thread_init(); 120 | } 121 | 122 | if (!auth_ena) { 123 | syslog(LOG_WARNING, "CLISH running with auth disabled"); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /CLI/actioner/README_cli_client.md: -------------------------------------------------------------------------------- 1 | # Generic REST Client for CLI 2 | 3 | Actioner scripts can use the generic rest client **cli_client.py** to communicate to REST Server. 4 | This client is tailor made to connect to local REST Server and handle the CLI actioner usecases. 5 | 6 | To use this tool, first create an `ApiClient` object. 7 | 8 | ```python 9 | import cli_client as cc 10 | 11 | api = cc.ApiClient() 12 | ``` 13 | 14 | Create a path object for target REST resource. It accepts parameterized path template and parameter 15 | values. Path template is similar to the template used by swagger. Parameter values will be URL-encoded 16 | and substituted in the template to get REST resource path. 17 | 18 | ```python 19 | path = cc.Path('/restconf/data/openconfig-acl:acl/acl-sets/acl-set={name},{type}/acl-entries', 20 | name='MyNewAccessList', type='ACL_IPV4') 21 | ``` 22 | 23 | Invoke REST API.. `ApiClient` object supports get, post, put, patch and delete operations. 24 | All these operations send a REST request and return a response object wrapping the REST response data. 25 | 26 | ```python 27 | response = api.get(path) 28 | ``` 29 | 30 | Check API status through `response.ok()` function, which returns true if API was success - REST server 31 | returned HTTP 2xx status code. `ok()` function returns false if server returned any other status response. 32 | Use `response.status_code` to inspect actual status code. 33 | 34 | ```python 35 | if response.ok() { 36 | respJson = response.content 37 | # invoke renderer to display respJson 38 | } else { 39 | print(response.error_message()) 40 | } 41 | ``` 42 | 43 | If request was successful, `response.content` will hold the response data as JSON dictionary object. 44 | If request failed, `response.content` will hold error JSON returned by the server. CLI displayable 45 | error message can be extracted using `response.error_message()` function. 46 | 47 | Examples of other REST API calls. 48 | 49 | ```python 50 | jsonDict = {} 51 | jsonDict["acl-set"]=[{ "name":the_acl_name, .... }] # construct your request data json 52 | 53 | # POST request 54 | response = api.post(path, data=jsonDict) 55 | 56 | # PUT request 57 | reponse = api.put(path, data=jsonDict) 58 | 59 | # PATCH request 60 | response = api.patch(path, data=jsonDict) 61 | 62 | # DELETE request 63 | response = api.delete(path) 64 | ``` 65 | 66 | Above example used `response.error_message()` function to get displayable error message from 67 | the REST response. REST server always returns error information in standard RESTCONF error format. 68 | The `error_message()` function looks for the **error-message** attribute to get user displayable message. 69 | A generic message will be returned based on **error-tag** attribute value if there was no **error-message** 70 | attribute. This can be customized through an error formatter function as shown below. 71 | Default error formatter is sufficient for most of the cases. 72 | 73 | ```python 74 | if not response.ok(): 75 | print(response.error_message(formatter_func=my_new_error_message_formatter)) 76 | ``` 77 | 78 | The custom formtter function would receive RESTCONF error json and should return a string. 79 | Below is a sample implementation which uses error-type attribute to format an error message. 80 | 81 | ```python 82 | def my_new_error_message_formatter(status_code, error_entry): 83 | if err_entry['error-type'] == 'protocol': 84 | return "System error.. Please reboot!!" 85 | return "Application error.. Please retry." 86 | ``` 87 | -------------------------------------------------------------------------------- /CLI/renderer/templates/show_access_list.j2: -------------------------------------------------------------------------------- 1 | {% macro traverse_acl_entry(acl_entry_list) -%} 2 | {% for seq in acl_entry_list %} 3 | {% set response_list = [] %} 4 | {# Get sequence id #} 5 | {% set seqid = seq["sequence-id"] %} 6 | {% set _list = response_list.append( seqid ) %} 7 | {# Get forwarding action #} 8 | {% set fwd_action = seq["actions"]["config"]["forwarding-action"] %} 9 | {%- if "ACCEPT" in fwd_action %} 10 | {% set fwd_action = "permit" %} 11 | {%- endif %} 12 | {%- if "DROP" in fwd_action %} 13 | {% set fwd_action = "deny" %} 14 | {%- endif %} 15 | {% set _list = response_list.append( fwd_action ) %} 16 | {# Get protocol #} 17 | {% set proto = seq["ipv4"]["state"]["protocol"].split(':')[1].split('_')[1]|lower %} 18 | {% set _list = response_list.append( proto ) %} 19 | {# Get Source IP #} 20 | {% set src_ip = seq["ipv4"]["state"]["source-address"] %} 21 | {% set _list = response_list.append( src_ip ) %} 22 | {# include src port number if available #} 23 | {%- if seq["transport"] %} 24 | {%- if seq["transport"]["config"]["source-port"] %} 25 | {% set src_port = "eq " + seq["transport"]["config"]["source-port"]|string %} 26 | {% set _list = response_list.append( src_port ) %} 27 | {%- endif %} 28 | {%- endif %} 29 | {# Get Destination IP #} 30 | {% set dstn_ip = seq["ipv4"]["state"]["destination-address"] %} 31 | {% set _list = response_list.append( dstn_ip ) %} 32 | {# include dstn port number if available #} 33 | {%- if seq["transport"] %} 34 | {%- if seq["transport"]["config"]["destination-port"] %} 35 | {% set dstn_port = "eq " + seq["transport"]["config"]["destination-port"]|string %} 36 | {% set _list = response_list.append( dstn_port ) %} 37 | {%- endif %} 38 | {%- if seq["transport"]["config"]["tcp-flags"] %} 39 | {% for var in seq["transport"]["config"]["tcp-flags"] %} 40 | {% set flag = var.split(':')[1].split('_')[1]|lower %} 41 | {% set _list = response_list.append( flag ) %} 42 | {% endfor %} 43 | {%- endif %} 44 | {%- endif %} 45 | {%- if seq["ipv4"]["state"]["dscp"] %} 46 | {% set _list = response_list.append( "dscp "+seq["ipv4"]["state"]["dscp"]|string ) %} 47 | {%- endif %} 48 | {{- " " }} {{ response_list|join(' ') }} 49 | {% endfor %} 50 | {%- endmacro %} 51 | {% for key in json_output %} 52 | {# This condition checks if the JSON response has data from the acl-entry list #} 53 | {% if "acl-entry" in key -%} 54 | {% set acl_entry = json_output[key] -%} 55 | {{ traverse_acl_entry(acl_entry) }} 56 | {%- endif %} 57 | {% endfor %} 58 | {% for acl_sets in json_output -%} 59 | {% if "acl-set" in acl_sets -%} 60 | {# This condition checks if the JSON response has data from the acl-sets container output -#} 61 | {% for acl_set in json_output[acl_sets] %} 62 | {% if acl_set["state"] -%} 63 | ip access-list {{ acl_set["state"]["name"] }} 64 | {% set acl_entry_list = acl_set["acl-entries"] %} 65 | {% if acl_entry_list -%} 66 | {% for each in acl_entry_list -%} 67 | {% set acl_entry = acl_entry_list[each] -%} 68 | {{ traverse_acl_entry(acl_entry) }} 69 | {%- endfor %} 70 | {%- endif %} 71 | {%- endif %} 72 | {% endfor %} 73 | {%- endif %} 74 | {%- endfor %} 75 | -------------------------------------------------------------------------------- /tools/test/rest-gotest.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################################################################################ 3 | # # 4 | # Copyright 2020 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 5 | # its subsidiaries. # 6 | # # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); # 8 | # you may not use this file except in compliance with the License. # 9 | # You may obtain a copy of the License at # 10 | # # 11 | # http://www.apache.org/licenses/LICENSE-2.0 # 12 | # # 13 | # Unless required by applicable law or agreed to in writing, software # 14 | # distributed under the License is distributed on an "AS IS" BASIS, # 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 16 | # See the License for the specific language governing permissions and # 17 | # limitations under the License. # 18 | # # 19 | ################################################################################ 20 | 21 | set -e 22 | 23 | [[ -z ${TOPDIR} ]] && TOPDIR=$(git rev-parse --show-toplevel) || true 24 | [[ -z ${GO} ]] && GO=go || true 25 | 26 | TESTARGS=() 27 | 28 | while [[ $# -gt 0 ]]; do 29 | case "$1" in 30 | -h|-help|--help) 31 | echo "usage: $(basename $0) [-bin] [-json] [-run NAME] [-auth] [ARGS...]" 32 | echo "" 33 | echo " -bin Run test binary {TOPDIR}/build/tests/rest/server.test" 34 | echo " -json Prints output in json format" 35 | echo " -run NAME Run specific test cases." 36 | echo " -auth Run auth tests; shorthand for '-run Auth -authtest local'" 37 | echo " ARGS... Arguments to test program (log level, auth test arguments etc)" 38 | exit 0 ;; 39 | -bin) 40 | TESTBIN=${TOPDIR}/build/tests/rest/server.test 41 | shift ;; 42 | -json) 43 | JSON=1 44 | shift ;; 45 | -run) 46 | TESTCASE="$2" 47 | shift 2 ;; 48 | -auth) 49 | TESTCASE="Auth" 50 | TESTARGS+=("-authtest" "local") 51 | shift ;; 52 | *) 53 | TESTARGS+=("$1") 54 | shift;; 55 | esac 56 | done 57 | 58 | MGMT_COMMON_DIR=$(realpath ${TOPDIR}/../sonic-mgmt-common) 59 | 60 | export CVL_SCHEMA_PATH=${MGMT_COMMON_DIR}/build/cvl/schema 61 | 62 | export DB_CONFIG_PATH=${MGMT_COMMON_DIR}/tools/test/database_config.json 63 | 64 | PKG="github.com/Azure/sonic-mgmt-framework/rest/server" 65 | DIR="${PWD}" 66 | 67 | if [[ -z ${TESTBIN} ]]; then 68 | # run "go test" from source 69 | CMD=( ${GO} test "${PKG}" -mod=vendor -v -cover -tags test ) 70 | [[ -z ${JSON} ]] || CMD+=( -json ) 71 | [[ -z ${TESTCASE} ]] || CMD+=( -run "${TESTCASE}" ) 72 | CMD+=( -args ) #keep it last 73 | else 74 | # run compiled test binary 75 | DIR="$(dirname ${TESTBIN})" 76 | CMD=( ./$(basename ${TESTBIN}) -test.v ) 77 | [[ -z ${JSON} ]] || CMD=( ${GO} tool test2json -p "${PKG}" -t "${CMD[@]}" ) 78 | [[ -z ${TESTCASE} ]] || CMD+=( -test.run "${TESTCASE}" ) 79 | fi 80 | 81 | [[ "${TESTARGS[@]}" =~ -(also)?logtostderr ]] || TESTARGS+=( -logtostderr ) 82 | 83 | (cd "${DIR}" && "${CMD[@]}" "${TESTARGS[@]}") 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SONiC Management Framework Repo 2 | 3 | ### Build Instruction 4 | Please note that the build instruction in this guide has only been tested on Ubuntu 16.04. 5 | #### Pre-rerequisit 6 | ##### User permissions: 7 | `sudo usermod -aG sudo $USER` 8 | `sudo usermod -aG docker $USER` 9 | 10 | ##### Packages to be installed: 11 | `sudo apt-get install git docker` 12 | 13 | #### Steps to build and create an installer 14 | 1. git clone https://github.com/project-arlo/sonic-buildimage.git 15 | 2. cd sonic-buildimage/ 16 | 3. sudo modprobe overlay 17 | 4. make init 18 | 5. make configure PLATFORM=broadcom 19 | 6. Run the prefetch python script to download all binaries (see below for the script). 20 | 7. To build mgmt-framework container: 21 | `BLDENV=stretch make target/docker-sonic-mgmt-framework.gz` 22 | 8. To build Debian Stretch, if not already downloaded: 23 | `BLDENV=stretch make stretch` 24 | 9. To build the ONIE installer: 25 | `BLDENV=stretch make target/sonic-broadcom.bin` 26 | 27 | #### Faster builds 28 | In order to speed up the process of build, you can prefetch the latest debian files from Azure server, and just build what you need. 29 | 30 | Here is a python script you could use to fetch latest prebuilt objects (deb, gz, ko, etc) from SONiC Jenkins cluster: 31 | 32 | import os 33 | import shutil 34 | import urllib.request 35 | from html.parser import HTMLParser 36 | 37 | UPSTREAM_PREFIX = 'https://sonic-jenkins.westus2.cloudapp.azure.com/job/broadcom/job/buildimage-brcm-all/lastSuccessfulBuild/artifact/' 38 | 39 | def get_all_bins(target_path, extension): 40 | """Get all files matching the given extension from the target path""" 41 | print('Fetching %s*%s' % (target_path, extension)) 42 | os.makedirs(target_path, exist_ok=True) 43 | 44 | req = urllib.request.urlopen(UPSTREAM_PREFIX + target_path) 45 | data = req.read().decode() 46 | 47 | class Downloader(HTMLParser): 48 | """Class to parse retrieved data, match against the given extension, 49 | and download the matching files to the given target directory""" 50 | def handle_starttag(self, tag, attrs): 51 | """Handle only tags""" 52 | if tag == 'a': 53 | for attr, val in attrs: 54 | if attr == 'href' and val.endswith(extension): 55 | self.download_file(val) 56 | 57 | @staticmethod 58 | def download_file(path): 59 | filename = os.path.join(target_path, path) 60 | freq = urllib.request.urlopen(UPSTREAM_PREFIX + target_path + path) 61 | 62 | print('\t%s' % path) 63 | with open(filename, 'wb') as fp: 64 | shutil.copyfileobj(freq, fp) 65 | 66 | 67 | parser = Downloader() 68 | parser.feed(data) 69 | print() 70 | 71 | get_all_bins('target/debs/stretch/', '.deb') 72 | get_all_bins('target/files/stretch/', '.ko') 73 | get_all_bins('target/python-debs/', '.deb') 74 | get_all_bins('target/python-wheels/', '.whl') 75 | get_all_bins('target/', '.gz') 76 | 77 | 78 | 79 | ##### Incremental builds 80 | Just clean up the deb's/gz that require re-build, and build again. Here is an exmple: 81 | 82 | ##### To build deb file for sonic-mgmt-framework 83 | 84 | BLDENV=stretch make target/debs/stretch/sonic-mgmt-framework_1.0-01_amd64.deb-clean 85 | BLDENV=stretch make target/debs/stretch/sonic-mgmt-framework_1.0-01_amd64.deb 86 | 87 | ##### To build sonic-mgmt-framework docker alone 88 | 89 | BLDENV=stretch make target/docker-sonic-mgmt-framework.gz-clean 90 | BLDENV=stretch make target/docker-sonic-mgmt-framework.gz 91 | -------------------------------------------------------------------------------- /tools/test/cli.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################################################################################ 3 | # # 4 | # Copyright 2020 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 5 | # its subsidiaries. # 6 | # # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); # 8 | # you may not use this file except in compliance with the License. # 9 | # You may obtain a copy of the License at # 10 | # # 11 | # http://www.apache.org/licenses/LICENSE-2.0 # 12 | # # 13 | # Unless required by applicable law or agreed to in writing, software # 14 | # distributed under the License is distributed on an "AS IS" BASIS, # 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 16 | # See the License for the specific language governing permissions and # 17 | # limitations under the License. # 18 | # # 19 | ################################################################################ 20 | 21 | set -e 22 | 23 | ARGS=() 24 | HOST=localhost 25 | PORT=443 26 | 27 | while [[ $# -gt 0 ]]; do 28 | case "$1" in 29 | -host) HOST=$2; shift 2 ;; 30 | -port) PORT=$2; shift 2 ;; 31 | -auth) AUTH=1; shift ;; 32 | *) ARGS+=("$1"); shift ;; 33 | esac 34 | done 35 | 36 | TOPDIR=$PWD 37 | BUILDDIR=$TOPDIR/build 38 | 39 | CLISOURCE=$TOPDIR/CLI 40 | CLIBUILD=$BUILDDIR/cli 41 | 42 | [ -z $AUTH ] && export CLISH_NOAUTH=1 43 | 44 | [ -z $SYSTEM_NAME ] && export SYSTEM_NAME=sonic-cli 45 | 46 | export REST_API_ROOT=https://$HOST:$PORT 47 | 48 | export SONIC_CLI_ROOT=$CLISOURCE/actioner 49 | 50 | export RENDERER_TEMPLATE_PATH=$CLISOURCE/renderer/templates 51 | 52 | export SHOW_CONFIG_TOOLS=$CLIBUILD/render-templates 53 | 54 | #export CLISH_PATH=$CLISOURCE/clitree/cli-xml 55 | export CLISH_PATH=$CLIBUILD/command-tree 56 | 57 | # KLISH_BIN can be set to use klish exe and libs from other directory. 58 | if [[ -z ${KLISH_BIN} ]]; then 59 | if [[ -f ${CLIBUILD}/clish ]]; then 60 | KLISH_BIN=${CLIBUILD} 61 | elif [[ -f ${BUILDDIR}/target/clish ]]; then 62 | KLISH_BIN=${BUILDDIR}/target 63 | else 64 | echo "Error: could not locate clish." 65 | exit 1 66 | fi 67 | fi 68 | 69 | PYTHONPATH+=:$CLISOURCE/actioner 70 | PYTHONPATH+=:$CLISOURCE/renderer 71 | PYTHONPATH+=:$CLISOURCE/renderer/scripts 72 | PYTHONPATH+=:$(realpath $TOPDIR/..)/sonic-py-swsssdk/src 73 | export PYTHONPATH 74 | 75 | # KLISH_BIN can be set to use klish exe and libs from other directory 76 | if [[ -z ${KLISH_BIN} ]]; then 77 | if [[ -f ${CLIBUILD}/clish ]]; then 78 | KLISH_BIN=${CLIBUILD} 79 | elif [[ -f ${BUILDDIR}/target/clish ]]; then 80 | KLISH_BIN=${BUILDDIR}/target 81 | else 82 | echo "Error: could not locate clish." 83 | exit 1 84 | fi 85 | fi 86 | 87 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$KLISH_BIN/.libs 88 | 89 | DBCLI="$(type -t sonic-db-cli > /dev/null && echo sonic-db-cli CONFIG_DB || echo redis-cli -n 4)" 90 | 91 | export SONIC_CLI_IFACE_MODE=$(${DBCLI} hget "DEVICE_METADATA|localhost" intf_naming_mode) 92 | [[ -z ${DEBUG} ]] || echo "SONIC_CLI_IFACE_MODE = '${SONIC_CLI_IFACE_MODE}'" 93 | 94 | (cd ${BUILDDIR} && ${KLISH_BIN}/clish "${ARGS[@]}") 95 | 96 | -------------------------------------------------------------------------------- /rest/server/req_validate.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or // 4 | // its subsidiaries. // 5 | // // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); // 7 | // you may not use this file except in compliance with the License. // 8 | // You may obtain a copy of the License at // 9 | // // 10 | // http://www.apache.org/licenses/LICENSE-2.0 // 11 | // // 12 | // Unless required by applicable law or agreed to in writing, software // 13 | // distributed under the License is distributed on an "AS IS" BASIS, // 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 15 | // See the License for the specific language governing permissions and // 16 | // limitations under the License. // 17 | // // 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | package server 21 | 22 | import ( 23 | "encoding/json" 24 | "reflect" 25 | 26 | "github.com/golang/glog" 27 | "gopkg.in/go-playground/validator.v9" 28 | ) 29 | 30 | func isSkipValidation(t reflect.Type) bool { 31 | if t == reflect.TypeOf([]int32{}) { 32 | return true 33 | } 34 | 35 | return false 36 | } 37 | 38 | // RequestValidate performas payload validation of request body. 39 | func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error) { 40 | if ctype.isJSON() { 41 | return validateRequestJSON(payload, rc) 42 | } 43 | 44 | glog.Infof("[%s] Skipping payload validation for content-type '%v'", rc.ID, ctype.Type) 45 | return payload, nil 46 | } 47 | 48 | // validateRequestJSON performs payload validation for JSON data 49 | func validateRequestJSON(jsn []byte, rc *RequestContext) ([]byte, error) { 50 | var err error 51 | v := rc.Model 52 | glog.Infof("[%s] Unmarshalling %d bytes into %T", rc.ID, len(jsn), v) 53 | 54 | err = json.Unmarshal(jsn, v) 55 | if err != nil { 56 | glog.Warningf("[%s] json decoding error; %v", rc.ID, err) 57 | return nil, httpBadRequest("Invalid json") 58 | } 59 | 60 | //log.Printf("Received data: %s\n", jsn) 61 | //log.Printf("Type is: %T, Value is:%v\n", v, v) 62 | val := reflect.ValueOf(v) 63 | if val.Kind() == reflect.Ptr && !val.IsNil() { 64 | val = val.Elem() 65 | } 66 | 67 | if !isSkipValidation(val.Type()) { 68 | glog.Infof("[%s] Going to validate request", rc.ID) 69 | validate := validator.New() 70 | if val.Kind() == reflect.Slice { 71 | //log.Println("Validate using Var") 72 | err = validate.Var(v, "dive") 73 | } else { 74 | //log.Println("Validate using Struct") 75 | err = validate.Struct(v) 76 | } 77 | if err != nil { 78 | glog.Warningf("[%s] validation failed: %v", rc.ID, err) 79 | return nil, httpBadRequest("Content not as per schema") 80 | } 81 | } else { 82 | glog.Infof("[%s] Skipping payload validation for dataType %v", rc.ID, val.Type()) 83 | } 84 | 85 | // Get sanitized json by marshalling validated body. Removes 86 | // extra fields if any.. 87 | newBody, err := json.Marshal(v) 88 | if err != nil { 89 | glog.Warningf("[%s] Failed to marshall; %v", rc.ID, err) 90 | return nil, httpServerError("Internal error") 91 | } 92 | 93 | return newBody, nil 94 | } 95 | -------------------------------------------------------------------------------- /rest/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # # 3 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 4 | # its subsidiaries. # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ################################################################################ 19 | 20 | TOPDIR := .. 21 | BUILD_DIR ?= $(TOPDIR)/build 22 | 23 | GO ?= go 24 | GOROOT ?= $(shell $(GO) env GOROOT) 25 | 26 | REST_BUILD_DIR := $(BUILD_DIR)/rest_server 27 | REST_BIN := $(REST_BUILD_DIR)/rest_server 28 | REST_TEST_BIN := $(BUILD_DIR)/tests/rest/server.test 29 | FORMAT_CHECK := $(REST_BUILD_DIR)/.formatcheck 30 | FORMAT_LOG := $(REST_BUILD_DIR)/go_format.log 31 | 32 | REST_GO_SRCS = $(shell find . -name '*.go' -not -name '*_test.go') 33 | REST_TEST_SRCS = $(shell find . -name '*_test.go') 34 | 35 | # Source files affecting REST server 36 | REST_SRCS := $(REST_GO_SRCS) 37 | REST_SRCS += $(shell find $(REST_BUILD_DIR)/dist -name '*.go') 38 | REST_SRCS += $(shell find $(TOPDIR)/vendor/github.com/Azure/sonic-mgmt-common -name '*.go') 39 | REST_SRCS += $(shell find $(TOPDIR)/models/openapi -name '*.yaml') 40 | 41 | # Certificate generator tool for generating temp certificates. 42 | # Compiled from standard crypto/tls/generate_cert.go 43 | CERTGEN_BIN := $(REST_BUILD_DIR)/generate_cert 44 | 45 | 46 | DEFAULT_TARGETS = $(REST_BIN) $(CERTGEN_BIN) $(FORMAT_CHECK) 47 | ifeq ($(NO_TEST_BINS),) 48 | DEFAULT_TARGETS += $(REST_TEST_BIN) 49 | endif 50 | 51 | all: $(DEFAULT_TARGETS) 52 | 53 | $(REST_BUILD_DIR)/: 54 | mkdir -p $@ 55 | 56 | # REST Server binary 57 | # Invokes yang and model make to generate swagger artifcats. 58 | $(REST_BIN): $(REST_SRCS) | $(REST_BUILD_DIR)/ 59 | ifeq ($(SONIC_COVERAGE_ON),y) 60 | $(GO) test -mod=vendor -coverpkg="./..." -c -o $@ ../rest/main/main.go ../rest/main/main_test.go 61 | else 62 | $(GO) build -mod=vendor -gcflags="all=-N -l" -v -o $@ ../rest/main/main.go 63 | endif 64 | 65 | # Gotest binary for REST Server 66 | $(REST_TEST_BIN): $(REST_TEST_SRCS) $(REST_SRCS) | $(REST_BUILD_DIR)/ 67 | $(GO) test -mod=vendor -tags test -cover -c ../rest/server -o $@ 68 | 69 | # Compile certificate generator from standard crypto/tls/generate_cert.go. 70 | # Source file will be available in GOROOT/src. 71 | $(CERTGEN_BIN): | $(REST_BUILD_DIR)/ 72 | $(GO) build -o $@ $(GOROOT)/src/crypto/tls/generate_cert.go 73 | 74 | .SECONDEXPANSION: 75 | 76 | $(FORMAT_CHECK): $(REST_GO_SRCS) $(REST_TEST_SRCS) | $$(@D)/. 77 | @echo "Checking Go file formatting..." 78 | @$(GOROOT)/bin/gofmt -l -d $? > $(FORMAT_LOG) 79 | @if [ -s $(FORMAT_LOG) ]; then \ 80 | cat $(FORMAT_LOG); \ 81 | echo "Formatting issues found. Please run 'gofmt -w .' on the above files and commit the changes."; \ 82 | exit 1; \ 83 | else \ 84 | echo "All files are properly formatted."; \ 85 | rm -f $(FORMAT_LOG); \ 86 | fi 87 | touch $@ 88 | 89 | clean: 90 | $(RM) $(REST_BIN) $(CERTGEN_BIN) 91 | $(RM) $(REST_TEST_BIN) 92 | 93 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | branches: 8 | include: 9 | - master 10 | - 202??? 11 | 12 | pr: 13 | branches: 14 | include: 15 | - master 16 | - 202??? 17 | 18 | variables: 19 | - name: BUILD_BRANCH 20 | ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: 21 | value: $(System.PullRequest.TargetBranch) 22 | ${{ else }}: 23 | value: $(Build.SourceBranchName) 24 | 25 | resources: 26 | repositories: 27 | - repository: sonic-mgmt-common 28 | type: github 29 | name: sonic-net/sonic-mgmt-common 30 | endpoint: sonic-net 31 | ref: refs/heads/$(BUILD_BRANCH) 32 | 33 | stages: 34 | - stage: Build 35 | jobs: 36 | - job: 37 | displayName: "build" 38 | timeoutInMinutes: 60 39 | 40 | pool: 41 | vmImage: ubuntu-latest 42 | 43 | container: 44 | image: sonicdev-microsoft.azurecr.io:443/sonic-slave-bookworm:latest 45 | 46 | steps: 47 | - checkout: self 48 | clean: true 49 | submodules: recursive 50 | displayName: 'Checkout code' 51 | 52 | - checkout: sonic-mgmt-common 53 | clean: true 54 | submodules: recursive 55 | displayName: 'Checkout sonic-mgmt-common' 56 | 57 | - task: DownloadPipelineArtifact@2 58 | inputs: 59 | source: specific 60 | project: build 61 | pipeline: Azure.sonic-buildimage.official.vs 62 | artifact: sonic-buildimage.vs 63 | runVersion: 'latestFromBranch' 64 | runBranch: 'refs/heads/$(BUILD_BRANCH)' 65 | patterns: | 66 | target/debs/bookworm/libyang*.deb 67 | target/python-wheels/bookworm/sonic_yang_models*.whl 68 | displayName: "Download sonic buildimage" 69 | 70 | - script: | 71 | # REDIS 72 | sudo apt-get update 73 | sudo apt-get install -y redis-server 74 | sudo sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf 75 | sudo sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf 76 | sudo sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf 77 | sudo service redis-server start 78 | 79 | # LIBYANG 80 | sudo dpkg -i ../target/debs/bookworm/libyang*1.0.73*.deb 81 | 82 | # Install from "requirement" files in sonic-mgmt-framework/tools/test directory. 83 | pushd sonic-mgmt-framework/tools/test 84 | 85 | [[ ! -f apt_requirements.txt ]] || \ 86 | sed 's/#.*//' apt_requirements.txt | xargs -r sudo apt-get install -y 87 | 88 | [[ ! -f python2_requirements.txt ]] || \ 89 | sudo pip install --no-cache-dir -r python2_requirements.txt 90 | 91 | [[ ! -f python3_requirements.txt ]] || \ 92 | sudo pip3 install --no-cache-dir -r python3_requirements.txt 93 | 94 | displayName: "Install dependency" 95 | 96 | - script: | 97 | sudo pip3 install ../target/python-wheels/bookworm/sonic_yang_models-1.0-py3-none-any.whl 98 | displayName: "Install sonic yangs" 99 | 100 | - script: | 101 | set -ex 102 | pushd sonic-mgmt-common 103 | 104 | NO_TEST_BINS=1 dpkg-buildpackage -rfakeroot -b -us -uc -j$(nproc) 105 | displayName: "Build sonic-mgmt-common" 106 | 107 | - script: | 108 | set -ex 109 | pushd sonic-mgmt-framework 110 | 111 | dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) && cp ../*.deb $(Build.ArtifactStagingDirectory)/ 112 | displayName: "Build" 113 | 114 | - publish: $(Build.ArtifactStagingDirectory)/ 115 | artifact: sonic-mgmt-framework 116 | displayName: "Archive artifacts" 117 | 118 | - script: | 119 | # Run REST Server gotests 120 | pushd sonic-mgmt-framework 121 | tools/test/rest-gotest.sh -bin 122 | displayName: "REST Server Sanity Test" 123 | 124 | - script: | 125 | # KLISH sanity 126 | pushd sonic-mgmt-framework 127 | tools/test/cli.sh -c 'exit' 128 | displayName: "KLISH Sanity Test" 129 | -------------------------------------------------------------------------------- /CLI/actioner/sonic-cli-sys.py: -------------------------------------------------------------------------------- 1 | #:!/usr/bin/python3 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | import sys 21 | from cli_client import ApiClient 22 | from rpipe_utils import pipestr 23 | from scripts.render_cli import show_cli_output 24 | 25 | 26 | def util_capitalize(value): 27 | for key, val in list(value.items()): 28 | temp = key.replace('-', '_').split('_') 29 | alt_key = '' 30 | for i in temp: 31 | alt_key = alt_key + i.capitalize() + ' ' 32 | value[alt_key] = value.pop(key) 33 | return value 34 | 35 | 36 | def system_state_key_change(value): 37 | value.pop('motd-banner', None) 38 | value.pop('login-banner', None) 39 | return util_capitalize(value) 40 | 41 | 42 | def memory_key_change(value): 43 | value['Total'] = value.pop('physical', 'Unknown') 44 | value['Used'] = value.pop('reserved', 'Unknown') 45 | return value 46 | 47 | 48 | class Handlers: 49 | @staticmethod 50 | def get_openconfig_system_system_state(template, *args): 51 | resp = ApiClient().get("/restconf/data/openconfig-system:system/state") 52 | if not resp.ok(): 53 | print(resp.error_message()) 54 | return 1 55 | if resp.content: 56 | data = resp.content.get("openconfig-system:state", {}) 57 | show_cli_output(template, system_state_key_change(data)) 58 | return 0 59 | 60 | @staticmethod 61 | def get_openconfig_system_system_memory(template, *args): 62 | resp = ApiClient().get("/restconf/data/openconfig-system:system/memory/state") 63 | if not resp.ok(): 64 | print(resp.error_message()) 65 | return 1 66 | if resp.content: 67 | data = resp.content.get("openconfig-system:state", {}) 68 | show_cli_output(template, memory_key_change(data)) 69 | return 0 70 | 71 | @staticmethod 72 | def get_openconfig_system_system_cpus(template, *args): 73 | resp = ApiClient().get("/restconf/data/openconfig-system:system/cpus/cpu") 74 | if not resp.ok(): 75 | print(resp.error_message()) 76 | return 1 77 | if resp.content: 78 | data = resp.content.get("openconfig-system:cpu", []) 79 | show_cli_output(template, data) 80 | return 0 81 | 82 | @staticmethod 83 | def get_openconfig_system_system_processes(template, pid, *args): 84 | resp = ApiClient().get("/restconf/data/openconfig-system:system/processes/process") 85 | if not resp.ok(): 86 | print(resp.error_message()) 87 | return 1 88 | data = resp.content.get("openconfig-system:process", []) if resp.content else [] 89 | # Show all process info if pid is not given 90 | if not pid.isnumeric(): 91 | show_cli_output(template, data) 92 | return 0 93 | # Lookup specific process by pid and display its state. 94 | # Not passing pid in the GET url since server is not handling 'not found' case properly 95 | for proc in data: 96 | if proc["pid"] == pid: 97 | proc_state = proc.get("state", {}) 98 | show_cli_output(template, util_capitalize(proc_state)) 99 | break 100 | return 0 101 | 102 | 103 | def run(func, args): 104 | return getattr(Handlers, func)(*args) 105 | 106 | 107 | if __name__ == '__main__': 108 | pipestr().write(sys.argv) 109 | func = sys.argv[1] 110 | run(func, sys.argv[2:]) 111 | -------------------------------------------------------------------------------- /CLI/klish/patches/klish-2.1.4/clish/shell/shell_help.c.diff: -------------------------------------------------------------------------------- 1 | 6a7 2 | > //#include "clish/plugin/clish_api.h" 3 | 17c18,19 4 | < clish_help_t *help, const char *line, size_t *max_width) 5 | --- 6 | > clish_help_t *help, const char *line, size_t *max_width, 7 | > clish_context_t *context) 8 | 20a23 9 | > clish_context_t local_context; 10 | 25a29 11 | > clish_context_init(&local_context, this); 12 | 26a31,38 13 | > clish_context__set_cmd(&local_context, cmd); 14 | > if(clish_shell_command_test(cmd, &local_context) == BOOL_FALSE) 15 | > continue; 16 | > 17 | > if (clish_command__get_hidden(cmd) == BOOL_TRUE) 18 | > continue; 19 | > if (clish_command__get_enabled(cmd) == BOOL_FALSE) 20 | > continue; 21 | 51c63 22 | < clish_pargv_status_e status = CLISH_LINE_OK; 23 | --- 24 | > clish_pargv_status_t status = CLISH_LINE_OK; 25 | 74c86 26 | < argv, &idx, completion, index); 27 | --- 28 | > argv, &idx, completion, index, NULL, NULL); 29 | 80a93 30 | > const clish_parg_t *parg; 31 | 84a98,104 32 | > if (clish_param__get_hidden(param) == BOOL_TRUE) 33 | > continue; 34 | > 35 | > if (clish_param__get_enabled(param) == BOOL_FALSE) 36 | > continue; 37 | > 38 | > parg = clish_pargv__get_parg(completion, i); 39 | 93c113 40 | < clish_param_help(param, help); 41 | --- 42 | > clish_param_help(param, help, clish_parg__get_value((parg))); 43 | 107c127,160 44 | < void clish_shell_help(clish_shell_t *this, const char *line) 45 | --- 46 | > void sort_help_command (const lub_argv_t *name , const lub_argv_t *help, int complete_status) { 47 | > int count = 0; 48 | > int indexi,indexj; 49 | > char * temp = NULL; 50 | > const char *str1 = NULL; 51 | > const char *str2 = NULL; 52 | > 53 | > count = lub_argv__get_count(name); 54 | > /* if the last element is , then don't sort that the last element */ 55 | > if (!complete_status) { 56 | > count = count - 1; 57 | > } 58 | > 59 | > for (indexi=0;indexi for (indexj=indexi+1;indexj str1 = lub_argv__get_arg(name, indexi); 62 | > str2 = lub_argv__get_arg(name, indexj); 63 | > 64 | > if ((str1 == NULL) || (str2 == NULL)) 65 | > continue; 66 | > /* check two strings. if compared string is lowest letter, then swap */ 67 | > if(lub_string_nocasecmp(str1,str2) > 0) { 68 | > /*swap the name to sort */ 69 | > lub_argv__swap_arg(name,indexi,indexj); 70 | > /*swap the corresponding help string of command */ 71 | > lub_argv__swap_arg(help,indexi,indexj); 72 | > } 73 | > } 74 | > } 75 | > 76 | > } 77 | > 78 | > /*--------------------------------------------------------- */ 79 | > void clish_shell_help(clish_shell_t *this, const char *line, clish_context_t *context) 80 | 112a166 81 | > int complete_status = 0; 82 | 119c173 83 | < available_commands(this, &help, line, &max_width); 84 | --- 85 | > available_commands(this, &help, line, &max_width, context); 86 | 122c176 87 | < cmd = clish_shell_resolve_command(this, line); 88 | --- 89 | > cmd = clish_shell_resolve_command(this, line, context); 90 | 126,127c180 91 | < int status; 92 | < status = available_params(this, &help, cmd, line, &width); 93 | --- 94 | > complete_status = available_params(this, &help, cmd, line, &width); 95 | 131c184 96 | < if (!status) { 97 | --- 98 | > if (!complete_status) { 99 | 138a192,196 100 | > 101 | > for (i = 0; i < lub_argv__get_count(help.name); i++) { 102 | > if(max_width < strlen(lub_argv__get_arg(help.name, i))) 103 | > max_width = strlen(lub_argv__get_arg(help.name, i)); 104 | > } 105 | 139a198,199 106 | > /* Sort the help command name and is help strings */ 107 | > sort_help_command(help.name, help.help, complete_status); 108 | 142c202,204 109 | < fprintf(stderr, " %-*s %s\n", (int)max_width, 110 | --- 111 | > if(max_width < strlen(lub_argv__get_arg(help.name, i))) 112 | > max_width = strlen(lub_argv__get_arg(help.name, i)); 113 | > fprintf(stderr, " %-*s %-s\n", (int)max_width, 114 | -------------------------------------------------------------------------------- /CLI/clitree/scripts/klish_platform_features_process.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################################################### 3 | # 4 | # Copyright 2019 Dell, Inc. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ########################################################################### 19 | 20 | #set -x 21 | # Validate all platform xml files 22 | # For all platform_*.xml, run xmllint feature_master.xsd $i.xml 23 | # Create entities_platform.xml and features_platform.xml 24 | # For all platforms_*/xml, run xsltproc $i.xml with entities.xml and features.xsl 25 | # Copy a clish_prepare.py to sysroot 26 | # Run clish_prepare.py with first platform and update entities 27 | # 28 | # Run xsltproc on feature_master.xsd to create an xml file of all features - fullfeatures.xml 29 | # 30 | # During clish start: 31 | # a. Open fullfeatures.xml to populate a list of features vs enabled-flag mappping. 32 | # b. While preparing the pfeature list, consult this list instead of consulting the list of #defines 33 | # c. Report errors on processing the fullfeatures.xml file 34 | 35 | PLATFORM_CONFIGS=platform_dummy.xml 36 | BUILD_DIR=$2/tmp 37 | PARSER_XML_PATH=$2 38 | ENTITIES_TEMPLATE=$1/mgmt_clish_entities.xsl 39 | FEATURES_MASTER=$1/mgmt_clish_feature_master.xsd 40 | 41 | function insert_in() 42 | { 43 | # Insert in file - $1 with $value set in calling routine 44 | filename=$1 45 | outfile=$filename.bak 46 | grep -q DOCTYPE $filename 47 | # If there are ENTITY definitions, add it as part of it 48 | # Else add a new DOCTYPE 49 | if [ $? -eq 0 ]; then 50 | option=1 51 | matchpattern=".*DOCTYPE.*" 52 | printvalue="${value}" 53 | else 54 | option=2 55 | matchpattern="" 58 | fi 59 | #echo Insert_in $filename. Option $option 60 | while IFS= read -r line; do 61 | echo "${line}" >> $outfile 62 | if [[ "${line}" =~ ${matchpattern} ]]; then 63 | #echo Match found for ${line} 64 | echo "${printvalue}" >> $outfile 65 | #set +x 66 | fi 67 | done < $filename 68 | #set -x 69 | touch $outfile $filename 70 | mv -f $outfile $filename 71 | } 72 | 73 | # Do a simple text based insertion of the feature-val entities 74 | # TBD - Replace them with an xml parser based insertion in future, if required 75 | function insert_entities() 76 | { 77 | value=`cat $1` 78 | parser=$2 79 | echo insert_entities: $1 $parser 80 | list=`echo ${parser}/*.xml` 81 | for i in ${list}; do 82 | echo Processing $i 83 | insert_in $i 84 | xmllint $i > /dev/null 85 | if [ $? -ne 0 ]; then 86 | echo ENTITY insertion in $i failed 87 | exit 1 88 | fi 89 | done 90 | #echo $i 91 | #insert_in $i 92 | } 93 | 94 | 95 | echo Sanity check of platform config files with feature master ... 96 | xmllint --schema $FEATURES_MASTER $PLATFORM_CONFIGS >& /dev/null 97 | if [ $? -ne 0 ]; then 98 | echo Failed to validate $PLATFORM_CONFIGS 99 | exit 1 100 | fi 101 | 102 | mkdir -p ${BUILD_DIR} 103 | echo Done. Generating platform specific files ... 104 | base=${PLATFORM_CONFIGS%*.xml} # Strip of the .xml suffix 105 | platform=${base#platform_*} # Get the platform name 106 | xsltproc $ENTITIES_TEMPLATE $PLATFORM_CONFIGS > $BUILD_DIR/${platform}_entities.ent #2>/dev/null 107 | # echo ${platform}_entities.ent ready 108 | if [ $? -ne 0 ]; then 109 | echo Failed to apply entities xsl template for $PLATFORM_CONFIGS 110 | exit 1 111 | fi 112 | echo Done 113 | 114 | # Use the last platform's file for compilation purpose 115 | pwd=${PWD} 116 | cd ${PARSER_XML_PATH} 117 | echo Inserting platform features 118 | insert_entities ${BUILD_DIR}/${platform}_entities.ent ${PARSER_XML_PATH}/command-tree 119 | cp ${BUILD_DIR}/*.xml ${PARSER_XML_PATH}/command-tree 120 | 121 | rm -r ${BUILD_DIR} 122 | exit 0 123 | -------------------------------------------------------------------------------- /CLI/clicfg/mgmt_clish_feature_master.xsd: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | This contains the allowed feature names for any platform specific customizable feature names. If you are adding a new platform customizable feature, add a record in the enumerated list here. 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | This contains the allowed feature-value names for any platform specific customizable feature-value strings. If you are adding a new platform customizable entity, add a record in the enumerated list here. 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | This represents a feature-value entity. Do not add or delete anything here. 43 | For adding a new feature-value, use entityname_t. For adding constraints on the count of 44 | entities, use entity_list_t 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | This represents a feature-value entity. Do not add or delete anything here. 60 | For adding a new feature-value, use entityname_t. For adding constraints on the count 61 | of entities, use entity_list_t 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 79 | 80 | 81 | 82 | 83 | This is the top level module that lists the master list of all features and feature-value names. 84 | If you are adding a new feature, add a record in the featurename_t. 85 | If you are adding a new feature-value, add a record in the entityname_t 86 | 87 | 88 | 89 | 91 | 92 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /tools/test/pylint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ################################################################################ 3 | # # 4 | # Copyright 2020 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 5 | # its subsidiaries. # 6 | # # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); # 8 | # you may not use this file except in compliance with the License. # 9 | # You may obtain a copy of the License at # 10 | # # 11 | # http://www.apache.org/licenses/LICENSE-2.0 # 12 | # # 13 | # Unless required by applicable law or agreed to in writing, software # 14 | # distributed under the License is distributed on an "AS IS" BASIS, # 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 16 | # See the License for the specific language governing permissions and # 17 | # limitations under the License. # 18 | # # 19 | ################################################################################ 20 | 21 | CONFIG="--disable=all" 22 | CONFIG+=" --enable=W0612" #unused-variable (W0612) 23 | CONFIG+=" --enable=W0611" #unused-import (W0611) 24 | CONFIG+=" --enable=C1001" #old-style-class (C1001) 25 | CONFIG+=" --enable=W0102" #dangerous-default-value (W0102) 26 | CONFIG+=" --enable=R0914" #too-many-locals (R0914) 27 | CONFIG+=" --enable=R0912" #too-many-branches (R0912) 28 | CONFIG+=" --enable=R0915" #too-many-statements (R0915) 29 | CONFIG+=" --enable=R0911" #too-many-return-statements (R0911) 30 | CONFIG+=" --enable=W0621" #redefined-outer-name (W0621) 31 | CONFIG+=" --enable=W0311" #bad-indentation (W0311) 32 | CONFIG+=" --enable=W0703" #broad-except (W0703) 33 | CONFIG+=" --enable=W0312" #mixed-indentation (W0312) 34 | CONFIG+=" --enable=W1401" #anomalous-backslash-in-string (W1401): 35 | CONFIG+=" --enable=W0622" #redefined-builtin (W0622): 36 | CONFIG+=" --enable=W0511" #fixme (W0511) 37 | CONFIG+=" --enable=E0401" #import-error (E0401) 38 | CONFIG+=" --enable=E0102" #function-redefined (E0102) 39 | CONFIG+=" --enable=W0201" #attribute-defined-outside-init (W0201) 40 | CONFIG+=" --enable=W0312" #mixed-indentation (W0312) 41 | CONFIG+=" --enable=W0123" #eval-used (W0123) 42 | CONFIG+=" --enable=C0302" #too-many-lines (C0302) 43 | CONFIG+=" --enable=W0141" #W0141: Used builtin function %r 44 | CONFIG+=" --enable=E1101" #maybe-no-member 45 | CONFIG+=" --enable=E0602" #undefined-variable (E0602) 46 | CONFIG+=" --enable=E0603" #undefined-all-variable (E0603) 47 | CONFIG+=" --enable=E0601" #used-before-assignment (E0601) 48 | CONFIG+=" --enable=W0601" #global-variable-undefined (W0601) 49 | CONFIG+=" --enable=E0103" #not-in-loop (E0103) 50 | CONFIG+=" --enable=E0116" #continue-in-finally (E0116) 51 | CONFIG+=" --enable=E0102" #function-redefined (E0102) 52 | CONFIG+=" --enable=W0601" #global-variable-undefined (W0601) 53 | 54 | if [[ $# -eq 0 ]]; then 55 | echo "Please specify one or more files or directories" 56 | exit 2 57 | fi 58 | 59 | REPO=$MGMT_REPO #SET on ENV is priority 60 | if [[ $REPO == '' ]]; then 61 | REPO=`git rev-parse --show-toplevel` 62 | if [[ $? != 0 ]]; then 63 | echo "MGMT_REPO cannot be determined, please set MGMT_REPO ENV" 64 | echo "(OR) execute this script inside sonic-mgmt-repo" 65 | exit 2 66 | fi 67 | fi 68 | 69 | if [[ "$REPO" != *sonic-mgmt-framework ]]; then 70 | echo "pylint script is tailored to work with sonic-mgmt-framework repo only" 71 | exit 2 72 | fi 73 | 74 | CLISOURCE=$REPO/CLI 75 | PYTHONPATH=$CLISOURCE/actioner 76 | PYTHONPATH+=":$CLISOURCE/renderer" 77 | PYTHONPATH+=":$CLISOURCE/renderer/scripts" 78 | PYTHONPATH+=":$CLISOURCE/clitree/scripts" 79 | export PYTHONPATH 80 | 81 | PY_FILES="" 82 | for arg in $*; do 83 | file_found=0 84 | if [[ -f $arg ]]; then 85 | PY_FILES+=" $arg" 86 | file_found=1 87 | fi 88 | if [[ -d $arg ]]; then 89 | PY_FILES+=" $(find $arg -name '*.py' | grep -v __init__.py)" 90 | file_found=1 91 | fi 92 | if [[ $file_found == 0 ]]; then 93 | echo "$arg: No such file or directory" 94 | exit 2 95 | fi 96 | done 97 | 98 | LINT="python -m pylint -rn $CONFIG" 99 | LOGDIR=$REPO/build/pylint 100 | 101 | if [[ ! -d $LOGDIR ]]; then 102 | mkdir -p $LOGDIR 103 | fi 104 | 105 | LOGFILE=$LOGDIR/pylint.log 106 | 107 | if [[ -f $LOGFILE ]]; then 108 | mv $LOGFILE $LOGDIR/pylint.log.1 109 | fi 110 | 111 | $LINT $PY_FILES 2>&1 | grep -v "Using config file " | tee $LOGFILE 112 | # TODO Exit with actual code in future when strict checking is enabled 113 | exit 0 114 | 115 | -------------------------------------------------------------------------------- /models/yang_to_openapi.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # # 3 | # Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or # 4 | # its subsidiaries. # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ################################################################################ 19 | 20 | TOPDIR := .. 21 | BUILD_DIR := $(TOPDIR)/build 22 | 23 | MGMT_COMMON_DIR ?= $(TOPDIR)/../sonic-mgmt-common 24 | YANGAPI_DIR := $(BUILD_DIR)/yaml 25 | MD_DIR := $(TOPDIR)/build/restconf_md 26 | SERVER_DIST_DIR := $(BUILD_DIR)/rest_server/dist/openapi 27 | YANGDIR := $(or $(wildcard $(MGMT_COMMON_DIR)/build/yang), $(MGMT_COMMON_DIR)/models/yang) 28 | YANGDIR_COMMON := $(YANGDIR)/common 29 | YANGDIR_EXTENSIONS := $(YANGDIR)/extensions 30 | YANG_MOD_FILES := $(wildcard $(YANGDIR)/*.yang) 31 | YANG_MOD_FILES += $(wildcard $(YANGDIR_EXTENSIONS)/*.yang) 32 | YANG_COMMON_FILES := $(wildcard $(YANGDIR_COMMON)/*.yang) 33 | 34 | YANGDIR_SONIC := $(YANGDIR)/sonic 35 | YANGDIR_SONIC_COMMON := $(YANGDIR_SONIC)/common 36 | SONIC_YANG_MOD_FILES := $(wildcard $(YANGDIR_SONIC)/*.yang) 37 | SONIC_YANG_COMMON_FILES := $(wildcard $(YANGDIR_SONIC_COMMON)/*.yang) 38 | 39 | TOOLS_DIR := $(TOPDIR)/tools 40 | PYANG_PLUGIN_DIR := $(TOOLS_DIR)/pyang/pyang_plugins 41 | PYANG ?= pyang 42 | 43 | OPENAPI_GEN_PRE := $(YANGAPI_DIR)/. $(MD_DIR)/. $(YANGAPI_DIR)/.openapi_gen_ut 44 | 45 | all: $(YANGAPI_DIR)/.openapi_gen_ut $(YANGAPI_DIR)/.done $(YANGAPI_DIR)/.sonic_done 46 | 47 | .PRECIOUS: %/. 48 | %/.: 49 | mkdir -p $@ 50 | 51 | #====================================================================== 52 | # Unit tests for OpenAPI generator 53 | #====================================================================== 54 | $(YANGAPI_DIR)/.openapi_gen_ut: $(PYANG_PLUGIN_DIR)/openapi.py | $(YANGAPI_DIR)/. 55 | $(MAKE) -C $(TOOLS_DIR)/openapi_tests 56 | touch $@ 57 | 58 | #====================================================================== 59 | # Generate YAML files for Yang modules 60 | #====================================================================== 61 | $(YANGAPI_DIR)/.done: $(YANG_MOD_FILES) $(YANG_COMMON_FILES) | $(OPENAPI_GEN_PRE) 62 | @echo "+++++ Generating YAML files for Yang modules +++++" 63 | $(PYANG) \ 64 | -f swaggerapi \ 65 | --outdir $(YANGAPI_DIR) \ 66 | --plugindir $(PYANG_PLUGIN_DIR) \ 67 | --with-md-doc \ 68 | --md-outdir $(MD_DIR) \ 69 | --with-serverstub \ 70 | --stub-outdir $(SERVER_DIST_DIR) \ 71 | -p $(YANGDIR_COMMON):$(YANGDIR):$(YANGDIR_EXTENSIONS) \ 72 | $(YANG_MOD_FILES) 73 | @echo "+++++ Generation of YAML files for Yang modules completed +++++" 74 | touch $@ 75 | 76 | #====================================================================== 77 | # Generate YAML files for SONiC YANG modules 78 | #====================================================================== 79 | $(YANGAPI_DIR)/.sonic_done: $(SONIC_YANG_MOD_FILES) $(SONIC_YANG_COMMON_FILES) | $(OPENAPI_GEN_PRE) 80 | @echo "+++++ Generating YAML files for Sonic Yang modules +++++" 81 | $(PYANG) \ 82 | -f swaggerapi \ 83 | --with-md-doc \ 84 | --outdir $(YANGAPI_DIR) \ 85 | --md-outdir $(MD_DIR) \ 86 | --plugindir $(PYANG_PLUGIN_DIR) \ 87 | --with-serverstub \ 88 | --stub-outdir $(SERVER_DIST_DIR) \ 89 | -p $(YANGDIR_COMMON):$(YANGDIR_SONIC_COMMON):$(YANGDIR_SONIC) \ 90 | $(SONIC_YANG_MOD_FILES) 91 | @echo "+++++ Generation of YAML files for Sonic Yang modules completed +++++" 92 | touch $@ 93 | 94 | #====================================================================== 95 | # Cleanups 96 | #====================================================================== 97 | 98 | clean: 99 | $(RM) -r $(YANGAPI_DIR) 100 | $(RM) -r $(MD_DIR) 101 | 102 | cleanall: clean 103 | 104 | --------------------------------------------------------------------------------