Commit 39271d13 authored by Marc Schiller's avatar Marc Schiller
Browse files

Adapt new Entry format.

parent fa7e07fc
......@@ -30,21 +30,18 @@ import de.tud.kom.p2psim.api.linklayer.mac.Link;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.MacLayer;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView.CellLink;
import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase;
import de.tud.kom.p2psim.impl.topology.views.fiveg.FiveGTopologyDatabase.Entry;
import de.tud.kom.p2psim.impl.topology.views.fiveg.ModelBasedSegmentDatabase;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.handover.HandoverSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
import edu.emory.mathcs.backport.java.util.Arrays;
......@@ -98,8 +95,6 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
private FiveGTopologyDatabase databaseAccessPoints = null;
private boolean databaseWantsLocationUpdates = false;
/**
* Configuration setting: all group IDs of nodes that act as cloudlets
* (e.g., act as basestations with a lower delay, whatever that means w.r.t.
......@@ -254,10 +249,6 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
lastMovementTimestamp = Time.getCurrentTime();
checkAPAssociations();
}
if (databaseWantsLocationUpdates) {
((ModelBasedSegmentDatabase) database).onLocationChanged(host,
location);
}
}
/**
......@@ -381,9 +372,6 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
public void setDatabase(FiveGTopologyDatabase database) {
assert this.database == null;
this.database = database;
if (LocationListener.class.isAssignableFrom(database.getClass())) {
this.databaseWantsLocationUpdates = true;
}
}
/**
......@@ -632,4 +620,4 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
}
}
}
\ No newline at end of file
......@@ -21,29 +21,18 @@
package de.tud.kom.p2psim.impl.topology.views.fiveg;
import java.util.HashMap;
import java.util.HashSet;
import de.tud.kom.p2psim.api.linklayer.mac.MacAddress;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.linklayer.ModularLinkLayer;
import de.tud.kom.p2psim.impl.topology.views.fiveg.models.AbstractModel;
import de.tud.kom.p2psim.impl.topology.views.fiveg.models.ParameterType;
import de.tud.kom.p2psim.impl.util.IncrementableHashMap;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
implements LocationListener {
public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase {
final Integer DEFAULT_SEGMENT_ID = new Integer(-1);
private HashMap<MacAddress, Integer> currentPositions = new HashMap<>();
IncrementableHashMap<Integer> usersPerSegment = new IncrementableHashMap<>();
HashMap<ParameterType, HashMap<Integer, AbstractModel>> models = new HashMap<>();
public ModelBasedSegmentDatabase() {
......@@ -53,7 +42,6 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
@Override
protected Entry createEntryFor(int segmentID, boolean isCloudlet) {
// TODO Handle Cloudlets differently?
return new ModelBasedEntry(segmentID);
}
......@@ -81,38 +69,13 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
}
}
@Override
public void onLocationChanged(Host host, Location location) {
try {
// Get MAC Address and the SegementID the user is now in
MacAddress mac = host.getComponent(ModularLinkLayer.class)
.getMac(PhyType.UMTS).getMacAddress();
Integer segmentID = new Integer(this.getSegmentID(
location.getLongitude(), location.getLatitude()));
// Check if it is a new host
if (currentPositions.containsKey(mac)) {
Integer oldSegmentID = currentPositions.get(mac);
// Host changed segment
if (oldSegmentID.compareTo(segmentID) != 0) {
usersPerSegment.decrement(oldSegmentID);
usersPerSegment.increment(segmentID);
currentPositions.put(mac, segmentID);
}
} else {
// New host
currentPositions.put(mac, segmentID);
usersPerSegment.increment(segmentID);
}
} catch (ComponentNotAvailableException e) {
// TODO Handle unknown host type
}
}
public class ModelBasedEntry implements FiveGTopologyDatabase.Entry {
private final int segment;
private boolean connectivity = true;
private boolean isAvailable = true;
private HashSet<MacAddress> hostsInSegment = new HashSet<>();
public ModelBasedEntry(int segment) {
this.segment = segment;
......@@ -122,15 +85,25 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
public int getSegmentID() {
return segment;
}
public void onHostLeavesSegment(MacAddress hostAddr) {
this.hostsInSegment.remove(hostAddr);
System.out.println(this.segment + ": " + this.hostsInSegment.size());
}
public void onHostEntersSegment(MacAddress hostAddr) {
this.hostsInSegment.add(hostAddr);
System.out.println(this.segment + ": " + this.hostsInSegment.size());
}
@Override
public double getDropProbability(boolean isUpload) {
if (!getConnectivity()) {
if (!isAvailable) {
return 1;
}
// TODO Up / Download?
Integer segmentID = new Integer(getSegmentID());
int usersInSegment = usersPerSegment.get(segmentID);
int usersInSegment = this.hostsInSegment.size();
// Is there a Model for Droprate?
if (models.containsKey(ParameterType.DROPRATE)) {
......@@ -149,7 +122,7 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
@Override
public long getLatency(boolean isUpload) {
if (!getConnectivity()) {
if (!isAvailable) {
return 9999 * Time.MILLISECOND;
}
// TODO Return Latency based on Model
......@@ -158,7 +131,7 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
@Override
public long getBandwidth(boolean isUpload) {
if (!getConnectivity()) {
if (!isAvailable) {
return 0;
}
// TODO Return Bandwidth based on Model
......@@ -166,13 +139,13 @@ public class ModelBasedSegmentDatabase extends AbstractGridBasedTopologyDatabase
}
@Override
public boolean getConnectivity() {
return connectivity;
public boolean isAvailable() {
return isAvailable;
}
@Override
public void setConnectivity(boolean connectivity) {
this.connectivity = connectivity;
public void setAvailability(boolean isAvailable) {
this.isAvailable = isAvailable;
}
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.util;
import java.util.HashMap;
public class IncrementableHashMap<K> {
private HashMap<K, Integer> storage;
public IncrementableHashMap() {
storage = new HashMap<>();
}
public int get(K key) {
return storage.get(key).intValue();
}
public void increment(K key) {
if(storage.containsKey(key)) {
Integer tmp = storage.get(key);
storage.put(key, new Integer(tmp.intValue() + 1));
} else {
storage.put(key, new Integer(1));
}
}
public void decrement(K key) {
if(storage.containsKey(key)) {
Integer tmp = storage.get(key);
if(tmp.compareTo(new Integer(1)) == 0) {
storage.put(key, new Integer(0));
} else {
storage.put(key, new Integer(tmp.intValue() - 1));
}
} else {
storage.put(key, new Integer(0));
}
}
public boolean containsKey(K key) {
return storage.containsKey(key);
}
public String toString() {
StringBuilder sb = new StringBuilder();
for(K key: storage.keySet()) {
sb.append(key.toString() + ": " + storage.get(key).toString() + "\n");
}
return sb.toString();
}
}
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