diff --git a/src/sonic-yang-mgmt/sonic_yang_ext.py b/src/sonic-yang-mgmt/sonic_yang_ext.py index 1f0a072be450..e85cdb42ff0f 100644 --- a/src/sonic-yang-mgmt/sonic_yang_ext.py +++ b/src/sonic-yang-mgmt/sonic_yang_ext.py @@ -377,7 +377,8 @@ def _xlateContainer(self, model, yang, config, table): ## Handle other leaves in container, leafDict = self._createLeafDict(model) - for vKey in configC.keys(): + vKeys = list(configC.keys()) + for vKey in vKeys: #vkey must be a leaf\leaf-list\choice in container if leafDict.get(vKey): self.sysLog(syslog.LOG_DEBUG, "xlateContainer vkey {}".format(vKey)) diff --git a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py index 597d13da0874..b761cd994c1d 100644 --- a/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py +++ b/src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py @@ -288,10 +288,13 @@ def test_xlate_rev_xlate(self, sonic_yang_data): syc = sonic_yang_data['syc'] jIn = self.readIjsonInput(test_file, 'SAMPLE_CONFIG_DB_JSON') + jIn = json.loads(jIn) + numTables = len(jIn) - syc.loadData(json.loads(jIn)) - - # TODO: Make sure no extra table is loaded + syc.loadData(jIn) + # check all tables are loaded and no tables is without Yang Models + assert len(syc.jIn) == numTables + assert len(syc.tablesWithOutYang) == 0 syc.getData() diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 4ba9fd61c92a..e651bb0d377d 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -41,13 +41,19 @@ packages=find_packages(), version='1.0', data_files=[ - ('yang-models', ['./yang-models/sonic-types.yang', + ('yang-models', ['./yang-models/sonic-acl.yang', + './yang-models/sonic-breakout_cfg.yang', + './yang-models/sonic-crm.yang', + './yang-models/sonic-device_metadata.yang', + './yang-models/sonic-device_neighbor.yang', './yang-models/sonic-extension.yang', - './yang-models/sonic-acl.yang', + './yang-models/sonic-flex_counter.yang', './yang-models/sonic-interface.yang', './yang-models/sonic-loopback-interface.yang', './yang-models/sonic-port.yang', './yang-models/sonic-portchannel.yang', + './yang-models/sonic-types.yang', + './yang-models/sonic-versions.yang', './yang-models/sonic-vlan.yang', './yang-models/sonic_yang_tree']), ], diff --git a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py index 966af237f272..3bc2886f38c7 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py +++ b/src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py @@ -125,6 +125,10 @@ def initTest(self): 'desc': 'Loopback Ip-prefix port-name must condition failure.', 'eStr': self.defaultYANGFailure['Must'] }, + 'CRM_BRK_CFG_FLEX_TABLE': { + 'desc': 'CRM BREAKOUT CFG FLEX COUNTER TABLE.', + 'eStr': self.defaultYANGFailure['None'] + }, 'INCORRECT_VLAN_NAME': { 'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.', 'eStr': self.defaultYANGFailure['Pattern'] + ["Vlan"] @@ -168,6 +172,52 @@ def initTest(self): 'PORT_NEG_TEST': { 'desc': 'LOAD PORT TABLE FEC PATTERN FAILURE', 'eStr': self.defaultYANGFailure['Pattern'] + ['rc'] + }, + 'CRM_WITH_WRONG_PERCENTAGE': { + 'desc': 'CRM_WITH_WRONG_PERCENTAGE must condition failure.', + 'eStr': self.defaultYANGFailure['Must'] + }, + 'CRM_WITH_HIGH_THRESHOLD_ERR': { + 'desc': 'CRM_WITH_HIGH_THRESHOLD_ERR must condition failure \ + about high threshold being lower than low threshold.', + 'eStr': self.defaultYANGFailure['high_threshold should be more \ + than low_threshold'] + }, + 'CRM_WITH_CORRECT_USED_VALUE': { + 'desc': 'CRM_WITH_CORRECT_USED_VALUE no failure.', + 'eStr': self.defaultYANGFailure['None'] + }, + 'FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE': { + 'desc': 'FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE no failure.', + 'eStr': self.defaultYANGFailure['None'] + }, + 'VERSIONS_WITH_INCORRECT_PATTERN': { + 'desc': 'VERSIONS_WITH_INCORRECT_PATTERN pattern failure.', + 'eStr': self.defaultYANGFailure['Pattern'] + }, + 'VERSIONS_WITH_INCORRECT_PATTERN2': { + 'desc': 'VERSIONS_WITH_INCORRECT_PATTERN pattern failure.', + 'eStr': self.defaultYANGFailure['Pattern'] + }, + 'DEVICE_METADATA_DEFAULT_BGP_STATUS': { + 'desc': 'DEVICE_METADATA DEFAULT VALUE FOR BGP_STATUS FIELD.', + 'eStr': self.defaultYANGFailure['Verify'], + 'verify': {'xpath': '/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname', + 'key': 'sonic-device_metadata:default_bgp_status', + 'value': 'up' + } + }, + 'DEVICE_METADATA_DEFAULT_PFCWD_STATUS': { + 'desc': 'DEVICE_METADATA DEFAULT VALUE FOR PFCWD FIELD.', + 'eStr': self.defaultYANGFailure['Verify'], + 'verify': {'xpath': '/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname', + 'key': 'sonic-device_metadata:default_pfcwd_status', + 'value': 'disable' + } + }, + 'DEVICE_METADATA_TYPE_INCORRECT_PATTERN': { + 'desc': 'DEVICE_METADATA_TYPE_INCORRECT_PATTERN pattern failure.', + 'eStr': self.defaultYANGFailure['Pattern'] } } @@ -260,20 +310,20 @@ def loadConfigData(self, jInput, verify=None): # verify the data tree if asked if verify is not None: xpath = verify['xpath'] - log.debug("Verify xpath: {}".format(xpath)) + log.info("Verify xpath: {}".format(xpath)) set = node.find_path(xpath) for dnode in set.data(): if (xpath == dnode.path()): - log.debug("Verify dnode: {}".format(dnode.path())) + log.info("Verify dnode: {}".format(dnode.path())) data = dnode.print_mem(ly.LYD_JSON, ly.LYP_WITHSIBLINGS \ | ly.LYP_FORMAT | ly.LYP_WD_ALL) data = json.loads(data) - log.debug("Verify data: {}".format(data)) + log.info("Verify data: {}".format(data)) assert (data[verify['key']] == verify['value']) s = 'verified' except Exception as e: s = str(e) - log.debug(s) + log.info(s) return s """ @@ -294,7 +344,7 @@ def runExceptionTest(self, test): log.info(desc + " Passed\n") return PASS else: - raise Exception("Unknown Error") + raise Exception("Mismatch {} and {}".format(eStr, s)) except Exception as e: printExceptionDetails() log.info(desc + " Failed\n") @@ -336,10 +386,10 @@ def runVlanSpecialTest(self, test): Run all tests from list self.tests """ def test_run_tests(self): + ret = 0 try: self.initTest() self.loadYangModel(self.yangDir) - ret = 0 for test in self.tests: test = test.strip() if test in self.ExceptionTests: @@ -350,6 +400,7 @@ def test_run_tests(self): raise Exception("Unexpected Test") except Exception as e: printExceptionDetails() + assert ret == 0 return # End of Class diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index 72c7b4630c33..90d748309dca 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -727,6 +727,218 @@ } } }, + + "CRM_WITH_WRONG_PERCENTAGE": { + "sonic-crm:sonic-crm": { + "sonic-crm:CRM": { + "Config": { + "acl_counter_high_threshold": 110, + "acl_counter_low_threshold": 85, + "acl_counter_threshold_type": "PERCENTAGE" + } + } + } + }, + + "CRM_WITH_HIGH_THRESHOLD_ERR": { + "sonic-crm:sonic-crm": { + "sonic-crm:CRM": { + "Config": { + "acl_counter_high_threshold": 80, + "acl_counter_low_threshold": 81, + "acl_counter_threshold_type": "PERCENTAGE" + } + } + } + }, + + "CRM_WITH_WRONG_THRESHOLD": { + "sonic-crm:sonic-crm": { + "sonic-crm:CRM": { + "Config": { + "acl_counter_high_threshold": 85, + "acl_counter_low_threshold": 90, + "acl_counter_threshold_type": "free" + } + } + } + }, + + "CRM_WITH_CORRECT_USED_VALUE": { + "sonic-crm:sonic-crm": { + "sonic-crm:CRM": { + "Config": { + "acl_counter_high_threshold": 85, + "acl_counter_low_threshold": 25, + "acl_counter_threshold_type": "used" + } + } + } + }, + + "DEVICE_METADATA_DEFAULT_BGP_STATUS": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "docker_routing_config_mode": "separated", + "platform": "Stone-DX010", + "hostname": "DUT-ASW", + "bgp_asn": "65000" + } + } + } + }, + + "DEVICE_METADATA_DEFAULT_PFCWD_STATUS": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "platform": "DX010", + "hostname": "DUT-CSW", + "bgp_asn": "65001" + } + } + } + }, + + "DEVICE_METADATA_TYPE_INCORRECT_PATTERN": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "bgp_asn": "65002", + "type": "ToRrouter" + } + } + } + }, + + "VERSIONS_WITH_INCORRECT_PATTERN": { + "sonic-versions:sonic-versions": { + "sonic-versions:VERSIONS": { + "DATABASE": { + "VERSION": "version_1_2" + } + } + } + }, + + "VERSIONS_WITH_INCORRECT_PATTERN2": { + "sonic-versions:sonic-versions": { + "sonic-versions:VERSIONS": { + "DATABASE": { + "VERSION": "version_0_2_77" + } + } + } + }, + + "FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE": { + "sonic-flex_counter:sonic-flex_counter": { + "sonic-flex_counter:FLEX_COUNTER_TABLE": { + "PFCWD": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PG_WATERMARK": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PORT": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PORT_RATES": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PORT_BUFFER_DROP": { + "FLEX_COUNTER_STATUS": "enable" + }, + "BUFFER_POOL_WATERMARK_KEY": { + "FLEX_COUNTER_STATUS": "enable" + }, + "QUEUE": { + "FLEX_COUNTER_STATUS": "enable" + }, + "QUEUE_WATERMARK": { + "FLEX_COUNTER_STATUS": "enable" + }, + "DEBUG_COUNTER": { + "FLEX_COUNTER_STATUS": "enable" + } + } + } + }, + "CRM_BRK_CFG_FLEX_TABLE": { + "sonic-crm:sonic-crm": { + "sonic-crm:CRM": { + "Config": { + "acl_counter_low_threshold": "70", + "acl_counter_high_threshold": "85", + "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "67", + "ipv6_neighbor_low_threshold": "56", + "ipv6_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "67", + "nexthop_group_low_threshold": "56", + "nexthop_group_threshold_type": "percentage", + "polling_interval": "0" + } + } + }, + "sonic-breakout_cfg:sonic-breakout_cfg": { + "sonic-breakout_cfg:BREAKOUT_CFG": { + "BREAKOUT_CFG_LIST": [ + { + "brkout_mode": "1x100G[40G]", + "port": "Ethernet0" + }, + { + "brkout_mode": "4x25G[10G]", + "port": "Ethernet8" + }, + { + "brkout_mode": "2x25G(2)+1x50G(2)", + "port": "Ethernet4" + }, + { + "brkout_mode": "1x400G", + "port": "Ethernet12" + }, + { + "brkout_mode": "2x200G", + "port": "Ethernet16" + }, + { + "brkout_mode": "4x100G", + "port": "Ethernet20" + }, + { + "brkout_mode": "8x50G", + "port": "Ethernet24" + } + ] + } + }, + "sonic-flex_counter:sonic-flex_counter": { + "sonic-flex_counter:FLEX_COUNTER_TABLE": { + "QUEUE": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PG_WATERMARK": { + "FLEX_COUNTER_STATUS": "enable" + }, + "QUEUE_WATERMARK": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PFCWD": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PORT": { + "FLEX_COUNTER_STATUS": "enable" + }, + "DEBUG_COUNTER": { + "FLEX_COUNTER_STATUS": "enable" + } + } + } + }, "ACL_RULE_WRONG_INNER_ETHER_TYPE": { "sonic-acl:sonic-acl": { "sonic-acl:ACL_RULE": { @@ -962,7 +1174,7 @@ }, "DEVICE_METADATA": { "localhost": { - "type": "ToR", + "type": "ToRRouter", "mac": "00:11:22:33:dd:5a", "hostname": "asw.dc", "bgp_asn": "64850", @@ -1450,7 +1662,7 @@ "brkout_mode": "1x100G[40G]" }, "Ethernet4": { - "brkout_mode": "4x25G" + "brkout_mode": "4x25G[10G]" }, "Ethernet8": { "brkout_mode": "1x100G[40G]" @@ -1471,11 +1683,23 @@ "PORT": { "FLEX_COUNTER_STATUS": "enable" }, + "PORT_RATES": { + "FLEX_COUNTER_STATUS": "enable" + }, + "PORT_BUFFER_DROP": { + "FLEX_COUNTER_STATUS": "enable" + }, + "BUFFER_POOL_WATERMARK_KEY": { + "FLEX_COUNTER_STATUS": "enable" + }, "QUEUE": { "FLEX_COUNTER_STATUS": "enable" }, "QUEUE_WATERMARK": { "FLEX_COUNTER_STATUS": "enable" + }, + "DEBUG_COUNTER": { + "FLEX_COUNTER_STATUS": "enable" } }, "CRM": { @@ -1483,6 +1707,12 @@ "acl_counter_high_threshold": "85", "acl_counter_low_threshold": "70", "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "67", + "ipv6_neighbor_low_threshold": "56", + "ipv6_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "67", + "nexthop_group_low_threshold": "56", + "nexthop_group_threshold_type": "percentage", "polling_interval": "0" } } diff --git a/src/sonic-yang-models/yang-models/sonic-acl.yang b/src/sonic-yang-models/yang-models/sonic-acl.yang index dcddd247e1c1..3ac0abe8074d 100644 --- a/src/sonic-yang-models/yang-models/sonic-acl.yang +++ b/src/sonic-yang-models/yang-models/sonic-acl.yang @@ -5,10 +5,6 @@ module sonic-acl { namespace "http://github.com/Azure/sonic-acl"; prefix acl; - import ietf-yang-types { - prefix yang; - } - import ietf-inet-types { prefix inet; } diff --git a/src/sonic-yang-models/yang-models/sonic-breakout_cfg.yang b/src/sonic-yang-models/yang-models/sonic-breakout_cfg.yang new file mode 100644 index 000000000000..7cc13f1731c7 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-breakout_cfg.yang @@ -0,0 +1,64 @@ +module sonic-breakout_cfg { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-breakout_cfg"; + prefix breakout_cfg; + + import sonic-extension { + prefix ext; + revision-date 2019-07-01; + } + + description "BREAKOUT_CFG YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-breakout_cfg { + + container BREAKOUT_CFG { + + description "BREAKOUT_CFG part of config_db.json"; + + list BREAKOUT_CFG_LIST { + + key "port"; + + ext:key-regex-configdb-to-yang "^([a-zA-Z0-9_-]+)$"; + + ext:key-regex-yang-to-configdb ""; + + /* + * This is leaf instead of a leafref towards port, because this + * table will contains Parent ports and their current breakout-mode, + * irrespective of port is present in PORT table or not. Specially + * during Dynamic Port Breakout, Parent Port may not be present in + * PORT table. + */ + leaf port { + type string { + length 1..255; + } + } + + leaf brkout_mode { + type string { + length 1..64; + /* + * Below allowed patterns are based on most used Platforms, + * Add any other breakout-mode to allow Dynamic Port + * Breakout to that breakout-mode. + */ + pattern '1x100G\[40G\]|2x50G|4x25G\[10G\]|2x25G\(2\)\+1x50G\(2\)|1x50G\(2\)\+2x25G\(2\)|1x400G|2x200G|4x100G|8x50G'; + } + } + } + /* end of list BREAKOUT_CFG_LIST */ + } + /* end of container BREAKOUT_CFG */ + } + /* end of top level container */ +} +/* end of module sonic-breakout_cfg */ diff --git a/src/sonic-yang-models/yang-models/sonic-crm.yang b/src/sonic-yang-models/yang-models/sonic-crm.yang new file mode 100644 index 000000000000..cc53aa7f0d50 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-crm.yang @@ -0,0 +1,303 @@ +module sonic-crm { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-crm"; + prefix crm; + + import sonic-types { + prefix stypes; + revision-date 2019-07-01; + } + + description "CRM YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-crm { + + container CRM { + + description "CRM part of config_db.json"; + + container Config { + + /* typedef specific to CRM */ + typedef threshold { + type uint16; + } + + leaf acl_counter_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../acl_counter_high_threshold<100 and + ../acl_counter_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf acl_counter_high_threshold { + must "(current() > ../acl_counter_low_threshold)" + { + error-message "high_threshold should be more than low_threshold"; + } + type threshold; + } + + leaf acl_counter_low_threshold { + type threshold; + } + + leaf acl_group_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../acl_group_high_threshold<100 and + ../acl_group_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf acl_group_high_threshold { + must "(current() > ../acl_group_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf acl_group_low_threshold { + type threshold; + } + + leaf acl_entry_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../acl_entry_high_threshold<100 and + ../acl_entry_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf acl_entry_high_threshold { + must "(current() > ../acl_entry_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf acl_entry_low_threshold { + type threshold; + } + + leaf acl_table_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../acl_table_high_threshold<100 and + ../acl_table_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf acl_table_high_threshold { + must "(current() > ../acl_table_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf acl_table_low_threshold { + type threshold; + } + + leaf fdb_entry_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../fdb_entry_high_threshold<100 and + ../fdb_entry_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf fdb_entry_high_threshold { + must "(current() > ../fdb_entry_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf fdb_entry_low_threshold { + type threshold; + } + + leaf ipv4_neighbor_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv4_neighbor_high_threshold<100 and + ../ipv4_neighbor_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv4_neighbor_high_threshold { + must "(current() > ../ipv4_neighbor_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv4_neighbor_low_threshold { + type threshold; + } + + leaf ipv4_nexthop_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv4_nexthop_high_threshold<100 and + ../ipv4_nexthop_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv4_nexthop_high_threshold { + must "(current() > ../ipv4_nexthop_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv4_nexthop_low_threshold { + type threshold; + } + + leaf ipv4_route_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv4_route_high_threshold<100 and + ../ipv4_route_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv4_route_high_threshold { + must "(current() > ../ipv4_route_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv4_route_low_threshold { + type threshold; + } + + leaf ipv6_neighbor_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv6_neighbor_high_threshold<100 and + ../ipv6_neighbor_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv6_neighbor_high_threshold { + must "(current() > ../ipv6_neighbor_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv6_neighbor_low_threshold { + type threshold; + } + + leaf ipv6_nexthop_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv6_nexthop_high_threshold<100 and + ../ipv6_nexthop_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv6_nexthop_high_threshold { + must "(current() > ../ipv6_nexthop_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv6_nexthop_low_threshold { + type threshold; + } + + leaf ipv6_route_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../ipv6_route_high_threshold<100 and + ../ipv6_route_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf ipv6_route_high_threshold { + must "(current() > ../ipv6_route_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf ipv6_route_low_threshold { + type threshold; + } + + leaf nexthop_group_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../nexthop_group_high_threshold<100 and + ../nexthop_group_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf nexthop_group_high_threshold { + must "(current() > ../nexthop_group_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf nexthop_group_low_threshold { + type threshold; + } + + leaf nexthop_group_member_threshold_type { + must "(((current()='PERCENTAGE' or current()='percentage') and + ../nexthop_group_member_high_threshold<100 and + ../nexthop_group_member_low_threshold<100) or + (current()!='PERCENTAGE' and current()!='percentage'))"; + type stypes:crm_threshold_type; + } + + leaf nexthop_group_member_high_threshold { + must "(current() > ../nexthop_group_member_low_threshold)" + { + error-message "high_threshold should be more that low_threshold"; + } + type threshold; + } + + leaf nexthop_group_member_low_threshold { + type threshold; + } + + leaf polling_interval { + type threshold; + } + + } + /* end of Config */ + } + /* end of container CRM */ + } + /* end of top level container */ +} +/* end of module sonic-crm */ diff --git a/src/sonic-yang-models/yang-models/sonic-device_metadata.yang b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang new file mode 100644 index 000000000000..054b436f2470 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang @@ -0,0 +1,99 @@ +module sonic-device_metadata { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-device_metadata"; + prefix device_metadata; + + import ietf-yang-types { + prefix yang; + } + + import ietf-inet-types { + prefix inet; + } + + import sonic-types { + prefix stypes; + revision-date 2019-07-01; + } + + description "DEVICE_METADATA YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-device_metadata { + + container DEVICE_METADATA { + + description "DEVICE_METADATA part of config_db.json"; + + container localhost{ + + leaf hwsku { + type stypes:hwsku; + } + + leaf default_bgp_status { + type enumeration { + enum up; + enum down; + } + default up; + } + + leaf docker_routing_config_mode { + type string { + pattern "unified|split|separated"; + } + default "unified"; + } + + leaf hostname { + type string { + length 1..255; + } + } + + leaf platform { + type string { + length 1..255; + } + } + + leaf mac { + type yang:mac-address; + } + + leaf default_pfcwd_status { + type enumeration { + enum disable; + enum enable; + } + default disable; + } + + leaf bgp_asn { + type inet:as-number; + } + + leaf deployment_id { + type uint32; + } + + leaf type { + type string { + length 1..255; + pattern "ToRRouter|LeafRouter|SpineChassisFrontendRouter|ChassisBackendRouter|ASIC"; + } + } + } + /* end of container localhost */ + } + /* end of container DEVICE_METADATA */ + } + /* end of top level container */ +} +/* end of module sonic-device_metadata */ diff --git a/src/sonic-yang-models/yang-models/sonic-device_neighbor.yang b/src/sonic-yang-models/yang-models/sonic-device_neighbor.yang new file mode 100644 index 000000000000..c764940fd138 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-device_neighbor.yang @@ -0,0 +1,82 @@ +module sonic-device_neighbor { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-device_neighbor"; + prefix device_neighbor; + + import ietf-inet-types { + prefix inet; + } + + import sonic-extension { + prefix ext; + revision-date 2019-07-01; + } + + import sonic-port { + prefix port; + revision-date 2019-07-01; + } + + description "DEVICE_NEIGHBOR YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-device_neighbor { + + container DEVICE_NEIGHBOR { + + description "DEVICE_NEIGHBOR part of config_db.json"; + + list DEVICE_NEIGHBOR_LIST { + + key "peer_name"; + + ext:key-regex-configdb-to-yang "^([a-zA-Z0-9_-]+)$"; + + ext:key-regex-yang-to-configdb ""; + + leaf peer_name { + type string { + length 1..255; + } + } + + leaf name { + type string { + length 1..255; + } + } + + leaf mgmt_addr { + type inet:ip-address; + } + + leaf local_port { + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + } + + leaf port { + type string { + length 1..255; + } + } + + leaf type { + type string { + length 1..255; + } + } + } + /* end of list DEVICE_NEIGHBOR_LIST */ + } + /* end of container DEVICE_NEIGHBOR */ + } + /* end of top level container */ +} +/* end of module sonic-device_neighbor */ diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang new file mode 100644 index 000000000000..83b0512aeb21 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -0,0 +1,112 @@ +module sonic-flex_counter { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-flex_counter"; + prefix flex_counter; + + description "FLEX COUNTER YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-flex_counter { + + container FLEX_COUNTER_TABLE { + + /* typedef specific to FLEX_COUNTER_TABLE */ + typedef flex_status { + type enumeration { + enum enable; + enum disable; + } + } + + description "FLEX_COUNTER_TABLE part of config_db.json"; + + /* below are in alphabetical order */ + + container BUFFER_POOL_WATERMARK_KEY { + /* BUFFER_POOL_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container DEBUG_COUNTER { + /* DEBUG_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PFCWD { + /* PFC_WD_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PG_WATERMARK { + /* PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PORT { + /* PORT_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PORT_RATES { + /* PORT_BUFFER_DROP_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PORT_BUFFER_DROP { + /* PORT_BUFFER_DROP_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container QUEUE { + /* QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container QUEUE_WATERMARK { + /* QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container RIF { + /* RIF_STAT_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container RIF_RATES { + /* RIF_RATE_COUNTER_FLEX_COUNTER_GROUP */ + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + } + /* end of container FLEX_COUNTER_TABLE */ + } + /* end of top level container */ +} +/* end of module sonic-flex_counter */ diff --git a/src/sonic-yang-models/yang-models/sonic-interface.yang b/src/sonic-yang-models/yang-models/sonic-interface.yang index d47268be69f9..9585aabbb2c2 100644 --- a/src/sonic-yang-models/yang-models/sonic-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-interface.yang @@ -5,14 +5,6 @@ module sonic-interface { namespace "http://github.com/Azure/sonic-interface"; prefix intf; - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - import sonic-types { prefix stypes; revision-date 2019-07-01; diff --git a/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang b/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang index 6b509a8df349..1ed165d26c3b 100644 --- a/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang @@ -5,10 +5,6 @@ module sonic-loopback-interface { namespace "http://github.com/Azure/sonic-loopback-interface"; prefix lointf; - import ietf-inet-types { - prefix inet; - } - import sonic-types { prefix stypes; revision-date 2019-07-01; diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 574780dcf064..8a41d13f1a49 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -5,14 +5,6 @@ module sonic-port{ namespace "http://github.com/Azure/sonic-port"; prefix port; - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - import sonic-types { prefix stypes; revision-date 2019-07-01; diff --git a/src/sonic-yang-models/yang-models/sonic-portchannel.yang b/src/sonic-yang-models/yang-models/sonic-portchannel.yang index 8d27398c61e8..69c8fa6ac161 100644 --- a/src/sonic-yang-models/yang-models/sonic-portchannel.yang +++ b/src/sonic-yang-models/yang-models/sonic-portchannel.yang @@ -5,14 +5,6 @@ module sonic-portchannel { namespace "http://github.com/Azure/sonic-portchannel"; prefix lag; - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - import sonic-types { prefix stypes; revision-date 2019-07-01; diff --git a/src/sonic-yang-models/yang-models/sonic-types.yang b/src/sonic-yang-models/yang-models/sonic-types.yang index fb651847582e..0bfcddc56103 100644 --- a/src/sonic-yang-models/yang-models/sonic-types.yang +++ b/src/sonic-yang-models/yang-models/sonic-types.yang @@ -6,6 +6,10 @@ module sonic-types { prefix sonic-types; description "SONiC type for yang Models of SONiC OS"; + /* + * Try to define only sonic specific types here. Rest can be written in + * respective YANG files. + */ revision 2019-07-01 { description "First Revision"; @@ -82,6 +86,13 @@ module sonic-types { } } + typedef hwsku { + type string { + length 1..255; + /* Should we list all hwsku here */ + } + } + typedef vlan_tagging_mode { type enumeration { enum tagged; @@ -89,4 +100,11 @@ module sonic-types { enum priority_tagged; } } + + typedef crm_threshold_type { + type string { + length 1..64; + pattern "percentage|used|free|PERCENTAGE|USED|FREE"; + } + } } diff --git a/src/sonic-yang-models/yang-models/sonic-versions.yang b/src/sonic-yang-models/yang-models/sonic-versions.yang new file mode 100644 index 000000000000..156102122706 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-versions.yang @@ -0,0 +1,36 @@ +module sonic-versions { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-versions"; + prefix versions; + + + description "VERSIONS YANG Module for SONiC OS"; + + revision 2020-04-10 { + description "First Revision"; + } + + container sonic-versions { + + container VERSIONS { + + description "DATABASE SCHEMA VERSIONS part of config_db.json"; + + container DATABASE { + + leaf VERSION { + type string { + length 1..255; + pattern 'version_([1-9]|[1-9]{1}[0-9]{1})_([0-9]{1,2})_([0-9]{1,2})'; + } + } + } + /* end of container DATABASE */ + } + /* end of container VERSIONS */ + } + /* end of top level container */ +} +/* end of module sonic-versions */ diff --git a/src/sonic-yang-models/yang-models/sonic-vlan.yang b/src/sonic-yang-models/yang-models/sonic-vlan.yang index 6d2b9b154cbe..d00e68b39029 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -5,10 +5,6 @@ module sonic-vlan { namespace "http://github.com/Azure/sonic-vlan"; prefix vlan; - import ietf-yang-types { - prefix yang; - } - import ietf-inet-types { prefix inet; }