Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
...@@ -32,6 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor; ...@@ -32,6 +32,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.core.SchedulerComponent; import de.tudarmstadt.maki.simonstrator.api.component.core.SchedulerComponent;
import de.tudarmstadt.maki.simonstrator.api.component.core.SimulationRuntimeAnalyzer;
import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent; import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent;
/** /**
...@@ -57,7 +58,7 @@ SchedulerComponent, TimeComponent { ...@@ -57,7 +58,7 @@ SchedulerComponent, TimeComponent {
private long statusInterval = SCHEDULER_WAKEUP_INTERVAL_IN_VIRTUALTIME; private long statusInterval = SCHEDULER_WAKEUP_INTERVAL_IN_VIRTUALTIME;
private static final int INITIAL_QUEUE_CAPACITY = 5000; private static final int INITIAL_QUEUE_CAPACITY = 50000;
private long processedEventCounter; private long processedEventCounter;
...@@ -93,6 +94,9 @@ SchedulerComponent, TimeComponent { ...@@ -93,6 +94,9 @@ SchedulerComponent, TimeComponent {
protected static final int TYPE_END = 3; protected static final int TYPE_END = 3;
private SimulationRuntimeAnalyzer _simulationRuntimeAnalyzer;
private boolean _simulationRuntimeAnalyzerInit;
/** /**
* Constructs a new scheduler instance using a calendar queue. If desired, * Constructs a new scheduler instance using a calendar queue. If desired,
* status events about the progress of the simulation will be plotted. * status events about the progress of the simulation will be plotted.
...@@ -267,8 +271,14 @@ SchedulerComponent, TimeComponent { ...@@ -267,8 +271,14 @@ SchedulerComponent, TimeComponent {
processedEventCounter++; processedEventCounter++;
currentTime = realEvent.getSimulationTime(); currentTime = realEvent.getSimulationTime();
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler; EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type); handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler); notifyListeners(realEvent, realEvent.handler);
if (realEvent.schedulerType == TYPE_END) if (realEvent.schedulerType == TYPE_END)
...@@ -298,8 +308,15 @@ SchedulerComponent, TimeComponent { ...@@ -298,8 +308,15 @@ SchedulerComponent, TimeComponent {
assert (realEvent.simTime == Long.MIN_VALUE); assert (realEvent.simTime == Long.MIN_VALUE);
realEvent.simTime = currentTime; realEvent.simTime = currentTime;
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler; EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type); handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler); notifyListeners(realEvent, realEvent.handler);
} }
...@@ -403,8 +420,14 @@ SchedulerComponent, TimeComponent { ...@@ -403,8 +420,14 @@ SchedulerComponent, TimeComponent {
} }
currentTime = realEvent.getSimulationTime(); currentTime = realEvent.getSimulationTime();
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().startEventExecution(realEvent.handler, realEvent.type);
}
EventHandler handler = realEvent.handler; EventHandler handler = realEvent.handler;
handler.eventOccurred(realEvent.data, realEvent.type); handler.eventOccurred(realEvent.data, realEvent.type);
if (hasSimulationRuntimeAnalyzer()) {
getSimulationRuntimeAnalyzer().endEventExecution(realEvent.handler, realEvent.type);
}
notifyListeners(realEvent, realEvent.handler); notifyListeners(realEvent, realEvent.handler);
if (realEvent.schedulerType == TYPE_END) { if (realEvent.schedulerType == TYPE_END) {
...@@ -612,4 +635,16 @@ SchedulerComponent, TimeComponent { ...@@ -612,4 +635,16 @@ SchedulerComponent, TimeComponent {
} }
} }
private SimulationRuntimeAnalyzer getSimulationRuntimeAnalyzer() {
return _simulationRuntimeAnalyzer;
}
private boolean hasSimulationRuntimeAnalyzer() {
if (!_simulationRuntimeAnalyzerInit) {
_simulationRuntimeAnalyzer = Monitor.getOrNull(SimulationRuntimeAnalyzer.class);
_simulationRuntimeAnalyzerInit = true;
}
return _simulationRuntimeAnalyzer != null;
}
} }
...@@ -208,7 +208,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent { ...@@ -208,7 +208,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
/* Real World Starting Time: /* Real World Starting Time:
* Block till we're allowed to start. * Block till we're allowed to start.
*/ */
if( realWorldStartTime != null ) { if(realWorldStartTime != null ) {
try { try {
...@@ -234,9 +234,13 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent { ...@@ -234,9 +234,13 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
finishedWithoutError = true; finishedWithoutError = true;
} catch (RuntimeException e) { } catch (RuntimeException e) {
finishedWithoutError = false;
finishedWithoutError = false;
reason = e;
throw e; throw e;
} finally { } finally {
this.running = false; this.running = false;
// After a simulation start the mechanisms, which // After a simulation start the mechanisms, which
// finalize a simulation // finalize a simulation
...@@ -248,10 +252,18 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent { ...@@ -248,10 +252,18 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
this.running = false; this.running = false;
if (finishedWithoutError) { if (finishedWithoutError) {
Monitor.log(Simulator.class, Level.INFO, Monitor.log(Simulator.class, Level.INFO,
"Simulation successfully finished..."); "Simulation successfully finished :)");
} else { } else {
if(reason == null) {
Monitor.log(Simulator.class, Level.ERROR,
"Simulation finished with unresolved errors ???");
}
else {
Monitor.log(Simulator.class, Level.ERROR, Monitor.log(Simulator.class, Level.ERROR,
"Simulation finished with errors...\n" + reason); "Simulation finished with errors :( \n " +
reason.toString() + " : " + reason.getStackTrace());
}
} }
long runTime = System.currentTimeMillis() - startTime; long runTime = System.currentTimeMillis() - startTime;
long minutes = (long) Math.floor((runTime) / 60000); long minutes = (long) Math.floor((runTime) / 60000);
...@@ -389,8 +401,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent { ...@@ -389,8 +401,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
if (randomGenerators.containsKey(source)) { if (randomGenerators.containsKey(source)) {
return randomGenerators.get(source); return randomGenerators.get(source);
} else { } else {
long thisSeed = source.toString().hashCode() + 31 long thisSeed = source.toString().hashCode() * seed + seed;
* seed;
Monitor.log(Simulator.class, Level.INFO, Monitor.log(Simulator.class, Level.INFO,
"Created a new Random Source for %s with seed %d", source, "Created a new Random Source for %s with seed %d", source,
thisSeed); thisSeed);
...@@ -475,7 +486,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent { ...@@ -475,7 +486,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
*/ */
@Deprecated @Deprecated
public void setDatabase(String database) { public void setDatabase(String database) {
DAO.database = database; DAO.setDatabase(database);
} }
/** /**
......
...@@ -32,9 +32,8 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel; ...@@ -32,9 +32,8 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.social.SocialView; import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tud.kom.p2psim.impl.topology.views.visualization.world.SocialViewComponentVis;
/** /**
* Very basic Topology * Very basic Topology
...@@ -58,7 +57,7 @@ public class DefaultTopology implements Topology { ...@@ -58,7 +57,7 @@ public class DefaultTopology implements Topology {
private List<SocialView> socialViews; private List<SocialView> socialViews;
private PositionVector worldDimensions; private static PositionVector worldDimensions;
private boolean initializedSocial = false; private boolean initializedSocial = false;
...@@ -94,6 +93,11 @@ public class DefaultTopology implements Topology { ...@@ -94,6 +93,11 @@ public class DefaultTopology implements Topology {
listener.changedWaypointModel(model); listener.changedWaypointModel(model);
} }
} }
@Override
public WaypointModel getWaypointModel() {
return waypointModel;
}
@Override @Override
public void setObstacleModel(ObstacleModel model) { public void setObstacleModel(ObstacleModel model) {
...@@ -102,6 +106,11 @@ public class DefaultTopology implements Topology { ...@@ -102,6 +106,11 @@ public class DefaultTopology implements Topology {
listener.changedObstacleModel(model); listener.changedObstacleModel(model);
} }
} }
@Override
public ObstacleModel getObstacleModel() {
return obstacleModel;
}
@Override @Override
public void addTopologyListener(TopologyListener listener) { public void addTopologyListener(TopologyListener listener) {
...@@ -175,13 +184,20 @@ public class DefaultTopology implements Topology { ...@@ -175,13 +184,20 @@ public class DefaultTopology implements Topology {
} }
} }
@Override public static boolean isWithinWorldBoundaries(double x, double y) {
public WaypointModel getWaypointModel() { if(x >= 0 && y >= 0
return waypointModel; && x <= worldDimensions.getX() && y <= worldDimensions.getY()) {
return true;
}
else {
return false;
}
} }
@Override public static boolean isWithinWorldBoundaries(Location location) {
public ObstacleModel getObstacleModel() { return isWithinWorldBoundaries(location.getLongitudeOrX(), location.getLatitudeOrY());
return obstacleModel;
} }
} }
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -36,23 +36,29 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView; ...@@ -36,23 +36,29 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.network.modular.DBHostListManager; import de.tud.kom.p2psim.impl.network.modular.DBHostListManager;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.DefaultTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.TopologyComponentFactory;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel; import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.NoMovement; import de.tud.kom.p2psim.impl.topology.movement.NoMovement;
import de.tud.kom.p2psim.impl.topology.placement.GNPPlacement; import de.tud.kom.p2psim.impl.topology.placement.GNPPlacement;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.latency.GNPLatency; import de.tud.kom.p2psim.impl.topology.views.latency.GNPLatency;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory; import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* This factory is configured with one or more {@link TopologyView}s if the * This factory is configured with one or more {@link TopologyView}s if the
* {@link LinkLayer} is used. * {@link LinkLayer} is used.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen, Julian Zobel
* @version 1.0, 01.03.2012 * @version 1.1, 06.09.2018
*/ */
public class TopologyFactory implements HostComponentFactory { public class TopologyFactory implements HostComponentFactory {
...@@ -71,7 +77,9 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -71,7 +77,9 @@ public class TopologyFactory implements HostComponentFactory {
private WaypointModel waypointModel; private WaypointModel waypointModel;
private ObstacleModel obstacleModel; private ObstacleModel obstacleModel;
private TopologyComponentFactory topologyComponentFactory = new DefaultTopologyComponent.Factory();
private boolean registerAsInformationProviderInSiS = false; private boolean registerAsInformationProviderInSiS = false;
private static NetMeasurementDB measurementDB = null; private static NetMeasurementDB measurementDB = null;
...@@ -87,7 +95,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -87,7 +95,7 @@ public class TopologyFactory implements HostComponentFactory {
private boolean alreadyAddedMovement = false; private boolean alreadyAddedMovement = false;
/** /**
* *
*/ */
@XMLConfigurableConstructor({ "worldX", "worldY" }) @XMLConfigurableConstructor({ "worldX", "worldY" })
public TopologyFactory(double worldX, double worldY) { public TopologyFactory(double worldX, double worldY) {
...@@ -126,8 +134,12 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -126,8 +134,12 @@ public class TopologyFactory implements HostComponentFactory {
* Create a TopologyComponent and register it with the Topology and its * Create a TopologyComponent and register it with the Topology and its
* movement model. * movement model.
*/ */
TopologyComponent toCo = new DefaultTopologyComponent(host, topo,
movement, placement, registerAsInformationProviderInSiS); if(topologyComponentFactory == null) {
throw new UnsupportedOperationException("[TopologyFactory] Cannot create topology component, topology component factory is NULL");
}
TopologyComponent toCo = topologyComponentFactory.createTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
/* /*
* Need to register TopoViews as movement listeners, as they might need * Need to register TopoViews as movement listeners, as they might need
...@@ -148,7 +160,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -148,7 +160,7 @@ public class TopologyFactory implements HostComponentFactory {
/** /**
* Set the {@link PlacementModel} for this group of hosts * Set the {@link PlacementModel} for this group of hosts
* *
* @param placementModel * @param placementModel
*/ */
public void setPlacement(PlacementModel placementModel) { public void setPlacement(PlacementModel placementModel) {
...@@ -180,7 +192,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -180,7 +192,7 @@ public class TopologyFactory implements HostComponentFactory {
/** /**
* Add a {@link TopologyView} * Add a {@link TopologyView}
* *
* @param topologyView * @param topologyView
*/ */
public void setView(TopologyView topologyView) { public void setView(TopologyView topologyView) {
...@@ -198,7 +210,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -198,7 +210,7 @@ public class TopologyFactory implements HostComponentFactory {
/** /**
* Set the {@link MovementModel} for this group of hosts * Set the {@link MovementModel} for this group of hosts
* *
* @param movement * @param movement
*/ */
public void setMovement(MovementModel movement) { public void setMovement(MovementModel movement) {
...@@ -213,7 +225,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -213,7 +225,7 @@ public class TopologyFactory implements HostComponentFactory {
/** /**
* For the {@link GNPLatency} and the {@link GNPPlacement}, a * For the {@link GNPLatency} and the {@link GNPPlacement}, a
* {@link NetMeasurementDB} is needed. * {@link NetMeasurementDB} is needed.
* *
* @param db * @param db
*/ */
public void setMeasurementDB(NetMeasurementDB db) { public void setMeasurementDB(NetMeasurementDB db) {
...@@ -229,11 +241,11 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -229,11 +241,11 @@ public class TopologyFactory implements HostComponentFactory {
public void setUseRegionGroups(boolean useRegionGroups) { public void setUseRegionGroups(boolean useRegionGroups) {
TopologyFactory.useRegionGroups = useRegionGroups; TopologyFactory.useRegionGroups = useRegionGroups;
} }
/** /**
* Option to disable the default behavior of nodes registering as * Option to enable the behavior of nodes registering as
* topology providers. * topology providers.
* *
* @param registerAsLocationProviderInSiS * @param registerAsLocationProviderInSiS
*/ */
public void setRegisterAsInformationProviderInSiS( public void setRegisterAsInformationProviderInSiS(
...@@ -245,7 +257,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -245,7 +257,7 @@ public class TopologyFactory implements HostComponentFactory {
* Allows GNP-based strategies to retrieve the unique * Allows GNP-based strategies to retrieve the unique
* {@link NetMeasurementDB.Host} - as this object should only be created * {@link NetMeasurementDB.Host} - as this object should only be created
* once per host, it is maintained in this static manner. * once per host, it is maintained in this static manner.
* *
* @param host * @param host
* @return * @return
*/ */
...@@ -258,7 +270,7 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -258,7 +270,7 @@ public class TopologyFactory implements HostComponentFactory {
/** /**
* The Measurement-DB * The Measurement-DB
* *
* @return * @return
*/ */
public static NetMeasurementDB getMeasurementDB() { public static NetMeasurementDB getMeasurementDB() {
...@@ -271,4 +283,9 @@ public class TopologyFactory implements HostComponentFactory { ...@@ -271,4 +283,9 @@ public class TopologyFactory implements HostComponentFactory {
public ObstacleModel getObstacleModel() { public ObstacleModel getObstacleModel() {
return obstacleModel; return obstacleModel;
} }
public void setTopologyComponentFactory(TopologyComponentFactory factory) {
this.topologyComponentFactory = factory;
}
} }
...@@ -2,106 +2,81 @@ ...@@ -2,106 +2,81 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package de.tud.kom.p2psim.impl.topology; package de.tud.kom.p2psim.impl.topology.component;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.Set; import java.util.Set;
import de.tud.kom.p2psim.api.common.HostProperties;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
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.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent; import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.impl.topology.util.LocalGraphView;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.topology.util.LocationRequestImpl;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Oracle;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph; import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge; import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode; import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; 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.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.component.sis.util.SiSTopologyProvider; import de.tudarmstadt.maki.simonstrator.api.component.sis.util.SiSTopologyProvider;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID; import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener; import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
/** /**
* Default implementation of a {@link TopologyComponent}. * Abstract implementation of the topology component interface, to support basic
* * functionalities to all topology components.
* @author Bjoern Richerzhagen *
* @version 1.0, 29.02.2012 * @author Julian Zobel
* @version 1.0, 6 Sep 2018
*/ */
public class DefaultTopologyComponent implements TopologyComponent { public abstract class AbstractTopologyComponent implements TopologyComponent {
protected static Random rnd = Randoms.getRandom(AttractionPoint.class); protected SimHost host;
protected final PositionVector position;
private SimHost host; protected Topology topology;
private final PositionVector position; protected MovementModel movementModel;
protected PlacementModel placementModel;
private Topology topology;
private final boolean registerAsInformationProviderInSiS;
private double currentMovementSpeed = -1;
private Map<LocationListener, LocationRequestImpl> openRequests = new LinkedHashMap<LocationListener, LocationRequestImpl>(); private Map<LocationListener, LocationRequestImpl> openRequests = new LinkedHashMap<LocationListener, LocationRequestImpl>();
private List<LocationListener> listeners = new LinkedList<>(); private List<LocationListener> listeners = new LinkedList<>();
private MovementModel movementModel;
private PlacementModel placementModel;
private final boolean registerAsInformationProviderInSiS; //
public AbstractTopologyComponent(SimHost host, Topology topology, MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
/**
* Create a TopologyComponent for the current host.
*
* @param host
* @param topology
* @param movementModel
*/
public DefaultTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
this.topology = topology; this.topology = topology;
this.host = host; this.host = host;
this.position = new PositionVector(0, 0); this.position = new PositionVector(0, 0);
...@@ -110,28 +85,23 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -110,28 +85,23 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (this.movementModel != null) { if (this.movementModel != null) {
this.movementModel.addComponent(this); this.movementModel.addComponent(this);
} }
this.placementModel = placementModel; this.placementModel = placementModel;
if (this.placementModel != null) { if (this.placementModel != null) {
this.placementModel.addComponent(this); this.placementModel.addComponent(this);
} }
this.registerAsInformationProviderInSiS = registerAsInformationProviderInSiS; this.registerAsInformationProviderInSiS = registerAsInformationProviderInSiS;
} }
@Override @Override
public void initialize() { public void initialize() {
/*
* Set the component's initial position and notify listeners of the
* Topology that this component is initialized.
*/
topology.addComponent(this); topology.addComponent(this);
movementModel.placeComponent(this); movementModel.placeComponent(this);
if (placementModel != null) { if (placementModel != null) {
/* // retrieve the initial position of this topology component
* Legacy support for placement models. position.set(placementModel.place(this));
*/
position.set(placementModel.place(this));
} }
if (registerAsInformationProviderInSiS) { if (registerAsInformationProviderInSiS) {
...@@ -201,9 +171,9 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -201,9 +171,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (getHost().getLinkLayer().hasPhy(PhyType.WIFI)) { if (getHost().getLinkLayer().hasPhy(PhyType.WIFI)) {
new SiSTopologyProvider(sis, new SiSTopologyProvider(sis,
SiSTypes.NEIGHBORS_WIFI, SiSTypes.NEIGHBORS_WIFI,
DefaultTopologyComponent.this, AbstractTopologyComponent.this,
getTopologyID(NetInterfaceName.WIFI, true), getTopologyID(NetInterfaceName.WIFI, true),
DefaultTopologyComponent.class); AbstractTopologyComponent.class);
} }
} }
}, null, 0); }, null, 0);
...@@ -213,29 +183,24 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -213,29 +183,24 @@ public class DefaultTopologyComponent implements TopologyComponent {
} }
} }
} }
@Override @Override
public void shutdown() { public void shutdown() {
topology = null; topology = null;
host = null; host = null;
movementModel = null; movementModel = null;
} }
@Override @Override
public SimHost getHost() { public SimHost getHost() {
return host; return host;
} }
@Override
public PositionVector getRealPosition() {
return position;
}
@Override @Override
public Topology getTopology() { public Topology getTopology() {
return topology; return topology;
} }
/** /**
* Access to the movement model * Access to the movement model
* @return * @return
...@@ -243,89 +208,30 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -243,89 +208,30 @@ public class DefaultTopologyComponent implements TopologyComponent {
public MovementModel getMovementModel() { public MovementModel getMovementModel() {
return movementModel; return movementModel;
} }
@Override
public double getMinMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMinMovementSpeed();
}
@Override
public double getMaxMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
}
private void calcRandomMovementSpeed() {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentMovementSpeed = (value * (max_speed - min_speed))
+ min_speed;
}
@Override
public double getMovementSpeed() {
if (currentMovementSpeed == -1) {
calcRandomMovementSpeed();
}
return this.currentMovementSpeed;
}
@Override
public void setMovementSpeed(double speed) {
this.currentMovementSpeed = speed;
}
@Override @Override
public Location getLastLocation() { public Location getLastLocation() {
/* /*
* As we want to mimic real world behavior, the current position * As we want to mimic real world behavior, the current position
* snapshot is cloned to prevent information propagation due to Java. * snapshot is cloned to prevent information propagation due to Java.
*/ */
return position.clone(); return position.clone();
} }
@Override @Override
public void updateCurrentLocation(Location location) { public PositionVector getRealPosition() {
return position; // no copy! See SimLocationActuator Interface Description!
}
@Override
public void updateCurrentLocation(Location location) {
position.set(location); position.set(location);
/*
* FIXME utilization of the NodeDebugMonitor leads to huge performance drop.
*/
// NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Current Location", location);
// try {
// NodeDebugMonitor.update(this.getClass(), getHost().getId(),
// "Distance to target",
// location.distanceTo(movementModel.getTargetLocation(this)));
// } catch (UnsupportedOperationException e) {
// // This is not supported by the movement model (which may happen see
// // MovementModel.java - thus catch and ignore)
// }
// notify "non-request" listeners
for (LocationListener locationListener : listeners) { for (LocationListener locationListener : listeners) {
locationListener.onLocationChanged(getHost(), getLastLocation()); locationListener.onLocationChanged(getHost(), getLastLocation());
} }
} }
@Override
public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint)
throws UnsupportedOperationException {
movementModel.changeTargetLocation(this, targetAttractionPoint);
// NodeDebugMonitor.update(this.getClass(), getHost().getId(), "Target Location", targetAttractionPoint);
}
@Override
public AttractionPoint getCurrentTargetAttractionPoint() {
return movementModel.getTargetLocation(this);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return movementModel.getAllAttractionPoints();
}
@Override @Override
public void requestLocationUpdates(LocationRequest request, public void requestLocationUpdates(LocationRequest request,
LocationListener listener) { LocationListener listener) {
...@@ -362,94 +268,9 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -362,94 +268,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
@Override @Override
public LocationRequest getLocationRequest() { public LocationRequest getLocationRequest() {
return new LocationRequestImpl(); return new LocationRequestImpl(getHost(), this);
}
/**
* Update 15.03.16 added support for multiple listeners (however, frequency
* etc. is immune after the first request is registered.)
*
* @author Bjoern Richerzhagen
* @version 1.0, Mar 15, 2016
*/
private class LocationRequestImpl implements LocationRequest, EventHandler {
private boolean immune = false;
private long interval = 1 * Simulator.MINUTE_UNIT;
private int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
private Location lastLocation = null;
private List<LocationListener> listeners = new LinkedList<LocationListener>();
private int eventTypeSeq = 0;
public LocationRequestImpl() {
// nothing to do
}
protected void cancel(LocationListener listener) {
boolean removed = listeners.remove(listener);
if (listeners.isEmpty()) {
// upcoming event is no longer valid!
eventTypeSeq++;
}
assert removed;
}
protected void immunizeAndStart(LocationListener listener) {
immune = true;
assert interval > 0;
if (listeners.isEmpty()) {
// Only start once!
lastLocation = null;
Event.scheduleImmediately(this, null, eventTypeSeq);
} else {
// Fire each new listener at least once
listener.onLocationChanged(getHost(), getLastLocation());
}
listeners.add(listener);
}
@Override
public void setInterval(long interval) {
if (!immune) {
this.interval = interval;
}
}
@Override
public void setPriority(int priority) {
if (!immune) {
this.priority = priority;
}
}
@Override
public void eventOccurred(Object content, int type) {
if (eventTypeSeq != type) {
/*
* Discard invalid events caused when a client cancels updates
* but reactivates the request within the update frequency
* interval. In this case, the old events continue rescheduling
* themselves.
*/
return;
}
if (!listeners.isEmpty()) {
// Only reschedule, if at least one listener is ... listening
Location newLoc = getLastLocation();
listeners.forEach((LocationListener listener) -> listener
.onLocationChanged(getHost(), newLoc));
lastLocation = newLoc;
Event.scheduleWithDelay(interval, this, null, eventTypeSeq);
}
}
} }
/* /*
* Methods for the Graph Interface * Methods for the Graph Interface
*/ */
...@@ -467,7 +288,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -467,7 +288,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
netName.toString() + (onlyOnline ? "-online" : "-all"), netName.toString() + (onlyOnline ? "-online" : "-all"),
DefaultTopologyComponent.class); DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) { if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id, new LocalGraphView(netName, onlyOnline)); this.graphViews.put(id, new LocalGraphView(netName, onlyOnline, topology));
} }
return id; return id;
} }
...@@ -481,7 +302,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -481,7 +302,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
DefaultTopologyComponent.class); DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) { if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id, this.graphViews.put(id,
new LocalGraphView(netName, onlyOnline, range)); new LocalGraphView(netName, onlyOnline, range, topology));
} }
return id; return id;
} }
...@@ -509,222 +330,9 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -509,222 +330,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
return graphViews.keySet(); return graphViews.keySet();
} }
/**
* This is calculated based on global knowledge. It only registers as
* {@link LocationListener}, if a range is specified by the Provider.
*
* @author Bjoern Richerzhagen
* @version 1.0, May 13, 2015
*/
private class LocalGraphView
implements LocationListener, ConnectivityListener {
/**
* Marker: has there been any movement since the graph view was last
* requested? If so: recalculate! Otherwise, we ignore this object to
* not perform calculations if no one is interested...
*/
private final double distance;
private final boolean isDistanceBased;
private final NetInterfaceName medium;
private final TopologyView topoView;
private final boolean onlyOnline;
private Graph currentView;
private boolean isInvalid = true;
private final PhyType phy;
public LocalGraphView(NetInterfaceName medium, boolean onlyOnline) {
this(medium, onlyOnline, -1);
}
public LocalGraphView(NetInterfaceName medium, boolean onlyOnline,
double distance) {
this.medium = medium;
PhyType localPhy = null;
for (PhyType currPhy : PhyType.values()) {
if (currPhy.getNetInterfaceName() == medium
&& getTopology().getTopologyView(currPhy) != null) {
localPhy = currPhy;
break;
}
}
phy = localPhy;
assert localPhy != null;
this.topoView = getTopology().getTopologyView(localPhy);
this.distance = distance;
this.onlyOnline = onlyOnline;
this.isDistanceBased = (distance > 0);
assert !isDistanceBased || phy.isBroadcastMedium();
if (phy.isBroadcastMedium() || onlyOnline) {
for (Host host : Oracle.getAllHosts()) {
if (phy.isBroadcastMedium()) {
try {
DefaultTopologyComponent dcomp = host.getComponent(
DefaultTopologyComponent.class);
dcomp.requestLocationUpdates(null,
LocalGraphView.this);
} catch (ComponentNotAvailableException e) {
continue;
}
}
if (onlyOnline) {
if (host.getNetworkComponent()
.getByName(medium) != null) {
host.getNetworkComponent().getByName(medium)
.addConnectivityListener(
LocalGraphView.this);
}
}
}
}
}
private void recalculateLocalView() {
if (!isInvalid) {
/*
* Graphs are invalidated (i) based on movement, IFF a range was
* specified, (ii) based on online/offline events, IFF only
* online hosts are to be considered.
*/
return;
}
/*
* Calculate a complete global connectivity graph
*/
// Create new, empty graph
currentView = Graphs.createGraph();
// Add all (online?) nodes
for (MacLayer mac : topoView.getAllMacs()) {
if (!onlyOnline || mac.isOnline()) {
INode node = currentView.createNode(mac.getHost().getId());
node.setProperty(SiSTypes.PHY_LOCATION,
topoView.getPosition(mac.getMacAddress()).clone());
currentView.addElement(node);
}
}
if (isDistanceBased) {
// Build neighbors solely based on an assumed range
for (MacLayer mac : topoView.getAllMacs()) {
// Fix Christoph Storm:
// Do not take offline nodes into account, unless told to do
// so...
if (onlyOnline && !currentView
.containsNode(mac.getHost().getId())) {
continue;
}
// Consider all nodes as potential neighbors
for (MacLayer neighborMac : topoView.getAllMacs()) {
// create, but do NOT add the node object
INode neighbor = currentView
.createNode(neighborMac.getHost().getId());
// only online nodes (already in graph)
if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
// Distance?
if (topoView.getDistance(mac.getMacAddress(),
neighborMac.getMacAddress()) <= distance) {
IEdge edge = currentView.createEdge(
mac.getHost().getId(),
neighborMac.getHost().getId());
currentView.addElement(edge);
}
}
}
}
} else {
// Build neighborhoods based on underlay neighbors (1-hop)
for (MacLayer mac : topoView.getAllMacs()) {
// Fix Christoph Storm:
// Do not take offline nodes into account, unless told to do
// so...
if (onlyOnline && !currentView
.containsNode(mac.getHost().getId())) {
continue;
}
// Rely on underlay for neighbors
List<MacAddress> neighbors = topoView
.getNeighbors(mac.getMacAddress());
for (MacAddress neighborMac : neighbors) {
// create, but do NOT add the node object
INode neighbor = currentView.createNode(
topoView.getMac(neighborMac).getHost().getId());
// only online nodes (already in graph)
if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
IEdge edge = currentView.createEdge(
mac.getHost().getId(),
topoView.getMac(neighborMac).getHost()
.getId());
currentView.addElement(edge);
edge.setProperty(SiSTypes.PHY_DISTANCE,
topoView.getDistance(mac.getMacAddress(),
neighborMac));
}
}
}
}
isInvalid = false;
}
public INode getOwnNode(SimHost ownHost) {
MacLayer mac = ownHost.getLinkLayer().getMac(phy);
if (!onlyOnline || mac.isOnline()) {
return currentView.createNode(ownHost.getId());
}
return null;
}
public Set<IEdge> getNeighbors(SimHost ownHost) {
recalculateLocalView();
INode ownNode = getOwnNode(ownHost);
return currentView.getOutgoingEdges(ownNode.getId());
}
/**
* This is the global view, therefore we do not distinguish between
* hosts.
*
* @return
*/
public Graph getLocalView() {
recalculateLocalView();
return currentView.clone();
}
@Override
public void onLocationChanged(Host host, Location location) {
this.isInvalid = true;
}
@Override
public void wentOnline(Host host, NetInterface netInterface) {
assert netInterface.getName() == medium;
this.isInvalid = true;
}
@Override
public void wentOffline(Host host, NetInterface netInterface) {
assert netInterface.getName() == medium;
this.isInvalid = true;
}
}
@Override @Override
public String toString() { public String toString() {
return "TopoComp: " + getHost().getId() + " at " + position.toString(); return "Topology Component #" + getHost().getId() + " at pos " + position.toString();
} }
} }
/*
* 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.topology.component;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.BaseToUAVInterface;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseInterface;
public class BaseTopologyComponent extends AbstractTopologyComponent {
private OverlayComponent baseOverlayComponent;
private UAVReplacementCharger charger;
private BaseToUAVInterface controllerInterface;
public BaseTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
super(host, topology, movementModel, placementModel,
registerAsInformationProviderInSiS);
// TODO Auto-generated constructor stub
}
@Override
public void initialize() {
super.initialize();
try {
charger = getHost().getComponent(UAVReplacementCharger.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("Unable to retrieve Replacement Charger for Base!");
}
}
@Override
public double getMinMovementSpeed() {
throw new UnsupportedOperationException();
}
@Override
public double getMaxMovementSpeed() {
throw new UnsupportedOperationException();
}
@Override
public double getMovementSpeed() {
throw new UnsupportedOperationException();
}
@Override
public void setMovementSpeed(double speed) {
throw new UnsupportedOperationException();
}
@Override
public Set<IAttractionPoint> getAllAttractionPoints() {
throw new UnsupportedOperationException();
}
@Override
public void setTargetAttractionPoint(IAttractionPoint targetAttractionPoint) {
throw new UnsupportedOperationException();
}
@Override
public IAttractionPoint getCurrentTargetAttractionPoint() {
throw new UnsupportedOperationException();
}
public void setOverlayComponent(OverlayComponent component) {
this.baseOverlayComponent = component;
}
public OverlayComponent getBaseComponent() {
return baseOverlayComponent;
}
public UAVReplacementCharger getCharger() {
return charger;
}
public void setControllerInterface(BaseToUAVInterface controllerInterface) {
this.controllerInterface = controllerInterface;
}
public void connectUAVToBase(UAVToBaseInterface uav) {
this.controllerInterface.connectUAVtoBase(uav);
}
public void disconnectUAVFromBase(UAVToBaseInterface uav) {
this.controllerInterface.disconnectUAV(uav);
}
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new BaseTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
}
/*
* 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.topology.component;
import java.util.Random;
import java.util.Set;
import de.tud.kom.p2psim.api.common.HostProperties;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Default implementation of a {@link TopologyComponent}.
*
* @author Bjoern Richerzhagen, Julian Zobel
* @version 2.0, 05.09.2018
*/
public class DefaultTopologyComponent extends AbstractTopologyComponent {
protected static Random rnd = Randoms.getRandom(DefaultTopologyComponent.class);
private double currentMovementSpeed = -1;
/**
* Create a TopologyComponent for the current host.
*
* @param host
* @param topology
* @param movementModel
*/
public DefaultTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
@Override
public void initialize() {
super.initialize();
}
@Override
public double getMinMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMinMovementSpeed();
}
@Override
public double getMaxMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
}
private void calcRandomMovementSpeed() {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentMovementSpeed = (value * (max_speed - min_speed))
+ min_speed;
}
@Override
public double getMovementSpeed() {
if (currentMovementSpeed == -1) {
calcRandomMovementSpeed();
}
return this.currentMovementSpeed;
}
@Override
public void setMovementSpeed(double speed) {
this.currentMovementSpeed = speed;
}
@Override
public void setTargetAttractionPoint(IAttractionPoint targetAttractionPoint)
throws UnsupportedOperationException {
movementModel.changeTargetLocation(this, targetAttractionPoint);
}
@Override
public IAttractionPoint getCurrentTargetAttractionPoint() {
return movementModel.getTargetLocation(this);
}
@Override
public Set<IAttractionPoint> getAllAttractionPoints() {
return movementModel.getAllAttractionPoints();
}
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new DefaultTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
}
/*
* 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.topology.component;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
public interface TopologyComponentFactory {
public TopologyComponent createTopologyComponent(SimHost host, Topology topology, MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS);
}
/*
* 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.topology.component;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.Analyzer;
public interface UAVStatisticAnalyzer extends Analyzer {
public void uavSwitchedStates(UAVTopologyComponent uav, UAVTopologyComponent.UAVstate newState);
}
/*
* 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.topology.component;
import java.util.LinkedList;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.energy.RechargeableBattery;
import de.tud.kom.p2psim.impl.energy.components.ActuatorComponent;
import de.tud.kom.p2psim.impl.energy.models.AbstractEnergyModel;
import de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseInterface;
/**
* Topology component extension prividing a broader topology functionality for UAVs
*
* @author Julian Zobel
* @version 1.0, 06.09.2018
*/
public class UAVTopologyComponent extends AbstractTopologyComponent implements SimUAVLocationActuator {
public enum UAVstate {OFFLINE, BASE_CONNECTION, ACTION, RETURN, CRASHED}
private UAVMovementModel movement;
private OverlayComponent uavOverlayComponent;
protected PositionVector direction;
private ActuatorComponent actuator;
private RechargeableBattery battery;
private UAVstate state = UAVstate.OFFLINE;
private PositionVector baseLocation;
private UAVToBaseInterface controllerInterface;
/**
* Create a TopologyComponent for the current host.
*
* @param host
* @param topology
* @param movementModel
*/
public UAVTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
direction = new PositionVector(0,-1,0);
}
@Override
public void initialize() {
super.initialize();
try {
actuator = getHost().getComponent(EnergyModel.class)
.getComponent(ComponentType.ACTUATOR, ActuatorComponent.class);
movement.setMotorControl(actuator);
} catch (ComponentNotAvailableException e) {
System.err.println("No Acutator Energy Component was found!");
}
try {
battery = (RechargeableBattery) getHost().getComponent(AbstractEnergyModel.class).getBattery();
} catch (ComponentNotAvailableException e) {
System.err.println("No Battery Component was found!");
}
// retrieve base location
baseLocation = UAVBasePlacement.base.position.clone();
}
public void setState(UAVstate newState) {
this.state = newState;
// TODO analyzer
if(Monitor.hasAnalyzer(UAVStatisticAnalyzer.class)) {
Monitor.getOrNull(UAVStatisticAnalyzer.class).uavSwitchedStates(this, newState);
}
}
public void setUAVComponent(OverlayComponent uavOverlayComponent) {
this.uavOverlayComponent = uavOverlayComponent;
}
public OverlayComponent getUAVComponent() {
return uavOverlayComponent;
}
@Override
public double getMinMovementSpeed() {
return movement.getHorizontalMinVelocity();
}
@Override
public double getMaxMovementSpeed() {
return movement.getHorizontalMaxVelocity();
}
@Override
public double getMovementSpeed() {
return movement.getCurrentVelocity();
}
@Override
public void setMovementSpeed(double speed) {
movement.setTargetVelocity(speed);
}
@Override
public boolean isActive() {
if(actuator.isOn()) {
return true;
} else {
if(state == UAVstate.ACTION || state == UAVstate.RETURN) {
this.deactivate();
}
return false;
}
}
@Override
public boolean activate() {
if(actuator.turnOn()) {
this.setState(UAVstate.ACTION);
return true;
}
else {
return false;
}
}
@Override
public boolean deactivate() {
actuator.turnOff();
if(this.position.getAltitude() != 0) {
this.setState(UAVstate.CRASHED);
uavOverlayComponent.shutdown();
shutdownCommunication();
} else {
this.setState(UAVstate.OFFLINE);
}
return true;
}
@Override
public PositionVector getCurrentLocation() {
return position.clone();
}
@Override
public double getCurrentBatteryLevel() {
return battery.getCurrentPercentage();
}
@Override
public double getCurrentBatteryEnergy() {
return battery.getCurrentEnergy();
}
public RechargeableBattery getBattery() {
return battery;
}
@Override
public double getMaximumBatteryCapacity() {
return battery.getMaximumEnergy();
}
@Override
public UAVMovementModel getUAVMovement() {
return movement;
}
@Override
public void setUAVMovement(UAVMovementModel uavMovement) {
this.movement = uavMovement;
}
@Override
public Set<IAttractionPoint> getAllAttractionPoints() {
throw new UnsupportedOperationException();
}
@Override
public void setTargetLocation(PositionVector targetLocation,
ReachedLocationCallback cb) {
movement.setTargetLocation(new PositionVector(targetLocation), cb);
}
@Override
public void addTargetLocation(PositionVector targetLocation,
ReachedLocationCallback cb) {
movement.addTargetLocation(new PositionVector(targetLocation), cb);
}
@Override
public void setTargetLocationRoute(LinkedList<PositionVector> route,
ReachedLocationCallback cb) {
LinkedList<PositionVector> positionvectorlist = new LinkedList<>();
for (Location loc : route) {
positionvectorlist.add(new PositionVector(loc));
}
movement.setTargetLocationRoute(positionvectorlist, cb);
}
@Override
public void removeAllTargetLocations() {
movement.removeTargetLocations();
}
@Override
public void setTargetAttractionPoint(IAttractionPoint targetAttractionPoint) {
throw new UnsupportedOperationException();
}
@Override
public IAttractionPoint getCurrentTargetAttractionPoint() {
throw new UnsupportedOperationException();
}
@Override
public LinkedList<PositionVector> getTargetLocations() {
return movement.getTargetLocations();
}
public UAVstate getUAVState() {
return state;
}
@Override
public void returnToBase(ReachedLocationCallback cb) {
this.setState(UAVstate.RETURN);
ReachedLocationCallback returnCallback = new ReachedLocationCallback() {
@Override
public void reachedLocation() {
deactivate();
cb.reachedLocation();
}
};
movement.setTargetVelocity(movement.getHorizontalMaxVelocity());
movement.setTargetLocation(baseLocation, returnCallback);
}
public void batteryReplacement(BatteryReplacementCallback cb) {
if(state != UAVstate.BASE_CONNECTION) {
throw new UnsupportedOperationException("Cannot recharge if not connected to base!");
}
BaseTopologyComponent base = UAVBasePlacement.base;
base.getCharger().charge(this, cb);
}
public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface;
}
@Override
public void connectToBase(BaseConnectedCallback cb) {
BaseTopologyComponent base = UAVBasePlacement.base;
base.connectUAVToBase(controllerInterface);
if(cb != null)
cb.successfulConnection();
this.setState(UAVstate.BASE_CONNECTION);
shutdownCommunication();
}
@Override
public void disconnectFromBase(BaseDisconnectedCallback cb) {
startCommunication();
BaseTopologyComponent base = UAVBasePlacement.base;
base.disconnectUAVFromBase(controllerInterface);
if(cb != null)
cb.successfulDisconnection();
}
private void shutdownCommunication() {
for (SimNetInterface net : getHost().getNetworkComponent().getSimNetworkInterfaces())
net.goOffline();
}
private void startCommunication() {
for (SimNetInterface net : getHost().getNetworkComponent().getSimNetworkInterfaces())
net.goOnline();
}
@Override
public PositionVector getCurrentDirection() {
return direction;
}
@Override
public void updateCurrentDirection(PositionVector direction) {
this.direction.set(direction);
}
@Override
public double estimatePowerConsumptionWatt(double velocity) {
return movement.estimatePowerConsumptionWatt(velocity);
}
@Override
public double estimateFlightDistance(double velocity, double batterylevel, double batterythreshold) {
assert batterylevel > batterythreshold;
assert batterylevel <= 1.0 && batterylevel >= 0.0;
assert batterythreshold <= 1.0 && batterythreshold >= 0.0;
double availableEnergy = (battery.getMaximumEnergy() * (batterylevel - batterythreshold)) / Battery.uJconverison; // since battery energy is in uJ, conversion in J is required
double powerconsumption = estimatePowerConsumptionWatt(velocity); // J/s (or Watt)
double distance = (availableEnergy / powerconsumption) * velocity; // d = (E/P)* v [m]
return distance;
}
@Override
public PositionVector getBaseLocation() {
return baseLocation.clone();
}
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
PlacementModel placementModel,
boolean registerAsInformationProviderInSiS) {
return new UAVTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
}
}
...@@ -20,29 +20,21 @@ ...@@ -20,29 +20,21 @@
package de.tud.kom.p2psim.impl.topology.movement; package de.tud.kom.p2psim.impl.topology.movement;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.TopologyFactory; import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* Unified movement Models. Can be used inside an Application (virtual Position) * Unified movement Models. Can be used inside an Application (virtual Position)
...@@ -98,7 +90,7 @@ public abstract class AbstractMovementModel implements MovementModel { ...@@ -98,7 +90,7 @@ public abstract class AbstractMovementModel implements MovementModel {
public void addComponent(SimLocationActuator component) { public void addComponent(SimLocationActuator component) {
if (worldDimensions == null) { if (worldDimensions == null) {
worldDimensions = Binder.getComponentOrNull(Topology.class) worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions(); .getWorldDimensions();
} }
components.add(component); components.add(component);
} }
...@@ -132,8 +124,8 @@ public abstract class AbstractMovementModel implements MovementModel { ...@@ -132,8 +124,8 @@ public abstract class AbstractMovementModel implements MovementModel {
double minLength, double maxLength) { double minLength, double maxLength) {
assert minLength <= maxLength; assert minLength <= maxLength;
PositionVector delta = null; PositionVector delta = null;
if (oldPosition.getDimensions() == 2) { if (oldPosition.getDimensions() == 2 || (oldPosition.getDimensions() == 3 && oldPosition.getAltitude() == 0)) {
double angle = random.nextDouble() * 2 * Math.PI; double angle = random.nextDouble() * 2 * Math.PI;
double length = random.nextDouble() * (maxLength - minLength) double length = random.nextDouble() * (maxLength - minLength)
+ minLength; + minLength;
...@@ -156,7 +148,9 @@ public abstract class AbstractMovementModel implements MovementModel { ...@@ -156,7 +148,9 @@ public abstract class AbstractMovementModel implements MovementModel {
* @return * @return
*/ */
protected boolean isValidPosition(PositionVector vector) { protected boolean isValidPosition(PositionVector vector) {
for (int i = 0; i < vector.getDimensions(); i++) { for (int i = 0; i < vector.getDimensions(); i++) {
if (vector.getEntry(i) > getWorldDimension(i) if (vector.getEntry(i) > getWorldDimension(i)
|| vector.getEntry(i) < 0) { || vector.getEntry(i) < 0) {
return false; return false;
......
...@@ -25,7 +25,6 @@ import java.util.Random; ...@@ -25,7 +25,6 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy; import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
...@@ -33,16 +32,14 @@ import de.tud.kom.p2psim.api.topology.placement.PlacementModel; ...@@ -33,16 +32,14 @@ import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After; import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure; import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.TopologyFactory; import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.Either; import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader; import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level; import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
......
...@@ -35,8 +35,8 @@ import java.util.zip.GZIPInputStream; ...@@ -35,8 +35,8 @@ import java.util.zip.GZIPInputStream;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.DefaultTopologyComponent; import de.tud.kom.p2psim.impl.topology.component.DefaultTopologyComponent;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
......
...@@ -35,17 +35,17 @@ import de.tud.kom.p2psim.api.topology.Topology; ...@@ -35,17 +35,17 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation; import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel; import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.FixedAssignmentStrategy; import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.FixedAssignmentStrategy;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* Movement of the {@link AttractionPoint}s in the {@link ModularMovementModel}. * Movement of the {@link IAttractionPoint}s in the {@link ModularMovementModel}.
* {@link AttractionPoint}s follow path given via a .csv file. * {@link IAttractionPoint}s follow path given via a .csv file.
* *
* @author Nils Richerzhagen * @author Nils Richerzhagen
* @version 1.0, 02.08.2014 * @version 1.0, 02.08.2014
...@@ -141,7 +141,7 @@ public class CsvMovement extends AbstractMovementModel { ...@@ -141,7 +141,7 @@ public class CsvMovement extends AbstractMovementModel {
double yDelta = (targetPos.getY() - actPos.getY()) / steps; double yDelta = (targetPos.getY() - actPos.getY()) / steps;
String groupId = transitionStrategy String groupId = transitionStrategy
.getGroupIdOfAttractionPoint((AttractionPoint) comp); .getGroupIdOfAttractionPoint((IAttractionPoint) comp);
if (!(groupId == null)) { if (!(groupId == null)) {
......
...@@ -25,7 +25,7 @@ import java.util.Map; ...@@ -25,7 +25,7 @@ import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......
...@@ -27,7 +27,7 @@ import java.util.Set; ...@@ -27,7 +27,7 @@ import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation; import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.stat.distributions.NormalDistribution; import de.tud.kom.p2psim.impl.util.stat.distributions.NormalDistribution;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
......
...@@ -29,9 +29,9 @@ import de.tud.kom.p2psim.api.network.SimNetInterface; ...@@ -29,9 +29,9 @@ import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer; import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
...@@ -39,6 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; ...@@ -39,6 +39,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
// FIXME javaDoc
public class RSUMovementModel implements MovementModel { public class RSUMovementModel implements MovementModel {
private final List<SimLocationActuator> components; private final List<SimLocationActuator> components;
...@@ -113,7 +114,7 @@ public class RSUMovementModel implements MovementModel { ...@@ -113,7 +114,7 @@ public class RSUMovementModel implements MovementModel {
if (_currentIndex < _intersections.size()) { if (_currentIndex < _intersections.size()) {
// Initial placement // Initial placement
Location intersection = _intersections.get(_currentIndex); Location intersection = _intersections.get(_currentIndex);
actuator.updateCurrentLocation(new PositionVector(intersection.getLongitude(), intersection.getLatitude())); actuator.updateCurrentLocation(new PositionVector(intersection.getLongitudeOrX(), intersection.getLatitudeOrY()));
hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex); hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex);
...@@ -141,13 +142,13 @@ public class RSUMovementModel implements MovementModel { ...@@ -141,13 +142,13 @@ public class RSUMovementModel implements MovementModel {
*/ */
protected void initializeModel() { protected void initializeModel() {
if (this.sumoExe != null) { if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); _controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, 1);
_controller.init(); _controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
} else { } else {
_controller = new XMLSimulationController(null, sumoIntersections); _controller = new XMLSimulationController(null, sumoIntersections);
_controller.init(); _controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
} }
......
/*
* 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.topology.movement;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RandomFixedWaypointMovement extends AbstractWaypointMovementModel {
private Random random = Randoms
.getRandom(RandomFixedWaypointMovement.class);
@XMLConfigurableConstructor({"worldX", "worldY"})
public RandomFixedWaypointMovement(double worldX, double worldY) {
super(worldX, worldY);
}
@Override
public void nextPosition(SimLocationActuator component) {
if (waypointModel == null) {
throw new ConfigurationException("SLAWMovementModel requires a valid waypoint model which hasn't been provided, cannot execute");
}
List<Waypoint> waypoints = Lists.newArrayList(waypointModel.getWaypoints(WeakWaypoint.class));
nextDestination(component, waypoints.get(random.nextInt(waypoints.size())).getPosition(), 0);
}
}
...@@ -23,13 +23,16 @@ package de.tud.kom.p2psim.impl.topology.movement; ...@@ -23,13 +23,16 @@ package de.tud.kom.p2psim.impl.topology.movement;
import java.util.Set; import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/** /**
* Mainly for testing: random movement * Mainly for testing: random movement
* *
* @author Bjoern Richerzhagen, adapted from ido.MoveModels * Update (JZ): Added position validation, such that the newly calculated positions do not
* @version 1.0, mm/dd/2011 * exceed the simulation boundaries.
*
* @author Bjoern Richerzhagen, adapted from ido.MoveModels; Julian Zobel
* @version 1.1, 09.2018
*/ */
public class RandomMovement extends AbstractMovementModel { public class RandomMovement extends AbstractMovementModel {
...@@ -39,16 +42,22 @@ public class RandomMovement extends AbstractMovementModel { ...@@ -39,16 +42,22 @@ public class RandomMovement extends AbstractMovementModel {
@Override @Override
public void move() { public void move() {
Set<SimLocationActuator> comps = getComponents(); Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) { for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition(); PositionVector pos = comp.getRealPosition();
updatePosition(comp, pos.plus(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed()))); PositionVector newPos;
do {
newPos = pos.plus(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed()));
}
while(!isValidPosition(newPos));
updatePosition(comp, newPos);
} }
} }
} }
...@@ -27,7 +27,7 @@ import java.util.Set; ...@@ -27,7 +27,7 @@ import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.MovementInformation; import de.tud.kom.p2psim.api.topology.movement.MovementInformation;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported; import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
/** /**
......
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