Skip to content
Snippets Groups Projects
Select Git revision
  • 9204eee79df228ece1231e135cf4d1e3deade2a0
  • master default
  • cnit_ofc26
  • feat/344-implement-a-new-firewall-agent-controllable-through-restconf-openconfig
  • feat/343-integration-of-mimir-deployment-in-production-environment
  • ofc_polimi
  • feat/305-cttc-enhanced-netconf-openconfig-sbi-driver-for-dscm-pluggables
  • feat/306-cttc-enhanced-restconf-based-openconfig-nbi-for-dscm-pluggables
  • feat/301-cttc-dscm-pluggables
  • CTTC-IMPLEMENT-NBI-CONNECTOR-NOS-ZTP
  • CTTC-TEST-SMARTNICS-6GMICROSDN-ZTP
  • develop protected
  • feat/327-tid-new-service-to-ipowdm-controller-to-manage-transceivers-configuration-on-external-agent
  • cnit_tapi
  • feat/330-tid-pcep-component
  • feat/tid-newer-pcep-component
  • feat/116-ubi-updates-in-telemetry-backend-to-support-p4-in-band-network-telemetry
  • feat/292-cttc-implement-integration-test-for-ryu-openflow
  • cnit-p2mp-premerge
  • feat/325-tid-nbi-e2e-to-manage-e2e-path-computation
  • feat/326-tid-external-management-of-devices-telemetry-nbi
  • feat/324-tid-nbi-ietf_l3vpn-deploy-fail
  • v5.0.0 protected
  • v4.0.0 protected
  • demo-dpiab-eucnc2024
  • v3.0.0 protected
  • v2.1.0 protected
  • v2.0.0 protected
  • v1.0.0 protected
29 results

test_unitary.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    MonitoringLoop.py 1.63 KiB
    # Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #      http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    import queue, threading
    from device.service.driver_api._Driver import _Driver
    
    class MonitoringLoop:
        def __init__(self, device_uuid : str, driver : _Driver, samples_queue : queue.Queue) -> None:
            self._device_uuid = device_uuid
            self._driver = driver
            self._samples_queue = samples_queue
            self._running = threading.Event()
            self._terminate = threading.Event()
            self._samples_stream = self._driver.GetState(blocking=True, terminate=self._terminate)
            self._collector_thread = threading.Thread(target=self._collect, daemon=True)
    
        def _collect(self) -> None:
            for sample in self._samples_stream:
                if self._terminate.is_set(): break
                sample = (self._device_uuid, *sample)
                self._samples_queue.put_nowait(sample)
    
        def start(self):
            self._collector_thread.start()
            self._running.set()
    
        @property
        def is_running(self): return self._running.is_set()
    
        def stop(self):
            self._terminate.set()
            self._collector_thread.join()