Selaa lähdekoodia

Adds ports V0.0 to represent timings etc. for each Device and Connection

Andreas T. Meyer-Berg 5 vuotta sitten
vanhempi
commit
ea2583104a

+ 79 - 71
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Connection.java

@@ -1,71 +1,79 @@
-package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
-
-import java.util.Collection;
-
-/**
- * Connection between two or more SmartDevices, which sends packages according
- * to a specified protocol
- * 
- * @author Andreas T. Meyer-Berg
- */
-public interface Connection {
-
-	/**
-	 * Returns the Link, which the connection uses
-	 * 
-	 * @return link this connection uses
-	 */
-	public Link getLink();
-
-	/**
-	 * Returns the SmartDevice which started this connection
-	 * 
-	 * @return source SmartDevice
-	 */
-	public SmartDevice getSource();
-
-	/**
-	 * Returns the SmartDevices that are part of this connection
-	 * 
-	 * @return SmartDevices participating in this connection
-	 */
-	public Collection<SmartDevice> getParticipants();
-
-	/**
-	 * Removes the SmartDevice from the Connection. Should create terminating
-	 * packages, that are returned on the next call of simulateTimeIntervall. If
-	 * the Connection will be fully closed, source should be set to null and
-	 * getTerminationPackages should return the lastPackages. If the connection
-	 * still continues, a new Device should become the source. The Calling
-	 * Method should remove the Connection in the SmartDevice and add the
-	 * Connection to Model.terminatedConnections(), if source was set to null.
-	 * 
-	 * @param sd
-	 *            SmartDevice to Remove
-	 */
-	public void removeSmartDevice(SmartDevice sd);
-
-	/**
-	 * Simulates the next Simulation interval and returns the packets that were
-	 * sent during this interval.
-	 * 
-	 * @param startTime
-	 *            Time the simulation interval starts in
-	 *            System.currentTimeMillis() time
-	 * @param duration
-	 *            Duration of the simulation interval in milliseconds
-	 * @return packets that were sent in this interval
-	 */
-	public Collection<Packet> simulateTimeInterval(long startTime, long duration);
-
-	/**
-	 * Returns the Packets, created to terminate the connection
-	 * 
-	 * @param startTime
-	 *            Time the simulation interval starts in
-	 *            System.currentTimeMillis() time
-	 * @return packets that were sent
-	 */
-	public Collection<Packet> getTerminationPackages(long startTime);
-
-}
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+import java.util.Collection;
+
+/**
+ * Connection between two or more SmartDevices, which sends packages according
+ * to a specified protocol
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
+public interface Connection {
+
+	/**
+	 * Returns the Link, which the connection uses
+	 * 
+	 * @return link this connection uses
+	 */
+	public Link getLink();
+
+	/**
+	 * Returns the SmartDevice which started this connection
+	 * 
+	 * @return source SmartDevice
+	 */
+	public SmartDevice getSource();
+
+	/**
+	 * Returns the SmartDevices that are part of this connection
+	 * 
+	 * @return SmartDevices participating in this connection
+	 */
+	public Collection<SmartDevice> getParticipants();
+
+	/**
+	 * Removes the SmartDevice from the Connection. Should create terminating
+	 * packages, that are returned on the next call of simulateTimeIntervall. If
+	 * the Connection will be fully closed, source should be set to null and
+	 * getTerminationPackages should return the lastPackages. If the connection
+	 * still continues, a new Device should become the source. The Calling
+	 * Method should remove the Connection in the SmartDevice and add the
+	 * Connection to Model.terminatedConnections(), if source was set to null.
+	 * 
+	 * @param sd
+	 *            SmartDevice to Remove
+	 */
+	public void removeSmartDevice(SmartDevice sd);
+
+	/**
+	 * Simulates the next Simulation interval and returns the packets that were
+	 * sent during this interval.
+	 * 
+	 * @param startTime
+	 *            Time the simulation interval starts in
+	 *            System.currentTimeMillis() time
+	 * @param duration
+	 *            Duration of the simulation interval in milliseconds
+	 * @return packets that were sent in this interval
+	 */
+	public Collection<Packet> simulateTimeInterval(long startTime, long duration);
+
+	/**
+	 * Returns the Packets, created to terminate the connection
+	 * 
+	 * @param startTime
+	 *            Time the simulation interval starts in
+	 *            System.currentTimeMillis() time
+	 * @return packets that were sent
+	 */
+	public Collection<Packet> getTerminationPackages(long startTime);
+	
+	//public Protocol getProtocol();
+	
+	//public void setProtocol(Protocol protocol);
+	
+	//public void setTriggerIntervall(long intervall); - or via ports
+	
+	//public long getTriggerIntervall();
+
+}

+ 133 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Port.java

@@ -0,0 +1,133 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+/**
+ * Representation of connection EndPoints, which allows configuration of timings
+ * and if it reacts to incoming traffic or even triggers new connections.
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
+public class Port {
+
+	/**
+	 * A closed Port which does not react to incoming traffic
+	 */
+	public final short CLOSED = 0;
+
+	/**
+	 * Open Port which reacts to incoming traffic
+	 */
+	public final short OPEN = 1;
+
+	/**
+	 * Open Port which reacts to incoming traffic and sends packets every
+	 * triggerInterval
+	 */
+	public final short SENDING = 2;
+
+	/**
+	 * Status of the Port, wethere it is CLOSED, OPEN or SENDING
+	 */
+	private short status;
+
+	/**
+	 * SmartDevice which owns the port
+	 */
+	private SmartDevice owner;
+
+	/**
+	 * Constant time interval, which triggers new traffic every
+	 * {@code triggerInterval} milliseconds.
+	 */
+	private long triggerInterval;
+
+	/**
+	 * Last timestep traffic was triggered
+	 */
+	private long lastTrigger;
+
+	/**
+	 * Time in milliseconds needed for responds to incoming 
+	 */
+	private short responseTime;
+
+	/**
+	 * Port number of this Port.
+	 */
+	private short portNumber;
+
+	/**
+	 * @return the status
+	 */
+	public short getStatus() {
+		return status;
+	}
+
+	/**
+	 * @param status
+	 *            the status to set
+	 */
+	public void setStatus(short status) {
+		this.status = status;
+	}
+
+	/**
+	 * @return the owner
+	 */
+	public SmartDevice getOwner() {
+		return owner;
+	}
+
+	/**
+	 * @param owner
+	 *            the owner to set
+	 */
+	public void setOwner(SmartDevice owner) {
+		this.owner = owner;
+	}
+
+	/**
+	 * @return the triggerInterval
+	 */
+	public long getTriggerInterval() {
+		return triggerInterval;
+	}
+
+	/**
+	 * @param triggerInterval
+	 *            the triggerInterval to set
+	 */
+	public void setTriggerInterval(long triggerInterval) {
+		this.triggerInterval = triggerInterval;
+	}
+
+	/**
+	 * @return the responseTime
+	 */
+	public short getResponseTime() {
+		return responseTime;
+	}
+
+	/**
+	 * @param responseTime
+	 *            the responseTime to set
+	 */
+	public void setResponseTime(short responseTime) {
+		this.responseTime = responseTime;
+	}
+
+	/**
+	 * @return the portNumber
+	 */
+	public short getPortNumber() {
+		return portNumber;
+	}
+
+	/**
+	 * @param portNumber
+	 *            the portNumber to set
+	 */
+	public void setPortNumber(short portNumber) {
+		this.portNumber = portNumber;
+	}
+
+}