|
@@ -1,8 +1,11 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Pair;
|
|
|
+
|
|
|
|
|
|
* Protocol according to which the packages are created. Can contain different
|
|
|
* Roles and multiple participating SmartDevice(Port)s.
|
|
@@ -10,6 +13,23 @@ import java.util.LinkedList;
|
|
|
* @author Andreas T. Meyer-Berg
|
|
|
*/
|
|
|
public interface Protocol {
|
|
|
+
|
|
|
+ * Topology options
|
|
|
+ */
|
|
|
+
|
|
|
+ * Every Port/Device is connected to every other Port/Device
|
|
|
+ */
|
|
|
+ public static final byte FULLY_CONNECTED = 0;
|
|
|
+
|
|
|
+
|
|
|
+ * Every Port/Device is connected to the Device of Role 0. (Has to be exactly one device of Role 0)
|
|
|
+ */
|
|
|
+ public static final byte STAR = 1;
|
|
|
+
|
|
|
+
|
|
|
+ * Custom topology, getTopology has to be overwritten.
|
|
|
+ */
|
|
|
+ public static final byte CUSTOM = 127;
|
|
|
|
|
|
|
|
|
* Generates the next packets<br>
|
|
@@ -106,4 +126,53 @@ public interface Protocol {
|
|
|
* @return name of the protocol
|
|
|
*/
|
|
|
public String getName();
|
|
|
+
|
|
|
+
|
|
|
+ * Returns the topology of this protocol as specified by the static final protocol fields.
|
|
|
+ *
|
|
|
+ * @return used topology
|
|
|
+ */
|
|
|
+ public default byte getTopologyType() {
|
|
|
+ return FULLY_CONNECTED;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Returns the different connections of this protocol, how the Ports are connected and transmitting packets.
|
|
|
+ *
|
|
|
+ * @return Connections
|
|
|
+ */
|
|
|
+ public default Collection<Pair<Port,Port>> getTopology(){
|
|
|
+ LinkedList<Pair<Port,Port>> topology = new LinkedList<Pair<Port,Port>>();
|
|
|
+ switch (getTopologyType()){
|
|
|
+ case STAR:
|
|
|
+ Collection<Port> devices = getDevicesWithRole(0);
|
|
|
+ Port router = null;
|
|
|
+ if(devices.size() == 1)
|
|
|
+ router = devices.iterator().next();
|
|
|
+ for (Iterator<Port> iterator = getDevices().iterator(); iterator.hasNext();) {
|
|
|
+ Port right = (Port) (iterator.next());
|
|
|
+ if(router != right)
|
|
|
+ topology.add(new Pair<Port, Port>(router, right));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case FULLY_CONNECTED:
|
|
|
+ case CUSTOM:
|
|
|
+ default:
|
|
|
+ for (Iterator<Port> iterator = getDevices().iterator(); iterator.hasNext();) {
|
|
|
+ Port left = (Port) (iterator.next());
|
|
|
+ boolean samePosition = false;
|
|
|
+ for(Iterator<Port> iterator2 = getDevices().iterator(); iterator2.hasNext();){
|
|
|
+ Port right = iterator2.next();
|
|
|
+ if(!samePosition){
|
|
|
+ if(left==right)
|
|
|
+ samePosition=true;
|
|
|
+ }else{
|
|
|
+ topology.add(new Pair<Port, Port>(left, right));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return topology;
|
|
|
+ }
|
|
|
}
|