Connection.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
  2. import java.util.Collection;
  3. /**
  4. * Connection between two or more SmartDevices, which sends packages according
  5. * to a specified protocol
  6. *
  7. * @author Andreas T. Meyer-Berg
  8. */
  9. public interface Connection {
  10. // States of the Connection
  11. /**
  12. * Connection won't sent more packets, can be removed from the model
  13. */
  14. public final byte DONE = 0b0;
  15. /**
  16. * Connection active, still sending packets
  17. */
  18. public final byte ACTIVE = 0b1;
  19. /**
  20. * Connection finished by the Protocol as planned
  21. */
  22. public final byte FINISHED = 0b10;
  23. /**
  24. * Connection was terminated not as planned
  25. */
  26. public final byte TERMINATED = 0b11;
  27. /**
  28. * Connection is halted, not sending packets at the moment, but might later
  29. */
  30. public final byte HALTED = 0b100;
  31. /**
  32. * Returns the Link, which the connection uses
  33. *
  34. * @return link this connection uses
  35. */
  36. public Link getLink();
  37. /**
  38. * Sets the Link, which the connection uses
  39. *
  40. * @param link the link of this connection
  41. */
  42. public void setLink(Link link);
  43. /**
  44. * Returns the SmartDevices that are part of this connection
  45. *
  46. * @return SmartDevices participating in this connection
  47. */
  48. public Collection<Port> getParticipants();
  49. /**
  50. * Returns the SmartDevices that are part of this connection, and the removed ones, which did not sent their last packages yet
  51. *
  52. * @return SmartDevices participating in this connection, and the removed ones, which haven't sent their terminating packages
  53. */
  54. public Collection<Port> getParticipantsAndRemoved();
  55. /**
  56. * Removes the SmartDevice from the Connection. Should create terminating
  57. * packages, that are returned on the next call of simulateTimeIntervall.<br> If
  58. * the Connection will be fully closed, status should be changed to
  59. * FINISHED or TERMINATED and
  60. * getTerminationPackages should return the lastPackages that were sent to
  61. * terminate the connection. If the connection still continues and the
  62. * source was removed, a new Device should become the source. The Calling
  63. * Method should remove the Connection in the SmartDevice and add the
  64. * Connection to Model.terminatedConnections(), if status changed.
  65. *
  66. * @param sd
  67. * SmartDevice to be removed
  68. * @return true if the device was removed
  69. */
  70. public boolean removeSmartDevice(Port sd);
  71. /**
  72. * Adds new SmartDevice(Port) to the connection, Caller also has to add it to the protocol.
  73. * @param sd Device to be added
  74. * @return true if it was added
  75. */
  76. public boolean addSmartDevice(Port sd);
  77. /**
  78. * Simulates the next Simulation interval and returns the packets that were
  79. * sent during this interval.
  80. *
  81. * @param startTime
  82. * Time the simulation interval starts in
  83. * System.currentTimeMillis() time
  84. * @param duration
  85. * Duration of the simulation interval in milliseconds
  86. * @return packets that were sent in this interval
  87. */
  88. @Deprecated
  89. public Collection<Packet> simulateTimeInterval(long startTime, long duration);
  90. /**
  91. * Returns the Packets, created to terminate the connection
  92. *
  93. * @param startTime
  94. * Time the simulation interval starts in
  95. * System.currentTimeMillis() time
  96. * @return packets that were sent
  97. */
  98. public Collection<Packet> getTerminationPackages(long startTime);
  99. /**
  100. * Encapsulates the given Packets
  101. * @param packets Packets which should be encapsulated
  102. * @return Encapsulated Packets
  103. */
  104. public Collection<Packet> encapsulatePackages(Collection<Packet> packets);
  105. /**
  106. * Returns the Protocol which is used on this Connection
  107. *
  108. * @return used Protocol instance
  109. */
  110. public Protocol getProtocol();
  111. /**
  112. * Set the Protocol which is used. Participants have to be updated
  113. *
  114. * @param protocol
  115. * new Protocol that shall be used
  116. * @return true if it was set
  117. */
  118. public boolean setProtocol(Protocol protocol);
  119. /**
  120. * Returns the current transmission status of the connection.
  121. * (FINISHED, ACTIVE, TERMINATED, HALTED)
  122. *
  123. * @return transmission status
  124. */
  125. public byte getStatus();
  126. /**
  127. * Set the transmission status of the connection
  128. * to FINISHED, ACTIVE, TERMINATED or HALTED
  129. *
  130. * @param status
  131. * transmission status
  132. */
  133. public void setStatus(byte status);
  134. /**
  135. * Set probability of packet loss. Should be between 0.0 (No packets are lost) and 1.0 (All packets are dropped)
  136. *
  137. * @param lossPercentage Probability that packets are lost
  138. */
  139. public void setPacketLossProbability(double lossPercentage);
  140. /**
  141. * Returns the probability that packets are lost
  142. *
  143. * @return probability of packet loss (between 0.0 and 1.0
  144. */
  145. public double getPacketLossProbability();
  146. /**
  147. * Returns true if the status, or participants changed during the last simulation time step
  148. *
  149. * @return true, if status changed
  150. */
  151. public boolean getStatusChanged();
  152. /**
  153. * Returns the Name of the connection if set
  154. * @return name of the connection
  155. */
  156. public String getName();
  157. /**
  158. * Sets the name of the connection
  159. * @param name new name of the connection
  160. */
  161. public void setName(String name);
  162. /**
  163. * Returns a String representation of the different status values
  164. * @param status status to be converted
  165. * @return String representation of the status
  166. */
  167. public static String getStatusName(byte status){
  168. switch (status) {
  169. case DONE:
  170. return "DONE";
  171. case ACTIVE:
  172. return "ACTIVE";
  173. case FINISHED:
  174. return "FINISHED";
  175. case TERMINATED:
  176. return "TERMINATED";
  177. case HALTED:
  178. return "HALTED";
  179. default:
  180. return "unknown";
  181. }
  182. }
  183. /**
  184. * Returns the default label for packets of this connection represented as a short
  185. * @return default label value
  186. */
  187. public short getLabel();
  188. /**
  189. * Set the default label value for packets of this connection
  190. * @param label new default label value
  191. */
  192. public void setLabel(short label);
  193. }