Packet.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * Number representing the label of the package
  22. */
  23. protected short label = 0;
  24. /**
  25. * Creates a new packet with the given timestamp
  26. * @param timestamp time the packet was sent
  27. * @param source Source of the packet
  28. * @param destination destination of the packet
  29. */
  30. protected Packet(long timestamp, Port source, Port destination){
  31. this.timestamp = timestamp;
  32. this.source = source;
  33. this.destination = destination;
  34. }
  35. /**
  36. *
  37. * @return Byte representation of the current packet
  38. */
  39. public abstract byte[] dumpBytes();
  40. /**
  41. * Returns a textual representation of the package
  42. *
  43. * @return Textual Representation of the Package
  44. */
  45. public abstract String getTextualRepresentation();
  46. /**
  47. * Returns the Payload as String
  48. *
  49. * @return Textual Representation of the Payload
  50. */
  51. public abstract String getPayload();
  52. /**
  53. * Returns the Timestamp, at which the packet was sent
  54. *
  55. * @return timestamp, the packet was sent
  56. */
  57. public long getTimestamp(){
  58. return timestamp;
  59. }
  60. /**
  61. * Sets the timestamp to the given value
  62. *
  63. * @param timestamp timstamp to set
  64. */
  65. public void setTimestamp(long timestamp){
  66. this.timestamp = timestamp;
  67. }
  68. /**
  69. * Returns the source port of the packet
  70. *
  71. * @return source port
  72. */
  73. public Port getSource(){
  74. return source;
  75. }
  76. /**
  77. * Returns the destination port of the packet
  78. *
  79. * @return destination port
  80. */
  81. public Port getDestination(){
  82. return destination;
  83. }
  84. /**
  85. * Return name of the protocol, the packets is part of
  86. *
  87. * @return Protocol name
  88. */
  89. public abstract String getProtocolName();
  90. /**
  91. * Returns the label represented as a short
  92. * @return label value
  93. */
  94. public short getLabel() {
  95. return label;
  96. }
  97. /**
  98. * Set the label value
  99. * @param label new label value
  100. */
  101. public void setLabel(short label) {
  102. this.label = label;
  103. }
  104. }