Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions pymodbus/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,6 @@
from pymodbus.utilities import dict_property


# ---------------------------------------------------------------------------#
# Network Access Control
# ---------------------------------------------------------------------------#
class ModbusAccessControl(Singleton):
"""Simple implementation of a Network Management System table.

Its purpose is to control access to the server (if it is used).
We assume that if an entry is in the table, it is allowed accesses to
resources. However, if the host does not appear in the table (all
unknown hosts) its connection will simply be closed.

Since it is a singleton, only one version can possible exist and all
instances pull from here.
"""

__nmstable = [
"127.0.0.1",
]

def __iter__(self):
"""Iterate over the network access table.

:returns: An iterator of the network access table
"""
return self.__nmstable.__iter__()

def __contains__(self, host):
"""Check if a host is allowed to access resources.

:param host: The host to check
"""
return host in self.__nmstable

def add(self, host):
"""Add allowed host(s) from the NMS table.

:param host: The host to add
"""
if not isinstance(host, list):
host = [host]
for entry in host:
if entry not in self.__nmstable:
self.__nmstable.append(entry)

def remove(self, host):
"""Remove allowed host(s) from the NMS table.

:param host: The host to remove
"""
if not isinstance(host, list):
host = [host]
for entry in host:
if entry in self.__nmstable:
self.__nmstable.remove(entry)

def check(self, host):
"""Check if a host is allowed to access resources.

:param host: The host to check
"""
return host in self.__nmstable


# ---------------------------------------------------------------------------#
# Modbus Plus Statistics
# ---------------------------------------------------------------------------#
Expand Down Expand Up @@ -657,7 +594,6 @@ def getDiagnosticRegister(self): # pylint: disable=invalid-name
# Exported Identifiers
# ---------------------------------------------------------------------------#
__all__ = [
"ModbusAccessControl",
"ModbusPlusStatistics",
"ModbusDeviceIdentification",
"DeviceInformationFactory",
Expand Down
29 changes: 0 additions & 29 deletions test/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pymodbus.constants import DeviceInformation
from pymodbus.device import (
DeviceInformationFactory,
ModbusAccessControl,
ModbusControlBlock,
ModbusDeviceIdentification,
ModbusPlusStatistics,
Expand Down Expand Up @@ -43,14 +42,12 @@ def setUp(self):
}
self.ident = ModbusDeviceIdentification(self.info)
self.control = ModbusControlBlock()
self.access = ModbusAccessControl()
self.control.reset()

def tearDown(self):
"""Clean up the test environment"""
del self.ident
del self.control
del self.access

def test_update_identity(self):
"""Test device identification reading"""
Expand Down Expand Up @@ -272,32 +269,6 @@ def test_modbus_control_block_invalid_diagnostic(self):
self.assertEqual(None, self.control.getDiagnostic(None))
self.assertEqual(None, self.control.getDiagnostic([1, 2, 3]))

def test_add_remove__single_clients(self):
"""Test adding and removing a host"""
self.assertFalse(self.access.check("192.168.1.1"))
self.access.add("192.168.1.1")
self.assertTrue(self.access.check("192.168.1.1"))
self.access.add("192.168.1.1")
self.access.remove("192.168.1.1")
self.assertFalse(self.access.check("192.168.1.1"))

def test_add_remove_multiple_clients(self):
"""Test adding and removing a host"""
clients = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
self.access.add(clients)
for host in clients:
self.assertTrue(self.access.check(host))
self.access.remove(clients)

def test_network_access_list_iterator(self):
"""Test adding and removing a host"""
clients = ["127.0.0.1", "192.168.1.1", "192.168.1.2", "192.168.1.3"]
self.access.add(clients)
for host in self.access:
self.assertTrue(host in clients)
for host in clients:
self.assertTrue(host in self.access)

def test_clearing_control_events(self):
"""Test adding and clearing modbus events"""
self.assertEqual(self.control.Events, [])
Expand Down