From 48b0beb7ff786c45597ea2ce8790400775bf6d2a Mon Sep 17 00:00:00 2001 From: Andriy Moroz Date: Thu, 24 Aug 2017 05:41:14 +0300 Subject: [PATCH] Port speed (#879) * Add port speed configuration * Add DeviceInfos support in minigraph parser * Add cfggen test 'test_minigraph_ethernet_interfaces' * Fixed PR comments * Update sonic-swss submodule reference --- dockers/docker-orchagent/Dockerfile.j2 | 1 + dockers/docker-orchagent/ports.json.j2 | 11 ++++ dockers/docker-orchagent/start.sh | 1 + dockers/docker-orchagent/swssconfig.sh | 2 +- src/sonic-config-engine/minigraph.py | 17 +++++ .../tests/simple-sample-graph.xml | 62 +++++++++++++++++++ src/sonic-config-engine/tests/test_cfggen.py | 5 ++ src/sonic-swss | 2 +- 8 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 dockers/docker-orchagent/ports.json.j2 diff --git a/dockers/docker-orchagent/Dockerfile.j2 b/dockers/docker-orchagent/Dockerfile.j2 index 73fb087401..587d8f4db2 100755 --- a/dockers/docker-orchagent/Dockerfile.j2 +++ b/dockers/docker-orchagent/Dockerfile.j2 @@ -30,5 +30,6 @@ COPY ["arp_update", "start.sh", "orchagent.sh", "swssconfig.sh", "/usr/bin/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["ipinip.json.j2", "/usr/share/sonic/templates/"] COPY ["mirror.json.j2", "/usr/share/sonic/templates/"] +COPY ["ports.json.j2", "/usr/share/sonic/templates/"] ENTRYPOINT ["/usr/bin/supervisord"] diff --git a/dockers/docker-orchagent/ports.json.j2 b/dockers/docker-orchagent/ports.json.j2 new file mode 100644 index 0000000000..f59ee993ee --- /dev/null +++ b/dockers/docker-orchagent/ports.json.j2 @@ -0,0 +1,11 @@ +[ +{% for interface in ethernet_interfaces %} + { + "PORT_TABLE:{{ interface['name'] }}": { + "speed": "{{ interface['speed'] }}" + }, + "OP": "SET" + }{% if not loop.last %},{% endif %} + +{% endfor %} +] diff --git a/dockers/docker-orchagent/start.sh b/dockers/docker-orchagent/start.sh index 40ef66441c..5f961a8bd2 100755 --- a/dockers/docker-orchagent/start.sh +++ b/dockers/docker-orchagent/start.sh @@ -4,6 +4,7 @@ mkdir -p /etc/swss/config.d/ sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json +sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json export platform=`sonic-cfggen -m /etc/sonic/minigraph.xml -v platform` diff --git a/dockers/docker-orchagent/swssconfig.sh b/dockers/docker-orchagent/swssconfig.sh index 768417779e..2530aca06b 100755 --- a/dockers/docker-orchagent/swssconfig.sh +++ b/dockers/docker-orchagent/swssconfig.sh @@ -38,7 +38,7 @@ fast_reboot HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v minigraph_hwsku` -SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json " +SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json " if [ "$HWSKU" == "Force10-S6000" ]; then SWSSCONFIG_ARGS+="td2.32ports.buffers.json td2.32ports.qos.json " diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 6dbf0d570d..1877e55285 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -325,6 +325,19 @@ def parse_meta(meta, hname): deployment_id = value return syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id +def parse_deviceinfo(meta, hwsku): + ethernet_interfaces = [] + + for device_info in meta.findall(str(QName(ns, "DeviceInfo"))): + dev_sku = device_info.find(str(QName(ns, "HwSku"))).text + if dev_sku == hwsku: + interfaces = device_info.find(str(QName(ns, "EthernetInterfaces"))) + for interface in interfaces.findall(str(QName(ns1, "EthernetInterface"))): + name = interface.find(str(QName(ns, "InterfaceName"))).text + speed = interface.find(str(QName(ns, "Speed"))).text + ethernet_interfaces.append({ 'name':name, 'speed':speed }) + + return ethernet_interfaces def get_console_info(devices, dev, port): for k, v in devices.items(): @@ -411,6 +424,7 @@ def parse_xml(filename, platform=None, port_config_file=None): neighbors = None devices = None hostname = None + ethernet_interfaces = [] syslog_servers = [] dhcp_servers = [] ntp_servers = [] @@ -440,6 +454,8 @@ def parse_xml(filename, platform=None, port_config_file=None): (u_neighbors, u_devices, _, _, _, _) = parse_png(child, hostname) elif child.tag == str(QName(ns, "MetadataDeclaration")): (syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname) + elif child.tag == str(QName(ns, "DeviceInfos")): + ethernet_interfaces = parse_deviceinfo(child, hwsku) results = {} results['minigraph_hwsku'] = hwsku @@ -488,6 +504,7 @@ def parse_xml(filename, platform=None, port_config_file=None): results['forced_mgmt_routes'] = mgmt_routes results['erspan_dst'] = erspan_dst results['deployment_id'] = deployment_id + results['ethernet_interfaces'] = ethernet_interfaces return results diff --git a/src/sonic-config-engine/tests/simple-sample-graph.xml b/src/sonic-config-engine/tests/simple-sample-graph.xml index 20bfb07f00..7daae24f49 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph.xml @@ -200,6 +200,68 @@ + + + true + + + DeviceInterface + + true + true + 1 + fortyGigE0/0 + + false + 0 + 0 + 10000 + + + DeviceInterface + + true + true + 1 + fortyGigE0/4 + + false + 0 + 0 + 25000 + + + DeviceInterface + + true + true + 1 + fortyGigE0/8 + + false + 0 + 0 + 40000 + + + DeviceInterface + + true + true + 1 + fortyGigE0/12 + + false + 0 + 0 + 1000000 + + + true + 0 + Force10-S6000 + + switch-t0 Force10-S6000 diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index d3ff3e8b9f..153b0bb14f 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -119,3 +119,8 @@ class TestCfgGen(TestCase): argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v deployment_id' output = self.run_script(argument) self.assertEqual(output.strip(), "1") + + def test_minigraph_ethernet_interfaces(self): + argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v ethernet_interfaces' + output = self.run_script(argument) + self.assertEqual(output.strip(), "[{'speed': '10000', 'name': 'fortyGigE0/0'}, {'speed': '25000', 'name': 'fortyGigE0/4'}, {'speed': '40000', 'name': 'fortyGigE0/8'}, {'speed': '1000000', 'name': 'fortyGigE0/12'}]") diff --git a/src/sonic-swss b/src/sonic-swss index f9b55d3027..eaccf67cab 160000 --- a/src/sonic-swss +++ b/src/sonic-swss @@ -1 +1 @@ -Subproject commit f9b55d30276d1a6ab94e7321d9b2a3bf076fd683 +Subproject commit eaccf67cabd22df0ff7d0117fe55f4261bc961d9