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,27 +44,20 @@ 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 {
public abstract class AbstractEnergyModel implements EnergyModel, BatterySensor, EnergyInfo {
// private static Logger log =
// SimLogger.getLogger(ModularEnergyModel.class);
protected SimHost host;
protected List<EnergyComponent> energyComponents;
protected Battery bat;
private SimHost host;
private List<EnergyComponent> energyComponents;
private Battery bat;
public ModularEnergyModel(SimHost host, Battery bat) {
public AbstractEnergyModel(SimHost host, Battery bat) {
energyComponents = new Vector<EnergyComponent>();
this.bat = bat;
this.host = host;
......@@ -138,12 +128,6 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
}
}
@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) {
......@@ -170,7 +154,7 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
}
@Override
public EnergyInfo getInfo() {
public EnergyInfo getEnergyInfo() {
/*
* We export our status to interested applications via this interface
*/
......@@ -189,23 +173,27 @@ 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) {
public void shutdown() {
throw new AssertionError(
"You are not supposed to shutdown this component.");
}
@Override
public void reset() {
throw new AssertionError(
"You are not supposed to reset this component.");
}
if (!bat.isEmpty()) {
double consumedEnergy = oldState.getEnergyConsumption()
* (timeSpentInOldState / (double) Time.SECOND);
bat.consumeEnergy(consumedEnergy);
protected void monitorEnergyConsumation(EnergyComponent component, double consumedEnergy) {
/*
* TODO Refactor the Energy-Analyzer to support EnergyComponents
* directly, rather than strings.
......@@ -216,41 +204,16 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
} 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()) {
protected void monitorEmptyBattery() {
/*
* Battery is now empty. Go offline.
* Battery is now empty.
*/
try {
Monitor.get(EnergyAnalyzer.class).batteryIsEmpty(getHost());
} catch (AnalyzerNotAvailableException e) {
//
}
for (SimNetInterface net : getHost().getNetworkComponent()
.getSimNetworkInterfaces()) {
net.goOffline();
}
}
}
}
@Override
public boolean turnOn(EnergyComponent component) {
return !bat.isEmpty();
}
@Override
public SimHost getHost() {
return host;
}
@Override
public void reset() {
bat.reset();
}
}
/*
* 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;
}
}
......@@ -873,19 +873,21 @@ 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();
}
......@@ -1011,8 +1013,9 @@ public abstract class AbstractMacLayer implements MacLayer {
}
@Override
public void turnOff() {
public boolean turnOff() {
on = false;
return true;
}
public boolean turnOn() {
......@@ -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();
}
......
......@@ -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;
......
......@@ -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;
......@@ -145,6 +146,8 @@ 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.
......@@ -199,6 +202,13 @@ 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
......@@ -245,13 +255,13 @@ 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);
}
}
......@@ -310,7 +320,6 @@ public class DefaultConfigurator implements Configurator {
* @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,6 +356,7 @@ public class DefaultConfigurator implements Configurator {
Monitor.log(DefaultConfigurator.class, Level.DEBUG,
"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.
......@@ -383,10 +393,19 @@ public class DefaultConfigurator implements Configurator {
}
} 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 {
for (Iterator iter = elem.elementIterator(); iter.hasNext();) {
Element child = (Element) iter.next();
processChild(null, child, null);
}
return null;
}
}
private Object createComponent(Element elem, Set<String> consAttrs) {
......@@ -455,6 +474,7 @@ public class DefaultConfigurator implements Configurator {
Object subcomponent = configureComponent(child);
if (!_parseOnly) {
String prefix = SET_METHOD_PREFIX_TAG;
String methodName = getMethodName(prefix, child.getName());
Method[] methods = component.getClass().getMethods();
......@@ -493,6 +513,7 @@ public class DefaultConfigurator implements Configurator {
}
}
}
}
public void configureAttributes(Object component, Element elem) {
Set<String> set = Collections.emptySet();
......@@ -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;
}
......@@ -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,13 +802,20 @@ public class DefaultConfigurator implements Configurator {
}
if (!incompatible) {
component = c.newInstance(consArgs);
for (String consAttr : cArgs) {
consAttrs.add(consAttr.toLowerCase());
if (currentConstructor == null || parameters.length < consArgs.length) {
currentConstructor = c;
parameters = consArgs;
usedArgs = cArgs;
}
}
}
break;
}
if (currentConstructor != null) {
component = currentConstructor.newInstance(parameters);
for (String consAttr : usedArgs) {
consAttrs.add(consAttr.toLowerCase());
}
}
......@@ -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)")) {
......
......@@ -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