Packet.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
  2. /**
  3. * Virtual network packet, that can be sent, collected, dumped and edited
  4. *
  5. * @author Andreas T. Meyer-Berg
  6. */
  7. public abstract class Packet {
  8. /**
  9. * Time when the packet was sent
  10. */
  11. protected long timestamp;
  12. /**
  13. * SourcePort of the packet
  14. */
  15. protected Port source;
  16. /**
  17. * DestinationPort of the packet
  18. */
  19. protected Port destination;
  20. /**
  21. * Creates a new packet with the given timestamp
  22. * @param timestamp time the packet was sent
  23. * @param source Source of the packet
  24. * @param destination destination of the packet
  25. */
  26. protected Packet(long timestamp, Port source, Port destination){
  27. this.timestamp = timestamp;
  28. this.source = source;
  29. this.destination = destination;
  30. }
  31. /**
  32. *
  33. * @return Byte representation of the current packet
  34. */
  35. public abstract byte[] dumpBytes();
  36. /**
  37. * Returns a textual representation of the package
  38. *
  39. * @return Textual Representation of the Package
  40. */
  41. public abstract String getTextualRepresentation();
  42. /**
  43. * Returns the Payload as String
  44. *
  45. * @return Textual Representation of the Payload
  46. */
  47. public abstract String getPayload();
  48. /**
  49. * Returns the Timestamp, at which the packet was sent
  50. *
  51. * @return timestamp, the packet was sent
  52. */
  53. public long getTimestamp(){
  54. return timestamp;
  55. }
  56. /**
  57. * Sets the timestamp to the given value
  58. *
  59. * @param timestamp timstamp to set
  60. */
  61. public void setTimestamp(long timestamp){
  62. this.timestamp = timestamp;
  63. }
  64. /**
  65. * Returns the source port of the packet
  66. *
  67. * @return source port
  68. */
  69. public Port getSource(){
  70. return source;
  71. }
  72. /**
  73. * Returns the destination port of the packet
  74. *
  75. * @return destination port
  76. */
  77. public Port getDestination(){
  78. return destination;
  79. }
  80. /**
  81. * Return name of the protocol, the packets is part of
  82. *
  83. * @return Protocol name
  84. */
  85. protected abstract String getProtocolName();
  86. }