├── .artifactignore ├── .gitignore ├── LICENSE ├── Makefile ├── azure-pipelines.yml ├── config └── transformer │ └── models_list ├── cvl ├── Makefile ├── README.md ├── common │ ├── cvl_types.go │ ├── db_access.go │ └── db_utils.go ├── conf │ └── cvl_cfg.json ├── custom_validation │ ├── common.go │ └── test_validations.go ├── cvl.go ├── cvl_api.go ├── cvl_cache.go ├── cvl_cust_validation_test.go ├── cvl_error_test.go ├── cvl_hint.go ├── cvl_hint_test.go ├── cvl_leaflist_test.go ├── cvl_leafref_test.go ├── cvl_luascript.go ├── cvl_must_test.go ├── cvl_optimisation_test.go ├── cvl_semantics.go ├── cvl_syntax.go ├── cvl_test.go ├── cvl_when_test.go ├── internal │ ├── util │ │ ├── luascript_util.go │ │ └── util.go │ └── yparser │ │ ├── ly_path.go │ │ └── yparser.go ├── jsondata_test.go ├── testdata │ ├── acl_rule.json │ ├── aclrule.json │ ├── acltable.json │ ├── config_db.json │ ├── config_db1.json │ ├── config_db2.json │ ├── create_acl_table.json │ ├── create_acl_table12.json │ ├── create_acl_table13.json │ ├── port_table.json │ └── schema │ │ ├── Makefile │ │ ├── sonic-acl.yang │ │ ├── sonic-bgp-global.yang │ │ ├── sonic-buffer-pg.yang │ │ ├── sonic-buffer-pool.yang │ │ ├── sonic-buffer-profile.yang │ │ ├── sonic-cablelength.yang │ │ ├── sonic-device-metadata.yang │ │ ├── sonic-device-neighbor.yang │ │ ├── sonic-dscp-tc-map.yang │ │ ├── sonic-ifa.yang │ │ ├── sonic-igmp-snooping.yang │ │ ├── sonic-interface.yang │ │ ├── sonic-leaflist-test.yang │ │ ├── sonic-loopback-interface.yang │ │ ├── sonic-mgmt_port.yang │ │ ├── sonic-mgmt_vrf.yang │ │ ├── sonic-mirror-session.yang │ │ ├── sonic-ospfv2.yang │ │ ├── sonic-pf-limits.yang │ │ ├── sonic-pfc-priority-queue-map.yang │ │ ├── sonic-pki.yang │ │ ├── sonic-port-qos-map.yang │ │ ├── sonic-port.yang │ │ ├── sonic-portchannel-interface.yang │ │ ├── sonic-portchannel.yang │ │ ├── sonic-queue.yang │ │ ├── sonic-scheduler.yang │ │ ├── sonic-security-global.yang │ │ ├── sonic-sflow.yang │ │ ├── sonic-spanning-tree.yang │ │ ├── sonic-static-route.yang │ │ ├── sonic-tam.yang │ │ ├── sonic-tc-priority-group-map.yang │ │ ├── sonic-tc-queue-map.yang │ │ ├── sonic-telemetry.yang │ │ ├── sonic-telemetry_client.yang │ │ ├── sonic-test-xfmr.yang │ │ ├── sonic-types.yang │ │ ├── sonic-vlan-deviation.yang │ │ ├── sonic-vlan-interface.yang │ │ ├── sonic-vlan-subinterface.yang │ │ ├── sonic-vlan.yang │ │ ├── sonic-vrf.yang │ │ ├── sonic-vxlan.yang │ │ └── sonic-wred-profile.yang ├── tests │ ├── Makefile │ ├── acl_rule.json │ ├── cfg_validator.go │ ├── config_db.json │ ├── config_db1.json │ ├── config_db2.json │ ├── create_acl_table.json │ ├── cv_acl.go │ ├── cv_edit_op.go │ ├── cv_vlan.go │ └── run_test.sh └── tools │ └── generate_yin.py ├── debian ├── .gitignore ├── changelog ├── compat ├── control ├── rules ├── sonic-mgmt-common-codegen.install ├── sonic-mgmt-common-codegen.postinst └── sonic-mgmt-common.install ├── go.mod ├── go.sum ├── models └── yang │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── annotations │ ├── openconfig-acl-annot.yang │ ├── openconfig-interfaces-annot.yang │ ├── openconfig-mclag-annot.yang │ ├── openconfig-sampling-sflow-annot.yang │ ├── sonic-extensions.yang │ └── sonic-showtech-annot.yang │ ├── common │ ├── iana-if-type.yang │ ├── ietf-inet-types.yang │ ├── ietf-interfaces.yang │ ├── ietf-yang-types.yang │ ├── openconfig-aaa-radius.yang │ ├── openconfig-aaa-tacacs.yang │ ├── openconfig-aaa-types.yang │ ├── openconfig-aaa.yang │ ├── openconfig-alarm-types.yang │ ├── openconfig-alarms.yang │ ├── openconfig-extensions.yang │ ├── openconfig-hashing.yang │ ├── openconfig-if-aggregate.yang │ ├── openconfig-if-ethernet-ext.yang │ ├── openconfig-if-ip-ext.yang │ ├── openconfig-if-poe.yang │ ├── openconfig-if-tunnel.yang │ ├── openconfig-if-types.yang │ ├── openconfig-inet-types.yang │ ├── openconfig-license.yang │ ├── openconfig-lldp-types.yang │ ├── openconfig-messages.yang │ ├── openconfig-packet-match-types.yang │ ├── openconfig-packet-match.yang │ ├── openconfig-platform-types.yang │ ├── openconfig-procmon.yang │ ├── openconfig-system-bootz.yang │ ├── openconfig-system-grpc.yang │ ├── openconfig-system-logging.yang │ ├── openconfig-system-management.yang │ ├── openconfig-system-terminal.yang │ ├── openconfig-system-utilization.yang │ ├── openconfig-types.yang │ ├── openconfig-vlan-types.yang │ ├── openconfig-vlan.yang │ └── openconfig-yang-types.yang │ ├── extensions │ ├── .gitkeep │ ├── openconfig-interfaces-deviation.yang │ ├── openconfig-mclag.yang │ └── openconfig-sampling-sflow-deviation.yang │ ├── ietf-yang-library.yang │ ├── lint_ignore.ietf │ ├── lint_ignore.ocstyle │ ├── openconfig-acl.yang │ ├── openconfig-if-ethernet.yang │ ├── openconfig-if-ip.yang │ ├── openconfig-interfaces.yang │ ├── openconfig-lldp.yang │ ├── openconfig-platform.yang │ ├── openconfig-sampling-sflow.yang │ ├── openconfig-system.yang │ ├── sonic │ ├── common │ │ ├── sonic-common.yang │ │ └── sonic-extension.yang │ ├── import.mk │ ├── sonic-acl.yang │ ├── sonic-interface.yang │ ├── sonic-port.yang │ └── sonic-show-techsupport.yang │ └── version.xml ├── patches ├── apply.sh ├── glog.patch ├── goyang │ └── goyang.patch ├── jsonquery.patch ├── xmlquery.patch ├── xpath.patch └── ygot │ └── ygot.patch ├── tools ├── pyang │ ├── import_yang.py │ ├── lint │ ├── pyang_plugins │ │ ├── annot_tree.py │ │ ├── doctree.py │ │ ├── sonic_linter.py │ │ ├── strict_lint.py │ │ ├── style.py │ │ └── validate_update.py │ ├── tree │ └── yangtools.py ├── test │ ├── database_config.json │ ├── dbconfig.py │ ├── dbinit.py │ ├── env.sh │ ├── format-check.sh │ ├── platform.json │ └── translib-test.sh └── xfmr │ └── annotate.sh └── translib ├── Makefile ├── acl_app.go ├── acl_app_test.go ├── api_tests_app.go ├── app_interface.go ├── app_utils.go ├── app_utils_test.go ├── authorize.go ├── common_app.go ├── cs ├── cs.go ├── cs_abort.go ├── cs_commit.go ├── cs_cphist.go ├── cs_ds.go ├── cs_exit.go ├── cs_getdb.go ├── cs_kill.go ├── cs_mesg.go ├── cs_session.go ├── cs_session_test.go ├── cs_start.go ├── cs_status.go ├── cs_test.go └── cs_tx.go ├── db ├── cvl_db_access.go ├── db.go ├── db_cache.go ├── db_config.go ├── db_cursor.go ├── db_cursor_test.go ├── db_cvl_hint.go ├── db_cvl_hint_test.go ├── db_datastore.go ├── db_debug.go ├── db_export.go ├── db_get.go ├── db_get_config.go ├── db_get_config_test.go ├── db_get_test.go ├── db_key.go ├── db_key_test.go ├── db_keys_pattern.go ├── db_keys_pattern_test.go ├── db_lock.go ├── db_lock_test.go ├── db_map.go ├── db_onchangecache.go ├── db_onchangecache_test.go ├── db_opts_to_test.go ├── db_redis_opts.go ├── db_redis_opts_test.go ├── db_redis_pipe_test.go ├── db_rpcdb.go ├── db_rpcdb_test.go ├── db_savepoint.go ├── db_savepoint_test.go ├── db_session.go ├── db_signal.go ├── db_stats.go ├── db_subscribe_sa.go ├── db_subscribe_test.go ├── db_table.go ├── db_table_pattern.go ├── db_table_pattern_test.go ├── db_test.go ├── db_value.go ├── db_value_test.go ├── map.go ├── subscribe.go └── test │ ├── arloIssue29.go │ ├── testdb.go │ ├── testmap.go │ └── testsubscribe.go ├── internal └── apis │ ├── db_diff.go │ ├── db_diff_test.go │ └── notify.go ├── lldp_app.go ├── nonyang_app.go.demo ├── ocbinds ├── emitjson.go ├── emitjson_select.go ├── emitjson_sort.go ├── emitjson_sort_test.go ├── emitjson_test.go ├── schema.go └── testdata │ ├── acl-10x10.yangjson │ ├── components.yangjson │ ├── if-phy-vlan1k.yangjson │ └── if-phy.yangjson ├── path ├── path.go ├── path_test.go ├── path_validator.go └── path_validator_test.go ├── path_utils.go ├── path_utils_test.go ├── pfm_app.go ├── pfm_app_test.go ├── request_binder.go ├── request_binder_test.go ├── subscribe.go ├── subscribe_app_interface.go ├── subscribe_app_utils.go ├── subscribe_notify.go ├── subscribe_test.go ├── subscribe_utils.go ├── sys_app.go ├── test ├── acl │ ├── 01_create_MyACL1_MyACL2.json │ ├── 02_create_MyACL3_5Rules.json │ ├── 03_create_MyACL1_5_more_rules.json │ ├── 04_create_MyACL1_1Rule_content.json │ ├── 05_Create_MyACL3_binding.json │ ├── 08_update_AclSets_MyACL3.json │ ├── 09_after_delete_1Rule_get_MyACL4_command.txt │ ├── 09_after_delete_1Rule_get_MyACL4_response.json │ ├── 09_create_MyACL4_4Rules.json │ ├── 09_create_MyACL4_4Rules_command.txt │ ├── 09_delete_1Rule_MyACL4_command.txt │ ├── 09_get_1Rule_MyACL4_command.txt │ ├── 09_get_all_MyACL4_4Rules_command.txt │ └── 09_get_all_MyACL4_4Rules_response.json ├── interfaces │ ├── 01_get_all_command.txt │ ├── 01_get_all_response.json │ ├── 02_get_interface_command.txt │ ├── 02_get_interface_response.json │ ├── 03_get_interface_config_command.txt │ ├── 03_get_interface_config_response.json │ ├── 04_get_interface_state_command.txt │ ├── 04_get_interface_state_response.json │ ├── 05_set_interface_mtu.json │ ├── 05_set_interface_mtu_command.txt │ ├── 06_set_interface_ipv4.json │ ├── 06_set_interface_ipv4_command.txt │ ├── 07_set_interface_ipv6.json │ ├── 07_set_interface_ipv6_command.txt │ ├── 08_delete_interface_ipv4_command.txt │ └── 09_delete_interface_ipv6_command.txt ├── lldp │ ├── 01-get-all-intf-command.txt │ ├── 01-get-all-intf-response.json │ ├── 02-get-one-intf-command.txt │ └── 02-get-one-intf-response.json ├── platform │ ├── 01_get_all_components.txt │ ├── 01_get_all_response.json │ ├── 02_get_one_component.txt │ ├── 02_get_one_component_response.json │ ├── 03_get_component_attribute_command.txt │ └── 03_get_component_attribute_response.json ├── system │ ├── 01_get_all_components.txt │ ├── 01_get_all_components_response.json │ ├── 02_get_system_state_command.txt │ ├── 02_get_system_state_response.json │ ├── 03_get_system_memory_command.txt │ ├── 03_get_system_memory_response.json │ ├── 04_get_system_cpus_command.txt │ ├── 04_get_system_cpus_response.json │ ├── 05_get_system_processes_command.txt │ ├── 05_get_system_processes_response.json │ ├── 06_get_system_processes_pid_command.txt │ ├── 06_get_system_processes_pid_response.json │ ├── 07_get_system_processes_pid_attribute_command.txt │ └── 07_get_system_processes_pid_attribute_response.json └── translibtest.go ├── tlerr ├── app_errors.go └── tlerr.go ├── transformer ├── host_comm.go ├── interfaces_openconfig_test.go ├── portchannel_openconfig_test.go ├── sflow_openconfig_test.go ├── sflow_sonic_test.go ├── subscribe_req_xlate.go ├── subscribe_resp_xlate.go ├── sw_portchannel.go ├── test │ ├── README.md │ ├── openconfig-test-xfmr-annot.yang │ ├── openconfig-test-xfmr.yang │ ├── sonic-test-xfmr-annot.yang │ └── sonic-test-xfmr.yang ├── testxfmryang_test.go ├── transformer.go ├── transformer.test ├── transformer_test.go ├── utils_test.go ├── xconst.go ├── xfmr_dbtbl_cbk_interface.go ├── xfmr_interface.go ├── xfmr_intf.go ├── xfmr_mclag.go ├── xfmr_path_utils.go ├── xfmr_sflow.go ├── xfmr_showtech.go ├── xfmr_testxfmr_callbacks.go ├── xlate.go ├── xlate_cascade_del.go ├── xlate_datastructs.go ├── xlate_del_to_db.go ├── xlate_from_db.go ├── xlate_prune.go ├── xlate_prune_acl_test.go ├── xlate_prune_interfaces_test.go ├── xlate_prune_ospf_test.go ├── xlate_prune_radius_test.go ├── xlate_prune_stats.go ├── xlate_prune_test.go ├── xlate_replace_utils.go ├── xlate_tbl_info.go ├── xlate_to_db.go ├── xlate_utils.go ├── xlate_xfmr_handler.go └── xspec.go ├── translib.go ├── translib_test.go ├── utils ├── bits.go └── utils.go ├── version.go ├── version_test.go ├── yanglib_app.go └── yanglib_app_test.go /.artifactignore: -------------------------------------------------------------------------------- 1 | **/* 2 | !*.deb 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.code-workspace 3 | build 4 | vendor 5 | __pycache__ 6 | *.pyc 7 | *.rdb 8 | *.swp 9 | *.yin 10 | *.tree 11 | translib/ocbinds/ocbinds.go 12 | models/yang/*.md 13 | .idea 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 := build 22 | 23 | GOPATH ?= /tmp/go 24 | GO ?= /usr/local/go/bin/go 25 | 26 | GO_MOD = go.mod 27 | GO_DEPS = vendor/.done 28 | GO_PATCHES = $(shell find patches -type f) 29 | GOYANG_BIN = $(abspath $(BUILD_DIR)/bin/goyang) 30 | 31 | export TOPDIR GO GOPATH 32 | 33 | all: models cvl translib 34 | 35 | $(GO_MOD): 36 | $(GO) mod init github.com/Azure/sonic-mgmt-common 37 | 38 | $(GO_DEPS): $(GO_MOD) $(GO_PATCHES) 39 | $(GO) mod vendor 40 | patches/apply.sh vendor 41 | touch $@ 42 | 43 | go-deps: $(GO_DEPS) 44 | 45 | go-deps-clean: 46 | $(RM) -r vendor 47 | 48 | .PHONY: cvl 49 | cvl: $(GO_DEPS) | models 50 | $(MAKE) -C ./cvl 51 | 52 | cvl-clean: 53 | $(MAKE) -C ./cvl clean 54 | 55 | cvl-test: 56 | $(MAKE) -C ./cvl gotest 57 | 58 | .PHONY: translib 59 | translib: $(GO_DEPS) | models 60 | $(MAKE) -C ./translib 61 | 62 | translib-all: $(GO_DEPS) 63 | $(MAKE) -C ./translib all 64 | 65 | translib-clean: 66 | $(MAKE) -C ./translib clean 67 | 68 | .PHONY: models 69 | models: | $(GO_DEPS) 70 | $(MAKE) -C models/yang 71 | 72 | models-clean: 73 | $(MAKE) -C models/yang clean 74 | 75 | annotgen: $(GOYANG_BIN) 76 | 77 | $(GOYANG_BIN): $(GO_DEPS) 78 | cd vendor/github.com/openconfig/goyang && \ 79 | $(GO) build -o $@ *.go 80 | 81 | clean: models-clean translib-clean cvl-clean go-deps-clean 82 | git check-ignore debian/* | xargs -r $(RM) -r 83 | $(RM) -r $(BUILD_DIR) 84 | 85 | cleanall: clean 86 | git clean -fdX tools 87 | -------------------------------------------------------------------------------- /config/transformer/models_list: -------------------------------------------------------------------------------- 1 | #List yang models transformer need to load 2 | openconfig-acl.yang 3 | openconfig-acl-annot.yang 4 | openconfig-sampling-sflow.yang 5 | openconfig-sampling-sflow-annot.yang 6 | openconfig-if-ethernet.yang 7 | openconfig-interfaces.yang 8 | openconfig-interfaces-annot.yang 9 | openconfig-if-ip.yang 10 | openconfig-if-aggregate.yang 11 | openconfig-interfaces-annot.yang 12 | openconfig-mclag.yang 13 | openconfig-mclag-annot.yang 14 | -------------------------------------------------------------------------------- /cvl/README.md: -------------------------------------------------------------------------------- 1 | 1. Install latest version of pyang tool. 2 | 3 | 2. Install libyang from https://github.com/CESNET/libyang along with its dependency. 4 | 5 | 3. Run 'make' from top level 'cvl' directory. 6 | 7 | 4. Refer to top level makefile rules for compiling individual targets. 8 | 9 | 5. 'schema' directory should contain all .yin files 10 | 11 | 6. On the target the 'schema' directory needs to be present in the same directory where application executable file is present. 12 | 13 | 14 | Debugging Info: 15 | =============== 16 | 17 | Below steps need to be done to enable CVL logging. 18 | 19 | 1. Find the CVL json config file in mgmt-framework docker in switch at "/usr/sbin/cvl_cfg.json" . 20 | 21 | 2. Change the logging flags from "false" to "true" as below: 22 | 23 | ``` 24 | { 25 | "TRACE_CACHE": "true", 26 | "TRACE_LIBYANG": "true", 27 | "TRACE_YPARSER": "true", 28 | "TRACE_CREATE": "true", 29 | "TRACE_UPDATE": "true", 30 | "TRACE_DELETE": "true", 31 | "TRACE_SEMANTIC": "true", 32 | "TRACE_SYNTAX": "true", 33 | "TRACE_ONERROR": "true", 34 | "__comment1__": "Set LOGTOSTDER to 'true' to log on standard error", 35 | "LOGTOSTDERR": "false", 36 | "__comment2__": "Log messages to standard error at or above this severity level", 37 | "STDERRTHRESHOLD": "ERROR", 38 | "__comment3__": "Log to /tmp/cvl.log file", 39 | "LOG_TO_FILE": "true", 40 | "__comment4__": "Limit log file size in bytes, 0 means no limit, default 10MB", 41 | "LOG_FILE_SIZE": "10485760", 42 | "__comment5__": "Set verbosity level(1 to 8) for verbose logs", 43 | "VERBOSITY": "0", 44 | "SKIP_VALIDATION": "false", 45 | "SKIP_SEMANTIC_VALIDATION": "false" 46 | } 47 | ``` 48 | 49 | 3. Below environment variables need to be set at the end in /usr/bin/rest-server.sh in mgmt-framework docker. 50 | 51 | export CVL_DEBUG=1 52 | export CVL_CFG_FILE=/usr/sbin/cvl_cfg.json 53 | 54 | Note : CVL_CFG_FILE enviroment variable can point to other location also. 55 | 56 | 4. CVL Traces can be enabled both with restart and without mgmt-framework docker restart . 57 | 58 | With Restart: 59 | ============ 60 | Restart mgmt-framework docker after which updated cvl_cfg.json file will be read. 61 | 62 | Without Restart: 63 | =============== 64 | Issue SIGUSR2 to rest process(kill -SIGUSR2 , to read changed cvl_cfg.json with logging enabled. 65 | 66 | 5. After following above steps, CVL traces can be seen in syslog file in host container at /var/log/syslog. 67 | 68 | 6. To disable CVL traces , disable the fields in cvl_cfg.json file and then perform same steps as in Step 4. 69 | 70 | 71 | -------------------------------------------------------------------------------- /cvl/common/cvl_types.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 common 21 | 22 | import ( 23 | "github.com/antchfx/xmlquery" 24 | ) 25 | 26 | // CVLEditConfigData Strcture for key and data in API 27 | type CVLEditConfigData struct { 28 | VType CVLValidateType //Validation type 29 | VOp CVLOperation //Operation type 30 | Key string //Key format : "PORT|Ethernet4" 31 | Data map[string]string //Value : {"alias": "40GE0/28", "mtu" : 9100, "admin_status": down} 32 | ReplaceOp bool 33 | } 34 | 35 | type CVLValidateType uint 36 | 37 | const ( 38 | VALIDATE_NONE CVLValidateType = iota //Data is used as dependent data 39 | VALIDATE_SYNTAX //Syntax is checked and data is used as dependent data 40 | VALIDATE_SEMANTICS //Semantics is checked 41 | VALIDATE_ALL //Syntax and Semantics are checked 42 | ) 43 | 44 | type CVLOperation uint 45 | 46 | const ( 47 | OP_NONE CVLOperation = 0 //Used to just validate the config without any operation 48 | OP_CREATE = 1 << 0 //For Create operation 49 | OP_UPDATE = 1 << 1 //For Update operation 50 | OP_DELETE = 1 << 2 //For Delete operation 51 | ) 52 | 53 | // RequestCacheType Struct for request data and YANG data 54 | type RequestCacheType struct { 55 | ReqData CVLEditConfigData 56 | YangData *xmlquery.Node 57 | } 58 | -------------------------------------------------------------------------------- /cvl/common/db_utils.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | // KeyMatch checks if the value matches a key pattern. 4 | // vIndex and pIndex are start positions of value and pattern strings to match. 5 | // Mimics redis pattern matcher - i.e, glob like pattern matcher which 6 | // matches '/' against wildcard. 7 | // Supports '*' and '?' wildcards with '\' as the escape character. 8 | // '*' matches any char sequence or none; '?' matches exactly one char. 9 | // Character classes are not supported (redis supports it). 10 | func KeyMatch(value, pattern string) bool { 11 | return keyMatch(value, 0, pattern, 0) 12 | } 13 | 14 | func keyMatch(value string, vIndex int, pattern string, pIndex int) bool { 15 | for pIndex < len(pattern) { 16 | switch pattern[pIndex] { 17 | case '*': 18 | // Skip successive *'s in the pattern 19 | pIndex++ 20 | for pIndex < len(pattern) && pattern[pIndex] == '*' { 21 | pIndex++ 22 | } 23 | // Pattern ends with *. Its a match always 24 | if pIndex == len(pattern) { 25 | return true 26 | } 27 | // Try to match remaining pattern with every value substring 28 | for ; vIndex < len(value); vIndex++ { 29 | if keyMatch(value, vIndex, pattern, pIndex) { 30 | return true 31 | } 32 | } 33 | // No match for remaining pattern 34 | return false 35 | 36 | case '?': 37 | // Accept any char.. there should be at least one 38 | if vIndex >= len(value) { 39 | return false 40 | } 41 | vIndex++ 42 | pIndex++ 43 | 44 | case '\\': 45 | // Do not treat \ as escape char if it is the last pattern char. 46 | // Redis commands behave this way. 47 | if pIndex+1 < len(pattern) { 48 | pIndex++ 49 | } 50 | fallthrough 51 | 52 | default: 53 | if vIndex >= len(value) || pattern[pIndex] != value[vIndex] { 54 | return false 55 | } 56 | vIndex++ 57 | pIndex++ 58 | } 59 | } 60 | 61 | // All pattern chars have been compared. 62 | // It is a match if all value chars have been exhausted too. 63 | return (vIndex == len(value)) 64 | } 65 | -------------------------------------------------------------------------------- /cvl/conf/cvl_cfg.json: -------------------------------------------------------------------------------- 1 | { 2 | "TRACE_CACHE": "false", 3 | "TRACE_LIBYANG": "false", 4 | "TRACE_YPARSER": "false", 5 | "TRACE_CREATE": "false", 6 | "TRACE_UPDATE": "false", 7 | "TRACE_DELETE": "false", 8 | "TRACE_SEMANTIC": "false", 9 | "TRACE_SYNTAX": "false", 10 | "TRACE_ONERROR": "false", 11 | "__comment1__": "Set LOGTOSTDER to 'true' to log on standard error", 12 | "LOGTOSTDERR": "false", 13 | "__comment2__": "Display log upto INFO level", 14 | "STDERRTHRESHOLD": "ERROR", 15 | "__comment3__": "Log to /tmp/cvl.log file", 16 | "LOG_TO_FILE": "false", 17 | "__comment4__": "Limit log file size in bytes, 0 means no limit, default 10MB", 18 | "LOG_FILE_SIZE": "10485760", 19 | "__comment5__": "Display log upto INFO level 8", 20 | "VERBOSITY": "0", 21 | "SKIP_VALIDATION": "false", 22 | "SKIP_SEMANTIC_VALIDATION": "false" 23 | } 24 | -------------------------------------------------------------------------------- /cvl/custom_validation/test_validations.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 | //go:build test 21 | // +build test 22 | 23 | package custom_validation 24 | 25 | import ( 26 | "strings" 27 | 28 | "github.com/Azure/sonic-mgmt-common/cvl/internal/util" 29 | ) 30 | 31 | func (t *CustomValidation) ValidateIfExtraFieldValidationCalled( 32 | vc *CustValidationCtxt) CVLErrorInfo { 33 | vc.SessCache.Hint["ExtraFieldValidationCalled"] = true 34 | return CVLErrorInfo{ErrCode: CVL_SUCCESS} 35 | 36 | } 37 | 38 | func (t *CustomValidation) ValidateIfListLevelValidationCalled( 39 | vc *CustValidationCtxt) CVLErrorInfo { 40 | vc.SessCache.Hint["ListLevelValidationCalled"] = true 41 | return CVLErrorInfo{ErrCode: CVL_SUCCESS} 42 | 43 | } 44 | 45 | func (t *CustomValidation) ValidateStpFeatureEnabled(vc *CustValidationCtxt) CVLErrorInfo { 46 | if vc.CurCfg.VOp == OP_DELETE { 47 | return CVLErrorInfo{} 48 | } 49 | applDb := util.NewDbClient("APPL_DB") 50 | if applDb == nil { 51 | return CVLErrorInfo{ 52 | ErrCode: CVL_INTERNAL_UNKNOWN, 53 | CVLErrDetails: "Database access failure", 54 | } 55 | } 56 | if enabled, _ := applDb.HGet("SWITCH_TABLE:switch", "stp_supported").Result(); enabled != "true" { 57 | keys := strings.Split(vc.CurCfg.Key, "|") 58 | return CVLErrorInfo{ 59 | ErrCode: CVL_SEMANTIC_ERROR, 60 | TableName: keys[0], 61 | Keys: keys, 62 | ConstraintErrMsg: "Spanning-tree feature not enabled", 63 | } 64 | } 65 | return CVLErrorInfo{} 66 | } 67 | -------------------------------------------------------------------------------- /cvl/cvl_cust_validation_test.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2025 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 cvl_test 21 | 22 | import ( 23 | "strconv" 24 | "testing" 25 | 26 | "github.com/Azure/sonic-mgmt-common/cvl/internal/util" 27 | ) 28 | 29 | func mockStpFeatureEnabled(t *testing.T, v bool) { 30 | t.Helper() 31 | applDb := util.NewDbClient("APPL_DB") 32 | if applDb == nil { 33 | t.Fatal("Failed to open APPL_DB client") 34 | } 35 | defer applDb.Close() 36 | res := applDb.HSet("SWITCH_TABLE:switch", "stp_supported", strconv.FormatBool(v)) 37 | if res.Err() != nil { 38 | t.Fatalf("Failed to set stp_supported=%v in APPL_DB, err=%v", v, res.Err()) 39 | } 40 | } 41 | 42 | func TestCustomValidation_success(t *testing.T) { 43 | mockStpFeatureEnabled(t, true) 44 | 45 | cfgData := []CVLEditConfigData{ 46 | { 47 | VType: VALIDATE_ALL, 48 | VOp: OP_CREATE, 49 | Key: "STP|GLOBAL", 50 | Data: map[string]string{"mode": "pvst"}, 51 | }, 52 | } 53 | 54 | verifyValidateEditConfig(t, cfgData, Success) 55 | } 56 | 57 | func TestCustomValidation_error(t *testing.T) { 58 | mockStpFeatureEnabled(t, false) 59 | defer mockStpFeatureEnabled(t, true) 60 | 61 | cfgData := []CVLEditConfigData{ 62 | { 63 | VType: VALIDATE_ALL, 64 | VOp: OP_CREATE, 65 | Key: "STP|GLOBAL", 66 | Data: map[string]string{"mode": "pvst"}, 67 | }, 68 | } 69 | 70 | verifyValidateEditConfig(t, cfgData, CVLErrorInfo{ 71 | ErrCode: CVL_SEMANTIC_ERROR, 72 | TableName: "STP", 73 | Keys: []string{"STP", "GLOBAL"}, 74 | ConstraintErrMsg: "Spanning-tree feature not enabled", 75 | }) 76 | } 77 | -------------------------------------------------------------------------------- /cvl/cvl_hint.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 cvl 21 | 22 | import ( 23 | //lint:ignore ST1001 This is safe to dot import for util package 24 | . "github.com/Azure/sonic-mgmt-common/cvl/internal/util" 25 | ) 26 | 27 | // StoreHint saves hints which are passed to the Custom Validation Callbacks 28 | // Caller guarantees that no other CRUD ops are in progress 29 | // key == nil: Clear all Hints 30 | func (c *CVL) StoreHint(key string, value interface{}) CVLRetCode { 31 | 32 | CVL_LOG(INFO_DEBUG, "StoreHint() %v: %v", key, value) 33 | 34 | if c == nil { 35 | return CVL_SUCCESS 36 | } 37 | 38 | if len(key) == 0 { 39 | for k := range c.custvCache.Hint { 40 | delete(c.custvCache.Hint, k) 41 | } 42 | } else if value == nil { 43 | delete(c.custvCache.Hint, key) 44 | } else { 45 | c.custvCache.Hint[key] = value 46 | } 47 | 48 | return CVL_SUCCESS 49 | } 50 | 51 | // LoadHint is used only for Go UT 52 | func (c *CVL) LoadHint(key string) (interface{}, bool) { 53 | if c == nil { 54 | return nil, false 55 | } 56 | 57 | value, ok := c.custvCache.Hint[key] 58 | 59 | CVL_LOG(INFO_DEBUG, "LoadHint() %v: %v", key, value) 60 | 61 | return value, ok 62 | } 63 | -------------------------------------------------------------------------------- /cvl/cvl_hint_test.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 cvl_test 21 | 22 | import ( 23 | "reflect" 24 | "testing" 25 | 26 | "github.com/Azure/sonic-mgmt-common/cvl" 27 | ) 28 | 29 | var hKey = "TESTKEY" 30 | var hValue = map[string]string{"a": "1", "b": "2"} 31 | 32 | func TestSetHint(t *testing.T) { 33 | cvSess, retCode := NewCvlSession() 34 | if retCode != cvl.CVL_SUCCESS { 35 | t.Fatalf("cvl.ValidationSessOpen() fails e: %v", retCode) 36 | } 37 | 38 | t.Cleanup(func() { cvl.ValidationSessClose(cvSess) }) 39 | 40 | if retCode = cvSess.StoreHint(hKey, hValue); retCode != cvl.CVL_SUCCESS { 41 | t.Fatalf("cvSess.StoreHint() fails e: %v", retCode) 42 | } 43 | 44 | value, ok := cvSess.LoadHint(hKey) 45 | if !ok || !reflect.DeepEqual(hValue, value) { 46 | t.Errorf("%v != %v", hValue, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cvl/jsondata_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 cvl_test 21 | 22 | var json_edit_config_create_acl_table_dependent_data = []string{`{ 23 | "stage": "INGRESS", 24 | "type": "L3" 25 | }`} 26 | 27 | var json_edit_config_create_acl_rule_config_data = []string{ 28 | `{ 29 | "PACKET_ACTION": "FORWARD", 30 | "IP_TYPE": "IPV4", 31 | "SRC_IP": "10.1.1.1/32", 32 | "L4_SRC_PORT": "1909", 33 | "IP_PROTOCOL": "103", 34 | "DST_IP": "20.2.2.2/32", 35 | "L4_DST_PORT_RANGE": "9000-12000" 36 | 37 | 38 | }`} 39 | 40 | var json_validate_config_data = []string{`{ 41 | "INTERFACE": { 42 | "Ethernet8|10.0.0.0/31": {}, 43 | "Ethernet12|10.0.0.2/31": {}, 44 | "Ethernet16|10.0.0.4/31": {} 45 | } 46 | }`, 47 | `{ 48 | "DEVICE_METADATA": { 49 | "localhost": { 50 | "hwsku": "Force10-S6100", 51 | "default_bgp_status": "up", 52 | "docker_routing_config_mode": "unified", 53 | "hostname": "sonic-s6100-01", 54 | "platform": "x86_64-dell_s6100_c2538-r0", 55 | "mac": "4c:76:25:f4:70:82", 56 | "default_pfcwd_status": "disable", 57 | "deployment_id": "1", 58 | "type": "ToRRouter" 59 | } 60 | } 61 | }`, 62 | `{ 63 | "CABLE_LENGTH": { 64 | "AZURE": { 65 | "Ethernet8": "5m", 66 | "Ethernet12": "5m", 67 | "Ethernet16": "5m" 68 | } 69 | } 70 | }`} 71 | -------------------------------------------------------------------------------- /cvl/testdata/acl_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_RULE": { 3 | "TestACL13|Rule1": { 4 | "PRIORITY": "55", 5 | "PACKET_ACTION": "DROP", 6 | "L4_SRC_PORT": "0", 7 | "IP_TYPE": "IPV4", 8 | "SRC_IP": "10.1.1.1/32", 9 | "DST_IP": "20.2.2.2/32" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cvl/testdata/aclrule.json: -------------------------------------------------------------------------------- 1 | { 2 | "PACKET_ACTION": "FORWARD", 3 | "IP_TYPE": "IPV4", 4 | "SRC_IP": "10.1.1.1/32", 5 | "L4_SRC_PORT": "1909", 6 | "IP_PROTOCOL": "103", 7 | "DST_IP": "20.2.2.2/32", 8 | "L4_DST_PORT_RANGE": "9000-12000" 9 | } 10 | -------------------------------------------------------------------------------- /cvl/testdata/acltable.json: -------------------------------------------------------------------------------- 1 | { 2 | "stage": "INGRESS", 3 | "type": "L3" 4 | } 5 | -------------------------------------------------------------------------------- /cvl/testdata/create_acl_table.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_TABLE": { 3 | "TestACL1": { 4 | "stage": "INGRESS", 5 | "type": "L3" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /cvl/testdata/create_acl_table12.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_TABLE": { 3 | "TestACL13": { 4 | "stage": "INGRESS", 5 | "type": "L3" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /cvl/testdata/create_acl_table13.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_TABLE": { 3 | "TestACL13": { 4 | "stage": "INGRESS", 5 | "type": "L3" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /cvl/testdata/schema/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 | 22 | all: schema 23 | 24 | .PHONY: schema 25 | schema: 26 | $(MAKE) -C ../.. test-schema 27 | 28 | .PHONY: tree 29 | tree: 30 | $(TOPDIR)/tools/pyang/tree \ 31 | --text=allyangs.tree \ 32 | -p $(TOPDIR)/models/yang/sonic/common *.yang 33 | 34 | clean: 35 | $(RM) -r allyangs.tree $(TOPDIR)/build/tests/cvl/testdata/schema 36 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-buffer-pg.yang: -------------------------------------------------------------------------------- 1 | module sonic-buffer-pg { 2 | namespace "http://github.com/Azure/sonic-buffer-pg"; 3 | prefix bpg; 4 | 5 | import sonic-extension { 6 | prefix sonic-ext; 7 | } 8 | 9 | import sonic-port { 10 | prefix prt; 11 | } 12 | 13 | import sonic-buffer-profile { 14 | prefix bpf; 15 | } 16 | 17 | organization 18 | "SONiC"; 19 | 20 | contact 21 | "SONiC"; 22 | 23 | description 24 | "SONIC BUFFER PG"; 25 | 26 | revision 2019-05-15 { 27 | description 28 | "Initial revision."; 29 | } 30 | 31 | 32 | container sonic-buffer-pg { 33 | 34 | container BUFFER_PG { 35 | 36 | list BUFFER_PG_LIST { 37 | key "ifname pg_num"; 38 | sonic-ext:key-pattern "BUFFER_PG|({ifname},)*|{pg_num}"; //special pattern used for extracting keys from 39 | //redis-key and fill populate the yang instance 40 | // Total list instance = number(key1) * number(key2) * number(key3) 41 | 42 | leaf ifname { 43 | type leafref { 44 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 45 | } 46 | } 47 | 48 | leaf pg_num { 49 | type string { 50 | pattern "[0-7]((-)[0-7])?" { 51 | error-message "Invalid Buffer PG number"; 52 | error-app-tag pg-num-invalid; 53 | } 54 | } 55 | } 56 | 57 | leaf profile { //Hash reference key 58 | type leafref { 59 | path "/bpf:sonic-buffer-profile/bpf:BUFFER_PROFILE/bpf:BUFFER_PROFILE_LIST/bpf:name"; 60 | } 61 | } 62 | 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-buffer-pool.yang: -------------------------------------------------------------------------------- 1 | module sonic-buffer-pool { 2 | namespace "http://github.com/Azure/sonic-buffer-pool"; 3 | prefix bpl; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC BUFFER POOL"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-buffer-pool { 20 | 21 | container BUFFER_POOL { 22 | 23 | list BUFFER_POOL_LIST { 24 | key "name"; 25 | 26 | leaf name { 27 | type string; 28 | } 29 | 30 | leaf type { 31 | type enumeration { 32 | enum ingress; 33 | enum egress; 34 | } 35 | } 36 | 37 | leaf mode { 38 | type enumeration { 39 | enum static; 40 | enum dynamic; 41 | } 42 | } 43 | 44 | leaf size { 45 | type uint64; 46 | } 47 | 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-buffer-profile.yang: -------------------------------------------------------------------------------- 1 | module sonic-buffer-profile { 2 | namespace "http://github.com/Azure/sonic-buffer-profile"; 3 | prefix bpf; 4 | 5 | import sonic-buffer-pool { 6 | prefix bpl; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC BUFFER PROFILE"; 17 | 18 | revision 2019-05-15 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | 24 | container sonic-buffer-profile { 25 | 26 | container BUFFER_PROFILE { 27 | 28 | list BUFFER_PROFILE_LIST { 29 | key "name"; 30 | 31 | leaf name { 32 | type string; 33 | } 34 | 35 | leaf static_th { 36 | type uint64; 37 | } 38 | 39 | leaf dynamic_th { 40 | type int64; 41 | } 42 | 43 | leaf size { 44 | type uint64; 45 | } 46 | 47 | leaf pool { 48 | type leafref { 49 | path "/bpl:sonic-buffer-pool/bpl:BUFFER_POOL/bpl:BUFFER_POOL_LIST/bpl:name"; 50 | } 51 | } 52 | 53 | leaf xon_offset { 54 | type uint64; 55 | } 56 | 57 | leaf xon { 58 | type uint64; 59 | } 60 | 61 | leaf xoff { 62 | type uint64; 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-cablelength.yang: -------------------------------------------------------------------------------- 1 | module sonic-cablelength { 2 | namespace "http://github.com/Azure/sonic-cablelength"; 3 | prefix scl; 4 | 5 | import sonic-port { 6 | prefix prt; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC CABLELENGTH"; 17 | 18 | revision 2019-07-02 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | container sonic-cablelength { 24 | 25 | container CABLE_LENGTH { 26 | 27 | list CABLE_LENGTH_LIST { 28 | key "name"; 29 | 30 | leaf name { 31 | type string; 32 | } 33 | 34 | list CABLE_LENGTH { //this is list inside list for storing mapping between two fields 35 | key "port"; 36 | 37 | leaf port { 38 | type leafref { 39 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 40 | } 41 | 42 | } 43 | 44 | leaf length { 45 | type string { 46 | pattern "[0-9]?[0-9]m"; 47 | } 48 | } 49 | } 50 | 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-device-metadata.yang: -------------------------------------------------------------------------------- 1 | module sonic-device-metadata { 2 | yang-version 1.1; 3 | namespace "http://github.com/Azure/sonic-device-metadata"; 4 | prefix sdm; 5 | 6 | import ietf-yang-types { 7 | prefix yang; 8 | } 9 | 10 | import sonic-common { 11 | prefix scommon; 12 | } 13 | 14 | import sonic-bgp-global { 15 | prefix sbg; 16 | } 17 | 18 | organization 19 | "SONiC"; 20 | 21 | contact 22 | "SONiC"; 23 | 24 | description 25 | "SONIC DEVICE METADATA"; 26 | 27 | revision 2019-07-02 { 28 | description 29 | "Initial revision."; 30 | } 31 | 32 | container sonic-device-metadata { 33 | 34 | container DEVICE_METADATA { 35 | 36 | list DEVICE_METADATA_LIST { 37 | key "name"; 38 | max-elements 1; 39 | 40 | leaf name{ 41 | type string; 42 | } 43 | 44 | leaf vrf_name { 45 | type enumeration { 46 | enum default; 47 | } 48 | default default; 49 | } 50 | 51 | leaf hwsku { 52 | type string; 53 | } 54 | 55 | leaf hostname { 56 | type string; 57 | } 58 | 59 | leaf platform { 60 | type string; 61 | } 62 | 63 | leaf mac { 64 | type yang:mac-address; 65 | } 66 | 67 | leaf bgp_asn { 68 | type leafref { 69 | path "/sbg:sonic-bgp-global/sbg:BGP_GLOBALS/sbg:BGP_GLOBALS_LIST[sbg:vrf_name=current()/../vrf_name]/sbg:local_asn"; 70 | } 71 | } 72 | 73 | leaf default_pfcwd_status { 74 | type enumeration { 75 | enum enable; 76 | enum disable; 77 | } 78 | } 79 | 80 | leaf default_bgp_status { 81 | type scommon:admin-status; 82 | } 83 | 84 | leaf docker_routing_config_mode { 85 | type enumeration { 86 | enum unified; 87 | enum separated; 88 | } 89 | } 90 | 91 | leaf deployment_id { 92 | type uint8 { 93 | range "0..255"; 94 | } 95 | } 96 | 97 | leaf type { 98 | type enumeration { 99 | enum ToRRouter; 100 | enum LeafRouter; 101 | } 102 | } 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-device-neighbor.yang: -------------------------------------------------------------------------------- 1 | module sonic-device-neighbor { 2 | namespace "http://github.com/Azure/sonic-device-neighbor"; 3 | prefix sdn; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | import sonic-port { 10 | prefix prt; 11 | } 12 | 13 | 14 | organization 15 | "SONiC"; 16 | 17 | contact 18 | "SONiC"; 19 | 20 | description 21 | "SONIC DEVICE NEIGHBOR"; 22 | 23 | revision 2019-07-02 { 24 | description 25 | "Initial revision."; 26 | } 27 | 28 | container sonic-device-neighbor { 29 | 30 | container DEVICE_NEIGHBOR { 31 | 32 | list DEVICE_NEIGHBOR_LIST { 33 | key "name"; 34 | 35 | leaf name{ 36 | type string; 37 | } 38 | 39 | leaf mgmt_addr{ 40 | type inet:ip-address; 41 | } 42 | 43 | leaf hwsku { 44 | type string; 45 | } 46 | 47 | leaf lo_addr { 48 | type inet:ip-address; 49 | } 50 | 51 | leaf local_port { 52 | type leafref { 53 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 54 | } 55 | } 56 | 57 | leaf type { 58 | type enumeration { 59 | enum ToRRouter; 60 | enum LeafRouter; 61 | } 62 | } 63 | 64 | leaf port { 65 | type leafref { 66 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-dscp-tc-map.yang: -------------------------------------------------------------------------------- 1 | module sonic-dscp-tc-map { 2 | namespace "http://github.com/Azure/sonic-dscp-tc-map"; 3 | prefix dtm; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC DSCP_TO_TC_MAP"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-dscp-tc-map { 20 | 21 | container DSCP_TO_TC_MAP { 22 | 23 | list DSCP_TO_TC_MAP_LIST { 24 | key "name"; 25 | 26 | leaf name { 27 | type string; 28 | } 29 | 30 | list DSCP_TO_TC_MAP { //this is list inside list for storing mapping between two fields 31 | key "dscp"; 32 | 33 | leaf tc_num { 34 | type string { 35 | pattern "[0-9]?"{ 36 | error-message "Invalid Traffic Class number"; 37 | error-app-tag tc-num-invalid; 38 | } 39 | } 40 | } 41 | 42 | leaf dscp { 43 | type string { 44 | pattern "[1-9][0-9]?|[0-9]?"; 45 | } 46 | } 47 | } 48 | 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-ifa.yang: -------------------------------------------------------------------------------- 1 | module sonic-ifa { 2 | namespace "http://github.com/Azure/sonic-ifa"; 3 | prefix ifa; 4 | 5 | yang-version 1.1; 6 | 7 | import sonic-acl { 8 | prefix acl; 9 | } 10 | 11 | organization 12 | "SONiC"; 13 | 14 | contact 15 | "SONiC"; 16 | 17 | description 18 | "SONIC TAM IFA"; 19 | 20 | revision 2019-11-12 { 21 | description 22 | "Initial revision."; 23 | } 24 | 25 | container sonic-ifa { 26 | 27 | container TAM_INT_IFA_FEATURE_TABLE { 28 | 29 | list TAM_INT_IFA_FEATURE_TABLE_LIST { 30 | key "name"; 31 | 32 | leaf name { 33 | type enumeration { 34 | enum feature; 35 | } 36 | } 37 | 38 | leaf enable { 39 | type boolean; 40 | } 41 | } 42 | } 43 | 44 | container TAM_INT_IFA_FLOW_TABLE { 45 | 46 | list TAM_INT_IFA_FLOW_TABLE_LIST { 47 | key "name"; 48 | 49 | leaf name { 50 | type string { 51 | pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,32})'; 52 | length 1..32; 53 | } 54 | } 55 | 56 | leaf acl-table-name { 57 | mandatory true; 58 | type leafref { 59 | path "/acl:sonic-acl/acl:ACL_TABLE/acl:ACL_TABLE_LIST/acl:aclname"; 60 | } 61 | } 62 | 63 | leaf acl-rule-name { 64 | mandatory true; 65 | type leafref { 66 | path "/acl:sonic-acl/acl:ACL_RULE/acl:ACL_RULE_LIST[acl:aclname=current()/../acl-table-name]/acl:rulename"; 67 | } 68 | } 69 | 70 | leaf sampling-rate { 71 | type uint16 { 72 | range "1..10000"{ 73 | error-app-tag "Invalid IFA flow sampling rate."; 74 | } 75 | } 76 | } 77 | 78 | leaf collector-name { 79 | type string { 80 | pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,32})'; 81 | length 1..32; 82 | } 83 | } 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-leaflist-test.yang: -------------------------------------------------------------------------------- 1 | module sonic-leaflist-test { 2 | namespace "http://github.com/Azure/sonic-leaflist-test"; 3 | prefix "test-ll"; 4 | 5 | organization "SONiC"; 6 | contact "SONiC"; 7 | description 8 | "A test schema for verification of various constratints on 9 | db fields modeled as leaf-list. Should not be used in production"; 10 | 11 | revision 2023-02-13 { 12 | description 13 | "Initial version with min-elements and max-elements constraints."; 14 | } 15 | 16 | container sonic-leaflist-test { 17 | 18 | container TEST_LEAFLIST { 19 | list TEST_LEAFLIST_LIST { 20 | key "id"; 21 | 22 | leaf id { 23 | type string; 24 | description "Key attribute"; 25 | } 26 | leaf-list without-minmax { 27 | type string; 28 | description "No min-elements and max-elements constrains."; 29 | } 30 | leaf-list with-min0 { 31 | type string; 32 | min-elements 0; 33 | description "min-elements 0; same as not defined"; 34 | } 35 | leaf-list with-min1-max2 { 36 | type string; 37 | min-elements 1; 38 | max-elements 2; 39 | description "min-elements 1 and max-elements 2"; 40 | } 41 | leaf-list with-min4 { 42 | type string; 43 | min-elements 4; 44 | description "min-elements 4"; 45 | } 46 | } 47 | } 48 | 49 | } 50 | } -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-loopback-interface.yang: -------------------------------------------------------------------------------- 1 | module sonic-loopback-interface { 2 | namespace "http://github.com/Azure/sonic-loopback-interface"; 3 | prefix sonic-lo-if; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC LOOPBACK INTERFACE"; 17 | 18 | revision 2019-07-02 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | container sonic-loopback-interface { 24 | 25 | container LOOPBACK_INTERFACE { 26 | 27 | list LOOPBACK_INTERFACE_LIST { 28 | key "loIfName"; 29 | 30 | leaf loIfName{ 31 | type string; 32 | } 33 | 34 | leaf vrf_name { 35 | type string; 36 | } 37 | } 38 | 39 | list LOOPBACK_INTERFACE_IPADDR_LIST { 40 | key "loIfName ip_prefix"; 41 | 42 | leaf loIfName{ 43 | type string; 44 | } 45 | 46 | leaf ip_prefix { 47 | mandatory true; 48 | type inet:ip-prefix; 49 | 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-mgmt_port.yang: -------------------------------------------------------------------------------- 1 | module sonic-mgmt_port { 2 | yang-version 1.1; 3 | namespace "http://github.com/sonic-net/sonic-mgmt_port"; 4 | prefix mgmtprt; 5 | 6 | import sonic-types { 7 | prefix stypes; 8 | } 9 | 10 | description 11 | "MANAGEMENT PORT yang Module for SONiC OS"; 12 | 13 | revision 2021-04-07 { 14 | description 15 | "First Revision"; 16 | } 17 | 18 | container sonic-mgmt_port { 19 | container MGMT_PORT { 20 | description 21 | "MANAGEMENT PORT part of config_db.json"; 22 | list MGMT_PORT_LIST { 23 | key "name"; 24 | leaf name { 25 | type string { 26 | pattern 'eth([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])'; 27 | } 28 | } 29 | leaf speed { 30 | type uint16 { 31 | range "10|100|1000"; 32 | } 33 | description 34 | "Management port speed in megabytes."; 35 | } 36 | leaf autoneg { 37 | type string { 38 | pattern 'on|off'; 39 | } 40 | } 41 | leaf alias { 42 | type string; 43 | } 44 | leaf description { 45 | type string; 46 | } 47 | leaf mtu { 48 | type uint16 { 49 | range "1500..9216"; 50 | } 51 | default "1500"; 52 | } 53 | leaf admin_status { 54 | type stypes:admin_status; 55 | default "up"; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-mgmt_vrf.yang: -------------------------------------------------------------------------------- 1 | module sonic-mgmt_vrf { 2 | yang-version 1.1; 3 | namespace "http://github.com/sonic-net/sonic-mgmt_vrf"; 4 | prefix mvrf; 5 | 6 | description 7 | "SONiC MGMT VRF"; 8 | 9 | revision 2021-04-07 { 10 | description 11 | "First revision"; 12 | } 13 | 14 | container sonic-mgmt_vrf { 15 | container MGMT_VRF_CONFIG { 16 | container vrf_global { 17 | leaf mgmtVrfEnabled { 18 | type boolean; 19 | default "false"; 20 | } 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-mirror-session.yang: -------------------------------------------------------------------------------- 1 | module sonic-mirror-session { 2 | namespace "http://github.com/Azure/sonic-mirror-session"; 3 | prefix sms; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC MIRROR SESSION"; 17 | 18 | revision 2019-05-15 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | container sonic-mirror-session { 24 | 25 | container MIRROR_SESSION { 26 | 27 | list MIRROR_SESSION_LIST { 28 | key "name"; 29 | 30 | leaf name { 31 | type string; 32 | } 33 | 34 | leaf src_ip { 35 | type inet:ipv4-address; 36 | } 37 | 38 | leaf dst_ip { 39 | type inet:ipv4-address; 40 | } 41 | 42 | leaf gre_type { 43 | type string; 44 | } 45 | 46 | leaf dscp { 47 | type uint8; 48 | } 49 | 50 | leaf ttl { 51 | type uint8; 52 | } 53 | 54 | leaf queue { 55 | type uint8; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-ospfv2.yang: -------------------------------------------------------------------------------- 1 | module sonic-ospfv2 { 2 | namespace "http://github.com/Azure/sonic-ospfv2"; 3 | prefix sn-ospfv2; 4 | yang-version 1.1; 5 | 6 | import sonic-extension { 7 | prefix sonic-ext; 8 | } 9 | import sonic-vlan-subinterface { 10 | prefix svlansub; 11 | } 12 | organization 13 | "SONiC"; 14 | 15 | contact 16 | "SONiC"; 17 | 18 | description 19 | "SONIC ospfv2 Global YANG"; 20 | 21 | revision 2020-03-21 { 22 | description 23 | "Added Yang definition for OSPFv2 features."; 24 | } 25 | 26 | typedef ospf-sub-vlan-interface { 27 | type union { 28 | type string { 29 | pattern "vlansub"; 30 | } 31 | type leafref { 32 | path "/svlansub:sonic-vlan-subinterface/svlansub:VLAN_SUB_INTERFACE/svlansub:VLAN_SUB_INTERFACE_LIST/svlansub:id"; 33 | } 34 | } 35 | } 36 | 37 | typedef ospf-interface { 38 | type union { 39 | type string { 40 | pattern "null"; 41 | } 42 | type ospf-sub-vlan-interface; 43 | } 44 | description 45 | "OSPF Interface name"; 46 | } 47 | 48 | container sonic-ospfv2 { 49 | container OSPFV2_INTERFACE { 50 | description 51 | "OSPFv2 Interface Table."; 52 | list OSPFV2_INTERFACE_LIST { 53 | key "name"; 54 | leaf name { 55 | type ospf-interface; 56 | description 57 | "OSPF interface"; 58 | } 59 | } //OSPFV2_INTERFACE_LIST 60 | } //OSPFV2_INTERFACE 61 | } //sonic-ospfv2 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-pf-limits.yang: -------------------------------------------------------------------------------- 1 | module sonic-pf-limits { 2 | namespace "http://github.com/Azure/sonic-pf-limits"; 3 | prefix spf; 4 | yang-version 1.1; 5 | 6 | import sonic-extension { 7 | prefix sonic-ext; 8 | } 9 | 10 | organization 11 | "SONiC"; 12 | 13 | contact 14 | "SONiC"; 15 | 16 | description 17 | "SONIC Platform constrainst"; 18 | 19 | revision 2019-05-15 { 20 | description 21 | "Initial revision."; 22 | } 23 | 24 | container sonic-pf-limits { 25 | sonic-ext:db-name "APPL_DB"; 26 | 27 | container acl { 28 | leaf MAX_ACL_RULES { 29 | type uint16; 30 | } 31 | leaf MAX_PRIORITY { 32 | type uint16 { 33 | range "1..65535"; 34 | } 35 | } 36 | 37 | } 38 | container vlan { 39 | leaf MAX_VLANS { 40 | type uint16; 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-pfc-priority-queue-map.yang: -------------------------------------------------------------------------------- 1 | module sonic-pfc-priority-queue-map { 2 | namespace "http://github.com/Azure/sonic-pfc-priority-queue-map"; 3 | prefix ppq; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC MAP_PFC_PRIORITY_TO_QUEUE"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-pfc-priority-queue-map { 20 | 21 | container MAP_PFC_PRIORITY_TO_QUEUE { 22 | 23 | list MAP_PFC_PRIORITY_TO_QUEUE_LIST { 24 | key "name"; 25 | 26 | leaf name { 27 | type string; 28 | } 29 | 30 | list MAP_PFC_PRIORITY_TO_QUEUE { //this is list inside list for storing mapping between two fields 31 | key "pfc_priority"; 32 | 33 | leaf pfc_priority { 34 | type string { 35 | pattern "[0-9]?"; 36 | } 37 | } 38 | 39 | leaf qindex { 40 | type string { 41 | pattern "[0-9]?"; 42 | } 43 | } 44 | } 45 | 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-pki.yang: -------------------------------------------------------------------------------- 1 | module sonic-pki { 2 | namespace "http://github.com/sonic-net/sonic-pki"; 3 | prefix sonic-pki; 4 | yang-version 1.1; 5 | 6 | organization 7 | "SONiC"; 8 | 9 | contact 10 | "SONiC"; 11 | 12 | description 13 | "SONIC PKI YANG"; 14 | 15 | revision 2024-01-30 { 16 | description 17 | "Add vrf-name attribute"; 18 | } 19 | revision 2023-01-10 { 20 | description 21 | "Add validations"; 22 | } 23 | revision 2022-09-30 { 24 | description 25 | "Initial revision."; 26 | } 27 | 28 | container sonic-pki { 29 | container SECURITY_PROFILES { 30 | list SECURITY_PROFILES_LIST { 31 | key "profile-name"; 32 | leaf "profile-name" { 33 | type string; 34 | description 35 | "Unique name for the security profile"; 36 | } 37 | leaf "certificate-name" { 38 | type string; 39 | description 40 | "Certificate file name"; 41 | } 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-port-qos-map.yang: -------------------------------------------------------------------------------- 1 | module sonic-port-qos-map { 2 | namespace "http://github.com/Azure/sonic-port-qos-map"; 3 | prefix pqm; 4 | 5 | import sonic-extension { 6 | prefix sonic-ext; 7 | } 8 | 9 | import sonic-port { 10 | prefix prt; 11 | } 12 | 13 | import sonic-tc-priority-group-map { 14 | prefix tpg; 15 | } 16 | 17 | import sonic-tc-queue-map { 18 | prefix tqm; 19 | } 20 | 21 | import sonic-pfc-priority-queue-map { 22 | prefix ppq; 23 | } 24 | 25 | import sonic-dscp-tc-map { 26 | prefix dtm; 27 | } 28 | 29 | organization 30 | "SONiC"; 31 | 32 | contact 33 | "SONiC"; 34 | 35 | description 36 | "SONIC PORT_QOS_MAP"; 37 | 38 | revision 2019-05-15 { 39 | description 40 | "Initial revision."; 41 | } 42 | 43 | container sonic-port-qos-map { 44 | 45 | list PORT_QOS_MAP { 46 | key "ifname"; 47 | sonic-ext:key-pattern "PORT_QOS_MAP|({ifname},)*"; //special pattern used for extracting keys from redis-key and fill populate the yang instance 48 | // Total list instance = number(key1) * number(key2) * number(key3) 49 | 50 | leaf ifname { 51 | type leafref { 52 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 53 | } 54 | } 55 | 56 | leaf tc_to_pg_map { 57 | type leafref { 58 | path "/tpg:sonic-tc-priority-group-map/tpg:TC_TO_PRIORITY_GROUP_MAP/tpg:TC_TO_PRIORITY_GROUP_MAP_LIST/tpg:name"; 59 | } 60 | } 61 | 62 | leaf tc_to_queue_map { 63 | type leafref { 64 | path "/tqm:sonic-tc-queue-map/tqm:TC_TO_QUEUE_MAP/tqm:TC_TO_QUEUE_MAP_LIST/tqm:name"; 65 | } 66 | } 67 | 68 | leaf pfc-enable { 69 | type string { 70 | pattern "[0-9](,[0-9])?"; 71 | } 72 | } 73 | 74 | leaf pfc_to_queue_map { 75 | type leafref { 76 | path "/ppq:sonic-pfc-priority-queue-map/ppq:MAP_PFC_PRIORITY_TO_QUEUE/ppq:MAP_PFC_PRIORITY_TO_QUEUE_LIST/ppq:name"; 77 | } 78 | } 79 | 80 | leaf dscp_to_tc_map { 81 | type leafref { 82 | path "/dtm:sonic-dscp-tc-map/dtm:DSCP_TO_TC_MAP/dtm:DSCP_TO_TC_MAP_LIST/dtm:name"; 83 | } 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-portchannel-interface.yang: -------------------------------------------------------------------------------- 1 | module sonic-portchannel-interface { 2 | yang-version 1.1; 3 | namespace "http://github.com/Azure/sonic-portchannel-interface"; 4 | prefix spchint; 5 | 6 | import ietf-inet-types { 7 | prefix inet; 8 | } 9 | 10 | import sonic-portchannel { 11 | prefix spc; 12 | } 13 | 14 | import sonic-vrf { 15 | prefix vrf; 16 | } 17 | 18 | organization 19 | "SONiC"; 20 | 21 | contact 22 | "SONiC"; 23 | 24 | description 25 | "SONIC PORTCHANNEL INTERFACE"; 26 | 27 | revision 2019-07-02 { 28 | description 29 | "Initial revision."; 30 | } 31 | 32 | container sonic-portchannel-interface { 33 | 34 | container PORTCHANNEL_INTERFACE { 35 | 36 | list PORTCHANNEL_INTERFACE_LIST { 37 | key "pch_name"; 38 | 39 | leaf pch_name{ 40 | type leafref { 41 | path "/spc:sonic-portchannel/spc:PORTCHANNEL/spc:PORTCHANNEL_LIST/spc:name"; 42 | } 43 | } 44 | 45 | leaf vrf_name { 46 | type union { 47 | type string { 48 | pattern "mgmt"; 49 | } 50 | type leafref { 51 | path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:vrf_name"; 52 | } 53 | } 54 | } 55 | } 56 | 57 | list PORTCHANNEL_INTERFACE_IPADDR_LIST { 58 | key "pch_name ip_prefix"; 59 | 60 | leaf pch_name{ 61 | type leafref { 62 | path "/spc:sonic-portchannel/spc:PORTCHANNEL/spc:PORTCHANNEL_LIST/spc:name"; 63 | } 64 | } 65 | 66 | leaf ip_prefix { 67 | mandatory true; 68 | type inet:ip-prefix; 69 | 70 | } 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-queue.yang: -------------------------------------------------------------------------------- 1 | module sonic-queue { 2 | namespace "http://github.com/Azure/sonic-queue"; 3 | prefix squeue; 4 | 5 | import sonic-extension { 6 | prefix sonic-ext; 7 | } 8 | 9 | import sonic-port { 10 | prefix prt; 11 | } 12 | 13 | import sonic-scheduler { 14 | prefix sch; 15 | } 16 | 17 | import sonic-wred-profile { 18 | prefix wrd; 19 | } 20 | 21 | organization 22 | "SONiC"; 23 | 24 | contact 25 | "SONiC"; 26 | 27 | description 28 | "SONIC QUEUE"; 29 | 30 | revision 2019-05-15 { 31 | description 32 | "Initial revision."; 33 | } 34 | 35 | 36 | container sonic-queue { 37 | 38 | container QUEUE { 39 | 40 | list QUEUE_LIST { 41 | key "ifname qindex"; 42 | sonic-ext:key-pattern "QUEUE|({ifname},)*|{qindex}"; //special pattern used for extracting keys from redis-key and populate the yang instance 43 | // Total list instances = number(key1) * number(key2) * number(key3) 44 | 45 | leaf ifname { 46 | type leafref { 47 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 48 | } 49 | } 50 | 51 | leaf qindex { 52 | type string { 53 | pattern "[0-8]((-)[0-8])?"{ 54 | error-message "Invalid Q-index"; 55 | error-app-tag qindex-invalid; 56 | } 57 | } 58 | } 59 | 60 | leaf scheduler { 61 | type leafref { 62 | path "/sch:sonic-scheduler/sch:SCHEDULER/sch:SCHEDULER_LIST/sch:name"; 63 | } 64 | } 65 | 66 | leaf wred_profile { 67 | type leafref { 68 | path "/wrd:sonic-wred-profile/wrd:WRED_PROFILE/wrd:WRED_PROFILE_LIST/wrd:name"; 69 | } 70 | } 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-scheduler.yang: -------------------------------------------------------------------------------- 1 | module sonic-scheduler { 2 | namespace "http://github.com/Azure/sonic-scheduler"; 3 | prefix sch; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC SCHEDULER"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-scheduler { 20 | 21 | container SCHEDULER { 22 | 23 | list SCHEDULER_LIST { 24 | key "name"; 25 | 26 | leaf name{ 27 | type string; 28 | } 29 | 30 | leaf type { 31 | type enumeration { 32 | enum DWRR; 33 | enum WRR; 34 | enum PRIORITY; 35 | } 36 | } 37 | 38 | leaf weight { 39 | type uint8 { 40 | range "0..255"; 41 | } 42 | } 43 | 44 | leaf priority { 45 | type uint8 { 46 | range "0..9"; 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-security-global.yang: -------------------------------------------------------------------------------- 1 | module sonic-security-global { 2 | namespace "http://github.com/sonic-net/sonic-security-global"; 3 | prefix sonic-security; 4 | yang-version 1.1; 5 | 6 | import sonic-pki { 7 | prefix spki; 8 | } 9 | 10 | organization 11 | "SONiC"; 12 | 13 | contact 14 | "SONiC"; 15 | 16 | description 17 | "This module defines the global security configuration for SONiC."; 18 | 19 | revision 2024-07-03 { 20 | description 21 | "Initial revision."; 22 | reference 23 | "RFC XXXX"; 24 | } 25 | 26 | container sonic-security-global { 27 | container SECURITY_GLOBAL { 28 | container global { 29 | leaf security_profile { 30 | type leafref { 31 | path "/spki:sonic-pki/spki:SECURITY_PROFILES/spki:SECURITY_PROFILES_LIST/spki:profile-name"; 32 | } 33 | description 34 | "Reference to the security profile defined in the sonic-pki module."; 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-tam.yang: -------------------------------------------------------------------------------- 1 | module sonic-tam { 2 | namespace "http://github.com/Azure/sonic-tam"; 3 | prefix tam; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC TAM"; 17 | 18 | revision 2019-11-08 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | container sonic-tam { 24 | 25 | container TAM_DEVICE_TABLE { 26 | 27 | list TAM_DEVICE_TABLE_LIST { 28 | key "name"; 29 | leaf name { 30 | type enumeration { 31 | enum device; 32 | } 33 | } 34 | 35 | leaf deviceid { 36 | type uint16; 37 | default 0; 38 | } 39 | } 40 | } 41 | 42 | container TAM_COLLECTOR_TABLE { 43 | 44 | list TAM_COLLECTOR_TABLE_LIST { 45 | key "name"; 46 | 47 | leaf name { 48 | type string { 49 | pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,32})'; 50 | length 1..32; 51 | } 52 | } 53 | 54 | leaf ipaddress-type { 55 | type enumeration { 56 | enum ipv4; 57 | enum ipv6; 58 | } 59 | 60 | must "(contains(../ipaddress, ':') and current()='ipv6') or " + 61 | "(contains(../ipaddress, '.') and current()='ipv4')" { 62 | error-app-tag ipaddres-type-mismatch; 63 | error-message "IP address and IP address type does not match."; 64 | } 65 | } 66 | 67 | leaf ipaddress { 68 | type inet:ip-address; 69 | } 70 | 71 | leaf port { 72 | type inet:port-number; 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-tc-priority-group-map.yang: -------------------------------------------------------------------------------- 1 | module sonic-tc-priority-group-map { 2 | namespace "http://github.com/Azure/sonic-tc-priority-group-map"; 3 | prefix tpg; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC TC_TO_PRIORITY_GROUP_MAP"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-tc-priority-group-map { 20 | 21 | container TC_TO_PRIORITY_GROUP_MAP { 22 | 23 | list TC_TO_PRIORITY_GROUP_MAP_LIST { 24 | key "name"; 25 | 26 | leaf name { 27 | type string; 28 | } 29 | 30 | list TC_TO_PRIORITY_GROUP_MAP { //this is list inside list for storing mapping between two fields 31 | key "tc_num"; 32 | 33 | leaf tc_num { 34 | type string { 35 | pattern "[0-9]?"; 36 | } 37 | } 38 | 39 | leaf pg_num { 40 | type string { 41 | pattern "[0-7]?"; 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-tc-queue-map.yang: -------------------------------------------------------------------------------- 1 | module sonic-tc-queue-map { 2 | namespace "http://github.com/Azure/sonic-tc-queue-map"; 3 | prefix tqm; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC TC_TO_QUEUE_MAP"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-tc-queue-map { 20 | 21 | container TC_TO_QUEUE_MAP { 22 | 23 | list TC_TO_QUEUE_MAP_LIST { 24 | key "name"; 25 | 26 | leaf name { 27 | type string; 28 | } 29 | 30 | list TC_TO_QUEUE_MAP { //this is list inside list for storing mapping between two fields 31 | key "tc_num"; 32 | 33 | leaf tc_num { 34 | type string { 35 | pattern "[0-9]?"; 36 | } 37 | } 38 | 39 | leaf qindex { 40 | type string { 41 | pattern "[0-9]?"; 42 | } 43 | } 44 | } 45 | 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-telemetry.yang: -------------------------------------------------------------------------------- 1 | module sonic-telemetry { 2 | 3 | yang-version 1.1; 4 | 5 | namespace "http://github.com/sonic-net/sonic-telemetry"; 6 | prefix telemetry; 7 | 8 | import ietf-inet-types { 9 | prefix inet; 10 | } 11 | 12 | organization 13 | "SONiC"; 14 | 15 | contact 16 | "SONiC"; 17 | 18 | description "TELEMETRY YANG Module for SONiC OS"; 19 | 20 | revision 2022-05-13 { 21 | description "First Revision"; 22 | } 23 | 24 | container sonic-telemetry { 25 | 26 | container TELEMETRY { 27 | 28 | description "TELEMETRY TABLE part of config_db.json"; 29 | 30 | container certs { 31 | 32 | leaf ca_crt { 33 | type string { 34 | pattern '(/[a-zA-Z0-9_-]+)*/([a-zA-Z0-9_-]+).cer'; 35 | } 36 | description "Local path for ca_crt."; 37 | } 38 | 39 | leaf-list crts { 40 | type string; 41 | max-elements 1; 42 | description 43 | "Just a sample to test leaf-list"; 44 | } 45 | 46 | } 47 | 48 | container gnmi { 49 | 50 | leaf ca_crt { 51 | type string; 52 | when "../../certs/ca_crt = '/someDirectory/subDirectory/myCertFile.cer'"; 53 | } 54 | 55 | leaf client_auth { 56 | type boolean; 57 | description "Flag for requiring client auth."; 58 | must "count(../../certs/crts) > 0" { 59 | error-message "No certs configured"; 60 | error-app-tag no-cert-configured; 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-telemetry_client.yang: -------------------------------------------------------------------------------- 1 | module sonic-telemetry_client { 2 | 3 | yang-version 1.1; 4 | 5 | namespace "http://github.com/sonic-net/sonic-telemetry_client"; 6 | prefix telemetry_client; 7 | 8 | import ietf-inet-types { 9 | prefix inet; 10 | } 11 | 12 | import sonic-types { 13 | prefix stypes; 14 | } 15 | 16 | organization 17 | "SONiC"; 18 | 19 | contact 20 | "SONiC"; 21 | 22 | description 23 | "TELEMETRY_CLIENT yang Module for SONiC OS"; 24 | 25 | revision 2023-01-12 { 26 | description 27 | "First revision"; 28 | } 29 | 30 | typedef report-type { 31 | type enumeration { 32 | enum periodic; 33 | enum stream; 34 | enum once; 35 | } 36 | } 37 | typedef path_target { 38 | type enumeration { 39 | enum APPL_DB; 40 | enum CONFIG_DB; 41 | enum COUNTERS_DB; 42 | enum STATE_DB; 43 | enum OTHERS; 44 | } 45 | } 46 | 47 | typedef encoding { 48 | type enumeration { 49 | enum JSON_IETF; 50 | enum ASCII; 51 | enum BYTES; 52 | enum PROTO; 53 | } 54 | } 55 | 56 | typedef ipv4-port { 57 | type string { 58 | pattern 59 | '((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' 60 | + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]):' 61 | + '([0-9]|[1-9]\d{1,3}|[1-5]\d{1,4}|6[0-4]\d{1,3}|65[0-4]\d{1,2}|655[0-2][0-9]|6553[0-5]),?)+'; 62 | } 63 | } 64 | 65 | 66 | container sonic-telemetry_client{ 67 | 68 | container TELEMETRY_CLIENT { 69 | container Global { 70 | leaf retry_interval { 71 | type uint64; 72 | description "retry_interval unit s"; 73 | } 74 | 75 | leaf src_ip { 76 | type inet:ip-address; 77 | } 78 | 79 | leaf encoding { 80 | type encoding; 81 | } 82 | 83 | leaf unidirectional { 84 | type boolean; 85 | default true; 86 | } 87 | } 88 | 89 | list TELEMETRY_CLIENT_LIST { 90 | ordered-by user; 91 | key "name"; 92 | 93 | // leaf prefix { 94 | // type string { 95 | // pattern 'Subscription|DestinationGroup'; 96 | // } 97 | // } 98 | leaf name { 99 | type string; 100 | } 101 | leaf report_interval { 102 | type uint64; 103 | description "report_interval unit ms"; 104 | default 5000; 105 | } 106 | } 107 | } 108 | } 109 | } 110 | 111 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-vlan-deviation.yang: -------------------------------------------------------------------------------- 1 | module sonic-vlan-deviation { 2 | namespace "http://github.com/Azure/sonic-vlan-deviation"; 3 | prefix svd; 4 | yang-version 1.1; 5 | 6 | /* 7 | import sonic-vlan { 8 | prefix svlan; 9 | } 10 | */ 11 | 12 | organization 13 | "SONiC"; 14 | 15 | contact 16 | "SONiC"; 17 | 18 | description 19 | "SONIC VLAN deviation file"; 20 | 21 | revision 2019-05-15 { 22 | description 23 | "Initial revision."; 24 | } 25 | 26 | /* 27 | deviation /svlan:sonic-vlan/svlan:VLAN/svlan:name { 28 | deviate replace { 29 | type string { 30 | // Supports 3K VLANs 31 | pattern "Vlan([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[1-9])"; 32 | } 33 | } 34 | } 35 | */ 36 | } 37 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-vlan-interface.yang: -------------------------------------------------------------------------------- 1 | module sonic-vlan-interface { 2 | namespace "http://github.com/Azure/sonic-vlan-interface"; 3 | prefix sVlanIf; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | import sonic-vlan { 10 | prefix svlan; 11 | } 12 | 13 | import sonic-common { 14 | prefix cmn; 15 | } 16 | 17 | import sonic-interface { 18 | prefix sint; 19 | } 20 | 21 | organization 22 | "SONiC"; 23 | 24 | contact 25 | "SONiC"; 26 | 27 | description 28 | "SONiC VLAN INTERFACE"; 29 | 30 | revision 2019-07-02 { 31 | description 32 | "Initial revision."; 33 | } 34 | 35 | container sonic-vlan-interface { 36 | 37 | container VLAN_INTERFACE { 38 | 39 | list VLAN_INTERFACE_LIST { 40 | key "vlanName"; 41 | 42 | leaf vlanName { 43 | type leafref { 44 | path "/svlan:sonic-vlan/svlan:VLAN/svlan:VLAN_LIST/svlan:name"; 45 | } 46 | must "count(/svlan:sonic-vlan/svlan:VLAN/svlan:VLAN_LIST/svlan:members) > 0" { 47 | error-message "No VLAN member is configured"; 48 | error-app-tag no-vlan-member-configured; 49 | } 50 | } 51 | 52 | } 53 | list VLAN_INTERFACE_IPADDR_LIST { 54 | key "vlanName ip_prefix"; 55 | 56 | leaf vlanName{ 57 | type leafref { 58 | path "/svlan:sonic-vlan/svlan:VLAN/svlan:VLAN_LIST/svlan:name"; 59 | } 60 | must "(/cmn:operation/cmn:operation != 'CREATE') or " + 61 | "(count(/sint:sonic-interface/sint:INTERFACE/sint:INTERFACE_IPADDR_LIST" + 62 | "[sint:ip_prefix=current()/../ip_prefix] " + 63 | "[sint:portname=(/svlan:sonic-vlan/svlan:VLAN_MEMBER/svlan:VLAN_MEMBER_LIST" + 64 | "[svlan:name=current()]/svlan:ifname)]) = 0)" { 65 | error-message "Vlan and port being member of same vlan can't have same IP prefix."; 66 | } 67 | } 68 | 69 | leaf ip_prefix { 70 | mandatory true; 71 | type inet:ip-prefix; 72 | 73 | } 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-vlan-subinterface.yang: -------------------------------------------------------------------------------- 1 | module sonic-vlan-subinterface { 2 | namespace "http://github.com/Azure/sonic-vlan-subinterface"; 3 | prefix svlansub; 4 | yang-version 1.1; 5 | 6 | organization 7 | "SONiC"; 8 | 9 | contact 10 | "SONiC"; 11 | 12 | description 13 | "SONIC SUN INTERFACE VLAN"; 14 | 15 | revision 2024-03-10 { 16 | description 17 | "Initial revision."; 18 | } 19 | 20 | container sonic-vlan-subinterface { 21 | container VLAN_SUB_INTERFACE { 22 | list VLAN_SUB_INTERFACE_LIST { 23 | key "id"; 24 | 25 | leaf id { 26 | type string { 27 | pattern '(Eth([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])' + 28 | '|Eth([1-9]/(([1-9][0-9]|[1-9])|([1-9][0-9]|[1-9])/([1-9][0-9]|[1-9])))' + 29 | '|Po([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-6])' + 30 | '|PortChannel([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-6]))\.' + 31 | '(6553[0-5]|655[0-2][0-9]|654[0-9]{2}|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])' { 32 | error-message "Invalid sub-interface name"; 33 | error-app-tag interface-name-invalid; 34 | } 35 | } 36 | } 37 | } 38 | list VLAN_SUB_INTERFACE_IPADDR_LIST { 39 | key "id"; 40 | leaf id { 41 | type leafref { 42 | path "/svlansub:sonic-vlan-subinterface/svlansub:VLAN_SUB_INTERFACE/svlansub:VLAN_SUB_INTERFACE_LIST/svlansub:id"; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-vrf.yang: -------------------------------------------------------------------------------- 1 | module sonic-vrf { 2 | namespace "http://github.com/Azure/sonic-vrf"; 3 | prefix vrf; 4 | 5 | import sonic-vxlan { 6 | prefix svxlan; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC VRF"; 17 | 18 | revision 2019-10-30 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | container sonic-vrf { 24 | container VRF { 25 | description "Vrf configuration."; 26 | 27 | list VRF_LIST { 28 | key "vrf_name"; 29 | 30 | leaf vrf_name { 31 | type string; 32 | description 33 | "Vrf name for SONiC, must start with Vrf."; 34 | } 35 | 36 | leaf fallback { 37 | type boolean; 38 | default false; 39 | description 40 | "Enalbe/disable fallback feature which is useful for specified VRF user to access internet through global/main route."; 41 | } 42 | 43 | leaf vni { 44 | type uint32 { 45 | range "0..16777215" { 46 | error-message "VNI ID out of range"; 47 | error-app-tag vnid-invalid; 48 | } 49 | } 50 | 51 | must "current() = 0 or count(/svxlan:sonic-vxlan/svxlan:VXLAN_TUNNEL_MAP/svxlan:VXLAN_TUNNEL_MAP_LIST[svxlan:vni=current()]) > 0" { 52 | error-app-tag vnid-not-configured; 53 | } 54 | 55 | default 0; 56 | description 57 | "VNI mapped to VRF"; 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cvl/testdata/schema/sonic-wred-profile.yang: -------------------------------------------------------------------------------- 1 | module sonic-wred-profile { 2 | namespace "http://github.com/Azure/sonic-wred-profile"; 3 | prefix wrd; 4 | 5 | organization 6 | "SONiC"; 7 | 8 | contact 9 | "SONiC"; 10 | 11 | description 12 | "SONIC WRED_PROFILE"; 13 | 14 | revision 2019-05-15 { 15 | description 16 | "Initial revision."; 17 | } 18 | 19 | container sonic-wred-profile { 20 | 21 | container WRED_PROFILE { 22 | 23 | list WRED_PROFILE_LIST { 24 | key "name"; 25 | 26 | leaf name{ 27 | type string; 28 | } 29 | 30 | leaf yellow_min_threshold { 31 | type uint64; 32 | } 33 | 34 | leaf green_min_threshold { 35 | type uint64; 36 | } 37 | 38 | leaf red_min_threshold { 39 | type uint64; 40 | } 41 | leaf yellow_max_threshold { 42 | type uint64; 43 | } 44 | 45 | leaf green_max_threshold { 46 | type uint64; 47 | } 48 | 49 | leaf red_max_threshold { 50 | type uint64; 51 | } 52 | 53 | leaf ecn { 54 | type enumeration { 55 | enum ecn_none; 56 | enum ecn_green; 57 | enum ecn_yellow; 58 | enum ecn_red; 59 | enum ecn_green_yellow; 60 | enum ecn_green_red; 61 | enum ecn_yellow_red; 62 | enum ecn_all; 63 | } 64 | } 65 | 66 | leaf wred_green_enable { 67 | type boolean; 68 | } 69 | 70 | leaf wred_yellow_enable { 71 | type boolean; 72 | } 73 | 74 | leaf wred_red_enable { 75 | type boolean; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /cvl/tests/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 | SRC_FILES=$(wildcard *.go) 21 | OUT=$(patsubst %.go, %, $(SRC_FILES)) 22 | TOPDIR := $(abspath ../..) 23 | GO=/usr/local/go/bin/go 24 | 25 | all:tests 26 | 27 | tests: $(OUT) 28 | 29 | %:%.go 30 | make -C ../testdata/schema 31 | @echo "Building $@ ..." 32 | $(GO) build -mod=vendor -gcflags="all=-N -l" $< 33 | 34 | clean: 35 | @echo "Removing files ..." 36 | rm -rf $(OUT) 37 | -------------------------------------------------------------------------------- /cvl/tests/acl_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_TABLE": { 3 | "TestACL11": { 4 | "type": "L3", 5 | "ports": "Ethernet0" 6 | } 7 | }, 8 | "ACL_RULE": { 9 | "TestACL11|Rule1": { 10 | "PRIORITY": "55", 11 | "PACKET_ACTION": "DROP", 12 | "L4_SRC_PORT": "0" 13 | }, 14 | "TestACL11|Rule2": { 15 | "PRIORITY": "55", 16 | "PACKET_ACTION": "DROP", 17 | "L4_SRC_PORT": "1" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cvl/tests/create_acl_table.json: -------------------------------------------------------------------------------- 1 | { 2 | "ACL_TABLE": { 3 | "TestACL1": { 4 | "stage": "INGRESS", 5 | "type": "L3" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /cvl/tests/run_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | profiling="" 4 | testcase="" 5 | coverpkgs="-coverpkg=github.com/Azure/sonic-mgmt-common/cvl,github.com/Azure/sonic-mgmt-common/cvl/internal/util,github.com/Azure/sonic-mgmt-common/cvl/internal/yparser" 6 | 7 | if [ "${BUILD}:" != ":" ] ; then 8 | go test -mod=vendor -v -c -gcflags="all=-N -l" 9 | fi 10 | 11 | if [ "${TESTCASE}:" != ":" ] ; then 12 | testcase="-run ${TESTCASE}" 13 | fi 14 | 15 | if [ "${PROFILE}:" != ":" ] ; then 16 | profiling="-bench=. -benchmem -cpuprofile profile.out" 17 | fi 18 | 19 | #Run test and display report 20 | if [ "${NOREPORT}:" != ":" ] ; then 21 | go test -mod=vendor -v -tags test -cover ${coverpkgs} ${testcase} 22 | elif [ "${COVERAGE}:" != ":" ] ; then 23 | go test -mod=vendor -v -tags test -cover -coverprofile coverage.out ${coverpkgs} ${testcase} 24 | go tool cover -html=coverage.out 25 | else 26 | go test -mod=vendor -v -tags test -cover -json ${profiling} ${testcase} | tparse -smallscreen -all 27 | fi 28 | 29 | #With profiling 30 | #go test -v -cover -json -bench=. -benchmem -cpuprofile profile.out | tparse -smallscreen -all 31 | 32 | -------------------------------------------------------------------------------- /debian/.gitignore: -------------------------------------------------------------------------------- 1 | .debhelper/ 2 | *.debhelper 3 | *.debhelper.log 4 | *.substvars 5 | sonic-mgmt-common/ 6 | sonic-mgmt-common-codegen/ 7 | sonic-host-service/ 8 | tmp/ 9 | files 10 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | sonic-mgmt-common (1.0.0) UNRELEASED; urgency=low 2 | 3 | * Initial release. 4 | 5 | -- Sachin Holla Fri, 03 Apr 2020 00:00:00 +0000 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: sonic-mgmt-common 2 | Maintainer: Sachin Holla 3 | Build-Depends: debhelper (>= 8.0.0), 4 | dh-systemd 5 | | debhelper (>= 9.20160709) 6 | Vcs-Git: https://github.com/Azure/sonic-mgmt-common 7 | Homepage: https://github.com/Azure/SONiC/ 8 | Standards-Version: 3.9.3 9 | Section: net 10 | 11 | Package: sonic-mgmt-common 12 | Priority: extra 13 | Architecture: any 14 | Depends: ${shlibs:Depends}, ${misc:Depends} 15 | Description: SONiC Management Infrastructure 16 | 17 | Package: sonic-mgmt-common-codegen 18 | Priority: extra 19 | Architecture: any 20 | Depends: ${shlibs:Depends}, ${misc:Depends} 21 | Description: SONiC Management Infrastructure generated code 22 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ --with systemd --parallel 4 | 5 | -------------------------------------------------------------------------------- /debian/sonic-mgmt-common-codegen.install: -------------------------------------------------------------------------------- 1 | translib/ocbinds/ocbinds.go sonic/src/sonic-mgmt-common/translib/ocbinds 2 | models/yang/allyangs.tree sonic/src/sonic-mgmt-common/models/yang 3 | models/yang/allyangs_tree.html sonic/src/sonic-mgmt-common/models/yang 4 | models/yang/sonic_allyangs.tree sonic/src/sonic-mgmt-common/models/yang 5 | models/yang/sonic_allyangs_tree.html sonic/src/sonic-mgmt-common/models/yang 6 | build/yang sonic/src/sonic-mgmt-common/build 7 | -------------------------------------------------------------------------------- /debian/sonic-mgmt-common-codegen.postinst: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd sonic/src/sonic-mgmt-common 6 | 7 | GITUSER=$(stat -c "%u:%g" .) 8 | 9 | GENSRC+=( build ) 10 | GENSRC+=( $(awk '/^build\//{next} /^[^#]/{print $1}' < debian/sonic-mgmt-common-codegen.install) ) 11 | 12 | for F in "${GENSRC[@]}"; do chown -vR ${GITUSER} "$F"; done 13 | 14 | -------------------------------------------------------------------------------- /debian/sonic-mgmt-common.install: -------------------------------------------------------------------------------- 1 | # Yang models 2 | build/yang/*.yang usr/models/yang 3 | build/yang/common/*.yang usr/models/yang 4 | build/yang/extensions/*.yang usr/models/yang 5 | build/yang/sonic/*.yang usr/models/yang 6 | build/yang/sonic/common/*.yang usr/models/yang 7 | build/yang/annotations/*.yang usr/models/yang 8 | build/transformer/models_list usr/models/yang 9 | models/yang/version.xml usr/models/yang 10 | 11 | # CVL files 12 | build/cvl/schema usr/sbin 13 | cvl/conf/cvl_cfg.json usr/sbin 14 | 15 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Azure/sonic-mgmt-common 2 | 3 | require ( 4 | github.com/Workiva/go-datastructures v1.0.50 5 | github.com/antchfx/jsonquery v1.1.4 6 | github.com/antchfx/xmlquery v1.3.1 7 | github.com/antchfx/xpath v1.1.10 8 | github.com/go-redis/redis/v7 v7.0.0-beta.3.0.20190824101152-d19aba07b476 9 | github.com/godbus/dbus/v5 v5.1.0 10 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b 11 | github.com/google/go-cmp v0.4.0 12 | github.com/kylelemons/godebug v1.1.0 13 | github.com/maruel/natural v1.1.1 14 | github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 15 | github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc 16 | github.com/openconfig/ygot v0.7.1 17 | github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f 18 | github.com/pkg/profile v1.7.0 19 | golang.org/x/text v0.3.3 20 | google.golang.org/grpc v1.28.0 21 | inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a 22 | ) 23 | 24 | require ( 25 | github.com/felixge/fgprof v0.9.3 // indirect 26 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect 27 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0 // indirect 28 | github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect 29 | go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect 30 | go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect 31 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 32 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect 33 | google.golang.org/genproto v0.0.0-20200319113533-08878b785e9c // indirect 34 | google.golang.org/protobuf v1.21.0 // indirect 35 | ) 36 | 37 | go 1.19 38 | -------------------------------------------------------------------------------- /models/yang/.gitignore: -------------------------------------------------------------------------------- 1 | *tree.html 2 | *_tree.md 3 | *.tree 4 | .annots_checked 5 | -------------------------------------------------------------------------------- /models/yang/README.md: -------------------------------------------------------------------------------- 1 | # YANG directory 2 | 3 | ## Directory structure 4 | 5 | yang/ --> Standard YANGs 6 | |-- annotations/ --> Transformer annotations 7 | |-- common/ --> Dependencies for standard YANGs 8 | |-- extensions/ --> Extenstions for standard YANGs 9 | |-- sonic/ --> SONiC yangs 10 | |-- testdata/ --> Test YANGs - ignored 11 | `-- version.xml --> YANG bundle version configuration file 12 | 13 | All supported standard YANG files (OpenConfig and IETF) are kept in this **yang** directory. Usual practice is to keep only top level YANG module here and keep dependent YANGs, submodules in **yang/common** directory. 14 | 15 | Example: openconfig-platform.yang is kept in top **yang** directory and openconfig-platform-types.yang in **yang/common** directory. 16 | 17 | All extenstion YANGs **MUST** be kept in **yang/extensions** directory. 18 | 19 | ## version.xml 20 | 21 | version.xml file maintains the yang bundle version number in **Major.Minor.Patch** format. 22 | It is the collective version number for all the YANG modules defined here. 23 | **UPDATE THIS VERSION NUMBER FOR EVERY YANG CHANGE.** 24 | 25 | **Major version** should be incremented if YANG model is changed in a non backward compatible manner. 26 | Such changes should be avoided. 27 | 28 | * Delete, rename or relocate data node 29 | * Change list key attributes 30 | * Change data type of a node to an incompatible type 31 | * Change leafref target 32 | 33 | **Minor version** should be incremented if the YANG change modifies the API in a backward 34 | compatible way. Patch version should be reset to 0. 35 | Candidate YANG changes for this category are: 36 | 37 | * Add new YANG module 38 | * Add new YANG data nodes 39 | * Mark a YANG data node as deprecated 40 | * Change data type of a node to a compatible type 41 | * Add new enum or identity 42 | 43 | **Patch version** should incremented for cosmetic fixes that do not change YANG API. 44 | Candidate YANG changes for this category are: 45 | 46 | * Change description, beautification. 47 | * Expand pattern or range of a node to wider set. 48 | * Change must expression to accept more cases. 49 | * Error message or error tag changes. 50 | 51 | 52 | -------------------------------------------------------------------------------- /models/yang/annotations/openconfig-sampling-sflow-annot.yang: -------------------------------------------------------------------------------- 1 | module openconfig-sampling-sflow-annot { 2 | 3 | yang-version "1"; 4 | 5 | namespace "http://openconfig.net/yang/annotation/oc-sampling-sflow-annot"; 6 | prefix "oc-sampling-annot"; 7 | 8 | import openconfig-extensions { prefix oc-ext; } 9 | import openconfig-sampling-sflow { prefix oc-sampling; } 10 | import sonic-extensions { prefix sonic-ext; } 11 | 12 | deviation /oc-sampling:sampling/oc-sampling:sflow { 13 | deviate add { 14 | sonic-ext:subtree-transformer "sflow_xfmr"; 15 | } 16 | } 17 | 18 | 19 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:collectors { 20 | deviate add { 21 | sonic-ext:subtree-transformer "sflow_collector_xfmr"; 22 | sonic-ext:path-transformer "sflow_collector_path_xfmr"; 23 | } 24 | } 25 | 26 | 27 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:interfaces { 28 | deviate add { 29 | sonic-ext:subtree-transformer "sflow_interface_xfmr"; 30 | sonic-ext:path-transformer "sflow_interface_path_xfmr"; 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /models/yang/annotations/sonic-showtech-annot.yang: -------------------------------------------------------------------------------- 1 | module sonic-showtech-annot { 2 | 3 | yang-version "1"; 4 | 5 | namespace "http://openconfig.net/Azure/sonic-showtech-annot"; 6 | prefix "showtech-annot"; 7 | 8 | import sonic-extensions { prefix sonic-ext; } 9 | import sonic-show-techsupport { prefix sshwtchspt; } 10 | 11 | deviation /sshwtchspt:sonic-show-techsupport-info { 12 | deviate add { 13 | sonic-ext:rpc-callback "rpc_showtech_cb"; 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /models/yang/common/openconfig-if-poe.yang: -------------------------------------------------------------------------------- 1 | module openconfig-if-poe { 2 | 3 | yang-version "1"; 4 | 5 | namespace "http://openconfig.net/yang/poe"; 6 | 7 | prefix "oc-poe"; 8 | 9 | import openconfig-if-ethernet { prefix oc-eth; } 10 | import openconfig-interfaces { prefix oc-if; } 11 | import openconfig-extensions { prefix oc-ext; } 12 | 13 | organization "OpenConfig working group"; 14 | 15 | contact 16 | "Openconfig working group 17 | www.openconfig.net"; 18 | 19 | description 20 | "This module defines configuration and state data for 21 | Power over Ethernet (PoE) based on the IEEE 802.3af 22 | standard."; 23 | 24 | oc-ext:openconfig-version "0.1.1"; 25 | 26 | revision "2018-11-21" { 27 | description 28 | "Add OpenConfig module metadata extensions."; 29 | reference "0.1.1"; 30 | } 31 | 32 | revision "2017-09-14" { 33 | description 34 | "Initial public revision"; 35 | reference "0.1.0"; 36 | } 37 | 38 | // OpenConfig specific extensions for module metadata. 39 | oc-ext:regexp-posix; 40 | oc-ext:catalog-organization "openconfig"; 41 | oc-ext:origin "openconfig"; 42 | 43 | grouping poe-ethernet-config { 44 | description 45 | "PoE ethernet config grouping"; 46 | 47 | leaf enabled { 48 | type boolean; 49 | default "true"; 50 | description 51 | "Enable or disable PoE in the ethernet interface."; 52 | } 53 | } 54 | 55 | grouping poe-ethernet-state { 56 | description 57 | "PoE ethernet state grouping"; 58 | 59 | leaf power-used { 60 | type decimal64 { 61 | fraction-digits 2; 62 | } 63 | units Watts; 64 | description 65 | "Power used by the ethernet interface in Watts."; 66 | } 67 | 68 | leaf power-class { 69 | type uint8; 70 | description 71 | "IEEE 802.3af Power class detected for this ethernet 72 | interface."; 73 | } 74 | } 75 | 76 | grouping poe-ethernet-top { 77 | description 78 | "Ethernet top level grouping"; 79 | 80 | container poe { 81 | description 82 | "Top-level container for PoE configuration and state data"; 83 | 84 | container config { 85 | description 86 | "Configuration data for PoE"; 87 | 88 | uses poe-ethernet-config; 89 | } 90 | 91 | container state { 92 | config false; 93 | 94 | description 95 | "Operational state data for PoE"; 96 | 97 | uses poe-ethernet-config; 98 | uses poe-ethernet-state; 99 | } 100 | } 101 | } 102 | 103 | augment "/oc-if:interfaces/oc-if:interface/oc-eth:ethernet" { 104 | description 105 | "Adds PoE to the ethernet model."; 106 | 107 | uses poe-ethernet-top; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /models/yang/common/openconfig-if-types.yang: -------------------------------------------------------------------------------- 1 | module openconfig-if-types { 2 | yang-version "1"; 3 | 4 | namespace "http://openconfig.net/yang/openconfig-if-types"; 5 | 6 | prefix "oc-ift"; 7 | 8 | // import statements 9 | import openconfig-extensions { prefix oc-ext; } 10 | 11 | // meta 12 | organization 13 | "OpenConfig working group"; 14 | 15 | contact 16 | "OpenConfig working group 17 | netopenconfig@googlegroups.com"; 18 | 19 | description 20 | "This module contains a set of interface type definitions that 21 | are used across OpenConfig models. These are generally physical 22 | or logical interfaces, distinct from hardware ports (which are 23 | described by the OpenConfig platform model)."; 24 | 25 | oc-ext:openconfig-version "0.2.1"; 26 | 27 | revision "2018-11-21" { 28 | description 29 | "Add OpenConfig module metadata extensions."; 30 | reference "0.2.1"; 31 | } 32 | 33 | revision "2018-01-05" { 34 | description 35 | "Add tunnel types into the INTERFACE_TYPE identity."; 36 | reference "0.2.0"; 37 | } 38 | 39 | revision "2016-11-14" { 40 | description 41 | "Initial version"; 42 | reference "0.1.0"; 43 | } 44 | 45 | // OpenConfig specific extensions for module metadata. 46 | oc-ext:regexp-posix; 47 | oc-ext:catalog-organization "openconfig"; 48 | oc-ext:origin "openconfig"; 49 | 50 | identity INTERFACE_TYPE { 51 | description 52 | "Base identity from which interface types are derived."; 53 | } 54 | 55 | identity IF_ETHERNET { 56 | base INTERFACE_TYPE; 57 | description 58 | "Ethernet interfaces based on IEEE 802.3 standards, as well 59 | as FlexEthernet"; 60 | reference 61 | "IEEE 802.3-2015 - IEEE Standard for Ethernet 62 | OIF Flex Ethernet Implementation Agreement 1.0"; 63 | } 64 | 65 | identity IF_AGGREGATE { 66 | base INTERFACE_TYPE; 67 | description 68 | "An aggregated, or bonded, interface forming a 69 | Link Aggregation Group (LAG), or bundle, most often based on 70 | the IEEE 802.1AX (or 802.3ad) standard."; 71 | reference 72 | "IEEE 802.1AX-2008"; 73 | } 74 | 75 | identity IF_LOOPBACK { 76 | base INTERFACE_TYPE; 77 | description 78 | "A virtual interface designated as a loopback used for 79 | various management and operations tasks."; 80 | } 81 | 82 | identity IF_ROUTED_VLAN { 83 | base INTERFACE_TYPE; 84 | description 85 | "A logical interface used for routing services on a VLAN. 86 | Such interfaces are also known as switch virtual interfaces 87 | (SVI) or integrated routing and bridging interfaces (IRBs)."; 88 | } 89 | 90 | identity IF_SONET { 91 | base INTERFACE_TYPE; 92 | description 93 | "SONET/SDH interface"; 94 | } 95 | 96 | identity IF_TUNNEL_GRE4 { 97 | base INTERFACE_TYPE; 98 | description 99 | "A GRE tunnel over IPv4 transport."; 100 | } 101 | 102 | identity IF_TUNNEL_GRE6 { 103 | base INTERFACE_TYPE; 104 | description 105 | "A GRE tunnel over IPv6 transport."; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /models/yang/extensions/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-common/bb0e47d3e6eb98a27b386636da91a7bfb4ecefbc/models/yang/extensions/.gitkeep -------------------------------------------------------------------------------- /models/yang/extensions/openconfig-sampling-sflow-deviation.yang: -------------------------------------------------------------------------------- 1 | module openconfig-sampling-sflow-deviation { 2 | 3 | yang-version "1.1"; 4 | 5 | // namespace 6 | namespace "http://openconfig.net/yang/sampling/sflow/deviation/extension"; 7 | 8 | prefix "oc-sampling-sflow-dev"; 9 | 10 | import openconfig-extensions { prefix "oc-ext"; } 11 | import openconfig-sampling-sflow { prefix oc-sampling; } 12 | 13 | organization "SONiC"; 14 | contact 15 | "SONiC"; 16 | description 17 | "This is a deviation yang for openconfig sampling model."; 18 | 19 | oc-ext:openconfig-version "0.1.0"; 20 | 21 | revision 2020-06-23 { 22 | description 23 | "Initial version."; 24 | reference "0.1.0"; 25 | } 26 | 27 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:config/oc-sampling:source-address { 28 | deviate not-supported; 29 | } 30 | 31 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:config/oc-sampling:sample-size { 32 | deviate not-supported; 33 | } 34 | 35 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:config/oc-sampling:sampling-rate { 36 | deviate not-supported; 37 | } 38 | 39 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:interfaces/oc-sampling:interface/oc-sampling:state/oc-sampling:packets-sampled { 40 | deviate not-supported; 41 | } 42 | 43 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:state/oc-sampling:source-address { 44 | deviate not-supported; 45 | } 46 | 47 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:state/oc-sampling:sample-size { 48 | deviate not-supported; 49 | } 50 | 51 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:state/oc-sampling:sampling-rate { 52 | deviate not-supported; 53 | } 54 | 55 | deviation /oc-sampling:sampling/oc-sampling:sflow/oc-sampling:collectors/oc-sampling:collector/oc-sampling:state/oc-sampling:packets-sent { 56 | deviate not-supported; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /models/yang/lint_ignore.ietf: -------------------------------------------------------------------------------- 1 | # Sample file, commented lines will be ignored 2 | #module-name line-number(optional) 3 | #ietf-interfaces #ignores all errors in the specified module 4 | #ietf-interfaces 1 10 20 #ignores errors at specificied line numbers alone 5 | -------------------------------------------------------------------------------- /models/yang/lint_ignore.ocstyle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-common/bb0e47d3e6eb98a27b386636da91a7bfb4ecefbc/models/yang/lint_ignore.ocstyle -------------------------------------------------------------------------------- /models/yang/sonic/common/sonic-common.yang: -------------------------------------------------------------------------------- 1 | 2 | module sonic-common { 3 | namespace "http://github.com/Azure/sonic-common"; 4 | prefix cmn; 5 | 6 | organization 7 | "SONiC"; 8 | 9 | contact 10 | "SONiC"; 11 | 12 | description 13 | "SONIC common definitions"; 14 | 15 | revision 2019-05-15 { 16 | description 17 | "Initial revision."; 18 | } 19 | 20 | typedef tagging_mode { 21 | type enumeration { 22 | enum untagged; 23 | enum tagged; 24 | enum priority_tagged; 25 | } 26 | } 27 | 28 | typedef admin-status { 29 | type enumeration { 30 | enum up; 31 | enum down; 32 | } 33 | } 34 | 35 | typedef oper-status { 36 | type enumeration { 37 | enum up; 38 | enum down; 39 | } 40 | } 41 | 42 | 43 | container operation { 44 | description "This definition is used internally by CVL and 45 | is not exposed in NBI. Leaf 'operation' allows 46 | evaluation of must expression for CREATE/UPDATE/DELETE 47 | operation."; 48 | 49 | leaf operation { 50 | type enumeration { 51 | enum NOP; 52 | enum CREATE; 53 | enum UPDATE; 54 | enum DELETE; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /models/yang/sonic/common/sonic-extension.yang: -------------------------------------------------------------------------------- 1 | 2 | module sonic-extension { 3 | namespace "http://github.com/Azure/sonic-extension"; 4 | prefix sonic-ext; 5 | 6 | organization 7 | "SONiC"; 8 | 9 | contact 10 | "SONiC"; 11 | 12 | description 13 | "SONIC Extension"; 14 | 15 | revision 2019-09-18 { 16 | description 17 | "Initial revision."; 18 | } 19 | 20 | extension db-name { 21 | description 22 | "DB name, e.g. APPL_DB, CONFIG_DB"; 23 | argument "value"; 24 | } 25 | 26 | extension key-delim { 27 | description 28 | "Key delimeter, e.g. - |, :"; 29 | argument "value"; 30 | } 31 | 32 | extension key-pattern { 33 | description 34 | "Key pattern, e.g. - ACL_RULE|{aclname}|{rulename}"; 35 | argument "value"; 36 | } 37 | 38 | extension map-list { 39 | description 40 | "If it is a map list"; 41 | argument "value"; 42 | } 43 | 44 | extension map-leaf { 45 | description 46 | "Map leaf names"; 47 | argument "value"; 48 | } 49 | 50 | extension custom-validation { 51 | description 52 | "Extension for custom validation. 53 | Platform specific validation can be implemented using custom validation."; 54 | argument "handler"; 55 | } 56 | 57 | extension dependent-on { 58 | description 59 | "Entension to define dependency on other table. So during create/update, 60 | operation will be performed first on parent table and then on this table. 61 | In delete operation, this table will be deleted first and then parent table. 62 | This extension can be defined only under list. Table name should always 63 | suffixed with '_LIST' as modeled in yang. 64 | e.g. - dependent-on STP_LIST"; 65 | argument "value"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /models/yang/sonic/import.mk: -------------------------------------------------------------------------------- 1 | 2 | ## 3 | # SONICYANG_IMPORTS is the list of sonic yang files to be copied 4 | # from SONICYANG_IMPORT_DIR. Only the file basenames (like sonic-sflow.yang) 5 | # or glob patterns of basenames (like sonic-telemetry*.yang) can be specified. 6 | # Other sonic yangs referred by these will also be copied. 7 | # 8 | SONICYANG_IMPORTS += sonic-sflow.yang 9 | SONICYANG_IMPORTS += sonic-interface.yang 10 | SONICYANG_IMPORTS += sonic-port.yang 11 | SONICYANG_IMPORTS += sonic-portchannel.yang 12 | SONICYANG_IMPORTS += sonic-mclag.yang 13 | SONICYANG_IMPORTS += sonic-types.yang 14 | SONICYANG_IMPORTS += sonic-vrf.yang -------------------------------------------------------------------------------- /models/yang/sonic/sonic-interface.yang: -------------------------------------------------------------------------------- 1 | module sonic-interface { 2 | namespace "http://github.com/Azure/sonic-interface"; 3 | prefix sint; 4 | 5 | import ietf-inet-types { 6 | prefix inet; 7 | } 8 | 9 | import sonic-port { 10 | prefix prt; 11 | } 12 | 13 | organization 14 | "SONiC"; 15 | 16 | contact 17 | "SONiC"; 18 | 19 | description 20 | "SONIC INTERFACE"; 21 | 22 | revision 2019-07-02 { 23 | description 24 | "Initial revision."; 25 | } 26 | 27 | container sonic-interface { 28 | 29 | container INTERFACE { 30 | 31 | list INTERFACE_LIST { 32 | key "portname"; 33 | 34 | leaf portname{ 35 | type leafref { 36 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 37 | } 38 | } 39 | 40 | /* Add a leafref, once VRF YANG is supported 41 | leaf vrf-name { 42 | type string { 43 | pattern 'Vrf([-a-zA-Z0-9_]{1,60})' { 44 | error-app-tag vrf-name-invalid; 45 | } 46 | } 47 | } 48 | */ 49 | 50 | } 51 | 52 | list INTERFACE_IPADDR_LIST { 53 | key "portname ip_prefix"; 54 | 55 | leaf portname{ 56 | type leafref { 57 | path "/prt:sonic-port/prt:PORT/prt:PORT_LIST/prt:ifname"; 58 | } 59 | } 60 | 61 | leaf ip_prefix { 62 | type inet:ip-prefix; 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /models/yang/sonic/sonic-port.yang: -------------------------------------------------------------------------------- 1 | module sonic-port { 2 | namespace "http://github.com/Azure/sonic-port"; 3 | prefix prt; 4 | 5 | import sonic-common { 6 | prefix cmn; 7 | } 8 | 9 | organization 10 | "SONiC"; 11 | 12 | contact 13 | "SONiC"; 14 | 15 | description 16 | "SONIC VLAN"; 17 | 18 | revision 2019-05-15 { 19 | description 20 | "Initial revision."; 21 | } 22 | 23 | 24 | container sonic-port { 25 | 26 | container PORT { 27 | 28 | list PORT_LIST { 29 | key "ifname"; 30 | 31 | leaf ifname { 32 | type string { 33 | pattern "Ethernet([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])" { 34 | error-message "Invalid interface name"; 35 | error-app-tag interface-name-invalid; 36 | } 37 | } 38 | } 39 | 40 | leaf index { 41 | type uint16; 42 | mandatory true; 43 | 44 | } 45 | 46 | leaf speed { 47 | type uint64 { 48 | range "1000|10000|25000|40000|50000|100000|400000" { 49 | error-message "Invalid Ethernet interface speed"; 50 | error-app-tag port-speed-invalid; 51 | } 52 | } 53 | } 54 | 55 | leaf valid_speeds { 56 | type string; 57 | } 58 | 59 | leaf alias { 60 | type string { 61 | pattern '[ -~]{0,64}'; 62 | } 63 | } 64 | 65 | leaf description { 66 | type string { 67 | pattern '[ -~]{0,64}'; 68 | } 69 | } 70 | 71 | leaf mtu{ 72 | type uint32 { 73 | range "1312..9216" { 74 | error-message "Invalid MTU value"; 75 | error-app-tag mtu-invalid; 76 | } 77 | } 78 | default 9100; 79 | } 80 | 81 | leaf lanes { 82 | type string; 83 | mandatory true; 84 | } 85 | 86 | leaf admin_status { 87 | type cmn:admin-status; 88 | default "down"; 89 | } 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /models/yang/sonic/sonic-show-techsupport.yang: -------------------------------------------------------------------------------- 1 | module sonic-show-techsupport { 2 | namespace "http://github.com/Azure/sonic-show-techsupport"; 3 | prefix sshwtchspt; 4 | yang-version 1.1; 5 | 6 | import ietf-yang-types { 7 | prefix yang; 8 | } 9 | 10 | organization 11 | "SONiC"; 12 | 13 | contact 14 | "SONiC"; 15 | 16 | description 17 | "SONiC TECH SUPPORT INFORMATION"; 18 | 19 | revision 2019-10-15 { 20 | description 21 | "Initial revision."; 22 | } 23 | 24 | rpc sonic-show-techsupport-info { 25 | input { 26 | leaf date { 27 | type yang:date-and-time; 28 | description 29 | "Date and time specification of the desired start 30 | point for collected log and core information"; 31 | } 32 | } 33 | output { 34 | leaf output-status { 35 | type string; 36 | description 37 | "'Success' or detailed failure message for execution of the 38 | 'show tech-support' request"; 39 | } 40 | leaf output-filename { 41 | type string; 42 | description 43 | "Name of the host compressed tar file containing the collected 44 | technical support information"; 45 | } 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /models/yang/version.xml: -------------------------------------------------------------------------------- 1 | 2 | 29 | 30 | 1 31 | 0 32 | 0 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /patches/apply.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | PATCH_DIR=$(dirname $(realpath ${BASH_SOURCE[0]})) 6 | 7 | DEST_DIR=vendor 8 | [ ! -z $1 ] && DEST_DIR=$1 9 | 10 | if [ ! -d "${DEST_DIR}" ]; then 11 | echo "Unknown DEST_DIR \"${DEST_DIR}\"" 12 | exit 1 13 | fi 14 | 15 | # Copy some of the packages from go mod download directory into vendor directory. 16 | # It is a workaround for 'go mod vendor' not copying all files 17 | 18 | [ -z ${GO} ] && GO=go 19 | [ -z ${GOPATH} ] && GOPATH=$(${GO} env GOPATH) 20 | PKGPATH=$(echo ${GOPATH} | sed 's/:.*$//g')/pkg/mod 21 | 22 | # Copy package files from GOPATH/pkg/mod to vendor 23 | # $1 = package name, $2 = version, $3... = files 24 | function copy() { 25 | for FILE in "${@:3}"; do 26 | rsync -r --chmod=u+w --exclude=testdata --exclude=*_test.go \ 27 | ${PKGPATH}/$1@$2/${FILE} ${DEST_DIR}/$1/ 28 | done 29 | } 30 | 31 | set -x 32 | 33 | copy github.com/openconfig/ygot v0.7.1 ygen genutil generator 34 | 35 | copy github.com/openconfig/goyang v0.0.0-20200309174518-a00bece872fc . 36 | 37 | copy github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 . 38 | 39 | # Apply patches 40 | 41 | patch -d ${DEST_DIR}/github.com/openconfig/ygot -p1 < ${PATCH_DIR}/ygot/ygot.patch 42 | 43 | patch -d ${DEST_DIR}/github.com/openconfig/goyang -p1 < ${PATCH_DIR}/goyang/goyang.patch 44 | 45 | patch -d ${DEST_DIR}/github.com/antchfx/jsonquery -p1 < ${PATCH_DIR}/jsonquery.patch 46 | patch -d ${DEST_DIR}/github.com/antchfx/xmlquery -p1 < ${PATCH_DIR}/xmlquery.patch 47 | patch -d ${DEST_DIR}/github.com/antchfx/xpath -p1 < ${PATCH_DIR}/xpath.patch 48 | 49 | patch -d ${DEST_DIR}/github.com/golang/glog -p1 < ${PATCH_DIR}/glog.patch 50 | 51 | -------------------------------------------------------------------------------- /patches/glog.patch: -------------------------------------------------------------------------------- 1 | diff --git a/glog.go b/glog.go 2 | index 54bd7af..dccc3c7 100644 3 | --- a/glog.go 4 | +++ b/glog.go 5 | @@ -677,7 +677,7 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo 6 | } 7 | data := buf.Bytes() 8 | if !flag.Parsed() { 9 | - os.Stderr.Write([]byte("ERROR: logging before flag.Parse: ")) 10 | + //os.Stderr.Write([]byte("ERROR: logging before flag.Parse: ")) 11 | os.Stderr.Write(data) 12 | } else if l.toStderr { 13 | os.Stderr.Write(data) 14 | -------------------------------------------------------------------------------- /patches/jsonquery.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node.go b/node.go 2 | index 4b28b32..afeed80 100644 3 | --- a/node.go 4 | +++ b/node.go 5 | @@ -8,6 +8,7 @@ import ( 6 | "net/http" 7 | "sort" 8 | "strconv" 9 | + "strings" 10 | ) 11 | 12 | // A NodeType is the type of a Node. 13 | @@ -143,6 +144,29 @@ func parseValue(x interface{}, top *Node, level int) { 14 | addNode(n) 15 | parseValue(vv, n, level+1) 16 | } 17 | + case map[string]string: 18 | + var keys []string 19 | + for key := range v { 20 | + keys = append(keys, key) 21 | + } 22 | + sort.Strings(keys) 23 | + for _, key := range keys { 24 | + tmpKey := key 25 | + var tmpVal interface{} 26 | + tmpVal = v[key] 27 | + if (strings.HasSuffix(key, "@")) { 28 | + tmpKey = key[:len(key) - 1] 29 | + tmpValArr := []interface{}{} 30 | + for _, val := range strings.Split(v[key], ",") { 31 | + tmpValArr = append(tmpValArr, val) 32 | + } 33 | + tmpVal = tmpValArr 34 | + } 35 | + 36 | + n := &Node{Data: tmpKey, Type: ElementNode, level: level} 37 | + addNode(n) 38 | + parseValue(tmpVal, n, level+1) 39 | + } 40 | case map[string]interface{}: 41 | // The Go’s map iteration order is random. 42 | // (https://blog.golang.org/go-maps-in-action#Iteration-order) 43 | @@ -152,9 +176,21 @@ func parseValue(x interface{}, top *Node, level int) { 44 | } 45 | sort.Strings(keys) 46 | for _, key := range keys { 47 | - n := &Node{Data: key, Type: ElementNode, level: level} 48 | + tmpKey := key 49 | + var tmpVal interface{} 50 | + tmpVal = v[key] 51 | + if (strings.HasSuffix(key, "@")) { 52 | + tmpKey = key[:len(key) - 1] 53 | + tmpValArr := []interface{}{} 54 | + for _, val := range strings.Split(v[key].(string), ",") { 55 | + tmpValArr = append(tmpValArr, val) 56 | + } 57 | + tmpVal = tmpValArr 58 | + } 59 | + 60 | + n := &Node{Data: tmpKey, Type: ElementNode, level: level} 61 | addNode(n) 62 | - parseValue(v[key], n, level+1) 63 | + parseValue(tmpVal, n, level+1) 64 | } 65 | case string: 66 | n := &Node{Data: v, Type: TextNode, level: level} 67 | @@ -188,3 +224,9 @@ func Parse(r io.Reader) (*Node, error) { 68 | } 69 | return parse(b) 70 | } 71 | + 72 | +func ParseJsonMap(jsonMap *map[string]interface{}) (*Node, error) { 73 | + doc := &Node{Type: DocumentNode} 74 | + parseValue(*jsonMap, doc, 1) 75 | + return doc, nil 76 | +} 77 | diff --git a/query.go b/query.go 78 | index 6421801..e3df27a 100644 79 | --- a/query.go 80 | +++ b/query.go 81 | @@ -120,6 +120,14 @@ func (a *NodeNavigator) MoveToRoot() { 82 | a.cur = a.root 83 | } 84 | 85 | +func (a *NodeNavigator) MoveToContext() { 86 | + return 87 | +} 88 | + 89 | +func (a *NodeNavigator) CurrentPrefix() string { 90 | + return "" 91 | +} 92 | + 93 | func (a *NodeNavigator) MoveToParent() bool { 94 | if n := a.cur.Parent; n != nil { 95 | a.cur = n 96 | -------------------------------------------------------------------------------- /patches/xmlquery.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node.go b/node.go 2 | index e053748..1c9a529 100644 3 | --- a/node.go 4 | +++ b/node.go 5 | @@ -45,7 +45,7 @@ type Node struct { 6 | 7 | // InnerText returns the text between the start and end tags of the object. 8 | func (n *Node) InnerText() string { 9 | - var output func(*bytes.Buffer, *Node) 10 | + /*var output func(*bytes.Buffer, *Node) 11 | output = func(buf *bytes.Buffer, n *Node) { 12 | switch n.Type { 13 | case TextNode, CharDataNode: 14 | @@ -60,7 +60,18 @@ func (n *Node) InnerText() string { 15 | 16 | var buf bytes.Buffer 17 | output(&buf, n) 18 | - return buf.String() 19 | + return buf.String()*/ 20 | + 21 | + if (n.Type == TextNode) { 22 | + return n.Data 23 | + } else if (n.Type == ElementNode) && 24 | + (n.FirstChild != nil) && 25 | + (n.FirstChild.Type == TextNode) { 26 | + return n.FirstChild.Data 27 | + } 28 | + 29 | + 30 | + return "" 31 | } 32 | 33 | func (n *Node) sanitizedData(preserveSpaces bool) string { 34 | diff --git a/query.go b/query.go 35 | index c148e5f..4ac76af 100644 36 | --- a/query.go 37 | +++ b/query.go 38 | @@ -49,6 +49,29 @@ func CreateXPathNavigator(top *Node) *NodeNavigator { 39 | return &NodeNavigator{curr: top, root: top, attr: -1} 40 | } 41 | 42 | +//Evaluate XPath expression, the expression should evaluate to true or false 43 | +func Eval(top, ctx *Node, exp *xpath.Expr) bool { 44 | + if exp == nil { 45 | + return false 46 | + } 47 | + 48 | + v := exp.Evaluate(&NodeNavigator{curr: ctx, ctxt: ctx, root: top, attr: -1}) 49 | + 50 | + switch val := v.(type) { 51 | + case bool: 52 | + return val 53 | + case string: 54 | + return (val != "") 55 | + case float64: 56 | + return (val != 0) 57 | + case *xpath.NodeIterator: 58 | + return (val != nil) 59 | + } 60 | + 61 | + //return v.(bool) 62 | + return false 63 | +} 64 | + 65 | func getCurrentNode(it *xpath.NodeIterator) *Node { 66 | n := it.Current().(*NodeNavigator) 67 | if n.NodeType() == xpath.AttributeNode { 68 | @@ -146,7 +169,7 @@ func FindEachWithBreak(top *Node, expr string, cb func(int, *Node) bool) { 69 | } 70 | 71 | type NodeNavigator struct { 72 | - root, curr *Node 73 | + root, curr, ctxt *Node 74 | attr int 75 | } 76 | 77 | @@ -217,6 +240,17 @@ func (x *NodeNavigator) MoveToRoot() { 78 | x.curr = x.root 79 | } 80 | 81 | +func (x *NodeNavigator) MoveToContext() { 82 | + x.curr = x.ctxt 83 | +} 84 | + 85 | +func (x *NodeNavigator) CurrentPrefix() string { 86 | + if (x.ctxt != nil) { 87 | + return x.ctxt.Prefix 88 | + } 89 | + return "" 90 | +} 91 | + 92 | func (x *NodeNavigator) MoveToParent() bool { 93 | if x.attr != -1 { 94 | x.attr = -1 95 | -------------------------------------------------------------------------------- /tools/test/database_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "INSTANCES": { 3 | "redis":{ 4 | "hostname" : "127.0.0.1", 5 | "port" : 6379 6 | } 7 | }, 8 | "DATABASES" : { 9 | "APPL_DB" : { 10 | "id" : 0, 11 | "separator": ":", 12 | "instance" : "redis" 13 | }, 14 | "ASIC_DB" : { 15 | "id" : 1, 16 | "separator": ":", 17 | "instance" : "redis" 18 | }, 19 | "COUNTERS_DB" : { 20 | "id" : 2, 21 | "separator": ":", 22 | "instance" : "redis" 23 | }, 24 | "CONFIG_DB" : { 25 | "id" : 4, 26 | "separator": "|", 27 | "instance" : "redis" 28 | }, 29 | "PFC_WD_DB" : { 30 | "id" : 5, 31 | "separator": ":", 32 | "instance" : "redis" 33 | }, 34 | "FLEX_COUNTER_DB" : { 35 | "id" : 5, 36 | "separator": ":", 37 | "instance" : "redis" 38 | }, 39 | "STATE_DB" : { 40 | "id" : 6, 41 | "separator": "|", 42 | "instance" : "redis" 43 | }, 44 | "SNMP_OVERLAY_DB" : { 45 | "id" : 7, 46 | "separator": "|", 47 | "instance" : "redis" 48 | } 49 | }, 50 | "VERSION" : "1.0" 51 | } 52 | -------------------------------------------------------------------------------- /tools/test/env.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function usage() { 4 | cat << EOM 5 | usage: $(basename $0) [OPTIONS] 6 | 7 | Options: 8 | --dest=DIR Copy yang and othermgmt_cmn files here. Creates a temporary directorty 9 | if not specified. 10 | --dbconfig-in=FILE Copy the database_config.json file from this file. 11 | Unix socket paths will be updated by reading the redis configs. 12 | Uses tools/test/database_config.json if not specified. 13 | --dbconfig=FILE Use this database_config.json instead of creating new one under DEST. 14 | 15 | EOM 16 | } 17 | 18 | set -e 19 | 20 | mgmt_cmn=$(git -C $(dirname ${BASH_SOURCE}) rev-parse --show-toplevel) 21 | 22 | while [[ $# != 0 ]]; do 23 | case "$1" in 24 | -h|--help) usage; exit 0;; 25 | --dest=*) DEST=${1#*=} ;; 26 | --dbconfig-in=*) DBCONFIG_IN="${1#*=}" ;; 27 | --dbconfig=*) export DB_CONFIG_PATH="${1#*=}" ;; 28 | *) >&2 echo "error: unknown option \"$1\""; exit 1;; 29 | esac 30 | shift 31 | done 32 | 33 | if [[ -z ${DEST} ]]; then 34 | DEST=$(mktemp -d /tmp/translib.XXXXX) 35 | elif [[ ! -d ${DEST} ]]; then 36 | mkdir -p ${DEST} 37 | fi 38 | 39 | # Create database_config.json if not specified through --dbconfig 40 | if [[ -z ${DB_CONFIG_PATH} ]]; then 41 | export DB_CONFIG_PATH=${DEST}/database_config.json 42 | fi 43 | if [[ ! -e ${DB_CONFIG_PATH} ]] || [[ -n ${DBCONFIG_IN} ]]; then 44 | ${mgmt_cmn}/tools/test/dbconfig.py \ 45 | -s ${DBCONFIG_IN:-${mgmt_cmn}/tools/test/database_config.json} \ 46 | -o ${DB_CONFIG_PATH} 47 | fi 48 | 49 | 50 | # Prepare yang files directiry for transformer 51 | if [[ -z ${YANG_MODELS_PATH} ]]; then 52 | export YANG_MODELS_PATH=${DEST}/yangs 53 | fi 54 | mkdir -p $V ${YANG_MODELS_PATH} 55 | pushd ${YANG_MODELS_PATH} > /dev/null 56 | rm -rf * 57 | find ${mgmt_cmn}/build/yang -name "*.yang" -exec ln -sf {} \; 58 | ln -sf ${mgmt_cmn}/models/yang/version.xml 59 | ln -sf ${mgmt_cmn}/build/transformer/models_list 60 | popd > /dev/null 61 | 62 | 63 | # Setup CVL schema directory 64 | if [[ -z ${CVL_SCHEMA_PATH} ]]; then 65 | export CVL_SCHEMA_PATH=${mgmt_cmn}/build/cvl/schema 66 | fi 67 | 68 | # Prepare CVL config file with all traces enabled 69 | if [[ -z ${CVL_CFG_FILE} ]]; then 70 | export CVL_CFG_FILE=${DEST}/cvl_cfg.json 71 | if [[ ! -e ${CVL_CFG_FILE} ]]; then 72 | F=${mgmt_cmn}/cvl/conf/cvl_cfg.json 73 | sed -E 's/((TRACE|LOG).*)\"false\"/\1\"true\"/' $F > ${CVL_CFG_FILE} 74 | fi 75 | fi 76 | 77 | 78 | cat << EOM 79 | DB_CONFIG_PATH=${DB_CONFIG_PATH} 80 | YANG_MODELS_PATH=${YANG_MODELS_PATH} 81 | CVL_SCHEMA_PATH=${CVL_SCHEMA_PATH} 82 | CVL_CFG_FILE=${CVL_CFG_FILE} 83 | 84 | EOM -------------------------------------------------------------------------------- /tools/test/translib-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function print_usage() { 4 | cat << EOM 5 | usage: $(basename $0) [OPTIONS] [TESTARGS] 6 | 7 | OPTIONS: 8 | -pkg PACKAGE Test package name. Should be translib or its child package. 9 | Defaults to translib. 10 | -run PATTERN Testcase pattern. Equivalent of 'go test -run PATTERN ...' 11 | -bench PATTERN Benchmark pattern. Only one of -run or -bench is allowed. 12 | Equivalent of 'go test -bench PATTERN -benchmem -run ^$ ...' 13 | -json Dump test logs in json format. Output can be piped to tools 14 | like tparse or gotestsum. 15 | -vet=off Equivalent to -vet=off option. 16 | -tags BLDTAGS Comma separated build tags to use. Defaults to "test" 17 | 18 | TESTARGS: Any other arguments to be passed to TestMain. All values that 19 | do not match above listed options are treated as test args. 20 | Equivalent of 'go test ... -args TESTARGS' 21 | 22 | EOM 23 | } 24 | 25 | set -e 26 | 27 | TOPDIR=$(git rev-parse --show-toplevel) 28 | GO=${GO:-go} 29 | 30 | TARGS=( -mod=vendor -cover ) 31 | PARGS=() 32 | PKG=translib 33 | TAG=test 34 | 35 | while [[ $# -gt 0 ]]; do 36 | case "$1" in 37 | -h|-help|--help) print_usage; exit 0;; 38 | -p|-pkg|-package) PKG=$2; shift 2;; 39 | -r|-run) TARGS+=( -run "$2" ); shift 2;; 40 | -b|-bench) TARGS+=( -bench "$2" -benchmem -run "^$" ); shift 2;; 41 | -j|-json) TARGS+=( -json ); ECHO=0; shift;; 42 | -vet=off) TARGS+=( -vet=off ); shift;; 43 | -tags) TAG="$2"; shift 2;; 44 | *) PARGS+=( "$1"); shift;; 45 | esac 46 | done 47 | 48 | cd ${TOPDIR} 49 | if [[ ! -d ${PKG} ]] && [[ -d translib/${PKG} ]]; then 50 | PKG=translib/${PKG} 51 | fi 52 | 53 | if [[ -z ${GOPATH} ]]; then 54 | export GOPATH=/tmp/go 55 | fi 56 | 57 | export $(${TOPDIR}/tools/test/env.sh --dest=${TOPDIR}/build/test | xargs) 58 | 59 | [[ ${TARGS[*]} =~ -bench ]] || TARGS+=( -v ) 60 | [[ -z ${TAG} ]] || TARGS+=( -tags ${TAG} ) 61 | [[ "${PARGS[@]}" =~ -(also)?log* ]] || PARGS+=( -logtostderr ) 62 | 63 | [[ ${ECHO} == 0 ]] || set -x 64 | ${GO} test ./${PKG} "${TARGS[@]}" -args "${PARGS[@]}" 65 | -------------------------------------------------------------------------------- /tools/xfmr/annotate.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=$(realpath $(dirname ${BASH_SOURCE[0]})/../..) 24 | [[ -z ${MAKE} ]] && MAKE=make 25 | 26 | YANGDIR=${TOPDIR}/models/yang 27 | 28 | if [ -z $1 ]; then 29 | echo "usage: $0 YANG_FILE_NAME..." 30 | exit -1 31 | fi 32 | 33 | # Download, patch and compile goyang 34 | ${MAKE} -s -C ${TOPDIR} annotgen 35 | 36 | # Run goyang to generate annotation file for the specified yang file. 37 | # Annotation output is dumped on stdout. 38 | ${TOPDIR}/build/bin/goyang --format=annotate --path=${YANGDIR} "$@" 39 | -------------------------------------------------------------------------------- /translib/authorize.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 | /* 21 | Package translib defines the functions to be used to authorize 22 | 23 | an incoming user. It also includes caching of the UserDB data 24 | 25 | needed to authorize the user. 26 | 27 | */ 28 | 29 | package translib 30 | 31 | func isAuthorizedForSet(req SetRequest) bool { 32 | if !req.AuthEnabled { 33 | return true 34 | } 35 | for _, r := range req.User.Roles { 36 | if r == "admin" { 37 | return true 38 | } 39 | } 40 | return false 41 | } 42 | 43 | func isAuthorizedForBulk(req BulkRequest) bool { 44 | if !req.AuthEnabled { 45 | return true 46 | } 47 | for _, r := range req.User.Roles { 48 | if r == "admin" { 49 | return true 50 | } 51 | } 52 | return false 53 | } 54 | 55 | func isAuthorizedForGet(req GetRequest) bool { 56 | if !req.AuthEnabled { 57 | return true 58 | } 59 | return true 60 | } 61 | 62 | func isAuthorizedForSubscribe(req SubscribeRequest) bool { 63 | if !req.AuthEnabled { 64 | return true 65 | } 66 | return true 67 | } 68 | 69 | func isAuthorizedForIsSubscribe(req IsSubscribeRequest) bool { 70 | if !req.AuthEnabled { 71 | return true 72 | } 73 | return true 74 | } 75 | 76 | func isAuthorizedForAction(req ActionRequest) bool { 77 | if !req.AuthEnabled { 78 | return true 79 | } 80 | return true 81 | } 82 | -------------------------------------------------------------------------------- /translib/cs/cs_abort.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 | // Config Session Abort 21 | 22 | package cs 23 | 24 | import ( 25 | "errors" 26 | 27 | "github.com/golang/glog" 28 | ) 29 | 30 | func (sess *Session) Abort() (bool, CsStatus) { 31 | glog.Infof("Abort:[%s]:Begin:", sess.token) 32 | 33 | var success bool 34 | var status CsStatus 35 | 36 | if sess.IsConfigSession() { 37 | 38 | switch sess.configSession.state { 39 | case cs_STATE_ACTIVE: 40 | var err, errU error 41 | 42 | //rollback if commit timer is running. 43 | if sess.configSession.commitState == cs_STATE_CONFIRM_TIMER { 44 | if err = abortSessionCommit(sess); err != nil { 45 | success = false 46 | status = CsStatusInternalError{Err: errors.New("Config reload failure on commit abort")} 47 | break 48 | } 49 | } 50 | 51 | err, errU = deleteCS(sess.name) 52 | if err != nil { 53 | status = CsStatusInternalError{Err: err} 54 | } else if errU != nil { 55 | success = true 56 | status = CsStatusAbortWarning{UnlockFailure: errU} 57 | } else { 58 | success = true 59 | status = CsStatusSuccess{} 60 | } 61 | 62 | default: 63 | 64 | glog.Infof("Abort: Session In Use") 65 | success = false 66 | status = CsStatusInvalidSession{Tag: ErrTagNotActive} 67 | 68 | } 69 | 70 | } else { 71 | 72 | success = false 73 | status = CsStatusInvalidSession{} 74 | } 75 | 76 | glog.Infof("Abort:[%s]:End:", sess.token) 77 | return success, status 78 | } 79 | -------------------------------------------------------------------------------- /translib/cs/cs_ds.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 cs 21 | 22 | // Config Session Data Store 23 | 24 | type DSType int 25 | 26 | const ( 27 | DSRunning DSType = iota 28 | 29 | DSCandidate // Label (Session Token, except in Start Request) 30 | DSCheckpoint // Label (* in /etc/sonic/checkpoints/*.cp.json) (Future) 31 | DSFile // Label (Arbitrary Filename *.json in the /etc dir) (Future) 32 | ) 33 | 34 | type DataStore struct { 35 | Type DSType 36 | Label string 37 | } 38 | 39 | // Token returns the Label if Type is DSCandidate. Otherwise "" 40 | func (ds *DataStore) Token() string { 41 | var token string 42 | switch ds.Type { 43 | case DSCandidate: 44 | token = ds.Label 45 | default: 46 | } 47 | return token 48 | } 49 | -------------------------------------------------------------------------------- /translib/cs/cs_exit.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 | // Config Session Exit 21 | 22 | package cs 23 | 24 | import ( 25 | "github.com/golang/glog" 26 | ) 27 | 28 | func (sess *Session) Exit() (bool, CsStatus) { 29 | glog.Infof("Exit:[%s]:Begin:", sess.token) 30 | 31 | var success bool 32 | var status CsStatus 33 | 34 | if sess.IsConfigSession() { 35 | 36 | switch sess.configSession.state { 37 | case cs_STATE_ACTIVE: 38 | 39 | suspendCS(sess.name) 40 | success = true 41 | status = CsStatusSuccess{} 42 | 43 | default: 44 | 45 | glog.Infof("Exit: Session In Use") 46 | success = false 47 | status = CsStatusInvalidSession{Tag: ErrTagNotActive} 48 | 49 | } 50 | 51 | } else { 52 | 53 | glog.Errorf("Exit: Invalid Session") 54 | success = false 55 | status = CsStatusInvalidSession{} 56 | } 57 | 58 | glog.Infof("Exit:[%s]:End:", sess.token) 59 | return success, status 60 | } 61 | -------------------------------------------------------------------------------- /translib/cs/cs_getdb.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 | // Config Session Get ConfigDB 21 | 22 | package cs 23 | 24 | import ( 25 | "github.com/Azure/sonic-mgmt-common/translib/db" 26 | "github.com/golang/glog" 27 | ) 28 | 29 | func (sess *Session) GetConfigDB(opts *db.Options) (*db.DB, bool, func(), 30 | error) { 31 | 32 | glog.Infof("GetConfigDB: %v", opts) 33 | 34 | var err error 35 | var d *db.DB 36 | var isCS bool 37 | var cleanup func() 38 | 39 | if sess.state == cs_STATE_None { 40 | 41 | cleanup = func() { d.DeleteDB() } 42 | var dopts *db.Options 43 | if opts != nil { 44 | dopts = opts 45 | } else { 46 | dopts = &(db.Options{DBNo: db.ConfigDB}) 47 | } 48 | dopts.DBNo = db.ConfigDB 49 | d, err = db.NewDB(*dopts) 50 | 51 | } else { 52 | 53 | glog.Infof("GetConfigDB: Session DB") 54 | d = sess.ccDB 55 | isCS = true 56 | cleanup = func() { 57 | sess.configSession.UpdateLastActiveTime() 58 | 59 | // Rollback the stale savepoint if exists (happens when the app module panics) 60 | if d.HasSP() { 61 | glog.Infof("Attempting to rollback the stale savepoint...") 62 | if rbErr := d.Rollback2SP(); rbErr != nil { 63 | glog.Errorf("Failed to rollback the stale savepoint: %v", rbErr) 64 | } 65 | } 66 | } 67 | 68 | } 69 | 70 | return d, isCS, cleanup, err 71 | } 72 | -------------------------------------------------------------------------------- /translib/cs/cs_mesg.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 | // Config Session Send Message 21 | 22 | package cs 23 | 24 | import ( 25 | "fmt" 26 | "os" 27 | 28 | "github.com/golang/glog" 29 | ) 30 | 31 | func (sess *Session) SendMesg(mesg string, userName string) error { 32 | glog.Infof("SendMesg:[%s]:Begin: %s: from %s", sess.token, mesg, userName) 33 | 34 | var err error 35 | var ttyName string 36 | var n int 37 | var tty *os.File 38 | 39 | fMesg := fmt.Sprintf("\n\nMessage from %s: %s\n\n", userName, mesg) 40 | if sess.IsConfigSession() && sess.IsPidActive() { 41 | link := fmt.Sprintf("/proc/%d/fd/0", sess.TerminalPID()) 42 | if ttyName, err = os.Readlink(link); err != nil { 43 | glog.Errorf("SendMesg: Readlink(%s) err %v", link, err) 44 | } else if tty, err = os.OpenFile(ttyName, os.O_RDWR, 0); err != nil { 45 | glog.Errorf("SendMesg: Open(%s) err %v", ttyName, err) 46 | } else { 47 | defer tty.Close() 48 | if n, err = tty.WriteString(fMesg); err != nil { 49 | glog.Infof("SendMesg: WriteString(%s) n %d err %v", fMesg, n, 50 | err) 51 | glog.Errorf("SendMesg: WriteString() fails, file: %s", ttyName) 52 | } 53 | } 54 | } 55 | 56 | glog.Infof("SendMesg:[%s]:End:", sess.token) 57 | return err 58 | } 59 | -------------------------------------------------------------------------------- /translib/cs/cs_test.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 | // Config Session Test 21 | 22 | package cs 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | ) 28 | 29 | var sName = "" 30 | var user = "sonicbld" 31 | var uR = []string{"sonicbld"} 32 | var pid = int32(os.Getpid()) 33 | var commitLabel = "TestCommitLabel" 34 | 35 | func TestCSNew(t *testing.T) { 36 | 37 | u, e := newCS(sName, user, uR, pid) 38 | if (u == nil) || (e != nil) { 39 | t.Fatalf("newCS() fails e: %v", e) 40 | } 41 | 42 | t.Cleanup(func() { deleteCS(sName) }) 43 | 44 | u, e = suspendCS(sName) 45 | if (u == nil) || (e != nil) { 46 | t.Fatalf("suspendCS() fails e: %v", e) 47 | } 48 | 49 | u, e = resumeCS(sName, uR, pid) 50 | if (u == nil) || (e != nil) { 51 | t.Fatalf("resumeCS() fails e: %v", e) 52 | } 53 | 54 | e, _, _ = commitCS(sName, "", false) 55 | if e != nil { 56 | t.Fatalf("commitCS() fails e: %v", e) 57 | } 58 | } 59 | 60 | func TestCSDelete(t *testing.T) { 61 | 62 | u, e := newCS(sName, user, uR, pid) 63 | if (u == nil) || (e != nil) { 64 | t.Fatalf("newCS() fails e: %v", e) 65 | } 66 | 67 | e, _ = deleteCS(sName) 68 | if e != nil { 69 | t.Fatalf("deleteCS() fails e: %v", e) 70 | } 71 | } 72 | 73 | func TestCSPidActive(t *testing.T) { 74 | u, e := newCS(sName, user, uR, pid) 75 | if (u == nil) || (e != nil) { 76 | t.Fatalf("newCS() fails e: %v", e) 77 | } 78 | 79 | t.Cleanup(func() { deleteCS(sName) }) 80 | 81 | u.UpdateLastActiveTime() 82 | 83 | if !u.IsPidActive() { 84 | t.Fatalf("IsPidActive() fails e: %v", e) 85 | } 86 | 87 | e, _ = deleteCS(sName) 88 | if e != nil { 89 | t.Fatalf("deleteCS() fails e: %v", e) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /translib/cs/cs_tx.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 cs 21 | 22 | // Config Session Transaction 23 | // (Start|Commit|Abort)Tx are to be used by the apps that need to invoke them 24 | 25 | import ( 26 | "github.com/Azure/sonic-mgmt-common/translib/db" 27 | "github.com/golang/glog" 28 | ) 29 | 30 | func (sess *Session) StartTx(d *db.DB, w []db.WatchKeys, 31 | tss []*db.TableSpec) error { 32 | 33 | glog.Infof("cs.StartTx:[%s]: Begin", sess.token) 34 | var e error 35 | if (sess.state == cs_STATE_None) && (d == sess.ccDB) { 36 | e = d.DeclareSP() 37 | } else { 38 | e = d.StartTx(w, tss) 39 | } 40 | return e 41 | } 42 | 43 | func (sess *Session) CommitTx(d *db.DB) error { 44 | glog.Infof("cs.CommitTx:[%s]: Begin", sess.token) 45 | var e error 46 | if (uCS != nil) && (d == uCS.ccDB) { 47 | e = d.ReleaseSP() 48 | } else { 49 | e = d.CommitTx() 50 | } 51 | return e 52 | } 53 | 54 | func (sess *Session) AbortTx(d *db.DB) error { 55 | glog.Infof("cs.AbortTx:[%s]: Begin", sess.token) 56 | var e error 57 | if (uCS != nil) && (d == uCS.ccDB) { 58 | e = d.Rollback2SP() 59 | } else { 60 | e = d.AbortTx() 61 | } 62 | return e 63 | } 64 | 65 | func csStartTx(d *db.DB) error { 66 | glog.Infof("csStartTx: Begin") 67 | return d.StartSessTx(nil, []*db.TableSpec{&(db.TableSpec{Name: "*"})}) 68 | } 69 | 70 | func csCommitTx(d *db.DB) error { 71 | glog.Infof("csCommitTx: Begin") 72 | return d.CommitSessTx() 73 | } 74 | 75 | func csAbortTx(d *db.DB) error { 76 | glog.Infof("csAbortTx: Begin") 77 | return d.AbortSessTx() 78 | } 79 | -------------------------------------------------------------------------------- /translib/db/db_cvl_hint_test.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 db 21 | 22 | import ( 23 | "testing" 24 | ) 25 | 26 | var hKey = "TESTKEY" 27 | var hValue = map[string]string{"a": "1", "b": "2"} 28 | 29 | func newEnableCVLDB(dBNum DBNum) (*DB, error) { 30 | d, e := NewDB(Options{ 31 | DBNo: dBNum, 32 | InitIndicator: "", 33 | TableNameSeparator: "|", 34 | KeySeparator: "|", 35 | }) 36 | return d, e 37 | } 38 | 39 | func cleanupCH(t *testing.T, d *DB) { 40 | if d == nil { 41 | return 42 | } 43 | 44 | d.DeleteDB() 45 | } 46 | 47 | func TestCVLHint(t *testing.T) { 48 | d, e := newEnableCVLDB(ConfigDB) 49 | if e != nil { 50 | t.Fatalf("newDB() fails e: %v", e) 51 | } 52 | 53 | d.clearCVLHint("") 54 | 55 | // Register CleanUp Function 56 | t.Cleanup(func() { cleanupCH(t, d) }) 57 | 58 | if e := d.StoreCVLHint(hKey, hValue); e != nil { 59 | t.Errorf("d.StoreCVLHint(%v, %v) fails e: %v", hKey, hValue, e) 60 | } 61 | 62 | d.clearCVLHint(hKey) 63 | 64 | // Negative Test 65 | if e := d.StoreCVLHint("", hValue); e == nil { 66 | t.Errorf("d.StoreCVLHint(%v, %v) succeeds", hValue, hValue) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /translib/db/db_datastore.go: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 db 21 | 22 | // import ( 23 | // "errors" 24 | // "flag" 25 | // "reflect" 26 | // "strconv" 27 | // "strings" 28 | // "sync" 29 | // "time" 30 | 31 | // "github.com/Azure/sonic-mgmt-common/cvl" 32 | // "github.com/go-redis/redis/v7" 33 | // "github.com/golang/glog" 34 | // ) 35 | 36 | //////////////////////////////////////////////////////////////////////////////// 37 | // Exported Types // 38 | //////////////////////////////////////////////////////////////////////////////// 39 | 40 | type DBDatastore interface { 41 | 42 | // Eg: Commit-ID, Filename(Future), Snapshot-ID(Future), Writable(Future) 43 | Attributes() map[string]string 44 | } 45 | 46 | // CommitIdDbDs is a Datastore modeled from a saved-to-disk CONFIG_DB of a 47 | // commit-id which is stored in the CHECKPOINTS_DIR, with a 48 | // CHECKPOINT_EXT (cp.json) 49 | type CommitIdDbDs struct { 50 | CommitID string 51 | } 52 | 53 | func (ds *CommitIdDbDs) Attributes() map[string]string { 54 | return map[string]string{ 55 | "commit-id": ds.CommitID, 56 | } 57 | } 58 | 59 | // DefaultDbDs is the default Datastore representing the data 60 | // stored in the CONFIG_DB database(/selection) of the redis-server 61 | type DefaultDbDs struct { 62 | } 63 | 64 | func (ds *DefaultDbDs) Attributes() map[string]string { 65 | return map[string]string{} 66 | } 67 | -------------------------------------------------------------------------------- /translib/db/db_debug.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 db 21 | 22 | // Dump the DB contents 23 | 24 | const ( 25 | InitialDebugDBSize int = 20 26 | ) 27 | 28 | func (d *DB) GetDebugDB() interface{} { 29 | if d == nil { 30 | return nil 31 | } 32 | dbd := make(map[string]interface{}, InitialDebugDBSize) 33 | dbd["Opts"] = d.Opts 34 | dbd["txState"] = d.txState 35 | dbd["txCmds"] = d.GetDebugTxCmds() 36 | dbd["txTsEntryMap"] = d.txTsEntryMap 37 | dbd["cvlEditConfigData"] = d.GetDebugCvlECD() 38 | dbd["cvlHintsB4Open"] = d.cvlHintsB4Open 39 | 40 | dbd["err"] = d.err 41 | 42 | dbd["sCIP"] = d.sCIP 43 | // Recursive Call? 44 | // dbd["sOnCCacheDB"] = d.sOnCCacheDB.GetDebugDB() 45 | 46 | dbd["dbStatsConfig"] = d.dbStatsConfig 47 | dbd["dbCacheConfig"] = d.dbCacheConfig 48 | 49 | dbd["stats"] = d.stats 50 | dbd["cache"] = d.cache 51 | 52 | dbd["onCReg"] = d.onCReg 53 | 54 | dbd["configDBLocked"] = d.configDBLocked 55 | 56 | return dbd 57 | } 58 | 59 | func (d *DB) GetDebugTxCmds() interface{} { 60 | if d == nil { 61 | return nil 62 | } 63 | txCmds := make([](map[string]interface{}), len(d.txCmds)) 64 | for i := range d.txCmds { 65 | txCmds[i] = make(map[string]interface{}) 66 | txCmds[i]["ts"] = d.txCmds[i].ts 67 | txCmds[i]["op"] = d.txCmds[i].op 68 | txCmds[i]["key"] = d.txCmds[i].key 69 | txCmds[i]["value"] = d.txCmds[i].value 70 | } 71 | return txCmds 72 | } 73 | 74 | func (d *DB) GetDebugCvlECD() interface{} { 75 | if d == nil { 76 | return nil 77 | } 78 | return d.cvlEditConfigData 79 | } 80 | -------------------------------------------------------------------------------- /translib/db/db_get.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2021 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 db 21 | 22 | import ( 23 | "strings" 24 | 25 | "github.com/Azure/sonic-mgmt-common/translib/tlerr" 26 | "github.com/golang/glog" 27 | ) 28 | 29 | //////////////////////////////////////////////////////////////////////////////// 30 | // Exported Types // 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | //////////////////////////////////////////////////////////////////////////////// 34 | // Exported Functions // 35 | //////////////////////////////////////////////////////////////////////////////// 36 | 37 | // Get gets the value of the key 38 | func (d *DB) Get(key string) (string, error) { 39 | if glog.V(3) { 40 | glog.Info("Get: Begin: key: ", key) 41 | } 42 | 43 | if (d == nil) || (d.client == nil) { 44 | return "", tlerr.TranslibDBConnectionReset{} 45 | } 46 | 47 | // Only meant to retrieve metadata. 48 | if !strings.HasPrefix(key, "CONFIG_DB") || strings.Contains(key, "|") { 49 | return "", UseGetEntry 50 | } 51 | 52 | glog.Info("Get: RedisCmd: ", d.Name(), ": ", "GET ", key) 53 | val, e := d.client.Get(key).Result() 54 | 55 | if glog.V(3) { 56 | glog.Info("Get: End: key: ", key, " val: ", val, " e: ", e) 57 | } 58 | 59 | return val, e 60 | } 61 | 62 | //////////////////////////////////////////////////////////////////////////////// 63 | // Internal Functions // 64 | //////////////////////////////////////////////////////////////////////////////// 65 | -------------------------------------------------------------------------------- /translib/db/db_session.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2022 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 db 21 | 22 | // DB Layer Session (Un)Registration for Sending CandidateConfig Notifications. 23 | // Currently, a list is not maintained. However, should a need arise, it 24 | // can be added in the future. 25 | 26 | func (d *DB) registerSessionDB() { 27 | d.sendSessionOpened() 28 | } 29 | 30 | func (d *DB) unRegisterSessionDB() { 31 | d.sendSessionClosed() 32 | } 33 | -------------------------------------------------------------------------------- /translib/db/db_signal.go: -------------------------------------------------------------------------------- 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 | package db 21 | 22 | import ( 23 | // "fmt" 24 | // "strconv" 25 | 26 | // "errors" 27 | // "strings" 28 | 29 | // "github.com/Azure/sonic-mgmt-common/cvl" 30 | // "github.com/go-redis/redis/v7" 31 | "os" 32 | "os/signal" 33 | "syscall" 34 | // "github.com/golang/glog" 35 | // "github.com/Azure/sonic-mgmt-common/translib/tlerr" 36 | ) 37 | 38 | //////////////////////////////////////////////////////////////////////////////// 39 | // Exported Types // 40 | //////////////////////////////////////////////////////////////////////////////// 41 | 42 | //////////////////////////////////////////////////////////////////////////////// 43 | // Exported Functions // 44 | //////////////////////////////////////////////////////////////////////////////// 45 | 46 | func SignalHandler() { 47 | sigs := make(chan os.Signal, 1) 48 | signal.Notify(sigs, syscall.SIGUSR2) 49 | go func() { 50 | for { 51 | s := <-sigs 52 | if s == syscall.SIGUSR2 { 53 | HandleSIGUSR2() 54 | } 55 | } 56 | }() 57 | } 58 | 59 | func HandleSIGUSR2() { 60 | if dbCacheConfig != nil { 61 | dbCacheConfig.handleReconfigureSignal() 62 | } 63 | 64 | if dbStatsConfig != nil { 65 | dbStatsConfig.handleReconfigureSignal() 66 | } 67 | 68 | if dbRedisOptsConfig != nil { 69 | dbRedisOptsConfig.handleReconfigureSignal() 70 | } 71 | } 72 | 73 | //////////////////////////////////////////////////////////////////////////////// 74 | // Internal Functions // 75 | //////////////////////////////////////////////////////////////////////////////// 76 | 77 | func init() { 78 | SignalHandler() 79 | } 80 | -------------------------------------------------------------------------------- /translib/db/test/arloIssue29.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 | /* 21 | UT for 22 | https://github.com/project-arlo/sonic-mgmt-framework/issues/29 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "fmt" 29 | // "errors" 30 | "flag" 31 | "github.com/Azure/sonic-mgmt-common/translib/db" 32 | "github.com/golang/glog" 33 | // "time" 34 | // "github.com/Azure/sonic-mgmt-common/translib/tlerr" 35 | ) 36 | 37 | func main() { 38 | var avalue db.Value 39 | var akey db.Key 40 | var e error 41 | 42 | defer glog.Flush() 43 | 44 | flag.Parse() 45 | 46 | fmt.Println("https://github.com/project-arlo/sonic-mgmt-framework/issues/29") 47 | fmt.Println("Creating the DB ==============") 48 | d, _ := db.NewDB(db.Options{ 49 | DBNo: db.ApplDB, 50 | InitIndicator: "", 51 | TableNameSeparator: ":", 52 | KeySeparator: ":", 53 | }) 54 | 55 | tsi := db.TableSpec{Name: "INTF_TABLE", CompCt: 2} 56 | 57 | ca := make([]string, 2, 2) 58 | 59 | fmt.Println("Testing SetEntry ==============") 60 | ca[0] = "Ethernet20" 61 | ca[1] = "a::b/64" 62 | akey = db.Key{Comp: ca} 63 | avalue = db.Value{Field: map[string]string{ 64 | "scope": "global", 65 | "family": "IPv4", 66 | }} 67 | 68 | e = d.SetEntry(&tsi, akey, avalue) 69 | if e != nil { 70 | fmt.Println("SetEntry() ERROR: e: ", e) 71 | return 72 | } 73 | 74 | fmt.Println("Testing GetEntry ==============") 75 | 76 | avalue, e = d.GetEntry(&tsi, akey) 77 | if e != nil { 78 | fmt.Println("GetEntry() ERROR: e: ", e) 79 | return 80 | } 81 | 82 | fmt.Println("ts: ", tsi, " ", akey, ": ", avalue) 83 | 84 | d.DeleteDB() 85 | } 86 | -------------------------------------------------------------------------------- /translib/db/test/testsubscribe.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 | // "errors" 25 | "flag" 26 | "github.com/Azure/sonic-mgmt-common/translib/db" 27 | "github.com/golang/glog" 28 | "time" 29 | // "github.com/Azure/sonic-mgmt-common/translib/tlerr" 30 | ) 31 | 32 | func handler(d *db.DB, skey *db.SKey, key *db.Key, event db.SEvent) error { 33 | fmt.Println("***handler: d: ", d, " skey: ", *skey, " key: ", *key, 34 | " event: ", event) 35 | return nil 36 | } 37 | 38 | func main() { 39 | // var avalue,rvalue db.Value 40 | var akey db.Key 41 | // var rkey db.Key 42 | // var e error 43 | 44 | defer glog.Flush() 45 | 46 | flag.Parse() 47 | 48 | tsa := db.TableSpec{Name: "ACL_TABLE"} 49 | // tsr := db.TableSpec { Name: "ACL_RULE" } 50 | 51 | ca := make([]string, 1, 1) 52 | ca[0] = "MyACL1_ACL_IPVNOTEXIST*" 53 | akey = db.Key{Comp: ca} 54 | var skeys []*db.SKey = make([]*db.SKey, 1) 55 | skeys[0] = &(db.SKey{Ts: &tsa, Key: &akey, 56 | SEMap: map[db.SEvent]bool{ 57 | db.SEventHSet: true, 58 | db.SEventHDel: true, 59 | db.SEventDel: true, 60 | }}) 61 | 62 | fmt.Println("Creating the SubscribeDB ==============") 63 | d, e := db.SubscribeDB(db.Options{ 64 | DBNo: db.ConfigDB, 65 | InitIndicator: "CONFIG_DB_INITIALIZED", 66 | TableNameSeparator: "|", 67 | KeySeparator: "|", 68 | }, skeys, handler) 69 | 70 | if e != nil { 71 | fmt.Println("Subscribe() returns error e: ", e) 72 | } 73 | 74 | fmt.Println("Sleeping 15 ==============") 75 | time.Sleep(15 * time.Second) 76 | 77 | fmt.Println("Testing UnsubscribeDB ==============") 78 | 79 | d.UnsubscribeDB() 80 | 81 | fmt.Println("Sleeping 5 ==============") 82 | time.Sleep(5 * time.Second) 83 | 84 | } 85 | -------------------------------------------------------------------------------- /translib/ocbinds/schema.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2021 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 ocbinds 21 | 22 | import ( 23 | "github.com/openconfig/ygot/ytypes" 24 | ) 25 | 26 | // GetSchema is equivalent of the Schema function, but avoids 27 | // UnzipSchema call. Reuses the SchemaTree loaded during init. 28 | func GetSchema() (*ytypes.Schema, error) { 29 | return &ytypes.Schema{ 30 | Root: &Device{}, 31 | SchemaTree: SchemaTree, 32 | Unmarshal: Unmarshal, 33 | }, nil 34 | } 35 | -------------------------------------------------------------------------------- /translib/test/acl/04_create_MyACL1_1Rule_content.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "sequence-id": 11, 4 | "description": "Description for MyACL1 Rule Seq 11" 5 | }, 6 | "ipv4": { 7 | "config": { 8 | "source-address": "11.1.1.11/32", 9 | "destination-address": "21.1.1.11/32", 10 | "dscp": 11, 11 | "protocol": "IP_TCP" 12 | } 13 | }, 14 | "transport": { 15 | "config": { 16 | "source-port": 111, 17 | "destination-port": 211 18 | } 19 | }, 20 | "actions": { 21 | "config": { 22 | "forwarding-action": "ACCEPT" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /translib/test/acl/05_Create_MyACL3_binding.json: -------------------------------------------------------------------------------- 1 | { 2 | "interface": [ 3 | { 4 | "id": "Ethernet8", 5 | "config": { 6 | "id": "Ethernet8" 7 | }, 8 | "interface-ref": { 9 | "config": { 10 | "interface": "Ethernet8" 11 | } 12 | }, 13 | "ingress-acl-sets": { 14 | "ingress-acl-set": [ 15 | { 16 | "set-name": "MyACL3", 17 | "type": "ACL_IPV4", 18 | "config": { 19 | "set-name": "MyACL3", 20 | "type": "ACL_IPV4" 21 | } 22 | } 23 | ] 24 | } 25 | } 26 | ] 27 | } 28 | 29 | -------------------------------------------------------------------------------- /translib/test/acl/09_after_delete_1Rule_get_MyACL4_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-acl:acl/acl-sets/acl-set[name=MyACL4][type=ACL_IPV4] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | 3 | -------------------------------------------------------------------------------- /translib/test/acl/09_after_delete_1Rule_get_MyACL4_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-acl:acl-set\":[{\"acl-entries\":{\"acl-entry\":[{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":3},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.3/32\"},\"state\":{\"destination-address\":\"22.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.3/32\"}},\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3},\"transport\":{\"config\":{\"destination-port\":203,\"source-port\":103}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":5},\"ipv4\":{\"config\":{\"destination-address\":\"22.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.5/32\"},\"state\":{\"destination-address\":\"22.1.1.5/32\",\"dscp\":5,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"12.1.1.5/32\"}},\"sequence-id\":5,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":5},\"transport\":{\"config\":{\"destination-port\":205,\"source-port\":105}}}]},\"config\":{\"description\":\"Description for MyACL4\",\"name\":\"MyACL4\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"name\":\"MyACL4\",\"state\":{\"description\":\"Description for MyACL4\",\"name\":\"MyACL4\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"}]} 2 | -------------------------------------------------------------------------------- /translib/test/acl/09_create_MyACL4_4Rules_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -replace /openconfig-acl:acl/:@./09_create_MyACL4_4Rules.json -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/acl/09_delete_1Rule_MyACL4_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -delete /openconfig-acl:acl/acl-sets/acl-set[name=MyACL4][type=ACL_IPV4]/acl-entries/acl-entry[sequence-id=1] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/acl/09_get_1Rule_MyACL4_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-acl:acl/acl-sets/acl-set[name=MyACL4][type=ACL_IPV4]/acl-entries/acl-entry[sequence-id=1] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | 3 | -------------------------------------------------------------------------------- /translib/test/acl/09_get_all_MyACL4_4Rules_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-acl:acl/acl-sets/acl-set[name=MyACL4][type=ACL_IPV4] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/acl/09_get_all_MyACL4_4Rules_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-acl:acl-set\":[{\"acl-entries\":{\"acl-entry\":[{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":1},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.1/32\"},\"state\":{\"destination-address\":\"21.1.1.1/32\",\"dscp\":1,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.1/32\"}},\"sequence-id\":1,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":1},\"transport\":{\"config\":{\"destination-port\":201,\"source-port\":101,\"tcp-flags\":[\"openconfig-packet-match-types:TCP_FIN\"]},\"state\":{\"tcp-flags\":[\"openconfig-packet-match-types:TCP_FIN\"]}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:DROP\"}},\"config\":{\"sequence-id\":2},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.2/32\",\"protocol\":\"openconfig-packet-match-types:IP_ICMP\",\"source-address\":\"11.1.1.2/32\"},\"state\":{\"destination-address\":\"21.1.1.2/32\",\"protocol\":\"openconfig-packet-match-types:IP_ICMP\",\"source-address\":\"11.1.1.2/32\"}},\"sequence-id\":2,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":2}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:ACCEPT\"}},\"config\":{\"sequence-id\":3},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.3/32\"},\"state\":{\"destination-address\":\"21.1.1.3/32\",\"dscp\":3,\"protocol\":\"openconfig-packet-match-types:IP_TCP\",\"source-address\":\"11.1.1.3/32\"}},\"sequence-id\":3,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":3},\"transport\":{\"config\":{\"destination-port\":203,\"source-port\":103}}},{\"actions\":{\"config\":{\"forwarding-action\":\"openconfig-acl:DROP\"}},\"config\":{\"sequence-id\":4},\"ipv4\":{\"config\":{\"destination-address\":\"21.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_PIM\",\"source-address\":\"11.1.1.4/32\"},\"state\":{\"destination-address\":\"21.1.1.4/32\",\"dscp\":4,\"protocol\":\"openconfig-packet-match-types:IP_PIM\",\"source-address\":\"11.1.1.4/32\"}},\"sequence-id\":4,\"state\":{\"matched-octets\":\"0\",\"matched-packets\":\"0\",\"sequence-id\":4}}]},\"config\":{\"description\":\"Description for MyACL4\",\"name\":\"MyACL4\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"name\":\"MyACL4\",\"state\":{\"description\":\"Description for MyACL4\",\"name\":\"MyACL4\",\"type\":\"openconfig-acl:ACL_IPV4\"},\"type\":\"openconfig-acl:ACL_IPV4\"}]} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/01_get_all_command.txt: -------------------------------------------------------------------------------- 1 | 2 | ./gnmi_get -xpath /openconfig-interfaces:interfaces -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 3 | -------------------------------------------------------------------------------- /translib/test/interfaces/02_get_interface_command.txt: -------------------------------------------------------------------------------- 1 | 2 | ./gnmi_get -xpath /openconfig-interfaces:interfaces/interface[name=Ethernet0] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 3 | -------------------------------------------------------------------------------- /translib/test/interfaces/02_get_interface_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-interfaces:interface\":[{\"config\":{\"description\":\"\",\"mtu\":9100,\"name\":\"Ethernet0\"},\"name\":\"Ethernet0\",\"openconfig-if-ethernet:ethernet\":{\"config\":{\"port-speed\":\"openconfig-if-ethernet:SPEED_40GB\"},\"state\":{\"port-speed\":\"openconfig-if-ethernet:SPEED_40GB\"}},\"state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"description\":\"\",\"ifindex\":0,\"mtu\":9100,\"name\":\"Ethernet0\",\"oper-status\":\"DOWN\"},\"subinterfaces\":{\"subinterface\":[{\"index\":0,\"openconfig-if-ip:ipv4\":{\"addresses\":{\"address\":[{\"config\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31},\"ip\":\"10.0.0.0\",\"state\":{\"ip\":\"10.0.0.0\",\"prefix-length\":31}}]}}}]}}]} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/03_get_interface_config_command.txt: -------------------------------------------------------------------------------- 1 | 2 | ./gnmi_get -xpath /openconfig-interfaces:interfaces/interface[name=Ethernet0]/config/ -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 3 | -------------------------------------------------------------------------------- /translib/test/interfaces/03_get_interface_config_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-interfaces:config\":{\"mtu\":9100,\"name\":\"Ethernet0\"}} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/04_get_interface_state_command.txt: -------------------------------------------------------------------------------- 1 | 2 | ./gnmi_get -xpath /openconfig-interfaces:interfaces/interface[name=Ethernet0]/state -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 3 | -------------------------------------------------------------------------------- /translib/test/interfaces/04_get_interface_state_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-interfaces:state\":{\"admin-status\":\"UP\",\"counters\":{\"in-broadcast-pkts\":\"0\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"0\",\"in-octets\":\"0\",\"in-pkts\":\"0\",\"in-unicast-pkts\":\"0\",\"out-broadcast-pkts\":\"0\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"0\",\"out-octets\":\"0\",\"out-pkts\":\"0\",\"out-unicast-pkts\":\"0\"},\"ifindex\":1,\"mtu\":9100,\"name\":\"Ethernet0\",\"oper-status\":\"DOWN\"}} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/05_set_interface_mtu.json: -------------------------------------------------------------------------------- 1 | {"mtu":9000} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/05_set_interface_mtu_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -replace /openconfig-interfaces:interfaces/interface[name=Ethernet0]/config/mtu:@./05_set_interface_mtu.json -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/06_set_interface_ipv4.json: -------------------------------------------------------------------------------- 1 | {"openconfig-if-ip:ipv4": {"addresses": {"address": [{"ip": "9.9.9.9","config": {"ip": "9.9.9.9","prefix-length": 24}}]}}} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/06_set_interface_ipv4_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -replace /openconfig-interfaces:interfaces/interface[name=Ethernet0]/subinterfaces/subinterface[index=0]:@./06_set_interface_ipv4.json -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/07_set_interface_ipv6.json: -------------------------------------------------------------------------------- 1 | {"openconfig-if-ip:ipv6": {"addresses": {"address": [{"ip": "2001:db8::","config": {"ip": "2001:db8::","prefix-length": 32}}]}}} 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/07_set_interface_ipv6_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -replace /openconfig-interfaces:interfaces/interface[name=Ethernet0]/subinterfaces/subinterface[index=0]:@./07_set_interface_ipv6.json -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/08_delete_interface_ipv4_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -delete /openconfig-interfaces:interfaces/interface[name=Ethernet0]/subinterfaces/subinterface[index=0]/ipv4/addresses/address[ip=9.9.9.9]/config/prefix-length -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/interfaces/09_delete_interface_ipv6_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_set -delete /openconfig-interfaces:interfaces/interface[name=Ethernet0]/subinterfaces/subinterface[index=0]/ipv6/addresses/address[ip=2001:db8::]/config/prefix-length -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/lldp/01-get-all-intf-command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-lldp:lldp/interfaces -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/lldp/01-get-all-intf-response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-lldp:interfaces\":{\"interface\":[{\"name\":\"Ethernet0\",\"neighbors\":{\"neighbor\":[{\"capabilities\":{\"capability\":[{\"name\":\"openconfig-lldp-types:MAC_BRIDGE\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:MAC_BRIDGE\"}},{\"name\":\"openconfig-lldp-types:REPEATER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:REPEATER\"}},{\"name\":\"openconfig-lldp-types:ROUTER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:ROUTER\"}}]},\"id\":\"Ethernet0\",\"state\":{\"chassis-id\":\"e4:f0:04:fe:64:e1\",\"chassis-id-type\":\"MAC_ADDRESS\",\"id\":\"1\",\"management-address\":\"\",\"port-description\":\"ethernet1/1/9\",\"port-id\":\"ethernet1/1/9\",\"port-id-type\":\"INTERFACE_NAME\",\"system-description\":\"Dell EMC Networking OS10-Enterprise.\\r\\nCopyright (c) 1999-2019 by Dell Inc. All Rights Reserved.\\r\\nSystem Description: OS10 Enterprise.\\r\\nOS Version: 10.4.3.1.\\r\\nSystem Type: S4148T-ON\",\"system-name\":\"swtor-b2lab2-1409\",\"ttl\":11666}}]}},{\"name\":\"eth0\",\"neighbors\":{\"neighbor\":[{\"capabilities\":{\"capability\":[{\"name\":\"openconfig-lldp-types:MAC_BRIDGE\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:MAC_BRIDGE\"}},{\"name\":\"openconfig-lldp-types:REPEATER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:REPEATER\"}},{\"name\":\"openconfig-lldp-types:ROUTER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:ROUTER\"}}]},\"id\":\"eth0\",\"state\":{\"chassis-id\":\"e4:f0:04:fe:64:e1\",\"chassis-id-type\":\"MAC_ADDRESS\",\"id\":\"1\",\"management-address\":\"\",\"port-description\":\"ethernet1/1/9\",\"port-id\":\"ethernet1/1/9\",\"port-id-type\":\"INTERFACE_NAME\",\"system-description\":\"Dell EMC Networking OS10-Enterprise.\\r\\nCopyright (c) 1999-2019 by Dell Inc. All Rights Reserved.\\r\\nSystem Description: OS10 Enterprise.\\r\\nOS Version: 10.4.3.1.\\r\\nSystem Type: S4148T-ON\",\"system-name\":\"swtor-b2lab2-1409\",\"ttl\":11666}}]}}]}} 2 | -------------------------------------------------------------------------------- /translib/test/lldp/02-get-one-intf-command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-lldp:lldp/interfaces/interface[name=Ethernet0] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/lldp/02-get-one-intf-response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-lldp:interface\":[{\"name\":\"Ethernet0\",\"neighbors\":{\"neighbor\":[{\"capabilities\":{\"capability\":[{\"name\":\"openconfig-lldp-types:MAC_BRIDGE\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:MAC_BRIDGE\"}},{\"name\":\"openconfig-lldp-types:REPEATER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:REPEATER\"}},{\"name\":\"openconfig-lldp-types:ROUTER\",\"state\":{\"enabled\":true,\"name\":\"openconfig-lldp-types:ROUTER\"}}]},\"id\":\"Ethernet0\",\"state\":{\"chassis-id\":\"e4:f0:04:fe:64:e1\",\"chassis-id-type\":\"MAC_ADDRESS\",\"id\":\"1\",\"management-address\":\"\",\"port-description\":\"ethernet1/1/9\",\"port-id\":\"ethernet1/1/9\",\"port-id-type\":\"INTERFACE_NAME\",\"system-description\":\"Dell EMC Networking OS10-Enterprise.\\r\\nCopyright (c) 1999-2019 by Dell Inc. All Rights Reserved.\\r\\nSystem Description: OS10 Enterprise.\\r\\nOS Version: 10.4.3.1.\\r\\nSystem Type: S4148T-ON\",\"system-name\":\"swtor-b2lab2-1409\",\"ttl\":1371}}]}}]} 2 | -------------------------------------------------------------------------------- /translib/test/platform/01_get_all_components.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-platform:components -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/platform/01_get_all_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-platform:components\":{\"component\":[{\"name\":\"System Eeprom\",\"state\":{\"empty\":false,\"hardware-version\":\"A00\",\"id\":\"S6000-ON\",\"location\":\"Slot 1\",\"mfg-name\":\"Dell\",\"name\" :\"System Eeprom\",\"oper-status\":\"openconfig-platform-types:ACTIVE\",\"part-no\":\"08YWFG\",\"removable\":false,\"serial-no\":\"CN08YWFG282983AR0146A00\"}}]}} 2 | -------------------------------------------------------------------------------- /translib/test/platform/02_get_one_component.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-platform:components/component -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/platform/02_get_one_component_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-platform:component\":[{\"name\":\"System Eeprom\",\"state\":{\"empty\":false,\"hardware-version\":\"A00\",\"id\":\"S6000-ON\",\"location\":\"Slot 1\",\"mfg-name\":\"Dell\",\"name\":\"System Eeprom\",\"oper-status\":\"openconfig-platform-types:ACTIVE\",\"part-no\":\"08YWFG\",\"removable\":false,\"serial-no\":\"CN08YWFG282983AR0146A00\"}}]} 2 | -------------------------------------------------------------------------------- /translib/test/platform/03_get_component_attribute_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-platform:components/component[name="System Eeprom"] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/platform/03_get_component_attribute_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-platform:name\":\"System Eeprom\",\"openconfig-platform:state\":{\"empty\":false,\"hardware-version\":\"A00\",\"id\":\"S6000-ON\",\"location\":\"Slot 1\",\"mfg-name\":\"Dell\",\"name\":\"System Eeprom\",\"oper-status\":\"openconfig-platform-types:ACTIVE\",\"part-no\":\"08YWFG\",\"removable\":false,\"serial-no\":\"CN08YWFG282983AR0146A00\"}} 2 | -------------------------------------------------------------------------------- /translib/test/system/01_get_all_components.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/02_get_system_state_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/state -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/02_get_system_state_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-system:state\":{\"boot-time\":\"1565051365\",\"current-datetime\":\"2019-08-06T22:55:26Z+00:00\",\"hostname\":\"sonic\"}} 2 | -------------------------------------------------------------------------------- /translib/test/system/03_get_system_memory_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/memory -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/03_get_system_memory_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-system:memory\":{\"state\":{\"physical\":\"8162872\",\"reserved\":\"1332456\"}}} 2 | -------------------------------------------------------------------------------- /translib/test/system/04_get_system_cpus_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/cpus -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/04_get_system_cpus_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-system:cpus\":{\"cpu\":[{\"index\":0,\"state\":{\"idle\":{\"instant\":62},\"kernel\":{\"instant\":17},\"user\":{\"instant\":17}}},{\"index\":1,\"state\":{\"idle\":{\"instant\":62},\"kernel\":{\"instant\":17},\"user\":{\"instant\":16}}},{\"index\":2,\"state\":{\"idle\":{\"instant\":62},\"kernel\":{\"instant\":17},\"user\":{\"instant\":17}}},{\"index\":3,\"state\":{\"idle\":{\"instant\":63},\"kernel\":{\"instant\":17},\"user\":{\"instant\":17}}},{\"index\":4,\"state\":{\"idle\":{\"instant\":63},\"kernel\":{\"instant\":17},\"user\":{\"instant\":17}}}]}} 2 | -------------------------------------------------------------------------------- /translib/test/system/05_get_system_processes_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/processes -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/06_get_system_processes_pid_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/processes/process[pid=1] -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/06_get_system_processes_pid_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-system:process\":[{\"pid\":\"1\",\"state\":{\"cpu-usage-system\":\"601\",\"cpu-usage-user\":\"543\",\"cpu-utilization\":0,\"memory-usage\":\"58884096\",\"memory-utilization\":0,\"name\":\"/sbin/init\",\"pid\":\"1\",\"start-time\":\"1565051366000000000\"}}]} 2 | -------------------------------------------------------------------------------- /translib/test/system/07_get_system_processes_pid_attribute_command.txt: -------------------------------------------------------------------------------- 1 | ./gnmi_get -xpath /openconfig-system:system/pid=1]/state/name -target_addr 127.0.0.1:8080 -alsologtostderr -insecure true -pretty 2 | -------------------------------------------------------------------------------- /translib/test/system/07_get_system_processes_pid_attribute_response.json: -------------------------------------------------------------------------------- 1 | {\"openconfig-system:process\":[{\"pid\":\"1\",\"state\":{\"cpu-usage-system\":\"662\",\"cpu-usage-user\":\"638\",\"cpu-utilization\":0,\"memory-usage\":\"58761216\",\"memory-utilization\":0,\"name\":\"/sbin/init\",\"pid\":\"1\",\"start-time\":\"1563911114000000000\"}}]} 2 | -------------------------------------------------------------------------------- /translib/transformer/host_comm.go: -------------------------------------------------------------------------------- 1 | package transformer 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/godbus/dbus/v5" 7 | log "github.com/golang/glog" 8 | ) 9 | 10 | // HostResult contains the body of the response and the error if any, when the 11 | // endpoint finishes servicing the D-Bus request. 12 | type HostResult struct { 13 | Body []interface{} 14 | Err error 15 | } 16 | 17 | // HostQuery calls the corresponding D-Bus endpoint on the host and returns 18 | // any error and response body 19 | func HostQuery(endpoint string, args ...interface{}) (result HostResult) { 20 | log.Infof("HostQuery called") 21 | result_ch, err := hostQueryAsync(endpoint, args...) 22 | 23 | if err != nil { 24 | result.Err = err 25 | return 26 | } 27 | 28 | result = <-result_ch 29 | return 30 | } 31 | 32 | // hostQueryAsync calls the corresponding D-Bus endpoint on the host and returns 33 | // a channel for the result, and any error 34 | func hostQueryAsync(endpoint string, args ...interface{}) (chan HostResult, error) { 35 | log.Infof("HostQueryAsync called") 36 | var result_ch = make(chan HostResult, 1) 37 | conn, err := dbus.SystemBus() 38 | if err != nil { 39 | return result_ch, err 40 | } 41 | log.Infof("HostQueryAsync conn established") 42 | 43 | service := strings.SplitN(endpoint, ".", 2) 44 | const bus_name_base = "org.SONiC.HostService." 45 | bus_name := bus_name_base + service[0] 46 | bus_path := dbus.ObjectPath("/org/SONiC/HostService/" + service[0]) 47 | 48 | obj := conn.Object(bus_name, bus_path) 49 | dest := bus_name_base + endpoint 50 | dbus_ch := make(chan *dbus.Call, 1) 51 | //log.Infof("HostQueryAsync dbus called %s "% string(bus_path)) 52 | //log.Infof("HostQueryAsync dbus called %s "% string(bus_name)) 53 | 54 | go func() { 55 | var result HostResult 56 | 57 | // Wait for a read on the channel 58 | call := <-dbus_ch 59 | 60 | if call.Err != nil { 61 | log.Infof("HostQueryAsync Err is not nill while reading") 62 | result.Err = call.Err 63 | } else { 64 | log.Infof("HostQueryAsync Body is taken") 65 | result.Body = call.Body 66 | } 67 | 68 | // Write the result to the channel 69 | result_ch <- result 70 | }() 71 | 72 | log.Infof("HostQueryAsync Before objgo") 73 | call := obj.Go(dest, 0, dbus_ch, args...) 74 | 75 | if call.Err != nil { 76 | log.Infof("HostQueryAsync Err is not after obj.Go") 77 | return result_ch, call.Err 78 | } 79 | 80 | return result_ch, nil 81 | } 82 | -------------------------------------------------------------------------------- /translib/transformer/test/README.md: -------------------------------------------------------------------------------- 1 | # Transformer Infra Unit Testing 2 | 3 | Following are the instructions on how to build and execute transformer infra unit test. 4 | The transformer folder (sonic-mgmt-common/translib/transformer) contains all the necessary source code files that includes transformer unit test framework files, callbacks to serve the annotations, transformer infra unit-test file to exercise the transformer-translations.The test folder (sonic-mgmt-common/translib/transformer/test) contains the test-yangs and annotations. All these files are needed to build and execute transformer infra test binary. 5 | 6 | Note: The transformer infra unit test files will use the build tag "xfmrtest". Other applications writing unit test cases will use the build tag "testapp". This is required to separate the app unit tests from transformer infra unit test files and not have the app tests duplicated in both the binaries if missing the correct build tag. The app unit test binary and transformer infra unit test binary are both added to the azure pipeline and will be run separately. 7 | 8 | * Generate transformer.test by building sonic-mgmt-common with the MAKE flag INCLUDE_TEST_MODELS=y to have the test yangs built 9 | * Copy the openconfig-test-xfmr.yang, openconfig-test-xfmr-annot.yang, sonic-test-xfmr.yang, sonic-test-xfmr-annot.yang to mgmt-framework docker /usr/models/yang directory 10 | * Edit the models_list file in mgmt-framework docker /usr/models/yang directory to include openconfig-test-xfmr.yang, openconfig-test-xfmr-annot.yang and sonic-test-xfmr-annot.yang files 11 | * Copy the sonic-test-xfmr.yin file from sonic-mgmtcommon/build/cvl/schema/ to /usr/sbin/schema/ in mgmt-framework docker 12 | * Copy the transformer.test binary to mgmt-framework docker in /usr/sbin directory and then execute : 13 | ```shell 14 | (./transformer.test -test.v -test.coverprofile=transformer.cover -logtostderr -v=5 | tee transformer.out ) >& transformer.log 15 | ``` 16 | * View the results in file transformer.out (All test-cases should have PASS prefix) 17 | * View the transformer.log file to view debug logs for debugging the test-case failures if any. 18 | -------------------------------------------------------------------------------- /translib/transformer/test/sonic-test-xfmr-annot.yang: -------------------------------------------------------------------------------- 1 | module sonic-test-xfmr-annot { 2 | 3 | yang-version "1"; 4 | 5 | namespace "http://openconfig.net/yang/annotation/sonic-test-xfmr-annot"; 6 | prefix "sonic-test-xfmr-annot"; 7 | 8 | import sonic-test-xfmr { prefix sonic-test-xfmr; } 9 | 10 | deviation /sonic-test-xfmr:sonic-test-xfmr/sonic-test-xfmr:TEST_SENSOR_MODE_TABLE/sonic-test-xfmr:TEST_SENSOR_MODE_TABLE_LIST { 11 | deviate add { 12 | sonic-ext:key-transformer "test_sensor_mode_key_xfmr"; 13 | } 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /translib/transformer/transformer.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonic-net/sonic-mgmt-common/bb0e47d3e6eb98a27b386636da91a7bfb4ecefbc/translib/transformer/transformer.test -------------------------------------------------------------------------------- /translib/transformer/xconst.go: -------------------------------------------------------------------------------- 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 | package transformer 20 | 21 | const ( 22 | XPATH_SEP_FWD_SLASH = "/" 23 | XFMR_EMPTY_STRING = "" 24 | XFMR_NONE_STRING = "NONE" 25 | SONIC_TABLE_INDEX = 2 26 | SONIC_TBL_CHILD_INDEX = 3 27 | SONIC_FIELD_INDEX = 4 28 | SONIC_NESTEDLIST_FIELD_INDEX = 5 29 | SONIC_TOPCONTR_INDEX = 1 30 | SONIC_MDL_PFX = "sonic" 31 | OC_MDL_PFX = "openconfig-" 32 | IETF_MDL_PFX = "ietf-" 33 | IANA_MDL_PFX = "iana-" 34 | PATH_XFMR_RET_ARGS = 1 35 | PATH_XFMR_RET_ERR_INDX = 0 36 | 37 | YANG_CONTAINER_NM_CONFIG = "config" 38 | CONFIG_CNT_SUFFIXED_XPATH = "/config" 39 | STATE_CNT_SUFFIXED_XPATH = "/state" 40 | CONFIG_CNT_WITHIN_XPATH = "/config/" 41 | STATE_CNT_WITHIN_XPATH = "/state/" 42 | ) 43 | 44 | const ( 45 | YANG_MODULE yangElementType = iota + 1 46 | YANG_LIST 47 | YANG_CONTAINER 48 | YANG_LEAF 49 | YANG_LEAF_LIST 50 | YANG_CHOICE 51 | YANG_CASE 52 | YANG_RPC 53 | YANG_NOTIF 54 | ) 55 | const ( 56 | XFMR_INVALID = iota - 1 57 | XFMR_DISABLE 58 | XFMR_ENABLE 59 | XFMR_DEFAULT_ENABLE 60 | ) 61 | 62 | const ( 63 | QUERY_CONTENT_ALL ContentType = iota 64 | QUERY_CONTENT_CONFIG 65 | QUERY_CONTENT_NONCONFIG 66 | QUERY_CONTENT_OPERATIONAL 67 | ) 68 | 69 | const ( 70 | QUERY_CONTENT_MISMATCH_ERR = "Query Parameter Content mismatch" 71 | QUERY_PARAMETER_SBT_PRUNING_ERR = "Query Parameter processing unsuccessful" 72 | ) 73 | 74 | const ( 75 | GET Operation = iota + 1 76 | CREATE 77 | REPLACE 78 | UPDATE 79 | DELETE 80 | SUBSCRIBE 81 | MAXOPER 82 | ) 83 | -------------------------------------------------------------------------------- /translib/transformer/xfmr_dbtbl_cbk_interface.go: -------------------------------------------------------------------------------- 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 | package transformer 20 | 21 | import ( 22 | "fmt" 23 | 24 | "github.com/Azure/sonic-mgmt-common/translib/db" 25 | ) 26 | 27 | type XfmrDbTblCbkParams struct { 28 | d *db.DB //Config DB handler 29 | oper Operation 30 | delDepRefKey string 31 | tblName string 32 | dbKey string 33 | delDepEntry map[string]string 34 | dbDataMap map[db.DBNum]map[string]map[string]db.Value 35 | delDepDataMap map[Operation]*RedisDbMap // Call back methods can add the data 36 | } 37 | 38 | func (inPm XfmrDbTblCbkParams) String() string { 39 | return fmt.Sprintf("{d: %v, oper: %v, delDepRefKey: %v, tblName: %v, dbKey: %v, delDepEntry: %v, dbDataMap: %v, delDepDataMap: %v}", 40 | inPm.d, inPm.oper, inPm.delDepRefKey, inPm.tblName, inPm.dbKey, inPm.delDepEntry, inPm.dbDataMap, inPm.delDepDataMap) 41 | } 42 | 43 | func formXfmrDbTblCbkParams(d *db.DB, oper Operation, delDepRefKey string, tblName string, dbKey string, delDepEntry map[string]string, dbDataMap RedisDbMap) XfmrDbTblCbkParams { 44 | 45 | var inParams XfmrDbTblCbkParams 46 | 47 | inParams.d = d 48 | inParams.oper = oper 49 | inParams.delDepRefKey = delDepRefKey 50 | inParams.tblName = tblName 51 | inParams.dbKey = dbKey 52 | inParams.delDepEntry = delDepEntry 53 | inParams.dbDataMap = dbDataMap 54 | inParams.delDepDataMap = make(map[Operation]*RedisDbMap) 55 | 56 | return inParams 57 | } 58 | 59 | type XfmrDbTblCbkMethod func(inParams XfmrDbTblCbkParams) error 60 | -------------------------------------------------------------------------------- /translib/transformer/xlate_prune_stats.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2021 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 transformer 21 | 22 | import ( 23 | "fmt" 24 | "time" 25 | ) 26 | 27 | type PruneQPStats struct { 28 | Hits uint `json:"hits"` 29 | 30 | Time time.Duration `json:"total-time"` 31 | Peak time.Duration `json:"peak-time"` 32 | Last time.Duration `json:"last-time"` 33 | 34 | PeakUri string `json:"peak-uri"` 35 | LastUri string `json:"last-uri"` 36 | } 37 | 38 | var pruneQPStats PruneQPStats 39 | var zeroPruneQPStats = &PruneQPStats{} 40 | 41 | func GetPruneQPStats() *PruneQPStats { 42 | return &pruneQPStats 43 | } 44 | 45 | func (pqps *PruneQPStats) ClearPruneQPStats() { 46 | if pqps != nil { 47 | *pqps = *zeroPruneQPStats 48 | } 49 | } 50 | 51 | func (pqps *PruneQPStats) String() string { 52 | return fmt.Sprintf("\tLastTime: %s LastUri: %s Hits: %d TotalTime: %s PeakTime: %s PeakUri: %s\n", 53 | pqps.Last, pqps.LastUri, pqps.Hits, pqps.Time, pqps.Peak, pqps.PeakUri) 54 | } 55 | 56 | func (pqps *PruneQPStats) add(t time.Duration, uri string) { 57 | pqps.Hits++ 58 | pqps.Last = t 59 | pqps.LastUri = uri 60 | pqps.Time += t 61 | if t > pqps.Peak { 62 | pqps.Peak = t 63 | pqps.PeakUri = uri 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /translib/translib_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 translib_test 21 | 22 | import ( 23 | "fmt" 24 | "path/filepath" 25 | "reflect" 26 | "runtime" 27 | "testing" 28 | ) 29 | 30 | // assert fails the test if the condition is false. 31 | func assert(tb testing.TB, condition bool, msg string, v ...interface{}) { 32 | if !condition { 33 | _, file, line, _ := runtime.Caller(1) 34 | fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) 35 | tb.FailNow() 36 | } 37 | } 38 | 39 | // ok fails the test if an err is not nil. 40 | func ok(tb testing.TB, err error) { 41 | if err != nil { 42 | _, file, line, _ := runtime.Caller(1) 43 | fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) 44 | tb.FailNow() 45 | } 46 | } 47 | 48 | // equals fails the test if exp is not equal to act. 49 | func equals(tb testing.TB, exp, act interface{}) { 50 | if !reflect.DeepEqual(exp, act) { 51 | _, file, line, _ := runtime.Caller(1) 52 | fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) 53 | tb.FailNow() 54 | } 55 | } 56 | 57 | func Test_Create(t *testing.T) { 58 | 59 | } 60 | -------------------------------------------------------------------------------- /translib/utils/bits.go: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // Copyright 2021 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 utils 21 | 22 | import "fmt" 23 | 24 | // Bits is a set of 8 bit flags. 25 | type Bits uint8 26 | 27 | // Set operations sets given bit flags into b 28 | func (b *Bits) Set(flags Bits) { 29 | *b |= flags 30 | } 31 | 32 | // Unset operations clears given bit flags from b 33 | func (b *Bits) Unset(flags Bits) { 34 | *b &^= flags 35 | } 36 | 37 | // Reset operations clears all bits from b 38 | func (b *Bits) Reset() { 39 | *b = 0 40 | } 41 | 42 | // Empty returns true if no bits are set in b 43 | func (b Bits) Empty() bool { 44 | return b != 0 45 | } 46 | 47 | // Has returns true if all flags are present in b 48 | func (b Bits) Has(flags Bits) bool { 49 | return (b & flags) == flags 50 | } 51 | 52 | // HasAny returns true if any of the flags is present in b 53 | func (b Bits) HasAny(flags Bits) bool { 54 | return (b & flags) != 0 55 | } 56 | 57 | func (b Bits) String() string { 58 | return fmt.Sprintf("%08b", b) 59 | } 60 | -------------------------------------------------------------------------------- /translib/utils/utils.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 utils 21 | 22 | import ( 23 | "fmt" 24 | //"github.com/Azure/sonic-mgmt-common/translib/db" 25 | "github.com/Azure/sonic-mgmt-common/cvl" 26 | "github.com/Azure/sonic-mgmt-common/translib/db" 27 | log "github.com/golang/glog" 28 | ) 29 | 30 | // SortAsPerTblDeps - sort transformer result table list based on dependencies (using CVL API) tables to be used for CRUD operations 31 | func SortAsPerTblDeps(tblLst []string) ([]string, error) { 32 | var resultTblLst []string 33 | var err error 34 | logStr := "Failure in CVL API to sort table list as per dependencies." 35 | 36 | cvSess, cvlRetSess := db.NewValidationSession() 37 | if cvlRetSess != nil { 38 | log.Errorf("Failure in creating CVL validation session object required to use CVl API(sort table list as per dependencies) - %v", cvlRetSess) 39 | err = fmt.Errorf("%v", logStr) 40 | return resultTblLst, err 41 | } 42 | cvlSortDepTblList, cvlRetDepTbl := cvSess.SortDepTables(tblLst) 43 | if cvlRetDepTbl != cvl.CVL_SUCCESS { 44 | log.Warningf("Failure in cvlSess.SortDepTables: %v", cvlRetDepTbl) 45 | cvl.ValidationSessClose(cvSess) 46 | err = fmt.Errorf("%v", logStr) 47 | return resultTblLst, err 48 | } 49 | log.Info("cvlSortDepTblList = ", cvlSortDepTblList) 50 | resultTblLst = cvlSortDepTblList 51 | 52 | cvl.ValidationSessClose(cvSess) 53 | return resultTblLst, err 54 | 55 | } 56 | 57 | // RemoveElement - Remove a specific string from a list of strings 58 | func RemoveElement(sl []string, str string) []string { 59 | for i := 0; i < len(sl); i++ { 60 | if sl[i] == str { 61 | sl = append(sl[:i], sl[i+1:]...) 62 | i-- 63 | break 64 | } 65 | } 66 | return sl 67 | } 68 | --------------------------------------------------------------------------------