Label.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import functools
  2. @functools.total_ordering
  3. class Label:
  4. def __init__(self, attack_name, timestamp_start, timestamp_end, injected_packets, seed, parameters, attack_note=""):
  5. """
  6. Creates a new attack label
  7. :param attack_name: The name of the associated attack
  8. :param timestamp_start: The timestamp as unix time of the first attack packet
  9. :param timestamp_end: The timestamp as unix time of the last attack packet
  10. :param injected_packets: The number of packets injected by the attack
  11. :param seed: The seed used for randomization
  12. :param parameters: The list of parameters used to run the attack
  13. :param attack_note: A note associated to the attack (optional)
  14. """
  15. self.attack_name = attack_name
  16. self.timestamp_start = timestamp_start
  17. self.timestamp_end = timestamp_end
  18. self.injected_packets = injected_packets
  19. self.seed = seed
  20. self.attack_note = attack_note
  21. self.parameters = parameters
  22. def __eq__(self, other):
  23. return self.timestamp_start == other.timestamp_start
  24. def __lt__(self, other):
  25. return self.timestamp_start < other.timestamp_start
  26. def __gt__(self, other):
  27. return self.timestamp_start > other.timestamp_start
  28. def __str__(self):
  29. # FIXME: maybe add self.parameters as well?
  30. return ''.join(
  31. ['(', self.attack_name, ',', self.attack_note, ',', str(self.timestamp_start), ',', str(self.timestamp_end),
  32. str(self.injected_packets), ',', str(self.seed), ')'])