diff --git a/src/sonic-yang-mgmt/sonic_yang_ext.py b/src/sonic-yang-mgmt/sonic_yang_ext.py index 13ca562998e8..10faf75e7e9b 100644 --- a/src/sonic-yang-mgmt/sonic_yang_ext.py +++ b/src/sonic-yang-mgmt/sonic_yang_ext.py @@ -76,7 +76,7 @@ def createDBTableToModuleMap(self): # get module name moduleName = j['module']['@name'] # topLevelContainer does not exist in sonic-head and sonic-extension. - if "sonic-head" in moduleName or "sonic-extension" in moduleName: + if "sonic-types" in moduleName or "sonic-extension" in moduleName: continue; # get all top level container topLevelContainer = j['module']['container'] @@ -297,6 +297,44 @@ def xlateList(self, model, yang, config, table): return + """ + Process list inside a Container. + This function will call xlateList based on list(s) present in Container. + """ + def xlateListInContainer(self, model, yang, configC, table): + clist = model + #print(clist['@name']) + yang[clist['@name']] = list() + self.sysLog(msg="xlateProcessListOfContainer: {}".format(clist['@name'])) + self.xlateList(clist, yang[clist['@name']], configC, table) + # clean empty lists + if len(yang[clist['@name']]) == 0: + del yang[clist['@name']] + + return + + """ + Process container inside a Container. + This function will call xlateContainer based on Container(s) present + in outer Container. + """ + def xlateContainerInContainer(self, model, yang, configC, table): + ccontainer = model + #print(ccontainer['@name']) + yang[ccontainer['@name']] = dict() + if not configC.get(ccontainer['@name']): + return + self.sysLog(msg="xlateProcessListOfContainer: {}".format(ccontainer['@name'])) + self.xlateContainer(ccontainer, yang[ccontainer['@name']], \ + configC[ccontainer['@name']], table) + # clean empty container + if len(yang[ccontainer['@name']]) == 0: + del yang[ccontainer['@name']] + # remove copy after processing + del configC[ccontainer['@name']] + + return + """ Xlate a container This function will xlate from a dict in config DB to a Yang JSON container @@ -304,7 +342,7 @@ def xlateList(self, model, yang, config, table): """ def xlateContainer(self, model, yang, config, table): - # To Handle multiple List, Make a copy of config, because we delete keys + # To Handle multiple Lists, Make a copy of config, because we delete keys # from config after each match. This is done to match one pkey with one list. configC = config.copy() @@ -312,26 +350,33 @@ def xlateContainer(self, model, yang, config, table): # If single list exists in container, if clist and isinstance(clist, dict) and \ clist['@name'] == model['@name']+"_LIST" and bool(configC): - #print(clist['@name']) - yang[clist['@name']] = list() - self.sysLog(msg="xlateContainer listD {}".format(clist['@name'])) - self.xlateList(clist, yang[clist['@name']], \ - configC, table) - # clean empty lists - if len(yang[clist['@name']]) == 0: - del yang[clist['@name']] - #print(yang[clist['@name']]) - + self.xlateListInContainer(clist, yang, configC, table) # If multi-list exists in container, elif clist and isinstance(clist, list) and bool(configC): for modelList in clist: - yang[modelList['@name']] = list() - self.sysLog(msg="xlateContainer listL {}".format(modelList['@name'])) - self.xlateList(modelList, yang[modelList['@name']], configC, table) - # clean empty lists - if len(yang[modelList['@name']]) == 0: - del yang[modelList['@name']] - + self.xlateListInContainer(modelList, yang, configC, table) + + # Handle container(s) in container + ccontainer = model.get('container') + # If single container exists in container, + if ccontainer and isinstance(ccontainer, dict) and bool(configC): + self.xlateContainerInContainer(ccontainer, yang, configC, table) + # If multi-containers in container, + elif ccontainer and isinstance(ccontainer, list) and bool(configC): + for modelContainer in ccontainer: + self.xlateContainerInContainer(modelContainer, yang, configC, table) + + ## Handle other leaves in container, + leafDict = self.createLeafDict(model) + for vKey in configC.keys(): + #vkey must be a leaf\leaf-list\choice in container + if leafDict.get(vKey): + self.sysLog(syslog.LOG_DEBUG, "xlateContainer vkey {}".format(vKey)) + yang[vKey] = self.findYangTypedValue(vKey, configC[vKey], leafDict) + # delete entry from copy of config + del configC[vKey] + + # All entries in copy of config must have been parsed. if len(configC): self.sysLog(syslog.LOG_ERR, "Alert: Remaining keys in Config") raise(Exception("All Keys are not parsed in {}".format(table))) @@ -446,23 +491,60 @@ def revXlateList(self, model, yang, config, table): return + """ + Rev xlate a list inside a yang container + """ + def revXlateListInContainer(self, model, yang, config, table): + modelList = model + # Pass matching list from Yang Json if exist + if yang.get(modelList['@name']): + self.sysLog(msg="revXlateListInContainer {}".format(modelList['@name'])) + self.revXlateList(modelList, yang[modelList['@name']], config, table) + return + + """ + Rev xlate a container inside a yang container + """ + def revXlateContainerInContainer(self, model, yang, config, table): + modelContainer = model + # Pass matching list from Yang Json if exist + if yang.get(modelContainer['@name']): + config[modelContainer['@name']] = dict() + self.sysLog(msg="revXlateContainerInContainer {}".format(modelContainer['@name'])) + self.revXlateContainer(modelContainer, yang[modelContainer['@name']], \ + config[modelContainer['@name']], table) + return + """ Rev xlate from yang container to table in config DB """ def revXlateContainer(self, model, yang, config, table): - # Note: right now containers has only LISTs. # IF container has only one list - if isinstance(model['list'], dict): - modelList = model['list'] - # Pass matching list from Yang Json - self.sysLog(msg="revXlateContainer {}".format(modelList['@name'])) - self.revXlateList(modelList, yang[modelList['@name']], config, table) - - elif isinstance(model['list'], list): - for modelList in model['list']: - self.sysLog(msg="revXlateContainer {}".format(modelList['@name'])) - self.revXlateList(modelList, yang[modelList['@name']], config, table) + clist = model.get('list') + if isinstance(clist, dict): + self.revXlateListInContainer(clist, yang, config, table) + # IF container has lists + elif isinstance(clist, list): + for modelList in clist: + self.revXlateListInContainer(modelList, yang, config, table) + + ccontainer = model.get('container') + # IF container has only one inner container + if isinstance(ccontainer, dict): + self.revXlateContainerInContainer(ccontainer, yang, config, table) + # IF container has many inner containers + elif isinstance(ccontainer, list): + for modelContainer in ccontainer: + self.revXlateContainerInContainer(modelContainer, yang, config, table) + + ## Handle other leaves in container, + leafDict = self.createLeafDict(model) + for vKey in yang: + #vkey must be a leaf\leaf-list\choice in container + if leafDict.get(vKey): + self.sysLog(syslog.LOG_DEBUG, "revXlateContainer vkey {}".format(vKey)) + config[vKey] = self.revFindYangTypedValue(vKey, yang[vKey], leafDict) return 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 cc212cffb956..55ccda2c868e 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,16 +288,17 @@ 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.load_data(json.loads(jIn)) - - syc.load_data(json.loads(jIn)) - - # TODO: Make sure no extra table is loaded + syc.load_data(jIn) + # check all tables are loaded and no tables is without Yang Models + assert len(syc.jIn) == numTables + assert len(syc.tablesWithOutYang) == 0 syc.get_data() - if syc.jIn and syc.jIn == syc.revXlateJson: + if len(syc.jIn) and syc.jIn == syc.revXlateJson: print("Xlate and Rev Xlate Passed") else: print("Xlate and Rev Xlate failed") diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 62f3f05b0be7..62732769397a 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -100,13 +100,19 @@ def run (self): setup_requires=setup_requirements, version='1.0', data_files=[ - ('yang-models', ['./yang-models/sonic-head.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/yangModelTesting.py b/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py index 286eefcc6fac..64a89514ed62 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py +++ b/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py @@ -132,6 +132,14 @@ def __init__(self, tests, yangDir, jsonFile): 'key': 'sonic-acl:stage', 'value': 'INGRESS' } + }, + 'CRM_BRK_CFG_FLEX_TABLE': { + 'desc': 'CRM BREAKOUT CFG FLEX COUNTER TABLE.', + 'eStr': self.defaultYANGFailure['None'] + }, + 'DEV_META_DEV_NEIGH_VERSION_TABLE': { + 'desc': 'DEVICE_METADATA DEVICE_NEIGHBOR VERSION TABLE.', + 'eStr': self.defaultYANGFailure['None'] } } 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 8407f96a6e1c..a46a9f8b5b77 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -601,6 +601,103 @@ } }, + "DEV_META_DEV_NEIGH_VERSION_TABLE": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "localhost": { + "bgp_asn": "64850", + "mac": "00:11:22:33:44:55", + "hostname": "asw.dc", + "type": "ToR", + "hwsku": "Stone" + } + } + }, + "sonic-device_neighbor:sonic-device_neighbor": { + "sonic-device_neighbor:DEVICE_NEIGHBOR": { + "DEVICE_NEIGHBOR_LIST": [ + { + "port": "Eth18", + "name": "dccsw03.nw", + "peer_name": "Ethernet116" + }, + { + "port": "Eth18", + "name": "dccsw02.nw", + "peer_name": "Ethernet114" + }, + { + "port": "Eth18", + "name": "dccsw01.nw", + "peer_name": "Ethernet112" + }, + { + "port": "Eth18", + "name": "dccsw04.nw", + "peer_name": "Ethernet118" + } + ] + } + }, + "sonic-versions:sonic-versions": { + "sonic-versions:VERSIONS": { + "DATABASE": { + "VERSION": "version_2_10_31" + } + } + } + }, + + "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", + "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": "1x100G[40G]", + "port": "Ethernet8" + }, + { + "brkout_mode": "4x25G", + "port": "Ethernet4" + } + ] + } + }, + "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" + } + } + } + }, + "ACL_RULE_WRONG_INNER_ETHER_TYPE": { "sonic-acl:sonic-acl": { "sonic-acl:ACL_RULE": { diff --git a/src/sonic-yang-models/yang-models/sonic-acl.yang b/src/sonic-yang-models/yang-models/sonic-acl.yang index 3709f81a2250..2faeec2554e3 100644 --- a/src/sonic-yang-models/yang-models/sonic-acl.yang +++ b/src/sonic-yang-models/yang-models/sonic-acl.yang @@ -5,16 +5,12 @@ module sonic-acl { namespace "http://github.com/Azure/sonic-acl"; prefix acl; - import ietf-yang-types { - prefix yang; - } - import ietf-inet-types { prefix inet; } - import sonic-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -70,11 +66,11 @@ module sonic-acl { } leaf PACKET_ACTION { - type head:packet_action; + type stypes:packet_action; } leaf IP_TYPE { - type head:ip_type; + type stypes:ip_type; } leaf PRIORITY { @@ -257,7 +253,7 @@ module sonic-acl { leaf type { mandatory true; - type head:acl_table_type; + type stypes:acl_table_type; } leaf stage { 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..77ff36de471e --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-breakout_cfg.yang @@ -0,0 +1,55 @@ +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 ""; + + leaf port { + type string { + length 1..255; + } + } + + leaf brkout_mode { + type string { + length 1..64; + /* should be not allow any pattern here, since this is + * auto populated by cli. + */ + /* pattern "1x100G[40G]|2x50G|4x25G[10G]"; */ + } + } + } + /* 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..bc90587a70a3 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-crm.yang @@ -0,0 +1,203 @@ +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 "BREAKOUT_CFG 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + type threshold; + } + + leaf ipv4_route_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 { + 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 { + type threshold; + } + + leaf ipv6_route_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..bccd02035d6a --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang @@ -0,0 +1,96 @@ +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; + } + } + + leaf docker_routing_config_mode { + type enumeration { + enum unified; + enum split; + } + } + + 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; + } + } + + leaf bgp_asn { + type inet:as-number; + } + + leaf deployment_id { + type uint32; + } + + leaf type { + type string { + length 1..255; + } + } + } + /* 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-extension.yang b/src/sonic-yang-models/yang-models/sonic-extension.yang index cdf2c08f2317..f4bc2133e326 100644 --- a/src/sonic-yang-models/yang-models/sonic-extension.yang +++ b/src/sonic-yang-models/yang-models/sonic-extension.yang @@ -5,11 +5,8 @@ module sonic-extension { namespace "http://github.com/Azure/sonic-extension"; prefix sonic-extension; - organization "Linkedin Corporation"; + description "Extension yang Module for SONiC OS"; - contact "lnos_coders@linkedin.com"; - - description "Head yang Module for SONiC OS"; revision 2019-07-01 { description "First Revision"; 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..d9005533bcfd --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -0,0 +1,63 @@ +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"; + + container PFCWD { + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PORT { + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container QUEUE { + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container PG_WATERMARK { + leaf FLEX_COUNTER_STATUS { + type flex_status; + } + } + + container QUEUE_WATERMARK { + 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 f63f56285d9b..9e154237ea15 100644 --- a/src/sonic-yang-models/yang-models/sonic-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-interface.yang @@ -5,16 +5,8 @@ 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-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -93,8 +85,8 @@ module sonic-interface { leaf ip-prefix { type union { - type head:sonic-ip4-prefix; - type head:sonic-ip6-prefix; + type stypes:sonic-ip4-prefix; + type stypes:sonic-ip6-prefix; } } @@ -115,7 +107,7 @@ module sonic-interface { must "(contains(../ip-prefix, ':') and current()='IPv6') or (contains(../ip-prefix, '.') and current()='IPv4')"; - type head:ip-family; + type stypes:ip-family; } } /* end of INTERFACE_IPPREFIX_LIST */ 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 ca55e56511c7..313039990dcf 100644 --- a/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-loopback-interface.yang @@ -1,14 +1,12 @@ module sonic-loopback-interface { + yang-version 1.1; + namespace "http://github.com/Azure/sonic-loopback-interface"; prefix lointf; - import ietf-inet-types { - prefix inet; - } - - import sonic-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -71,8 +69,8 @@ module sonic-loopback-interface { leaf ip-prefix { type union { - type head:sonic-ip4-prefix; - type head:sonic-ip6-prefix; + type stypes:sonic-ip4-prefix; + type stypes:sonic-ip6-prefix; } } @@ -93,7 +91,7 @@ module sonic-loopback-interface { must "(contains(../ip-prefix, ':') and current()='IPv6') or (contains(../ip-prefix, '.') and current()='IPv4')"; - type head:ip-family; + type stypes:ip-family; } } } diff --git a/src/sonic-yang-models/yang-models/sonic-port.yang b/src/sonic-yang-models/yang-models/sonic-port.yang index 25718be95a99..2c01b8829640 100644 --- a/src/sonic-yang-models/yang-models/sonic-port.yang +++ b/src/sonic-yang-models/yang-models/sonic-port.yang @@ -5,16 +5,8 @@ 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-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -92,7 +84,7 @@ module sonic-port{ } leaf admin_status { - type head:admin_status; + type stypes:admin_status; } leaf fec { diff --git a/src/sonic-yang-models/yang-models/sonic-portchannel.yang b/src/sonic-yang-models/yang-models/sonic-portchannel.yang index bf342b9fcfec..ff3b093d5a14 100644 --- a/src/sonic-yang-models/yang-models/sonic-portchannel.yang +++ b/src/sonic-yang-models/yang-models/sonic-portchannel.yang @@ -5,16 +5,8 @@ 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-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -95,7 +87,7 @@ module sonic-portchannel { leaf admin_status { mandatory true; - type head:admin_status; + type stypes:admin_status; } } /* end of list PORTCHANNEL_LIST */ diff --git a/src/sonic-yang-models/yang-models/sonic-head.yang b/src/sonic-yang-models/yang-models/sonic-types.yang similarity index 80% rename from src/sonic-yang-models/yang-models/sonic-head.yang rename to src/sonic-yang-models/yang-models/sonic-types.yang index 2ef86c41ccbc..0bfcddc56103 100644 --- a/src/sonic-yang-models/yang-models/sonic-head.yang +++ b/src/sonic-yang-models/yang-models/sonic-types.yang @@ -1,15 +1,15 @@ -module sonic-head { +module sonic-types { yang-version 1.1; namespace "http://github.com/Azure/sonic-head"; - prefix sonic-head; + prefix sonic-types; - organization "Linkedin Corporation"; - - contact "lnos_coders@linkedin.com"; - - description "Head yang Module for SONiC OS"; + 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"; @@ -86,6 +86,13 @@ module sonic-head { } } + typedef hwsku { + type string { + length 1..255; + /* Should we list all hwsku here */ + } + } + typedef vlan_tagging_mode { type enumeration { enum tagged; @@ -93,4 +100,11 @@ module sonic-head { 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..4cbf53481d28 --- /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 "VERSIONS part of config_db.json"; + + container DATABASE { + + leaf VERSION { + type string { + length 1..255; + pattern 'version_([0-9]{1,2})_([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 cba7ce1d0f8e..6c30e3bc1687 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -1,18 +1,16 @@ module sonic-vlan { + yang-version 1.1; + namespace "http://github.com/Azure/sonic-vlan"; prefix vlan; - import ietf-yang-types { - prefix yang; - } - import ietf-inet-types { prefix inet; } - import sonic-head { - prefix head; + import sonic-types { + prefix stypes; revision-date 2019-07-01; } @@ -89,8 +87,8 @@ module sonic-vlan { leaf ip-prefix { type union { - type head:sonic-ip4-prefix; - type head:sonic-ip6-prefix; + type stypes:sonic-ip4-prefix; + type stypes:sonic-ip6-prefix; } } @@ -111,7 +109,7 @@ module sonic-vlan { must "(contains(../ip-prefix, ':') and current()='IPv6') or (contains(../ip-prefix, '.') and current()='IPv4')"; - type head:ip-family; + type stypes:ip-family; } } /* end of VLAN_INTERFACE_LIST */ @@ -159,7 +157,7 @@ module sonic-vlan { } leaf admin_status { - type head:admin_status; + type stypes:admin_status; } } /* end of VLAN_LIST */ @@ -193,7 +191,7 @@ module sonic-vlan { leaf tagging_mode { mandatory true; - type head:vlan_tagging_mode; + type stypes:vlan_tagging_mode; } } /* end of list VLAN_MEMBER_LIST */