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

[_sonic_yang_ext.py]: Extend sonic yang class to support cropping, transalation, reverse translation of Config DB. #3891

Closed

Conversation

praveen-li
Copy link
Collaborator

@praveen-li praveen-li commented Dec 12, 2019

…config DB.

This PR changes are added in PR 3861 now.

From the json format of yang models, a map is created from config DB tables
to container in yang model. Input Config is cropped on based of this map.
Input Config is also translated based of this map.
Similarly from yang data tree, output is reverse translated to config DB.

This PR also includes:
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.

- What I did
-- Cropping input config based on Yang Model.
-- Translate input config based on Yang Model.
-- rev Translate input config based on Yang Model.
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.

- How I did it
Yang model can be represented in JSON as below:

{
  "module": {
    "@name": "sonic-vlan", 
    "@xmlns": "urn:ietf:params:xml:ns:yang:yin:1", 
    "@xmlns:vlan": "http://github.com/Azure/sonic-vlan", 
    "@xmlns:yang": "urn:ietf:params:xml:ns:yang:ietf-yang-types", 
    "@xmlns:inet": "urn:ietf:params:xml:ns:yang:ietf-inet-types", 
    "@xmlns:head": "http://sonic-head", 
    "@xmlns:port": "http://github.com/Azure/sonic-port", 
    "namespace": {
      "@uri": "http://github.com/Azure/sonic-vlan"
    }, 
    "prefix": {
      "@value": "vlan"
    }, 
    "import": [
      {
        "@module": "ietf-yang-types", 
        "prefix": {
          "@value": "yang"
        }
      }, 
      {
        "@module": "ietf-inet-types", 
        "prefix": {
          "@value": "inet"
        }
      }, 
      {
        "@module": "sonic-head", 
        "prefix": {
          "@value": "head"
        }, 
        "revision-date": {
          "@date": "2019-07-01"
        }
      }, 
      {
        "@module": "sonic-port", 
        "prefix": {
          "@value": "port"
        }, 
        "revision-date": {
          "@date": "2019-07-01"
        }
      }
    ], 
    "organization": {
      "text": "Linkedin Corporation"
    }, 
    "contact": {
      "text": "lnos_coders@linkedin.com"
    }, 
    "description": {
      "text": "VLAN yang Module for SONiC OS"
    }, 
    "revision": {
      "@date": "2019-07-01", 
      "description": {
        "text": "First Revision"
      }
    },
    "container": {
      "@name": "sonic-vlan", 
      "container": [
        {
          "@name": "VLAN_INTERFACE", 
          "description": {
            "text": "VLAN_INTERFACE part of config_db.json"
          }, 
          "list": {
            "@name": "VLAN_INTERFACE_LIST", 
            "key": {
              "@value": "vlanid ip-prefix"
            }, 
            "leaf": [
              {
                "@name": "vlanid", 
                "type": {
                  "@name": "leafref", 
                  "path": {
                    "@value": "../../../VLAN/VLAN_LIST/vlanid"
                  }
                }
              }, 
              {
                "@name": "ip-prefix", 
                "type": {
                  "@name": "inet:ip-prefix"
                }, 
                "mandatory": {
                  "@value": "true"
                }
              }, 

This is used to create a map between Config DB Table and YANG Model Container.
Note: As per guideline https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md. Table maps to only container in YANG.

Map and json format of yang model is used to:
-- Cropping input config based on Yang Model.
-- Translate input config based on Yang Model.
-- rev Translate input config based on Yang Model.
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.

- How to verify it
Added PyTest:
Below are sample config and cropped config files.

{
	"VLAN_INTERFACE": {
		"Vlan111|2a04:5555:45:6709::1/64": {
			"scope": "global",
			"family": "IPv6"
		},
		"Vlan111|10.222.10.65/26": {
			"scope": "global",
			"family": "IPv4"
		},
		"Vlan111|fe80::1/10": {
			"scope": "local",
			"family": "IPv6"
		},
		"Vlan777|2a04:5555:41:4e9::1/64": {
			"scope": "global",
			"family": "IPv6"
		},
		"Vlan777|10.111.58.65/26": {
			"scope": "global",
			"family": "IPv4"
		},
		"Vlan777|fe80::1/10": {
			"scope": "local",
			"family": "IPv6"
		}
	},
	"ACL_RULE": {
		"V4-ACL-TABLE|DEFAULT_DENY": {
			"PACKET_ACTION": "DROP",
			"IP_TYPE": "IPv4ANY",
			"PRIORITY": "0"
		},
		"V4-ACL-TABLE|Rule_20": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.222.72.0/26",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777780",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_40": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.222.72.64/26",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777760",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_60": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.222.80.0/26",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777740",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_80": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.222.80.64/26",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777720",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_111": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.152.17.52/32",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777700",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_120": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.252.208.41/32",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777880",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_140": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.148.128.245/32",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777860",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_160": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.222.1.245/32",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777840",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_180": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "10.252.222.21/32",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "777820",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_9000": {
			"PACKET_ACTION": "DROP",
			"DST_IP": "0.0.0.0/0",
			"SRC_IP": "10.222.0.0/15",
			"PRIORITY": "991110",
			"IP_TYPE": "IPv4ANY"
		},
		"V4-ACL-TABLE|Rule_11100": {
			"PACKET_ACTION": "FORWARD",
			"DST_IP": "0.0.0.0/0",
			"SRC_IP": "0.0.0.0/0",
			"PRIORITY": "990000",
			"IP_TYPE": "IPv4ANY"
		},
		"V6-ACL-TBLE|DEFAULT_DENY": {
			"PACKET_ACTION": "DROP",
			"IP_TYPE": "IPv6ANY",
			"PRIORITY": "0"
		},
		"V6-ACL-TBLE|Rule_20": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "777780",
			"DST_IPV6": "2a04:5555:43:320::/64"
		},
		"V6-ACL-TBLE|Rule_40": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "777760",
			"DST_IPV6": "2a04:5555:43:321::/64"
		},
		"V6-ACL-TBLE|Rule_60": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "777740",
			"DST_IPV6": "2a04:5555:43:340::/64"
		},
		"V6-ACL-TBLE|Rule_80": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "777720",
			"DST_IPV6": "2a04:5555:43:341::/64"
		},
		"V6-ACL-TBLE|Rule_111": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "777700",
			"DST_IPV6": "2a04:5555:32:12::/64"
		},
		"V6-ACL-TBLE|Rule_9000": {
			"PACKET_ACTION": "DROP",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "2a04:5555:41::/48",
			"PRIORITY": "991110",
			"DST_IPV6": "::/0"
		},
		"V6-ACL-TBLE|Rule_11100": {
			"PACKET_ACTION": "FORWARD",
			"IP_TYPE": "IPv6ANY",
			"SRC_IPV6": "::/0",
			"PRIORITY": "990000",
			"DST_IPV6": "::/0"
		}
	},
	"DEVICE_METADATA": {
		"localhost": {
			"mg_type": "ToR",
			"mac": "00:11:22:33:dd:5a",
			"hostname": "asw.dc",
			"bgp_asn": "64850",
			"hwsku": "Stone"
		}
	},
	"VLAN": {
		"Vlan111": {
			"description": "svlan",
			"dhcp_servers": [
				"10.222.72.116"
			],
			"vlanid": "111",
			"mtu": "9216",
			"admin_status": "up",
			"members": [
				"Ethernet8",
				"Ethernet3",
				"Ethernet0",
				"Ethernet1",
				"Ethernet6",
				"Ethernet4",
				"Ethernet5",
				"Ethernet9",
				"Ethernet2",
				"Ethernet7",
				"Ethernet32",
				"Ethernet30",
				"Ethernet31",
				"Ethernet36",
				"Ethernet34",
				"Ethernet33",
				"Ethernet35",
				"Ethernet29",
				"Ethernet21",
				"Ethernet20",
				"Ethernet23",
				"Ethernet22",
				"Ethernet27",
				"Ethernet26",
				"Ethernet18",
				"Ethernet19",
				"Ethernet14",
				"Ethernet15",
				"Ethernet16",
				"Ethernet17",
				"Ethernet10",
				"Ethernet11",
				"Ethernet12",
				"Ethernet13",
				"Ethernet28"
			]
		},
		"Vlan777": {
			"description": "pvlan",
			"dhcp_servers": [
				"10.222.72.116"
			],
			"vlanid": "777",
			"mtu": "9216",
			"admin_status": "up",
			"members": [
				"Ethernet9",
				"Ethernet2",
				"Ethernet8",
				"Ethernet27",
				"Ethernet14",
				"Ethernet35"
			]
		}
	},
	"DEVICE_NEIGHBOR": {
		"Ethernet112": {
			"name": "dccsw01.nw",
			"port": "Eth18"
		},
		"Ethernet114": {
			"name": "dccsw02.nw",
			"port": "Eth18"
		},
		"Ethernet116": {
			"name": "dccsw03.nw",
			"port": "Eth18"
		},
		"Ethernet118": {
			"name": "dccsw04.nw",
			"port": "Eth18"
		}
	},
	"PORT": {
		"Ethernet0": {
			"alias": "Eth1/1",
			"lanes": "65",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet1": {
			"alias": "Eth1/2",
			"lanes": "66",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet2": {
			"alias": "Eth1/3",
			"lanes": "67",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet3": {
			"alias": "Eth1/4",
			"lanes": "68",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet4": {
			"alias": "Eth2/1",
			"lanes": "69",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet5": {
			"alias": "Eth2/2",
			"lanes": "70",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet6": {
			"alias": "Eth2/3",
			"lanes": "71",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet7": {
			"alias": "Eth2/4",
			"lanes": "72",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet8": {
			"alias": "Eth3/1",
			"lanes": "73",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet9": {
			"alias": "Eth3/2",
			"lanes": "74",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet10": {
			"alias": "Eth3/3",
			"lanes": "75",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet11": {
			"alias": "Eth3/4",
			"lanes": "76",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet12": {
			"alias": "Eth4/1",
			"lanes": "77",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet13": {
			"alias": "Eth4/2",
			"lanes": "78",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet14": {
			"alias": "Eth4/3",
			"lanes": "79",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet15": {
			"alias": "Eth4/4",
			"lanes": "80",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet16": {
			"alias": "Eth5/1",
			"lanes": "33",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet17": {
			"alias": "Eth5/2",
			"lanes": "34",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet18": {
			"alias": "Eth5/3",
			"lanes": "35",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet19": {
			"alias": "Eth5/4",
			"lanes": "36",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet20": {
			"alias": "Eth6/1",
			"lanes": "37",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet21": {
			"alias": "Eth6/2",
			"lanes": "38",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet22": {
			"alias": "Eth6/3",
			"lanes": "39",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet23": {
			"alias": "Eth6/4",
			"lanes": "40",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet24": {
			"alias": "Eth7/1",
			"lanes": "41",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet25": {
			"alias": "Eth7/2",
			"lanes": "42",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet26": {
			"alias": "Eth7/3",
			"lanes": "43",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet27": {
			"alias": "Eth7/4",
			"lanes": "44",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet28": {
			"alias": "Eth8/1",
			"lanes": "45",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet29": {
			"alias": "Eth8/2",
			"lanes": "46",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet30": {
			"alias": "Eth8/3",
			"lanes": "47",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet31": {
			"alias": "Eth8/4",
			"lanes": "48",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet32": {
			"alias": "Eth9/1",
			"lanes": "49",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet33": {
			"alias": "Eth9/2",
			"lanes": "50",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet34": {
			"alias": "Eth9/3",
			"lanes": "51",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet35": {
			"alias": "Eth9/4",
			"lanes": "52",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet36": {
			"alias": "Eth10/1",
			"lanes": "53",
			"description": "",
			"speed": "11100",
			"admin_status": "up"
		},
		"Ethernet112": {
			"alias": "Eth29/1",
			"lanes": "113,114",
			"description": "50G|dccsw01.nw|Eth18",
			"fec": "fc",
			"admin_status": "up"
		}
	},
	"ACL_TABLE": {
		"V4-ACL-TABLE": {
			"type": "L3",
			"policy_desc": "V4-ACL-TABLE",
			"ports": [
				"Ethernet26",
				"Ethernet27",
				"Ethernet24"
			]
		},
		"V6-ACL-TBLE": {
			"type": "L3V6",
			"policy_desc": "V6-ACL-TBLE",
			"ports": [
				"Ethernet14",
				"Ethernet15",
				"Ethernet23",
				"Ethernet30",
				"Ethernet31",
				"Ethernet18",
				"Ethernet19",
				"Ethernet25",
				"Ethernet24"
			]
		}
	},
	"INTERFACE": {
		"Ethernet112|2a04:5555:40:a709::2/126": {
			"scope": "global",
			"family": "IPv6"
		},
		"Ethernet112|10.184.228.211/31": {
			"scope": "global",
			"family": "IPv4"
		},
		"Ethernet14|2a04:5555:40:a749::2/126": {
			"scope": "global",
			"family": "IPv6"
		},
		"Ethernet14|10.184.229.211/31": {
			"scope": "global",
			"family": "IPv4"
		},
		"Ethernet16|2a04:5555:40:a789::2/126": {
			"scope": "global",
			"family": "IPv6"
		},
		"Ethernet16|10.184.230.211/31": {
			"scope": "global",
			"family": "IPv4"
		},
		"Ethernet18|2a04:5555:40:a7c9::2/126": {
			"scope": "global",
			"family": "IPv6"
		},
		"Ethernet18|10.184.231.211/31": {
			"scope": "global",
			"family": "IPv4"
		}
	},
	"VLAN_MEMBER": {
		"Vlan111|Ethernet0": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet1": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet2": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet3": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet4": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet5": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet6": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet29": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet30": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet31": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet32": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet33": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet34": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet35": {
			"tagging_mode": "untagged"
		},
		"Vlan111|Ethernet36": {
			"tagging_mode": "untagged"
		}
	},
	"LOOPBACK_INTERFACE": {
		"Loopback0|2a04:5555:40:4::4e9/128": {
			"scope": "global",
			"family": "IPv6"
		},
		"Loopback0|10.184.8.233/32": {
			"scope": "global",
			"family": "IPv4"
		}
	},
	"CRM": {
		"Config": {
			"polling_interval": "0"
		}
	}
}

Cropped Config

{
    "VLAN_INTERFACE": {
        "Vlan777|fe80::1/10": {
            "scope": "local", 
            "family": "IPv6"
        }, 
        "Vlan777|10.111.58.65/26": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Vlan111|10.222.10.65/26": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Vlan777|2a04:5555:41:4e9::1/64": {
            "scope": "global", 
            "family": "IPv6"
        }, 
        "Vlan111|2a04:5555:45:6709::1/64": {
            "scope": "global", 
            "family": "IPv6"
        }, 
        "Vlan111|fe80::1/10": {
            "scope": "local", 
            "family": "IPv6"
        }
    }, 
    "ACL_RULE": {
        "V4-ACL-TABLE|Rule_20": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.222.72.0/26", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777780"
        }, 
        "V4-ACL-TABLE|Rule_111": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.152.17.52/32", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777700"
        }, 
        "V6-ACL-TBLE|Rule_80": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "2a04:5555:43:341::/64", 
            "PRIORITY": "777720"
        }, 
        "V6-ACL-TBLE|Rule_40": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "2a04:5555:43:321::/64", 
            "PRIORITY": "777760"
        }, 
        "V4-ACL-TABLE|Rule_180": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.252.222.21/32", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777820"
        }, 
        "V4-ACL-TABLE|Rule_140": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.148.128.245/32", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777860"
        }, 
        "V6-ACL-TBLE|Rule_60": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "2a04:5555:43:340::/64", 
            "PRIORITY": "777740"
        }, 
        "V4-ACL-TABLE|Rule_80": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.222.80.64/26", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777720"
        }, 
        "V6-ACL-TBLE|Rule_11100": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "::/0", 
            "DST_IPV6": "::/0", 
            "PRIORITY": "990000"
        }, 
        "V4-ACL-TABLE|Rule_120": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.252.208.41/32", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777880"
        }, 
        "V4-ACL-TABLE|Rule_11100": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "0.0.0.0/0", 
            "SRC_IP": "0.0.0.0/0", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "990000"
        }, 
        "V4-ACL-TABLE|Rule_9000": {
            "PACKET_ACTION": "DROP", 
            "DST_IP": "0.0.0.0/0", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "991110"
        }, 
        "V4-ACL-TABLE|DEFAULT_DENY": {
            "PACKET_ACTION": "DROP", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "0"
        }, 
        "V6-ACL-TBLE|Rule_9000": {
            "PACKET_ACTION": "DROP", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "::/0", 
            "PRIORITY": "991110"
        }, 
        "V6-ACL-TBLE|DEFAULT_DENY": {
            "PACKET_ACTION": "DROP", 
            "IP_TYPE": "IPv6ANY", 
            "PRIORITY": "0"
        }, 
        "V4-ACL-TABLE|Rule_40": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.222.72.64/26", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777760"
        }, 
        "V4-ACL-TABLE|Rule_160": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.222.1.245/32", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777840"
        }, 
        "V6-ACL-TBLE|Rule_20": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "2a04:5555:43:320::/64", 
            "PRIORITY": "777780"
        }, 
        "V4-ACL-TABLE|Rule_60": {
            "PACKET_ACTION": "FORWARD", 
            "DST_IP": "10.222.80.0/26", 
            "SRC_IP": "10.222.0.0/15", 
            "IP_TYPE": "IPv4ANY", 
            "PRIORITY": "777740"
        }, 
        "V6-ACL-TBLE|Rule_111": {
            "PACKET_ACTION": "FORWARD", 
            "IP_TYPE": "IPv6ANY", 
            "SRC_IPV6": "2a04:5555:41::/48", 
            "DST_IPV6": "2a04:5555:32:12::/64", 
            "PRIORITY": "777700"
        }
    }, 
    "VLAN": {
        "Vlan111": {
            "description": "svlan", 
            "dhcp_servers": [
                "10.222.72.116"
            ], 
            "vlanid": "111", 
            "mtu": "9216", 
            "admin_status": "up", 
            "members": [
                "Ethernet8", 
                "Ethernet3", 
                "Ethernet0", 
                "Ethernet1", 
                "Ethernet6", 
                "Ethernet4", 
                "Ethernet5", 
                "Ethernet9", 
                "Ethernet2", 
                "Ethernet7", 
                "Ethernet32", 
                "Ethernet30", 
                "Ethernet31", 
                "Ethernet36", 
                "Ethernet34", 
                "Ethernet33", 
                "Ethernet35", 
                "Ethernet29", 
                "Ethernet21", 
                "Ethernet20", 
                "Ethernet23", 
                "Ethernet22", 
                "Ethernet27", 
                "Ethernet26", 
                "Ethernet18", 
                "Ethernet19", 
                "Ethernet14", 
                "Ethernet15", 
                "Ethernet16", 
                "Ethernet17", 
                "Ethernet10", 
                "Ethernet11", 
                "Ethernet12", 
                "Ethernet13", 
                "Ethernet28"
            ]
        }, 
        "Vlan777": {
            "description": "pvlan", 
            "dhcp_servers": [
                "10.222.72.116"
            ], 
            "vlanid": "777", 
            "mtu": "9216", 
            "admin_status": "up", 
            "members": [
                "Ethernet9", 
                "Ethernet2", 
                "Ethernet8", 
                "Ethernet27", 
                "Ethernet14", 
                "Ethernet35"
            ]
        }
    }, 
    "ACL_TABLE": {
        "V6-ACL-TBLE": {
            "type": "L3V6", 
            "policy_desc": "V6-ACL-TBLE", 
            "ports": [
                "Ethernet14", 
                "Ethernet15", 
                "Ethernet23", 
                "Ethernet30", 
                "Ethernet31", 
                "Ethernet18", 
                "Ethernet19", 
                "Ethernet25", 
                "Ethernet24"
            ]
        }, 
        "V4-ACL-TABLE": {
            "type": "L3", 
            "policy_desc": "V4-ACL-TABLE", 
            "ports": [
                "Ethernet26", 
                "Ethernet27", 
                "Ethernet24"
            ]
        }
    }, 
    "INTERFACE": {
        "Ethernet16|10.184.230.211/31": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Ethernet112|10.184.228.211/31": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Ethernet112|2a04:5555:40:a709::2/126": {
            "scope": "global", 
            "family": "IPv6"
        }, 
        "Ethernet18|2a04:5555:40:a7c9::2/126": {
            "scope": "global", 
            "family": "IPv6"
        }, 
        "Ethernet14|2a04:5555:40:a749::2/126": {
            "scope": "global", 
            "family": "IPv6"
        }, 
        "Ethernet18|10.184.231.211/31": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Ethernet14|10.184.229.211/31": {
            "scope": "global", 
            "family": "IPv4"
        }, 
        "Ethernet16|2a04:5555:40:a789::2/126": {
            "scope": "global", 
            "family": "IPv6"
        }
    }, 
    "VLAN_MEMBER": {
        "Vlan111|Ethernet4": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet5": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet6": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet0": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet1": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet2": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet3": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet29": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet30": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet31": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet32": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet33": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet34": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet35": {
            "tagging_mode": "untagged"
        }, 
        "Vlan111|Ethernet36": {
            "tagging_mode": "untagged"
        }
    }, 
    "PORT": {
        "Ethernet35": {
            "alias": "Eth9/4", 
            "admin_status": "up", 
            "lanes": "52", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet8": {
            "alias": "Eth3/1", 
            "admin_status": "up", 
            "lanes": "73", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet9": {
            "alias": "Eth3/2", 
            "admin_status": "up", 
            "lanes": "74", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet2": {
            "alias": "Eth1/3", 
            "admin_status": "up", 
            "lanes": "67", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet3": {
            "alias": "Eth1/4", 
            "admin_status": "up", 
            "lanes": "68", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet0": {
            "alias": "Eth1/1", 
            "admin_status": "up", 
            "lanes": "65", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet1": {
            "alias": "Eth1/2", 
            "admin_status": "up", 
            "lanes": "66", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet6": {
            "alias": "Eth2/3", 
            "admin_status": "up", 
            "lanes": "71", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet7": {
            "alias": "Eth2/4", 
            "admin_status": "up", 
            "lanes": "72", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet4": {
            "alias": "Eth2/1", 
            "admin_status": "up", 
            "lanes": "69", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet5": {
            "alias": "Eth2/2", 
            "admin_status": "up", 
            "lanes": "70", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet18": {
            "alias": "Eth5/3", 
            "admin_status": "up", 
            "lanes": "35", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet19": {
            "alias": "Eth5/4", 
            "admin_status": "up", 
            "lanes": "36", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet14": {
            "alias": "Eth4/3", 
            "admin_status": "up", 
            "lanes": "79", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet15": {
            "alias": "Eth4/4", 
            "admin_status": "up", 
            "lanes": "80", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet16": {
            "alias": "Eth5/1", 
            "admin_status": "up", 
            "lanes": "33", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet17": {
            "alias": "Eth5/2", 
            "admin_status": "up", 
            "lanes": "34", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet10": {
            "alias": "Eth3/3", 
            "admin_status": "up", 
            "lanes": "75", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet11": {
            "alias": "Eth3/4", 
            "admin_status": "up", 
            "lanes": "76", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet12": {
            "alias": "Eth4/1", 
            "admin_status": "up", 
            "lanes": "77", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet13": {
            "alias": "Eth4/2", 
            "admin_status": "up", 
            "lanes": "78", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet32": {
            "alias": "Eth9/1", 
            "admin_status": "up", 
            "lanes": "49", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet33": {
            "alias": "Eth9/2", 
            "admin_status": "up", 
            "lanes": "50", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet112": {
            "alias": "Eth29/1", 
            "admin_status": "up", 
            "lanes": "113,114", 
            "description": "50G|dccsw01.nw|Eth18", 
            "fec": "fc"
        }, 
        "Ethernet30": {
            "alias": "Eth8/3", 
            "admin_status": "up", 
            "lanes": "47", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet31": {
            "alias": "Eth8/4", 
            "admin_status": "up", 
            "lanes": "48", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet36": {
            "alias": "Eth10/1", 
            "admin_status": "up", 
            "lanes": "53", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet29": {
            "alias": "Eth8/2", 
            "admin_status": "up", 
            "lanes": "46", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet28": {
            "alias": "Eth8/1", 
            "admin_status": "up", 
            "lanes": "45", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet34": {
            "alias": "Eth9/3", 
            "admin_status": "up", 
            "lanes": "51", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet21": {
            "alias": "Eth6/2", 
            "admin_status": "up", 
            "lanes": "38", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet20": {
            "alias": "Eth6/1", 
            "admin_status": "up", 
            "lanes": "37", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet23": {
            "alias": "Eth6/4", 
            "admin_status": "up", 
            "lanes": "40", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet22": {
            "alias": "Eth6/3", 
            "admin_status": "up", 
            "lanes": "39", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet25": {
            "alias": "Eth7/2", 
            "admin_status": "up", 
            "lanes": "42", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet24": {
            "alias": "Eth7/1", 
            "admin_status": "up", 
            "lanes": "41", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet27": {
            "alias": "Eth7/4", 
            "admin_status": "up", 
            "lanes": "44", 
            "description": "", 
            "speed": "11100"
        }, 
        "Ethernet26": {
            "alias": "Eth7/3", 
            "admin_status": "up", 
            "lanes": "43", 
            "description": "", 
            "speed": "11100"
        }
    }
}

Praveen Chaudhary and others added 4 commits December 11, 2019 10:33
This Package will contain YANG models for sonic which are written with guidelines mentioned in
https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md.

This package will include python yang libraries which will be used with sonic utilities
pacakge to validate the config.
      - python APIs based on libyang
      - functions to load/merge yang models and data files
      - add/set/delete node in schema and data trees
      - find dependencies
…, PortChannel and ACL.

[Sonic Yang Tree]: YANG models as per Guidelines.

Guideline doc: https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md

[yang-model-tests]: YANG model test code and JSON input for testing.

[setup.py]: Add testing for yang models.

[sonic-slave-stretch]: Add a package ijson for sonic_yang_mgmt build.
…ansalation, reverse translation of config DB.

This PR includes:
-- Cropping input config based on Yang Model.
-- Translate input config based on Yang Model.
-- rev Translate input config based on Yang Model.
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.
@renukamanavalan
Copy link
Contributor

Curious!
This is precisely what Broadcom's checkin is expected to do, while validating against SONiC Yang. Are we re-inventing the wheel ?

Having two different modules doing the same would be hard to maintain.

Have you looked in-depth the committed code (from Broadcom) that does this translation ?

@praveen-li
Copy link
Collaborator Author

praveen-li commented Jan 22, 2020

Curious!
This is precisely what Broadcom's checkin is expected to do, while validating against SONiC Yang. Are we re-inventing the wheel ?

Having two different modules doing the same would be hard to maintain.

Have you looked in-depth the committed code (from Broadcom) that does this translation ?

@renukamanavalan
We did analysis before starting this development.
Broadcom was not providing below functionalities:
1.) APIs to find all dependencies for an node in YANG Data Tree say for PORT.
2.) Delete the node in Data Tree, i.e Delete Dependencies and Ports in Data Tree.
3.) Reverse translation from Data Tree to Config DB, this is not done even today as I know. For LKDN this is critical since We change Data Tree with Dynamic Port Breakout. And we push config from Data Tree to Config DB.
4.) BCRM config validation is not plugged with Python Click i.e. Config reload/load. If we are providing config validation then this is the first thing our Network Operation folks will ask.
5.) We chose python, because Python script can be updated on FLY. Which means say we have thousand of switches where this feature is deployed. Later we need to modify YANG models and Python script on those switches. We can do it via our tools, without building any new package just by changing YANG and python files.

Thanks

@praveen-li
Copy link
Collaborator Author

@renukamanavalan
Gentle Reminder, Kindly Review. This also can be review irrespective of YANG changes.

@praveen-li
Copy link
Collaborator Author

This PR is merged in PR 3861.

@praveen-li praveen-li closed this May 1, 2020
@praveen-li praveen-li deleted the sonic_yang_extension_msft branch May 1, 2020 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants