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 @@
package de.tud.kom.p2psim.api.common;
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
......@@ -30,9 +31,10 @@ import de.tudarmstadt.maki.simonstrator.api.common.Transmitable;
*
* @author Bjoern Richerzhagen
* @version 1.0, 05/26/2011
* @deprecated please consider using {@link Location} instead!
*/
public interface Position extends Transmitable, Cloneable {
@Deprecated
public interface Position extends Transmitable, Cloneable, Location {
/**
* 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;
import de.tud.kom.p2psim.api.network.BandwidthImpl;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
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
......@@ -45,6 +46,13 @@ public interface MacLayer extends SimHostComponent, EventHandler {
* @return
*/
public MacAddress getMacAddress();
/**
* The NetID used via this mac (convenience method)
*
* @return
*/
public NetID getNetId();
/**
* The {@link TopologyView} this MAC operates on
......
......@@ -47,6 +47,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported,
* @author Bjoern Richerzhagen
* @version 1.0, 26.02.2012
*/
@Deprecated
public static enum PositionAccuracy {
HIGH, MEDIUM, LOW
}
......@@ -61,6 +62,7 @@ public interface TopologyComponent extends SimHostComponent, MovementSupported,
* a QoS-Class for the accuracy
* @return An estimate of the current position
*/
@Deprecated
public Position getPosition(PositionAccuracy accuracy);
/**
......
......@@ -53,6 +53,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
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.
......@@ -97,6 +98,11 @@ 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.
*/
private NetID netID;
/**
* Each MAC has a Message queue for outgoing messages
......@@ -889,6 +895,18 @@ public abstract class AbstractMacLayer implements MacLayer {
public final MacAddress getMacAddress() {
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
public final void setMessageListener(LinkMessageListener listener) {
......
......@@ -25,6 +25,7 @@ import java.util.ArrayList;
import de.tud.kom.p2psim.api.common.Position;
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
......@@ -312,5 +313,36 @@ public class GnpPosition implements Position, Comparable<GnpPosition> {
public GnpPosition clone() {
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
import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host;
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.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.NetworkComponent.NetInterfaceName;
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.LocationRequest;
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.transport.ConnectivityListener;
import de.tudarmstadt.maki.simonstrator.api.operation.Operations;
......@@ -339,13 +342,13 @@ public class DefaultTopologyComponent implements TopologyComponent {
}
@Override
public Node getNode(TopologyID identifier) {
public INode getNode(TopologyID identifier) {
assert graphViews.containsKey(identifier);
return graphViews.get(identifier).getOwnNode(host);
}
@Override
public Set<DirectedEdge> getNeighbors(TopologyID topologyIdentifier) {
public Set<IEdge> getNeighbors(TopologyID topologyIdentifier) {
assert graphViews.containsKey(topologyIdentifier);
return graphViews.get(topologyIdentifier).getNeighbors(host);
}
......@@ -401,7 +404,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
this.medium = medium;
PhyType localPhy = null;
for (PhyType currPhy : PhyType.values()) {
if (currPhy.getNetInterfaceName() == medium) {
if (currPhy.getNetInterfaceName() == medium
&& getTopology().getTopologyView(currPhy) != null) {
localPhy = currPhy;
break;
}
......@@ -443,28 +447,32 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Add all (online?) nodes
for (MacLayer mac : topoView.getAllMacs()) {
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) {
// Build neighbors solely based on an assumed range
for (MacLayer mac : topoView.getAllMacs()) {
// Add neighbors
Node currentNode = currentView.createNode(mac
.getMacAddress());
// Consider all nodes as potential neighbors
for (MacLayer neighborMac : topoView.getAllMacs()) {
// create, but do NOT add the node object
Node neighbor = currentView.createNode(neighborMac
.getMacAddress());
INode neighbor = currentView.createNode(INodeID
.get(neighborMac.getNetId()));
// only online nodes (already in graph)
if (!onlyOnline || currentView.contains(neighbor)) {
if (!onlyOnline
|| currentView.containsNode(neighbor.getId())) {
// Distance?
if (topoView.getDistance(mac.getMacAddress(),
neighborMac.getMacAddress()) <= distance) {
currentView.createAndAddEdge(currentNode,
neighbor);
IEdge edge = currentView.createEdge(
INodeID.get(mac.getNetId()),
INodeID.get(neighborMac.getNetId()));
currentView.addElement(edge);
}
}
}
......@@ -472,18 +480,23 @@ public class DefaultTopologyComponent implements TopologyComponent {
} else {
// Build neighborhoods based on underlay neighbors (1-hop)
for (MacLayer mac : topoView.getAllMacs()) {
// Add neighbors
Node currentNode = currentView.createNode(mac
.getMacAddress());
// Rely on underlay for neighbors
List<MacAddress> neighbors = topoView.getNeighbors(mac
.getMacAddress());
for (MacAddress neighborMac : neighbors) {
// 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)
if (!onlyOnline || currentView.contains(neighbor)) {
currentView.createAndAddEdge(currentNode, neighbor);
if (!onlyOnline
|| 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 {
isInvalid = false;
}
public Node getOwnNode(SimHost ownHost) {
public INode getOwnNode(SimHost ownHost) {
MacLayer mac = ownHost.getLinkLayer().getMac(phy);
if (!onlyOnline || mac.isOnline()) {
return currentView.createNode(ownHost.getLinkLayer()
.getMac(phy).getMacAddress());
return currentView.createNode(INodeID.get(ownHost
.getLinkLayer().getMac(phy).getNetId()));
}
return null;
}
public Set<DirectedEdge> getNeighbors(SimHost ownHost) {
public Set<IEdge> getNeighbors(SimHost ownHost) {
recalculateLocalView();
Node ownNode = getOwnNode(ownHost);
return currentView.getOutgoingEdges(ownNode);
INode ownNode = getOwnNode(ownHost);
return currentView.getOutgoingEdges(ownNode.getId());
}
/**
......
......@@ -35,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
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.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.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent;
......@@ -196,8 +198,8 @@ public class GlobalOracle implements OracleComponent {
public static <T extends TopologyProvider> Graph getTopology(
Class<T> component, TopologyID identifier) {
HashSet<DirectedEdge> edges = new LinkedHashSet<>();
HashSet<Node> nodes = new LinkedHashSet<Node>();
HashSet<IEdge> edges = new LinkedHashSet<>();
HashSet<INode> nodes = new LinkedHashSet<>();
LinkedList<TopologyProvider> allProviders = new LinkedList<>();
......@@ -206,7 +208,7 @@ public class GlobalOracle implements OracleComponent {
TopologyProvider topologyProvider = host
.getComponent(component);
Node providerNode = topologyProvider.getNode(identifier);
INode providerNode = topologyProvider.getNode(identifier);
nodes.add(providerNode);
......@@ -221,17 +223,21 @@ public class GlobalOracle implements OracleComponent {
}
for (TopologyProvider topologyProvider : allProviders) {
Set<de.tudarmstadt.maki.simonstrator.api.common.graph.DirectedEdge> neighbors = topologyProvider
.getNeighbors(identifier);
Set<IEdge> neighbors = topologyProvider.getNeighbors(identifier);
edges.addAll(neighbors);
}
/*
* Copy elements and (!) attached properties
*/
Graph graph = Graphs.createGraph();
for(Node node : nodes){
graph.add(node);
for(INode node : nodes){
INode copy = graph.createNode(node.getId());
copy.addPropertiesFrom(node);
}
for(DirectedEdge edge : edges) {
graph.add(edge);
for(IEdge edge : edges) {
IEdge copy = graph.createEdge(edge.fromId(), edge.toId());
copy.addPropertiesFrom(edge);
}
return graph;
......
......@@ -8,6 +8,7 @@ import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
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.
*
......@@ -89,11 +90,13 @@ public class GeoSpherePosition implements Transmitable, Position {
}
/** Get the latitude in degrees */
@Override
public double getLatitude() {
return Math.toDegrees(latitude);
}
/** Get the longitude in degrees */
@Override
public double getLongitude() {
return Math.toDegrees(longitude);
}
......@@ -435,4 +438,24 @@ public class GeoSpherePosition implements Transmitable, Position {
public static boolean isBearingCacheEnabled() {
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