+ local switch_name = x.name or x['.name']
+ local has_vlan4k = nil
+ local has_ptpvid = nil
+ local max_vid = 16
+ local num_vlans = 16
+ local num_ports = 5
+ local cpu_port = 5
+
+ local swc = io.popen("swconfig dev %q help 2>/dev/null" % switch_name)
+ if swc then
+
+ local is_port_attr = false
+ local is_vlan_attr = false
+
+ while true do
+ local line = swc:read("*l")
+ if not line then break end
+
+ if line:match("^%s+%-%-vlan") then
+ is_vlan_attr = true
+
+ elseif line:match("^%s+%-%-port") then
+ is_vlan_attr = false
+ is_port_attr = true
+
+ elseif line:match("^Switch %d+:") then
+ num_ports, cpu_port, num_vlans =
+ line:match("ports: (%d+) %(cpu @ (%d+)%), vlans: (%d+)")
+
+ num_ports = tonumber(num_ports or 5)
+ num_vlans = tonumber(num_vlans or 16)
+ cpu_port = tonumber(cpu_port or 5)
+
+ elseif line:match("%-%-pvid") or line:match("%-%-tag") or line:match("%-%-vid") then
+ if is_vlan_attr then has_vlan4k = line:match("%-%-(%w+)") end
+ if is_port_attr then has_ptpvid = line:match("%-%-(%w+)") end
+
+ end
+ end
+
+ swc:close()
+ end