diff --git a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java index 668073d673c198c39109091d2fc8810cf2e01c74..e9d5c7e6e0d89b9939c8e8655473519ac450324b 100644 --- a/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java +++ b/src/de/tud/kom/p2psim/impl/topology/views/FiveGTopologyView.java @@ -37,12 +37,14 @@ 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; @@ -96,6 +98,8 @@ public class FiveGTopologyView extends AbstractTopologyView { 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. @@ -213,12 +217,12 @@ public class FiveGTopologyView extends AbstractTopologyView { null); } } - + /** - * Check, if a node moved into a new segment. If so, we need to update - * the HandoverSensor to trigger the listeners. We only need to check - * nodes that are included in the list of ap-enabled nodes (i.e., they - * already have a HandoverSensor-instance). + * Check, if a node moved into a new segment. If so, we need to update the + * HandoverSensor to trigger the listeners. We only need to check nodes that + * are included in the list of ap-enabled nodes (i.e., they already have a + * HandoverSensor-instance). */ protected void checkAPAssociations() { for (HandoverSensor5G sensor : handoverSensors) { @@ -232,7 +236,7 @@ public class FiveGTopologyView extends AbstractTopologyView { databaseAccessPoints.getEntryFor(segId, false) != null); } } - + /* * FIXME the not-so-elegant approach of updating all max-BWs */ @@ -240,9 +244,9 @@ public class FiveGTopologyView extends AbstractTopologyView { updateMaxMacBandwidth(mobileClient); } } - + long lastMovementTimestamp = 0; - + @Override public void onLocationChanged(Host host, Location location) { super.onLocationChanged(host, location); @@ -250,6 +254,10 @@ public class FiveGTopologyView extends AbstractTopologyView { lastMovementTimestamp = Time.getCurrentTime(); checkAPAssociations(); } + if (databaseWantsLocationUpdates) { + ((ModelBasedSegmentDatabase) database).onLocationChanged(host, + location); + } } /** @@ -353,6 +361,9 @@ public class FiveGTopologyView extends AbstractTopologyView { public void setDatabase(FiveGTopologyDatabase database) { assert this.database == null; this.database = database; + if (LocationListener.class.isAssignableFrom(database.getClass())) { + this.databaseWantsLocationUpdates = true; + } } /** @@ -485,10 +496,11 @@ public class FiveGTopologyView extends AbstractTopologyView { } @Override - public boolean isConnected() - { - if(apLinkData != null) return apLinkData.getConnectivity(); - if(linkData != null) return linkData.getConnectivity(); + public boolean isConnected() { + if (apLinkData != null) + return apLinkData.getConnectivity(); + if (linkData != null) + return linkData.getConnectivity(); return false; } diff --git a/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java new file mode 100644 index 0000000000000000000000000000000000000000..908b4daeff932a872f920e389114b5ad4eec8389 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/views/fiveg/ModelBasedSegmentDatabase.java @@ -0,0 +1,108 @@ +/* + * 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 . + * + */ + +package de.tud.kom.p2psim.impl.topology.views.fiveg; + +import de.tud.kom.p2psim.api.linklayer.mac.MacLayer; +import de.tud.kom.p2psim.impl.linklayer.mac.AbstractMacLayer; +import de.tud.kom.p2psim.impl.linklayer.mac.SimpleMacLayer; +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 ModelBasedSegmentDatabase() { + super(100, true); + super.setSupportCloudlets(true); + } + + @Override + protected Entry createEntryFor(int segmentID, boolean isCloudlet) { + // TODO Handle Cloudlets differently? + return new ModelBasedEntry(segmentID); + } + + @Override + public void onLocationChanged(Host host, Location location) { + try { + System.out.println(host.getComponent(SimpleMacLayer.class).getMacAddress()); + } catch (ComponentNotAvailableException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public class ModelBasedEntry implements FiveGTopologyDatabase.Entry { + + private final int segment; + + private boolean connectivity = true; + + public ModelBasedEntry(int segment) { + this.segment = segment; + } + + @Override + public int getSegmentID() { + return segment; + } + + @Override + public double getDropProbability(boolean isUpload) { + if (!getConnectivity()) { + return 1; + } + // TODO Return Drop Probability based on Model + return 0; + } + + @Override + public long getLatency(boolean isUpload) { + if (!getConnectivity()) { + return 9999 * Time.MILLISECOND; + } + // TODO Return Latency based on Model + return 0; + } + + @Override + public long getBandwidth(boolean isUpload) { + if (!getConnectivity()) { + return 0; + } + // TODO Return Bandwidth based on Model + return 0; + } + + @Override + public boolean getConnectivity() { + return connectivity; + } + + @Override + public void setConnectivity(boolean connectivity) { + this.connectivity = connectivity; + } + } +}