SimplePacket.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation;
  2. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
  3. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
  4. /**
  5. * Simple dummy packet for testing purposes
  6. *
  7. * @author Andreas T. Meyer-Berg
  8. */
  9. public class SimplePacket extends Packet {
  10. /**
  11. * Payload which was sent
  12. */
  13. private String payload;
  14. /**
  15. * Creates a new dummy packet without payload
  16. *
  17. * @param time
  18. * time the package was created in System.currentTimeMillis
  19. * @param source
  20. * SmartDevice which sent this packet
  21. * @param destination
  22. * SmartDevice which should receive this packet
  23. */
  24. public SimplePacket(long time, Port source, Port destination) {
  25. super(time, source, destination);
  26. this.payload = "";
  27. }
  28. /**
  29. * Creates a new dummy packet with a String as payload
  30. *
  31. * @param time
  32. * time the package was created in System.currentTimeMillis
  33. * @param source
  34. * SmartDevice which sent this packet
  35. * @param destination
  36. * SmartDevice which should receive this packet
  37. * @param payload
  38. * String which represents the payload which is encapsulated by
  39. * this packet
  40. * @param label
  41. * Label of this packet, represented as a short
  42. */
  43. public SimplePacket(long time, Port source, Port destination, String payload) {
  44. super(time, source, destination);
  45. this.source = source;
  46. this.destination = destination;
  47. this.payload = payload;
  48. }
  49. /**
  50. * Creates a new dummy packet with a String as payload
  51. *
  52. * @param time
  53. * time the package was created in System.currentTimeMillis
  54. * @param source
  55. * SmartDevice which sent this packet
  56. * @param destination
  57. * SmartDevice which should receive this packet
  58. * @param payload
  59. * String which represents the payload which is encapsulated by
  60. * this packet
  61. * @param label
  62. * Label of this packet, represented as a short
  63. */
  64. public SimplePacket(long time, Port source, Port destination, String payload, short label) {
  65. super(time, source, destination);
  66. this.source = source;
  67. this.destination = destination;
  68. this.payload = payload;
  69. this.label = label;
  70. }
  71. @Override
  72. public byte[] dumpBytes() {
  73. return this.dumpBytes();
  74. }
  75. @Override
  76. public String getTextualRepresentation() {
  77. return this.toString();
  78. }
  79. @Override
  80. public String toString() {
  81. String destName = destination == null ? "null" : (destination.getOwner().getName()+":"+destination.getPortNumber());
  82. String srcName = source == null ? "null" : (source.getOwner().getName()+":"+source.getPortNumber());
  83. return "[SimplePacket:" + payload + " time:" + timestamp + ";source:" + srcName + ";dest:"
  84. + destName + "]";
  85. }
  86. @Override
  87. public String getPayload() {
  88. return payload == null ? "" : payload;
  89. }
  90. @Override
  91. public String getProtocolName() {
  92. return "Simple";
  93. }
  94. }