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