SimplePacket.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. */
  41. public SimplePacket(long time, Port source, Port destination, String payload) {
  42. super(time, source, destination);
  43. this.source = source;
  44. this.destination = destination;
  45. this.payload = payload;
  46. }
  47. @Override
  48. public byte[] dumpBytes() {
  49. return this.dumpBytes();
  50. }
  51. @Override
  52. public String getTextualRepresentation() {
  53. return this.toString();
  54. }
  55. @Override
  56. public String toString() {
  57. String destName = destination == null ? "null" : destination.getOwner().getName();
  58. String srcName = source == null ? "null" : source.getOwner().getName();
  59. return "[SimplePacket:" + payload + " time-" + timestamp + ";source:" + srcName + ";dest:"
  60. + destName + "]";
  61. }
  62. @Override
  63. public String getPayload() {
  64. return payload == null ? "" : payload;
  65. }
  66. @Override
  67. protected String getProtocolName() {
  68. return "Simple";
  69. }
  70. }