Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yang-models]: First version of yang models for Port, VLan and ACL. #2

Merged
merged 5 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions src/sonic-yang-mgmt/test_code/yangModelTesting.py
Original file line number Diff line number Diff line change
@@ -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()
101 changes: 101 additions & 0 deletions src/sonic-yang-mgmt/yang-models/Sonic Yang Tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module: sonic-acl
+--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 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 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 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
Loading