Commit 3dfacb41 authored by Clemens Krug's avatar Clemens Krug
Browse files

Add possibility of "dead" cells

+ Cells can be killed/shutdown by using the setConnectivity method on a FiveGTopologyDatabase entry.
+ Add visualisation for "dead" cells
+ Cells can be killed and resurrected by clicking on them in the visualisation.
parent 23c565fb
......@@ -124,7 +124,7 @@ public class DefaultLink implements Link {
* @return
*/
@Override
public final boolean isConnected() {
public boolean isConnected() {
return isConnected;
}
......
......@@ -325,7 +325,7 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
/**
* GroupIDs that act as clients and have access to access points.
*
* @param cloudletGroups
* @param accessPointGroups
*/
@SuppressWarnings("unchecked")
public void setAccessPointGroups(String[] accessPointGroups) {
......@@ -451,6 +451,8 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
@Override
public long getBandwidth(boolean isBroadcast) {
// if(!isConnected()) return 0;
assert (apLinkData != null && supportsAccessPoints)
|| apLinkData == null;
return apLinkData != null ? apLinkData.getBandwidth(isUpload)
......@@ -459,6 +461,8 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
@Override
public double getDropProbability() {
// if(!isConnected()) return 1;
assert (apLinkData != null && supportsAccessPoints)
|| apLinkData == null;
return apLinkData != null ? apLinkData.getDropProbability(isUpload)
......@@ -467,12 +471,22 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
@Override
public long getLatency() {
// if(!isConnected()) return 9999;
assert (apLinkData != null && supportsAccessPoints)
|| apLinkData == null;
return apLinkData != null ? apLinkData.getLatency(isUpload)
: linkData.getLatency(isUpload);
}
@Override
public boolean isConnected()
{
if(apLinkData != null) return apLinkData.getConnectivity();
if(linkData != null) return linkData.getConnectivity();
return false;
}
}
/**
......
......@@ -27,6 +27,7 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
import de.tud.kom.p2psim.impl.topology.views.visualization.world.FiveGVisualization;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Abstract base class working on grids of configurable size.
......@@ -141,6 +142,8 @@ public abstract class AbstractGridBasedTopologyDatabase
private final long latencyUp, latencyDown, bandwidthUp, bandwidthDown;
private boolean connectivity = true;
/**
* Segment offering both, cell and access point with different
......@@ -173,19 +176,34 @@ public abstract class AbstractGridBasedTopologyDatabase
@Override
public double getDropProbability(boolean isUpload) {
if(!getConnectivity()) return 1;
return isUpload ? dropUp : dropDown;
}
@Override
public long getLatency(boolean isUpload) {
if(!getConnectivity()) return 9999 * Time.MILLISECOND;
return isUpload ? latencyUp : latencyDown;
}
@Override
public long getBandwidth(boolean isUpload) {
if(!getConnectivity()) return 0;
return isUpload ? bandwidthUp : bandwidthDown;
}
@Override
public boolean getConnectivity()
{
return connectivity;
}
@Override
public void setConnectivity(boolean connectivity)
{
this.connectivity = connectivity;
}
}
}
......@@ -101,6 +101,20 @@ public interface FiveGTopologyDatabase {
*/
public long getBandwidth(boolean isUpload);
/**
* Connectivity of the cell.
*
* @return <code>false</code> if the cell is broken down/damaged and upload/download isn't possible.
* <code>true</code> otherwise.
*/
boolean getConnectivity();
/**
* Set the connectivity of the cell. When set to <code>false</code>, it should be impossible to upload or
* download data via this cell. {@link CellLink} refers to this attribute when returning e.g. BW or drop rate.
* @param connectivity
*/
void setConnectivity(boolean connectivity);
}
}
......@@ -44,7 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
* @author Bjoern Richerzhagen
* @version 1.0, Nov 5, 2015
*/
public class FiveGVisualization extends JComponent {
public class FiveGVisualization extends JComponent implements VisualizationInjector.MouseClickListener{
protected BufferedImage image;
......@@ -61,6 +61,8 @@ public class FiveGVisualization extends JComponent {
this.database = database;
image = new BufferedImage(VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY(), BufferedImage.TYPE_INT_ARGB);
VisualizationInjector.addMouseListener(this);
}
@Override
......@@ -91,6 +93,8 @@ public class FiveGVisualization extends JComponent {
try {
drawEntries(g2);
} catch (RuntimeException e) {
e.printStackTrace();
System.exit(0);
needsRedraw = true;
}
}
......@@ -112,10 +116,10 @@ public class FiveGVisualization extends JComponent {
if (entry == null) {
continue;
}
if (entry.getLatency(isUpload) > maxLatency) {
if (entry.getConnectivity() && entry.getLatency(isUpload) > maxLatency) {
maxLatency = entry.getLatency(isUpload);
}
if (entry.getLatency(isUpload) < minLatency) {
if (entry.getConnectivity() && entry.getLatency(isUpload) < minLatency) {
minLatency = entry.getLatency(isUpload);
}
}
......@@ -135,17 +139,17 @@ public class FiveGVisualization extends JComponent {
// TODO add checkbox for upload/download toggle?
// Latency
double latencyFactor = (entry.getLatency(isUpload) - minLatency)
/ (maxLatency - minLatency);
double latencyFactor = entry.getConnectivity() ? (entry.getLatency(isUpload) - minLatency)
/ (maxLatency - minLatency) : 4;
g2.setColor(
new Color(255, 0, 0, 10 + (int) (40 * latencyFactor)));
new Color(255, 0, 0, 10 + (int) (40 * latencyFactor)));
g2.fillRect(x, y, stepSize, stepSize);
// Drop-Prob
g2.setColor(new Color(255, 0, 0,
10 + (int) (100 * entry.getDropProbability(isUpload))));
g2.setStroke(new BasicStroke(
(float) (10 * entry.getDropProbability(isUpload))));
float strokeWidth = entry.getConnectivity() ? (float) entry.getDropProbability(isUpload) : 0.2f;
g2.setStroke(new BasicStroke((10 * strokeWidth)));
g2.drawRect(x, y, stepSize, stepSize);
g2.setColor(new Color(255, 255, 255, 255));
g2.drawString("L: "
......@@ -158,9 +162,26 @@ public class FiveGVisualization extends JComponent {
g2.drawString("BW: "
+ (int) (entry.getBandwidth(isUpload) / Rate.kbit_s)
+ " kBit/s", x + 10, y + 35);
if(!entry.getConnectivity())
{
g2.drawString("!DEAD!", x + 30, y + 70);
}
}
}
}
/**
* When a grid cell is clicked, the cell changes it connectivity.
* @param x
* @param y
*/
@Override
public void mouseClicked(int x, int y)
{
int segID = database.getSegmentID(x,y);
Entry entry = database.getEntryFor(segID, false);
entry.setConnectivity(!entry.getConnectivity());
needsRedraw = true;
}
}
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