Skip to content

Commit

Permalink
Merge pull request #487 from tiiuae/MS2.4.0_to_main
Browse files Browse the repository at this point in the history
MeshShield 2.4.0 to main
  • Loading branch information
joenpera authored Nov 5, 2024
2 parents 6f876b2 + 729ab68 commit d3424cf
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 38 deletions.
2 changes: 1 addition & 1 deletion common/scripts/mesh-11s_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ EOF
# Radio parameters
echo "set radio parameters"
# /usr/local/bin/cli_app set txpwr fixed 23
/usr/local/bin/cli_app set gi long
/usr/local/bin/cli_app set gi short
/usr/local/bin/cli_app set support_ch_width 1
/usr/local/bin/cli_app set mesh_rssi_threshold -105

Expand Down
2 changes: 2 additions & 0 deletions common/tools/field_test_logger/field_test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def timestamp() -> str:
ftl.register_logger_function("Halow SNR", wifi_stats.get_snr)
ftl.register_logger_function("RX MCS [MAC,MCS;MAC,MCS ...]", wifi_stats.get_rx_mcs)
ftl.register_logger_function("TX MCS [MAC,MCS;MAC,MCS ...]", wifi_stats.get_tx_mcs)
ftl.register_logger_function("Exp. throughput(Mbps) [MAC,Exp.Tput ...]", wifi_stats.get_expected_throughput)
ftl.register_logger_function("inactive time (ms) [MAC,inactive time ...]", wifi_stats.get_inactive_time)
ftl.register_logger_function("RX throughput [Bits/s]", wifi_stats.get_rx_throughput)
ftl.register_logger_function("TX throughput [Bits/s]", wifi_stats.get_tx_throughput)
ftl.register_logger_function("Neighbors", wifi_stats.get_neighbors)
Expand Down
39 changes: 38 additions & 1 deletion common/tools/field_test_logger/wifi_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ def get_tx_mcs(self):

return out

def get_expected_throughput(self):
out = ""
for i in self.__stations.keys():
# Expected throughput is at index 3
out = f"{out}{i},{self.__stations[i][3]};"

# Remove semicolon after the last station
return out[:-1]

def get_inactive_time(self):
out = ""
for i in self.__stations.keys():
# Inactive Time is at index 4
out = f"{out}{i},{self.__stations[i][4]};"

# Remove semicolon after the last station
return out[:-1]

def get_txpower(self):
return self.__txpower

Expand Down Expand Up @@ -150,6 +168,8 @@ def __update_mcs_and_rssi(self):
tx_mcs = "NaN"
rx_mcs = "NaN"
rssi = "NaN"
expected_throughput = "NaN"
inactive_time = "NaN"

# halow station info fetched from cli_app if needed.
halow_stations = None
Expand Down Expand Up @@ -189,7 +209,24 @@ def __update_mcs_and_rssi(self):
rx_mcs = halow_stations.get(station_mac)[1]
except (IndexError, TypeError):
pass
self.__stations[station_mac] = [rssi, tx_mcs, rx_mcs]

if "expected throughput:" in line:
# Extract the value and remove the "Mbps" suffix
throughput_str = line.split("expected throughput:")[1].strip().replace("Mbps", "").strip()
try:
expected_throughput = float(throughput_str)
except ValueError:
pass

if "inactive time:" in line:
# Extract the value and remove the "ms" suffix
inactive_time_str = line.split("inactive time:")[1].strip().replace("ms", "").strip()
try:
inactive_time = int(inactive_time_str)
except ValueError:
pass

self.__stations[station_mac] = [rssi, tx_mcs, rx_mcs, expected_throughput, inactive_time]

def get_halow_stations(self) -> dict:
cli_app_cmd = ['/usr/local/bin/cli_app', 'show', 'sta', '0', 'all']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_openssl_certificate() -> None:
end_data: datetime = certificate.get_end_date()
assert end_data

assert '64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2' == str(skid)
assert '04:14:64:73:81:83:b3:f1:72:ad:28:6d:be:9b:0f:a1:d9:d4:7f:75:72:c2' == skid.hex(':')
assert '2024-05-13 09:16:24' == str(end_data)
assert ('keyid:64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2\n'
'DirName:/CN=Stop-Gap Insecure CA\n'
'serial:13:51:37:43:26:0A:A9:DE:32:FD:1C:EF:18:F2:9B:E7:A6:16:54:EF') == str(akid)
assert '04:14:75:05:b3:00:68:0b:9c:d0:c0:46:e5:b5:aa:58:cb:8b:44:a2:92:d5' == skid.hex(':')
assert '2024-03-17 08:21:07' == str(end_data)
assert '30:16:80:14:14:38:d5:36:b1:5d:ab:f3:30:83:23:f0:6f:5b:c7:bf:2b:51:f5:9c' == akid.hex(':')



Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, cert_paths: CBMACertificates, tls_method: int) -> None:
def verify(self, conn, cert, errnum, depth, ok) -> bool:
return True

secure_socket = TestSecureSocket(cert_paths, SSL.TLS_SERVER_METHOD)
secure_socket = TestSecureSocket(cert_paths, SSL.SSLv23_METHOD)
try:
secure_socket.create_ssl_context()
assert True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-8.0.0, pluggy-1.4.0 -- /home/mika/work/nix/mesh_com/modules/sc-mesh-secure-deployment/src/nats/unittest_cbma/bin/python3
cachedir: .pytest_cache
rootdir: /home/mika/work/nix/mesh_com/modules/sc-mesh-secure-deployment/src/nats
plugins: cov-5.0.0
collecting ... collected 2 items

cbma/unittests/test_certificate_handler.py::test_openssl_certificate PASSED [ 50%]
cbma/unittests/test_secure_socket.py::TestCreateSSLContext::test_certificate_loading PASSED [100%]

---------- coverage: platform linux, python 3.10.12-final-0 ----------
Name Stmts Miss Cover Missing
------------------------------------------------------------------------------
cbma/cbma.py 134 134 0% 1-207
cbma/certificates/certificates.py 29 3 90% 20, 28, 44
cbma/controller.py 122 122 0% 1-169
cbma/models/certificates.py 19 3 84% 17, 21, 25
cbma/models/secure_socket/secure_connection.py 28 8 71% 10, 15, 20, 25, 30, 35, 40, 45
cbma/models/secure_socket/secure_context.py 8 1 88% 13
cbma/models/secure_socket/verification.py 11 1 91% 19
cbma/secure_socket/__init__.py 0 0 100%
cbma/secure_socket/client.py 79 79 0% 1-127
cbma/secure_socket/secure_connection.py 47 28 40% 27-30, 34, 38, 42-46, 50-56, 60-70
cbma/secure_socket/secure_context.py 34 7 79% 58-61, 65-68
cbma/secure_socket/secure_socket.py 11 2 82% 14-16
cbma/secure_socket/server.py 73 73 0% 1-105
cbma/secure_socket/verification.py 78 54 31% 43-54, 58-68, 72-76, 80-103, 107-114, 128-145
cbma/standalone.py 106 106 0% 1-175
cbma/unittests/test_certificate_handler.py 19 0 100%
cbma/unittests/test_secure_socket.py 24 3 88% 27, 33-34
cbma/utils/__init__.py 0 0 100%
cbma/utils/certificates.py 22 14 36% 18-33
cbma/utils/common.py 38 29 24% 12-28, 33-48, 52, 56, 60-61
cbma/utils/logging.py 132 73 45% 29, 49, 58-60, 68-69, 87-123, 127-136, 145, 154-159, 169-199
cbma/utils/macsec.py 81 81 0% 1-125
cbma/utils/multicast.py 2 2 0% 3-8
cbma/utils/networking.py 30 21 30% 13-16, 20-25, 29-40, 44-49
------------------------------------------------------------------------------
TOTAL 1127 844 25%


============================== 2 passed in 0.22s ===============================
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Mesh Shield config file #
###########################

# hostname of the device
hostname: nixos

# All the interfaces are black by default.
# Excluded interfaces or interfaces without macsec certificates are not added to lower CBMA.
# White interfaces are added to upper CBMA and are excluded automatically from lower CBMA.
Expand All @@ -21,10 +24,16 @@ CBMA:
- sap0
- sta0
- wfd0
white_interfaces:
- end0
- end1
white_interfaces:
red_interfaces:
- wlan1
- usb0
- eth0
- end0
- end1
- lan1

BATMAN:
routing_algo: BATMAN_V
Expand All @@ -35,17 +44,17 @@ BATMAN:
hardif:
halow1: 20

VLAN:
#VLAN:
# Remember that IP address definitions for such interface that is added to
# CBMA's red_interfaces list (i.e. br-lan bridge) are not effective.
vlan_black:
parent_interface: eth0
vlan_id: 100
ipv4_address: 192.168.1.1
ipv4_subnet_mask: 255.255.255.0
ipv6_local_address: fe80::192.168.1.1
ipv6_prefix_length: 64
vlan_red:
parent_interface: eth0
vlan_id: 200
# vlan_black:
# parent_interface: eth0
# vlan_id: 100
# ipv4_address: 192.168.1.1
# ipv4_subnet_mask: 255.255.255.0
# ipv6_local_address: fe80::192.168.1.1
# ipv6_prefix_length: 64
# vlan_red:
# parent_interface: eth0
# vlan_id: 200

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# preconditions
if [ ! -f "$(pwd)/$(basename $0)" ]; then
echo "Script is not being executed in the same folder"
exit 1
fi

# python virtualenv
python3 -m venv unittest_cbma
source unittest_cbma/bin/activate

# install dependencies to virtualenv
pip install -r ./cbma/requirements.txt
pip install -r ./requirements.txt
# install testing only related dependencies
pip install pytest pytest-cov

# discover and run unittests
pytest --cov=cbma --cov-report term-missing -v --ignore=lucius/unittests --ignore=debug_tests --ignore=cbma/unittest --ignore=cbma/tests --ignore=tests |& tee ./cbma_coverage_report.txt

## deactivate virtualenv
deactivate

# Clean up __pycache__ directories
find . -type d -name '__pycache__' -exec rm -rf {} +
# Clean up unittest venv
rm -rf unittest_cbma
# Clean up coverage tool's SQL database
rm -f .coverage

Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def configure_batman_interface(self, batman_if: str) -> None:
["batctl", "meshif", batman_if, "fragmentation", "1"], check=True
)

ogm_interval = "5000" if is_upper else "500"
subprocess.run(
["batctl", "meshif", batman_if, "orig_interval", "5000"], check=True
["batctl", "meshif", batman_if, "orig_interval", ogm_interval], check=True
)

except subprocess.CalledProcessError as e:
Expand Down
Loading

0 comments on commit d3424cf

Please sign in to comment.