Commit 1d0530f6 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added speed to SiSTypes, provided by DefaultTopologyComponent

parent 8a484e4e
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -44,7 +44,6 @@ import de.tudarmstadt.maki.simonstrator.api.Graphs; ...@@ -44,7 +44,6 @@ 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.Oracle; import de.tudarmstadt.maki.simonstrator.api.Oracle;
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.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.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode; import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
...@@ -68,7 +67,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityList ...@@ -68,7 +67,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityList
/** /**
* Default implementation of a {@link TopologyComponent}. * Default implementation of a {@link TopologyComponent}.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 29.02.2012 * @version 1.0, 29.02.2012
*/ */
...@@ -94,7 +93,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -94,7 +93,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/** /**
* Create a TopologyComponent for the current host. * Create a TopologyComponent for the current host.
* *
* @param host * @param host
* @param topology * @param topology
* @param movementModel * @param movementModel
...@@ -137,30 +136,58 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -137,30 +136,58 @@ public class DefaultTopologyComponent implements TopologyComponent {
sis.provide().nodeState(SiSTypes.PHY_LOCATION, sis.provide().nodeState(SiSTypes.PHY_LOCATION,
new SiSDataCallback<Location>() { new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID Set<INodeID> localID = INodeID
.getSingleIDSet(getHost().getId()); .getSingleIDSet(getHost().getId());
@Override @Override
public Location getValue(INodeID nodeID, public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle) SiSProviderHandle providerHandle)
throws InformationNotAvailableException { throws InformationNotAvailableException {
if (nodeID.equals(getHost().getId())) { if (nodeID.equals(getHost().getId())) {
return getLastLocation(); return getLastLocation();
} else { } else {
throw new InformationNotAvailableException(); throw new InformationNotAvailableException();
} }
} }
@Override @Override
public Set<INodeID> getObservedNodes() { public Set<INodeID> getObservedNodes() {
return localID; return localID;
} }
@Override @Override
public SiSInfoProperties getInfoProperties() { public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties(); return new SiSInfoProperties();
} }
}); });
sis.provide().nodeState(SiSTypes.SPEED,
new SiSDataCallback<Double>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(getHost().getId());
@Override
public Double getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(getHost().getId())) {
return getMovementSpeed();
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
// Provide Underlay topology // Provide Underlay topology
Event.scheduleImmediately(new EventHandler() { Event.scheduleImmediately(new EventHandler() {
...@@ -202,7 +229,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -202,7 +229,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
public Topology getTopology() { public Topology getTopology() {
return topology; return topology;
} }
/** /**
* Access to the movement model * Access to the movement model
* @return * @return
...@@ -263,18 +290,18 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -263,18 +290,18 @@ public class DefaultTopologyComponent implements TopologyComponent {
locationListener.onLocationChanged(getHost(), getLastLocation()); locationListener.onLocationChanged(getHost(), getLastLocation());
} }
} }
@Override @Override
public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint)
throws UnsupportedOperationException { throws UnsupportedOperationException {
movementModel.changeTargetLocation(this, targetAttractionPoint); movementModel.changeTargetLocation(this, targetAttractionPoint);
} }
@Override @Override
public AttractionPoint getCurrentTargetAttractionPoint() { public AttractionPoint getCurrentTargetAttractionPoint() {
return movementModel.getTargetLocation(this); return movementModel.getTargetLocation(this);
} }
@Override @Override
public Set<AttractionPoint> getAllAttractionPoints() { public Set<AttractionPoint> getAllAttractionPoints() {
return movementModel.getAllAttractionPoints(); return movementModel.getAllAttractionPoints();
...@@ -322,7 +349,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -322,7 +349,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/** /**
* Update 15.03.16 added support for multiple listeners (however, frequency * Update 15.03.16 added support for multiple listeners (however, frequency
* etc. is immune after the first request is registered.) * etc. is immune after the first request is registered.)
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, Mar 15, 2016 * @version 1.0, Mar 15, 2016
*/ */
...@@ -337,7 +364,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -337,7 +364,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
private Location lastLocation = null; private Location lastLocation = null;
private List<LocationListener> listeners = new LinkedList<LocationListener>(); private List<LocationListener> listeners = new LinkedList<LocationListener>();
private int eventTypeSeq = 0; private int eventTypeSeq = 0;
public LocationRequestImpl() { public LocationRequestImpl() {
...@@ -385,9 +412,9 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -385,9 +412,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
public void eventOccurred(Object content, int type) { public void eventOccurred(Object content, int type) {
if (eventTypeSeq != type) { if (eventTypeSeq != type) {
/* /*
* Discard invalid events caused when a client cancels updates * Discard invalid events caused when a client cancels updates
* but reactivates the request within the update frequency * but reactivates the request within the update frequency
* interval. In this case, the old events continue rescheduling * interval. In this case, the old events continue rescheduling
* themselves. * themselves.
*/ */
return; return;
...@@ -396,7 +423,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -396,7 +423,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Only reschedule, if at least one listener is ... listening // Only reschedule, if at least one listener is ... listening
Location newLoc = getLastLocation(); Location newLoc = getLastLocation();
listeners.forEach((LocationListener listener) -> listener listeners.forEach((LocationListener listener) -> listener
.onLocationChanged(getHost(), newLoc)); .onLocationChanged(getHost(), newLoc));
lastLocation = newLoc; lastLocation = newLoc;
Event.scheduleWithDelay(interval, this, null, eventTypeSeq); Event.scheduleWithDelay(interval, this, null, eventTypeSeq);
} }
...@@ -431,7 +458,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -431,7 +458,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
boolean onlyOnline, double range) { boolean onlyOnline, double range) {
TopologyID id = TopologyID.getIdentifier( TopologyID id = TopologyID.getIdentifier(
netName.toString() + (onlyOnline ? "-online" : "-all") netName.toString() + (onlyOnline ? "-online" : "-all")
+ String.valueOf(range), + String.valueOf(range),
DefaultTopologyComponent.class); DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) { if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id, this.graphViews.put(id,
...@@ -466,12 +493,12 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -466,12 +493,12 @@ public class DefaultTopologyComponent implements TopologyComponent {
/** /**
* This is calculated based on global knowledge. It only registers as * This is calculated based on global knowledge. It only registers as
* {@link LocationListener}, if a range is specified by the Provider. * {@link LocationListener}, if a range is specified by the Provider.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, May 13, 2015 * @version 1.0, May 13, 2015
*/ */
private class LocalGraphView private class LocalGraphView
implements LocationListener, ConnectivityListener { implements LocationListener, ConnectivityListener {
/** /**
* Marker: has there been any movement since the graph view was last * Marker: has there been any movement since the graph view was last
...@@ -533,8 +560,8 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -533,8 +560,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (host.getNetworkComponent() if (host.getNetworkComponent()
.getByName(medium) != null) { .getByName(medium) != null) {
host.getNetworkComponent().getByName(medium) host.getNetworkComponent().getByName(medium)
.addConnectivityListener( .addConnectivityListener(
LocalGraphView.this); LocalGraphView.this);
} }
} }
} }
...@@ -619,7 +646,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -619,7 +646,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
IEdge edge = currentView.createEdge( IEdge edge = currentView.createEdge(
mac.getHost().getId(), mac.getHost().getId(),
topoView.getMac(neighborMac).getHost() topoView.getMac(neighborMac).getHost()
.getId()); .getId());
currentView.addElement(edge); currentView.addElement(edge);
edge.setProperty(SiSTypes.PHY_DISTANCE, edge.setProperty(SiSTypes.PHY_DISTANCE,
topoView.getDistance(mac.getMacAddress(), topoView.getDistance(mac.getMacAddress(),
...@@ -649,7 +676,7 @@ public class DefaultTopologyComponent implements TopologyComponent { ...@@ -649,7 +676,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/** /**
* This is the global view, therefore we do not distinguish between * This is the global view, therefore we do not distinguish between
* hosts. * hosts.
* *
* @return * @return
*/ */
public Graph getLocalView() { public Graph getLocalView() {
......
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