Commit 050cc5e8 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Merge remote-tracking branch 'origin/br/sis-development'

parents 04f1f32a 4d49e3e5
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.tud.kom.p2psim.api.common; package de.tud.kom.p2psim.api.common;
import de.tudarmstadt.maki.simonstrator.api.common.Transmitable; import de.tudarmstadt.maki.simonstrator.api.common.Transmitable;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* The common interface for positions within PeerfactSim, this hides the * The common interface for positions within PeerfactSim, this hides the
...@@ -30,9 +31,10 @@ import de.tudarmstadt.maki.simonstrator.api.common.Transmitable; ...@@ -30,9 +31,10 @@ import de.tudarmstadt.maki.simonstrator.api.common.Transmitable;
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 05/26/2011 * @version 1.0, 05/26/2011
* @deprecated please consider using {@link Location} instead!
*/ */
@Deprecated
public interface Position extends Transmitable, Cloneable { public interface Position extends Transmitable, Cloneable, Location {
/** /**
* Get the distance of this position compared to any other Position, if they * Get the distance of this position compared to any other Position, if they
......
...@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.linklayer.LinkMessageListener; ...@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.linklayer.LinkMessageListener;
import de.tud.kom.p2psim.api.network.BandwidthImpl; import de.tud.kom.p2psim.api.network.BandwidthImpl;
import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/** /**
* The MAC (Medium Access Control) is a central part of the LinkLayer. In * The MAC (Medium Access Control) is a central part of the LinkLayer. In
...@@ -45,6 +46,13 @@ public interface MacLayer extends SimHostComponent, EventHandler { ...@@ -45,6 +46,13 @@ public interface MacLayer extends SimHostComponent, EventHandler {
* @return * @return
*/ */
public MacAddress getMacAddress(); public MacAddress getMacAddress();
/**
* The NetID used via this mac (convenience method)
*
* @return
*/
public NetID getNetId();
/** /**
* The {@link TopologyView} this MAC operates on * The {@link TopologyView} this MAC operates on
......
...@@ -47,6 +47,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported, ...@@ -47,6 +47,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported,
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 26.02.2012 * @version 1.0, 26.02.2012
*/ */
@Deprecated
public static enum PositionAccuracy { public static enum PositionAccuracy {
HIGH, MEDIUM, LOW HIGH, MEDIUM, LOW
} }
...@@ -61,6 +62,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported, ...@@ -61,6 +62,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported,
* a QoS-Class for the accuracy * a QoS-Class for the accuracy
* @return An estimate of the current position * @return An estimate of the current position
*/ */
@Deprecated
public Position getPosition(PositionAccuracy accuracy); public Position getPosition(PositionAccuracy accuracy);
/** /**
......
...@@ -53,6 +53,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor; ...@@ -53,6 +53,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
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.core.MonitorComponent.AnalyzerNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/** /**
* Basic implementation of a MacLayer running on a PHY-CommunicationComponent. * Basic implementation of a MacLayer running on a PHY-CommunicationComponent.
...@@ -97,6 +98,11 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -97,6 +98,11 @@ 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.
*/
private NetID netID;
/** /**
* Each MAC has a Message queue for outgoing messages * Each MAC has a Message queue for outgoing messages
...@@ -889,6 +895,18 @@ public abstract class AbstractMacLayer implements MacLayer { ...@@ -889,6 +895,18 @@ public abstract class AbstractMacLayer implements MacLayer {
public final MacAddress getMacAddress() { public final MacAddress getMacAddress() {
return macAddress; return macAddress;
} }
@Override
public NetID getNetId() {
if (netID == null) {
// Wow... :)
netID = host.getNetworkComponent().getByName(getPhyType().getNetInterfaceName()).getLocalInetAddress();
if (netID == null) {
throw new AssertionError();
}
}
return netID;
}
@Override @Override
public final void setMessageListener(LinkMessageListener listener) { public final void setMessageListener(LinkMessageListener listener) {
......
...@@ -25,6 +25,7 @@ import java.util.ArrayList; ...@@ -25,6 +25,7 @@ import java.util.ArrayList;
import de.tud.kom.p2psim.api.common.Position; import de.tud.kom.p2psim.api.common.Position;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* This class implements a NetPosition for a GNP-Based calculation of round trip * This class implements a NetPosition for a GNP-Based calculation of round trip
...@@ -312,5 +313,36 @@ public class GnpPosition implements Position, Comparable<GnpPosition> { ...@@ -312,5 +313,36 @@ public class GnpPosition implements Position, Comparable<GnpPosition> {
public GnpPosition clone() { public GnpPosition clone() {
return new GnpPosition(gnpCoordinates); return new GnpPosition(gnpCoordinates);
}
@Override
public float bearingTo(Location dest) {
throw new AssertionError(
"bearingTo is not defined for this Position-Type");
}
@Override
public double distanceTo(Location dest) {
return getDistance((Position) dest);
}
@Override
public long getAgeOfLocation() {
throw new UnsupportedOperationException();
}
@Override
public double getLatitude() {
throw new UnsupportedOperationException();
}
@Override
public double getLongitude() {
throw new UnsupportedOperationException();
}
@Override
public void set(Location l) {
throw new UnsupportedOperationException();
} }
} }
...@@ -45,15 +45,18 @@ import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoi ...@@ -45,15 +45,18 @@ import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoi
import de.tudarmstadt.maki.simonstrator.api.Graphs; import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph; import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Node; import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface; import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName; import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID; import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener; import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener;
import de.tudarmstadt.maki.simonstrator.api.operation.Operations; import de.tudarmstadt.maki.simonstrator.api.operation.Operations;
...@@ -339,13 +342,13 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -339,13 +342,13 @@ public class DefaultTopologyComponent implements TopologyComponent {
} }
@Override @Override
public Node getNode(TopologyID identifier) { public INode getNode(TopologyID identifier) {
assert graphViews.containsKey(identifier); assert graphViews.containsKey(identifier);
return graphViews.get(identifier).getOwnNode(host); return graphViews.get(identifier).getOwnNode(host);
} }
@Override @Override
public Set<DirectedEdge> getNeighbors(TopologyID topologyIdentifier) { public Set<IEdge> getNeighbors(TopologyID topologyIdentifier) {
assert graphViews.containsKey(topologyIdentifier); assert graphViews.containsKey(topologyIdentifier);
return graphViews.get(topologyIdentifier).getNeighbors(host); return graphViews.get(topologyIdentifier).getNeighbors(host);
} }
...@@ -401,7 +404,8 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -401,7 +404,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
this.medium = medium; this.medium = medium;
PhyType localPhy = null; PhyType localPhy = null;
for (PhyType currPhy : PhyType.values()) { for (PhyType currPhy : PhyType.values()) {
if (currPhy.getNetInterfaceName() == medium) { if (currPhy.getNetInterfaceName() == medium
&& getTopology().getTopologyView(currPhy) != null) {
localPhy = currPhy; localPhy = currPhy;
break; break;
} }
...@@ -443,28 +447,32 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -443,28 +447,32 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Add all (online?) nodes // Add all (online?) nodes
for (MacLayer mac : topoView.getAllMacs()) { for (MacLayer mac : topoView.getAllMacs()) {
if (!onlyOnline || mac.isOnline()) { if (!onlyOnline || mac.isOnline()) {
currentView.createAndAddNode(mac.getHost().getHostId()); INode node = currentView.createNode(INodeID.get(mac
.getNetId()));
node.setProperty(SiSTypes.PHY_LOCATION,
topoView.getPosition(mac.getMacAddress()));
currentView.addElement(node);
} }
} }
if (isDistanceBased) { if (isDistanceBased) {
// Build neighbors solely based on an assumed range // Build neighbors solely based on an assumed range
for (MacLayer mac : topoView.getAllMacs()) { for (MacLayer mac : topoView.getAllMacs()) {
// Add neighbors
Node currentNode = currentView.createNode(mac
.getMacAddress());
// Consider all nodes as potential neighbors // Consider all nodes as potential neighbors
for (MacLayer neighborMac : topoView.getAllMacs()) { for (MacLayer neighborMac : topoView.getAllMacs()) {
// create, but do NOT add the node object // create, but do NOT add the node object
Node neighbor = currentView.createNode(neighborMac INode neighbor = currentView.createNode(INodeID
.getMacAddress()); .get(neighborMac.getNetId()));
// only online nodes (already in graph) // only online nodes (already in graph)
if (!onlyOnline || currentView.contains(neighbor)) { if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
// Distance? // Distance?
if (topoView.getDistance(mac.getMacAddress(), if (topoView.getDistance(mac.getMacAddress(),
neighborMac.getMacAddress()) <= distance) { neighborMac.getMacAddress()) <= distance) {
currentView.createAndAddEdge(currentNode, IEdge edge = currentView.createEdge(
neighbor); INodeID.get(mac.getNetId()),
INodeID.get(neighborMac.getNetId()));
currentView.addElement(edge);
} }
} }
} }
...@@ -472,18 +480,23 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -472,18 +480,23 @@ public class DefaultTopologyComponent implements TopologyComponent {
} else { } else {
// Build neighborhoods based on underlay neighbors (1-hop) // Build neighborhoods based on underlay neighbors (1-hop)
for (MacLayer mac : topoView.getAllMacs()) { for (MacLayer mac : topoView.getAllMacs()) {
// Add neighbors
Node currentNode = currentView.createNode(mac
.getMacAddress());
// Rely on underlay for neighbors // Rely on underlay for neighbors
List<MacAddress> neighbors = topoView.getNeighbors(mac List<MacAddress> neighbors = topoView.getNeighbors(mac
.getMacAddress()); .getMacAddress());
for (MacAddress neighborMac : neighbors) { for (MacAddress neighborMac : neighbors) {
// create, but do NOT add the node object // create, but do NOT add the node object
Node neighbor = currentView.createNode(neighborMac); INode neighbor = currentView.createNode(INodeID
.get(topoView.getMac(neighborMac).getNetId()));
// only online nodes (already in graph) // only online nodes (already in graph)
if (!onlyOnline || currentView.contains(neighbor)) { if (!onlyOnline
currentView.createAndAddEdge(currentNode, neighbor); || currentView.containsNode(neighbor.getId())) {
IEdge edge = currentView.createEdge(INodeID.get(mac
.getNetId()), INodeID.get(topoView.getMac(
neighborMac).getNetId()));
currentView.addElement(edge);
edge.setProperty(SiSTypes.PHY_DISTANCE, topoView
.getDistance(mac.getMacAddress(),
neighborMac));
} }
} }
} }
...@@ -492,19 +505,19 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -492,19 +505,19 @@ public class DefaultTopologyComponent implements TopologyComponent {
isInvalid = false; isInvalid = false;
} }
public Node getOwnNode(SimHost ownHost) { public INode getOwnNode(SimHost ownHost) {
MacLayer mac = ownHost.getLinkLayer().getMac(phy); MacLayer mac = ownHost.getLinkLayer().getMac(phy);
if (!onlyOnline || mac.isOnline()) { if (!onlyOnline || mac.isOnline()) {
return currentView.createNode(ownHost.getLinkLayer() return currentView.createNode(INodeID.get(ownHost
.getMac(phy).getMacAddress()); .getLinkLayer().getMac(phy).getNetId()));
} }
return null; return null;
} }
public Set<DirectedEdge> getNeighbors(SimHost ownHost) { public Set<IEdge> getNeighbors(SimHost ownHost) {
recalculateLocalView(); recalculateLocalView();
Node ownNode = getOwnNode(ownHost); INode ownNode = getOwnNode(ownHost);
return currentView.getOutgoingEdges(ownNode); return currentView.getOutgoingEdges(ownNode.getId());
} }
/** /**
......
...@@ -35,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.Host; ...@@ -35,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge; import de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph; import de.tudarmstadt.maki.simonstrator.api.common.graph.Graph;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.Node; import de.tudarmstadt.maki.simonstrator.api.common.graph.Node;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent; import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent;
...@@ -196,8 +198,8 @@ public class GlobalOracle implements OracleComponent { ...@@ -196,8 +198,8 @@ public class GlobalOracle implements OracleComponent {
public static <T extends TopologyProvider> Graph getTopology( public static <T extends TopologyProvider> Graph getTopology(
Class<T> component, TopologyID identifier) { Class<T> component, TopologyID identifier) {
HashSet<DirectedEdge> edges = new LinkedHashSet<>(); HashSet<IEdge> edges = new LinkedHashSet<>();
HashSet<Node> nodes = new LinkedHashSet<Node>(); HashSet<INode> nodes = new LinkedHashSet<>();
LinkedList<TopologyProvider> allProviders = new LinkedList<>(); LinkedList<TopologyProvider> allProviders = new LinkedList<>();
...@@ -206,7 +208,7 @@ public class GlobalOracle implements OracleComponent { ...@@ -206,7 +208,7 @@ public class GlobalOracle implements OracleComponent {
TopologyProvider topologyProvider = host TopologyProvider topologyProvider = host
.getComponent(component); .getComponent(component);
Node providerNode = topologyProvider.getNode(identifier); INode providerNode = topologyProvider.getNode(identifier);
nodes.add(providerNode); nodes.add(providerNode);
...@@ -221,17 +223,21 @@ public class GlobalOracle implements OracleComponent { ...@@ -221,17 +223,21 @@ public class GlobalOracle implements OracleComponent {
} }
for (TopologyProvider topologyProvider : allProviders) { for (TopologyProvider topologyProvider : allProviders) {
Set<de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge> neighbors = topologyProvider Set<IEdge> neighbors = topologyProvider.getNeighbors(identifier);
.getNeighbors(identifier);
edges.addAll(neighbors); edges.addAll(neighbors);
} }
/*
* Copy elements and (!) attached properties
*/
Graph graph = Graphs.createGraph(); Graph graph = Graphs.createGraph();
for(Node node : nodes){ for(INode node : nodes){
graph.add(node); INode copy = graph.createNode(node.getId());
copy.addPropertiesFrom(node);
} }
for(DirectedEdge edge : edges) { for(IEdge edge : edges) {
graph.add(edge); IEdge copy = graph.createEdge(edge.fromId(), edge.toId());
copy.addPropertiesFrom(edge);
} }
return graph; return graph;
......
...@@ -8,6 +8,7 @@ import de.tud.kom.p2psim.api.common.Position; ...@@ -8,6 +8,7 @@ import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit; import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.common.Transmitable; import de.tudarmstadt.maki.simonstrator.api.common.Transmitable;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** Immutable geographical position implementation based on a spherical Earth model. /** Immutable geographical position implementation based on a spherical Earth model.
* *
...@@ -89,11 +90,13 @@ public class GeoSpherePosition implements Transmitable, Position { ...@@ -89,11 +90,13 @@ public class GeoSpherePosition implements Transmitable, Position {
} }
/** Get the latitude in degrees */ /** Get the latitude in degrees */
@Override
public double getLatitude() { public double getLatitude() {
return Math.toDegrees(latitude); return Math.toDegrees(latitude);
} }
/** Get the longitude in degrees */ /** Get the longitude in degrees */
@Override
public double getLongitude() { public double getLongitude() {
return Math.toDegrees(longitude); return Math.toDegrees(longitude);
} }
...@@ -435,4 +438,24 @@ public class GeoSpherePosition implements Transmitable, Position { ...@@ -435,4 +438,24 @@ public class GeoSpherePosition implements Transmitable, Position {
public static boolean isBearingCacheEnabled() { public static boolean isBearingCacheEnabled() {
return enableBearingCache; return enableBearingCache;
} }
@Override
public void set(Location l) {
throw new UnsupportedOperationException();
}
@Override
public long getAgeOfLocation() {
throw new UnsupportedOperationException();
}
@Override
public double distanceTo(Location dest) {
return getDistance((Position) dest);
}
@Override
public float bearingTo(Location dest) {
return (float) getBearing((Position) dest);
}
} }
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