Commit 999d2436 authored by Marc Schiller's avatar Marc Schiller
Browse files

Rewrote Visualization. Rewrote menu creation. Added periodic repainting. Fixed...

Rewrote Visualization. Rewrote menu creation. Added periodic repainting. Fixed getStatus(). Removed overload debug output.
parent 02ba22b3
......@@ -194,7 +194,7 @@ public class ModelBasedSegmentDatabase
// How is a overload defined
private final long OVERLOAD_LATENCY = 9999 * Time.MILLISECOND;
private final long OVERLOAD_BANDWIDTH = (long) 0.1;
private final long OVERLOAD_BANDWIDTH = 1;
private final double OVERLOAD_DROPRATE = 1;
......@@ -205,7 +205,7 @@ public class ModelBasedSegmentDatabase
private final double THRESHOLD_DROPRATE = 1;
private final double YELLOW_INDICATOR = .9;
private final double YELLOW_INDICATOR = .8;
// Other storage
private final int segment;
......@@ -324,11 +324,11 @@ public class ModelBasedSegmentDatabase
public int getStatus(ParameterType type, Direction dir) {
if(type.equals(ParameterType.BANDWIDTH) && dir.equals(Direction.UPLOAD)) {
if(this.bandUp < THRESHOLD_BANDWIDTH) {
if(this.bandUp <= THRESHOLD_BANDWIDTH) {
return 2;
}
if(this.bandUp < (YELLOW_INDICATOR * THRESHOLD_BANDWIDTH)) {
if(this.bandUp < ((2 - YELLOW_INDICATOR) * THRESHOLD_BANDWIDTH)) {
return 1;
}
......@@ -336,11 +336,11 @@ public class ModelBasedSegmentDatabase
}
if(type.equals(ParameterType.BANDWIDTH) && dir.equals(Direction.DOWNLOAD)) {
if(this.bandDown < THRESHOLD_BANDWIDTH) {
if(this.bandDown <= THRESHOLD_BANDWIDTH) {
return 2;
}
if(this.bandDown < (YELLOW_INDICATOR * THRESHOLD_BANDWIDTH)) {
if(this.bandDown < ((2 - YELLOW_INDICATOR) * THRESHOLD_BANDWIDTH)) {
return 1;
}
......@@ -348,7 +348,7 @@ public class ModelBasedSegmentDatabase
}
if(type.equals(ParameterType.DROPRATE) && dir.equals(Direction.UPLOAD)) {
if(this.dropUp > THRESHOLD_DROPRATE) {
if(this.dropUp >= THRESHOLD_DROPRATE) {
return 2;
}
......@@ -360,7 +360,7 @@ public class ModelBasedSegmentDatabase
}
if(type.equals(ParameterType.DROPRATE) && dir.equals(Direction.DOWNLOAD)) {
if(this.dropDown > THRESHOLD_DROPRATE) {
if(this.dropDown >= THRESHOLD_DROPRATE) {
return 2;
}
......@@ -372,22 +372,22 @@ public class ModelBasedSegmentDatabase
}
if(type.equals(ParameterType.LATENCY) && dir.equals(Direction.UPLOAD)) {
if(this.latUp > THRESHOLD_LATENCY) {
if(this.latUp >= THRESHOLD_LATENCY) {
return 2;
}
if(this.latUp > (YELLOW_INDICATOR * THRESHOLD_LATENCY)) {
if(this.latUp > ((2 - YELLOW_INDICATOR) * THRESHOLD_LATENCY)) {
return 1;
}
return 0;
}
if(type.equals(ParameterType.LATENCY) && dir.equals(Direction.DOWNLOAD)) {
if(this.latDown > THRESHOLD_LATENCY) {
if(this.latDown >= THRESHOLD_LATENCY) {
return 2;
}
if(this.latDown > (YELLOW_INDICATOR * THRESHOLD_LATENCY)) {
if(this.latDown > ((2 - YELLOW_INDICATOR) * THRESHOLD_LATENCY)) {
return 1;
}
return 0;
......@@ -395,6 +395,14 @@ public class ModelBasedSegmentDatabase
return 0;
}
public boolean isOverloaded() {
return overload;
}
public int getHostsInSegment() {
return this.hostsInSegment.size();
}
/**
* Recalculate every metric when a host leaves or enters
......@@ -414,8 +422,6 @@ public class ModelBasedSegmentDatabase
if (bandDown <= THRESHOLD_BANDWIDTH
|| bandUp <= THRESHOLD_BANDWIDTH) {
overload = true;
System.out.println("Bandwidth is overloaded in Segment: "
+ getSegmentID());
}
// Calc Latency
......@@ -426,8 +432,6 @@ public class ModelBasedSegmentDatabase
if (latUp >= THRESHOLD_LATENCY || latDown >= THRESHOLD_LATENCY) {
overload = true;
System.out.println(
"Latency is overloaded in Segment: " + getSegmentID());
}
// Calc Droprate
......@@ -439,8 +443,6 @@ public class ModelBasedSegmentDatabase
if (dropUp >= THRESHOLD_DROPRATE
|| dropDown >= THRESHOLD_DROPRATE) {
overload = true;
System.out.println(
"Droprate is overloaded in Segment: " + getSegmentID());
}
}
}
......
......@@ -29,8 +29,6 @@ import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.Direction;
import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.ParameterType;
import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
import de.tudarmstadt.maki.simonstrator.api.Rate;
import de.tudarmstadt.maki.simonstrator.api.Time;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
......@@ -49,40 +47,45 @@ import javax.swing.*;
/**
* Visualization for the {@link FiveGTopologyView}
*
* Added 06.10.2016 Nils Richerzhagen, Clemens Krug
* Functionality to 'destroy' cells using SHIFT + Left-click. Enable/Disable using the enableCellDestruction
* Added 06.10.2016 Nils Richerzhagen, Clemens Krug Functionality to 'destroy'
* cells using SHIFT + Left-click. Enable/Disable using the
* enableCellDestruction
*
* @author Bjoern Richerzhagen
* @version 1.0, Nov 5, 2015
*/
public class ModelFiveGVisualization extends JComponent implements VisualizationComponent, ActionListener, MouseClickListener {
public class ModelFiveGVisualization extends JComponent
implements VisualizationComponent, ActionListener, MouseClickListener {
private static final ModelFiveGVisualization instance = new ModelFiveGVisualization();
private ModelBasedSegmentDatabase database;
private final JMenu menu = new JMenu("FiveG");
protected BufferedImage image;
protected volatile boolean needsRedraw = false;
private Direction selectedDirection = null;
private ParameterType selectedType = null;
private HashSet<JCheckBoxMenuItem> menuItems = new HashSet<>(6);
private ModelFiveGVisualization() {
setBounds(0, 0, VisualizationInjector.getWorldX(), VisualizationInjector.getWorldY());
setBounds(0, 0, VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY());
setOpaque(true);
setVisible(true);
image = new BufferedImage(VisualizationInjector.getWorldX(),
VisualizationInjector.getWorldY(), BufferedImage.TYPE_INT_ARGB);
this.generateMenu();
VisualizationInjector.addMouseListener(this);
}
public static ModelFiveGVisualization getInstance() {
return instance;
}
......@@ -110,58 +113,26 @@ public class ModelFiveGVisualization extends JComponent implements Visualization
public boolean isHidden() {
return false;
}
private void generateMenu() {
JMenu bwMenu = new JMenu("Bandwidth");
JCheckBoxMenuItem bwUMenu = new JCheckBoxMenuItem("Upload");
bwUMenu.setName("Bandwidth Upload");
bwUMenu.addActionListener(this);
bwMenu.add(bwUMenu);
menuItems.add(bwUMenu);
JCheckBoxMenuItem bwDMenu = new JCheckBoxMenuItem("Download");
bwDMenu.setName("Bandwidth Download");
bwDMenu.addActionListener(this);
bwMenu.add(bwDMenu);
menuItems.add(bwDMenu);
menu.add(bwMenu);
JMenu latMenu = new JMenu("Latency");
String[] entries1 = { "Bandwidth", "Latency", "Droprate" };
String[] entries2 = { "Download", "Upload" };
JCheckBoxMenuItem latUMenu = new JCheckBoxMenuItem("Upload");
latUMenu.setName("Latency Upload");
latUMenu.addActionListener(this);
latMenu.add(latUMenu);
menuItems.add(latUMenu);
JCheckBoxMenuItem latDMenu = new JCheckBoxMenuItem("Download");
latDMenu.setName("Latency Download");
latDMenu.addActionListener(this);
latMenu.add(latDMenu);
menuItems.add(latDMenu);
menu.add(latMenu);
JMenu dropMenu = new JMenu("Droprate");
for(String entry1: entries1) {
JMenu tmpMenu = new JMenu(entry1);
for(String entry2: entries2) {
JCheckBoxMenuItem checkbox = new JCheckBoxMenuItem(entry2);
checkbox.setName(entry1 + " " + entry2);
checkbox.addActionListener(this);
tmpMenu.add(checkbox);
menuItems.add(checkbox);
}
menu.add(tmpMenu);
}
JCheckBoxMenuItem dropUMenu = new JCheckBoxMenuItem("Upload");
dropUMenu.setName("Droprate Upload");
dropUMenu.addActionListener(this);
dropMenu.add(dropUMenu);
menuItems.add(dropUMenu);
JCheckBoxMenuItem dropDMenu = new JCheckBoxMenuItem("Download");
dropDMenu.setName("Droprate Download");
dropDMenu.addActionListener(this);
dropMenu.add(dropDMenu);
menuItems.add(dropDMenu);
menu.add(dropMenu);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
......@@ -173,8 +144,9 @@ public class ModelFiveGVisualization extends JComponent implements Visualization
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(image, 0, 0, null);
}
protected void redraw() {
needsRedraw = false;
Graphics2D g2 = (Graphics2D) image.getGraphics();
......@@ -193,74 +165,97 @@ public class ModelFiveGVisualization extends JComponent implements Visualization
e.printStackTrace();
System.exit(0);
needsRedraw = true;
} finally {
// Schedule next redraw
new Thread(() -> {
try {
Thread.sleep(100);
needsRedraw = true;
} catch (InterruptedException e) {
// Ignore any error in Timer
}
}).start();
}
}
private void drawEntries(Graphics2D g2) {
// Iterate over grid coordinates
int stepSize = database.getGridSize();
double maxLatency = 0;
double minLatency = Double.MAX_VALUE;
boolean isUpload = false;
for (int x = 0; x < VisualizationInjector.getWorldX(); x += stepSize) {
for (int y = 0; y < VisualizationInjector
.getWorldY(); y += stepSize) {
// TODO add checkbox for cloudlets?
Entry entry = database.getEntryFor(database.getSegmentID(x, y),
false);
if (entry == null) {
continue;
}
}
}
boolean isUpload = selectedDirection.equals(Direction.UPLOAD) ? true
: false;
// Loop through world
for (int x = 0; x < VisualizationInjector.getWorldX(); x += stepSize) {
for (int y = 0; y < VisualizationInjector
.getWorldY(); y += stepSize) {
// TODO add checkbox for cloudlets?
ModelBasedEntry entry = (ModelBasedEntry) database.getEntryFor(database.getSegmentID(x, y),
false);
// Fetch entry
ModelBasedEntry entry = (ModelBasedEntry) database
.getEntryFor(database.getSegmentID(x, y), false);
// Skip cell if no entry is found
if (entry == null) {
continue;
}
int status = entry.getStatus(selectedType, selectedDirection);
Color color = null;
if(status == 0) {
if (entry.isAvailable() && status == 0) {
// Cell is ok => green
color = new Color(0, 128, 0, 40);
} else if (status == 1) {
} else if (entry.isAvailable() && status == 1) {
// Cell is shortly before overload
color = new Color(255, 255, 0, 40);
} else {
color = new Color(255, 0, 0, 40);
} else if (!entry.isAvailable() || status == 2) {
// Cell is overloaded or unavailable
color = new Color(255, 0, 0, 100);
}
// Latency
// Fill with color for given metric
g2.setColor(color);
g2.fillRect(x, y, stepSize, stepSize);
// Drop-Prob
g2.setColor(new Color(255, 0, 0,
10 + (int) (100 * entry.getDropProbability(isUpload))));
float strokeWidth = (float) entry.getDropProbability(isUpload);
g2.setStroke(new BasicStroke((10 * strokeWidth)));
// Draw border
if (entry.isAvailable()) {
g2.setColor(new Color(255, 0, 0, 10));
g2.setStroke(new BasicStroke(1));
} else {
g2.setColor(new Color(255, 0, 0, 100));
g2.setStroke(new BasicStroke(5));
}
g2.drawRect(x, y, stepSize, stepSize);
// Write current values to cell
g2.setColor(new Color(255, 255, 255, 255));
g2.drawString("L: "
+ entry.getLatency(isUpload) / Time.MILLISECOND + " ms",
x + 10, y + 15);
// Latency
if (entry.isAvailable() && !entry.isOverloaded()) {
g2.drawString("L: " + entry.getLatency(isUpload) + " ms",
x + 10, y + 15);
} else {
g2.drawString("L: ∞ ms", x + 10, y + 15);
}
// Droprate
g2.drawString(
"D: " + (int) (entry.getDropProbability(isUpload) * 100)
+ " %",
x + 10, y + 25);
g2.drawString("B: "
+ (int) (entry.getBandwidth(isUpload) / Rate.kbit_s)
+ " kBit/s", x + 10, y + 35);
// Bandwidth
g2.drawString("B: " + entry.getBandwidth(isUpload) + " kBit/s",
x + 10, y + 35);
// SegmentID
g2.drawString("S:" + entry.getSegmentID(), x + 10, y + 45);
if(!entry.isAvailable()) {
// Current Hosts in Segment
g2.drawString("H:" + entry.getHostsInSegment(), x + 10, y + 55);
// Host has been killed manually
if (!entry.isAvailable()) {
g2.drawString("!DEAD!", x + 30, y + 70);
}
}
......@@ -301,18 +296,17 @@ public class ModelFiveGVisualization extends JComponent implements Visualization
break;
}
needsRedraw = true;
for(JCheckBoxMenuItem item: menuItems) {
for (JCheckBoxMenuItem item : menuItems) {
item.setSelected(false);
}
source.setSelected(true);
}
@Override
public void mouseClicked(int x, int y, int modifier)
{
public void mouseClicked(int x, int y, int modifier) {
// 17 == Shift
if(modifier == 17)
{
if (modifier == 17) {
int segID = database.getSegmentID(x, y);
Entry entry = database.getEntryFor(segID, false);
entry.setAvailability(!entry.isAvailable());
......
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