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
...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs; ...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration; import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType; import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.SmartphoneCommunicationEnergyComponent; import de.tud.kom.p2psim.impl.energy.components.SmartphoneCommunicationEnergyComponent;
public class TimeBased implements public class TimeBased implements
EnergyConfiguration<SmartphoneCommunicationEnergyComponent> { EnergyConfiguration<SmartphoneCommunicationEnergyComponent> {
......
...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs; ...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration; import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType; import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.StateEnergyCommunicationComponent; import de.tud.kom.p2psim.impl.energy.components.StateEnergyCommunicationComponent;
/** /**
* This class is a configuration for the * This class is a configuration for the
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
*/ */
package de.tud.kom.p2psim.impl.energy; package de.tud.kom.p2psim.impl.energy.models;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -26,15 +26,12 @@ import java.util.Vector; ...@@ -26,15 +26,12 @@ import java.util.Vector;
import de.tud.kom.p2psim.api.analyzer.EnergyAnalyzer; import de.tud.kom.p2psim.api.analyzer.EnergyAnalyzer;
import de.tud.kom.p2psim.api.common.SimHost; 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.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent; import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyInfo; import de.tud.kom.p2psim.api.energy.EnergyInfo;
import de.tud.kom.p2psim.api.energy.EnergyModel; import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
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;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
...@@ -47,32 +44,25 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationN ...@@ -47,32 +44,25 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationN
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
/** /**
* The default energy model that is composed of different * The default functionalities for energy models, composed of different
* {@link EnergyComponent}s and configured via the factory. In contrast to the * {@link EnergyComponent}s and configured via the factory.
* <i>old</i> EnergyModels these are Host components, ie. there is one instance
* for each host.
* *
* @author Bjoern Richerzhagen * @author Julian Zobel
* @version 1.0, 27.02.2012 * @version 1.0, 07.09.2018
*/ */
public class ModularEnergyModel implements EnergyModel, EnergyEventListener, public abstract class AbstractEnergyModel implements EnergyModel, BatterySensor, EnergyInfo {
EnergyInfo, BatterySensor {
protected SimHost host;
// private static Logger log = protected List<EnergyComponent> energyComponents;
// SimLogger.getLogger(ModularEnergyModel.class); protected Battery bat;
private SimHost host;
public AbstractEnergyModel(SimHost host, Battery bat) {
private List<EnergyComponent> energyComponents;
private Battery bat;
public ModularEnergyModel(SimHost host, Battery bat) {
energyComponents = new Vector<EnergyComponent>(); energyComponents = new Vector<EnergyComponent>();
this.bat = bat; this.bat = bat;
this.host = host; this.host = host;
} }
@Override @Override
public void initialize() { public void initialize() {
// //
...@@ -137,13 +127,7 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener, ...@@ -137,13 +127,7 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
// OK // OK
} }
} }
@Override
public void shutdown() {
throw new AssertionError(
"You are not supposed to shutdown this component.");
}
@Override @Override
public <T extends EnergyComponent> List<T> getComponents( public <T extends EnergyComponent> List<T> getComponents(
ComponentType type, Class<T> componentClass) { ComponentType type, Class<T> componentClass) {
...@@ -168,15 +152,15 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener, ...@@ -168,15 +152,15 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
} }
return null; return null;
} }
@Override @Override
public EnergyInfo getInfo() { public EnergyInfo getEnergyInfo() {
/* /*
* We export our status to interested applications via this interface * We export our status to interested applications via this interface
*/ */
return this; return this;
} }
@Override @Override
public Battery getBattery() { public Battery getBattery() {
return bat; return bat;
...@@ -189,68 +173,47 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener, ...@@ -189,68 +173,47 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
@Override @Override
public double getCurrentEnergyLevel() { public double getCurrentEnergyLevel() {
return bat.getCurrentEnergyLevel(); return bat.getCurrentEnergy();
} }
@Override @Override
public void registerComponent(EnergyComponent comp) { public SimHost getHost() {
comp.setEnergyEventListener(this); return host;
energyComponents.add(comp);
} }
@Override @Override
public void switchedState(EnergyComponent component, EnergyState oldState, public void shutdown() {
EnergyState newState, long timeSpentInOldState) { throw new AssertionError(
"You are not supposed to shutdown this component.");
if (!bat.isEmpty()) {
double consumedEnergy = oldState.getEnergyConsumption()
* (timeSpentInOldState / (double) Time.SECOND);
bat.consumeEnergy(consumedEnergy);
/*
* TODO Refactor the Energy-Analyzer to support EnergyComponents
* directly, rather than strings.
*/
try {
Monitor.get(EnergyAnalyzer.class).consumeEnergy(getHost(),
consumedEnergy, component);
} catch (AnalyzerNotAvailableException e1) {
//
}
// log.debug(component.toString() + " consumed " + consumedEnergy
// + " uJ in State " + oldState.getName() + " after spending "
// + (timeSpentInOldState/Simulator.SECOND_UNIT) + " sec there.");
if (bat.isEmpty()) {
/*
* Battery is now empty. Go offline.
*/
try {
Monitor.get(EnergyAnalyzer.class).batteryIsEmpty(getHost());
} catch (AnalyzerNotAvailableException e) {
//
}
for (SimNetInterface net : getHost().getNetworkComponent()
.getSimNetworkInterfaces()) {
net.goOffline();
}
}
}
} }
@Override @Override
public boolean turnOn(EnergyComponent component) { public void reset() {
return !bat.isEmpty(); throw new AssertionError(
"You are not supposed to reset this component.");
} }
@Override protected void monitorEnergyConsumation(EnergyComponent component, double consumedEnergy) {
public SimHost getHost() { /*
return host; * TODO Refactor the Energy-Analyzer to support EnergyComponents
* directly, rather than strings.
*/
try {
Monitor.get(EnergyAnalyzer.class).consumeEnergy(getHost(),
consumedEnergy, component);
} catch (AnalyzerNotAvailableException e1) {
//
}
} }
@Override protected void monitorEmptyBattery() {
public void reset() { /*
bat.reset(); * Battery is now empty.
*/
try {
Monitor.get(EnergyAnalyzer.class).batteryIsEmpty(getHost());
} catch (AnalyzerNotAvailableException e) {
//
}
} }
} }
/*
* 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.energy.models;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.impl.energy.components.StatefulActuatorComponent;
/**
* Energy Model based on multiple exchangeable components. Each component states the amount of consumed energy,
* which the energy model than will remove from the battery.
*
* @author Julian Zobel
* @version 1.0, 11.09.2018
*/
public class ComponentBasedEnergyModel extends AbstractEnergyModel implements EnergyEventListener {
public ComponentBasedEnergyModel(SimHost host, Battery bat) {
super(host, bat);
}
@Override
public void registerComponent(EnergyComponent comp) {
energyComponents.add(comp);
comp.setEnergyEventListener(this);
}
@Override
public void componentConsumedEnergy(EnergyComponent component, double consumedEnergy) {
if (!bat.isEmpty()) {
bat.consumeEnergy(consumedEnergy);
monitorEnergyConsumation(component, consumedEnergy);
if (bat.isEmpty()) {
monitorEmptyBattery();
if(component instanceof StatefulActuatorComponent) {
((StatefulActuatorComponent) component).turnOff();
}
/*
* Battery is now empty. Go offline.
*/
for (SimNetInterface net : getHost().getNetworkComponent()
.getSimNetworkInterfaces()) {
net.goOffline();
}
}
}
}
@Override
public boolean componentCanBeActivated(EnergyComponent component) {
if(!bat.isEmpty()) {
return true;
}
return false;
}
}
...@@ -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/>.
* *
...@@ -60,16 +60,16 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetID; ...@@ -60,16 +60,16 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
* As with the {@link ModularLinkLayer} you should extend this class to add a * As with the {@link ModularLinkLayer} you should extend this class to add a
* more advanced MAC to ensure basic functionality and consistent behavior. For * more advanced MAC to ensure basic functionality and consistent behavior. For
* this reason, some methods in this class are marked as final... * this reason, some methods in this class are marked as final...
* *
* If a MAC wants to implement a protocol (ie. send messages to other MACs * If a MAC wants to implement a protocol (ie. send messages to other MACs
* without triggering a deliver to higher layers) it can do so by implementing a * without triggering a deliver to higher layers) it can do so by implementing a
* corresponding Message type and/or {@link MacEventInformation}. <b>A Message * corresponding Message type and/or {@link MacEventInformation}. <b>A Message
* is only delivered to the higher layers if notifyLinkLayer is called</b>. * is only delivered to the higher layers if notifyLinkLayer is called</b>.
* *
* This Layer takes care of energy consumption, as long as the sendUnicast and * This Layer takes care of energy consumption, as long as the sendUnicast and
* sendBroadcast-methods are used to dispatch all messages (also the * sendBroadcast-methods are used to dispatch all messages (also the
* control-messages, if a protocol is implemented) * control-messages, if a protocol is implemented)
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 21.02.2012 * @version 1.0, 21.02.2012
*/ */
...@@ -98,7 +98,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -98,7 +98,7 @@ public abstract class AbstractMacLayer implements MacLayer {
* Our own MacAddress on this PHY * Our own MacAddress on this PHY
*/ */
private MacAddress macAddress; private MacAddress macAddress;
/** /**
* Our own IP used by the NetLayer on this PHY. Not available during initialization. * Our own IP used by the NetLayer on this PHY. Not available during initialization.
*/ */
...@@ -127,7 +127,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -127,7 +127,7 @@ public abstract class AbstractMacLayer implements MacLayer {
private final boolean enableErrorControl; private final boolean enableErrorControl;
/** /**
* *
*/ */
private boolean isOnline; private boolean isOnline;
...@@ -156,7 +156,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -156,7 +156,7 @@ public abstract class AbstractMacLayer implements MacLayer {
* Returns an approximation of the current bandwidth * Returns an approximation of the current bandwidth
*/ */
protected final BandwidthEstimator currentBandwidth; protected final BandwidthEstimator currentBandwidth;
private final Random random = Randoms.getRandom(AbstractMacLayer.class); private final Random random = Randoms.getRandom(AbstractMacLayer.class);
/* /*
...@@ -179,7 +179,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -179,7 +179,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Create a new MacLayer without bounds on the outgoing message queue (ie. * Create a new MacLayer without bounds on the outgoing message queue (ie.
* endless size, no limit on the waiting time). * endless size, no limit on the waiting time).
* *
* @param ownMacAddress * @param ownMacAddress
* @param phy * @param phy
* @param maxRetransmissions * @param maxRetransmissions
...@@ -198,7 +198,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -198,7 +198,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Create a new MacLayer with a bounded outgoing queue (max length) and a * Create a new MacLayer with a bounded outgoing queue (max length) and a
* timeout for messages in said queue. * timeout for messages in said queue.
* *
* @param ownMacAddress * @param ownMacAddress
* @param phy * @param phy
* @param maxQueueLength * @param maxQueueLength
...@@ -291,7 +291,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -291,7 +291,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Use this component to account for energy consumption. This is safe to * Use this component to account for energy consumption. This is safe to
* use, as it is always backed by a stub - it is never null. * use, as it is always backed by a stub - it is never null.
* *
* @return * @return
*/ */
@Override @Override
...@@ -301,7 +301,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -301,7 +301,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Current size of the outgoing Queue * Current size of the outgoing Queue
* *
* @return * @return
*/ */
protected final int getQueueSize() { protected final int getQueueSize() {
...@@ -310,7 +310,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -310,7 +310,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Maximum length of the outgoing queue, if equal to zero there is no limit * Maximum length of the outgoing queue, if equal to zero there is no limit
* *
* @return * @return
*/ */
protected final int getMaxQueueLength() { protected final int getMaxQueueLength() {
...@@ -319,7 +319,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -319,7 +319,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Gets the maximal retransmissions. * Gets the maximal retransmissions.
* *
* @return the maximal retransmissions. * @return the maximal retransmissions.
*/ */
public final int getMaxRetransmissions() { public final int getMaxRetransmissions() {
...@@ -329,7 +329,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -329,7 +329,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Maximum time a message is kept in the outgoing queue. If equal to zero * Maximum time a message is kept in the outgoing queue. If equal to zero
* there is no limit. * there is no limit.
* *
* @return * @return
*/ */
protected final long getMaxTimeInQueue() { protected final long getMaxTimeInQueue() {
...@@ -339,7 +339,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -339,7 +339,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Retrieves and <b>removes</b> the first element in the Queue, after all * Retrieves and <b>removes</b> the first element in the Queue, after all
* entries that already timed out are deleted. * entries that already timed out are deleted.
* *
* @return * @return
*/ */
protected final QueueEntry getQueueHead() { protected final QueueEntry getQueueHead() {
...@@ -351,7 +351,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -351,7 +351,7 @@ public abstract class AbstractMacLayer implements MacLayer {
* Removes all messages that are already waiting longer than maxTimeInQueue, * Removes all messages that are already waiting longer than maxTimeInQueue,
* notifying messageDropped() for each dropped message. The reason will be * notifying messageDropped() for each dropped message. The reason will be
* QUEUE_TIMEOUT in this case. * QUEUE_TIMEOUT in this case.
* *
*/ */
private void removeOutdatedQueueEntries() { private void removeOutdatedQueueEntries() {
if (maxTimeInQueue == 0) { if (maxTimeInQueue == 0) {
...@@ -371,11 +371,11 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -371,11 +371,11 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* This is called whenever a drop occurs within the MAC/PHY. A great * This is called whenever a drop occurs within the MAC/PHY. A great
* opportunity to add an Analyzer or some error handling for higher layers. * opportunity to add an Analyzer or some error handling for higher layers.
* *
* Please note, that this might happen asynchronously - the messages are not * Please note, that this might happen asynchronously - the messages are not
* removed from the queue the second their timeout expires but instead as * removed from the queue the second their timeout expires but instead as
* soon as a new send() or a new getQueueHead() is issued. * soon as a new send() or a new getQueueHead() is issued.
* *
* @param reason * @param reason
* @param msg * @param msg
*/ */
...@@ -402,7 +402,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -402,7 +402,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Notification: a message arrived! * Notification: a message arrived!
* *
* @param message * @param message
* the message itself * the message itself
* @param info * @param info
...@@ -413,7 +413,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -413,7 +413,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* This is to be called by the MAC if a Message should be passed to upper * This is to be called by the MAC if a Message should be passed to upper
* layers (ie. it is no MAC_ctrl-Message) * layers (ie. it is no MAC_ctrl-Message)
* *
* @param eventInfo * @param eventInfo
*/ */
protected final void notifyLinkLayer(LinkMessageEvent eventInfo) { protected final void notifyLinkLayer(LinkMessageEvent eventInfo) {
...@@ -424,7 +424,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -424,7 +424,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Send a Message to the MAC on the receiver-side (event scheduling). * Send a Message to the MAC on the receiver-side (event scheduling).
* *
* @param receiver * @param receiver
* @param eventInformation * @param eventInformation
* @param delay * @param delay
...@@ -454,7 +454,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -454,7 +454,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Use this method to dispatch a broadcast message in your MAC-Layer. It * Use this method to dispatch a broadcast message in your MAC-Layer. It
* will take care of energy consumption and scheduling. * will take care of energy consumption and scheduling.
* *
* @param eventInfo * @param eventInfo
* an implementation of {@link MacEventInformation} containing * an implementation of {@link MacEventInformation} containing
* information about the message to send as well as the message * information about the message to send as well as the message
...@@ -516,7 +516,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -516,7 +516,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Send an unicast message * Send an unicast message
* *
* @param toSend * @param toSend
*/ */
protected final long sendUnicast(MacEventInformation eventInfo) { protected final long sendUnicast(MacEventInformation eventInfo) {
...@@ -592,13 +592,13 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -592,13 +592,13 @@ public abstract class AbstractMacLayer implements MacLayer {
* broadcast, the BW should be constant across all links (we assume the PHY * broadcast, the BW should be constant across all links (we assume the PHY
* selects a fixed, more robust modulation for Broadcasts), as there is no * selects a fixed, more robust modulation for Broadcasts), as there is no
* handshaking. Therefore, Broadcasts have no retransmits. * handshaking. Therefore, Broadcasts have no retransmits.
* *
* This method <b>must be called exactly once</b> for every receiver of a * This method <b>must be called exactly once</b> for every receiver of a
* message (in the unicast case, it will be called only once). The receiver * message (in the unicast case, it will be called only once). The receiver
* is determined by the link-object. Access this method via the sendUnicast * is determined by the link-object. Access this method via the sendUnicast
* and sendBroadcast methods to ensure correct behavior of all callbacks and * and sendBroadcast methods to ensure correct behavior of all callbacks and
* events. * events.
* *
* @param eventInfo * @param eventInfo
* containing the Message * containing the Message
* @param l * @param l
...@@ -758,10 +758,10 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -758,10 +758,10 @@ public abstract class AbstractMacLayer implements MacLayer {
* sending would be possible at the full RawBandwidth of the PHY). A more * sending would be possible at the full RawBandwidth of the PHY). A more
* advanced MAC will add some coding (making the message larger) and access * advanced MAC will add some coding (making the message larger) and access
* control scheme for multiple transmissions. * control scheme for multiple transmissions.
* *
* This time is later used to account for energy consumption at sender and * This time is later used to account for energy consumption at sender and
* receiver. * receiver.
* *
* @param msg * @param msg
* @param l * @param l
* @return * @return
...@@ -782,7 +782,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -782,7 +782,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* Overwrite this method to implement additional event handling, if needed. * Overwrite this method to implement additional event handling, if needed.
* *
* @param se * @param se
*/ */
protected void handleEvent(Object data, int type) { protected void handleEvent(Object data, int type) {
...@@ -873,21 +873,23 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -873,21 +873,23 @@ public abstract class AbstractMacLayer implements MacLayer {
messageDropped(DropReason.QUEUE_FULL, message); messageDropped(DropReason.QUEUE_FULL, message);
// FIXME BR DEBUG Print it // FIXME BR DEBUG Print it
// int idx = 0; // System.out.println("[AbstractMacLayer] debug output");
// for (QueueEntry qe : queue) { // int idx = 0;
// Message msg = qe.getMessage(); // for (QueueEntry qe : queue) {
// while (msg.getPayload() != null) { // Message msg = qe.getMessage();
// msg = msg.getPayload(); // while (msg.getPayload() != null) {
// } // msg = msg.getPayload();
// System.out.println(idx + " " // }
// + msg.getClass().getSimpleName() + " " // System.out.println(idx + " "
// + msg.toString()); // + msg.getClass().getSimpleName() + " "
// idx++; // + msg.toString());
// } // idx++;
// }
} else { } else {
// still a spot in the queue, add message and notify MAC // still a spot in the queue, add message and notify MAC
queue.add(new QueueEntry(receiver, message)); queue.add(new QueueEntry(receiver, message));
handleNewQueueEntry(); handleNewQueueEntry();
} }
} }
} }
...@@ -896,7 +898,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -896,7 +898,7 @@ public abstract class AbstractMacLayer implements MacLayer {
public final MacAddress getMacAddress() { public final MacAddress getMacAddress() {
return macAddress; return macAddress;
} }
@Override @Override
public NetID getNetId() { public NetID getNetId() {
if (netID == null) { if (netID == null) {
...@@ -926,7 +928,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -926,7 +928,7 @@ public abstract class AbstractMacLayer implements MacLayer {
/** /**
* An entry in the Message queue of the MAC * An entry in the Message queue of the MAC
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 21.02.2012 * @version 1.0, 21.02.2012
*/ */
...@@ -965,7 +967,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -965,7 +967,7 @@ public abstract class AbstractMacLayer implements MacLayer {
* A Stub for an {@link EnergyCommunicationComponent} to allow simulations * A Stub for an {@link EnergyCommunicationComponent} to allow simulations
* without an energy model. Otherwise we would have to flood the code with * without an energy model. Otherwise we would have to flood the code with
* if == null statements. * if == null statements.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 27.02.2012 * @version 1.0, 27.02.2012
*/ */
...@@ -1011,8 +1013,9 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -1011,8 +1013,9 @@ public abstract class AbstractMacLayer implements MacLayer {
} }
@Override @Override
public void turnOff() { public boolean turnOff() {
on = false; on = false;
return true;
} }
public boolean turnOn() { public boolean turnOn() {
...@@ -1028,14 +1031,14 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -1028,14 +1031,14 @@ public abstract class AbstractMacLayer implements MacLayer {
@Override @Override
public void doFakeStateChange() { public void doFakeStateChange() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }
/** /**
* A Live-Analyzer that aggregates Message Drop reasons inside the MAC. * A Live-Analyzer that aggregates Message Drop reasons inside the MAC.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 26.03.2012 * @version 1.0, 26.03.2012
*/ */
...@@ -1066,7 +1069,7 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -1066,7 +1069,7 @@ public abstract class AbstractMacLayer implements MacLayer {
out.append(reason.toString()); out.append(reason.toString());
out.append(": "); out.append(": ");
out.append(_messageDropCounters[reason.ordinal()]); out.append(_messageDropCounters[reason.ordinal()]);
out.append("\n"); out.append(" | \n");
} }
return out.toString(); return out.toString();
} }
......
...@@ -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/>.
* *
...@@ -37,7 +37,7 @@ import de.tudarmstadt.maki.simonstrator.api.Time; ...@@ -37,7 +37,7 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
* the other (this does not imply that this MAC handles collisions on a * the other (this does not imply that this MAC handles collisions on a
* broadcast medium). It just mimics the behavior of the ModularNetLayer with a * broadcast medium). It just mimics the behavior of the ModularNetLayer with a
* TrafficControl-Strategy enabled. * TrafficControl-Strategy enabled.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 24.03.2012 * @version 1.0, 24.03.2012
*/ */
...@@ -64,7 +64,7 @@ public class EnqueuingMac extends AbstractMacLayer { ...@@ -64,7 +64,7 @@ public class EnqueuingMac extends AbstractMacLayer {
* A MAC that provides an outgoing queue (messages are sent one after the * A MAC that provides an outgoing queue (messages are sent one after the
* other). This may lead to packet drop if the queue is bound or if a * other). This may lead to packet drop if the queue is bound or if a
* timeout is configured and the message has been in the queue for too long. * timeout is configured and the message has been in the queue for too long.
* *
* @param ownMacAddress * @param ownMacAddress
* @param phy * @param phy
* @param maxQueueLength * @param maxQueueLength
......
...@@ -46,7 +46,7 @@ import de.tud.kom.p2psim.impl.linklayer.DefaultLinkMessageEvent; ...@@ -46,7 +46,7 @@ import de.tud.kom.p2psim.impl.linklayer.DefaultLinkMessageEvent;
import de.tud.kom.p2psim.impl.linklayer.mac.AbstractMacLayer; import de.tud.kom.p2psim.impl.linklayer.mac.AbstractMacLayer;
import de.tud.kom.p2psim.impl.linklayer.mac.wifi.AbstractRateManager.RateManagerTypes; import de.tud.kom.p2psim.impl.linklayer.mac.wifi.AbstractRateManager.RateManagerTypes;
import de.tud.kom.p2psim.impl.linklayer.mac.wifi.DcfManager.WifiState; import de.tud.kom.p2psim.impl.linklayer.mac.wifi.DcfManager.WifiState;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.wifi.WifiTopologyView; import de.tud.kom.p2psim.impl.topology.views.wifi.WifiTopologyView;
import de.tud.kom.p2psim.impl.util.LiveMonitoring; import de.tud.kom.p2psim.impl.util.LiveMonitoring;
import de.tud.kom.p2psim.impl.util.LiveMonitoring.ProgressValue; import de.tud.kom.p2psim.impl.util.LiveMonitoring.ProgressValue;
......
...@@ -34,7 +34,7 @@ import de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup; ...@@ -34,7 +34,7 @@ import de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup;
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.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import umontreal.iro.lecuyer.probdist.LognormalDist; import umontreal.ssj.probdist.LognormalDist;
public class GnpLatencyModel implements NetLatencyModel { public class GnpLatencyModel implements NetLatencyModel {
......
...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.network.gnp.topology; ...@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.network.gnp.topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
......
...@@ -319,12 +319,12 @@ public class GnpPosition implements Location, Comparable<GnpPosition> { ...@@ -319,12 +319,12 @@ public class GnpPosition implements Location, Comparable<GnpPosition> {
} }
@Override @Override
public double getLatitude() { public double getLatitudeOrY() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public double getLongitude() { public double getLongitudeOrX() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
...@@ -35,7 +35,6 @@ import java.util.Set; ...@@ -35,7 +35,6 @@ import java.util.Set;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.tree.DefaultElement; import org.dom4j.tree.DefaultElement;
import umontreal.iro.lecuyer.probdist.LognormalDist;
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.network.modular.db.NetMeasurementDB.Country; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.Country;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.GlobalSummaryRelation; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.GlobalSummaryRelation;
...@@ -44,6 +43,7 @@ import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.RegionRegionSu ...@@ -44,6 +43,7 @@ import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.RegionRegionSu
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.SummaryRelation; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.SummaryRelation;
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 umontreal.ssj.probdist.LognormalDist;
/** /**
* This Class Implements a container for the PingER summary reports used as a * This Class Implements a container for the PingER summary reports used as a
......
...@@ -23,8 +23,7 @@ package de.tud.kom.p2psim.impl.network.modular.common; ...@@ -23,8 +23,7 @@ package de.tud.kom.p2psim.impl.network.modular.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import umontreal.ssj.probdist.LognormalDist;
import umontreal.iro.lecuyer.probdist.LognormalDist;
/** /**
* *
......
...@@ -36,7 +36,6 @@ import javax.xml.parsers.ParserConfigurationException; ...@@ -36,7 +36,6 @@ import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tud.kom.p2psim.impl.network.IPv4NetID; import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.network.modular.common.PingErToolkit; import de.tud.kom.p2psim.impl.network.modular.common.PingErToolkit;
import de.tud.kom.p2psim.impl.util.BackToXMLWritable; import de.tud.kom.p2psim.impl.util.BackToXMLWritable;
...@@ -44,6 +43,7 @@ import de.tud.kom.p2psim.impl.util.SymmetricRelation; ...@@ -44,6 +43,7 @@ import de.tud.kom.p2psim.impl.util.SymmetricRelation;
import de.tud.kom.p2psim.impl.util.Tuple; import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.db.relational.DBInstantiationException; import de.tud.kom.p2psim.impl.util.db.relational.DBInstantiationException;
import de.tud.kom.p2psim.impl.util.db.relational.RelationalDB; import de.tud.kom.p2psim.impl.util.db.relational.RelationalDB;
import umontreal.ssj.probdist.LognormalDist;
/** /**
* Database format for measurements of network characteristics for the Modular Network Layer. * Database format for measurements of network characteristics for the Modular Network Layer.
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
package de.tud.kom.p2psim.impl.network.modular.st.jitter; package de.tud.kom.p2psim.impl.network.modular.st.jitter;
import java.util.Random; import java.util.Random;
import umontreal.ssj.probdist.LognormalDist;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tud.kom.p2psim.api.network.NetMessage; import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer; import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB; import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
......
...@@ -28,7 +28,7 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -28,7 +28,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.common.GNPToolkit; import de.tud.kom.p2psim.impl.network.modular.common.GNPToolkit;
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.network.modular.st.PositioningStrategy; import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
......
...@@ -25,7 +25,7 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -25,7 +25,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit; import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit;
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.network.modular.st.PositioningStrategy; import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
......
...@@ -26,7 +26,7 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -26,7 +26,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
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.network.modular.st.PositioningStrategy; import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.network.simple.SimpleSubnet; import de.tud.kom.p2psim.impl.network.simple.SimpleSubnet;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
......
...@@ -26,7 +26,7 @@ import java.util.Random; ...@@ -26,7 +26,7 @@ import java.util.Random;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
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.network.modular.st.PositioningStrategy; import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab * Copyright (c) 2005-2011 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/>.
* *
...@@ -37,6 +37,7 @@ import java.util.Map; ...@@ -37,6 +37,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import javax.sound.midi.Synthesizer;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
...@@ -70,11 +71,11 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; ...@@ -70,11 +71,11 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* The default implementation of the configuration mechanism. For a detailed * The default implementation of the configuration mechanism. For a detailed
* explanation, see {@link Configurator}. * explanation, see {@link Configurator}.
* *
* @author Konstantin Pussep * @author Konstantin Pussep
* @author Sebastian Kaune * @author Sebastian Kaune
* @version 3.0, 14.12.2007 * @version 3.0, 14.12.2007
* *
*/ */
public class DefaultConfigurator implements Configurator { public class DefaultConfigurator implements Configurator {
...@@ -84,7 +85,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -84,7 +85,7 @@ public class DefaultConfigurator implements Configurator {
* this name. They will be treated as if they were direct children of the * this name. They will be treated as if they were direct children of the
* parent of this fake container element. * parent of this fake container element.
* </p> * </p>
* *
* <p> * <p>
* Needed to work around the lack of support for XPointer in the XInclude * Needed to work around the lack of support for XPointer in the XInclude
* implementation of Apache Xerces (which should be the most common * implementation of Apache Xerces (which should be the most common
...@@ -145,10 +146,12 @@ public class DefaultConfigurator implements Configurator { ...@@ -145,10 +146,12 @@ public class DefaultConfigurator implements Configurator {
private Map<String, String> variables = new LinkedHashMap<String, String>(); private Map<String, String> variables = new LinkedHashMap<String, String>();
private boolean _parseOnly = false;
/** /**
* Create new configurator instance with the configuration data in the given * Create new configurator instance with the configuration data in the given
* XML file. * XML file.
* *
* @param file * @param file
* XML config file * XML config file
*/ */
...@@ -158,7 +161,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -158,7 +161,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Gets the name of the configuration file. * Gets the name of the configuration file.
* *
* @return Name of the configuration file. * @return Name of the configuration file.
*/ */
public File getConfigFile() { public File getConfigFile() {
...@@ -167,7 +170,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -167,7 +170,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Return a copy of the map with variables. * Return a copy of the map with variables.
* *
* @return A copy of stored variables. * @return A copy of stored variables.
*/ */
public Map<String, String> getVariables() { public Map<String, String> getVariables() {
...@@ -183,7 +186,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -183,7 +186,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Register a specific component module by the provided name. * Register a specific component module by the provided name.
* *
* @param name * @param name
* unique name for the component module * unique name for the component module
* @param component * @param component
...@@ -199,11 +202,18 @@ public class DefaultConfigurator implements Configurator { ...@@ -199,11 +202,18 @@ public class DefaultConfigurator implements Configurator {
} }
} }
public Map<String, String> parseAllDefaults() throws ConfigurationException {
_parseOnly = true;
configureAll();
_parseOnly = false;
return getVariables();
}
/** /**
* Configure all components of the simulator. The single components are * Configure all components of the simulator. The single components are
* either registered via the <code>register(name, component)</code> method * either registered via the <code>register(name, component)</code> method
* or specified in the config file. * or specified in the config file.
* *
* @return a collection of components. * @return a collection of components.
* @throws ConfigurationException * @throws ConfigurationException
*/ */
...@@ -245,20 +255,20 @@ public class DefaultConfigurator implements Configurator { ...@@ -245,20 +255,20 @@ public class DefaultConfigurator implements Configurator {
return componentList; return componentList;
} catch (DocumentException e) { } catch (DocumentException e) {
throw new ConfigurationException( throw new ConfigurationException(
"Failed to load configuration from file " + configFile, e); "Failed to load configuration from file " + configFile + " (DocumentException)", e);
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
throw new ConfigurationException( throw new ConfigurationException(
"Failed to load configuration from file " + configFile, e); "Failed to load configuration from file " + configFile + " (ParserConfigurationException)", e);
} catch (SAXException e) { } catch (SAXException e) {
throw new ConfigurationException( throw new ConfigurationException(
"Failed to load configuration from file " + configFile, e); "Failed to load configuration from file " + configFile + " (SAXException)", e);
} }
} }
/** /**
* Process the XML subtree. * Process the XML subtree.
* *
* @param parent * @param parent
* root of the subtree * root of the subtree
*/ */
...@@ -273,7 +283,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -273,7 +283,7 @@ public class DefaultConfigurator implements Configurator {
} else if (elem.getName().equals(Configurator.DEFAULT_TAG)) { } else if (elem.getName().equals(Configurator.DEFAULT_TAG)) {
configureDefaults(elem); configureDefaults(elem);
} else { } else {
configureComponent(elem); configureComponent(elem);
} }
} }
} }
...@@ -281,7 +291,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -281,7 +291,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Processes a <code><Default></code> Tag by setting the respective * Processes a <code><Default></code> Tag by setting the respective
* variables. * variables.
* *
* @param defaultElement * @param defaultElement
*/ */
private void configureDefaults(Element elem) { private void configureDefaults(Element elem) {
...@@ -304,13 +314,12 @@ public class DefaultConfigurator implements Configurator { ...@@ -304,13 +314,12 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Create (if not existent yet) and configure a configurable component by * Create (if not existent yet) and configure a configurable component by
* parsing the XML subtree. * parsing the XML subtree.
* *
* @param elem * @param elem
* XML subtree with configuration data * XML subtree with configuration data
* @return configured component * @return configured component
*/ */
public Object configureComponent(Element elem) { public Object configureComponent(Element elem) {
String name = elem.getName(); String name = elem.getName();
if (Configurator.SPECIAL_IF_EQUAL_STR.equalsIgnoreCase(name)) { if (Configurator.SPECIAL_IF_EQUAL_STR.equalsIgnoreCase(name)) {
processIfEqualStr(elem, new ToConfigureCallback() { processIfEqualStr(elem, new ToConfigureCallback() {
...@@ -347,46 +356,56 @@ public class DefaultConfigurator implements Configurator { ...@@ -347,46 +356,56 @@ public class DefaultConfigurator implements Configurator {
Monitor.log(DefaultConfigurator.class, Level.DEBUG, Monitor.log(DefaultConfigurator.class, Level.DEBUG,
"Configure component " + name); "Configure component " + name);
/* if (!_parseOnly) {
* FIXED (BR) - if a component specifies a class-tag, do NOT reuse the /*
* old component for configuration. Instead, create a new component. * FIXED (BR) - if a component specifies a class-tag, do NOT reuse the
*/ * old component for configuration. Instead, create a new component.
// Constructor Attributes */
Object component = configurables.get(name); // Constructor Attributes
Set<String> consAttrs = new HashSet<String>(); Object component = configurables.get(name);
String clazz = getAttributeValue(elem.attribute(CLASS_TAG)); Set<String> consAttrs = new HashSet<String>();
if (clazz != null) { String clazz = getAttributeValue(elem.attribute(CLASS_TAG));
// Create component if (clazz != null) {
component = createComponent(elem, consAttrs); // Create component
} component = createComponent(elem, consAttrs);
}
// configure it
if (component != null) { // configure it
Monitor.log(DefaultConfigurator.class, Level.INFO, if (component != null) {
"Configure component " Monitor.log(DefaultConfigurator.class, Level.INFO,
+ component.getClass().getSimpleName() "Configure component "
+ " with element " + name); + component.getClass().getSimpleName()
configureAttributes(component, elem, consAttrs); + " with element " + name);
// configure subcomponents configureAttributes(component, elem, consAttrs);
if (component instanceof Builder) { // configure subcomponents
Monitor.log(DefaultConfigurator.class, Level.INFO, if (component instanceof Builder) {
"Configure builder " + component); Monitor.log(DefaultConfigurator.class, Level.INFO,
Builder builder = (Builder) component; "Configure builder " + component);
builder.parse(elem, this); Builder builder = (Builder) component;
} else { builder.parse(elem, this);
for (Iterator iter = elem.elementIterator(); iter.hasNext();) { } else {
Element child = (Element) iter.next(); for (Iterator iter = elem.elementIterator(); iter.hasNext();) {
if (!consAttrs.contains(child.getName().toLowerCase())) { Element child = (Element) iter.next();
processChild(component, child, consAttrs); if (!consAttrs.contains(child.getName().toLowerCase())) {
} processChild(component, child, consAttrs);
} }
} }
}
} else {
// component cannot be created and has not been registered
if (!name.equals("Description"))
Monitor.log(DefaultConfigurator.class, Level.WARN,
"Skip element " + name);
}
return component;
} else { } else {
// component cannot be created and has not been registered for (Iterator iter = elem.elementIterator(); iter.hasNext();) {
Monitor.log(DefaultConfigurator.class, Level.WARN, Element child = (Element) iter.next();
"Skip element " + name); processChild(null, child, null);
}
return null;
} }
return component;
} }
private Object createComponent(Element elem, Set<String> consAttrs) { private Object createComponent(Element elem, Set<String> consAttrs) {
...@@ -413,7 +432,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -413,7 +432,7 @@ public class DefaultConfigurator implements Configurator {
} }
/** /**
* *
* @param component * @param component
* @param child * @param child
* @param consAttrs * @param consAttrs
...@@ -455,42 +474,44 @@ public class DefaultConfigurator implements Configurator { ...@@ -455,42 +474,44 @@ public class DefaultConfigurator implements Configurator {
Object subcomponent = configureComponent(child); Object subcomponent = configureComponent(child);
String prefix = SET_METHOD_PREFIX_TAG; if (!_parseOnly) {
String methodName = getMethodName(prefix, child.getName()); String prefix = SET_METHOD_PREFIX_TAG;
Method[] methods = component.getClass().getMethods(); String methodName = getMethodName(prefix, child.getName());
Method match = null; Method[] methods = component.getClass().getMethods();
for (int i = 0; i < methods.length; i++) { Method match = null;
if (methodName.equals(methods[i].getName())) { for (int i = 0; i < methods.length; i++) {
match = methods[i]; if (methodName.equals(methods[i].getName())) {
Monitor.log(DefaultConfigurator.class, Level.DEBUG, match = methods[i];
"Match " + match); Monitor.log(DefaultConfigurator.class, Level.DEBUG,
break; "Match " + match);
} break;
} }
if (match == null) { }
Monitor.log(DefaultConfigurator.class, Level.WARN, if (match == null) {
"Cannot set " + subcomponent + " as there is no method " Monitor.log(DefaultConfigurator.class, Level.WARN,
+ methodName + " declared in " + component); "Cannot set " + subcomponent + " as there is no method "
throw new ConfigurationException( + methodName + " declared in " + component);
"Cannot set " + subcomponent + " as there is no method " throw new ConfigurationException(
+ methodName + " declared in " + component); "Cannot set " + subcomponent + " as there is no method "
} else { + methodName + " declared in " + component);
Class[] types = match.getParameterTypes(); } else {
Monitor.log(DefaultConfigurator.class, Level.DEBUG, Class[] types = match.getParameterTypes();
"Param types" + Arrays.asList(types)); Monitor.log(DefaultConfigurator.class, Level.DEBUG,
if (types.length == 1) { "Param types" + Arrays.asList(types));
try { if (types.length == 1) {
match.invoke(component, types[0].cast(subcomponent)); try {
} catch (Exception e) { match.invoke(component, types[0].cast(subcomponent));
throw new ConfigurationException( } catch (Exception e) {
"Failed to configure " + methodName + " in " throw new ConfigurationException(
+ component + " with " + subcomponent, "Failed to configure " + methodName + " in "
e); + component + " with " + subcomponent,
} e);
} else { }
throw new ConfigurationException("Wrong number of params for " } else {
+ methodName + " in " + component); throw new ConfigurationException("Wrong number of params for "
} + methodName + " in " + component);
}
}
} }
} }
...@@ -585,7 +606,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -585,7 +606,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Automagically convert the string value to desired type. Supported types * Automagically convert the string value to desired type. Supported types
* are all simple types, i.e. boolean, int, long, double. * are all simple types, i.e. boolean, int, long, double.
* *
* @param value * @param value
* @param typeClass * @param typeClass
* @return converted * @return converted
...@@ -628,8 +649,9 @@ public class DefaultConfigurator implements Configurator { ...@@ -628,8 +649,9 @@ public class DefaultConfigurator implements Configurator {
} }
param = lvals; param = lvals;
} else { } else {
throw new IllegalArgumentException( param = value;
"Parameter type " + typeClass + " is not supported"); // throw new IllegalArgumentException(
// "Parameter type " + typeClass + " is not supported");
} }
return param; return param;
} }
...@@ -645,7 +667,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -645,7 +667,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Can be either a variable (if starts with $) or a plain value * Can be either a variable (if starts with $) or a plain value
* *
* @param attr * @param attr
* @return proper value * @return proper value
*/ */
...@@ -693,7 +715,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -693,7 +715,7 @@ public class DefaultConfigurator implements Configurator {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see * @see
* de.tud.kom.p2psim.impl.scenario.ConfigurablesManager#getComponent(java * de.tud.kom.p2psim.impl.scenario.ConfigurablesManager#getComponent(java
* .lang.String) * .lang.String)
...@@ -711,7 +733,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -711,7 +733,7 @@ public class DefaultConfigurator implements Configurator {
* (full) class name and the optional method name. If the method name is * (full) class name and the optional method name. If the method name is
* null, the default constructor will be used. The method's signature should * null, the default constructor will be used. The method's signature should
* have no arguments. * have no arguments.
* *
* @param className * @param className
* @param staticMethod * @param staticMethod
* @param consAttrs * @param consAttrs
...@@ -727,6 +749,9 @@ public class DefaultConfigurator implements Configurator { ...@@ -727,6 +749,9 @@ public class DefaultConfigurator implements Configurator {
if (staticMethod == null) { if (staticMethod == null) {
Constructor[] cs = forName.getConstructors(); Constructor[] cs = forName.getConstructors();
Constructor currentConstructor = null;
String[] usedArgs = null;
Object[] parameters = null;
for (Constructor<?> c : cs) { for (Constructor<?> c : cs) {
XMLConfigurableConstructor a = c XMLConfigurableConstructor a = c
...@@ -759,7 +784,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -759,7 +784,7 @@ public class DefaultConfigurator implements Configurator {
break; break;
} }
consArgs[i] = configureComponent(elem); consArgs[i] = configureComponent(elem);
if (consArgs[i].getClass() if (!consArgs[i].getClass()
.isAssignableFrom(types[i])) .isAssignableFrom(types[i]))
throw new ConfigurationException( throw new ConfigurationException(
"The type of the component configured for the parameter '" "The type of the component configured for the parameter '"
...@@ -777,16 +802,23 @@ public class DefaultConfigurator implements Configurator { ...@@ -777,16 +802,23 @@ public class DefaultConfigurator implements Configurator {
} }
if (!incompatible) { if (!incompatible) {
component = c.newInstance(consArgs); if (currentConstructor == null || parameters.length < consArgs.length) {
currentConstructor = c;
for (String consAttr : cArgs) { parameters = consArgs;
consAttrs.add(consAttr.toLowerCase()); usedArgs = cArgs;
} }
break;
} }
} }
} }
if (currentConstructor != null) {
component = currentConstructor.newInstance(parameters);
for (String consAttr : usedArgs) {
consAttrs.add(consAttr.toLowerCase());
}
}
if (component == null) if (component == null)
component = forName.newInstance(); component = forName.newInstance();
...@@ -807,7 +839,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -807,7 +839,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Set variables with values which replace the variable names in the * Set variables with values which replace the variable names in the
* configuration file. Default values will be overwritten. * configuration file. Default values will be overwritten.
* *
* @param variables * @param variables
*/ */
public void setVariables(Map<String, String> variables) { public void setVariables(Map<String, String> variables) {
...@@ -823,11 +855,11 @@ public class DefaultConfigurator implements Configurator { ...@@ -823,11 +855,11 @@ public class DefaultConfigurator implements Configurator {
* number followed by a "ms", "s", "m" or "h" for milliseconds, seconds * number followed by a "ms", "s", "m" or "h" for milliseconds, seconds
* etc.. The conversion is done according to the constants defined in the * etc.. The conversion is done according to the constants defined in the
* {@link Time} class. * {@link Time} class.
* *
* If no time-unit is found, we search for bandwidth-units and parse * If no time-unit is found, we search for bandwidth-units and parse
* according to the unit, and if that does not work as well, the long is * according to the unit, and if that does not work as well, the long is
* returned. * returned.
* *
* @param value * @param value
* - time value to parse * - time value to parse
* @return parsed value * @return parsed value
...@@ -836,6 +868,10 @@ public class DefaultConfigurator implements Configurator { ...@@ -836,6 +868,10 @@ public class DefaultConfigurator implements Configurator {
public static <T extends Number> T parseNumber(String value, public static <T extends Number> T parseNumber(String value,
Class<T> targetClass) { Class<T> targetClass) {
assert value != null; assert value != null;
if(value == null)
System.out.println("");
String number = value; String number = value;
double factor = 1; double factor = 1;
// Time // Time
...@@ -875,6 +911,9 @@ public class DefaultConfigurator implements Configurator { ...@@ -875,6 +911,9 @@ public class DefaultConfigurator implements Configurator {
} else { } else {
throw new IllegalStateException("Invalid bandwidth unit."); throw new IllegalStateException("Invalid bandwidth unit.");
} }
} else if (value.matches("\\d+%") || value.matches("\\d+\\.\\d+%")) {
factor = 0.01;
number = value.substring(0, value.length() - 1);
} }
// Size (Byte) // Size (Byte)
if (value.matches("\\d+(B|KB|MB)")) { if (value.matches("\\d+(B|KB|MB)")) {
...@@ -910,11 +949,11 @@ public class DefaultConfigurator implements Configurator { ...@@ -910,11 +949,11 @@ public class DefaultConfigurator implements Configurator {
/** /**
* You can create elements like * You can create elements like
* *
* &lt;IfEqualStr arg0="$variable" arg1="value"&gt; [...your configuration * &lt;IfEqualStr arg0="$variable" arg1="value"&gt; [...your configuration
* ... ] &lt;/IfEqualStr&gt;, and they will be applied only if the strings * ... ] &lt;/IfEqualStr&gt;, and they will be applied only if the strings
* are equal. * are equal.
* *
* @param ifClause * @param ifClause
* @param toExecuteOnTrue * @param toExecuteOnTrue
* @return * @return
...@@ -952,11 +991,11 @@ public class DefaultConfigurator implements Configurator { ...@@ -952,11 +991,11 @@ public class DefaultConfigurator implements Configurator {
/** /**
* You can create elements like * You can create elements like
* *
* &lt;IfNotEqualStr arg0="$variable" arg1="value"&gt; [...your * &lt;IfNotEqualStr arg0="$variable" arg1="value"&gt; [...your
* configuration ... ] &lt;/IfNotEqualStr&gt;, and they will be applied only * configuration ... ] &lt;/IfNotEqualStr&gt;, and they will be applied only
* if the strings are NOT equal. * if the strings are NOT equal.
* *
* @param ifClause * @param ifClause
* @param toExecuteOnFalse * @param toExecuteOnFalse
* @return * @return
...@@ -995,7 +1034,7 @@ public class DefaultConfigurator implements Configurator { ...@@ -995,7 +1034,7 @@ public class DefaultConfigurator implements Configurator {
/** /**
* Gets the parsed XML-Configuration File. So are the included tags * Gets the parsed XML-Configuration File. So are the included tags
* resolved. * resolved.
* *
* @param configFile * @param configFile
* The File of the config * The File of the config
* @return The parsed config as text. * @return The parsed config as text.
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
package de.tud.kom.p2psim.impl.scenario.simcfg2.utils; package de.tud.kom.p2psim.impl.scenario.simcfg2.utils;
import de.tud.kom.p2psim.impl.scenario.simcfg2.configuration.SimCfgConfiguration; import de.tud.kom.p2psim.impl.scenario.simcfg2.configuration.SimCfgConfiguration;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.script.*; import javax.script.*;
import java.util.Map; import java.util.Map;
...@@ -30,7 +32,7 @@ import java.util.Map; ...@@ -30,7 +32,7 @@ import java.util.Map;
* @version 1.0, 12.07.13 * @version 1.0, 12.07.13
*/ */
public class SimCfgExpressionExecutor { public class SimCfgExpressionExecutor {
private static final Logger log = Logger.getLogger(SimCfgExpressionExecutor.class); private static final Logger log = LogManager.getLogger(SimCfgExpressionExecutor.class);
private ScriptEngine javascriptEngine = null; private ScriptEngine javascriptEngine = null;
public SimCfgExpressionExecutor() { public SimCfgExpressionExecutor() {
......
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