From b7d2d4944ee3e4bf9609a1744879a7409c0375e1 Mon Sep 17 00:00:00 2001 From: Zhenggen Xu Date: Thu, 20 Jun 2019 11:52:14 -0700 Subject: [PATCH 1/5] Point the sonic-utilities to forked repo Signed-off-by: Zhenggen Xu --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 3d2a8e3f7a1d..e2a581d6a8b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,7 +34,7 @@ url = https://github.com/p4lang/ptf.git [submodule "src/sonic-utilities"] path = src/sonic-utilities - url = https://github.com/Azure/sonic-utilities + url = https://github.com/zhenggen-xu/sonic-utilities [submodule "platform/broadcom/sonic-platform-modules-arista"] path = platform/broadcom/sonic-platform-modules-arista url = https://github.com/aristanetworks/sonic From 3c3d6cf79e1315730051ef5e6ba2fbfc15878cbf Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Thu, 1 Aug 2019 10:31:31 -0700 Subject: [PATCH 2/5] [yang-models]: First version of yang models for Port, VLan and ACL. RB= G=lnos-reviewers R=pchaudhary,pmao,rmolina,samaity,sfardeen,zxu A= --- .../yang-models/Sonic Yang Tree | 90 ++++++ .../yang-models/sonic-acl.yang | 291 ++++++++++++++++++ .../yang-models/sonic-head.yang | 76 +++++ .../yang-models/sonic-port.yang | 100 ++++++ .../yang-models/sonic-vlan.yang | 180 +++++++++++ 5 files changed, 737 insertions(+) create mode 100644 src/sonic-yang-mgmt/yang-models/Sonic Yang Tree create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-acl.yang create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-head.yang create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-port.yang create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-vlan.yang diff --git a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree new file mode 100644 index 000000000000..923f5a141b74 --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree @@ -0,0 +1,90 @@ +Sonic Yang TREE: + +bash-3.2$ pyang -f tree sonic-vlan.yang +sonic-vlan.yang:6: warning: imported module "ietf-yang-types" not used +module: sonic-vlan + +--rw VLAN_INTERFACE + | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] + | +--rw vlanid -> /VLAN/VLAN_LIST/vlanid + | +--rw ip-prefix inet:ip-prefix + | +--rw scope enumeration + | +--rw family sonic-head:ip-family + +--rw VLAN + | +--rw VLAN_LIST* [vlanid] + | +--rw vlanid uint16 + | +--rw description? string + | +--rw dhcp_servers* inet:ip-address + | +--rw mtu? uint16 + | +--rw admin_status sonic-head:admin_status + | +--rw members* -> /sonic-port:PORT/PORT_LIST/port_name + +--rw VLAN_MEMBER + +--rw VLAN_MEMBER_LIST* [vlanid port] + +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid + +--rw port -> /sonic-port:PORT/PORT_LIST/port_name + +--rw tagging_mode sonic-head:vlan_tagging_mode + + +bash-3.2$ pyang -f tree sonic-port.yang +module: sonic-port + +--rw PORT + +--rw PORT_LIST* [port_name] + +--rw port_name string + +--ro alias? string + +--ro lanes? string + +--rw description? string + +--rw speed? uint32 + +--rw mtu? uint16 + +--rw admin_status sonic-head:admin_status + + +bash-3.2$ pyang -f tree sonic-acl.yang +module: sonic-acl + +--rw ACL_RULE + | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] + | +--rw ACL_TABLE_NAME -> /ACL_TABLE/ACL_TABLE_LIST/ACL_TABLE_NAME + | +--rw RULE_NAME string + | +--rw PACKET_ACTION? sonic-head:packet_action + | +--rw IP_TYPE? sonic-head:ip_type + | +--rw PRIORITY? uint32 + | +--rw (ip_prefix)? + | | +--:(ip4_prefix) + | | | +--rw SRC_IP? inet:ipv4-prefix + | | | +--rw DST_IP? inet:ipv4-prefix + | | +--:(ip6_prefix) + | | +--rw SRC_IPV6? inet:ipv6-prefix + | | +--rw DST_IPV6? inet:ipv6-prefix + | +--rw IN_PORTS* uint16 + | +--rw OUT_PORTS* uint16 + | +--rw (src_port)? + | | +--:(l4_src_port) + | | | +--rw L4_SRC_PORT? uint16 + | | +--:(l4_src_port_range) + | | +--rw L4_SRC_PORT_RANGE? string + | +--rw (dst_port)? + | | +--:(l4_dst_port) + | | | +--rw L4_DST_PORT? uint16 + | | +--:(l4_dst_port_range) + | | +--rw L4_DST_PORT_RANGE? string + | +--rw ETHER_TYPE? string + | +--rw IP_PROTOCOL? uint8 + | +--rw TCP_FLAGS? string + | +--rw DSCP? uint8 + | +--rw TC? uint8 + | +--rw (icmp)? + | | +--:(icmp4) + | | | +--rw ICMP_TYPE? uint8 + | | | +--rw ICMP_CODE? uint8 + | | +--:(icmp6) + | | +--rw ICMPV6_TYPE? uint8 + | | +--rw ICMPV6_CODE? uint8 + | +--rw INNER_ETHER_TYPE? string + | +--rw INNER_IP_PROTOCOL? uint8 + | +--rw INNER_L4_SRC_PORT? uint16 + | +--rw INNER_L4_DST_PORT? uint16 + +--rw ACL_TABLE + +--rw ACL_TABLE_LIST* [ACL_TABLE_NAME] + +--rw ACL_TABLE_NAME string + +--rw policy_desc? string + +--rw type? sonic-head:acl_table_type + +--rw stage? enumeration + +--rw ports* -> /sonic-port:PORT/PORT_LIST/port_name \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang new file mode 100644 index 000000000000..38e7d05822c2 --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang @@ -0,0 +1,291 @@ +module sonic-acl { + + namespace "http://sonic-acl"; + prefix sonic-acl; +/* + import ietf-yang-types { + prefix yang; + } +*/ + import ietf-inet-types { + prefix inet; + } + + import sonic-head { + prefix sonic-head; + revision-date 2019-07-01; + } + + import sonic-port { + prefix sonic-port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "ACL yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container ACL_RULE { + + description "ACL_RULE part of config_db.json"; + + list ACL_RULE_LIST { + + key "ACL_TABLE_NAME RULE_NAME"; +/* + sonic-head:sonic_db_path "ACL_RULE"; + + sonic-head:sonic_db_schema { + "{ACL_TABLE_NAME}|{RULE_NAME}": { + "PACKET_ACTION": {PACKET_ACTION}, + "IP_TYPE": {IP_TYPE}, + "PRIORITY": {PRIORITY} + "DST_IP": {DST_IP}, + "SRC_IP": {SRC_IP}, + "SRC_IPV6": {SRC_IPV6}, + "DST_IPV6": {DST_IPV6}, + "IN_PORTS": {IN_PORTS}, + "OUT_PORTS": {OUT_PORTS}, + "L4_SRC_PORT": {L4_SRC_PORT}, + "L4_DST_PORT": {L4_DST_PORT}, + "L4_SRC_PORT_RANGE": {L4_SRC_PORT_RANGE}, + "L4_DST_PORT_RANGE": {L4_DST_PORT_RANGE}, + "ETHER_TYPE": {ETHER_TYPE}, + "IP_PROTOCOL": {IP_PROTOCOL}, + "TCP_FLAGS": {TCP_FLAGS}, + "DSCP": {DSCP}, + "TC": {TC}, + "ICMP_TYPE": {ICMP_TYPE}, + "ICMP_CODE": {ICMP_CODE}, + "ICMPV6_TYPE": {ICMPV6_TYPE}, + "ICMPV6_CODE": {ICMPV6_CODE}, + "INNER_ETHER_TYPE": {INNER_ETHER_TYPE}, + "INNER_IP_PROTOCOL": {INNER_IP_PROTOCOL}, + "INNER_L4_SRC_PORT": {INNER_L4_SRC_PORT}, + "INNER_L4_DST_PORT": {INNER_L4_DST_PORT} + } + } +*/ + + leaf ACL_TABLE_NAME { + type leafref { + path "/sonic-acl:ACL_TABLE/sonic-acl:ACL_TABLE_LIST/sonic-acl:ACL_TABLE_NAME"; + } + } + + leaf RULE_NAME { + type string { + length 1..255; + } + } + + leaf PACKET_ACTION { + type sonic-head:packet_action; + } + + leaf IP_TYPE { + type sonic-head:ip_type; + } + + leaf PRIORITY { + type uint32 { + range 0..999999; + } + } + + choice ip_prefix { + + case ip4_prefix { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; + leaf SRC_IP { + type inet:ipv4-prefix; + } + + leaf DST_IP { + type inet:ipv4-prefix; + } + } + + case ip6_prefix { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; + leaf SRC_IPV6 { + type inet:ipv6-prefix; + } + + leaf DST_IPV6 { + type inet:ipv6-prefix; + } + } + } + + leaf-list IN_PORTS { + /* Values in leaf list are UNIQUE */ + type uint16; + } + + leaf-list OUT_PORTS { + /* Values in leaf list are UNIQUE */ + type uint16; + } + + choice src_port { + case l4_src_port { + leaf L4_SRC_PORT { + type uint16; + } + } + + case l4_src_port_range { + leaf L4_SRC_PORT_RANGE { + type string { + pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; + } + } + } + } + + choice dst_port { + case l4_dst_port { + leaf L4_DST_PORT { + type uint16; + } + } + + case l4_dst_port_range { + leaf L4_DST_PORT_RANGE { + type string { + pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; + } + } + } + } + + leaf ETHER_TYPE { + type string { + pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)"; + } + } + + leaf IP_PROTOCOL { + type uint8 { + range 1..143; + } + } + + leaf TCP_FLAGS { + type string { + pattern '0[x][0-9a-fA-F]{1,2}|0[X][0-9a-fA-F]{1,2}'; + } + } + + leaf DSCP { + type uint8; + } + + leaf TC { + type uint8; + } + + choice icmp { + + case icmp4 { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; + leaf ICMP_TYPE { + type uint8 { + range 1..44; + } + } + + leaf ICMP_CODE { + type uint8 { + range 1..16; + } + } + } + + case icmp6 { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; + leaf ICMPV6_TYPE { + type uint8 { + range 1..44; + } + } + + leaf ICMPV6_CODE { + type uint8 { + range 1..16; + } + } + } + } + + leaf INNER_ETHER_TYPE { + type string { + pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)"; + } + } + + leaf INNER_IP_PROTOCOL { + type uint8 { + range 1..143; + } + } + + leaf INNER_L4_SRC_PORT { + type uint16; + } + + leaf INNER_L4_DST_PORT { + type uint16; + } + } + /* end of ACL_RULE_LIST */ + } + /* end of container ACL_RULE */ + + container ACL_TABLE { + + description "ACL_TABLE part of config_db.json"; + + list ACL_TABLE_LIST { + + key "ACL_TABLE_NAME"; + + leaf ACL_TABLE_NAME { + type string; + } + + leaf policy_desc { + type string { + length 1..255; + } + } + + leaf type { + type sonic-head:acl_table_type; + } + + leaf stage { + type enumeration { + enum INGRESS; + enum EGRESS; + } + } + + leaf-list ports { + type leafref { + path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; + } + } + + } + /* end of container ACL_TABLE */ + } + /* end of ACL_TABLE_LIST */ +} \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-head.yang b/src/sonic-yang-mgmt/yang-models/sonic-head.yang new file mode 100644 index 000000000000..1f2875fca15e --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-head.yang @@ -0,0 +1,76 @@ +module sonic-head { + + namespace "http://sonic-head"; + prefix sonic-head; + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "Head yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + typedef ip-family { + type enumeration { + enum IPv4; + enum IPv6; + } + } + + typedef admin_status { + type enumeration { + enum up; + enum down; + } + } + + typedef packet_action{ + type enumeration { + enum DROP; + enum FORWARD; + enum REDIRECT; + } + } + + typedef ip_type { + type enumeration { + enum ANY; + enum IP; + enum NON_IP; + enum IPV4; + enum IPV6; + enum IPV4ANY; + enum NON_IPv4; + enum IPV6ANY; + enum NON_IPv6; + enum ARP; + } + } + + typedef acl_table_type { + type enumeration { + enum L2; + enum L3; + enum L3V6; + enum MIRROR; + enum MIRRORV6; + enum MIRROR_DSCP; + enum CTRLPLANE; + } + } + + typedef vlan_tagging_mode { + type enumeration { + enum tagged; + enum untagged; + enum priority_tagged; + } + } + + extension sonic_db_path; + + extension sonic_db_schema; +} \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-port.yang b/src/sonic-yang-mgmt/yang-models/sonic-port.yang new file mode 100644 index 000000000000..f6af9b91fe97 --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-port.yang @@ -0,0 +1,100 @@ +module sonic-port{ + + namespace "http://sonic-port"; + prefix sonic-port; +/* + import ietf-yang-types { + prefix yang; + } + + import ietf-inet-types { + prefix inet; + } +*/ + import sonic-head { + prefix sonic-head; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "PORT yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container PORT { + + description "PORT part of config_db.json"; + + list PORT_LIST { + + key "port_name"; +/* + sonic-head:sonic_db_path = PORT; [Todo: Fix by extension] + + sonic-head:sonic_db_schema { [Todo: Fix by extension] + {port_name}: { + "alias": {alias}, + "lanes": {lanes}, + "description": {description}, + "speed": {speed}, + "mtu": {mtu} + } + } +*/ + leaf port_name { + type string { + length 1..128; + /* ; [Todo: verify this] */ + } + } + + leaf alias { + config false; + type string { + length 1..128; + /* ; [Todo] */ + } + } + + leaf lanes { + config false; + type string { + length 1..128; + /* ; [Todo] */ + } + } + + leaf description { + type string { + length 1..255; + } + } + + leaf speed { + type uint32 { + range 1..100000; + /* ; [Todo: verify this] */ + } + } + + leaf mtu { + type uint16 { + range 1..9216; + } + } + + leaf admin_status { + mandatory true; + type sonic-head:admin_status; + } + } + /* end of list PORT_LIST */ + } + /* end of container PORT */ +} +/* end of module sonic-port */ \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang new file mode 100644 index 000000000000..2bd1e3c263ff --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang @@ -0,0 +1,180 @@ +module sonic-vlan { + + namespace "http://sonic-vlan"; + prefix sonic-vlan; + + import ietf-yang-types { + prefix yang; + } + + import ietf-inet-types { + prefix inet; + } + + import sonic-head { + prefix sonic-head; + revision-date 2019-07-01; + } + + import sonic-port { + prefix sonic-port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "VLAN yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container VLAN_INTERFACE { + + description "VLAN_INTERFACE part of config_db.json"; + + list VLAN_INTERFACE_LIST { + + key "vlanid ip-prefix"; +/* + sonic-head:sonic_db_path "VLAN_INTERFACE"; [Todo: Fix by extension] + + sonic-head:sonic_db_schema { [Todo: Fix by extension] + "Vlan{vlanid}|{ip-prefix}": { + "scope": {scope}, + "family": {family} + } + } +*/ + leaf vlanid { + type leafref { + path "/VLAN/VLAN_LIST/vlanid"; + } + } + + + /* We need a check like when "family = 'IPv6'"; */ + leaf ip-prefix { + mandatory true; + type inet:ip-prefix; + } + + leaf scope { + mandatory true; + type enumeration { + enum global; + enum local; + } + } + + leaf family { + mandatory true; + type sonic-head:ip-family; + } + } + /* end of VLAN_INTERFACE_LIST */ + + } + /* end of VLAN_INTERFACE container */ + + container VLAN { + + description "VLAN part of config_db.json"; + + list VLAN_LIST { + + key "vlanid"; +/* + \sonic_db_path "VLAN"; + + sonic-head:sonic_db_schema { + "Vlan{vlanid}: { + "description": {description}, + "dhcp_servers": {dhcp_servers}, + "vlanid": {vlanid}, + "mtu": {mtu}, + "admin_status": {admin_status}, + "members": {members}, + } + } +*/ + leaf vlanid { + type uint16 { + range 1..4094; + } + } + + leaf description { + type string { + length 1..255; + } + } + + leaf-list dhcp_servers { + type inet:ip-address; + } + + leaf mtu { + type uint16 { + range 1..9216; + } + } + + leaf admin_status { + mandatory true; + type sonic-head:admin_status; + } + + leaf-list members { + /* leaf-list members are unique by default */ + + type leafref { + path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; + } + } + } + /* end of VLAN_LIST */ + } + /* end of container VLAN */ + + container VLAN_MEMBER { + + description "VLAN_MEMBER part of config_db.json"; + + list VLAN_MEMBER_LIST { + + key "vlanid port"; +/* + sonic-head:sonic_db_path "VLAN"; + + sonic-head:sonic_db_schema { + "Vlan{vlanid}|{port}": { + "tagging_mode": {tagging_mode} + } + } +*/ + leaf vlanid { + type leafref { + path ../../../VLAN/VLAN_LIST/vlanid; + } + } + + leaf port { + /* key elements are mandatory by default */ + mandatory true; + type leafref { + path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; + } + } + + leaf tagging_mode { + mandatory true; + type sonic-head:vlan_tagging_mode; + } + } + /* end of list VLAN_MEMBER_LIST */ + } + /* end of container VLAN_MEMBER */ +} \ No newline at end of file From de8f568ff866ba47b42eb847da8bcc39958b5730 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Wed, 7 Aug 2019 12:37:51 -0700 Subject: [PATCH 3/5] [yangModelTesting.py]: Test code for POC. Minor Corrections in yang model files. --- .../test_code/yangModelTesting.py | 67 +++++ .../yang-models/Sonic Yang Tree | 8 +- .../yang-models/sonic-acl.yang | 6 +- .../yang-models/sonic-port.yang | 6 +- .../yang-models/sonic_config_data.json | 259 ++++++++++++++++++ 5 files changed, 333 insertions(+), 13 deletions(-) create mode 100644 src/sonic-yang-mgmt/test_code/yangModelTesting.py create mode 100644 src/sonic-yang-mgmt/yang-models/sonic_config_data.json diff --git a/src/sonic-yang-mgmt/test_code/yangModelTesting.py b/src/sonic-yang-mgmt/test_code/yangModelTesting.py new file mode 100644 index 000000000000..8a20578c247e --- /dev/null +++ b/src/sonic-yang-mgmt/test_code/yangModelTesting.py @@ -0,0 +1,67 @@ +import yang as ly +import sonic_yang as sy +import logging + +from os import listdir +from os.path import isfile, join, splitext + +logging.basicConfig(level=logging.DEBUG) +log = logging.getLogger(":") +log.setLevel(logging.DEBUG) +log.addHandler(logging.NullHandler()) + +def main(): + + yangDir = "/sonic/src/sonic-yang-mgmt/models" + yangDataInst = yangDir + "/sonic_config_data.json" + + # get all files + yangFiles = [f for f in listdir(yangDir) if isfile(join(yangDir, f))] + # get all yang files + yangFiles = [f for f in yangFiles if splitext(f)[-1].lower()==".yang"] + yangFiles = [f.split('.')[0] for f in yangFiles] + + # load yang mdoules + ctx = ly.Context(yangDir) + for f in yangFiles: + # load a module m + m = ctx.get_module(f) + if m is not None: + log.error(m.name()) + else: + m = ctx.load_module(f) + if m is not None: + log.info("module: {} is loaded successfully".format(m.name())) + + try: + root = ctx.parse_data_path(yangDataInst, ly.LYD_JSON, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) + + if root: + log.info("Tree DFS\n") + p = root.print_mem(ly.LYD_JSON, ly.LYP_WITHSIBLINGS | ly.LYP_FORMAT) + log.info("===================Data=================") + log.info(p) + + sYangInst = sy.sonic_yang(yangDir) + sYangInst.root = root + sYangInst.validate_data_tree(root, ctx) + + xpath = "/sonic-port:PORT/PORT_LIST[port_name='Ethernet1']/port_name" + #find_topo_sort_dependencies(sYangInst, xpath) + refs = sYangInst.find_data_dependencies(xpath) + printList(refs) + + except Exception as e: + print(e) + + +def printList(l): # list l + + print("list: ") + for item in l: + print (item) + + return + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree index 923f5a141b74..b06ea5b226ee 100644 --- a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree +++ b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree @@ -1,7 +1,5 @@ Sonic Yang TREE: -bash-3.2$ pyang -f tree sonic-vlan.yang -sonic-vlan.yang:6: warning: imported module "ietf-yang-types" not used module: sonic-vlan +--rw VLAN_INTERFACE | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] @@ -23,8 +21,6 @@ module: sonic-vlan +--rw port -> /sonic-port:PORT/PORT_LIST/port_name +--rw tagging_mode sonic-head:vlan_tagging_mode - -bash-3.2$ pyang -f tree sonic-port.yang module: sonic-port +--rw PORT +--rw PORT_LIST* [port_name] @@ -36,8 +32,6 @@ module: sonic-port +--rw mtu? uint16 +--rw admin_status sonic-head:admin_status - -bash-3.2$ pyang -f tree sonic-acl.yang module: sonic-acl +--rw ACL_RULE | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] @@ -87,4 +81,4 @@ module: sonic-acl +--rw policy_desc? string +--rw type? sonic-head:acl_table_type +--rw stage? enumeration - +--rw ports* -> /sonic-port:PORT/PORT_LIST/port_name \ No newline at end of file + +--rw ports* -> /sonic-port:PORT/PORT_LIST/port_name diff --git a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang index 38e7d05822c2..f37e5b32edc0 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang @@ -168,7 +168,7 @@ module sonic-acl { leaf ETHER_TYPE { type string { - pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)"; + pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; } } @@ -227,7 +227,7 @@ module sonic-acl { leaf INNER_ETHER_TYPE { type string { - pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)"; + pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; } } @@ -288,4 +288,4 @@ module sonic-acl { /* end of container ACL_TABLE */ } /* end of ACL_TABLE_LIST */ -} \ No newline at end of file +} diff --git a/src/sonic-yang-mgmt/yang-models/sonic-port.yang b/src/sonic-yang-mgmt/yang-models/sonic-port.yang index f6af9b91fe97..11145c480814 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-port.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-port.yang @@ -54,7 +54,7 @@ module sonic-port{ } leaf alias { - config false; + /* config false; */ type string { length 1..128; /* ; [Todo] */ @@ -62,7 +62,7 @@ module sonic-port{ } leaf lanes { - config false; + /* config false; */ type string { length 1..128; /* ; [Todo] */ @@ -97,4 +97,4 @@ module sonic-port{ } /* end of container PORT */ } -/* end of module sonic-port */ \ No newline at end of file +/* end of module sonic-port */ diff --git a/src/sonic-yang-mgmt/yang-models/sonic_config_data.json b/src/sonic-yang-mgmt/yang-models/sonic_config_data.json new file mode 100644 index 000000000000..9dacaf52d802 --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic_config_data.json @@ -0,0 +1,259 @@ +{ + "sonic-vlan:VLAN_INTERFACE": { + "VLAN_INTERFACE_LIST": [ + { + "vlanid": 100, + "ip-prefix": "2a04:f547:45:6709::1/64", + "scope": "global", + "family": "IPv6" + }, + { + "vlanid": 100, + "ip-prefix": "10.189.10.65/26", + "scope": "global", + "family": "IPv6" + }, + { + "vlanid": 100, + "ip-prefix": "fe80::1/10", + "scope": "local", + "family": "IPv6" + }, + { + "vlanid": 777, + "ip-prefix": "2a04:f547:41:4e9::1/64", + "scope": "global", + "family": "IPv6" + }, + { + "vlanid": 777, + "ip-prefix": "10.177.58.65/26", + "scope": "global", + "family": "IPv6" + }, + { + "vlanid": 777, + "ip-prefix": "fe80::1/10", + "scope": "local", + "family": "IPv6" + } + ] + }, + + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "vlanid": 100, + "description": "server_vlan", + "dhcp_servers": [ + "10.186.72.116" + ], + "mtu": "9216", + "admin_status": "up", + "members": [ + "Ethernet8", + "Ethernet3", + "Ethernet0", + "Ethernet1", + "Ethernet6", + "Ethernet4", + "Ethernet5", + "Ethernet9", + "Ethernet2" + ] + }, + { + "vlanid": 777, + "description": "ipmi_vlan", + "dhcp_servers": [ + "10.186.72.116" + ], + "mtu": "9216", + "admin_status": "up", + "members": [ + "Ethernet9", + "Ethernet2", + "Ethernet8" + ] + } + ] + }, + + "sonic-vlan:VLAN_MEMBER": { + "VLAN_MEMBER_LIST": [ + { + "vlanid": 100, + "port": "Ethernet0", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet1", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet2", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet3", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet4", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet5", + "tagging_mode": "tagged" + }, + { + "vlanid": 100, + "port": "Ethernet6", + "tagging_mode": "tagged" + } + ] + }, + + "sonic-port:PORT": { + "PORT_LIST": [ + { + "port_name": "Ethernet0", + "alias": "eth0", + "description": "Ethernet0", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet1", + "alias": "eth1", + "description": "Ethernet1", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet2", + "alias": "eth2", + "description": "Ethernet2", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet3", + "alias": "eth2", + "description": "Ethernet3", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet4", + "alias": "eth4", + "description": "Ethernet4", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet5", + "alias": "eth5", + "description": "Ethernet5", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet6", + "alias": "eth6", + "description": "Ethernet6", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet7", + "alias": "eth7", + "description": "Ethernet7", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet8", + "alias": "eth8", + "description": "Ethernet8", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + }, + { + "port_name": "Ethernet9", + "alias": "eth9", + "description": "Ethernet9", + "speed": 25000, + "mtu": 9000, + "admin_status": "up" + } + ] + }, + + "sonic-acl:ACL_RULE": { + "ACL_RULE_LIST": [ + { + "ACL_TABLE_NAME": "NO-NSW-PACL-V4", + "RULE_NAME": "Rule_20", + "PACKET_ACTION": "FORWARD", + "DST_IP": "10.186.72.0/26", + "SRC_IP": "10.176.0.0/15", + "PRIORITY": "999980", + "IP_TYPE": "IPV4ANY" + }, + { + "ACL_TABLE_NAME": "NO-NSW-PACL-V4", + "RULE_NAME": "Rule_40", + "PACKET_ACTION": "FORWARD", + "DST_IP": "10.186.72.64/26", + "SRC_IP": "10.176.0.0/15", + "PRIORITY": "999960", + "IP_TYPE": "IPV4ANY", + "INNER_ETHER_TYPE": "0x88CC" + }, + { + "ACL_TABLE_NAME": "NO-NSW-PACL-V6", + "RULE_NAME": "Rule_20", + "PACKET_ACTION": "FORWARD", + "IP_TYPE": "IP", + "SRC_IPV6": "2a04:f547:41::/48", + "PRIORITY": "999980", + "DST_IPV6": "2a04:f547:43:320::/64", + "L4_SRC_PORT_RANGE": "653-1053" + } + ] + }, + + "sonic-acl:ACL_TABLE": { + "ACL_TABLE_LIST": [ + { + "ACL_TABLE_NAME": "NO-NSW-PACL-V6", + "policy_desc": "Filter IPv6", + "type": "L3V6", + "stage": "EGRESS", + "ports": ["Ethernet7", "Ethernet9", "Ethernet8"] + }, + { + "ACL_TABLE_NAME": "NO-NSW-PACL-V4", + "policy_desc": "Filter IPv6", + "type": "L3", + "stage": "INGRESS", + "ports": ["Ethernet2", "Ethernet0", "Ethernet1"] + } + ] + } +} From 7af01087ad6272e761b08bc14cc637a97a4d5b26 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Wed, 21 Aug 2019 13:08:56 -0700 Subject: [PATCH 4/5] [sonic-interface.yang]: Interface yang model. Minor changes in yang tree and other models. --- .../yang-models/Sonic Yang Tree | 71 ++--- .../yang-models/sonic-acl.yang | 10 +- .../yang-models/sonic-interface.yang | 79 ++++++ .../yang-models/sonic-port.yang | 12 +- .../yang-models/sonic-vlan.yang | 8 +- .../yang-models/sonic_config_data.json | 259 ------------------ 6 files changed, 126 insertions(+), 313 deletions(-) create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-interface.yang delete mode 100644 src/sonic-yang-mgmt/yang-models/sonic_config_data.json diff --git a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree index b06ea5b226ee..b64dda8175c5 100644 --- a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree +++ b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree @@ -1,37 +1,3 @@ -Sonic Yang TREE: - -module: sonic-vlan - +--rw VLAN_INTERFACE - | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] - | +--rw vlanid -> /VLAN/VLAN_LIST/vlanid - | +--rw ip-prefix inet:ip-prefix - | +--rw scope enumeration - | +--rw family sonic-head:ip-family - +--rw VLAN - | +--rw VLAN_LIST* [vlanid] - | +--rw vlanid uint16 - | +--rw description? string - | +--rw dhcp_servers* inet:ip-address - | +--rw mtu? uint16 - | +--rw admin_status sonic-head:admin_status - | +--rw members* -> /sonic-port:PORT/PORT_LIST/port_name - +--rw VLAN_MEMBER - +--rw VLAN_MEMBER_LIST* [vlanid port] - +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid - +--rw port -> /sonic-port:PORT/PORT_LIST/port_name - +--rw tagging_mode sonic-head:vlan_tagging_mode - -module: sonic-port - +--rw PORT - +--rw PORT_LIST* [port_name] - +--rw port_name string - +--ro alias? string - +--ro lanes? string - +--rw description? string - +--rw speed? uint32 - +--rw mtu? uint16 - +--rw admin_status sonic-head:admin_status - module: sonic-acl +--rw ACL_RULE | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] @@ -82,3 +48,40 @@ module: sonic-acl +--rw type? sonic-head:acl_table_type +--rw stage? enumeration +--rw ports* -> /sonic-port:PORT/PORT_LIST/port_name +module: sonic-interface + +--rw INTERFACE + +--rw INTERFACE_LIST* [interface ip-prefix] + +--rw interface -> /sonic-port:PORT/PORT_LIST/port_name + +--rw ip-prefix inet:ip-prefix + +--rw scope? enumeration + +--rw family? sonic-head:ip-family +module: sonic-port + +--rw PORT + +--rw PORT_LIST* [port_name] + +--rw port_name string + +--rw alias? string + +--rw lanes? string + +--rw description? string + +--rw speed? uint32 + +--rw mtu? uint16 + +--rw admin_status sonic-head:admin_status +module: sonic-vlan + +--rw VLAN_INTERFACE + | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] + | +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid + | +--rw ip-prefix inet:ip-prefix + | +--rw scope? enumeration + | +--rw family? sonic-head:ip-family + +--rw VLAN + | +--rw VLAN_LIST* [vlanid] + | +--rw vlanid uint16 + | +--rw description? string + | +--rw dhcp_servers* inet:ip-address + | +--rw mtu? uint16 + | +--rw admin_status sonic-head:admin_status + | +--rw members* -> /sonic-port:PORT/PORT_LIST/port_name + +--rw VLAN_MEMBER + +--rw VLAN_MEMBER_LIST* [vlanid port] + +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid + +--rw port -> /sonic-port:PORT/PORT_LIST/port_name + +--rw tagging_mode sonic-head:vlan_tagging_mode diff --git a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang index f37e5b32edc0..29ecda668224 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang @@ -2,11 +2,11 @@ module sonic-acl { namespace "http://sonic-acl"; prefix sonic-acl; -/* + import ietf-yang-types { prefix yang; } -*/ + import ietf-inet-types { prefix inet; } @@ -72,7 +72,6 @@ module sonic-acl { } } */ - leaf ACL_TABLE_NAME { type leafref { path "/sonic-acl:ACL_TABLE/sonic-acl:ACL_TABLE_LIST/sonic-acl:ACL_TABLE_NAME"; @@ -171,7 +170,7 @@ module sonic-acl { pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; } } - + leaf IP_PROTOCOL { type uint8 { range 1..143; @@ -283,9 +282,8 @@ module sonic-acl { path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; } } - } /* end of container ACL_TABLE */ } /* end of ACL_TABLE_LIST */ -} +} \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-interface.yang b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang new file mode 100644 index 000000000000..aa1a07ad2d3b --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang @@ -0,0 +1,79 @@ +module sonic-interface { + + namespace "http://sonic-interface"; + prefix sonic-intf; + + import ietf-yang-types { + prefix yang; + } + + import ietf-inet-types { + prefix inet; + } + + import sonic-head { + prefix sonic-head; + revision-date 2019-07-01; + } + + import sonic-port { + prefix sonic-port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "INTERFACE yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container INTERFACE { + + description "INTERFACE part of config_db.json"; + + list INTERFACE_LIST { + + key "interface ip-prefix"; +/* + sonic-head:sonic_db_path "INTERFACE"; [Todo: Fix by extension] + + sonic-head:sonic_db_schema { [Todo: Fix by extension] + "{interface}|{ip-prefix}": { + "scope": {scope}, + "family": {family} + } + } +*/ + leaf interface { + type leafref { + path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; + } + } + + leaf ip-prefix { + mandatory true; + type inet:ip-prefix; + } + + leaf scope { + type enumeration { + enum global; + enum local; + } + } + + leaf family { + must "(contains(../ip-prefix, ':') and current()='IPv6') or + (contains(../ip-prefix, '.') and current()='IPv4')"; + type sonic-head:ip-family; + } + } + /* end of INTERFACE_LIST */ + + } + /* end of INTERFACE container */ +} \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-port.yang b/src/sonic-yang-mgmt/yang-models/sonic-port.yang index 11145c480814..97cad636c58a 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-port.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-port.yang @@ -2,7 +2,7 @@ module sonic-port{ namespace "http://sonic-port"; prefix sonic-port; -/* + import ietf-yang-types { prefix yang; } @@ -10,7 +10,7 @@ module sonic-port{ import ietf-inet-types { prefix inet; } -*/ + import sonic-head { prefix sonic-head; revision-date 2019-07-01; @@ -49,23 +49,18 @@ module sonic-port{ leaf port_name { type string { length 1..128; - /* ; [Todo: verify this] */ } } leaf alias { - /* config false; */ type string { length 1..128; - /* ; [Todo] */ } } leaf lanes { - /* config false; */ type string { length 1..128; - /* ; [Todo] */ } } @@ -78,7 +73,6 @@ module sonic-port{ leaf speed { type uint32 { range 1..100000; - /* ; [Todo: verify this] */ } } @@ -97,4 +91,4 @@ module sonic-port{ } /* end of container PORT */ } -/* end of module sonic-port */ +/* end of module sonic-port */ \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang index 2bd1e3c263ff..bf8bf658af65 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang @@ -50,19 +50,16 @@ module sonic-vlan { */ leaf vlanid { type leafref { - path "/VLAN/VLAN_LIST/vlanid"; + path ../../../VLAN/VLAN_LIST/vlanid; } } - - /* We need a check like when "family = 'IPv6'"; */ leaf ip-prefix { mandatory true; type inet:ip-prefix; } leaf scope { - mandatory true; type enumeration { enum global; enum local; @@ -70,7 +67,8 @@ module sonic-vlan { } leaf family { - mandatory true; + must "(contains(../ip-prefix, ':') and current()='IPv6') or + (contains(../ip-prefix, '.') and current()='IPv4')"; type sonic-head:ip-family; } } diff --git a/src/sonic-yang-mgmt/yang-models/sonic_config_data.json b/src/sonic-yang-mgmt/yang-models/sonic_config_data.json deleted file mode 100644 index 9dacaf52d802..000000000000 --- a/src/sonic-yang-mgmt/yang-models/sonic_config_data.json +++ /dev/null @@ -1,259 +0,0 @@ -{ - "sonic-vlan:VLAN_INTERFACE": { - "VLAN_INTERFACE_LIST": [ - { - "vlanid": 100, - "ip-prefix": "2a04:f547:45:6709::1/64", - "scope": "global", - "family": "IPv6" - }, - { - "vlanid": 100, - "ip-prefix": "10.189.10.65/26", - "scope": "global", - "family": "IPv6" - }, - { - "vlanid": 100, - "ip-prefix": "fe80::1/10", - "scope": "local", - "family": "IPv6" - }, - { - "vlanid": 777, - "ip-prefix": "2a04:f547:41:4e9::1/64", - "scope": "global", - "family": "IPv6" - }, - { - "vlanid": 777, - "ip-prefix": "10.177.58.65/26", - "scope": "global", - "family": "IPv6" - }, - { - "vlanid": 777, - "ip-prefix": "fe80::1/10", - "scope": "local", - "family": "IPv6" - } - ] - }, - - "sonic-vlan:VLAN": { - "VLAN_LIST": [ - { - "vlanid": 100, - "description": "server_vlan", - "dhcp_servers": [ - "10.186.72.116" - ], - "mtu": "9216", - "admin_status": "up", - "members": [ - "Ethernet8", - "Ethernet3", - "Ethernet0", - "Ethernet1", - "Ethernet6", - "Ethernet4", - "Ethernet5", - "Ethernet9", - "Ethernet2" - ] - }, - { - "vlanid": 777, - "description": "ipmi_vlan", - "dhcp_servers": [ - "10.186.72.116" - ], - "mtu": "9216", - "admin_status": "up", - "members": [ - "Ethernet9", - "Ethernet2", - "Ethernet8" - ] - } - ] - }, - - "sonic-vlan:VLAN_MEMBER": { - "VLAN_MEMBER_LIST": [ - { - "vlanid": 100, - "port": "Ethernet0", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet1", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet2", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet3", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet4", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet5", - "tagging_mode": "tagged" - }, - { - "vlanid": 100, - "port": "Ethernet6", - "tagging_mode": "tagged" - } - ] - }, - - "sonic-port:PORT": { - "PORT_LIST": [ - { - "port_name": "Ethernet0", - "alias": "eth0", - "description": "Ethernet0", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet1", - "alias": "eth1", - "description": "Ethernet1", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet2", - "alias": "eth2", - "description": "Ethernet2", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet3", - "alias": "eth2", - "description": "Ethernet3", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet4", - "alias": "eth4", - "description": "Ethernet4", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet5", - "alias": "eth5", - "description": "Ethernet5", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet6", - "alias": "eth6", - "description": "Ethernet6", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet7", - "alias": "eth7", - "description": "Ethernet7", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet8", - "alias": "eth8", - "description": "Ethernet8", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - }, - { - "port_name": "Ethernet9", - "alias": "eth9", - "description": "Ethernet9", - "speed": 25000, - "mtu": 9000, - "admin_status": "up" - } - ] - }, - - "sonic-acl:ACL_RULE": { - "ACL_RULE_LIST": [ - { - "ACL_TABLE_NAME": "NO-NSW-PACL-V4", - "RULE_NAME": "Rule_20", - "PACKET_ACTION": "FORWARD", - "DST_IP": "10.186.72.0/26", - "SRC_IP": "10.176.0.0/15", - "PRIORITY": "999980", - "IP_TYPE": "IPV4ANY" - }, - { - "ACL_TABLE_NAME": "NO-NSW-PACL-V4", - "RULE_NAME": "Rule_40", - "PACKET_ACTION": "FORWARD", - "DST_IP": "10.186.72.64/26", - "SRC_IP": "10.176.0.0/15", - "PRIORITY": "999960", - "IP_TYPE": "IPV4ANY", - "INNER_ETHER_TYPE": "0x88CC" - }, - { - "ACL_TABLE_NAME": "NO-NSW-PACL-V6", - "RULE_NAME": "Rule_20", - "PACKET_ACTION": "FORWARD", - "IP_TYPE": "IP", - "SRC_IPV6": "2a04:f547:41::/48", - "PRIORITY": "999980", - "DST_IPV6": "2a04:f547:43:320::/64", - "L4_SRC_PORT_RANGE": "653-1053" - } - ] - }, - - "sonic-acl:ACL_TABLE": { - "ACL_TABLE_LIST": [ - { - "ACL_TABLE_NAME": "NO-NSW-PACL-V6", - "policy_desc": "Filter IPv6", - "type": "L3V6", - "stage": "EGRESS", - "ports": ["Ethernet7", "Ethernet9", "Ethernet8"] - }, - { - "ACL_TABLE_NAME": "NO-NSW-PACL-V4", - "policy_desc": "Filter IPv6", - "type": "L3", - "stage": "INGRESS", - "ports": ["Ethernet2", "Ethernet0", "Ethernet1"] - } - ] - } -} From 9519de99b5ebd315181fd05f8713fcf5d3d3beb4 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Mon, 30 Sep 2019 15:11:45 -0700 Subject: [PATCH 5/5] [Sonic Yang Tree]: Modified YANG models as per Guidelines. Guideline doc: https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md --- .../yang-models/Sonic Yang Tree | 180 +++--- .../yang-models/sonic-acl.yang | 555 +++++++++--------- .../yang-models/sonic-head.yang | 4 - .../yang-models/sonic-interface.yang | 155 +++-- .../yang-models/sonic-port.yang | 174 +++--- .../yang-models/sonic-portchannel.yang | 85 +++ .../yang-models/sonic-vlan.yang | 334 +++++------ 7 files changed, 767 insertions(+), 720 deletions(-) create mode 100644 src/sonic-yang-mgmt/yang-models/sonic-portchannel.yang diff --git a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree index b64dda8175c5..6dc84d264054 100644 --- a/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree +++ b/src/sonic-yang-mgmt/yang-models/Sonic Yang Tree @@ -1,87 +1,101 @@ module: sonic-acl - +--rw ACL_RULE - | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] - | +--rw ACL_TABLE_NAME -> /ACL_TABLE/ACL_TABLE_LIST/ACL_TABLE_NAME - | +--rw RULE_NAME string - | +--rw PACKET_ACTION? sonic-head:packet_action - | +--rw IP_TYPE? sonic-head:ip_type - | +--rw PRIORITY? uint32 - | +--rw (ip_prefix)? - | | +--:(ip4_prefix) - | | | +--rw SRC_IP? inet:ipv4-prefix - | | | +--rw DST_IP? inet:ipv4-prefix - | | +--:(ip6_prefix) - | | +--rw SRC_IPV6? inet:ipv6-prefix - | | +--rw DST_IPV6? inet:ipv6-prefix - | +--rw IN_PORTS* uint16 - | +--rw OUT_PORTS* uint16 - | +--rw (src_port)? - | | +--:(l4_src_port) - | | | +--rw L4_SRC_PORT? uint16 - | | +--:(l4_src_port_range) - | | +--rw L4_SRC_PORT_RANGE? string - | +--rw (dst_port)? - | | +--:(l4_dst_port) - | | | +--rw L4_DST_PORT? uint16 - | | +--:(l4_dst_port_range) - | | +--rw L4_DST_PORT_RANGE? string - | +--rw ETHER_TYPE? string - | +--rw IP_PROTOCOL? uint8 - | +--rw TCP_FLAGS? string - | +--rw DSCP? uint8 - | +--rw TC? uint8 - | +--rw (icmp)? - | | +--:(icmp4) - | | | +--rw ICMP_TYPE? uint8 - | | | +--rw ICMP_CODE? uint8 - | | +--:(icmp6) - | | +--rw ICMPV6_TYPE? uint8 - | | +--rw ICMPV6_CODE? uint8 - | +--rw INNER_ETHER_TYPE? string - | +--rw INNER_IP_PROTOCOL? uint8 - | +--rw INNER_L4_SRC_PORT? uint16 - | +--rw INNER_L4_DST_PORT? uint16 - +--rw ACL_TABLE - +--rw ACL_TABLE_LIST* [ACL_TABLE_NAME] - +--rw ACL_TABLE_NAME string - +--rw policy_desc? string - +--rw type? sonic-head:acl_table_type - +--rw stage? enumeration - +--rw ports* -> /sonic-port:PORT/PORT_LIST/port_name + +--rw sonic-acl + +--rw ACL_RULE + | +--rw ACL_RULE_LIST* [ACL_TABLE_NAME RULE_NAME] + | +--rw ACL_TABLE_NAME -> /sonic-acl/ACL_TABLE/ACL_TABLE_LIST/ACL_TABLE_NAME + | +--rw RULE_NAME string + | +--rw PACKET_ACTION? head:packet_action + | +--rw IP_TYPE? head:ip_type + | +--rw PRIORITY? uint32 + | +--rw (ip_prefix)? + | | +--:(ip4_prefix) + | | | +--rw SRC_IP? inet:ipv4-prefix + | | | +--rw DST_IP? inet:ipv4-prefix + | | +--:(ip6_prefix) + | | +--rw SRC_IPV6? inet:ipv6-prefix + | | +--rw DST_IPV6? inet:ipv6-prefix + | +--rw IN_PORTS* uint16 + | +--rw OUT_PORTS* uint16 + | +--rw (src_port)? + | | +--:(l4_src_port) + | | | +--rw L4_SRC_PORT? uint16 + | | +--:(l4_src_port_range) + | | +--rw L4_SRC_PORT_RANGE? string + | +--rw (dst_port)? + | | +--:(l4_dst_port) + | | | +--rw L4_DST_PORT? uint16 + | | +--:(l4_dst_port_range) + | | +--rw L4_DST_PORT_RANGE? string + | +--rw ETHER_TYPE? string + | +--rw IP_PROTOCOL? uint8 + | +--rw TCP_FLAGS? string + | +--rw DSCP? uint8 + | +--rw TC? uint8 + | +--rw (icmp)? + | | +--:(icmp4) + | | | +--rw ICMP_TYPE? uint8 + | | | +--rw ICMP_CODE? uint8 + | | +--:(icmp6) + | | +--rw ICMPV6_TYPE? uint8 + | | +--rw ICMPV6_CODE? uint8 + | +--rw INNER_ETHER_TYPE? string + | +--rw INNER_IP_PROTOCOL? uint8 + | +--rw INNER_L4_SRC_PORT? uint16 + | +--rw INNER_L4_DST_PORT? uint16 + +--rw ACL_TABLE + +--rw ACL_TABLE_LIST* [ACL_TABLE_NAME] + +--rw ACL_TABLE_NAME string + +--rw policy_desc? string + +--rw type? head:acl_table_type + +--rw stage? enumeration + +--rw ports* union module: sonic-interface - +--rw INTERFACE - +--rw INTERFACE_LIST* [interface ip-prefix] - +--rw interface -> /sonic-port:PORT/PORT_LIST/port_name - +--rw ip-prefix inet:ip-prefix - +--rw scope? enumeration - +--rw family? sonic-head:ip-family + +--rw sonic-interface + +--rw INTERFACE + +--rw INTERFACE_LIST* [interface ip-prefix] + +--rw interface -> /port:sonic-port/PORT/PORT_LIST/port_name + +--rw ip-prefix inet:ip-prefix + +--rw scope? enumeration + +--rw family? head:ip-family module: sonic-port - +--rw PORT - +--rw PORT_LIST* [port_name] - +--rw port_name string - +--rw alias? string - +--rw lanes? string - +--rw description? string - +--rw speed? uint32 - +--rw mtu? uint16 - +--rw admin_status sonic-head:admin_status + +--rw sonic-port + +--rw PORT + +--rw PORT_LIST* [port_name] + +--rw port_name string + +--rw alias? string + +--rw lanes? string + +--rw description? string + +--rw speed? uint32 + +--rw mtu? uint16 + +--rw admin_status head:admin_status +module: sonic-portchannel + +--rw sonic-portchannel + +--rw PORTCHANNEL + +--rw PORTCHANNEL_LIST* [portchannel_name] + +--rw portchannel_name string + +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name + +--rw min_links? uint8 + +--rw description? string + +--rw mtu? uint16 + +--rw admin_status head:admin_status module: sonic-vlan - +--rw VLAN_INTERFACE - | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] - | +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid - | +--rw ip-prefix inet:ip-prefix - | +--rw scope? enumeration - | +--rw family? sonic-head:ip-family - +--rw VLAN - | +--rw VLAN_LIST* [vlanid] - | +--rw vlanid uint16 - | +--rw description? string - | +--rw dhcp_servers* inet:ip-address - | +--rw mtu? uint16 - | +--rw admin_status sonic-head:admin_status - | +--rw members* -> /sonic-port:PORT/PORT_LIST/port_name - +--rw VLAN_MEMBER - +--rw VLAN_MEMBER_LIST* [vlanid port] - +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid - +--rw port -> /sonic-port:PORT/PORT_LIST/port_name - +--rw tagging_mode sonic-head:vlan_tagging_mode + +--rw sonic-vlan + +--rw VLAN_INTERFACE + | +--rw VLAN_INTERFACE_LIST* [vlanid ip-prefix] + | +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid + | +--rw ip-prefix inet:ip-prefix + | +--rw scope? enumeration + | +--rw family? head:ip-family + +--rw VLAN + | +--rw VLAN_LIST* [vlanid] + | +--rw vlanid uint16 + | +--rw description? string + | +--rw dhcp_servers* inet:ip-address + | +--rw mtu? uint16 + | +--rw admin_status head:admin_status + | +--rw members* -> /port:sonic-port/PORT/PORT_LIST/port_name + +--rw VLAN_MEMBER + +--rw VLAN_MEMBER_LIST* [vlanid port] + +--rw vlanid -> ../../../VLAN/VLAN_LIST/vlanid + +--rw port -> /port:sonic-port/PORT/PORT_LIST/port_name + +--rw tagging_mode head:vlan_tagging_mode diff --git a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang index 29ecda668224..cdd5a53f912e 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-acl.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-acl.yang @@ -1,289 +1,272 @@ module sonic-acl { - namespace "http://sonic-acl"; - prefix sonic-acl; - - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - - import sonic-head { - prefix sonic-head; - revision-date 2019-07-01; - } - - import sonic-port { - prefix sonic-port; - revision-date 2019-07-01; - } - - organization "Linkedin Corporation"; - - contact "lnos_coders@linkedin.com"; - - description "ACL yang Module for SONiC OS"; - - revision 2019-07-01 { - description "First Revision"; - } - - container ACL_RULE { - - description "ACL_RULE part of config_db.json"; - - list ACL_RULE_LIST { - - key "ACL_TABLE_NAME RULE_NAME"; -/* - sonic-head:sonic_db_path "ACL_RULE"; - - sonic-head:sonic_db_schema { - "{ACL_TABLE_NAME}|{RULE_NAME}": { - "PACKET_ACTION": {PACKET_ACTION}, - "IP_TYPE": {IP_TYPE}, - "PRIORITY": {PRIORITY} - "DST_IP": {DST_IP}, - "SRC_IP": {SRC_IP}, - "SRC_IPV6": {SRC_IPV6}, - "DST_IPV6": {DST_IPV6}, - "IN_PORTS": {IN_PORTS}, - "OUT_PORTS": {OUT_PORTS}, - "L4_SRC_PORT": {L4_SRC_PORT}, - "L4_DST_PORT": {L4_DST_PORT}, - "L4_SRC_PORT_RANGE": {L4_SRC_PORT_RANGE}, - "L4_DST_PORT_RANGE": {L4_DST_PORT_RANGE}, - "ETHER_TYPE": {ETHER_TYPE}, - "IP_PROTOCOL": {IP_PROTOCOL}, - "TCP_FLAGS": {TCP_FLAGS}, - "DSCP": {DSCP}, - "TC": {TC}, - "ICMP_TYPE": {ICMP_TYPE}, - "ICMP_CODE": {ICMP_CODE}, - "ICMPV6_TYPE": {ICMPV6_TYPE}, - "ICMPV6_CODE": {ICMPV6_CODE}, - "INNER_ETHER_TYPE": {INNER_ETHER_TYPE}, - "INNER_IP_PROTOCOL": {INNER_IP_PROTOCOL}, - "INNER_L4_SRC_PORT": {INNER_L4_SRC_PORT}, - "INNER_L4_DST_PORT": {INNER_L4_DST_PORT} - } - } -*/ - leaf ACL_TABLE_NAME { - type leafref { - path "/sonic-acl:ACL_TABLE/sonic-acl:ACL_TABLE_LIST/sonic-acl:ACL_TABLE_NAME"; - } - } - - leaf RULE_NAME { - type string { - length 1..255; - } - } - - leaf PACKET_ACTION { - type sonic-head:packet_action; - } - - leaf IP_TYPE { - type sonic-head:ip_type; - } - - leaf PRIORITY { - type uint32 { - range 0..999999; - } - } - - choice ip_prefix { - - case ip4_prefix { - when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; - leaf SRC_IP { - type inet:ipv4-prefix; - } - - leaf DST_IP { - type inet:ipv4-prefix; - } - } - - case ip6_prefix { - when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; - leaf SRC_IPV6 { - type inet:ipv6-prefix; - } - - leaf DST_IPV6 { - type inet:ipv6-prefix; - } - } - } - - leaf-list IN_PORTS { - /* Values in leaf list are UNIQUE */ - type uint16; - } - - leaf-list OUT_PORTS { - /* Values in leaf list are UNIQUE */ - type uint16; - } - - choice src_port { - case l4_src_port { - leaf L4_SRC_PORT { - type uint16; - } - } - - case l4_src_port_range { - leaf L4_SRC_PORT_RANGE { - type string { - pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; - } - } - } - } - - choice dst_port { - case l4_dst_port { - leaf L4_DST_PORT { - type uint16; - } - } - - case l4_dst_port_range { - leaf L4_DST_PORT_RANGE { - type string { - pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; - } - } - } - } - - leaf ETHER_TYPE { - type string { - pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; - } - } - - leaf IP_PROTOCOL { - type uint8 { - range 1..143; - } - } - - leaf TCP_FLAGS { - type string { - pattern '0[x][0-9a-fA-F]{1,2}|0[X][0-9a-fA-F]{1,2}'; - } - } - - leaf DSCP { - type uint8; - } - - leaf TC { - type uint8; - } - - choice icmp { - - case icmp4 { - when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; - leaf ICMP_TYPE { - type uint8 { - range 1..44; - } - } - - leaf ICMP_CODE { - type uint8 { - range 1..16; - } - } - } - - case icmp6 { - when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; - leaf ICMPV6_TYPE { - type uint8 { - range 1..44; - } - } - - leaf ICMPV6_CODE { - type uint8 { - range 1..16; - } - } - } - } - - leaf INNER_ETHER_TYPE { - type string { - pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; - } - } - - leaf INNER_IP_PROTOCOL { - type uint8 { - range 1..143; - } - } - - leaf INNER_L4_SRC_PORT { - type uint16; - } - - leaf INNER_L4_DST_PORT { - type uint16; - } - } - /* end of ACL_RULE_LIST */ - } - /* end of container ACL_RULE */ - - container ACL_TABLE { - - description "ACL_TABLE part of config_db.json"; - - list ACL_TABLE_LIST { - - key "ACL_TABLE_NAME"; - - leaf ACL_TABLE_NAME { - type string; - } - - leaf policy_desc { - type string { - length 1..255; - } - } - - leaf type { - type sonic-head:acl_table_type; - } - - leaf stage { - type enumeration { - enum INGRESS; - enum EGRESS; - } - } - - leaf-list ports { - type leafref { - path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; - } - } - } + 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; + revision-date 2019-07-01; + } + + import sonic-port { + prefix port; + revision-date 2019-07-01; + } + + import sonic-portchannel { + prefix lag; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "ACL YANG Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container sonic-acl { + + container ACL_RULE { + + description "ACL_RULE part of config_db.json"; + + list ACL_RULE_LIST { + + key "ACL_TABLE_NAME RULE_NAME"; + + leaf ACL_TABLE_NAME { + type leafref { + path "/acl:sonic-acl/acl:ACL_TABLE/acl:ACL_TABLE_LIST/acl:ACL_TABLE_NAME"; + } + } + + leaf RULE_NAME { + type string { + length 1..255; + } + } + + leaf PACKET_ACTION { + type head:packet_action; + } + + leaf IP_TYPE { + type head:ip_type; + } + + leaf PRIORITY { + type uint32 { + range 0..999999; + } + } + + choice ip_prefix { + + case ip4_prefix { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; + leaf SRC_IP { + type inet:ipv4-prefix; + } + + leaf DST_IP { + type inet:ipv4-prefix; + } + } + + case ip6_prefix { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; + leaf SRC_IPV6 { + type inet:ipv6-prefix; + } + + leaf DST_IPV6 { + type inet:ipv6-prefix; + } + } + } + + leaf-list IN_PORTS { + /* Values in leaf list are UNIQUE */ + type uint16; + } + + leaf-list OUT_PORTS { + /* Values in leaf list are UNIQUE */ + type uint16; + } + + choice src_port { + case l4_src_port { + leaf L4_SRC_PORT { + type uint16; + } + } + + case l4_src_port_range { + leaf L4_SRC_PORT_RANGE { + type string { + pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; + } + } + } + } + + choice dst_port { + case l4_dst_port { + leaf L4_DST_PORT { + type uint16; + } + } + + case l4_dst_port_range { + leaf L4_DST_PORT_RANGE { + type string { + pattern '([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])'; + } + } + } + } + + leaf ETHER_TYPE { + type string { + pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; + } + } + + leaf IP_PROTOCOL { + type uint8 { + range 1..143; + } + } + + leaf TCP_FLAGS { + type string { + pattern '0[x][0-9a-fA-F]{1,2}|0[X][0-9a-fA-F]{1,2}'; + } + } + + leaf DSCP { + type uint8; + } + + leaf TC { + type uint8; + } + + choice icmp { + + case icmp4 { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV4' or .='IPV4ANY' or .='ARP'])"; + leaf ICMP_TYPE { + type uint8 { + range 1..44; + } + } + + leaf ICMP_CODE { + type uint8 { + range 1..16; + } + } + } + + case icmp6 { + when "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])"; + leaf ICMPV6_TYPE { + type uint8 { + range 1..44; + } + } + + leaf ICMPV6_CODE { + type uint8 { + range 1..16; + } + } + } + } + + leaf INNER_ETHER_TYPE { + type string { + pattern "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)"; + } + } + + leaf INNER_IP_PROTOCOL { + type uint8 { + range 1..143; + } + } + + leaf INNER_L4_SRC_PORT { + type uint16; + } + + leaf INNER_L4_DST_PORT { + type uint16; + } + } + /* end of ACL_RULE_LIST */ + } + /* end of container ACL_RULE */ + + container ACL_TABLE { + + description "ACL_TABLE part of config_db.json"; + + list ACL_TABLE_LIST { + + key "ACL_TABLE_NAME"; + + leaf ACL_TABLE_NAME { + type string; + } + + leaf policy_desc { + type string { + length 1..255; + } + } + + leaf type { + type head:acl_table_type; + } + + leaf stage { + type enumeration { + enum INGRESS; + enum EGRESS; + } + } + + leaf-list ports { + /* union of leafref is allowed in YANG 1.1 */ + type union { + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + type leafref { + path /lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:portchannel_name; + } + } + } + } + /* end of ACL_TABLE_LIST */ + } /* end of container ACL_TABLE */ - } - /* end of ACL_TABLE_LIST */ -} \ No newline at end of file + } + /* end of container sonic-acl */ +} +/* end of module sonic-acl */ diff --git a/src/sonic-yang-mgmt/yang-models/sonic-head.yang b/src/sonic-yang-mgmt/yang-models/sonic-head.yang index 1f2875fca15e..dd0da92c7152 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-head.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-head.yang @@ -69,8 +69,4 @@ module sonic-head { enum priority_tagged; } } - - extension sonic_db_path; - - extension sonic_db_schema; } \ No newline at end of file diff --git a/src/sonic-yang-mgmt/yang-models/sonic-interface.yang b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang index aa1a07ad2d3b..dc8bc7389ea1 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-interface.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-interface.yang @@ -1,79 +1,78 @@ module sonic-interface { - - namespace "http://sonic-interface"; - prefix sonic-intf; - - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - - import sonic-head { - prefix sonic-head; - revision-date 2019-07-01; - } - - import sonic-port { - prefix sonic-port; - revision-date 2019-07-01; - } - - organization "Linkedin Corporation"; - - contact "lnos_coders@linkedin.com"; - - description "INTERFACE yang Module for SONiC OS"; - - revision 2019-07-01 { - description "First Revision"; - } - - container INTERFACE { - - description "INTERFACE part of config_db.json"; - - list INTERFACE_LIST { - - key "interface ip-prefix"; -/* - sonic-head:sonic_db_path "INTERFACE"; [Todo: Fix by extension] - - sonic-head:sonic_db_schema { [Todo: Fix by extension] - "{interface}|{ip-prefix}": { - "scope": {scope}, - "family": {family} - } - } -*/ - leaf interface { - type leafref { - path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; - } - } - - leaf ip-prefix { - mandatory true; - type inet:ip-prefix; - } - - leaf scope { - type enumeration { - enum global; - enum local; - } - } - - leaf family { - must "(contains(../ip-prefix, ':') and current()='IPv6') or - (contains(../ip-prefix, '.') and current()='IPv4')"; - type sonic-head:ip-family; - } - } - /* end of INTERFACE_LIST */ - - } - /* end of INTERFACE container */ -} \ No newline at end of file + + 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; + revision-date 2019-07-01; + } + + import sonic-port { + prefix port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "INTERFACE yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container sonic-interface { + container INTERFACE { + + description "INTERFACE part of config_db.json"; + + list INTERFACE_LIST { + + key "interface ip-prefix"; + + leaf interface { + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + } + + leaf ip-prefix { + type inet:ip-prefix; + } + + leaf scope { + type enumeration { + enum global; + enum local; + } + } + + leaf family { + + /* family leaf needed for backward compatibility + Both ip4 and ip6 address are string in IETF RFC 6021, + so must statement can check based on : or ., family + should be IPv4 or IPv6 according. + */ + + must "(contains(../ip-prefix, ':') and current()='IPv6') or + (contains(../ip-prefix, '.') and current()='IPv4')"; + type head:ip-family; + } + } + /* end of INTERFACE_LIST */ + + } + /* end of INTERFACE container */ + } +} diff --git a/src/sonic-yang-mgmt/yang-models/sonic-port.yang b/src/sonic-yang-mgmt/yang-models/sonic-port.yang index 97cad636c58a..be04a8aea4bd 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-port.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-port.yang @@ -1,94 +1,84 @@ module sonic-port{ - namespace "http://sonic-port"; - prefix sonic-port; - - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - - import sonic-head { - prefix sonic-head; - revision-date 2019-07-01; - } - - organization "Linkedin Corporation"; - - contact "lnos_coders@linkedin.com"; - - description "PORT yang Module for SONiC OS"; - - revision 2019-07-01 { - description "First Revision"; - } - - container PORT { - - description "PORT part of config_db.json"; - - list PORT_LIST { - - key "port_name"; -/* - sonic-head:sonic_db_path = PORT; [Todo: Fix by extension] - - sonic-head:sonic_db_schema { [Todo: Fix by extension] - {port_name}: { - "alias": {alias}, - "lanes": {lanes}, - "description": {description}, - "speed": {speed}, - "mtu": {mtu} - } - } -*/ - leaf port_name { - type string { - length 1..128; - } - } - - leaf alias { - type string { - length 1..128; - } - } - - leaf lanes { - type string { - length 1..128; - } - } - - leaf description { - type string { - length 1..255; - } - } - - leaf speed { - type uint32 { - range 1..100000; - } - } - - leaf mtu { - type uint16 { - range 1..9216; - } - } - - leaf admin_status { - mandatory true; - type sonic-head:admin_status; - } - } - /* end of list PORT_LIST */ - } - /* end of container PORT */ -} -/* end of module sonic-port */ \ No newline at end of file + 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; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "PORT yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container sonic-port{ + container PORT { + + description "PORT part of config_db.json"; + + list PORT_LIST { + + key "port_name"; + + leaf port_name { + type string { + length 1..128; + } + } + + leaf alias { + type string { + length 1..128; + } + } + + leaf lanes { + type string { + length 1..128; + } + } + + leaf description { + type string { + length 1..255; + } + } + + leaf speed { + type uint32 { + range 1..100000; + } + } + + leaf mtu { + type uint16 { + range 1..9216; + } + } + + leaf admin_status { + mandatory true; + type head:admin_status; + } + } /* end of list PORT_LIST */ + + } /* end of container PORT */ + + } /* end of container sonic-port */ + +} /* end of module sonic-port */ diff --git a/src/sonic-yang-mgmt/yang-models/sonic-portchannel.yang b/src/sonic-yang-mgmt/yang-models/sonic-portchannel.yang new file mode 100644 index 000000000000..656351f4e635 --- /dev/null +++ b/src/sonic-yang-mgmt/yang-models/sonic-portchannel.yang @@ -0,0 +1,85 @@ +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; + revision-date 2019-07-01; + } + + import sonic-port { + prefix port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "PORTCHANNEL yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container sonic-portchannel { + container PORTCHANNEL { + + description "PORTCHANNEL part of config_db.json"; + + list PORTCHANNEL_LIST { + + key "portchannel_name"; + + leaf portchannel_name { + type string { + length 1..128; + pattern 'PortChannel[0-9]{1,4}'; + } + } + + leaf-list members { + /* leaf-list members are unique by default */ + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + } + + leaf min_links { + type uint8 { + range 1..128; + } + } + + leaf description { + type string { + length 1..255; + } + } + + leaf mtu { + type uint16 { + range 1..9216; + } + } + + leaf admin_status { + mandatory true; + type head:admin_status; + } + } /* end of list PORTCHANNEL_LIST */ + + } /* end of container PORTCHANNEL */ + + } /* end of container sonic-portchannel */ + +} /* end of module sonic-port */ diff --git a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang index bf8bf658af65..6058ce3f1bfc 100644 --- a/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-mgmt/yang-models/sonic-vlan.yang @@ -1,178 +1,158 @@ module sonic-vlan { - - namespace "http://sonic-vlan"; - prefix sonic-vlan; - - import ietf-yang-types { - prefix yang; - } - - import ietf-inet-types { - prefix inet; - } - - import sonic-head { - prefix sonic-head; - revision-date 2019-07-01; - } - - import sonic-port { - prefix sonic-port; - revision-date 2019-07-01; - } - - organization "Linkedin Corporation"; - - contact "lnos_coders@linkedin.com"; - - description "VLAN yang Module for SONiC OS"; - - revision 2019-07-01 { - description "First Revision"; - } - - container VLAN_INTERFACE { - - description "VLAN_INTERFACE part of config_db.json"; - - list VLAN_INTERFACE_LIST { - - key "vlanid ip-prefix"; -/* - sonic-head:sonic_db_path "VLAN_INTERFACE"; [Todo: Fix by extension] - - sonic-head:sonic_db_schema { [Todo: Fix by extension] - "Vlan{vlanid}|{ip-prefix}": { - "scope": {scope}, - "family": {family} - } - } -*/ - leaf vlanid { - type leafref { - path ../../../VLAN/VLAN_LIST/vlanid; - } - } - - leaf ip-prefix { - mandatory true; - type inet:ip-prefix; - } - - leaf scope { - type enumeration { - enum global; - enum local; - } - } - - leaf family { - must "(contains(../ip-prefix, ':') and current()='IPv6') or - (contains(../ip-prefix, '.') and current()='IPv4')"; - type sonic-head:ip-family; - } - } - /* end of VLAN_INTERFACE_LIST */ - - } - /* end of VLAN_INTERFACE container */ - - container VLAN { - - description "VLAN part of config_db.json"; - - list VLAN_LIST { - - key "vlanid"; -/* - \sonic_db_path "VLAN"; - - sonic-head:sonic_db_schema { - "Vlan{vlanid}: { - "description": {description}, - "dhcp_servers": {dhcp_servers}, - "vlanid": {vlanid}, - "mtu": {mtu}, - "admin_status": {admin_status}, - "members": {members}, - } - } -*/ - leaf vlanid { - type uint16 { - range 1..4094; - } - } - - leaf description { - type string { - length 1..255; - } - } - - leaf-list dhcp_servers { - type inet:ip-address; - } - - leaf mtu { - type uint16 { - range 1..9216; - } - } - - leaf admin_status { - mandatory true; - type sonic-head:admin_status; - } - - leaf-list members { - /* leaf-list members are unique by default */ - - type leafref { - path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; - } - } - } - /* end of VLAN_LIST */ - } - /* end of container VLAN */ - - container VLAN_MEMBER { - - description "VLAN_MEMBER part of config_db.json"; - - list VLAN_MEMBER_LIST { - - key "vlanid port"; -/* - sonic-head:sonic_db_path "VLAN"; - - sonic-head:sonic_db_schema { - "Vlan{vlanid}|{port}": { - "tagging_mode": {tagging_mode} - } - } -*/ - leaf vlanid { - type leafref { - path ../../../VLAN/VLAN_LIST/vlanid; - } - } - - leaf port { - /* key elements are mandatory by default */ - mandatory true; - type leafref { - path /sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name; - } - } - - leaf tagging_mode { - mandatory true; - type sonic-head:vlan_tagging_mode; - } - } - /* end of list VLAN_MEMBER_LIST */ - } - /* end of container VLAN_MEMBER */ -} \ No newline at end of file + + 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; + revision-date 2019-07-01; + } + + import sonic-port { + prefix port; + revision-date 2019-07-01; + } + + organization "Linkedin Corporation"; + + contact "lnos_coders@linkedin.com"; + + description "VLAN yang Module for SONiC OS"; + + revision 2019-07-01 { + description "First Revision"; + } + + container sonic-vlan { + container VLAN_INTERFACE { + + description "VLAN_INTERFACE part of config_db.json"; + + list VLAN_INTERFACE_LIST { + + key "vlanid ip-prefix"; + + leaf vlanid { + type leafref { + path ../../../VLAN/VLAN_LIST/vlanid; + } + } + + leaf ip-prefix { + mandatory true; + type inet:ip-prefix; + } + + leaf scope { + type enumeration { + enum global; + enum local; + } + } + + leaf family { + + /* family leaf needed for backward compatibility + Both ip4 and ip6 address are string in IETF RFC 6021, + so must statement can check based on : or ., family + should be IPv4 or IPv6 according. + */ + + must "(contains(../ip-prefix, ':') and current()='IPv6') or + (contains(../ip-prefix, '.') and current()='IPv4')"; + type head:ip-family; + } + } + /* end of VLAN_INTERFACE_LIST */ + } + /* end of VLAN_INTERFACE container */ + + container VLAN { + + description "VLAN part of config_db.json"; + + list VLAN_LIST { + + key "vlanid"; + + leaf vlanid { + type uint16 { + range 1..4094; + } + } + + leaf description { + type string { + length 1..255; + } + } + + leaf-list dhcp_servers { + type inet:ip-address; + } + + leaf mtu { + type uint16 { + range 1..9216; + } + } + + leaf admin_status { + mandatory true; + type head:admin_status; + } + + leaf-list members { + /* leaf-list members are unique by default */ + + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + } + } + /* end of VLAN_LIST */ + } + /* end of container VLAN */ + + container VLAN_MEMBER { + + description "VLAN_MEMBER part of config_db.json"; + + list VLAN_MEMBER_LIST { + + key "vlanid port"; + + leaf vlanid { + type leafref { + path ../../../VLAN/VLAN_LIST/vlanid; + } + } + + leaf port { + /* key elements are mandatory by default */ + mandatory true; + type leafref { + path /port:sonic-port/port:PORT/port:PORT_LIST/port:port_name; + } + } + + leaf tagging_mode { + mandatory true; + type head:vlan_tagging_mode; + } + } + /* end of list VLAN_MEMBER_LIST */ + } + /* end of container VLAN_MEMBER */ + } + /* end of container sonic-vlan */ +} +/* end of module sonic-vlan */