Commit 040822f5 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

First version for privacy-aware offloading

parent 18180bef
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.privacy;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class PrivacyComponent implements HostComponent {
private Host _host;
private PrivacyLevel _privacy = PrivacyLevel.NO_PRIVACY;
public PrivacyComponent(Host pHost) {
_host = pHost;
}
public void setPrivacy(PrivacyLevel pLevel) {
_privacy = pLevel;
}
@Override
public void initialize() {
}
@Override
public void shutdown() {
}
@Override
public Host getHost() {
return _host;
}
public Location obscureLocation(Location pLocation) {
Location location = pLocation.clone();
location.setAccuracy(_privacy.getImprecisionAreaRadius());
return location;
}
public PrivacyLevel getPrivacyLevel() {
return _privacy;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.privacy;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PrivacyComponentFactory implements HostComponentFactory {
private List<PrivacyLevelFrequency> _levels = new ArrayList<>();
private double _sum = 0;
private Random _random = Randoms.getRandom(getClass());
@Override
public HostComponent createComponent(Host pHost) {
PrivacyLevel level = PrivacyLevel.NO_PRIVACY;
double randomValue = _random.nextDouble() * _sum;
double count = 0;
for (int i = 0; i < _levels.size(); i++) {
count += _levels.get(i).getProbability();
if (count > randomValue) {
level = _levels.get(i).getLevel();
break;
}
}
PrivacyComponent privacyComponent = new PrivacyComponent(pHost);
privacyComponent.setPrivacy(level);
return privacyComponent;
}
public void setPrivacyFrequency(PrivacyLevelFrequency pPrivacyLevel) {
_levels.add(pPrivacyLevel);
_sum += pPrivacyLevel.getProbability();
PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel.getLevel());
}
public static class PrivacyLevelFrequency {
private PrivacyLevel _level;
private double _probability;
@XMLConfigurableConstructor({ "privacy", "probability" })
public PrivacyLevelFrequency(PrivacyLevel pLevel, double pProbability) {
_level = pLevel;
_probability = pProbability;
}
public double getProbability() {
return _probability;
}
public PrivacyLevel getLevel() {
return _level;
}
}
}
package de.tudarmstadt.maki.simonstrator.api.component.privacy;
import java.util.ArrayList;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class PrivacyLevel implements Comparable<PrivacyLevel> {
public static final PrivacyLevel NO_PRIVACY = new PrivacyLevel(0);
public static final List<PrivacyLevel> PRIVACY_LEVELS = new ArrayList<>();
private static int staticID = 0;
private final int id;
private double imprecisionAreaRadius;
@XMLConfigurableConstructor({ "imprecision" })
public PrivacyLevel(double pImprecisionAreaRadius) {
synchronized (PrivacyLevel.class) {
id = staticID++;
}
imprecisionAreaRadius = pImprecisionAreaRadius;
}
public int getId() {
return id;
}
public double getImprecisionAreaRadius() {
return imprecisionAreaRadius;
}
@Override
public int hashCode() {
return id;
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof PrivacyLevel) {
return ((PrivacyLevel) pObj).id == id;
}
return false;
}
@Override
public int compareTo(PrivacyLevel pArg0) {
return Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius());
}
}
...@@ -29,6 +29,8 @@ public interface CostBasedPubSubComponent extends PubSubComponent { ...@@ -29,6 +29,8 @@ public interface CostBasedPubSubComponent extends PubSubComponent {
public Subscription createSubscription(Topic topic, Filter filter, double costs); public Subscription createSubscription(Topic topic, Filter filter, double costs);
public Subscription createSubscription(Topic topic, Filter filter, double[] costs);
public Notification createNotification(Topic topic, public Notification createNotification(Topic topic,
List<Attribute<?>> attributes, double costs, byte[] payload); List<Attribute<?>> attributes, double costs, byte[] payload);
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular; package de.tudarmstadt.maki.simonstrator.api.component.relevance.vehicular;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.VehicularPointInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.VehicularPointInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
...@@ -33,6 +34,12 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road ...@@ -33,6 +34,12 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
* *
*/ */
public interface VehicularRelevanceCalculationComponent extends HostComponent { public interface VehicularRelevanceCalculationComponent extends HostComponent {
public enum PositionRepresentation {
ROAD_BASED, LOCATION_BASED
}
PositionRepresentation getPositionRepresentation();
/** /**
* This method calculates the relevance of an event for a vehicle, combining * This method calculates the relevance of an event for a vehicle, combining
* the temporal and the geographical relevance. * the temporal and the geographical relevance.
...@@ -45,6 +52,18 @@ public interface VehicularRelevanceCalculationComponent extends HostComponent { ...@@ -45,6 +52,18 @@ public interface VehicularRelevanceCalculationComponent extends HostComponent {
*/ */
double calculateRelevance(RoadNetworkEdge pVehiclePosition, VehicularPointInformation pInformation); double calculateRelevance(RoadNetworkEdge pVehiclePosition, VehicularPointInformation pInformation);
/**
* This method calculates the relevance of an event for a vehicle, combining the
* temporal and the geographical relevance.
*
* @param pVehiclePosition
* The vehicle's position
* @param pInformation
* The information for which the relevance is calculated.
* @return The relevance of the event.
*/
double calculateRelevance(Location pLocation, VehicularPointInformation pInformation);
/** /**
* This method calculates the relevance of an event for a vehicle, combining * This method calculates the relevance of an event for a vehicle, combining
* the temporal and the geographical relevance. * the temporal and the geographical relevance.
......
...@@ -20,34 +20,45 @@ ...@@ -20,34 +20,45 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
import java.util.HashMap;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification; import de.tudarmstadt.maki.simonstrator.api.component.pubsub.Notification;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.BumpProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.FogProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.HazardProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.LocationBasedEnvironmentProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.LocationBasedEnvironmentProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RainProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty; import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.RoadProperty;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.TrafficSignProperty;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.EnvironmentInformation;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPropertyImpactEstimator { public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPropertyImpactEstimator {
private Map<Class<?>, VehicularPropertyImpact> _properties = new HashMap<>();
public ConfigurableVehicularPropertyImpactEstimator() {
PropertyImpactEstimatorFactory.registerPropertyBenefitEstimator(this);
}
public void setPropertyImpact(VehicularPropertyImpact pImpact) {
try {
_properties.put(Class.forName(pImpact.getProperty()), pImpact);
} catch (ClassNotFoundException e) {
throw new AssertionError("Unknown class: ", e);
}
}
@Override @Override
public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) { public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) { if (_properties.containsKey(pProperty)) {
return 3 * Math.pow(10, 2); return _properties.get(pProperty).getImpactKnown();
} else if (pProperty.equals(RainProperty.class)) { }
return 1; return 0;
} else if (pProperty.equals(FogProperty.class)) { }
return 1;
} else if (pProperty.equals(HazardProperty.class)) { @Override
return Math.pow(10, 3); public double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty) {
} else if (pProperty.equals(TrafficSignProperty.class)) { if (_properties.containsKey(pProperty)) {
return 10; return _properties.get(pProperty).getImpactUnknown();
} }
return 10; return 0;
} }
@Override @Override
...@@ -74,16 +85,35 @@ public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPr ...@@ -74,16 +85,35 @@ public class ConfigurableVehicularPropertyImpactEstimator implements VehicularPr
throw new AssertionError("Cost calculation only valid for road information!"); throw new AssertionError("Cost calculation only valid for road information!");
} }
@Override public static class VehicularPropertyImpact {
public double calculateImpactIfUnknown(Class<? extends RoadProperty> pProperty) { private String _property;
if (pProperty.equals(JamProperty.class)) { private double _impactKnown;
return Math.pow(10, 4); private double _impactUnknown;
} else if (pProperty.equals(BumpProperty.class)) {
return Math.pow(10, -2); @XMLConfigurableConstructor({ "property", "known", "unknown" })
} else if (pProperty.equals(HazardProperty.class)) { public VehicularPropertyImpact(String pProperty, double pImpactKnown, double pImpactUnknown) {
return Math.pow(10, 6); _property = pProperty;
_impactKnown = pImpactKnown;
_impactUnknown = pImpactUnknown;
}
@XMLConfigurableConstructor({ "property", "known" })
public VehicularPropertyImpact(String pProperty, double pImpactKnown) {
_property = pProperty;
_impactKnown = pImpactKnown;
_impactUnknown = pImpactKnown;
} }
return 1;
public String getProperty() {
return _property;
}
public double getImpactKnown() {
return _impactKnown;
} }
public double getImpactUnknown() {
return _impactUnknown;
}
}
} }
...@@ -37,7 +37,7 @@ public class DefaultVehicularPropertyImpactEstimator implements VehicularPropert ...@@ -37,7 +37,7 @@ public class DefaultVehicularPropertyImpactEstimator implements VehicularPropert
@Override @Override
public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) { public double calculateImpactIfKnown(Class<? extends RoadProperty> pProperty) {
if (pProperty.equals(JamProperty.class)) { if (pProperty.equals(JamProperty.class)) {
return 3 * Math.pow(10, 2); return Math.pow(10, 2);
} else if (pProperty.equals(RainProperty.class)) { } else if (pProperty.equals(RainProperty.class)) {
return 1; return 1;
} else if (pProperty.equals(FogProperty.class)) { } else if (pProperty.equals(FogProperty.class)) {
......
...@@ -23,7 +23,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs; ...@@ -23,7 +23,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.costs;
public class PropertyImpactEstimatorFactory { public class PropertyImpactEstimatorFactory {
private static PropertyImpactEstimator _costEstimator = null; private static PropertyImpactEstimator _costEstimator = null;
public void registerPropertyBenefitEstimator(PropertyImpactEstimator pBenefitEstimator) { public static void registerPropertyBenefitEstimator(PropertyImpactEstimator pBenefitEstimator) {
synchronized (PropertyImpactEstimatorFactory.class) { synchronized (PropertyImpactEstimatorFactory.class) {
_costEstimator = pBenefitEstimator; _costEstimator = pBenefitEstimator;
} }
......
...@@ -33,8 +33,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.pr ...@@ -33,8 +33,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.pr
*/ */
public class EventInformationContainer { public class EventInformationContainer {
private static Map<Class<? extends RoadProperty>, Long> durations = new HashMap<>(); private static Map<Class<? extends RoadProperty>, Long> durations = new HashMap<>();
private static Map<Class<? extends RoadProperty>, Double> disseminationRange = new HashMap<>();
public static void registerEvent(Class<? extends RoadProperty> pClass, long pDuration) { public static void registerEventDuration(Class<? extends RoadProperty> pClass, long pDuration) {
if (!durations.containsKey(pClass)) { if (!durations.containsKey(pClass)) {
durations.put(pClass, pDuration); durations.put(pClass, pDuration);
} else { } else {
...@@ -42,10 +43,25 @@ public class EventInformationContainer { ...@@ -42,10 +43,25 @@ public class EventInformationContainer {
} }
} }
public static void registerEventRange(Class<? extends RoadProperty> pClass, double pRange) {
if (!disseminationRange.containsKey(pClass)) {
disseminationRange.put(pClass, pRange);
} else {
throw new AssertionError(pClass + " has already been registered!");
}
}
public static long getEventDuration(Class<? extends RoadProperty> pClass) { public static long getEventDuration(Class<? extends RoadProperty> pClass) {
if (durations.containsKey(pClass)) { if (durations.containsKey(pClass)) {
return durations.get(pClass); return durations.get(pClass);
} }
throw new AssertionError(pClass + " has not been registered!"); throw new AssertionError(pClass + " has not been registered!");
} }
public static double getEventRange(Class<? extends RoadProperty> pClass) {
if (disseminationRange.containsKey(pClass)) {
return disseminationRange.get(pClass);
}
return Double.POSITIVE_INFINITY;
}
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties; package de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties;
import de.tudarmstadt.maki.simonstrator.api.component.privacy.PrivacyLevel;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
...@@ -35,12 +36,20 @@ public class VehicleProperty extends AbstractRoadProperty { ...@@ -35,12 +36,20 @@ public class VehicleProperty extends AbstractRoadProperty {
private final double _speed; private final double _speed;
private final double _length; private final double _length;
private PrivacyLevel _privacy;
public VehicleProperty(long pId, Location pLocation, RoadNetworkEdge pEdge, double pSpeed, double pLength) { public VehicleProperty(long pId, Location pLocation, RoadNetworkEdge pEdge, double pSpeed, double pLength) {
this(pId, pLocation, pEdge, pSpeed, pLength, PrivacyLevel.NO_PRIVACY);
}
public VehicleProperty(long pId, Location pLocation, RoadNetworkEdge pEdge, double pSpeed, double pLength,
PrivacyLevel pPrivacyLevel) {
super(pLocation, pEdge); super(pLocation, pEdge);
_id = pId; _id = pId;
_speed = pSpeed; _speed = pSpeed;
_length = pLength; _length = pLength;
_privacy = pPrivacyLevel;
} }
public long getId() { public long getId() {
...@@ -60,6 +69,10 @@ public class VehicleProperty extends AbstractRoadProperty { ...@@ -60,6 +69,10 @@ public class VehicleProperty extends AbstractRoadProperty {
return _length; return _length;
} }
public PrivacyLevel getPrivacy() {
return _privacy;
}
@Override @Override
public RoadProperty getDefaultProperty() { public RoadProperty getDefaultProperty() {
return null; return null;
...@@ -67,7 +80,7 @@ public class VehicleProperty extends AbstractRoadProperty { ...@@ -67,7 +80,7 @@ public class VehicleProperty extends AbstractRoadProperty {
@Override @Override
public VehicleProperty clone() { public VehicleProperty clone() {
return new VehicleProperty(_id, getLocation(), getEdge(), _speed, _length); return new VehicleProperty(_id, getLocation(), getEdge(), _speed, _length, _privacy);
} }
} }
...@@ -26,4 +26,6 @@ public interface VehicularReceiver extends HostComponent { ...@@ -26,4 +26,6 @@ public interface VehicularReceiver extends HostComponent {
void initialize(); void initialize();
void registerCommunicationListener(CommunicationListener pListener); void registerCommunicationListener(CommunicationListener pListener);
double getAvailableBandwidth();
} }
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