Skip to content

Commit

Permalink
minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
noursaidi committed Nov 5, 2024
1 parent 90ab482 commit 978bab0
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 27 deletions.
4 changes: 2 additions & 2 deletions misc/discoverynode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"key_file": "/workspaces/udmi/sites/udmi_site_model/devices/AHU-1/rsa_private.pem",
"algorithm": "RS256",
},
"udmi":{"discovery": {"ipv4":"false", "ethmac": false, "bacnet": false}},
"udmi":{"discovery": {"ipv4":"false", "ether": false, "bacnet": false}},
"bacnet": {"ip": "192.168.11.251"}
}
```
Expand All @@ -54,7 +54,7 @@
"algorithm": "RS256",
"authentication_mechanism": "udmi_local"
},
"udmi":{"discovery": {"ipv4":"false", "ethmac": false, "bacnet":false}},
"udmi":{"discovery": {"ipv4":"false", "ether": false, "bacnet":false}},
"nmap": {
"targets": [
"127.0.0.1"
Expand Down
3 changes: 2 additions & 1 deletion misc/discoverynode/bin/install_daemon
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fi

if [[ -n $install || -n $upgrade ]]; then
cp -r $ROOT_DIR/src $LIB_DIR
git describe | tr -d '\n' > $LIB_DIR/src/installed_version.txt
python3 -m venv $LIB_DIR/venv
VENV_PYTHON=$LIB_DIR/venv/bin/python3
$VENV_PYTHON -m pip install -r $LIB_DIR/src/requirements.txt
Expand All @@ -72,7 +73,7 @@ if [[ -n $install || -n $reconfigure ]]; then
},
"udmi": {
"discovery": {
"ethmac": false,
"ether": false,
"bacnet": false
}
}
Expand Down
2 changes: 1 addition & 1 deletion misc/discoverynode/samples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"algorithm": "RS256",
"authentication_mechanism": "udmi_local"
},
"udmi":{"discovery": {"ipv4":"false", "ethmac": false, "bacnet":false}},
"udmi":{"discovery": {"ipv4":"false", "ether": false, "bacnet":false}},
"nmap": {
"targets": [
"127.0.0.1"
Expand Down
4 changes: 2 additions & 2 deletions misc/discoverynode/samples/config_clearblade.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"mqtt": {
"device_id": "AHU-1",
"host": "localhost",
"host": "mqtt.bos.goog",
"port": 8883,
"registry_id": "ZZ-TRI-FECTA",
"region": "us-central1",
Expand All @@ -11,6 +11,6 @@

"authentication_mechanism": "jwt_gcp"
},
"udmi":{"discovery": {"ipv4":"false", "ethmac": false, "bacnet": false}},
"udmi":{"discovery": {"ipv4":"false", "ether": false, "bacnet": false}},
"bacnet": {"ip": "192.168.11.251"}
}
2 changes: 1 addition & 1 deletion misc/discoverynode/samples/config_localhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"cert_file": "/workspaces/udmi/sites/udmi_site_model/devices/AHU-1/rsa_private.crt",
"authentication_mechanism": "udmi_local"
},
"udmi":{"discovery": {"ipv4":"false", "ethmac": false, "bacnet":false}},
"udmi":{"discovery": {"ipv4":"false", "ether": false, "bacnet":false}},
"bacnet": {"ip": "192.168.11.251"}
}
4 changes: 2 additions & 2 deletions misc/discoverynode/src/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_bacnet_integration():
print(message.to_json())
print("----")

expected_ethmacs = set(d["ethmac"] for d in docker_config.values())
seen_ethmac_toplevel = set(m.families["ethmac"].addr for m in messages if "ethmac" in m.families)
expected_ethmacs = set(d["ether"] for d in docker_config.values())
seen_ethmac_toplevel = set(m.families["ether"].addr for m in messages if "ether" in m.families)

expected_bacnet_ids = set(str(d["bacnet_id"]) for d in docker_config.values())
seen_bacnet_ids_toplevel = set(m.scan_addr for m in messages if m.scan_family == "bacnet")
Expand Down
25 changes: 17 additions & 8 deletions misc/discoverynode/src/udmi/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import contextlib
import json
import logging
import pathlib
import threading
import time
import textwrap
Expand All @@ -25,7 +27,9 @@ class UDMICore:
EVENT_POINTSET_TOPIC_TEMPLATE = "{}/events/pointset"
EVENT_DISCOVERY_TOPIC_TEMPLATE = "{}/events/discovery"
EVENT_SYSTEM_TOPIC_TEMPLATE = "{}/events/system"
_state_monitor_interval = 1 # [s]
_STATE_MONITOR_INTERVAL = 1 # [s]

INSTALLED_VERSION_FILE = "installed_version.txt"

def __init__(
self,
Expand All @@ -36,10 +40,17 @@ def __init__(
):
self.publisher = publisher
self.config = config
self.state = udmi.schema.state.State()
self.components = {}
self.callbacks = {} # lambda,

self.state = udmi.schema.state.State()

with contextlib.suppress(FileNotFoundError):
installed_version_file = pathlib.Path(__file__).with_name(UDMICore.INSTALLED_VERSION_FILE)
with open(installed_version_file, encoding="utf-8") as f:
if (installed_version := f.read()) != "":
self.state.system.software.version = installed_version

self.topic_state = UDMICore.STATE_TOPIC_TEMPLATE.format(topic_prefix)

self.topic_discovery_event = UDMICore.EVENT_DISCOVERY_TOPIC_TEMPLATE.format(
Expand All @@ -49,8 +60,6 @@ def __init__(
topic_prefix
)

print(self.topic_state)

threading.Thread(target=self.state_monitor, args=[], daemon=True).start()

self.enable_discovery(**config.get("udmi",{}).get("discovery", {}))
Expand Down Expand Up @@ -92,18 +101,18 @@ def state_monitor(self):
if self._last_state_hash != current_hash:
self.publish_state()
self._last_state_hash = current_hash
time.sleep(self._state_monitor_interval)
time.sleep(self._STATE_MONITOR_INTERVAL)

def publish_state(self):
state = self.state.to_json()
logging.warning("published state: %s", state)
self.publisher.publish_message(self.topic_state, state)

def publish_discovery(self, payload):
logging.warning("published discovery: %s", payload.to_json())
logging.warning("published discovery for %s:%s", payload["scan_family"], payload["scan_addr"])
self.publisher.publish_message(self.topic_discovery_event, payload.to_json())

def enable_discovery(self,*,bacnet=True,vendor=True,ipv4=True,ethmac=True):
def enable_discovery(self,*,bacnet=True,vendor=True,ipv4=True,ether=True):

if vendor:
number_discovery = udmi.discovery.numbers.NumberDiscovery(
Expand Down Expand Up @@ -143,7 +152,7 @@ def enable_discovery(self,*,bacnet=True,vendor=True,ipv4=True,ethmac=True):

self.components["passive_discovery"] = passive_discovery

if ethmac:
if ether:
nmap_banner_scan = udmi.discovery.nmap.NmapBannerScan(
self.state,
self.publish_discovery,
Expand Down
19 changes: 12 additions & 7 deletions misc/discoverynode/src/udmi/discovery/bacnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ def result_producer(self):

# if depths ...
# Get make and model
object_name, vendor_name, firmware_version, model_name, serial_number = (
self.bacnet.readMultiple(
f"{address} device {id} objectName vendorName"
" firmwareRevision modelName serialNumber"
)
)

try:
object_name, vendor_name, firmware_version, model_name, serial_number = (
self.bacnet.readMultiple(
f"{address} device {id} objectName vendorName"
" firmwareRevision modelName serialNumber"
)
)
except ValueError:
logging.exception(f"error reading from {address}/{id}")
continue

logging.info("object_name %s vendor_name %s firmware %s model %s serial %s", object_name, vendor_name, firmware_version, model_name, serial_number)
event = udmi.schema.discovery_event.DiscoveryEvent(
generation=self.config.generation,
scan_family=self.scan_family,
Expand Down
2 changes: 1 addition & 1 deletion misc/discoverynode/src/udmi/discovery/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class NmapBannerScan(discovery.DiscoveryController):
"""Passive Network Discovery."""

scan_family = "ethmac"
scan_family = "ethwe"

def __init__(self, state, publisher, *, target_ips: list[str]):
self.cancel_threads = threading.Event()
Expand Down
2 changes: 1 addition & 1 deletion misc/discoverynode/src/udmi/discovery/passive.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def discovery_service(self):
scan_addr=device_record.addr,
scan_family=self.scan_family,
families=dict(
ethmac=udmi.schema.discovery_event.DiscoveryFamily(
ether=udmi.schema.discovery_event.DiscoveryFamily(
device_record.mac
)
),
Expand Down
2 changes: 1 addition & 1 deletion misc/discoverynode/testing/e2e/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def localnet_block_from_id(id: int):

return {
"ipv4": {"addr": f"192.168.11.{id}"},
"ethmac": {"addr": f"00:00:aa:bb:cc:{id:02x}"},
"ether": {"addr": f"00:00:aa:bb:cc:{id:02x}"},
"bacnet": {"addr": str(3000 + id)},
"vendor": {"addr": str(id)},
}
Expand Down

0 comments on commit 978bab0

Please sign in to comment.