diff --git a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java index 111c39dc67448a18089b07a7d5434fec30f0a8a2..5afd81dff301d9c99866dbc36e3256bbb19bb873 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java @@ -521,8 +521,9 @@ public class FiveGTopologyView extends AbstractTopologyView { public long getBandwidth(boolean isBroadcast) { assert (apLinkData != null && supportsAccessPoints) || apLinkData == null; - return apLinkData != null ? apLinkData.getBandwidth(isUpload) + long tmp = apLinkData != null ? apLinkData.getBandwidth(isUpload) : linkData.getBandwidth(isUpload); + return tmp; } @Override diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java index 0ad7843a021c8a7e5e717f70ee3affc5674598ef..bf67bf7a87000f8ee9d03164ef574421d3deb96f 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java @@ -48,8 +48,17 @@ public class ModelBasedSegmentDatabase return new ModelBasedEntry(segmentID); } + /** + * Add a model to Database + * + * @param model + * the model to add + */ public void setModel(AbstractModel model) { + // Enable debugging model.debug(); + + // Check if model is valid ParameterType type = model.getParameterType(); if (type == null) { throw new ConfigurationException( @@ -64,11 +73,20 @@ public class ModelBasedSegmentDatabase Integer segmentID = new Integer(model.getSegmentID()); + // Check if there is no contradicting model if (models.containsKey(type)) { // There is already this Type if (models.get(type).containsKey(segmentID)) { // There is already this SegID - if (models.get(type).get(segmentID).containsKey(dir) || (models.get(type).get(segmentID).containsKey(Direction.BOTH) && (dir.equals(Direction.DOWNLOAD) || dir.equals(Direction.UPLOAD)))|| (dir.equals(Direction.BOTH) && (models.get(type).get(segmentID).containsKey(Direction.DOWNLOAD) || models.get(type).get(segmentID).containsKey(Direction.UPLOAD)))) { + if (models.get(type).get(segmentID).containsKey(dir) + || (models.get(type).get(segmentID) + .containsKey(Direction.BOTH) + && (dir.equals(Direction.DOWNLOAD) + || dir.equals(Direction.UPLOAD))) + || (dir.equals(Direction.BOTH) && (models.get(type) + .get(segmentID).containsKey(Direction.DOWNLOAD) + || models.get(type).get(segmentID) + .containsKey(Direction.UPLOAD)))) { // There is already a model defined throw new ConfigurationException( "Conflicting Models for SegmentID " + segmentID @@ -99,10 +117,19 @@ public class ModelBasedSegmentDatabase models.put(type, tmp2); } - - System.out.println(models.toString()); } + /** + * Get the model for the specific combination + * + * @param segID + * The SegmentID to get the model for + * @param type + * The Type of the Parameter + * @param isUpload + * Is it a Up or Downlink + * @return The Model for the given segment + */ AbstractModel getModel(int segID, ParameterType type, Boolean isUpload) { Integer segmentID = new Integer(segID); @@ -141,26 +168,38 @@ public class ModelBasedSegmentDatabase } public class ModelBasedEntry implements FiveGTopologyDatabase.Entry { - + + // How is a overload defined private final long OVERLOAD_LATENCY = 9999 * Time.MILLISECOND; private final long OVERLOAD_BANDWIDTH = (long) 0.1; private final double OVERLOAD_DROPRATE = 1; - + + // When is a node considered overloaded private final long THRESHOLD_LATENCY = Time.SECOND; private final long THRESHOLD_BANDWIDTH = 10; private final double THRESHOLD_DROPRATE = 1; - - private HashMap> currentValues = new HashMap<>(); + // Other storage private final int segment; - private boolean isAvailable = true; - private HashSet hostsInSegment = new HashSet<>(); - + private boolean overload; + + // The current metrics of this segment + private long bandUp; + private long bandDown; + private long latUp; + private long latDown; + private double dropUp; + private double dropDown; + + /** + * Create a new entry for the given segment + * @param segment + */ public ModelBasedEntry(int segment) { this.segment = segment; - evaluateAll(); + calc(); } @Override @@ -168,40 +207,66 @@ public class ModelBasedSegmentDatabase return segment; } + /** + * A host leaves this segment + */ public void onHostLeavesSegment(MacAddress hostAddr) { + // Remove MAC from current users this.hostsInSegment.remove(hostAddr); - evaluateAll(); + calc(); } + /** + * A host enters this segment + */ public void onHostEntersSegment(MacAddress hostAddr) { + // Add MAC to current users this.hostsInSegment.add(hostAddr); - evaluateAll(); + calc(); } @Override public double getDropProbability(boolean isUpload) { - if(isUpload) { - return this.currentValues.get(ParameterType.DROPRATE).get(Direction.UPLOAD); + // Segment is overloaded or not available return overloaded drop probability + if (!isAvailable || overload) { + return OVERLOAD_DROPRATE; + } + + // Return calculated drop probability + if (isUpload) { + return dropUp; } else { - return this.currentValues.get(ParameterType.DROPRATE).get(Direction.DOWNLOAD); + return dropDown; } } @Override public long getLatency(boolean isUpload) { - if(isUpload) { - return this.currentValues.get(ParameterType.LATENCY).get(Direction.UPLOAD); + // Segment is overloaded or not available return overloaded latency + if (!isAvailable || overload) { + return OVERLOAD_LATENCY; + } + + // Return calculated latency + if (isUpload) { + return latUp; } else { - return this.currentValues.get(ParameterType.LATENCY).get(Direction.DOWNLOAD); + return latDown; } } @Override public long getBandwidth(boolean isUpload) { - if(isUpload) { - return this.currentValues.get(ParameterType.BANDWIDTH).get(Direction.UPLOAD); + // Segment is overloaded or not available return overloaded bandwidth + if (!isAvailable || overload) { + return OVERLOAD_BANDWIDTH; + } + + // Return calculated bandwidth + if (isUpload) { + return bandUp; } else { - return this.currentValues.get(ParameterType.BANDWIDTH).get(Direction.DOWNLOAD); + return bandDown; } } @@ -214,63 +279,50 @@ public class ModelBasedSegmentDatabase public void setAvailability(boolean isAvailable) { this.isAvailable = isAvailable; } - - private void evaluateAll() { - int currentUsers = this.hostsInSegment.size(); + + /** + * Recalculate every metric when a host leaves or enters + */ + private void calc() { + int users = this.hostsInSegment.size(); + + // Assume not overloaded + this.overload = false; // Calc Bandwidth - long bandUp = getModel(getSegmentID(), ParameterType.BANDWIDTH, true).getLong(currentUsers); - long bandDown = getModel(getSegmentID(), ParameterType.BANDWIDTH, true).getLong(currentUsers); - + this.bandUp = getModel(getSegmentID(), ParameterType.BANDWIDTH, + true).getLong(users); + this.bandDown = getModel(getSegmentID(), ParameterType.BANDWIDTH, + false).getLong(users); + + if (bandDown <= THRESHOLD_BANDWIDTH + || bandUp <= THRESHOLD_BANDWIDTH) { + overload = true; + System.out.println("Bandwidth is overloaded in Segment: " + getSegmentID()); + } + // Calc Latency - long latencyUp = getModel(getSegmentID(), ParameterType.LATENCY, true).getLong(currentUsers); - long latencyDown = getModel(getSegmentID(), ParameterType.LATENCY, true).getLong(currentUsers); - - // Calc DropRate - double droprateUp = getModel(getSegmentID(), ParameterType.DROPRATE, true).getLong(currentUsers); - double droprateDown = getModel(getSegmentID(), ParameterType.DROPRATE, true).getLong(currentUsers); - - // One Value is above threshold -> everyone is down - if(!isAvailable || bandUp <= THRESHOLD_BANDWIDTH || bandDown <= THRESHOLD_BANDWIDTH || latencyUp >= THRESHOLD_LATENCY || latencyDown >= THRESHOLD_LATENCY || droprateDown >= THRESHOLD_DROPRATE || droprateUp >= THRESHOLD_DROPRATE) { - //System.out.println("Overload!"); - HashMap tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, OVERLOAD_BANDWIDTH); - tmp.put(Direction.UPLOAD, OVERLOAD_BANDWIDTH); - - this.currentValues.put(ParameterType.BANDWIDTH, tmp); - - tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, OVERLOAD_LATENCY); - tmp.put(Direction.UPLOAD, OVERLOAD_LATENCY); - - this.currentValues.put(ParameterType.LATENCY, tmp); - - tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, (long) OVERLOAD_DROPRATE); - tmp.put(Direction.UPLOAD, (long) OVERLOAD_DROPRATE); - - this.currentValues.put(ParameterType.DROPRATE, tmp); - } else { - //System.out.println("Everything ok!"); - HashMap tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, bandDown); - tmp.put(Direction.UPLOAD, bandUp); - - this.currentValues.put(ParameterType.BANDWIDTH, tmp); - - tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, latencyDown); - tmp.put(Direction.UPLOAD, latencyUp); - - this.currentValues.put(ParameterType.LATENCY, tmp); - - tmp = new HashMap<>(2); - tmp.put(Direction.DOWNLOAD, (long) droprateDown); - tmp.put(Direction.UPLOAD, (long) droprateUp); - - this.currentValues.put(ParameterType.DROPRATE, tmp); + this.latUp = getModel(getSegmentID(), ParameterType.LATENCY, true) + .getLong(users); + this.latDown = getModel(getSegmentID(), ParameterType.LATENCY, + false).getLong(users); + + if (latUp >= THRESHOLD_LATENCY || latDown >= THRESHOLD_LATENCY) { + overload = true; + System.out.println("Latency is overloaded in Segment: " + getSegmentID()); + } + + // Calc Droprate + this.dropUp = getModel(getSegmentID(), ParameterType.DROPRATE, true) + .getDouble(users); + this.dropDown = getModel(getSegmentID(), ParameterType.DROPRATE, + false).getDouble(users); + + if (dropUp >= THRESHOLD_DROPRATE + || dropDown >= THRESHOLD_DROPRATE) { + overload = true; + System.out.println("Droprate is overloaded in Segment: " + getSegmentID()); } - //System.out.println(this.currentValues); } } } diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java index 48cdf065594ccef6d09ebc3102f59248aa6c3665..26fe6e9ec74970c3b04b0dda9b86c4d6c98b201a 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/AbstractModel.java @@ -26,12 +26,13 @@ import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.Graph; import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.ParameterType; public abstract class AbstractModel { + + // Storage private int segmentID = -1; - private ParameterType type; - private Direction dir = Direction.BOTH; + // Is debug enabled for this model private boolean debug = false; public void setSegmentID(int segmentid) { @@ -43,8 +44,13 @@ public abstract class AbstractModel { return this.segmentID; } + /** + * Set the parameter type {@link ParameterType} + * @param param + */ public void setParameterType(String param) { param = param.toUpperCase(); + // Check if type is valid try { this.type = ParameterType.valueOf(param); } catch (IllegalArgumentException e) { @@ -63,6 +69,10 @@ public abstract class AbstractModel { return type; } + /** + * Set the direction of model {@link Direction} + * @param param + */ public void setDirection(String param) { param = param.toUpperCase(); try { @@ -83,8 +93,12 @@ public abstract class AbstractModel { return dir; } + /** + * Enable debugging + * @param debug + */ public void setDebug(boolean debug) { - this.debug = true; + this.debug = debug; } public boolean getDebug() { @@ -95,8 +109,11 @@ public abstract class AbstractModel { public abstract double getDouble(int users); + /** + * Debug this model + */ public void debug() { - Graph test = new Graph("Debug Graph"); + Graph test = new Graph(); test.setModel(this); } } diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ConstantModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ConstantModel.java new file mode 100644 index 0000000000000000000000000000000000000000..b7ecb9f93012f55345185ab41d770ddf0a732fda --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ConstantModel.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.views.fiveg.models; + +/** + * A Constant Model which return always the constant value C + * c(u) = C + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ +public class ConstantModel extends AbstractModel { + + private long c = 0; + + public void setC(long c) { + this.c = c; + } + + @Override + public long getLong(int users) { + return this.c; + } + + @Override + public double getDouble(int users) { + return this.c; + } + + public String toString() { + return "Constant Model: c(u) = " + c; + } +} diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/CutOffModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/CutOffModel.java index 1699d573691d9f4d6502163bec1eb771df1abc52..8ae1a8d94ece401d003bb1a18165d2129c716131 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/CutOffModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/CutOffModel.java @@ -19,7 +19,12 @@ */ package de.tud.kom.p2psim.impl.topology.views.fiveg.models; - +/** + * A cut off model based on the heaviside step function. + * cut(u) = a * θ(c * u + d) + b + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public class CutOffModel extends AbstractModel { private long a = 1; diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ExponentialModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ExponentialModel.java index 27b98616b9f6eb87ea99d001c3f44be1c793010a..330b5638f0c85d62aced2ea3ffdc812735931d59 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ExponentialModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/ExponentialModel.java @@ -20,6 +20,12 @@ package de.tud.kom.p2psim.impl.topology.views.fiveg.models; +/** + * An exponential model + * exp(u) = a * e^(c * u + d) + b + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public class ExponentialModel extends AbstractModel { // exp(u) = a * e ^(c * u + d) + b diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LinearModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LinearModel.java index 89aebab9cbf7a270fa33b191c1881e50c2d4005b..0ce01b8e2b3d3dcca7b9f0d7c0bacd947ae016e8 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LinearModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LinearModel.java @@ -20,6 +20,12 @@ package de.tud.kom.p2psim.impl.topology.views.fiveg.models; +/** + * Linear Model + * lin(u) = a * u + b + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public class LinearModel extends AbstractModel { private long a = 0; @@ -44,7 +50,7 @@ public class LinearModel extends AbstractModel { } public String toString() { - return "Linear Model: f(u) = " + a + " * u + " + b; + return "Linear Model: lin(u) = " + a + " * u + " + b; } } diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LogarithmicModel.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LogarithmicModel.java index 629d3dee9c0b425573af18090bab59faa412eba1..bb991940ecc7dbfa9e4ca333d5037f713d5b883b 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LogarithmicModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/models/LogarithmicModel.java @@ -20,10 +20,14 @@ package de.tud.kom.p2psim.impl.topology.views.fiveg.models; +/** + * Logarithmic model + * log(u) = a * ln(c * u + d) + b + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public class LogarithmicModel extends AbstractModel { - // log(u) = a * ln(c * u + d) + b - private long a = 1; private long b = 0; diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Direction.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Direction.java index f6dc07a3fb5e71bc802c06751de03c2d14089bca..e3c70fc7cce1ed1d49513e00174b289112dfd4fd 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Direction.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Direction.java @@ -20,6 +20,11 @@ package de.tud.kom.p2psim.impl.topology.views.fiveg.utils; +/** + * Enumeration for defining the direction (Up,Down or Both) for a model. + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public enum Direction { BOTH(), UPLOAD(), diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Graph.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Graph.java index 5514329141c998126b858d5fcc2105fcafbb4026..f86112e28f8eb6b5349de12f7080958a76864ebf 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Graph.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/Graph.java @@ -29,15 +29,22 @@ import org.jfree.ui.ApplicationFrame; import de.tud.kom.p2psim.impl.topology.views.fiveg.models.AbstractModel; +/** + * A simple graph for debugging the models + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public class Graph extends ApplicationFrame { - public Graph(String title) { - super(title); + public Graph() { + super("Debug Graph"); + // TODO: Schließen ohne simonstrator zu killen. } public void setModel(AbstractModel model) { if (model.getDebug()) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + // TODO: Get max users. for (int i = 0; i <= 500; i += 1) { System.out.println(model.getDouble(i)); dataset.addValue(model.getDouble(i), "Value", diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/ParameterType.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/ParameterType.java index fd70d7cbbf78b3527b8ad42f0f2f11a4b7f7e995..8f6ff984cf21e5d9fadbe71ec6fe4dcd6c1483d1 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/ParameterType.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/utils/ParameterType.java @@ -20,6 +20,11 @@ package de.tud.kom.p2psim.impl.topology.views.fiveg.utils; +/** + * Enumeration for defining the type (Bandwidth, Drop Rate, Latency) for a model. + * @author Marc Schiller + * @version 1.0, 15 Dec 2016 + */ public enum ParameterType { BANDWIDTH(), DROPRATE(),