Explorar el Código

Adds SensorCollector support to MQTT, Renames old version to SimpleMQTT

Andreas T. Meyer-Berg hace 5 años
padre
commit
ab2e1208b1

+ 2 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/configuration/ImportConfiguration.java

@@ -16,6 +16,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensorDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.Ping_protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleMQTT;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
 
 /**
@@ -49,6 +50,7 @@ public class ImportConfiguration {
 		standardProtocols.add(MQTT_protocol.class);
 		standardProtocols.add(Ping_protocol.class);
 		standardProtocols.add(SimpleProtocol.class);
+		standardProtocols.add(SimpleMQTT.class);
 		
 		standardLinks.add(SimpleLink.class);
 		standardLinks.add(PrecisionLink.class);

+ 294 - 169
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/MQTT_protocol.java

@@ -3,12 +3,18 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.Random;
 
 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;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollector;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensor;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollector;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensor;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTT_packet;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Pair;
 
@@ -34,11 +40,11 @@ public class MQTT_protocol implements Protocol {
 	 * Subscriber which subscribe to different Topics
 	 */
 	private LinkedList<Port> subs;
-	
+
 	/**
 	 * Topics subscribed by each Port
 	 */
-	private HashMap<Port,LinkedList<String>> subbedTopics = new HashMap<Port,LinkedList<String>>();
+	private HashMap<Port, LinkedList<String>> subbedTopics = new HashMap<Port, LinkedList<String>>();
 
 	/**
 	 * Devices that are Publisher and Subscriber and therefore send and receive
@@ -51,67 +57,69 @@ public class MQTT_protocol implements Protocol {
 	 * last generatePackets Call
 	 */
 	private LinkedList<Packet> currentPackets = new LinkedList<Packet>();
-	
-	private LinkedList<Pair<Port,Port>> deletedConnectionLinks = new LinkedList<Pair<Port,Port>>();
+
+	// For Visualization in case of deleting the broker
+	private LinkedList<Pair<Port, Port>> deletedConnectionLinks = new LinkedList<Pair<Port, Port>>();
 	private SmartDevice deletedBroker = new SmartDevice("DeletedBroker");
-	private Port deletedBrokerPort = new Port(deletedBroker,(short)-1);
-	
+	private Port deletedBrokerPort = new Port(deletedBroker, (short) -1);
+
 	/**
 	 * Topics of the MQTT Broker
 	 */
-	private LinkedList<String> topics = new LinkedList<String>();
+	// private LinkedList<String> topics = new LinkedList<String>();
 
 	/**
 	 * Creates a new MQTT Protocol
 	 */
 	public MQTT_protocol() {
 		this.broker = null;
-	    initialize();
-	    
+		initialize();
+
 	}
-	
+
 	/**
 	 * Creates a new MQTT Protocol
 	 * 
-	 * @param broker broker of the protocol
+	 * @param broker
+	 *            broker of the protocol
 	 */
 	public MQTT_protocol(Port broker) {
 		this.broker = broker;
 		initialize();
-		
+
 	}
-	
+
 	/**
 	 * Initializes the different fields
 	 */
 	private void initialize() {
-		topics.add("/home/temperatureHot");
-	    topics.add("/home/doorOpen");
-	    topics.add("/home/lightOn");
-	    subs = new LinkedList<Port>();
-	    pubs = new LinkedList<Port>();
-	    pubSubs = new LinkedList<Port>();
+		subs = new LinkedList<Port>();
+		pubs = new LinkedList<Port>();
+		pubSubs = new LinkedList<Port>();
 	}
-	
+
 	@Override
 	public Collection<Packet> generateNextPackets(Port port, long timestep, boolean packetLost) {
 		/**
 		 * Packets which will be generated
 		 */
 		LinkedList<Packet> returnPackets = new LinkedList<Packet>();
-		//Update all Timestamps of previous created Packets
-		for(Packet p: currentPackets){
-			p.setTimestamp(p.getTimestamp()+timestep);
+		// Update all Timestamps of previous created Packets
+		for (Packet p : currentPackets) {
+			p.setTimestamp(p.getTimestamp() + timestep);
 		}
-		//Add these packets to the return
+		// Add these packets to the return
 		returnPackets.addAll(currentPackets);
-		//remove packets from the old list
+		// remove packets from the old list
 		currentPackets.clear();
-		//Clear deleted connections
+		// Clear deleted connections
 		deletedConnectionLinks.clear();
-		//Return termination packets
-		if(port==null)return returnPackets;
-		
+		// Return termination packets
+		if (port == null)
+			return returnPackets;
+		SmartDevice device = port.getOwner();
+		if (device == null)
+			return returnPackets;
 		/**
 		 * Update the lastTime the port was triggered
 		 */
@@ -119,131 +127,249 @@ public class MQTT_protocol implements Protocol {
 		/**
 		 * if port null, skip this step
 		 */
-		if(broker==null)return returnPackets;
-		
+		if (broker == null)
+			return returnPackets;
+
 		/**
 		 * Generate new Packets regarding to their class
 		 */
-		if(port==broker){
-			//Broker should not send new packages, without new messages
-			//But could perform some Ping request to random participants
+		if (port == broker) {
+			// Broker should not send new packages, without new messages
+			// But could perform some Ping request to random participants
 			Collection<Port> devices = getDevices();
 			devices.remove(port);
 			Port dest = null;
-			java.util.Iterator<Port> it = devices.iterator();
-			for(int i=0; i<(Math.random()*devices.size())&&it.hasNext();i++){
+			Iterator<Port> it = devices.iterator();
+			for (int i = 0; i < (Math.random() * devices.size()) && it.hasNext(); i++) {
 				dest = it.next();
 			}
-			if(dest != null){
+			if (dest != null) {
 				returnPackets.add(new MQTT_packet(MQTT_packet.PINGREQ, timestep, port, dest));
 				/**
 				 * Delay to the destination
 				 */
 				long delayBrokerDest = broker.getTransmissionDelayTo(dest);
-				if(dest.getStatus()!=Port.CLOSED && delayBrokerDest!=Long.MAX_VALUE)
-					returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP, timestep+delayBrokerDest+dest.getJitter()+dest.getResponseTime(), dest, port));
+				if (dest.getStatus() != Port.CLOSED && delayBrokerDest != Long.MAX_VALUE)
+					returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP,
+							timestep + delayBrokerDest + dest.getJitter() + dest.getResponseTime(), dest, port));
 			}
 		}
-		if(subs.contains(port)||pubSubs.contains(port)){
-			
-			//Subs can either subscribe to topics or unsubscribe
+		if (subs.contains(port) || pubSubs.contains(port)) {
+			// Subs can either subscribe to topics or unsubscribe
 			/**
 			 * Topics, the SmartDevice is subscribed to
 			 */
-			LinkedList<String> tops= subbedTopics.get(port);
-			
+			LinkedList<String> tops = subbedTopics.get(port);
+
+			/**
+			 * Topic which should be subscribed to
+			 */
+			String newTopic = null;
+
 			/**
-			 * Topic which should be subscribed or unsubscribed
+			 * Check if FloatCollector & not subscribed
 			 */
-			String newTopic;
-			//Subscribe if no subscriptions so far or not subscribed to all, with a probability of70%
-			if(tops.size()==0||(tops.size()!=topics.size()&&Math.random()<0.7)){
-				//Forced Subscribe
-				LinkedList<String> available = new LinkedList<String>();
-				available.addAll(topics);
-				available.removeAll(tops);
-				
-				newTopic = available.get((int) Math.floor(Math.random()*available.size()));
-				returnPackets.add(new MQTT_packet(MQTT_packet.SUBSCRIBE, timestep, port, broker, "topic:"+newTopic));
-				
+			if (device instanceof FloatCollector) {
+				FloatCollector fCollector = (FloatCollector) device;
+				if (!tops.contains(fCollector.getFCinfoName()))
+					newTopic = fCollector.getFCinfoName();
+			}
+			/**
+			 * Check if BoolCollector & not subscribed
+			 */
+			if (device instanceof BoolCollector) {
+				BoolCollector bCollector = (BoolCollector) device;
+				if (!tops.contains(bCollector.getBCinfoName()))
+					newTopic = bCollector.getBCinfoName();
+			}
+
+			// Subscribe if no subscriptions so far or not subscribed to all,
+			// with a probability of70%
+			if (newTopic != null) {
+				/**
+				 * Subscribe Request
+				 */
+				returnPackets.add(new MQTT_packet(MQTT_packet.SUBSCRIBE, timestep, port, broker, "topic:" + newTopic));
+
 				/**
 				 * Delay to the broker
 				 */
 				long delayPortToBroker = port.getTransmissionDelayTo(broker);
-				
-				if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
-					timestep+=broker.getResponseTime();
-					returnPackets.add(new MQTT_packet(MQTT_packet.SUBACK, timestep+delayPortToBroker, broker, port));
+
+				if (broker.getStatus() != Port.CLOSED && delayPortToBroker != Long.MAX_VALUE) {
+					timestep += broker.getResponseTime();
+					returnPackets.add(new MQTT_packet(MQTT_packet.SUBACK, timestep + delayPortToBroker, broker, port));
 					tops.add(newTopic);
 				}
-			}
-			else if(tops.size()==topics.size()){
-				//Forced Unsubscribe
-				newTopic = tops.get((int) Math.floor(Math.random()*tops.size()));
-				returnPackets.add(new MQTT_packet(MQTT_packet.UNSUBSCRIBE, timestep, port, broker, "topic:"+newTopic));
+			} else {
 				/**
-				 * Delay to the broker
+				 * Check if some topics should be unsubscribed (e.g., one topic
+				 * name change)
 				 */
-				long delayPortToBroker = port.getTransmissionDelayTo(broker);
-				
-				if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
-					timestep+=broker.getResponseTime();
-					returnPackets.add(new MQTT_packet(MQTT_packet.UNSUBACK, timestep+delayPortToBroker, broker, port));
-					tops.remove(newTopic);
+				newTopic = null;
+				LinkedList<String> oldTopics = new LinkedList<String>(tops);
+				if (!oldTopics.isEmpty()) {
+					/**
+					 * Check if FloatCollector & not subscribed
+					 */
+					if (device instanceof FloatCollector) {
+						FloatCollector fCollector = (FloatCollector) device;
+						oldTopics.remove(fCollector.getFCinfoName());
+					}
+					/**
+					 * Check if BoolCollector & not subscribed
+					 */
+					if (device instanceof BoolCollector) {
+						BoolCollector bCollector = (BoolCollector) device;
+						oldTopics.remove(bCollector.getBCinfoName());
+					}
+					if (!oldTopics.isEmpty()) {
+						newTopic = oldTopics.getFirst();
+						/**
+						 * Send Unsubscribe Packet
+						 */
+						returnPackets.add(
+								new MQTT_packet(MQTT_packet.UNSUBSCRIBE, timestep, port, broker, "topic:" + newTopic));
+						/**
+						 * Delay to the broker
+						 */
+						long delayPortToBroker = port.getTransmissionDelayTo(broker);
+						/**
+						 * Ackknowledgement
+						 */
+						if (broker.getStatus() != Port.CLOSED && delayPortToBroker != Long.MAX_VALUE) {
+							timestep += broker.getResponseTime();
+							returnPackets.add(
+									new MQTT_packet(MQTT_packet.UNSUBACK, timestep + delayPortToBroker, broker, port));
+							tops.remove(newTopic);
+						}
+					}
 				}
 			}
 		}
-		if(pubs.contains(port)||pubSubs.contains(port)&&Math.random()<0.3){
-			String newTopic = topics.get((int) Math.floor(Math.random()*topics.size()));
+
+		if (pubs.contains(port) || pubSubs.contains(port) && Math.random() < 0.3) {
 			/**
-			 * Message to be published (Should be further specialized by a Sensor Device) 
+			 * Topic which should be published to
 			 */
-			String msg = "Topic:"+newTopic+":"+(Math.random()<0.5?"true":"false");
-			returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, port, broker, msg));
-			
+			String newTopic = null;
 			/**
-			 * Delay to the broker
+			 * Value which should be published
 			 */
-			long delayPortToBroker = port.getTransmissionDelayTo(broker);
-			//Publish to Subscribers
-			//Should be be improved to just notify Subs that are subscribed to the topic
-			if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
-				//Response
-				timestep+=broker.getResponseTime()+delayPortToBroker;
-				returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep, broker, port));
-				
-				for(Port p:subs){
-					if(!subbedTopics.get(p).contains(newTopic))continue;//Skip unsubbed ports
-					/**
-					 * Delay broker to subscriber
-					 */
-					long delayBrokerToSub = broker.getTransmissionDelayTo(p);
-					timestep+=broker.getResponseTime();
-					returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
-					if(p.getStatus()!=Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE)
-						returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep+p.getResponseTime(), p, broker));
+			String newValue = null;
+
+			/**
+			 * Check if FloatSensor
+			 */
+			if (device instanceof FloatSensor) {
+				FloatSensor fSensor = (FloatSensor) device;
+				newTopic = fSensor.getFSinfoName();
+				newValue = "" + fSensor.getFSval();
+			}
+
+			/**
+			 * Check if BoolSensor - if also FloatSensor: 50% chance of
+			 * overriding
+			 */
+			if (device instanceof BoolSensor) {
+				BoolSensor bSensor = (BoolSensor) device;
+				if (newTopic == null || new Random().nextBoolean()) {
+					newTopic = bSensor.getBSinfoName();
+					newValue = "" + bSensor.getBSval();
 				}
-				for(Port p:pubSubs){
-					if(!subbedTopics.get(p).contains(newTopic))continue;//skip unsubbed ports
-					timestep+=broker.getResponseTime();
+			}
+
+			if (newTopic != null) {
+				/**
+				 * Message to be published
+				 */
+				String msg = "Topic:" + newTopic + ":" + newValue;
+				/**
+				 * Send Packet
+				 */
+				returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, port, broker, msg));
+
+				/**
+				 * Delay to the broker
+				 */
+				long delayPortToBroker = port.getTransmissionDelayTo(broker);
+
+				// Publish to Subscribers
+				if (broker.getStatus() != Port.CLOSED && delayPortToBroker != Long.MAX_VALUE) {
 					/**
-					 * Delay broker to subscriber
+					 * Response/Acknowledgement
 					 */
-					long delayBrokerToSub = broker.getTransmissionDelayTo(p);
-					returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
-					if(p.getStatus()!=Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE)
-						returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep+p.getResponseTime(), p, broker));
+					timestep += broker.getResponseTime() + delayPortToBroker;
+					returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep, broker, port));
+
+					for (Port p : subs) {
+						/**
+						 * Skip unsubcribed ports
+						 */
+						if (!subbedTopics.get(p).contains(newTopic))
+							continue;
+						/**
+						 * Delay broker to subscriber
+						 */
+						long delayBrokerToSub = broker.getTransmissionDelayTo(p);
+						timestep += broker.getResponseTime();
+
+						returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
+						if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
+							returnPackets.add(
+									new MQTT_packet(MQTT_packet.PUBACK, timestep + p.getResponseTime(), p, broker));
+							// Update Collector
+							if (device instanceof FloatSensor && p.getOwner() instanceof FloatCollector
+									&& newTopic.equals(((FloatSensor) device).getFSinfoName())) {
+								((FloatCollector) p.getOwner()).setFCval(((FloatSensor) device).getFSval());
+							} else if (device instanceof BoolSensor && p.getOwner() instanceof BoolCollector
+									&& newTopic.equals(((BoolSensor) device).getBSinfoName())) {
+								((BoolCollector) p.getOwner()).setBCval(((BoolSensor) device).getBSval());
+							}
+						}
+					}
+					for (Port p : pubSubs) {
+						/**
+						 * Skip unsubscribed Ports
+						 */
+						if (!subbedTopics.get(p).contains(newTopic) || p.getOwner() == null)
+							continue;
+
+						/**
+						 * Delay broker to subscriber
+						 */
+						long delayBrokerToSub = broker.getTransmissionDelayTo(p);
+						timestep += broker.getResponseTime();
+
+						returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
+						if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
+							returnPackets.add(
+									new MQTT_packet(MQTT_packet.PUBACK, timestep + p.getResponseTime(), p, broker));
+							// Update Collector
+							if (device instanceof FloatSensor && p.getOwner() instanceof FloatCollector
+									&& newTopic.equals(((FloatSensor) device).getFSinfoName())) {
+								((FloatCollector) p.getOwner()).setFCval(((FloatSensor) device).getFSval());
+							} else if (device instanceof BoolSensor && p.getOwner() instanceof BoolCollector
+									&& newTopic.equals(((BoolSensor) device).getBSinfoName())) {
+								((BoolCollector) p.getOwner()).setBCval(((BoolSensor) device).getBSval());
+							}
+						}
+					}
 				}
 			}
 		}
-		if(Math.random() < 0.05 && port != broker){
+		/**
+		 * Rare Ping request to broker
+		 */
+		if (Math.random() < 0.05 && port != broker) {
 			returnPackets.add(new MQTT_packet(MQTT_packet.PINGREQ, timestep, port, broker));
 			/**
 			 * Delay broker to subscriber
 			 */
 			long delayPortToBroker = port.getTransmissionDelayTo(broker);
-			if(broker.getStatus()!=Port.CLOSED && delayPortToBroker != Long.MAX_VALUE)
-				returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP, timestep+delayPortToBroker+broker.getResponseTime(), broker, port));
+			if (broker.getStatus() != Port.CLOSED && delayPortToBroker != Long.MAX_VALUE)
+				returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP,
+						timestep + delayPortToBroker + broker.getResponseTime(), broker, port));
 		}
 		return returnPackets;
 	}
@@ -279,9 +405,9 @@ public class MQTT_protocol implements Protocol {
 	@Override
 	public boolean addDeviceOfRole(Port device, int role) {
 		/*
-		 * First device has to be the Broker 
+		 * First device has to be the Broker
 		 */
-		if (broker==null) {
+		if (broker == null) {
 			if (role == 0) {
 				broker = device;
 				updateBrokerOnDeletedConnections(null);
@@ -292,7 +418,7 @@ public class MQTT_protocol implements Protocol {
 		}
 		switch (role) {
 		case 0:
-			//Just one broker allowed.
+			// Just one broker allowed.
 			return false;
 		case 1:
 			pubSubs.add(device);
@@ -310,8 +436,8 @@ public class MQTT_protocol implements Protocol {
 			return false;
 		}
 		// Create packets for the connecting Client
-		currentPackets.add(new MQTT_packet(MQTT_packet.CONNECT, currentPackets.size()/2, device, broker));
-		currentPackets.add(new MQTT_packet(MQTT_packet.CONNACK, currentPackets.size()/2+1, broker, device));
+		currentPackets.add(new MQTT_packet(MQTT_packet.CONNECT, currentPackets.size() / 2, device, broker));
+		currentPackets.add(new MQTT_packet(MQTT_packet.CONNACK, currentPackets.size() / 2 + 1, broker, device));
 		return true;
 	}
 
@@ -320,81 +446,79 @@ public class MQTT_protocol implements Protocol {
 		/**
 		 * true if the device was removed
 		 */
-		boolean removedDevice=false;
-		if (broker == device){
+		boolean removedDevice = false;
+		if (broker == device) {
 			broker = null;
-			deletedConnectionLinks.add(new Pair<Port, Port>(new Port(device.getOwner(), (short)-1), deletedBrokerPort));
+			deletedConnectionLinks
+					.add(new Pair<Port, Port>(new Port(device.getOwner(), (short) -1), deletedBrokerPort));
 			updateBrokerOnDeletedConnections(device);
 		}
-		removedDevice|=pubSubs.remove(device);
-		removedDevice|=subs.remove(device);
-		removedDevice|=pubs.remove(device);
-		//Remove Port from topics and clear its list
+		removedDevice |= pubSubs.remove(device);
+		removedDevice |= subs.remove(device);
+		removedDevice |= pubs.remove(device);
+		// Remove Port from topics and clear its list
 		LinkedList<String> oldTopics = subbedTopics.remove(device);
-		if(oldTopics!=null)oldTopics.clear();
-		if(removedDevice){
-			if(broker == null){
-				deletedConnectionLinks.add(new Pair<Port, Port>(deletedBrokerPort,device));
-			}else{
+		if (oldTopics != null)
+			oldTopics.clear();
+		if (removedDevice) {
+			if (broker == null) {
+				deletedConnectionLinks.add(new Pair<Port, Port>(deletedBrokerPort, device));
+			} else {
 				deletedConnectionLinks.add(new Pair<Port, Port>(broker, device));
-				//If not the broker and device was removed -> disconnect
-				currentPackets.add(new MQTT_packet(MQTT_packet.DISCONNECT, currentPackets.size()/2, device, broker));
+				// If not the broker and device was removed -> disconnect
+				currentPackets.add(new MQTT_packet(MQTT_packet.DISCONNECT, currentPackets.size() / 2, device, broker));
 			}
 		}
 	}
-	
-	public void addTopic(String topic){
-		topics.add(topic);
-	}
 
 	@Override
 	public String getName() {
 		return "MQTT";
 	}
-	
+
 	@Override
-	public int getRoleOfDevice(Port device){
-		if(device == null)
+	public int getRoleOfDevice(Port device) {
+		if (device == null)
 			return -1;
-		if(device == broker)
+		if (device == broker)
 			return 0;
-		if(pubSubs.contains(device))
+		if (pubSubs.contains(device))
 			return 1;
-		if(pubs.contains(device))
+		if (pubs.contains(device))
 			return 2;
-		if(subs.contains(device))
+		if (subs.contains(device))
 			return 3;
 		return -1;
 	}
-	
+
 	@Override
-	public Collection<Port> getDevices(){
+	public Collection<Port> getDevices() {
 		LinkedList<Port> returnDevices = new LinkedList<Port>();
-		if(broker!=null)
+		if (broker != null)
 			returnDevices.add(broker);
 		returnDevices.addAll(pubSubs);
 		returnDevices.addAll(pubs);
 		returnDevices.addAll(subs);
 		return returnDevices;
 	}
-	
+
 	@Override
 	public byte getTopologyType() {
 		return STAR;
 	}
-	
+
 	@Override
-	public Collection<Pair<Port,Port>> getTopology(){
-		LinkedList<Pair<Port,Port>> topology = new LinkedList<Pair<Port,Port>>();
+	public Collection<Pair<Port, Port>> getTopology() {
+		LinkedList<Pair<Port, Port>> topology = new LinkedList<Pair<Port, Port>>();
 		Port center = broker;
 		calcDeletedBrokerPosition();
-		if(broker==null)
-			center = new Port(deletedBroker, (short)-1);
-		for(Port p: pubSubs)
+		if (broker == null)
+			center = new Port(deletedBroker, (short) -1);
+		for (Port p : pubSubs)
 			topology.add(new Pair<Port, Port>(center, p));
-		for(Port p: pubs)
+		for (Port p : pubs)
 			topology.add(new Pair<Port, Port>(center, p));
-		for(Port p: subs)
+		for (Port p : subs)
 			topology.add(new Pair<Port, Port>(center, p));
 		return topology;
 	}
@@ -404,45 +528,46 @@ public class MQTT_protocol implements Protocol {
 		calcDeletedBrokerPosition();
 		return deletedConnectionLinks;
 	}
-	
+
 	/**
 	 * Calculate and update the position of the deleted Broker
 	 */
-	private void calcDeletedBrokerPosition(){
-		if(broker == null){
+	private void calcDeletedBrokerPosition() {
+		if (broker == null) {
 			int x = 0, y = 0, noP = 0;
-			for(Port p: getDevices()){
-				if(p!=null && p.getOwner()!=null){
+			for (Port p : getDevices()) {
+				if (p != null && p.getOwner() != null) {
 					x += p.getOwner().getX();
 					y += p.getOwner().getY();
 					noP++;
 				}
 			}
-			if(noP==0)
+			if (noP == 0)
 				return;
-			deletedBroker.setX(((int)(x*1.0)/noP));
-			deletedBroker.setY(((int)(y*1.0)/noP));
+			deletedBroker.setX(((int) (x * 1.0) / noP));
+			deletedBroker.setY(((int) (y * 1.0) / noP));
 		}
 	}
-	
+
 	/**
 	 * Update the broker port on the deleted Connections
 	 * 
-	 * @param device old broker
+	 * @param device
+	 *            old broker
 	 */
-	private void updateBrokerOnDeletedConnections(Port device){
-		for(Pair<Port, Port> p: deletedConnectionLinks){
-			if(broker == null){
-				if(p.getLeft() == device)
+	private void updateBrokerOnDeletedConnections(Port device) {
+		for (Pair<Port, Port> p : deletedConnectionLinks) {
+			if (broker == null) {
+				if (p.getLeft() == device)
 					p.setLeft(deletedBrokerPort);
-				if(p.getRight() == device)
+				if (p.getRight() == device)
 					p.setRight(deletedBrokerPort);
-			}else{
-				if(p.getLeft() == deletedBrokerPort)
+			} else {
+				if (p.getLeft() == deletedBrokerPort)
 					p.setLeft(broker);
-				if(p.getRight() == deletedBrokerPort)
+				if (p.getRight() == deletedBrokerPort)
 					p.setRight(broker);
-				
+
 			}
 		}
 	}

+ 450 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/simpleImplementation/SimpleMQTT.java

@@ -0,0 +1,450 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+
+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;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTT_packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Pair;
+
+/**
+ * SimpleImplementation of the MQTT Protocol to generate packets for the simulation, it generates random Publish/Subscribe packets for one of three topics with random boolean values
+ * 
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class SimpleMQTT implements Protocol {
+
+	/**
+	 * Broker which collects and distributes messages
+	 */
+	private Port broker;
+
+	/**
+	 * Publishers like sensors, which publish data
+	 */
+	private LinkedList<Port> pubs;
+
+	/**
+	 * Subscriber which subscribe to different Topics
+	 */
+	private LinkedList<Port> subs;
+	
+	/**
+	 * Topics subscribed by each Port
+	 */
+	private HashMap<Port,LinkedList<String>> subbedTopics = new HashMap<Port,LinkedList<String>>();
+
+	/**
+	 * Devices that are Publisher and Subscriber and therefore send and receive
+	 * messages
+	 */
+	private LinkedList<Port> pubSubs;
+
+	/**
+	 * Packets which are currently being generated or were generated after the
+	 * last generatePackets Call
+	 */
+	private LinkedList<Packet> currentPackets = new LinkedList<Packet>();
+	
+	private LinkedList<Pair<Port,Port>> deletedConnectionLinks = new LinkedList<Pair<Port,Port>>();
+	private SmartDevice deletedBroker = new SmartDevice("DeletedBroker");
+	private Port deletedBrokerPort = new Port(deletedBroker,(short)-1);
+	
+	/**
+	 * Topics of the MQTT Broker
+	 */
+	private LinkedList<String> topics = new LinkedList<String>();
+
+	/**
+	 * Creates a new MQTT Protocol
+	 */
+	public SimpleMQTT() {
+		this.broker = null;
+	    initialize();
+	    
+	}
+	
+	/**
+	 * Creates a new MQTT Protocol
+	 * 
+	 * @param broker broker of the protocol
+	 */
+	public SimpleMQTT(Port broker) {
+		this.broker = broker;
+		initialize();
+		
+	}
+	
+	/**
+	 * Initializes the different fields
+	 */
+	private void initialize() {
+		topics.add("/home/temperatureHot");
+	    topics.add("/home/doorOpen");
+	    topics.add("/home/lightOn");
+	    subs = new LinkedList<Port>();
+	    pubs = new LinkedList<Port>();
+	    pubSubs = new LinkedList<Port>();
+	}
+	
+	@Override
+	public Collection<Packet> generateNextPackets(Port port, long timestep, boolean packetLost) {
+		/**
+		 * Packets which will be generated
+		 */
+		LinkedList<Packet> returnPackets = new LinkedList<Packet>();
+		//Update all Timestamps of previous created Packets
+		for(Packet p: currentPackets){
+			p.setTimestamp(p.getTimestamp()+timestep);
+		}
+		//Add these packets to the return
+		returnPackets.addAll(currentPackets);
+		//remove packets from the old list
+		currentPackets.clear();
+		//Clear deleted connections
+		deletedConnectionLinks.clear();
+		//Return termination packets
+		if(port==null)return returnPackets;
+		
+		/**
+		 * Update the lastTime the port was triggered
+		 */
+		port.setLastTrigger(timestep);
+		/**
+		 * if port null, skip this step
+		 */
+		if(broker==null)return returnPackets;
+		
+		/**
+		 * Generate new Packets regarding to their class
+		 */
+		if(port==broker){
+			//Broker should not send new packages, without new messages
+			//But could perform some Ping request to random participants
+			Collection<Port> devices = getDevices();
+			devices.remove(port);
+			Port dest = null;
+			java.util.Iterator<Port> it = devices.iterator();
+			for(int i=0; i<(Math.random()*devices.size())&&it.hasNext();i++){
+				dest = it.next();
+			}
+			if(dest != null){
+				returnPackets.add(new MQTT_packet(MQTT_packet.PINGREQ, timestep, port, dest));
+				/**
+				 * Delay to the destination
+				 */
+				long delayBrokerDest = broker.getTransmissionDelayTo(dest);
+				if(dest.getStatus()!=Port.CLOSED && delayBrokerDest!=Long.MAX_VALUE)
+					returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP, timestep+delayBrokerDest+dest.getJitter()+dest.getResponseTime(), dest, port));
+			}
+		}
+		if(subs.contains(port)||pubSubs.contains(port)){
+			
+			//Subs can either subscribe to topics or unsubscribe
+			/**
+			 * Topics, the SmartDevice is subscribed to
+			 */
+			LinkedList<String> tops= subbedTopics.get(port);
+			
+			/**
+			 * Topic which should be subscribed or unsubscribed
+			 */
+			String newTopic;
+			//Subscribe if no subscriptions so far or not subscribed to all, with a probability of70%
+			if(tops.size()==0||(tops.size()!=topics.size()&&Math.random()<0.7)){
+				//Forced Subscribe
+				LinkedList<String> available = new LinkedList<String>();
+				available.addAll(topics);
+				available.removeAll(tops);
+				
+				newTopic = available.get((int) Math.floor(Math.random()*available.size()));
+				returnPackets.add(new MQTT_packet(MQTT_packet.SUBSCRIBE, timestep, port, broker, "topic:"+newTopic));
+				
+				/**
+				 * Delay to the broker
+				 */
+				long delayPortToBroker = port.getTransmissionDelayTo(broker);
+				
+				if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
+					timestep+=broker.getResponseTime();
+					returnPackets.add(new MQTT_packet(MQTT_packet.SUBACK, timestep+delayPortToBroker, broker, port));
+					tops.add(newTopic);
+				}
+			}
+			else if(tops.size()==topics.size()){
+				//Forced Unsubscribe
+				newTopic = tops.get((int) Math.floor(Math.random()*tops.size()));
+				returnPackets.add(new MQTT_packet(MQTT_packet.UNSUBSCRIBE, timestep, port, broker, "topic:"+newTopic));
+				/**
+				 * Delay to the broker
+				 */
+				long delayPortToBroker = port.getTransmissionDelayTo(broker);
+				
+				if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
+					timestep+=broker.getResponseTime();
+					returnPackets.add(new MQTT_packet(MQTT_packet.UNSUBACK, timestep+delayPortToBroker, broker, port));
+					tops.remove(newTopic);
+				}
+			}
+		}
+		if(pubs.contains(port)||pubSubs.contains(port)&&Math.random()<0.3){
+			String newTopic = topics.get((int) Math.floor(Math.random()*topics.size()));
+			/**
+			 * Message to be published (Should be further specialized by a Sensor Device) 
+			 */
+			String msg = "Topic:"+newTopic+":"+(Math.random()<0.5?"true":"false");
+			returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, port, broker, msg));
+			
+			/**
+			 * Delay to the broker
+			 */
+			long delayPortToBroker = port.getTransmissionDelayTo(broker);
+			//Publish to Subscribers
+			//Should be be improved to just notify Subs that are subscribed to the topic
+			if(broker.getStatus()!=Port.CLOSED && delayPortToBroker!=Long.MAX_VALUE){
+				//Response
+				timestep+=broker.getResponseTime()+delayPortToBroker;
+				returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep, broker, port));
+				
+				for(Port p:subs){
+					if(!subbedTopics.get(p).contains(newTopic))continue;//Skip unsubbed ports
+					/**
+					 * Delay broker to subscriber
+					 */
+					long delayBrokerToSub = broker.getTransmissionDelayTo(p);
+					timestep+=broker.getResponseTime();
+					returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
+					if(p.getStatus()!=Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE)
+						returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep+p.getResponseTime(), p, broker));
+				}
+				for(Port p:pubSubs){
+					if(!subbedTopics.get(p).contains(newTopic))continue;//skip unsubbed ports
+					timestep+=broker.getResponseTime();
+					/**
+					 * Delay broker to subscriber
+					 */
+					long delayBrokerToSub = broker.getTransmissionDelayTo(p);
+					returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
+					if(p.getStatus()!=Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE)
+						returnPackets.add(new MQTT_packet(MQTT_packet.PUBACK, timestep+p.getResponseTime(), p, broker));
+				}
+			}
+		}
+		if(Math.random() < 0.05 && port != broker){
+			returnPackets.add(new MQTT_packet(MQTT_packet.PINGREQ, timestep, port, broker));
+			/**
+			 * Delay broker to subscriber
+			 */
+			long delayPortToBroker = port.getTransmissionDelayTo(broker);
+			if(broker.getStatus()!=Port.CLOSED && delayPortToBroker != Long.MAX_VALUE)
+				returnPackets.add(new MQTT_packet(MQTT_packet.PINGRESP, timestep+delayPortToBroker+broker.getResponseTime(), broker, port));
+		}
+		return returnPackets;
+	}
+
+	@Override
+	public int getNumberOfRoles() {
+		return 4;
+	}
+
+	@Override
+	public String[] getRoles() {
+		// PublisherSubscriber is Publisher as well as Subscriber
+		return new String[] { "Broker", "PublisherSubscriber", "Publisher", "Subscriber" };
+	}
+
+	@Override
+	public Collection<Port> getDevicesWithRole(int role) {
+		switch (role) {
+		case 0:
+			return new LinkedList<Port>(Arrays.asList(broker));
+		case 1:
+			return pubSubs;
+		case 2:
+			return pubs;
+		case 3:
+			return subs;
+
+		default:
+			return null;
+		}
+	}
+
+	@Override
+	public boolean addDeviceOfRole(Port device, int role) {
+		/*
+		 * First device has to be the Broker 
+		 */
+		if (broker==null) {
+			if (role == 0) {
+				broker = device;
+				updateBrokerOnDeletedConnections(null);
+				return true;
+			} else {
+				return false;
+			}
+		}
+		switch (role) {
+		case 0:
+			//Just one broker allowed.
+			return false;
+		case 1:
+			pubSubs.add(device);
+			subbedTopics.putIfAbsent(device, new LinkedList<String>());
+			break;
+		case 2:
+			pubs.add(device);
+			break;
+		case 3:
+			subs.add(device);
+			subbedTopics.putIfAbsent(device, new LinkedList<String>());
+			break;
+		default:
+			// invalid role
+			return false;
+		}
+		// Create packets for the connecting Client
+		currentPackets.add(new MQTT_packet(MQTT_packet.CONNECT, currentPackets.size()/2, device, broker));
+		currentPackets.add(new MQTT_packet(MQTT_packet.CONNACK, currentPackets.size()/2+1, broker, device));
+		return true;
+	}
+
+	@Override
+	public void removeDevice(Port device) {
+		/**
+		 * true if the device was removed
+		 */
+		boolean removedDevice=false;
+		if (broker == device){
+			broker = null;
+			deletedConnectionLinks.add(new Pair<Port, Port>(new Port(device.getOwner(), (short)-1), deletedBrokerPort));
+			updateBrokerOnDeletedConnections(device);
+		}
+		removedDevice|=pubSubs.remove(device);
+		removedDevice|=subs.remove(device);
+		removedDevice|=pubs.remove(device);
+		//Remove Port from topics and clear its list
+		LinkedList<String> oldTopics = subbedTopics.remove(device);
+		if(oldTopics!=null)oldTopics.clear();
+		if(removedDevice){
+			if(broker == null){
+				deletedConnectionLinks.add(new Pair<Port, Port>(deletedBrokerPort,device));
+			}else{
+				deletedConnectionLinks.add(new Pair<Port, Port>(broker, device));
+				//If not the broker and device was removed -> disconnect
+				currentPackets.add(new MQTT_packet(MQTT_packet.DISCONNECT, currentPackets.size()/2, device, broker));
+			}
+		}
+	}
+	
+	public void addTopic(String topic){
+		topics.add(topic);
+	}
+
+	@Override
+	public String getName() {
+		return "SimpleMQTT";
+	}
+	
+	@Override
+	public int getRoleOfDevice(Port device){
+		if(device == null)
+			return -1;
+		if(device == broker)
+			return 0;
+		if(pubSubs.contains(device))
+			return 1;
+		if(pubs.contains(device))
+			return 2;
+		if(subs.contains(device))
+			return 3;
+		return -1;
+	}
+	
+	@Override
+	public Collection<Port> getDevices(){
+		LinkedList<Port> returnDevices = new LinkedList<Port>();
+		if(broker!=null)
+			returnDevices.add(broker);
+		returnDevices.addAll(pubSubs);
+		returnDevices.addAll(pubs);
+		returnDevices.addAll(subs);
+		return returnDevices;
+	}
+	
+	@Override
+	public byte getTopologyType() {
+		return STAR;
+	}
+	
+	@Override
+	public Collection<Pair<Port,Port>> getTopology(){
+		LinkedList<Pair<Port,Port>> topology = new LinkedList<Pair<Port,Port>>();
+		Port center = broker;
+		calcDeletedBrokerPosition();
+		if(broker==null)
+			center = new Port(deletedBroker, (short)-1);
+		for(Port p: pubSubs)
+			topology.add(new Pair<Port, Port>(center, p));
+		for(Port p: pubs)
+			topology.add(new Pair<Port, Port>(center, p));
+		for(Port p: subs)
+			topology.add(new Pair<Port, Port>(center, p));
+		return topology;
+	}
+
+	@Override
+	public Collection<Pair<Port, Port>> getDeletedTopology() {
+		calcDeletedBrokerPosition();
+		return deletedConnectionLinks;
+	}
+	
+	/**
+	 * Calculate and update the position of the deleted Broker
+	 */
+	private void calcDeletedBrokerPosition(){
+		if(broker == null){
+			int x = 0, y = 0, noP = 0;
+			for(Port p: getDevices()){
+				if(p!=null && p.getOwner()!=null){
+					x += p.getOwner().getX();
+					y += p.getOwner().getY();
+					noP++;
+				}
+			}
+			if(noP==0)
+				return;
+			deletedBroker.setX(((int)(x*1.0)/noP));
+			deletedBroker.setY(((int)(y*1.0)/noP));
+		}
+	}
+	
+	/**
+	 * Update the broker port on the deleted Connections
+	 * 
+	 * @param device old broker
+	 */
+	private void updateBrokerOnDeletedConnections(Port device){
+		for(Pair<Port, Port> p: deletedConnectionLinks){
+			if(broker == null){
+				if(p.getLeft() == device)
+					p.setLeft(deletedBrokerPort);
+				if(p.getRight() == device)
+					p.setRight(deletedBrokerPort);
+			}else{
+				if(p.getLeft() == deletedBrokerPort)
+					p.setLeft(broker);
+				if(p.getRight() == deletedBrokerPort)
+					p.setRight(broker);
+				
+			}
+		}
+	}
+
+}

+ 60 - 8
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/MenuBarNetworkExamples.java

@@ -22,6 +22,10 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollectorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollectorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensorDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.CountingMetric;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.Manipulation_RandomMove;
@@ -265,7 +269,8 @@ public class MenuBarNetworkExamples extends JMenu{
 	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
 	 */
 	private void initializeMQTTTest(){
-		Link link = new SimpleLink("WIFI");
+		SimpleLink link = new SimpleLink("WIFI");
+		link.setFixedDelay(5);
 		
 		SmartDevice broker = new SmartDevice("MQTT-Broker");
 		broker.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
@@ -292,10 +297,12 @@ public class MenuBarNetworkExamples extends JMenu{
 		link.addConnection(con);
 		networkController.addConnection(con);
 		
-		SmartDevice A = null, B = null, C = null;
-		Port aP,bP,cP;
+		SmartDevice A = null, A1 = null, A2 = null, B = null, C = null;
+		Port aP,a1P,a2P,bP,cP;
 		for(int i = 0; i<3; i++){
-			A = new SmartDevice("SmartTV"+i+"(Sub)");		
+			FloatSensorDevice aS = new FloatSensorDevice("SmartThermostat"+i+"(Pub)");	
+			aS.setFSinfoName("room"+i+"/temperature");
+			A=aS;
 			A.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			A.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			link.addDevice(A);
@@ -307,15 +314,59 @@ public class MenuBarNetworkExamples extends JMenu{
 			aP.setJitter((short) (Math.random()*50));
 			aP.setStatus(Port.SENDING);
 			aP.setConnection(con);
-			protocol.addDeviceOfRole(aP, 3);
+			protocol.addDeviceOfRole(aP, 2);
 			con.addSmartDevice(aP);
 			A.addPort(aP);
 			
 			networkController.addSmartDevice(A);
 			
 			
+			FloatCollectorDevice aS1 = new FloatCollectorDevice("SmartAirCondition"+i+"(Sub)");	
+			aS1.setFCinfoName("room"+i+"/temperature");
+			A1=aS1;
+			A1.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A1.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(A1);
+			A1.addLink(link);
+			
+			a1P = new Port(A1,((short) (3*i+1)));
+			a1P.setLastTrigger(0);
+			a1P.setTriggerInterval(100+(int)(Math.random()*900));
+			a1P.setJitter((short) (Math.random()*50));
+			a1P.setStatus(Port.SENDING);
+			a1P.setConnection(con);
+			protocol.addDeviceOfRole(a1P, 3);
+			con.addSmartDevice(a1P);
+			A1.addPort(a1P);
+			
+			networkController.addSmartDevice(A1);
+			
+			
+			FloatCollectorDevice aS2 = new FloatCollectorDevice("SmartHeater"+i+"(Sub)");	
+			aS2.setFCinfoName("room"+i+"/temperature");
+			A2=aS2;
+			A2.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A2.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(A2);
+			A2.addLink(link);
+			
+			a2P = new Port(A2,((short) (3*i+1)));
+			a2P.setLastTrigger(0);
+			a2P.setTriggerInterval(100+(int)(Math.random()*900));
+			a2P.setJitter((short) (Math.random()*50));
+			a2P.setStatus(Port.SENDING);
+			a2P.setConnection(con);
+			protocol.addDeviceOfRole(a2P, 3);
+			con.addSmartDevice(a2P);
+			A2.addPort(a2P);
+			
+			networkController.addSmartDevice(A2);
+			
+			
+			
 			
-			B = new SmartDevice("SmartDoor"+i+"(Pub)");
+			B = new BoolSensorDevice("SmartDoor"+i+"(Pub)");
+			((BoolSensorDevice)B).setBSinfoName("room"+i+"/DoorOpen");
 			B.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			B.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			link.addDevice(B);
@@ -333,7 +384,8 @@ public class MenuBarNetworkExamples extends JMenu{
 			
 			networkController.addSmartDevice(B);
 			
-			C = new SmartDevice("SmartLight"+i+"(Pub,Sub)");
+			C = new BoolCollectorDevice("SmartDoorStatusLight"+i+"(Sub)");
+			((BoolCollectorDevice)C).setBCinfoName("room"+i+"/DoorOpen");
 			C.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			C.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
 			link.addDevice(C);
@@ -345,7 +397,7 @@ public class MenuBarNetworkExamples extends JMenu{
 			cP.setJitter((short) (Math.random()*50));
 			cP.setStatus(Port.SENDING);
 			cP.setConnection(con);
-			protocol.addDeviceOfRole(cP, 1);
+			protocol.addDeviceOfRole(cP, 3);
 			con.addSmartDevice(cP);
 			C.addPort(cP);