diff --git a/ebpfcat/arraymap.py b/ebpfcat/arraymap.py index 808e7e4d4ae9286e073b3d91238f4c8b3e58321a..eaf71e7adb8b426f8bc327589ae46d01f00baaea 100644 --- a/ebpfcat/arraymap.py +++ b/ebpfcat/arraymap.py @@ -60,40 +60,6 @@ class ArrayMapAccess: def __init__(self, data, size): self.data = data self.size = size - #self.data = bytearray(size) - - def read(self): - """read all variables in the map from EBPF to user space""" - #self.data = lookup_elem(self.fd, b"\0\0\0\0", self.size) - - def write(self): - """write all variables in the map from user space to EBPF - - *all* variables are written, even those not marked ``write=True`` - """ - #update_elem(self.fd, b"\0\0\0\0", self.data, 0) - - def readwrite(self): - """read variables from EBPF and write them out immediately - - This reads all variables, swaps in the user-modified values for - the ``write=True`` variables, and writes the out again - immediately. - - This means that even the read-only variables will be overwritten - with the values we have just read. If the EBPF program changed - the value in the meantime, that may be a problem. - - Note that after this method returns, all *write* variables - will have the value from the EBPF program in user space, and - vice-versa. - """ - return - write = self.data[:self.write_size] - data = lookup_elem(self.fd, b"\0\0\0\0", self.size) - self.data[:] = data - data[:self.write_size] = write - update_elem(self.fd, b"\0\0\0\0", data, 0) class ArrayMap(Map): @@ -108,28 +74,20 @@ class ArrayMap(Map): for prog in chain([ebpf], ebpf.subprograms): for k, v in prog.__class__.__dict__.items(): if isinstance(v, ArrayGlobalVarDesc): - collection.append((v.write, calcsize(v.fmt), prog, k)) - collection.sort(key=lambda t: t[:2], reverse=True) + collection.append((calcsize(v.fmt), prog, k)) + collection.sort(key=lambda t: t[0], reverse=True) position = 0 - last_write = write = True - for write, size, prog, name in collection: - if last_write != write: - position = (position + 7) & -8 - write_size = position + for size, prog, name in collection: prog.__dict__[name] = position position += size - last_write = write - if write: # there are read variables - return position, position - else: - return write_size, position + return position def __set_name__(self, owner, name): self.name = name def init(self, ebpf): setattr(ebpf, self.name, 0) - write_size, size = self.collect(ebpf) + size = self.collect(ebpf) if not size: # nobody is actually using the map return fd = create_map(MapType.ARRAY, 4, size, 1, MapFlags.MMAPABLE) diff --git a/ebpfcat/devices.py b/ebpfcat/devices.py index b82cae2499d6fcea8f309a8b56fde39f368271d8..ba12a7f5635fb3652c7760fd052888c50d4ffa17 100644 --- a/ebpfcat/devices.py +++ b/ebpfcat/devices.py @@ -33,7 +33,7 @@ class AnalogInput(Device): It will read from there and return the result in its parameter `value`. """ - value = DeviceVar(write=False) + value = DeviceVar() data = TerminalVar() def __init__(self, data): @@ -52,7 +52,7 @@ class AnalogOutput(Device): This device can be linked to an analog output of a terminal. It will write the `value` to that terminal. """ - value = DeviceVar(write=True) + value = DeviceVar() data = TerminalVar() def __init__(self, data): @@ -72,7 +72,7 @@ class DigitalInput(Device): It will read from there and return the result in its parameter `value`. """ - value = DeviceVar(write=False) + value = DeviceVar() data = TerminalVar() def __init__(self, data): @@ -91,7 +91,7 @@ class DigitalOutput(Device): This device can be linked to an analog output of a terminal. It will write the `value` to that terminal. """ - value = DeviceVar(write=True) + value = DeviceVar() data = TerminalVar() def __init__(self, data): @@ -110,8 +110,8 @@ class PWM(Device): This device can be linked to an analog output of a terminal. It will write the `value` to that terminal. """ - seed = DeviceVar("I", write=True) - value = DeviceVar("I", write=True) + seed = DeviceVar("I") + value = DeviceVar("I") data = TerminalVar() def __init__(self, data): @@ -130,8 +130,8 @@ class Counter(Device): count = DeviceVar("I") lasttime = DeviceVar("Q") - maxtime = DeviceVar("Q", write=True) - squared = DeviceVar("Q", write=True) + maxtime = DeviceVar("Q") + squared = DeviceVar("Q") def program(self): self.count += 1 @@ -157,12 +157,12 @@ class Motor(Device): enable = TerminalVar() current_position = DeviceVar() - set_velocity = DeviceVar(write=True) - set_enable = DeviceVar(write=True) - max_velocity = DeviceVar(write=True) - max_acceleration = DeviceVar(write=True) - target = DeviceVar(write=True) - proportional = DeviceVar(write=True) + set_velocity = DeviceVar() + set_enable = DeviceVar() + max_velocity = DeviceVar() + max_acceleration = DeviceVar() + target = DeviceVar() + proportional = DeviceVar() def update(self): velocity = self.proportional * (self.target - self.encoder) @@ -214,7 +214,7 @@ class Dummy(Device): class RandomDropper(Device): - rate = DeviceVar("I", write=True) + rate = DeviceVar("I") def program(self): from .xdp import XDPExitCode diff --git a/ebpfcat/ebpfcat.py b/ebpfcat/ebpfcat.py index 4bf61f705e678bada326150046c15ab164dfd9b4..91104bf844bef3be43dcc8795f9faf5b04e8c5ef 100644 --- a/ebpfcat/ebpfcat.py +++ b/ebpfcat/ebpfcat.py @@ -174,8 +174,8 @@ class TerminalVar: class DeviceVar(ArrayGlobalVarDesc): - def __init__(self, size="I", write=False): - super().__init__(FastSyncGroup.properties, size, write) + def __init__(self, size="I"): + super().__init__(FastSyncGroup.properties, size) def __get__(self, instance, owner): if instance is None: