Skip to content

Commit d6819c4

Browse files
committed
OPER DATA
1 parent c91d22f commit d6819c4

File tree

3 files changed

+51
-54
lines changed

3 files changed

+51
-54
lines changed

src/statd/python/cli_pretty/cli_pretty.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class PadWifiScan:
204204
class PadWifiStations:
205205
mac = 20
206206
signal = 9
207+
tx_speed = 11
208+
rx_speed = 11
209+
connected_time = 16
207210

208211

209212
class PadLldp:
@@ -338,15 +341,15 @@ def title(txt, len=None, bold=True):
338341
print(txt)
339342

340343

341-
def rssi_to_status(rssi):
344+
def rssi_to_status(rssi, width=0):
342345
if rssi <= -75:
343-
status = Decore.bright_green("excellent")
346+
status = Decore.bright_green(f"{'excellent':<{width}}" if width else "excellent")
344347
elif rssi <= -65:
345-
status = Decore.green("good")
348+
status = Decore.green(f"{'good':<{width}}" if width else "good")
346349
elif rssi <= -50:
347-
status = Decore.yellow("poor")
350+
status = Decore.yellow(f"{'poor':<{width}}" if width else "poor")
348351
else:
349-
status = Decore.red("bad")
352+
status = Decore.red(f"{'bad':<{width}}" if width else "bad")
350353

351354
return status
352355

@@ -872,7 +875,7 @@ def __init__(self, data):
872875
self.lower_if = ''
873876

874877
def is_wifi(self):
875-
return self.type == "infix-if-type:wifi"
878+
return self.type == "infix-if-type:wifi" or self.type == "infix-if-type:wifi-ap"
876879

877880
def is_vlan(self):
878881
return self.type == "infix-if-type:vlan"
@@ -974,14 +977,20 @@ def pr_wifi_stations(self):
974977
print(Decore.invert(hdr))
975978
hdr = (f"{'MAC':<{PadWifiStations.mac}}"
976979
f"{'SIGNAL':<{PadWifiStations.signal}}"
980+
f"{'TX speed':<{PadWifiStations.tx_speed}}"
981+
f"{'RX speed':<{PadWifiStations.rx_speed}}"
982+
f"{'Connected':<{PadWifiStations.connected_time}}"
977983
)
978984
print(Decore.invert(hdr))
979985

980986
stations=self.wifi.get("connected-stations", {})
981987
for station in stations:
982-
status=rssi_to_status(station["rssi"])
988+
status=rssi_to_status(station["rssi"], PadWifiStations.signal)
983989
row = f"{station['mac-address']:<{PadWifiStations.mac}}"
984-
row += f"{status:<{PadWifiStations.signal}}"
990+
row += status
991+
row += f"{station['tx-speed']:<{PadWifiStations.tx_speed}}"
992+
row += f"{station['rx-speed']:<{PadWifiStations.rx_speed}}"
993+
row += f"{station['connected-time']:<{PadWifiStations.connected_time}}"
985994
print(row)
986995

987996
def pr_wifi_ssids(self):
@@ -1301,10 +1310,10 @@ def pr_iface(self):
13011310
key = remove_yang_prefix(key)
13021311
print(f"eth-{key:<{25}}: {val}")
13031312
if self.wifi:
1304-
ssid=self.wifi.get('active-ssid', "")
1305-
rssi=self.wifi.get('active-rssi', "")
13061313
mode=self.wifi.get('mode')
13071314
if mode == "client":
1315+
ssid=self.wifi.get('active-ssid', "")
1316+
rssi=self.wifi.get('active-rssi', "")
13081317
print(f"{'SSID':<{20}}: {ssid}")
13091318
print(f"{'Signal':<{20}}: {rssi}")
13101319
print("")

src/statd/python/yanger/ietf_interfaces/link.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def iplink2yang_type(iplink):
3535
case "ether":
3636
data = HOST.run(tuple(f"ls /sys/class/net/{ifname}/wireless/".split()), default="no")
3737
if data != "no":
38+
iw_data=HOST.run(tuple(f"iw dev {ifname} info".split()), default="")
39+
for line in iw_data.splitlines():
40+
if line.strip() == "type AP":
41+
return "infix-if-type:wifi-ap"
3842
return "infix-if-type:wifi"
3943
case _:
4044
return "infix-if-type:other"
@@ -138,7 +142,7 @@ def interface(iplink, ipaddr):
138142
case "infix-if-type:vlan":
139143
if v := vlan.vlan(iplink):
140144
interface["infix-interfaces:vlan"] = v
141-
case "infix-if-type:wifi":
145+
case "infix-if-type:wifi-ap" | "infix-if-type:wifi":
142146
if w := wifi.wifi(iplink["ifname"]):
143147
interface["infix-interfaces:wifi"] = w
144148

src/statd/python/yanger/ietf_interfaces/wifi.py

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,38 @@ def wifi(ifname):
66
wifi_data={}
77

88
try:
9-
10-
data=HOST.run(tuple(f"wpa_cli -i {ifname} status".split()), default="")
119
iw_data=HOST.run(tuple(f"iw dev {ifname} info".split()), default="")
12-
13-
if iw_data != "":
14-
for line in iw_data.splitlines():
15-
line=line.strip() # Fix crazy output from iw.
16-
l=line.split(" ")
17-
if l[0] == "type":
18-
if l[1] == "AP":
10+
if iw_data != "":
11+
for line in iw_data.splitlines():
12+
line=line.strip() # Fix crazy output from iw.
13+
if line == "type AP":
1914
wifi_data["mode"] = "accesspoint"
15+
break
2016
else:
2117
wifi_data["mode"] = "station"
2218

23-
if wifi_data["mode"] == "station":
24-
station_data=HOST.run(tuple(f"wpa_cli -i {ifname} status".split()), default="")
25-
if station_data != "":
26-
for line in station_data.splitlines():
27-
k,v = line.split("=")
28-
if k == "ssid":
29-
wifi_data["active-ssid"] = v
30-
except ValueError:
31-
# Skip malformed lines
32-
continue
33-
34-
try:
35-
if wifi_data["mode"] == "client":
36-
client_data=HOST.run(tuple(f"wpa_cli -i {ifname} status".split()), default="")
37-
if client_data != "":
38-
for line in client_data.splitlines():
39-
k,v = line.split("=")
40-
if k == "ssid":
41-
wifi_data["active-ssid"] = v
42-
43-
data=HOST.run(tuple(f"wpa_cli -i {ifname} signal_poll".split()), default="FAIL")
44-
45-
# signal_poll return FAIL not connected
46-
if data.strip() != "FAIL":
47-
for line in data.splitlines():
48-
k,v = line.strip().split("=")
49-
if k == "RSSI":
50-
wifi_data["active-rssi"]=int(v)
51-
data=HOST.run(tuple(f"wpa_cli -i {ifname} scan_result".split()), default="FAIL")
52-
if data != "FAIL":
53-
wifi_data["scan-results"] = parse_wpa_scan_result(data)
54-
elif wifi_data["mode"] == "accesspoint":
55-
stations=HOST.run_json(tuple(f"/usr/libexec/infix/wifi-ap-stations {ifname}".split()), default=[])
56-
wifi_data["connected-stations"] = stations
19+
if wifi_data["mode"] == "station":
20+
client_data=HOST.run(tuple(f"wpa_cli -i {ifname} status".split()), default="")
21+
if client_data != "":
22+
for line in client_data.splitlines():
23+
k,v = line.split("=")
24+
if k == "ssid":
25+
wifi_data["active-ssid"] = v
26+
27+
data=HOST.run(tuple(f"wpa_cli -i {ifname} signal_poll".split()), default="FAIL")
28+
29+
# signal_poll return FAIL not connected
30+
if data.strip() != "FAIL":
31+
for line in data.splitlines():
32+
k,v = line.strip().split("=")
33+
if k == "RSSI":
34+
wifi_data["active-rssi"]=int(v)
35+
data=HOST.run(tuple(f"wpa_cli -i {ifname} scan_result".split()), default="FAIL")
36+
if data != "FAIL":
37+
wifi_data["scan-results"] = parse_wpa_scan_result(data)
38+
elif wifi_data["mode"] == "accesspoint":
39+
stations=HOST.run_json(tuple(f"/usr/libexec/infix/wifi-ap-stations {ifname}".split()), default=[])
40+
wifi_data["connected-stations"] = stations
5741
except Exception:
5842
# If status query fails entirely, continue with scan results
5943
pass

0 commit comments

Comments
 (0)