Kaynağa Gözat

Updates all connections to use Ports instead of SmartDevices

Each Port can have distinct timings, statuses etc.
Andreas T. Meyer-Berg 5 yıl önce
ebeveyn
işleme
9459e938a2

+ 18 - 4
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/Main.java

@@ -3,6 +3,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleConnection;
@@ -46,7 +47,7 @@ public class Main {
 	    v = new MainFrame(m, c);
 	    sim = new SimulationManager(m);
 	    initializeTest();
-	    sim.simulateTimeIntervall(0, 1000);
+	    sim.simulateTimeIntervall(0, 100000);
 	}
 	
 	/**
@@ -78,10 +79,23 @@ public class Main {
 		B.addLink(link);
 		C.addLink(link);
 		
-		SimpleConnection s = new SimpleConnection(A, B, link, new SimpleProtocol(A, B));
-		A.addConnection(s);
-		B.addConnection(s);
+		Port a = new Port(A, (short) 1);
+		a.setLastTrigger(0);
+		a.setTriggerInterval(68);
+		a.setStatus(Port.SENDING);
+		A.addPort(a);
+		Port b = new Port(B, (short) 2);
+		b.setTriggerInterval(102);
+		b.setStatus(Port.SENDING);
+		B.addPort(b);
+		
+		SimpleConnection s = new SimpleConnection(a, b, link, new SimpleProtocol(a, b));
+
+		a.setConnection(s);
+		b.setConnection(s);
 		m.addConnectionNetwork(link);
+		link.addConnection(s);
+		m.addConnection(s);
 	}
 
 }

+ 13 - 7
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -3,6 +3,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 /**
@@ -196,16 +197,21 @@ public class Controller {
 		toDelete.getLinks().clear();
 
 		// Delete Connections
-		for (Connection c : toDelete.getConnections()) {
-			c.removeSmartDevice(toDelete);
-			if (c.getSource() == null) {
-				model.addTerminatingConnections(c);
-				for (SmartDevice sd : c.getParticipants()) {
-					if (sd != null)
-						sd.getConnections().remove(c);
+		for (Port p : toDelete.getPorts()) {
+			//Skip ports that are not connected
+			if(p.getConnection()==null)continue;
+			Connection c = p.getConnection();
+			c.removeSmartDevice(p);
+			if (c.getStatus()==Connection.FINISHED||c.getStatus()==Connection.TERMINATED) {
+				//if connection terminated - remove rest of ports
+				for (Port sd : c.getParticipants()) {
+					if (sd != null && sd != p)
+						sd.getOwner().removePort(sd);
 				}
 			}
 		}
+		//Remove all ports from the device
+		toDelete.getPorts().clear();
 		model.getDevices().remove(toDelete);
 	}
 

+ 75 - 17
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Connection.java

@@ -10,6 +10,28 @@ import java.util.Collection;
  */
 public interface Connection {
 
+	// States of the Connection
+	/**
+	 * Connection won't sent more packets, can be removed from the model
+	 */
+	public final byte DONE = 0b0;
+	/**
+	 * Connection active, still sending packets
+	 */
+	public final byte ACTIVE = 0b1;
+	/**
+	 * Connection finished by the Protocol as planned
+	 */
+	public final byte FINISHED = 0b10;
+	/**
+	 * Connection was terminated not as planned
+	 */
+	public final byte TERMINATED = 0b11;
+	/**
+	 * Connection is halted, not sending packets at the moment, but might later
+	 */
+	public final byte HALTED = 0b100;
+
 	/**
 	 * Returns the Link, which the connection uses
 	 * 
@@ -22,28 +44,38 @@ public interface Connection {
 	 * 
 	 * @return source SmartDevice
 	 */
-	public SmartDevice getSource();
+	public Port getSource();
 
 	/**
 	 * Returns the SmartDevices that are part of this connection
 	 * 
 	 * @return SmartDevices participating in this connection
 	 */
-	public Collection<SmartDevice> getParticipants();
+	public Collection<Port> 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
+	 * packages, that are returned on the next call of simulateTimeIntervall.<br> If
+	 * the Connection will be fully closed, status should be changed to
+	 * {@link Connection#FINISHED} or {@link Connection#TERMINATED} and
+	 * getTerminationPackages should return the lastPackages that were sent to
+	 * terminate the connection. If the connection still continues and the
+	 * source was removed, 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.
+	 * Connection to Model.terminatedConnections(), if status changed.
 	 * 
 	 * @param sd
-	 *            SmartDevice to Remove
+	 *            SmartDevice to be removed
+	 * @return true if the device was removed
 	 */
-	public void removeSmartDevice(SmartDevice sd);
+	public boolean removeSmartDevice(Port sd);
+
+	/**
+	 * Adds new SmartDevice(Port) to the connection, Caller also has to add it to the protocol.
+	 * @param sd Device to be added
+	 * @return true if it was added
+	 */
+	public boolean addSmartDevice(Port sd);
 
 	/**
 	 * Simulates the next Simulation interval and returns the packets that were
@@ -67,13 +99,39 @@ public interface Connection {
 	 * @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();
 
+	/**
+	 * Returns the Protocol which is used on this Connection
+	 * 
+	 * @return used Protocol instance
+	 */
+	public Protocol getProtocol();
+
+	/**
+	 * Set the Protocol which is used. Participants have to be updated
+	 * 
+	 * @param protocol
+	 *            new Protocol that shall be used
+	 * @return true if it was set
+	 */
+	public boolean setProtocol(Protocol protocol);
+
+	/**
+	 * Returns the current transmission status of the connection.
+	 * 
+	 * @return transmission status
+	 * @see {@link Connection#FINISHED}, {@link Connection#ACTIVE},
+	 *      {@link Connection#TERMINATED} and {@link Connection#HALTED}
+	 */
+	public byte getStatus();
+
+	/**
+	 * Set the transmission status of the connection
+	 * 
+	 * @param status
+	 *            transmission status
+	 * @see {@link Connection#FINISHED}, {@link Connection#ACTIVE},
+	 *      {@link Connection#TERMINATED} and {@link Connection#HALTED}
+	 */
+	public void setStatus(byte status);
 }

+ 17 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Link.java

@@ -36,6 +36,23 @@ public interface Link {
 	 *            the devices to remove
 	 */
 	public void removeDevice(SmartDevice device);
+	
+	/**
+	 * @return the connections
+	 */
+	public Collection<Connection> getConnections();
+
+	/**
+	 * @param coonnection
+	 *            the connection to add
+	 */
+	public void addConnection(Connection connection);
+	
+	/**
+	 * @param connection
+	 *            the connection to remove
+	 */
+	public void removeConnection(Connection Connection);
 
 	/**
 	 * Simulates an interval starting at startTime for a given duration

+ 12 - 6
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Model.java

@@ -13,7 +13,7 @@ public class Model {
 
 	private List<SmartDevice> devices;
 	private List<Link> connectionNetworks;
-	private List<Connection> terminatingConnections;
+	private List<Connection> connections;
 	
 	/**
 	 * Width of the smart home model, 0 <= device.x < width
@@ -47,7 +47,7 @@ public class Model {
 		
 		devices = new ArrayList<SmartDevice>();
 		connectionNetworks = new ArrayList<Link>();
-		terminatingConnections = new LinkedList<Connection>();
+		connections = new LinkedList<Connection>();
 	}
 
 	/**
@@ -135,11 +135,17 @@ public class Model {
 		this.device_visualization_radius = device_visualization_radius;
 	}
 	
-	public List<Connection> getTerminatingConnections() {
-		return terminatingConnections;
+	/**
+	 * @return the connections
+	 */
+	public List<Connection> getConnections() {
+		return connections;
 	}
 
-	public void addTerminatingConnections(Connection terminatedConnection) {
-		this.terminatingConnections.add(terminatedConnection);
+	/**
+	 * @param connection the connection to add
+	 */
+	public void addConnection(Connection connection) {
+		this.connections.add(connection);
 	}	
 }

+ 32 - 27
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Packet.java

@@ -1,27 +1,32 @@
-package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
-
-/**
- * Virtual network packet, that can be sent, collected, dumped and edited
- * 
- * @author Andreas T. Meyer-Berg
- */
-public abstract class Packet {
-
-	/**
-	 * 
-	 * @return Byte representation of the current packet
-	 */
-	public abstract Byte[] dumpBytes();
-
-	/**
-	 * 
-	 * @return Textual Representation of the Package
-	 */
-	public abstract String getTextualRepresentation();
-
-	/**
-	 * 
-	 * @return Textual Representation of the Package
-	 */
-	public abstract String getPayload();
-}
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+/**
+ * Virtual network packet, that can be sent, collected, dumped and edited
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
+public abstract class Packet {
+
+	/**
+	 * 
+	 * @return Byte representation of the current packet
+	 */
+	public abstract Byte[] dumpBytes();
+
+	/**
+	 * 
+	 * @return Textual Representation of the Package
+	 */
+	public abstract String getTextualRepresentation();
+
+	/**
+	 * 
+	 * @return Textual Representation of the Package
+	 */
+	public abstract String getPayload();
+
+	/**
+	 * Returns the Timestamp, wehn the packet was sent
+	 */
+	public abstract long getTimestamp();
+}

+ 52 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Port.java

@@ -11,18 +11,18 @@ public class Port {
 	/**
 	 * A closed Port which does not react to incoming traffic
 	 */
-	public final short CLOSED = 0;
+	public static final short CLOSED = 0;
 
 	/**
 	 * Open Port which reacts to incoming traffic
 	 */
-	public final short OPEN = 1;
+	public static final short OPEN = 1;
 
 	/**
 	 * Open Port which reacts to incoming traffic and sends packets every
 	 * triggerInterval
 	 */
-	public final short SENDING = 2;
+	public static final short SENDING = 2;
 
 	/**
 	 * Status of the Port, wethere it is CLOSED, OPEN or SENDING
@@ -34,6 +34,11 @@ public class Port {
 	 */
 	private SmartDevice owner;
 
+	/**
+	 * Connection this Port listens to
+	 */
+	private Connection connection;
+	
 	/**
 	 * Constant time interval, which triggers new traffic every
 	 * {@code triggerInterval} milliseconds.
@@ -55,6 +60,22 @@ public class Port {
 	 */
 	private short portNumber;
 
+	/**
+	 * Creates a new Port for the given Device with the specified PortNumber
+	 * @param device
+	 * @param portNumber
+	 */
+	public Port(SmartDevice device, short portNumber){
+		status = CLOSED;
+		owner = device;
+		connection = null;
+		triggerInterval = 1000;
+		lastTrigger = 0;
+		responseTime = 5;
+		this.portNumber = portNumber;
+	}
+	
+	
 	/**
 	 * @return the status
 	 */
@@ -130,4 +151,32 @@ public class Port {
 		this.portNumber = portNumber;
 	}
 
+	/**
+	 * @return the last timestep the port sent a package
+	 */
+	public long getLastTrigger() {
+		return lastTrigger;
+	}
+
+	/**
+	 * @param lastTrigger the last timestep the port sent
+	 */
+	public void setLastTrigger(long lastTrigger) {
+		this.lastTrigger = lastTrigger;
+	}
+
+	/**
+	 * @return the connection
+	 */
+	public Connection getConnection() {
+		return connection;
+	}
+
+	/**
+	 * @param connection the connection to set
+	 */
+	public void setConnection(Connection connection) {
+		this.connection = connection;
+	}
+
 }

+ 72 - 70
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Protocol.java

@@ -1,70 +1,72 @@
-package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
-
-import java.util.Collection;
-
-/**
- * Protocol according to which the packages are created. Can contain different
- * Roles.
- * 
- * @author Andreas T. Meyer-Berg
- */
-public interface Protocol {
-
-	/**
-	 * Generates the next packet
-	 * 
-	 * @param timestep
-	 *            Time the package should be sent, in System.currentTimeMillis
-	 * @return next Packet, which was sent
-	 */
-	public Packet generateNextPaket(long timestep);
-
-	/**
-	 * Returns the number of different roles the participating SmartDevices
-	 * could have
-	 * 
-	 * @return number of different roles
-	 */
-	public int getNumberOfRoles();
-
-	/**
-	 * Returns the textual representation of the different Roles. The Array
-	 * should contain {@code NumberOfRoles} Strings. {@code Array[role]} should be
-	 * a human-readable String representation of the Role at its position
-	 * {@code role}.
-	 * 
-	 * @return String representations of the roles
-	 */
-	public String[] getRoles();
-
-	/**
-	 * Returns all SmartDevices of the given Role. Returns {@code null}, if the role
-	 * number was invalid.
-	 * 
-	 * @param role
-	 *            Position of the role in {@code getNumberOfRoles}
-	 * @return SmartDevices of Role with index {@code role}
-	 */
-	public Collection<SmartDevice> getDevicesWithRole(int role);
-
-	/**
-	 * Adds a new SmartDevice to the role, returns {@code true} if it was
-	 * assigned successfully, {@code false} if it wasn't. (Either invalid role
-	 * number or maximum number of devices for the role reached)
-	 * 
-	 * @param device
-	 *            SmartDevice that should be assigned to the given role
-	 * @param role
-	 *            Position of the role in {@code getNumberOfRoles}
-	 * @return true, if the SmartDevice was added
-	 */
-	public boolean addDeviceOfRole(SmartDevice device, int role);
-
-	/**
-	 * Remove a SmartDevice from this protocol
-	 * 
-	 * @param device
-	 *            device that should be removed
-	 */
-	public void removeDevice(SmartDevice device);
-}
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+import java.util.Collection;
+
+/**
+ * Protocol according to which the packages are created. Can contain different
+ * Roles and multiple participating SmartDevice(Port)s.
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
+public interface Protocol {
+	
+	/**
+	 * Generates the next packet
+	 * 
+	 * @param port SmartDevice(Port) which sends the package
+	 * @param timestep
+	 *            Time the package should be sent, in System.currentTimeMillis
+	 * @return next Packet, which was sent
+	 */
+	public Packet generateNextPaket(Port port, long timestep);
+
+	/**
+	 * Returns the number of different roles the participating SmartDevice(Port)s
+	 * could have
+	 * 
+	 * @return number of different roles
+	 */
+	public int getNumberOfRoles();
+
+	/**
+	 * Returns the textual representation of the different Roles. The Array
+	 * should contain {@code NumberOfRoles} Strings. {@code Array[role]} should be
+	 * a human-readable String representation of the Role at its position
+	 * {@code role}.
+	 * 
+	 * @return String representations of the roles
+	 */
+	public String[] getRoles();
+
+	/**
+	 * Returns all SmartDevice(Port)s of the given Role. Returns {@code null}, if the role
+	 * number was invalid.
+	 * 
+	 * @param role
+	 *            Position of the role in {@code getNumberOfRoles}
+	 * @return SmartDevices of Role with index {@code role}
+	 */
+	public Collection<Port> getDevicesWithRole(int role);
+
+	/**
+	 * Adds a new SmartDevice to the role, returns {@code true} if it was
+	 * assigned successfully, {@code false} if it wasn't. (Either invalid role
+	 * number or maximum number of devices for the role reached)
+	 * 
+	 * @param device
+	 *            SmartDevice(Port) that should be assigned to the given role
+	 * @param role
+	 *            Position of the role in {@code getNumberOfRoles}
+	 * @return true, if the SmartDevice(Port) was added
+	 */
+	public boolean addDeviceOfRole(Port device, int role);
+
+	/**
+	 * Remove a SmartDevice(Port) from this Protocol
+	 * 
+	 * @param device
+	 *            device that should be removed
+	 */
+	public void removeDevice(Port device);
+
+}

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/SimulationManager.java

@@ -7,7 +7,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
  */
 public class SimulationManager {
 	Model model;
-
+	long stepDuration = 100;
 	/**
 	 * Creates a new Simulationmanager
 	 * 

+ 44 - 9
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/SmartDevice.java

@@ -20,11 +20,16 @@ public class SmartDevice {
 	 */
 	private List<Link> links;
 
-	/**
+	/* *
 	 * Virtual Connections to other SmartDevices
 	 */
-	private List<Connection> connections;
+	//private List<Connection> connections;
 
+	/**
+	 * Ports of this device
+	 */
+	private List<Port> ports;
+	
 	/**
 	 * Creates a new SmartDevice without links
 	 * 
@@ -34,7 +39,7 @@ public class SmartDevice {
 	public SmartDevice(String name) {
 		this.name = name;
 		links = new LinkedList<Link>();
-		connections = new LinkedList<Connection>();
+		ports = new LinkedList<Port>();
 	}
 
 	/**
@@ -159,24 +164,33 @@ public class SmartDevice {
 		this.z = z;
 	}
 
-	/**
+	/* *
 	 * Returns all connections of this device
 	 * 
 	 * @return the connections of this device
-	 */
+	 * /
 	public List<Connection> getConnections() {
 		return connections;
-	}
+	}*/
 
-	/**
+	/* *
 	 * Adds a connection to this device
 	 * 
 	 * @param connections
 	 *            the connection add
-	 */
+	 * /
 	public void addConnection(Connection connections) {
 		this.connections.add(connections);
-	}
+	}*/
+	
+	/* *
+	 * Removes connection
+	 * 
+	 * @param connection connection to remove
+	 * /
+	public void removeConnection(Connection c) {
+		this.connections.remove(c);
+	}*/
 
 	/**
 	 * Simulates the next Timestep
@@ -191,4 +205,25 @@ public class SmartDevice {
 
 	}
 
+	/**
+	 * @return the ports
+	 */
+	public List<Port> getPorts() {
+		return ports;
+	}
+
+	/**
+	 * @param ports the ports to set
+	 */
+	public void addPort(Port port) {
+		this.ports.add(port);
+	}
+	
+	/**
+	 * @param ports the ports to set
+	 */
+	public void removePort(Port port) {
+		this.ports.remove(port);
+	}
+
 }

+ 92 - 33
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleConnection.java

@@ -7,52 +7,63 @@ import java.util.LinkedList;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 public class SimpleConnection implements Connection {
 
 	/**
-	 * SmartDevice which is the source of this connection
+	 * SmartDevice(Port) which is the source of this connection
 	 */
-	private SmartDevice source;
+	private Port source;
 	/**
-	 * SmartDevice which is the destination of this connection
+	 * SmartDevice(Port) which is the destination of this connection
 	 */
-	private SmartDevice destination;
+	private Port destination;
 	/**
-	 * Link which connects {@code source} and  {@code destination}
+	 * Link which connects {@code source} and {@code destination}
 	 */
 	private Link link;
 	/**
 	 * Protocol, which specifies the packet generation
 	 */
 	private Protocol p;
-	
-	//for Termination
+
+	// for Termination
 	/**
-	 * SmartDevice which started the termination process
+	 * SmartDevice(Port) which started the termination process
 	 */
-	private SmartDevice srcOfTermination;
-	/**
+	private Port srcOfTermination;
+	/* *
 	 * SmartDevice which responds in the termination process
 	 */
-	private SmartDevice other;
-	
+	// private SmartDevice other;
+
 	/**
-	 * Creates a new connection between to SmartDevices on a given Link, which communicate with a protocol p
+	 * Transmission status of the connection
+	 */
+	private byte status = Connection.ACTIVE;
+
+	/**
+	 * Creates a new connection between to SmartDevices on a given Link, which
+	 * communicate with a protocol p
 	 * 
-	 * @param src SmartDevice which is the source of this connection
-	 * @param dest SmartDevice which is the destination of this connection
-	 * @param link Link which connects {@code src} and  {@code dest}
-	 * @param p Protocol, which specifies the packet generation
+	 * @param src
+	 *            SmartDevice which is the source of this connection
+	 * @param dest
+	 *            SmartDevice which is the destination of this connection
+	 * @param link
+	 *            Link which connects {@code src} and {@code dest}
+	 * @param p
+	 *            Protocol, which specifies the packet generation
 	 */
-	public SimpleConnection(SmartDevice src, SmartDevice dest, Link link, Protocol p) {
+	public SimpleConnection(Port src, Port dest, Link link, Protocol p) {
 		source = src;
 		destination = dest;
 		this.link = link;
 		this.p = p;
 	}
+
 	@Override
 	public Link getLink() {
 		return link;
@@ -61,31 +72,79 @@ public class SimpleConnection implements Connection {
 	@Override
 	public Collection<Packet> simulateTimeInterval(long startTime, long duration) {
 		LinkedList<Packet> list = new LinkedList<Packet>();
-		for(long i = 0; i<duration; i+=100)
-			list.add(p.generateNextPaket(startTime+i));
+		if(status != ACTIVE)return list;
+		//Generate packets by source
+		if(source.getLastTrigger()+source.getTriggerInterval()<startTime && source.getStatus()==Port.SENDING){
+			list.add(p.generateNextPaket(source, startTime));
+		}
+		while(source.getLastTrigger()+source.getTriggerInterval()<startTime+duration &&source.getStatus()==Port.SENDING)
+			list.add(p.generateNextPaket(source, source.getLastTrigger()+source.getTriggerInterval()));
+		
+		if(destination.getLastTrigger()+destination.getTriggerInterval()<startTime && destination.getStatus()==Port.SENDING){
+			list.add(p.generateNextPaket(destination, startTime));
+		}
+		while(destination.getLastTrigger()+destination.getTriggerInterval()<startTime+duration &&destination.getStatus()==Port.SENDING)
+			list.add(p.generateNextPaket(destination, destination.getLastTrigger()+destination.getTriggerInterval()));
+
+		list.sort((x,y) -> Long.compare(x.getTimestamp(),y.getTimestamp()));
 		return list;
 	}
+
 	@Override
-	public SmartDevice getSource() {
+	public Port getSource() {
 		return source;
 	}
+
 	@Override
-	public Collection<SmartDevice> getParticipants() {
-		return new LinkedList<SmartDevice>(Arrays.asList(source, destination));
+	public Collection<Port> getParticipants() {
+		return new LinkedList<Port>(Arrays.asList(source, destination));
 	}
+
 	@Override
-	public void removeSmartDevice(SmartDevice sd) {
-		//of source == null - connection was already terminated
-		if(source == null)return;
-		srcOfTermination = sd;
-		other = sd == source? destination : source;
-		source = null;
-		destination = null;	
+	public boolean removeSmartDevice(Port sd) {
+		if (sd == source || sd == destination) {
+			// of source == null - connection was already terminated
+			status = Connection.TERMINATED;
+			srcOfTermination = sd;
+			return true;
+		} else
+			return false;
 	}
-	
+
 	@Override
 	public Collection<Packet> getTerminationPackages(long startTime) {
-		return new LinkedList<Packet>(Arrays.asList((Packet)new SimplePacket(startTime, srcOfTermination, other,"Terminated")));
+		status = DONE;
+		return new LinkedList<Packet>(Arrays.asList((Packet) new SimplePacket(
+				startTime, srcOfTermination.getOwner(),
+				srcOfTermination == source ? destination.getOwner() : source
+						.getOwner(), "Terminated")));
+	}
+
+	@Override
+	public boolean addSmartDevice(Port sd) {
+		// Not possible to add Devices
+		return false;
+	}
+
+	@Override
+	public Protocol getProtocol() {
+		return p;
+	}
+
+	@Override
+	public boolean setProtocol(Protocol protocol) {
+		return false;
+
+	}
+
+	@Override
+	public byte getStatus() {
+		return status;
+	}
+
+	@Override
+	public void setStatus(byte status) {
+		this.status = status;
 	}
 
 }

+ 28 - 6
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleLink.java

@@ -28,6 +28,7 @@ public class SimpleLink implements Link {
 	 */
 	private ArrayList<SmartDevice> devices;
 
+	private ArrayList<Connection> connections;
 	/**
 	 * List of packages to store packages sent during simulation intervals, or
 	 * after termination
@@ -44,6 +45,7 @@ public class SimpleLink implements Link {
 		this.name = name;
 		this.devices = new ArrayList<SmartDevice>();
 		this.packets = new LinkedList<Packet>();
+		this.connections = new ArrayList<Connection>();
 	}
 
 	/**
@@ -97,16 +99,36 @@ public class SimpleLink implements Link {
 	@Override
 	public void simulateTimeInterval(long startTime, long duration) {
 		packets.clear();
-		for (SmartDevice sd : devices)
-			for (Connection c : sd.getConnections()) {
-				// Simulate just if source and link match
-				if (c.getLink() == this && c.getSource() == sd)
-					packets.addAll(c.simulateTimeInterval(startTime, duration));
-			}
+		for (Connection c : connections) {
+			if (c.getLink() != this)
+				continue;
+			// Simulate just if source and link match
+			if ((c.getStatus() == Connection.ACTIVE || c.getStatus() == Connection.HALTED))
+				packets.addAll(c.simulateTimeInterval(startTime, duration));
+			else if (c.getStatus() == Connection.FINISHED
+					|| c.getStatus() == Connection.TERMINATED)
+				//Produce Termination packages
+				packets.addAll(c.getTerminationPackages(startTime));
+		}
 	}
 
 	@Override
 	public Collection<Packet> getPackets() {
 		return packets;
 	}
+
+	@Override
+	public Collection<Connection> getConnections() {
+		return connections;
+	}
+
+	@Override
+	public void addConnection(Connection connection) {
+		connections.add(connection);
+	}
+
+	@Override
+	public void removeConnection(Connection connection) {
+		connections.remove(connection);
+	}
 }

+ 5 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimplePacket.java

@@ -91,4 +91,9 @@ public class SimplePacket extends Packet {
 		return payload == null ? "" : payload;
 	}
 
+	@Override
+	public long getTimestamp() {
+		return time;
+	}
+
 }

+ 12 - 13
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleProtocol.java

@@ -4,8 +4,8 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
-import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 /**
  * Simple Implementation of a protocol, which sends 
@@ -17,25 +17,25 @@ public class SimpleProtocol implements Protocol {
 	/**
 	 * Source of the protocol, and destination which responds
 	 */
-	SmartDevice source, destination;
+	Port source, destination;
 	
 	/**
 	 * True if the next Package is send by source, false if the next one will be send by destination
 	 */
 	boolean srcSends;
 	
-	public SimpleProtocol(SmartDevice src, SmartDevice dest){
+	public SimpleProtocol(Port src, Port dest){
 		source = src;
 		destination = dest;
 		srcSends = true;
 	}
 	@Override
-	public Packet generateNextPaket(long timestep) {
-		srcSends = !srcSends;
-		if(srcSends)
-			return new SimplePacket(timestep, destination, source);
+	public Packet generateNextPaket(Port p, long timestep) {
+		p.setLastTrigger(timestep);
+		if(p == destination)
+			return new SimplePacket(timestep, destination.getOwner(), source.getOwner());
 		else
-			return new SimplePacket(timestep, source, destination);
+			return new SimplePacket(timestep, source.getOwner(), destination.getOwner());
 	}
 	
 	@Override
@@ -50,8 +50,8 @@ public class SimpleProtocol implements Protocol {
 	}
 	
 	@Override
-	public Collection<SmartDevice> getDevicesWithRole(int role) {
-		SmartDevice ret = null;
+	public Collection<Port> getDevicesWithRole(int role) {
+		Port ret = null;
 		switch (role) {
 		case 0:
 			ret = source;
@@ -69,7 +69,7 @@ public class SimpleProtocol implements Protocol {
 	}
 	
 	@Override
-	public boolean addDeviceOfRole(SmartDevice device, int role) {
+	public boolean addDeviceOfRole(Port device, int role) {
 		if(role == 0 && source == null){
 			source = device;
 		}else if(role == 1 && destination == source){
@@ -81,13 +81,12 @@ public class SimpleProtocol implements Protocol {
 	}
 	
 	@Override
-	public void removeDevice(SmartDevice device) {
+	public void removeDevice(Port device) {
 		if(device == source)
 			source = null;
 		if(device == destination)
 			destination = null;
 		
 	}
-	
 
 }