dtp.py 588 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """Dynamic Trunking Protocol."""
  2. from pypacker import pypacker, triggerlist
  3. import struct
  4. TRUNK_NAME = 0x01
  5. MAC_ADDR = 0x04
  6. class DTP(pypacker.Packet):
  7. __hdr__ = (
  8. ("v", "B", 0),
  9. ("tvs", None, triggerlist.TriggerList)
  10. )
  11. def _dissect(self, buf):
  12. off = 1
  13. dlen = len(buf)
  14. tvs = []
  15. while off < dlen:
  16. # length: inclusive header
  17. _, l = struct.unpack('>HH', buf[off: off + 4])
  18. packet = TV(buf[off: off + l])
  19. tvs.append(packet)
  20. off += l
  21. self.tvs.extend(tvs)
  22. return 1 + dlen
  23. class TV(pypacker.Packet):
  24. __hdr__ = (
  25. ("t", "H", 0),
  26. ("len", "H", 0)
  27. )