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 @@
* 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/>.
*
......@@ -44,7 +44,6 @@ import de.tudarmstadt.maki.simonstrator.api.Graphs;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Oracle;
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.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
......@@ -68,7 +67,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityList
/**
* Default implementation of a {@link TopologyComponent}.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 29.02.2012
*/
......@@ -94,7 +93,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/**
* Create a TopologyComponent for the current host.
*
*
* @param host
* @param topology
* @param movementModel
......@@ -137,30 +136,58 @@ public class DefaultTopologyComponent implements TopologyComponent {
sis.provide().nodeState(SiSTypes.PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(getHost().getId());
Set<INodeID> localID = INodeID
.getSingleIDSet(getHost().getId());
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(getHost().getId())) {
return getLastLocation();
} else {
throw new InformationNotAvailableException();
}
}
if (nodeID.equals(getHost().getId())) {
return getLastLocation();
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
@Override
public SiSInfoProperties getInfoProperties() {
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
Event.scheduleImmediately(new EventHandler() {
......@@ -202,7 +229,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
public Topology getTopology() {
return topology;
}
/**
* Access to the movement model
* @return
......@@ -263,18 +290,18 @@ public class DefaultTopologyComponent implements TopologyComponent {
locationListener.onLocationChanged(getHost(), getLastLocation());
}
}
@Override
public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint)
throws UnsupportedOperationException {
movementModel.changeTargetLocation(this, targetAttractionPoint);
}
@Override
public AttractionPoint getCurrentTargetAttractionPoint() {
return movementModel.getTargetLocation(this);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return movementModel.getAllAttractionPoints();
......@@ -322,7 +349,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/**
* Update 15.03.16 added support for multiple listeners (however, frequency
* etc. is immune after the first request is registered.)
*
*
* @author Bjoern Richerzhagen
* @version 1.0, Mar 15, 2016
*/
......@@ -337,7 +364,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
private Location lastLocation = null;
private List<LocationListener> listeners = new LinkedList<LocationListener>();
private int eventTypeSeq = 0;
public LocationRequestImpl() {
......@@ -385,9 +412,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
public void eventOccurred(Object content, int type) {
if (eventTypeSeq != type) {
/*
* Discard invalid events caused when a client cancels updates
* but reactivates the request within the update frequency
* interval. In this case, the old events continue rescheduling
* Discard invalid events caused when a client cancels updates
* but reactivates the request within the update frequency
* interval. In this case, the old events continue rescheduling
* themselves.
*/
return;
......@@ -396,7 +423,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
// Only reschedule, if at least one listener is ... listening
Location newLoc = getLastLocation();
listeners.forEach((LocationListener listener) -> listener
.onLocationChanged(getHost(), newLoc));
.onLocationChanged(getHost(), newLoc));
lastLocation = newLoc;
Event.scheduleWithDelay(interval, this, null, eventTypeSeq);
}
......@@ -431,7 +458,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
boolean onlyOnline, double range) {
TopologyID id = TopologyID.getIdentifier(
netName.toString() + (onlyOnline ? "-online" : "-all")
+ String.valueOf(range),
+ String.valueOf(range),
DefaultTopologyComponent.class);
if (!this.graphViews.containsKey(id)) {
this.graphViews.put(id,
......@@ -466,12 +493,12 @@ public class DefaultTopologyComponent implements TopologyComponent {
/**
* This is calculated based on global knowledge. It only registers as
* {@link LocationListener}, if a range is specified by the Provider.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, May 13, 2015
*/
private class LocalGraphView
implements LocationListener, ConnectivityListener {
implements LocationListener, ConnectivityListener {
/**
* Marker: has there been any movement since the graph view was last
......@@ -533,8 +560,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
if (host.getNetworkComponent()
.getByName(medium) != null) {
host.getNetworkComponent().getByName(medium)
.addConnectivityListener(
LocalGraphView.this);
.addConnectivityListener(
LocalGraphView.this);
}
}
}
......@@ -619,7 +646,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
IEdge edge = currentView.createEdge(
mac.getHost().getId(),
topoView.getMac(neighborMac).getHost()
.getId());
.getId());
currentView.addElement(edge);
edge.setProperty(SiSTypes.PHY_DISTANCE,
topoView.getDistance(mac.getMacAddress(),
......@@ -649,7 +676,7 @@ public class DefaultTopologyComponent implements TopologyComponent {
/**
* This is the global view, therefore we do not distinguish between
* hosts.
*
*
* @return
*/
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