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
AbstractModel getModel(int segID, ParameterType type, Boolean isUpload) {
Integer segmentID = new Integer(segID);
Direction dir = Direction.DOWNLOAD;
if (isUpload) {
dir = Direction.UPLOAD;
}
// Check if type exists
if (!this.models.containsKey(type)) {
throw new ConfigurationException(
"No Model is defined for " + type + ".");
}
if (!this.models.get(type).containsKey(segmentID)) {
segmentID = DEFAULT_SEGMENT_ID;
// Check if there is a specific model
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)) {
throw new ConfigurationException("No Model is defined for Type "
+ type + " and Segment ID " + segmentID + ".");
// Check if there is a BOTH model in this segment
if(this.models.get(type).containsKey(segmentID) && this.models.get(type).get(segmentID).containsKey(Direction.BOTH)) {
return this.models.get(type).get(segmentID).get(Direction.BOTH);
}
Direction dir = Direction.DOWNLOAD;
if (isUpload) {
dir = Direction.UPLOAD;
// 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)) {
return this.models.get(type).get(DEFAULT_SEGMENT_ID).get(dir);
}
if (!this.models.get(type).get(segmentID).containsKey(dir)) {
dir = Direction.BOTH;
// Check if there is a default BOTH model
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(
"No Model is defined for Type " + type + ", Segment ID "
+ segmentID + " and Direction " + dir + ".");
}
return this.models.get(type).get(segmentID).get(dir);
throw new ConfigurationException(
"No Model is defined for Type " + type + ", Segment ID "
+ segmentID + " and Direction " + dir + ".");
}
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;
// Other storage
private final int segment;
private boolean isAvailable = true;
private HashSet<MacAddress> 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) {
......@@ -227,7 +243,8 @@ public class ModelBasedSegmentDatabase
@Override
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) {
return OVERLOAD_DROPRATE;
}
......@@ -257,7 +274,8 @@ public class ModelBasedSegmentDatabase
@Override
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) {
return OVERLOAD_BANDWIDTH;
}
......@@ -280,7 +298,7 @@ public class ModelBasedSegmentDatabase
this.isAvailable = isAvailable;
}
/**
/**
* Recalculate every metric when a host leaves or enters
*/
private void calc() {
......@@ -298,7 +316,8 @@ public class ModelBasedSegmentDatabase
if (bandDown <= THRESHOLD_BANDWIDTH
|| bandUp <= THRESHOLD_BANDWIDTH) {
overload = true;
System.out.println("Bandwidth is overloaded in Segment: " + getSegmentID());
System.out.println("Bandwidth is overloaded in Segment: "
+ getSegmentID());
}
// Calc Latency
......@@ -309,7 +328,8 @@ public class ModelBasedSegmentDatabase
if (latUp >= THRESHOLD_LATENCY || latDown >= THRESHOLD_LATENCY) {
overload = true;
System.out.println("Latency is overloaded in Segment: " + getSegmentID());
System.out.println(
"Latency is overloaded in Segment: " + getSegmentID());
}
// Calc Droprate
......@@ -321,7 +341,8 @@ public class ModelBasedSegmentDatabase
if (dropUp >= THRESHOLD_DROPRATE
|| dropDown >= THRESHOLD_DROPRATE) {
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