Commit ded77519 authored by Marc Schiller's avatar Marc Schiller
Browse files

Fixed getModel() for specific combinations.

parent 3434115d
...@@ -133,68 +133,84 @@ public class ModelBasedSegmentDatabase ...@@ -133,68 +133,84 @@ public class ModelBasedSegmentDatabase
AbstractModel getModel(int segID, ParameterType type, Boolean isUpload) { AbstractModel getModel(int segID, ParameterType type, Boolean isUpload) {
Integer segmentID = new Integer(segID); Integer segmentID = new Integer(segID);
Direction dir = Direction.DOWNLOAD;
if (isUpload) {
dir = Direction.UPLOAD;
}
// Check if type exists
if (!this.models.containsKey(type)) { if (!this.models.containsKey(type)) {
throw new ConfigurationException( throw new ConfigurationException(
"No Model is defined for " + type + "."); "No Model is defined for " + type + ".");
} }
if (!this.models.get(type).containsKey(segmentID)) { // Check if there is a specific model
segmentID = DEFAULT_SEGMENT_ID; if(this.models.get(type).containsKey(segmentID) && this.models.get(type).get(segmentID).containsKey(dir)) {
return this.models.get(type).get(segmentID).get(dir);
} }
if (!this.models.get(type).containsKey(segmentID)) { // Check if there is a BOTH model in this segment
throw new ConfigurationException("No Model is defined for Type " if(this.models.get(type).containsKey(segmentID) && this.models.get(type).get(segmentID).containsKey(Direction.BOTH)) {
+ type + " and Segment ID " + segmentID + "."); return this.models.get(type).get(segmentID).get(Direction.BOTH);
} }
Direction dir = Direction.DOWNLOAD; // Check default model for specific model
if(this.models.get(type).containsKey(DEFAULT_SEGMENT_ID) && this.models.get(type).get(DEFAULT_SEGMENT_ID).containsKey(dir)) {
if (isUpload) { return this.models.get(type).get(DEFAULT_SEGMENT_ID).get(dir);
dir = Direction.UPLOAD;
} }
if (!this.models.get(type).get(segmentID).containsKey(dir)) { // Check if there is a default BOTH model
dir = Direction.BOTH; if(this.models.get(type).containsKey(DEFAULT_SEGMENT_ID) && this.models.get(type).get(DEFAULT_SEGMENT_ID).containsKey(Direction.BOTH)) {
return this.models.get(type).get(DEFAULT_SEGMENT_ID).get(Direction.BOTH);
} }
if (!this.models.get(type).get(segmentID).containsKey(dir)) {
throw new ConfigurationException( throw new ConfigurationException(
"No Model is defined for Type " + type + ", Segment ID " "No Model is defined for Type " + type + ", Segment ID "
+ segmentID + " and Direction " + dir + "."); + segmentID + " and Direction " + dir + ".");
} }
return this.models.get(type).get(segmentID).get(dir);
}
public class ModelBasedEntry implements FiveGTopologyDatabase.Entry { public class ModelBasedEntry implements FiveGTopologyDatabase.Entry {
// How is a overload defined // How is a overload defined
private final long OVERLOAD_LATENCY = 9999 * Time.MILLISECOND; private final long OVERLOAD_LATENCY = 9999 * Time.MILLISECOND;
private final long OVERLOAD_BANDWIDTH = (long) 0.1; private final long OVERLOAD_BANDWIDTH = (long) 0.1;
private final double OVERLOAD_DROPRATE = 1; private final double OVERLOAD_DROPRATE = 1;
// When is a node considered overloaded // When is a node considered overloaded
private final long THRESHOLD_LATENCY = Time.SECOND; private final long THRESHOLD_LATENCY = Time.SECOND;
private final long THRESHOLD_BANDWIDTH = 10; private final long THRESHOLD_BANDWIDTH = 10;
private final double THRESHOLD_DROPRATE = 1; private final double THRESHOLD_DROPRATE = 1;
// Other storage // Other storage
private final int segment; private final int segment;
private boolean isAvailable = true; private boolean isAvailable = true;
private HashSet<MacAddress> hostsInSegment = new HashSet<>(); private HashSet<MacAddress> hostsInSegment = new HashSet<>();
private boolean overload; private boolean overload;
// The current metrics of this segment // The current metrics of this segment
private long bandUp; private long bandUp;
private long bandDown; private long bandDown;
private long latUp; private long latUp;
private long latDown; private long latDown;
private double dropUp; private double dropUp;
private double dropDown; private double dropDown;
/** /**
* Create a new entry for the given segment * Create a new entry for the given segment
*
* @param segment * @param segment
*/ */
public ModelBasedEntry(int segment) { public ModelBasedEntry(int segment) {
...@@ -227,7 +243,8 @@ public class ModelBasedSegmentDatabase ...@@ -227,7 +243,8 @@ public class ModelBasedSegmentDatabase
@Override @Override
public double getDropProbability(boolean isUpload) { public double getDropProbability(boolean isUpload) {
// Segment is overloaded or not available return overloaded drop probability // Segment is overloaded or not available return overloaded drop
// probability
if (!isAvailable || overload) { if (!isAvailable || overload) {
return OVERLOAD_DROPRATE; return OVERLOAD_DROPRATE;
} }
...@@ -257,7 +274,8 @@ public class ModelBasedSegmentDatabase ...@@ -257,7 +274,8 @@ public class ModelBasedSegmentDatabase
@Override @Override
public long getBandwidth(boolean isUpload) { public long getBandwidth(boolean isUpload) {
// Segment is overloaded or not available return overloaded bandwidth // Segment is overloaded or not available return overloaded
// bandwidth
if (!isAvailable || overload) { if (!isAvailable || overload) {
return OVERLOAD_BANDWIDTH; return OVERLOAD_BANDWIDTH;
} }
...@@ -298,7 +316,8 @@ public class ModelBasedSegmentDatabase ...@@ -298,7 +316,8 @@ public class ModelBasedSegmentDatabase
if (bandDown <= THRESHOLD_BANDWIDTH if (bandDown <= THRESHOLD_BANDWIDTH
|| bandUp <= THRESHOLD_BANDWIDTH) { || bandUp <= THRESHOLD_BANDWIDTH) {
overload = true; overload = true;
System.out.println("Bandwidth is overloaded in Segment: " + getSegmentID()); System.out.println("Bandwidth is overloaded in Segment: "
+ getSegmentID());
} }
// Calc Latency // Calc Latency
...@@ -309,7 +328,8 @@ public class ModelBasedSegmentDatabase ...@@ -309,7 +328,8 @@ public class ModelBasedSegmentDatabase
if (latUp >= THRESHOLD_LATENCY || latDown >= THRESHOLD_LATENCY) { if (latUp >= THRESHOLD_LATENCY || latDown >= THRESHOLD_LATENCY) {
overload = true; overload = true;
System.out.println("Latency is overloaded in Segment: " + getSegmentID()); System.out.println(
"Latency is overloaded in Segment: " + getSegmentID());
} }
// Calc Droprate // Calc Droprate
...@@ -321,7 +341,8 @@ public class ModelBasedSegmentDatabase ...@@ -321,7 +341,8 @@ public class ModelBasedSegmentDatabase
if (dropUp >= THRESHOLD_DROPRATE if (dropUp >= THRESHOLD_DROPRATE
|| dropDown >= THRESHOLD_DROPRATE) { || dropDown >= THRESHOLD_DROPRATE) {
overload = true; overload = true;
System.out.println("Droprate is overloaded in Segment: " + getSegmentID()); System.out.println(
"Droprate is overloaded in Segment: " + getSegmentID());
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment