Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
0c80da45
Commit
0c80da45
authored
Nov 06, 2015
by
Björn Richerzhagen
Browse files
Removed deprecated `Position`-Interface
parent
db566de9
Changes
64
Expand all
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/common/Position.java
deleted
100644 → 0
View file @
db566de9
/*
* 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/>.
*
*/
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
* business logic of a PositionVector in util.position.
*
* You should consider extending PositionVector for your implementations.
*
* @author Bjoern Richerzhagen
* @version 1.0, 05/26/2011
* @deprecated please consider using {@link Location} instead!
*/
@Deprecated
public
interface
Position
extends
Transmitable
,
Cloneable
,
Location
{
/**
* Get the distance of this position compared to any other Position, if they
* have the same number of dimensions and are compatible.
*
* @param position
* @return
*/
public
double
getDistance
(
Position
position
);
/**
* Calculates the angle <b>in rad</b> from the current position to the
* target.
*
* @param target
* @return An angle in rad between -PI and PI, where 0 is "East", or the
* direction of the positive x-Axis
*/
public
double
getAngle
(
Position
target
);
/**
* This method should be consistent with the getDistance and
* getAngle-methods. It returns a Position that has the given distance and
* angle from the current position.
*
* @param distance
* @param angle
* an angle in rad between -PI and PI, where 0 is the direction
* of the positive x-Axis and angles are incremented
* counter-clockwise (mathematical)
* @return
*/
public
Position
getTarget
(
double
distance
,
double
angle
);
/**
* CLone a Position, ensuring there is no information propagation due to
* Java. Consider a clone() as some kind of snapshot of the current state of
* the cloned position. It is very important to call clone() in scenarios
* with moving hosts!
*
* @return
*/
public
Position
clone
();
}
src/de/tud/kom/p2psim/api/network/NetLayer.java
View file @
0c80da45
...
...
@@ -19,40 +19,40 @@
*/
package
de.tud.kom.p2psim.api.network
;
import
de.tud.kom.p2psim.api.common.Position
;
package
de.tud.kom.p2psim.api.network
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.network.routing.RoutingAlgorithm
;
import
de.tudarmstadt.maki.simonstrator.api.Message
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.Bandwidth
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetID
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface
;
/**
* The NetLayer provides a general interface to encapsulate various networking
* models. This way, it is possible to use network solutions with different
* abstraction levels and complexity. For instance, one can choose either
* between a lightweight simple implementation which offers an adequate model
* with minimum demands in resource requirements and a more complex
* implementation capable to model fairshare bandwidth allocation of TCP but
* having a lot of CPU consumption.
*
* @author Sebastian Kaune
* @author Konstantin Pussep
* @version 3.0, 11/29/2007
*
*/
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* The NetLayer provides a general interface to encapsulate various networking
* models. This way, it is possible to use network solutions with different
* abstraction levels and complexity. For instance, one can choose either
* between a lightweight simple implementation which offers an adequate model
* with minimum demands in resource requirements and a more complex
* implementation capable to model fairshare bandwidth allocation of TCP but
* having a lot of CPU consumption.
*
* @author Sebastian Kaune
* @author Konstantin Pussep
* @version 3.0, 11/29/2007
*
*/
public
interface
NetLayer
extends
NetInterface
{
/**
*
* @return
*/
public
SimHost
getHost
();
public
SimHost
getHost
();
/**
*
* Deliver a message with the given data to the destination using the given
...
...
@@ -68,48 +68,48 @@ public interface NetLayer extends NetInterface {
* the remote receiver
* @param protocol
* the used network protocol
*/
public
void
send
(
Message
msg
,
NetID
receiver
,
NetProtocol
protocol
);
/**
* Returns whether the network layer has connectivity to the physical
* network.
*
* @return return true if the network layer has connectivity to the physical
* network
*/
public
boolean
isOnline
();
/**
* Returns whether the network layer has connectivity to the physical
* network.
*
* @return return true if the network layer does not have connectivity to
* the physical network
*/
public
boolean
isOffline
();
/**
* Returns the NetID of a NetLayer instance
*
* @return the NetID of a given NetLayer instance
*/
public
NetID
getNetID
();
/**
* Establishes the connection to the physical network. Further to this, if
* installed, the correspondent ConnectivityListener will be informed about
* the changes in connectivity.
*
*/
public
void
goOnline
();
/**
* Releases the connection to the physical network. Further to this, if
* installed, the correspondent ConnectivityListener will be informed about
* the changes in connectivity.
*
*/
*/
public
void
send
(
Message
msg
,
NetID
receiver
,
NetProtocol
protocol
);
/**
* Returns whether the network layer has connectivity to the physical
* network.
*
* @return return true if the network layer has connectivity to the physical
* network
*/
public
boolean
isOnline
();
/**
* Returns whether the network layer has connectivity to the physical
* network.
*
* @return return true if the network layer does not have connectivity to
* the physical network
*/
public
boolean
isOffline
();
/**
* Returns the NetID of a NetLayer instance
*
* @return the NetID of a given NetLayer instance
*/
public
NetID
getNetID
();
/**
* Establishes the connection to the physical network. Further to this, if
* installed, the correspondent ConnectivityListener will be informed about
* the changes in connectivity.
*
*/
public
void
goOnline
();
/**
* Releases the connection to the physical network. Further to this, if
* installed, the correspondent ConnectivityListener will be informed about
* the changes in connectivity.
*
*/
public
void
goOffline
();
/**
...
...
@@ -122,8 +122,8 @@ public interface NetLayer extends NetInterface {
* which is described by two numbers--its latitude and its longitude.
*
* @return Position the appropriate position
*/
public
Posi
tion
getNetPosition
();
*/
public
Loca
tion
getNetPosition
();
/**
* Returns the maximum physical bandwidth that is available at the given
...
...
@@ -131,8 +131,8 @@ public interface NetLayer extends NetInterface {
* and download connections are closed.
*
* @return
*/
public
Bandwidth
getMaxBandwidth
();
*/
public
Bandwidth
getMaxBandwidth
();
/**
* Returns the current available download bandwidth of the network layer as
...
...
@@ -140,25 +140,25 @@ public interface NetLayer extends NetInterface {
* connections.
*
* @return the available download bandwidth
*/
public
Bandwidth
getCurrentBandwidth
();
/**
* Adds the given NetMessageListener as a handler for incoming NetMsgEvents
* triggered by the NetLayer which implements the message passing from the
* NetLayer to a layer above.
*
* @param listener
* the listener for network events
*/
public
void
addNetMsgListener
(
NetMessageListener
listener
);
/**
* Removes the given NetMessageListener which handles incoming NetMsgEvents
*
* @param listener
* the listener for network events
*/
*/
public
Bandwidth
getCurrentBandwidth
();
/**
* Adds the given NetMessageListener as a handler for incoming NetMsgEvents
* triggered by the NetLayer which implements the message passing from the
* NetLayer to a layer above.
*
* @param listener
* the listener for network events
*/
public
void
addNetMsgListener
(
NetMessageListener
listener
);
/**
* Removes the given NetMessageListener which handles incoming NetMsgEvents
*
* @param listener
* the listener for network events
*/
public
void
removeNetMsgListener
(
NetMessageListener
listener
);
}
}
src/de/tud/kom/p2psim/api/topology/Topology.java
View file @
0c80da45
...
...
@@ -26,6 +26,7 @@ import de.tud.kom.p2psim.api.topology.social.SocialView;
import
de.tud.kom.p2psim.api.topology.views.TopologyView
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModel
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.component.GlobalComponent
;
/**
* We provide a global Topology-Object (ie. this object is only created once in
...
...
@@ -36,7 +37,7 @@ import de.tud.kom.p2psim.impl.topology.PositionVector;
* @author Bjoern Richerzhagen
* @version 1.0, 21.02.2012
*/
public
interface
Topology
{
public
interface
Topology
extends
GlobalComponent
{
/**
* This Position Vector contains the upper bounds for each dimension used in
...
...
src/de/tud/kom/p2psim/api/topology/TopologyComponent.java
View file @
0c80da45
...
...
@@ -20,9 +20,7 @@
package
de.tud.kom.p2psim.api.topology
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHostComponent
;
import
de.tud.kom.p2psim.api.energy.EnergyComponent
;
import
de.tud.kom.p2psim.api.topology.movement.MovementListener
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
import
de.tud.kom.p2psim.api.topology.views.TopologyView
;
...
...
@@ -40,33 +38,10 @@ import de.tudarmstadt.maki.simonstrator.api.component.topology.UnderlayTopologyP
public
interface
TopologyComponent
extends
SimHostComponent
,
MovementSupported
,
MovementListener
,
UnderlayTopologyProvider
,
LocationSensor
{
/**
* Abstract QoS-Classes for the Accuracy of the position. Implementation
* depends on the {@link EnergyComponent}
*
* @author Bjoern Richerzhagen
* @version 1.0, 26.02.2012
*/
@Deprecated
public
static
enum
PositionAccuracy
{
HIGH
,
MEDIUM
,
LOW
}
/**
* This uses an {@link EnergyComponent} for position retrieving (ie a GPS).
* A call might trigger energy consumption and the result will in most cases
* not be 100% accurate. Use this in your application if you want to add
* another layer of realism.
*
* @param accuracy
* a QoS-Class for the accuracy
* @return An estimate of the current position
*/
@Deprecated
public
Position
getPosition
(
PositionAccuracy
accuracy
);
/**
* Returns the Topology-Object that provides access to {@link TopologyView}s
* Note: the {@link Topology} is also available as a GlobalComponent via the
* Binder-class.
*
* @return
*/
...
...
src/de/tud/kom/p2psim/api/topology/obstacles/Obstacle.java
View file @
0c80da45
...
...
@@ -24,7 +24,6 @@ import java.util.List;
import
com.vividsolutions.jts.geom.Geometry
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.topology.views.TopologyView
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
...
...
src/de/tud/kom/p2psim/api/topology/views/TopologyView.java
View file @
0c80da45
...
...
@@ -23,13 +23,13 @@ package de.tud.kom.p2psim.api.topology.views;
import
java.util.Collection
;
import
java.util.List
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.linklayer.mac.Link
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacLayer
;
import
de.tud.kom.p2psim.api.linklayer.mac.PhyType
;
import
de.tud.kom.p2psim.api.topology.TopologyListener
;
import
de.tud.kom.p2psim.api.topology.movement.MovementListener
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* Each MAC has a view on the global topology of hosts (ie. the
...
...
@@ -119,7 +119,7 @@ public interface TopologyView extends TopologyListener, MovementListener {
* The {@link MacAddress} of the host
* @return The real Position of the Host.
*/
public
Posi
tion
getPosition
(
MacAddress
address
);
public
Loca
tion
getPosition
(
MacAddress
address
);
/**
* Gets the real distance between the two hosts.
...
...
src/de/tud/kom/p2psim/api/topology/views/wifi/phy/PropagationLossModel.java
View file @
0c80da45
...
...
@@ -20,7 +20,7 @@
package
de.tud.kom.p2psim.api.topology.views.wifi.phy
;
import
de.tud
.kom.p2psim
.api.com
m
on
.Posi
tion
;
import
de.tud
armstadt.maki.simonstrator
.api.com
p
on
ent.sensor.location.Loca
tion
;
/**
* This interface is for the calculation of the propagation loss of an
...
...
@@ -52,8 +52,8 @@ public abstract class PropagationLossModel {
* The second position
* @return The RX power in dBm
*/
public
abstract
double
getRxPowerDbm
(
double
txPowerDbm
,
Posi
tion
a
,
Posi
tion
b
);
public
abstract
double
getRxPowerDbm
(
double
txPowerDbm
,
Loca
tion
a
,
Loca
tion
b
);
/**
* Gets the RX Power in dBm for the distance.
...
...
src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/AbstractRateManager.java
View file @
0c80da45
...
...
@@ -28,13 +28,13 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Set
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacLayer
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.WifiMode
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.WifiPhy.Standard_802_11
;
import
de.tud.kom.p2psim.impl.topology.views.wifi.phy.InterferenceHelper
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* This class is an interface for other implementation of Rate Managers. The
...
...
@@ -598,8 +598,8 @@ public abstract class AbstractRateManager {
* antenna. <br>
* This is only a helper to calculate the SNR in the AdHocMac.
*/
public
double
calculateActuallySNR
(
Posi
tion
startPosition
,
Posi
tion
targetPosition
,
WifiMode
mode
,
double
txPowerDbm
)
{
public
double
calculateActuallySNR
(
Loca
tion
startPosition
,
Loca
tion
targetPosition
,
WifiMode
mode
,
double
txPowerDbm
)
{
InterferenceHelper
helper
=
mac
.
getWifiTopologyView
()
.
getInterferenceHelper
();
double
noiseInterferenceW
=
helper
...
...
src/de/tud/kom/p2psim/impl/linklayer/mac/wifi/Ieee80211AdHocMac.java
View file @
0c80da45
...
...
@@ -28,7 +28,6 @@ import java.util.Random;
import
de.tud.kom.p2psim.api.analyzer.LinklayerAnalyzer
;
import
de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.linklayer.LinkLayerMessage
;
import
de.tud.kom.p2psim.api.linklayer.mac.Link
;
...
...
@@ -47,6 +46,7 @@ import de.tud.kom.p2psim.impl.linklayer.DefaultLinkMessageEvent;
import
de.tud.kom.p2psim.impl.linklayer.mac.AbstractMacLayer
;
import
de.tud.kom.p2psim.impl.linklayer.mac.wifi.AbstractRateManager.RateManagerTypes
;
import
de.tud.kom.p2psim.impl.linklayer.mac.wifi.DcfManager.WifiState
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.views.wifi.WifiTopologyView
;
import
de.tud.kom.p2psim.impl.util.LiveMonitoring
;
import
de.tud.kom.p2psim.impl.util.LiveMonitoring.ProgressValue
;
...
...
@@ -56,6 +56,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
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.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.operation.AbstractOperation
;
/**
...
...
@@ -671,14 +672,12 @@ public class Ieee80211AdHocMac extends AbstractMacLayer {
/**
* Gets a copy of the real position of this host.
*
* Clone <strong>ONLY</strong> here.
*
* @return The position of this host.
*/
private
Position
getPosition
()
{
/*
* FIXME this leads to serious performance degradations. Do we REALLY
* need a copy?
*/
return
this
.
getHost
().
getTopologyComponent
().
getRealPosition
();
// .clone();
private
PositionVector
getPosition
()
{
return
this
.
getHost
().
getTopologyComponent
().
getRealPosition
().
clone
();
}
/**
...
...
@@ -919,9 +918,9 @@ public class Ieee80211AdHocMac extends AbstractMacLayer {
WifiMacEventInformation
eInfo
=
(
WifiMacEventInformation
)
eventInfo
;
// startPosition is from receiver (because ack come from this!)
Posi
tion
startPosition
=
((
Ieee80211AdHocMac
)
topoView
Loca
tion
startPosition
=
((
Ieee80211AdHocMac
)
topoView
.
getMac
(
eventInfo
.
getReceiver
())).
getPosition
();
Posi
tion
targetPosition
=
this
.
getPosition
();
Loca
tion
targetPosition
=
this
.
getPosition
();
double
ackSnr
=
rateManager
.
calculateActuallySNR
(
startPosition
,
targetPosition
,
eInfo
.
getAckMode
(),
txPowerDbm
);
rateManager
.
reportDataOk
(
eventInfo
.
getReceiver
(),
ackSnr
,
...
...
src/de/tud/kom/p2psim/impl/network/AbstractNetLayer.java
View file @
0c80da45
...
...
@@ -26,7 +26,6 @@ import java.util.List;
import
de.tud.kom.p2psim.api.analyzer.ConnectivityAnalyzer
;
import
de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason
;
import
de.tud.kom.p2psim.api.analyzer.NetlayerAnalyzer
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.linklayer.mac.PhyType
;
import
de.tud.kom.p2psim.api.network.NetMessage
;
...
...
@@ -42,6 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.Anal
import
de.tudarmstadt.maki.simonstrator.api.component.network.Bandwidth
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetID
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener
;
/**
...
...
@@ -70,7 +70,7 @@ public abstract class AbstractNetLayer implements SimNetworkComponent,
private
boolean
online
;
private
Posi
tion
position
;
private
Loca
tion
position
;
Bandwidth
currentBandwidth
;
...
...
@@ -93,7 +93,7 @@ public abstract class AbstractNetLayer implements SimNetworkComponent,
* the NetPosition of the network layer
*/
public
AbstractNetLayer
(
SimHost
host
,
NetID
netId
,
Bandwidth
maxBandwidth
,
Posi
tion
position
,
NetMeasurementDB
.
Host
hostMeta
)
{
Loca
tion
position
,
NetMeasurementDB
.
Host
hostMeta
)
{
this
.
myID
=
netId
;
this
.
msgListeners
=
new
LinkedList
<
NetMessageListener
>();
this
.
connListeners
=
new
LinkedList
<
ConnectivityListener
>();
...
...
@@ -378,7 +378,7 @@ public abstract class AbstractNetLayer implements SimNetworkComponent,
* @see de.tud.kom.p2psim.api.api.network.NetLayer#getNetPosition()
*/
@Override
public
Posi
tion
getNetPosition
()
{
public
Loca
tion
getNetPosition
()
{
return
this
.
position
;
}
...
...
src/de/tud/kom/p2psim/impl/network/fairshareng/FairshareNode.java
View file @
0c80da45
package
de.tud.kom.p2psim.impl.network.fairshareng
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason
;
import
de.tud.kom.p2psim.api.common.
Position
;
import
de.tud.kom.p2psim.api.
common.SimHost
;
import
de.tud.kom.p2psim.api.network.
BandwidthImpl
;
import
de.tud.kom.p2psim.api.network.
FlowBasedNetlayer
;
import
de.tud.kom.p2psim.api.network.Net
Message
;
import
de.tud.kom.p2psim.api.
network.Net
Protocol
;
import
de.tud.kom.p2psim.
api.transport.TransProtocol
;
import
de.tud.kom.p2psim.impl.network.
AbstractNetLayer
;
import
de.tud.kom.p2psim.impl.network.
IPv4Message
;
import
de.tud.kom.p2psim.impl.
network.modular.db.NetMeasurementDB
;
import
de.tud
.kom.p2psim.impl.transport.AbstractTrans
Message
;
import
de.tudarmstadt.maki.simonstrator.api.M
essage
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.
Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.
network.NetID
;
/**
* The Class Node.
*/
public
class
FairshareNode
extends
AbstractNetLayer
implements
FlowBasedNetlayer
{
/** The subnet. */
private
final
FairshareSubnet
subnet
;
/** The host queues. */
private
final
Map
<
FairshareNode
,
LinkedList
<
NetMessage
>>
hostQueues
;
/** The Constant FLOAT_DELTA to correct Floats 9.999 to 10. */
private
final
static
float
FLOAT_DELTA
=
1
e
-
7
f
;
/** The hash code. */
private
final
int
hashCode
;
/**
* Instantiates a new node.
* @param netID
* @param geoLoc
*/
public
FairshareNode
(
SimHost
host
,
FairshareSubnet
subnet
,
NetID
netID
,
BandwidthImpl
maxBandwidth
,
Posi
tion
position
,
NetMeasurementDB
.
Host
hostMeta
)
{
super
(
host
,
netID
,
maxBandwidth
,
position
,
hostMeta
);
this
.
subnet
=
subnet
;
this
.
hostQueues
=
new
LinkedHashMap
<
FairshareNode
,
LinkedList
<
NetMessage
>>();
this
.
hashCode
=
this
.
getNetID
().
hashCode
();
}
/**
* Adds rate to the current down rate.
*
* @param downRate
*
* the down rate
* @throws Exception
* the exception
*/
public
void
addCurrentDownRate
(
double
downRate
)
throws
Exception
{
final
double
currentDownBW
=
this
.
getCurrentBandwidth
().
getDownBW
();
double
realDownRate
=
currentDownBW
-
downRate
;
/* Fix float, in case we get 9.999 save 10. */
if
(
Math
.
abs
(
Math
.
round
(
realDownRate
)
-
realDownRate
)
<
FLOAT_DELTA
)
{
realDownRate
=
Math
.
round
(
realDownRate
);
}
this
.
getCurrentBandwidth
().
setDownBW
(
realDownRate
);
}
/**
* Adds rate to the current up rate.
*
* @param upRate
* the up rate
* @throws Exception
* the exception
*/
public
void
addCurrentUpRate
(
double
upRate
)
throws
Exception
{
final
double
currentUpBW
=
this
.
getCurrentBandwidth
().
getUpBW
();
double
realUpRate
=
currentUpBW
-
upRate
;
/* Fix float, in case we get 9.999 save 10. */
if
(
Math
.
abs
(
Math
.
round
(
realUpRate
)
-
realUpRate
)
<
FLOAT_DELTA
)
{
realUpRate
=
Math
.
round
(
realUpRate
);
}
this
.
getCurrentBandwidth
().
setUpBW
(
realUpRate
);
}
/**
* Resets the node by setting current rates to zero.
*/
public
void
reset
()
{
this
.
setCurrentBandwidth
(
this
.
getMaxBandwidth
().
clone
());
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.AbstractNetLayer#goOffline()
*/
@Override
public
void
goOffline
()
{
super
.
goOffline
();
this
.
subnet
.
disconnectHost
(
this
);
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.api.network.NetLayer#send(de.tud.kom.p2psim.api.common.Message, de.tud.kom.p2psim.api.network.NetID, de.tud.kom.p2psim.api.network.NetProtocol)
*/
@Override
public
void
send
(
Message
msg
,
NetID
receiverId
,
NetProtocol
protocol
)
{
if
(
isOnline
())
{
assert
(
msg
.
getSize
()
>=
0
);
assert
(
isSupported
(((
AbstractTransMessage
)
msg
).
getProtocol
()));
final
NetMessage
netMsg
=
new
IPv4Message
(
msg
,
receiverId
,
this
.
getNetID
());
final
TransProtocol
tpMsg
=
((
AbstractTransMessage
)
msg
).
getProtocol
();
if
(
tpMsg
.
equals
(
TransProtocol
.
UDP
))
{
if
(
hasAnalyzer
)
{
netAnalyzerProxy
.
netMsgEvent
(
netMsg
,
getHost
(),
Reason
.
SEND
);
}
this
.
subnet
.
sendUDP
(
netMsg
);
}
else
if
(
tpMsg
.
equals
(
TransProtocol
.
TCP
))
{
final
FairshareNode
receiver
=
this
.
subnet
.
getNetLayer
(
receiverId
);
LinkedList
<
NetMessage
>
queuedMessages
=
this
.
hostQueues
.
get
(
receiver
);
if
(
queuedMessages
==
null
)
{
queuedMessages
=
new
LinkedList
<
NetMessage
>();
this
.
hostQueues
.
put
(
receiver
,
queuedMessages
);
}
if
(
hasAnalyzer
)
{
netAnalyzerProxy
.
netMsgEvent
(
netMsg
,
getHost
(),
Reason
.
SEND
);
}
if
(
queuedMessages
.
isEmpty
())
{
try
{
this
.
subnet
.
sendTCPMessage
(
netMsg
);
}
catch
(
final
Exception
e
)
{
/*
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
ERROR
,
"Exception..: sendTCP failed. %s"
,
e
);
assert
(
false
)
:
"sendTCP failed: "
+
e
;
}
}
queuedMessages
.
add
(
netMsg
);
}
else
{
/*
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
ERROR
,
"Unsupported transport protocol "
+
tpMsg
);
assert
(
false
)
:
"Unsupported transport protocol "
+
tpMsg
;
}
}
else
{
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
WARN
,
"Host "
+
this
+
" is offline."
);
}
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.AbstractNetLayer#isSupported(de.tud.kom.p2psim.api.transport.TransProtocol)
*/
@Override
protected
boolean
isSupported
(
TransProtocol
protocol
)
{
return
(
protocol
.
equals
(
TransProtocol
.
UDP
)
||
protocol
.
equals
(
TransProtocol
.
TCP
));
}
/**
* Checks if message queue is empty.
*
* @param receiver the receiver
* @return true, if is message queue empty
*/
public
boolean
isMessageQueueEmpty
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
isEmpty
();
}
/**
* Peek message queue and return size of next expected arrival.
*
* @param receiver the receiver
* @return the double
*/
public
double
peekMessageQueue
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
get
(
0
).
getSize
();
}
/**
* Gets a read-only view on message queue.
*
* @param receiver the receiver
* @return the view on message queue
*/
public
List
<
NetMessage
>
getViewOnMessageQueue
(
FairshareNode
receiver
)
{
return
Collections
.
unmodifiableList
(
this
.
hostQueues
.
get
(
receiver
));
}
/**
* Removes the message from queue.
*
* @param receiver the receiver
* @return the net message
*/
public
NetMessage
removeMessageFromQueue
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
remove
(
0
);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public
boolean
equals
(
Object
obj
)
{
return
(
obj
instanceof
FairshareNode
)
?
((
FairshareNode
)
obj
).
getNetID
().
hashCode
()
==
this
.
getNetID
().
hashCode
()
:
super
.
equals
(
obj
);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
this
.
getLocalInetAddress
()
+
" (U:"
+
this
.
getCurrentBandwidth
().
getUpBW
()
+
"/D:"
+
this
.
getCurrentBandwidth
().
getDownBW
()
+
")"
;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public
int
hashCode
()
{
/* Precomputed to save time. */
return
this
.
hashCode
;
}
}
package
de.tud.kom.p2psim.impl.network.fairshareng
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason
;
import
de.tud.kom.p2psim.api.common.
SimHost
;
import
de.tud.kom.p2psim.api.
network.BandwidthImpl
;
import
de.tud.kom.p2psim.api.network.
FlowBasedNetlayer
;
import
de.tud.kom.p2psim.api.network.
NetMessage
;
import
de.tud.kom.p2psim.api.network.Net
Protocol
;
import
de.tud.kom.p2psim.api.
transport.Trans
Protocol
;
import
de.tud.kom.p2psim.
impl.network.AbstractNetLayer
;
import
de.tud.kom.p2psim.impl.network.
IPv4Message
;
import
de.tud.kom.p2psim.impl.network.
modular.db.NetMeasurementDB
;
import
de.tud.kom.p2psim.impl.
transport.AbstractTransMessage
;
import
de.tud
armstadt.maki.simonstrator.api.
Message
;
import
de.tudarmstadt.maki.simonstrator.api.M
onitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
.Level
;
import
de.tudarmstadt.maki.simonstrator.api.
component.network.NetID
;
import
de.tudarmstadt.maki.simonstrator.api.component.
sensor.location.Location
;
/**
* The Class Node.
*/
public
class
FairshareNode
extends
AbstractNetLayer
implements
FlowBasedNetlayer
{
/** The subnet. */
private
final
FairshareSubnet
subnet
;
/** The host queues. */
private
final
Map
<
FairshareNode
,
LinkedList
<
NetMessage
>>
hostQueues
;
/** The Constant FLOAT_DELTA to correct Floats 9.999 to 10. */
private
final
static
float
FLOAT_DELTA
=
1
e
-
7
f
;
/** The hash code. */
private
final
int
hashCode
;
/**
* Instantiates a new node.
* @param netID
* @param geoLoc
*/
public
FairshareNode
(
SimHost
host
,
FairshareSubnet
subnet
,
NetID
netID
,
BandwidthImpl
maxBandwidth
,
Loca
tion
position
,
NetMeasurementDB
.
Host
hostMeta
)
{
super
(
host
,
netID
,
maxBandwidth
,
position
,
hostMeta
);
this
.
subnet
=
subnet
;
this
.
hostQueues
=
new
LinkedHashMap
<
FairshareNode
,
LinkedList
<
NetMessage
>>();
this
.
hashCode
=
this
.
getNetID
().
hashCode
();
}
/**
* Adds rate to the current down rate.
*
* @param downRate
*
* the down rate
* @throws Exception
* the exception
*/
public
void
addCurrentDownRate
(
double
downRate
)
throws
Exception
{
final
double
currentDownBW
=
this
.
getCurrentBandwidth
().
getDownBW
();
double
realDownRate
=
currentDownBW
-
downRate
;
/* Fix float, in case we get 9.999 save 10. */
if
(
Math
.
abs
(
Math
.
round
(
realDownRate
)
-
realDownRate
)
<
FLOAT_DELTA
)
{
realDownRate
=
Math
.
round
(
realDownRate
);
}
this
.
getCurrentBandwidth
().
setDownBW
(
realDownRate
);
}
/**
* Adds rate to the current up rate.
*
* @param upRate
* the up rate
* @throws Exception
* the exception
*/
public
void
addCurrentUpRate
(
double
upRate
)
throws
Exception
{
final
double
currentUpBW
=
this
.
getCurrentBandwidth
().
getUpBW
();
double
realUpRate
=
currentUpBW
-
upRate
;
/* Fix float, in case we get 9.999 save 10. */
if
(
Math
.
abs
(
Math
.
round
(
realUpRate
)
-
realUpRate
)
<
FLOAT_DELTA
)
{
realUpRate
=
Math
.
round
(
realUpRate
);
}
this
.
getCurrentBandwidth
().
setUpBW
(
realUpRate
);
}
/**
* Resets the node by setting current rates to zero.
*/
public
void
reset
()
{
this
.
setCurrentBandwidth
(
this
.
getMaxBandwidth
().
clone
());
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.AbstractNetLayer#goOffline()
*/
@Override
public
void
goOffline
()
{
super
.
goOffline
();
this
.
subnet
.
disconnectHost
(
this
);
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.api.network.NetLayer#send(de.tud.kom.p2psim.api.common.Message, de.tud.kom.p2psim.api.network.NetID, de.tud.kom.p2psim.api.network.NetProtocol)
*/
@Override
public
void
send
(
Message
msg
,
NetID
receiverId
,
NetProtocol
protocol
)
{
if
(
isOnline
())
{
assert
(
msg
.
getSize
()
>=
0
);
assert
(
isSupported
(((
AbstractTransMessage
)
msg
).
getProtocol
()));
final
NetMessage
netMsg
=
new
IPv4Message
(
msg
,
receiverId
,
this
.
getNetID
());
final
TransProtocol
tpMsg
=
((
AbstractTransMessage
)
msg
).
getProtocol
();
if
(
tpMsg
.
equals
(
TransProtocol
.
UDP
))
{
if
(
hasAnalyzer
)
{
netAnalyzerProxy
.
netMsgEvent
(
netMsg
,
getHost
(),
Reason
.
SEND
);
}
this
.
subnet
.
sendUDP
(
netMsg
);
}
else
if
(
tpMsg
.
equals
(
TransProtocol
.
TCP
))
{
final
FairshareNode
receiver
=
this
.
subnet
.
getNetLayer
(
receiverId
);
LinkedList
<
NetMessage
>
queuedMessages
=
this
.
hostQueues
.
get
(
receiver
);
if
(
queuedMessages
==
null
)
{
queuedMessages
=
new
LinkedList
<
NetMessage
>();
this
.
hostQueues
.
put
(
receiver
,
queuedMessages
);
}
if
(
hasAnalyzer
)
{
netAnalyzerProxy
.
netMsgEvent
(
netMsg
,
getHost
(),
Reason
.
SEND
);
}
if
(
queuedMessages
.
isEmpty
())
{
try
{
this
.
subnet
.
sendTCPMessage
(
netMsg
);
}
catch
(
final
Exception
e
)
{
/*
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
ERROR
,
"Exception..: sendTCP failed. %s"
,
e
);
assert
(
false
)
:
"sendTCP failed: "
+
e
;
}
}
queuedMessages
.
add
(
netMsg
);
}
else
{
/*
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
ERROR
,
"Unsupported transport protocol "
+
tpMsg
);
assert
(
false
)
:
"Unsupported transport protocol "
+
tpMsg
;
}
}
else
{
Monitor
.
log
(
FairshareNode
.
class
,
Level
.
WARN
,
"Host "
+
this
+
" is offline."
);
}
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.AbstractNetLayer#isSupported(de.tud.kom.p2psim.api.transport.TransProtocol)
*/
@Override
protected
boolean
isSupported
(
TransProtocol
protocol
)
{
return
(
protocol
.
equals
(
TransProtocol
.
UDP
)
||
protocol
.
equals
(
TransProtocol
.
TCP
));
}
/**
* Checks if message queue is empty.
*
* @param receiver the receiver
* @return true, if is message queue empty
*/
public
boolean
isMessageQueueEmpty
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
isEmpty
();
}
/**
* Peek message queue and return size of next expected arrival.
*
* @param receiver the receiver
* @return the double
*/
public
double
peekMessageQueue
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
get
(
0
).
getSize
();
}
/**
* Gets a read-only view on message queue.
*
* @param receiver the receiver
* @return the view on message queue
*/
public
List
<
NetMessage
>
getViewOnMessageQueue
(
FairshareNode
receiver
)
{
return
Collections
.
unmodifiableList
(
this
.
hostQueues
.
get
(
receiver
));
}
/**
* Removes the message from queue.
*
* @param receiver the receiver
* @return the net message
*/
public
NetMessage
removeMessageFromQueue
(
FairshareNode
receiver
)
{
return
this
.
hostQueues
.
get
(
receiver
).
remove
(
0
);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public
boolean
equals
(
Object
obj
)
{
return
(
obj
instanceof
FairshareNode
)
?
((
FairshareNode
)
obj
).
getNetID
().
hashCode
()
==
this
.
getNetID
().
hashCode
()
:
super
.
equals
(
obj
);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
this
.
getLocalInetAddress
()
+
" (U:"
+
this
.
getCurrentBandwidth
().
getUpBW
()
+
"/D:"
+
this
.
getCurrentBandwidth
().
getDownBW
()
+
")"
;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public
int
hashCode
()
{
/* Precomputed to save time. */
return
this
.
hashCode
;
}
}
src/de/tud/kom/p2psim/impl/network/gnp/GnpLatencyModel.java
View file @
0c80da45
...
...
@@ -19,12 +19,10 @@
*/
package
de.tud.kom.p2psim.impl.network.gnp
;
package
de.tud.kom.p2psim.impl.network.gnp
;
import
java.util.Random
;
import
umontreal.iro.lecuyer.probdist.LognormalDist
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.linklayer.mac.PhyType
;
import
de.tud.kom.p2psim.api.network.NetLatencyModel
;
import
de.tud.kom.p2psim.api.network.NetLayer
;
...
...
@@ -35,133 +33,135 @@ import de.tud.kom.p2psim.impl.network.gnp.topology.CountryLookup;
import
de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
umontreal.iro.lecuyer.probdist.LognormalDist
;
public
class
GnpLatencyModel
implements
NetLatencyModel
{
private
Random
rnd
=
Randoms
.
getRandom
(
GnpLatencyModel
.
class
);
private
Random
rnd
=
Randoms
.
getRandom
(
GnpLatencyModel
.
class
);
public
static
final
int
MSS
=
PhyType
.
ETHERNET
.
getDefaultMTU
()
-
NetProtocol
.
IPv4
.
getHeaderSize
()
-
TransProtocol
.
TCP
.
getHeaderSize
();
private
static
PingErLookup
pingErLookup
;
private
static
CountryLookup
countryLookup
;
private
boolean
usePingErInsteadOfGnp
=
false
;
private
boolean
useAnalyticalFunctionInsteadOfGnp
=
false
;
private
boolean
usePingErJitter
=
false
;
private
boolean
usePingErPacketLoss
=
false
;
public
void
init
(
PingErLookup
pingErLookup
,
CountryLookup
countryLookup
)
{
GnpLatencyModel
.
pingErLookup
=
pingErLookup
;
GnpLatencyModel
.
countryLookup
=
countryLookup
;
}
private
double
getMinimumRTT
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
minRtt
=
0.0
;
if
(
usePingErInsteadOfGnp
)
{
minRtt
=
pingErLookup
.
getMinimumRtt
(
ccSender
,
ccReceiver
,
countryLookup
);
}
else
if
(
useAnalyticalFunctionInsteadOfGnp
)
{
double
distance
=
GeoLocationOracle
.
getGeographicalDistance
(
sender
.
getNetID
(),
receiver
.
getNetID
());
minRtt
=
62
+
(
0.02
*
distance
);
}
else
{
Posi
tion
senderPos
=
sender
.
getNetPosition
();
Posi
tion
receiverPos
=
receiver
.
getNetPosition
();
minRtt
=
senderPos
.
getD
istance
(
receiverPos
);
}
return
minRtt
;
}
private
double
getPacketLossProbability
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
twoWayLossRate
=
0.0
;
double
oneWayLossRate
=
0.0
;
if
(
usePingErPacketLoss
)
{
twoWayLossRate
=
pingErLookup
.
getPacktLossRate
(
ccSender
,
ccReceiver
,
countryLookup
);
twoWayLossRate
/=
100
;
oneWayLossRate
=
1
-
Math
.
sqrt
(
1
-
twoWayLossRate
);
}
return
oneWayLossRate
;
}
private
double
getNextJitter
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
randomJitter
=
0.0
;
if
(
usePingErJitter
)
{
LognormalDist
distri
=
pingErLookup
.
getJitterDistribution
(
ccSender
,
ccReceiver
,
countryLookup
);
randomJitter
=
distri
.
inverseF
(
rnd
.
nextDouble
());
}
return
randomJitter
;
}
private
double
getAverageJitter
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
jitter
=
0.0
;
if
(
usePingErJitter
)
{
jitter
=
pingErLookup
.
getAverageRtt
(
ccSender
,
ccReceiver
,
countryLookup
)
-
pingErLookup
.
getMinimumRtt
(
ccSender
,
ccReceiver
,
countryLookup
);
}
return
jitter
;
}
public
double
getUDPerrorProbability
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
,
IPv4Message
msg
)
{
if
(
msg
.
getPayload
().
getSize
()
>
65507
)
throw
new
IllegalArgumentException
(
"Message-Size ist too big for a UDP-Datagramm (max 65507 byte)"
);
double
lp
=
getPacketLossProbability
(
sender
,
receiver
);
double
errorProb
=
1
-
Math
.
pow
(
1
-
lp
,
msg
.
getNoOfFragments
());
return
errorProb
;
}
public
double
getTcpThroughput
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
double
minRtt
=
getMinimumRTT
(
sender
,
receiver
);
double
averageJitter
=
getAverageJitter
(
sender
,
receiver
);
double
packetLossRate
=
getPacketLossProbability
(
sender
,
receiver
);
double
mathisBW
=
((
MSS
*
1000
)
/
(
minRtt
+
averageJitter
))
*
Math
.
sqrt
(
1.5
/
packetLossRate
);
return
mathisBW
;
}
public
long
getTransmissionDelay
(
double
bytes
,
double
bandwidth
)
{
double
messageTime
=
bytes
/
bandwidth
;
long
delay
=
Math
.
round
((
messageTime
*
Time
.
SECOND
));
return
delay
;
}
public
long
getPropagationDelay
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
double
minRtt
=
getMinimumRTT
(
sender
,
receiver
);
double
randomJitter
=
getNextJitter
(
sender
,
receiver
);
double
receiveTime
=
(
minRtt
+
randomJitter
)
/
2.0
;
long
latency
=
Math
.
round
(
receiveTime
*
Time
.
MILLISECOND
);
return
latency
;
}
public
long
getLatency
(
NetLayer
sender
,
NetLayer
receiver
)
{
return
getPropagationDelay
((
GnpNetLayer
)
sender
,
(
GnpNetLayer
)
receiver
);
}
public
void
setUsePingErRttData
(
boolean
pingErRtt
)
{
usePingErInsteadOfGnp
=
pingErRtt
;
}
public
void
setUseAnalyticalRtt
(
boolean
analyticalRtt
)
{
useAnalyticalFunctionInsteadOfGnp
=
analyticalRtt
;
}
public
void
setUsePingErJitter
(
boolean
pingErRtt
)
{
usePingErJitter
=
pingErRtt
;
}
public
void
setUsePingErPacketLoss
(
boolean
pingErPacketLoss
)
{
usePingErPacketLoss
=
pingErPacketLoss
;
}
-
TransProtocol
.
TCP
.
getHeaderSize
();
private
static
PingErLookup
pingErLookup
;
private
static
CountryLookup
countryLookup
;
private
boolean
usePingErInsteadOfGnp
=
false
;
private
boolean
useAnalyticalFunctionInsteadOfGnp
=
false
;
private
boolean
usePingErJitter
=
false
;
private
boolean
usePingErPacketLoss
=
false
;
public
void
init
(
PingErLookup
pingErLookup
,
CountryLookup
countryLookup
)
{
GnpLatencyModel
.
pingErLookup
=
pingErLookup
;
GnpLatencyModel
.
countryLookup
=
countryLookup
;
}
private
double
getMinimumRTT
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
minRtt
=
0.0
;
if
(
usePingErInsteadOfGnp
)
{
minRtt
=
pingErLookup
.
getMinimumRtt
(
ccSender
,
ccReceiver
,
countryLookup
);
}
else
if
(
useAnalyticalFunctionInsteadOfGnp
)
{
double
distance
=
GeoLocationOracle
.
getGeographicalDistance
(
sender
.
getNetID
(),
receiver
.
getNetID
());
minRtt
=
62
+
(
0.02
*
distance
);
}
else
{
Loca
tion
senderPos
=
sender
.
getNetPosition
();
Loca
tion
receiverPos
=
receiver
.
getNetPosition
();
minRtt
=
senderPos
.
d
istance
To
(
receiverPos
);
}
return
minRtt
;
}
private
double
getPacketLossProbability
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
twoWayLossRate
=
0.0
;
double
oneWayLossRate
=
0.0
;
if
(
usePingErPacketLoss
)
{
twoWayLossRate
=
pingErLookup
.
getPacktLossRate
(
ccSender
,
ccReceiver
,
countryLookup
);
twoWayLossRate
/=
100
;
oneWayLossRate
=
1
-
Math
.
sqrt
(
1
-
twoWayLossRate
);
}
return
oneWayLossRate
;
}
private
double
getNextJitter
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
randomJitter
=
0.0
;
if
(
usePingErJitter
)
{
LognormalDist
distri
=
pingErLookup
.
getJitterDistribution
(
ccSender
,
ccReceiver
,
countryLookup
);
randomJitter
=
distri
.
inverseF
(
rnd
.
nextDouble
());
}
return
randomJitter
;
}
private
double
getAverageJitter
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
String
ccSender
=
sender
.
getCountryCode
();
String
ccReceiver
=
receiver
.
getCountryCode
();
double
jitter
=
0.0
;
if
(
usePingErJitter
)
{
jitter
=
pingErLookup
.
getAverageRtt
(
ccSender
,
ccReceiver
,
countryLookup
)
-
pingErLookup
.
getMinimumRtt
(
ccSender
,
ccReceiver
,
countryLookup
);
}
return
jitter
;
}
public
double
getUDPerrorProbability
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
,
IPv4Message
msg
)
{
if
(
msg
.
getPayload
().
getSize
()
>
65507
)
throw
new
IllegalArgumentException
(
"Message-Size ist too big for a UDP-Datagramm (max 65507 byte)"
);
double
lp
=
getPacketLossProbability
(
sender
,
receiver
);
double
errorProb
=
1
-
Math
.
pow
(
1
-
lp
,
msg
.
getNoOfFragments
());
return
errorProb
;
}
public
double
getTcpThroughput
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
double
minRtt
=
getMinimumRTT
(
sender
,
receiver
);
double
averageJitter
=
getAverageJitter
(
sender
,
receiver
);
double
packetLossRate
=
getPacketLossProbability
(
sender
,
receiver
);
double
mathisBW
=
((
MSS
*
1000
)
/
(
minRtt
+
averageJitter
))
*
Math
.
sqrt
(
1.5
/
packetLossRate
);
return
mathisBW
;
}
public
long
getTransmissionDelay
(
double
bytes
,
double
bandwidth
)
{
double
messageTime
=
bytes
/
bandwidth
;
long
delay
=
Math
.
round
((
messageTime
*
Time
.
SECOND
));
return
delay
;
}
public
long
getPropagationDelay
(
GnpNetLayer
sender
,
GnpNetLayer
receiver
)
{
double
minRtt
=
getMinimumRTT
(
sender
,
receiver
);
double
randomJitter
=
getNextJitter
(
sender
,
receiver
);
double
receiveTime
=
(
minRtt
+
randomJitter
)
/
2.0
;
long
latency
=
Math
.
round
(
receiveTime
*
Time
.
MILLISECOND
);
return
latency
;
}
public
long
getLatency
(
NetLayer
sender
,
NetLayer
receiver
)
{
return
getPropagationDelay
((
GnpNetLayer
)
sender
,
(
GnpNetLayer
)
receiver
);
}
public
void
setUsePingErRttData
(
boolean
pingErRtt
)
{
usePingErInsteadOfGnp
=
pingErRtt
;
}
public
void
setUseAnalyticalRtt
(
boolean
analyticalRtt
)
{
useAnalyticalFunctionInsteadOfGnp
=
analyticalRtt
;
}
public
void
setUsePingErJitter
(
boolean
pingErRtt
)
{
usePingErJitter
=
pingErRtt
;
}
public
void
setUsePingErPacketLoss
(
boolean
pingErPacketLoss
)
{
usePingErPacketLoss
=
pingErPacketLoss
;
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/network/gnp/topology/GeographicPosition.java
View file @
0c80da45
...
...
@@ -19,59 +19,53 @@
*/
package
de.tud.kom.p2psim.impl.network.gnp.topology
;
package
de.tud.kom.p2psim.impl.network.gnp.topology
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
/**
* Implementation of NetPosition for Position and distance measurnment on the
* earth.
*
* @author Gerald Klunker
* @version 0.1, 05.02.2008
*
*/
public
class
GeographicPosition
extends
PositionVector
{
private
double
latitude
;
private
double
longitude
;
/**
*
* @param longitude
* @param latitude
*/
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* Implementation of NetPosition for Position and distance measurnment on the
* earth.
*
* @author Gerald Klunker
* @version 0.1, 05.02.2008
*
*/
public
class
GeographicPosition
extends
PositionVector
{
private
double
latitude
;
private
double
longitude
;
/**
*
* @param longitude
* @param latitude
*/
public
GeographicPosition
(
double
longitude
,
double
latitude
)
{
super
(
new
double
[]
{
longitude
,
latitude
});
this
.
longitude
=
longitude
;
this
.
latitude
=
latitude
;
}
/**
* @return geographical distance in km
*/
public
double
getDistance
(
Position
point
)
{
double
pi
=
3.14159265
;
double
radConverter
=
pi
/
180
;
double
lat1
=
latitude
*
radConverter
;
double
lat2
=
((
GeographicPosition
)
point
).
getLatitude
()
*
radConverter
;
double
delta_lat
=
lat2
-
lat1
;
double
delta_lon
=
(((
GeographicPosition
)
point
).
getLongitude
()
-
longitude
)
*
radConverter
;
double
temp
=
Math
.
pow
(
Math
.
sin
(
delta_lat
/
2
),
2
)
+
Math
.
cos
(
lat1
)
*
Math
.
cos
(
lat2
)
*
Math
.
pow
(
Math
.
sin
(
delta_lon
/
2
),
2
);
return
2
*
6378.2
*
Math
.
atan2
(
Math
.
sqrt
(
temp
),
Math
.
sqrt
(
1
-
temp
));
super
(
new
double
[]
{
longitude
,
latitude
});
this
.
longitude
=
longitude
;
this
.
latitude
=
latitude
;
}
@Override
public
double
getAngle
(
Position
target
)
{
throw
new
AssertionError
(
"getAngle is not defined for this Position-Type"
);
/**
* @return geographical distance in km
*/
public
double
distanceTo
(
Location
point
)
{
double
pi
=
3.14159265
;
double
radConverter
=
pi
/
180
;
double
lat1
=
latitude
*
radConverter
;
double
lat2
=
((
GeographicPosition
)
point
).
getLatitude
()
*
radConverter
;
double
delta_lat
=
lat2
-
lat1
;
double
delta_lon
=
(((
GeographicPosition
)
point
).
getLongitude
()
-
longitude
)
*
radConverter
;
double
temp
=
Math
.
pow
(
Math
.
sin
(
delta_lat
/
2
),
2
)
+
Math
.
cos
(
lat1
)
*
Math
.
cos
(
lat2
)
*
Math
.
pow
(
Math
.
sin
(
delta_lon
/
2
),
2
);
return
2
*
6378.2
*
Math
.
atan2
(
Math
.
sqrt
(
temp
),
Math
.
sqrt
(
1
-
temp
));
}
@Override
...
...
@@ -81,22 +75,22 @@ public class GeographicPosition extends PositionVector {
public
GeographicPosition
clone
()
{
return
new
GeographicPosition
(
longitude
,
latitude
);
}
/**
*
* @return latitude of position
*/
public
double
getLatitude
()
{
return
latitude
;
}
/**
*
* @return longitude of position
*/
public
double
getLongitude
()
{
return
longitude
;
}
}
}
/**
*
* @return latitude of position
*/
public
double
getLatitude
()
{
return
latitude
;
}
/**
*
* @return longitude of position
*/
public
double
getLongitude
()
{
return
longitude
;
}
}
src/de/tud/kom/p2psim/impl/network/gnp/topology/GnpPosition.java
View file @
0c80da45
...
...
@@ -19,296 +19,283 @@
*/
package
de.tud.kom.p2psim.impl.network.gnp.topology
;
package
de.tud.kom.p2psim.impl.network.gnp.topology
;
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
* times. Therefore it includes methods for error estimation and methods for
* positioning by a downhill simplex algorithm in the GnpSpace class
*
* @author Gerald Klunker
* @version 0.1, 09.01.2008
*
*/
public
class
GnpPosition
implements
Position
,
Comparable
<
GnpPosition
>
{
private
static
final
long
serialVersionUID
=
-
1103996725403557900L
;
private
double
[]
gnpCoordinates
;
private
GnpSpace
gnpRef
;
private
Host
hostRef
;
private
double
error
=
-
1.0
;
/**
*
* @param gnpCoordinates
* coordinate array for new position
*/
public
GnpPosition
(
double
[]
gnpCoordinates
)
{
super
();
this
.
gnpCoordinates
=
gnpCoordinates
;
}
/**
* Object will be initialized with a random position. Position must be
* random according to the downhill simplex
*
* @param noOfDimensions
* number of dimensions
* @param hostRef
* related Host object
* @param gnpRef
* related GnpSpace object
*/
public
GnpPosition
(
int
noOfDimensions
,
Host
hostRef
,
GnpSpace
gnpRef
)
{
super
();
gnpCoordinates
=
new
double
[
noOfDimensions
];
this
.
hostRef
=
hostRef
;
this
.
gnpRef
=
gnpRef
;
for
(
int
c
=
0
;
c
<
gnpCoordinates
.
length
;
c
++)
/**
* This class implements a NetPosition for a GNP-Based calculation of round trip
* times. Therefore it includes methods for error estimation and methods for
* positioning by a downhill simplex algorithm in the GnpSpace class
*
* @author Gerald Klunker
* @version 0.1, 09.01.2008
*
*/
public
class
GnpPosition
implements
Location
,
Comparable
<
GnpPosition
>
{
private
static
final
long
serialVersionUID
=
-
1103996725403557900L
;
private
double
[]
gnpCoordinates
;
private
GnpSpace
gnpRef
;
private
Host
hostRef
;
private
double
error
=
-
1.0
;
/**
*
* @param gnpCoordinates
* coordinate array for new position
*/
public
GnpPosition
(
double
[]
gnpCoordinates
)
{
super
();
this
.
gnpCoordinates
=
gnpCoordinates
;
}
/**
* Object will be initialized with a random position. Position must be
* random according to the downhill simplex
*
* @param noOfDimensions
* number of dimensions
* @param hostRef
* related Host object
* @param gnpRef
* related GnpSpace object
*/
public
GnpPosition
(
int
noOfDimensions
,
Host
hostRef
,
GnpSpace
gnpRef
)
{
super
();
gnpCoordinates
=
new
double
[
noOfDimensions
];
this
.
hostRef
=
hostRef
;
this
.
gnpRef
=
gnpRef
;
for
(
int
c
=
0
;
c
<
gnpCoordinates
.
length
;
c
++)
gnpCoordinates
[
c
]
=
Randoms
.
getRandom
(
GnpPosition
.
class
)
.
nextDouble
();
}
/**
*
* @param dimension
* @param maxDiversity
*/
public
void
diversify
(
double
[][]
dimension
,
double
maxDiversity
)
{
for
(
int
c
=
0
;
c
<
this
.
gnpCoordinates
.
length
;
c
++)
{
double
rand
=
(
2
*
maxDiversity
*
Math
.
random
())
-
maxDiversity
;
gnpCoordinates
[
c
]
=
gnpCoordinates
[
c
]
+
(
rand
*
dimension
[
c
][
2
]);
}
error
=
-
1.0
;
}
/**
* reposition
*
* @param pos
* position in the coordinate array
* @param value
* new value at position pos
*/
public
void
setGnpCoordinates
(
int
pos
,
double
value
)
{
gnpCoordinates
[
pos
]
=
value
;
error
=
-
1.0
;
}
/**
*
* @return the related GnpSpace object
*/
private
GnpSpace
getGnpRef
()
{
return
gnpRef
;
}
/**
*
* @return the related Host object
*/
public
Host
getHostRef
()
{
return
hostRef
;
}
/**
*
* @return number of dimensions
*/
public
int
getNoOfDimensions
()
{
return
gnpCoordinates
.
length
;
}
/**
*
* @param pos
* position in the coordinate array
* @return value at position pos
*/
public
double
getGnpCoordinates
(
int
pos
)
{
return
gnpCoordinates
[
pos
];
}
/**
* Calculates the sum of all errors according to the downhill simplex
* operator.
*
* @return error
*/
public
double
getDownhillSimplexError
()
{
if
(
error
<
0.0
)
{
error
=
0.0
;
for
(
int
c
=
0
;
c
<
getGnpRef
().
getNumberOfMonitors
();
c
++)
{
error
+=
getDownhillSimplexError
(
getGnpRef
()
.
getMonitorPosition
(
c
));
}
}
return
error
;
}
/**
* Calculates the error to a monitor according to the downhill simplex
* operator
*
* @param monitor
* @return error
*/
public
double
getDownhillSimplexError
(
GnpPosition
monitor
)
{
double
calculatedDistance
=
this
.
getDistance
(
monitor
);
double
measuredDistance
=
this
.
getMeasuredRtt
(
monitor
);
if
(
Double
.
compare
(
measuredDistance
,
Double
.
NaN
)
==
0
)
return
0.0
;
double
error
=
Math
.
pow
((
calculatedDistance
-
measuredDistance
)
/
calculatedDistance
,
2
);
return
error
;
}
/**
* Calculates an error, that indicates the deviation of the measured vs. the
* calculated rtt.
*
* @param monitor
* @return error value
*/
public
double
getDirectionalRelativError
(
GnpPosition
monitor
)
{
double
calculatedDistance
=
this
.
getDistance
(
monitor
);
double
measuredDistance
=
this
.
getMeasuredRtt
(
monitor
);
if
(
Double
.
compare
(
measuredDistance
,
Double
.
NaN
)
==
0
)
return
Double
.
NaN
;
double
error
=
(
calculatedDistance
-
measuredDistance
)
/
Math
.
min
(
calculatedDistance
,
measuredDistance
);
return
error
;
}
/**
* Method must be overwrite to sort different GnpPositions in order of their
* quality.
*
* Is needed for the positioning with the downhill simplex
*
*/
public
int
compareTo
(
GnpPosition
arg0
)
{
double
val1
=
this
.
getDownhillSimplexError
();
double
val2
=
arg0
.
getDownhillSimplexError
();
if
(
val1
<
val2
)
return
-
1
;
if
(
val1
>
val2
)
return
1
;
else
return
0
;
}
/**
*
* @return Comma-separated list of coordinates
*/
public
String
getCoordinateString
()
{
if
(
gnpCoordinates
.
length
==
0
)
{
return
""
;
}
else
{
String
result
=
String
.
valueOf
(
gnpCoordinates
[
0
]);
for
(
int
c
=
1
;
c
<
gnpCoordinates
.
length
;
c
++)
result
=
result
+
","
+
gnpCoordinates
[
c
];
return
result
;
}
}
/**
*
* @param monitor
* @return measured rtt to monitor, nan if no rtt was measured
*/
public
double
getMeasuredRtt
(
GnpPosition
monitor
)
{
return
this
.
getHostRef
().
getRtt
(
monitor
.
getHostRef
());
}
/**
* @return euclidean distance
*/
public
double
getDistance
(
Position
point
)
{
GnpPosition
coord
=
(
GnpPosition
)
point
;
double
distance
=
0.0
;
for
(
int
c
=
0
;
c
<
gnpCoordinates
.
length
;
c
++)
distance
+=
Math
.
pow
(
gnpCoordinates
[
c
]
-
coord
.
getGnpCoordinates
(
c
),
2
);
return
Math
.
sqrt
(
distance
);
.
nextDouble
();
}
@Override
public
double
getAngle
(
Position
target
)
{
throw
new
AssertionError
(
"getAngle is not defined for this Position-Type"
);
/**
*
* @param dimension
* @param maxDiversity
*/
public
void
diversify
(
double
[][]
dimension
,
double
maxDiversity
)
{
for
(
int
c
=
0
;
c
<
this
.
gnpCoordinates
.
length
;
c
++)
{
double
rand
=
(
2
*
maxDiversity
*
Math
.
random
())
-
maxDiversity
;
gnpCoordinates
[
c
]
=
gnpCoordinates
[
c
]
+
(
rand
*
dimension
[
c
][
2
]);
}
error
=
-
1.0
;
}
@Override
public
Position
getTarget
(
double
distance
,
double
angle
)
{
throw
new
AssertionError
(
"getTarget is not defined for this Position-Type"
);
}
/**
* reposition
*
* @param pos
* position in the coordinate array
* @param value
* new value at position pos
*/
public
void
setGnpCoordinates
(
int
pos
,
double
value
)
{
gnpCoordinates
[
pos
]
=
value
;
error
=
-
1.0
;
}
/**
*
* @return the related GnpSpace object
*/
private
GnpSpace
getGnpRef
()
{
return
gnpRef
;
}
/**
*
* @return the related Host object
*/
public
Host
getHostRef
()
{
return
hostRef
;
}
/**
*
* @return number of dimensions
*/
public
int
getNoOfDimensions
()
{
return
gnpCoordinates
.
length
;
}
/**
*
* @param pos
* position in the coordinate array
* @return value at position pos
*/
public
double
getGnpCoordinates
(
int
pos
)
{
return
gnpCoordinates
[
pos
];
}
/**
* Calculates the sum of all errors according to the downhill simplex
* operator.
*
* @return error
*/
public
double
getDownhillSimplexError
()
{
if
(
error
<
0.0
)
{
error
=
0.0
;
for
(
int
c
=
0
;
c
<
getGnpRef
().
getNumberOfMonitors
();
c
++)
{
error
+=
getDownhillSimplexError
(
getGnpRef
()
.
getMonitorPosition
(
c
));
}
}
return
error
;
}
/**
* Calculates the error to a monitor according to the downhill simplex
* operator
*
* @param monitor
* @return error
*/
public
double
getDownhillSimplexError
(
GnpPosition
monitor
)
{
double
calculatedDistance
=
this
.
distanceTo
(
monitor
);
double
measuredDistance
=
this
.
getMeasuredRtt
(
monitor
);
if
(
Double
.
compare
(
measuredDistance
,
Double
.
NaN
)
==
0
)
return
0.0
;
double
error
=
Math
.
pow
((
calculatedDistance
-
measuredDistance
)
/
calculatedDistance
,
2
);
return
error
;
}
/**
* Calculates an error, that indicates the deviation of the measured vs. the
* calculated rtt.
*
* @param monitor
* @return error value
*/
public
double
getDirectionalRelativError
(
GnpPosition
monitor
)
{
double
calculatedDistance
=
this
.
distanceTo
(
monitor
);
double
measuredDistance
=
this
.
getMeasuredRtt
(
monitor
);
if
(
Double
.
compare
(
measuredDistance
,
Double
.
NaN
)
==
0
)
return
Double
.
NaN
;
double
error
=
(
calculatedDistance
-
measuredDistance
)
/
Math
.
min
(
calculatedDistance
,
measuredDistance
);
return
error
;
}
/**
* Method must be overwrite to sort different GnpPositions in order of their
* quality.
*
* Is needed for the positioning with the downhill simplex
*
*/
public
int
compareTo
(
GnpPosition
arg0
)
{
double
val1
=
this
.
getDownhillSimplexError
();
double
val2
=
arg0
.
getDownhillSimplexError
();
if
(
val1
<
val2
)
return
-
1
;
if
(
val1
>
val2
)
return
1
;
else
return
0
;
}
/**
*
* @return Comma-separated list of coordinates
*/
public
String
getCoordinateString
()
{
if
(
gnpCoordinates
.
length
==
0
)
{
return
""
;
}
else
{
String
result
=
String
.
valueOf
(
gnpCoordinates
[
0
]);
for
(
int
c
=
1
;
c
<
gnpCoordinates
.
length
;
c
++)
result
=
result
+
","
+
gnpCoordinates
[
c
];
return
result
;
}
}
/**
*
* @param monitor
* @return measured rtt to monitor, nan if no rtt was measured
*/
public
double
getMeasuredRtt
(
GnpPosition
monitor
)
{
return
this
.
getHostRef
().
getRtt
(
monitor
.
getHostRef
());
}
/**
* @return euclidean distance
*/
public
double
getDistance
(
Location
point
)
{
GnpPosition
coord
=
(
GnpPosition
)
point
;
double
distance
=
0.0
;
for
(
int
c
=
0
;
c
<
gnpCoordinates
.
length
;
c
++)
distance
+=
Math
.
pow
(
gnpCoordinates
[
c
]
-
coord
.
getGnpCoordinates
(
c
),
2
);
return
Math
.
sqrt
(
distance
);
}
@Override
public
int
getTransmissionSize
()
{
return
16
;
// 2 * double
}
/**
* Static method generates a new GnpPosition according to the downhill
* simplex operator
*
* @param solution
* @param moveToSolution
* @param moveFactor
* @return new position
*/
public
static
GnpPosition
getMovedSolution
(
GnpPosition
solution
,
GnpPosition
moveToSolution
,
double
moveFactor
)
{
GnpPosition
returnValue
=
new
GnpPosition
(
solution
.
getNoOfDimensions
(),
solution
.
getHostRef
(),
solution
.
getGnpRef
());
for
(
int
c
=
0
;
c
<
solution
.
getNoOfDimensions
();
c
++)
{
double
newCoord
=
(
moveToSolution
.
getGnpCoordinates
(
c
)
-
solution
.
getGnpCoordinates
(
c
))
*
moveFactor
+
solution
.
getGnpCoordinates
(
c
);
returnValue
.
setGnpCoordinates
(
c
,
newCoord
);
}
return
returnValue
;
}
/**
* Static method generates a new GnpPosition according to the downhill
* simplex operator
*
* @param solution
* @param moveToSolution
* @param moveFactor
* @return new position
*/
public
static
GnpPosition
getCenterSolution
(
ArrayList
<
GnpPosition
>
solutions
)
{
GnpPosition
returnValue
=
new
GnpPosition
(
solutions
.
get
(
0
)
.
getNoOfDimensions
(),
solutions
.
get
(
0
).
getHostRef
(),
solutions
.
get
(
0
).
getGnpRef
());
for
(
int
d
=
0
;
d
<
solutions
.
size
();
d
++)
{
for
(
int
c
=
0
;
c
<
solutions
.
get
(
0
).
getNoOfDimensions
();
c
++)
{
returnValue
.
setGnpCoordinates
(
c
,
returnValue
.
getGnpCoordinates
(
c
)
+
solutions
.
get
(
d
).
getGnpCoordinates
(
c
));
}
}
for
(
int
c
=
0
;
c
<
returnValue
.
getNoOfDimensions
();
c
++)
{
returnValue
.
setGnpCoordinates
(
c
,
returnValue
.
getGnpCoordinates
(
c
)
/
solutions
.
size
());
}
return
returnValue
;
/**
* Static method generates a new GnpPosition according to the downhill
* simplex operator
*
* @param solution
* @param moveToSolution
* @param moveFactor
* @return new position
*/
public
static
GnpPosition
getMovedSolution
(
GnpPosition
solution
,
GnpPosition
moveToSolution
,
double
moveFactor
)
{
GnpPosition
returnValue
=
new
GnpPosition
(
solution
.
getNoOfDimensions
(),
solution
.
getHostRef
(),
solution
.
getGnpRef
());
for
(
int
c
=
0
;
c
<
solution
.
getNoOfDimensions
();
c
++)
{
double
newCoord
=
(
moveToSolution
.
getGnpCoordinates
(
c
)
-
solution
.
getGnpCoordinates
(
c
))
*
moveFactor
+
solution
.
getGnpCoordinates
(
c
);
returnValue
.
setGnpCoordinates
(
c
,
newCoord
);
}
return
returnValue
;
}
/**
* Static method generates a new GnpPosition according to the downhill
* simplex operator
*
* @param solution
* @param moveToSolution
* @param moveFactor
* @return new position
*/
public
static
GnpPosition
getCenterSolution
(
ArrayList
<
GnpPosition
>
solutions
)
{
GnpPosition
returnValue
=
new
GnpPosition
(
solutions
.
get
(
0
)
.
getNoOfDimensions
(),
solutions
.
get
(
0
).
getHostRef
(),
solutions
.
get
(
0
).
getGnpRef
());
for
(
int
d
=
0
;
d
<
solutions
.
size
();
d
++)
{
for
(
int
c
=
0
;
c
<
solutions
.
get
(
0
).
getNoOfDimensions
();
c
++)
{
returnValue
.
setGnpCoordinates
(
c
,
returnValue
.
getGnpCoordinates
(
c
)
+
solutions
.
get
(
d
).
getGnpCoordinates
(
c
));
}
}
for
(
int
c
=
0
;
c
<
returnValue
.
getNoOfDimensions
();
c
++)
{
returnValue
.
setGnpCoordinates
(
c
,
returnValue
.
getGnpCoordinates
(
c
)
/
solutions
.
size
());
}
return
returnValue
;
}
public
GnpPosition
clone
()
{
...
...
@@ -323,7 +310,7 @@ public class GnpPosition implements Position, Comparable<GnpPosition> {
@Override
public
double
distanceTo
(
Location
dest
)
{
return
getDistance
(
(
Position
)
dest
);
return
getDistance
(
dest
);
}
@Override
...
...
@@ -344,5 +331,5 @@ public class GnpPosition implements Position, Comparable<GnpPosition> {
@Override
public
void
set
(
Location
l
)
{
throw
new
UnsupportedOperationException
();
}
}
}
}
src/de/tud/kom/p2psim/impl/network/gnp/topology/HostMap.java
View file @
0c80da45
This diff is collapsed.
Click to expand it.
src/de/tud/kom/p2psim/impl/network/modular/ModularNetLayer.java
View file @
0c80da45
...
...
@@ -23,7 +23,6 @@ package de.tud.kom.p2psim.impl.network.modular;
import
java.util.Collection
;
import
de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.network.BandwidthImpl
;
import
de.tud.kom.p2psim.api.network.NetMessage
;
...
...
@@ -54,6 +53,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.Bandwidth
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetID
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* <p>
...
...
@@ -113,7 +113,8 @@ public class ModularNetLayer extends AbstractNetLayer {
* Device-Type of this Host
*/
ModularNetLayer
(
SimHost
host
,
AbstractModularSubnet
subnet
,
BandwidthImpl
maxBW
,
NetMeasurementDB
.
Host
hostMeta
,
Position
position
,
BandwidthImpl
maxBW
,
NetMeasurementDB
.
Host
hostMeta
,
Location
position
,
IPv4NetID
id
)
{
super
(
host
,
id
,
maxBW
,
position
,
hostMeta
);
this
.
subnet
=
subnet
;
...
...
src/de/tud/kom/p2psim/impl/network/modular/st/PositioningStrategy.java
View file @
0c80da45
...
...
@@ -21,9 +21,9 @@
package
de.tud.kom.p2psim.impl.network.modular.st
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* This strategy determines an abstract network position of a given host
...
...
@@ -43,7 +43,7 @@ public interface PositioningStrategy extends ModNetLayerStrategy {
* @param hostMeta
* @return
*/
public
Posi
tion
getPosition
(
public
Loca
tion
getPosition
(
SimHost
host
,
NetMeasurementDB
db
,
NetMeasurementDB
.
Host
hostMeta
);
...
...
src/de/tud/kom/p2psim/impl/network/modular/st/latency/FootprintLatency.java
View file @
0c80da45
...
...
@@ -30,7 +30,8 @@ public class FootprintLatency implements LatencyStrategy {
throw
new
IllegalArgumentException
(
"FootprintLatency is incompatible with the NetMeasurementDB"
);
}
double
distance
=
nlSender
.
getNetPosition
().
getDistance
(
nlReceiver
.
getNetPosition
());
double
distance
=
nlSender
.
getNetPosition
()
.
distanceTo
(
nlReceiver
.
getNetPosition
());
return
(
staticPart
+
Math
.
round
(
geoDistFactor
*
distance
))
*
Time
.
MILLISECOND
;
...
...
src/de/tud/kom/p2psim/impl/network/modular/st/latency/SimpleLatencyModel.java
View file @
0c80da45
...
...
@@ -19,12 +19,11 @@
*/
package
de.tud.kom.p2psim.impl.network.modular.st.latency
;
package
de.tud.kom.p2psim.impl.network.modular.st.latency
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.network.NetLayer
;
import
de.tud.kom.p2psim.api.network.NetMessage
;
import
de.tud.kom.p2psim.impl.network.AbstractNetLayer
;
...
...
@@ -33,50 +32,51 @@ import de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy;
import
de.tud.kom.p2psim.impl.network.simple.SimpleSubnet
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
/**
* This model is abstracting the details of the four lower OSI layers (UDP and
* TCP) from the end-to-end connections between peers although important network
* characteristics, like the geographical distance between peers, the processing
* delay of intermediate systems, signal propagation, congestions,
* retransmission and packet loss are incorporated into it. The message delay is
* calculated using the following formula:
*
* Message delay = f * (df + dist/v)
*
* where dist - describes the geographical distance between the start and the
* end point of the transmission, df - represents the processing delay of the
* intermediate systems, v - stands for the speed of the signal propagation
* through the transmission medium, and f - is a variable part which
* encapsulates the retransmission, congestion.
*
* @author Sebastian Kaune
*
*/
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* This model is abstracting the details of the four lower OSI layers (UDP and
* TCP) from the end-to-end connections between peers although important network
* characteristics, like the geographical distance between peers, the processing
* delay of intermediate systems, signal propagation, congestions,
* retransmission and packet loss are incorporated into it. The message delay is
* calculated using the following formula:
*
* Message delay = f * (df + dist/v)
*
* where dist - describes the geographical distance between the start and the
* end point of the transmission, df - represents the processing delay of the
* intermediate systems, v - stands for the speed of the signal propagation
* through the transmission medium, and f - is a variable part which
* encapsulates the retransmission, congestion.
*
* @author Sebastian Kaune
*
*/
public
class
SimpleLatencyModel
implements
LatencyStrategy
{
private
Random
rnd
=
Randoms
.
getRandom
(
SimpleLatencyModel
.
class
);
/**
* Speed in kilometer per second
*/
private
final
int
signalSpeed
=
100000
;
/**
* Earth circumference in kilometres
*/
private
final
int
earth_circumference
=
40000
;
private
final
double
relSignalSpeed
;
/**
* Constructor
*
*/
public
SimpleLatencyModel
()
{
relSignalSpeed
=
signalSpeed
*
(
SimpleSubnet
.
SUBNET_WIDTH
/
earth_circumference
);
}
private
Random
rnd
=
Randoms
.
getRandom
(
SimpleLatencyModel
.
class
);
/**
* Speed in kilometer per second
*/
private
final
int
signalSpeed
=
100000
;
/**
* Earth circumference in kilometres
*/
private
final
int
earth_circumference
=
40000
;
private
final
double
relSignalSpeed
;
/**
* Constructor
*
*/
public
SimpleLatencyModel
()
{
relSignalSpeed
=
signalSpeed
*
(
SimpleSubnet
.
SUBNET_WIDTH
/
earth_circumference
);
}
/**
* Gets the distance.
*
...
...
@@ -84,12 +84,12 @@ public class SimpleLatencyModel implements LatencyStrategy {
* @param receiver the receiver
* @return the distance
*/
public
double
getDistance
(
NetLayer
sender
,
NetLayer
receiver
)
{
Posi
tion
ps
=
sender
.
getNetPosition
();
Posi
tion
pr
=
receiver
.
getNetPosition
();
return
ps
.
getD
istance
(
pr
);
}
public
double
getDistance
(
NetLayer
sender
,
NetLayer
receiver
)
{
Loca
tion
ps
=
sender
.
getNetPosition
();
Loca
tion
pr
=
receiver
.
getNetPosition
();
return
ps
.
d
istance
To
(
pr
);
}
/**
* Calc static delay.
*
...
...
@@ -97,9 +97,9 @@ public class SimpleLatencyModel implements LatencyStrategy {
* @param distance the distance
* @return the double
*/
public
double
calcStaticDelay
(
NetLayer
receiver
,
double
distance
)
{
int
df
=
Math
.
abs
(
receiver
.
hashCode
()
%
31
);
return
(
df
+
(
distance
/
relSignalSpeed
)
*
1000
);
public
double
calcStaticDelay
(
NetLayer
receiver
,
double
distance
)
{
int
df
=
Math
.
abs
(
receiver
.
hashCode
()
%
31
);
return
(
df
+
(
distance
/
relSignalSpeed
)
*
1000
);
}
@Override
...
...
@@ -119,6 +119,6 @@ public class SimpleLatencyModel implements LatencyStrategy {
@Override
public
void
writeBackToXML
(
BackWriter
bw
)
{
// None.
}
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/network/modular/st/latency/SimpleStaticLatencyModel.java
View file @
0c80da45
...
...
@@ -19,36 +19,36 @@
*/
package
de.tud.kom.p2psim.impl.network.modular.st.latency
;
import
de.tud.kom.p2psim.api.common.Position
;
package
de.tud.kom.p2psim.impl.network.modular.st.latency
;
import
de.tud.kom.p2psim.api.network.NetMessage
;
import
de.tud.kom.p2psim.impl.network.AbstractNetLayer
;
import
de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB
;
import
de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
class
SimpleStaticLatencyModel
implements
LatencyStrategy
{
protected
long
propagationDelay
=
10
;
// 10 ms
public
SimpleStaticLatencyModel
(
long
staticLatency
)
{
this
.
setLatency
(
staticLatency
);
}
/**
* Sets the static latency which is expected in millseconds. That is, if
* <code>staticLatency</code> is set to 10, the simulator will translate it
* into simulation units as follows: staticLatency *
* Simulator.MILLISECOND_UNIT.
*
* @param staticLatency
* the static latency in milliseconds.
*/
public
void
setLatency
(
long
staticLatency
)
{
this
.
propagationDelay
=
staticLatency
;
protected
long
propagationDelay
=
10
;
// 10 ms
public
SimpleStaticLatencyModel
(
long
staticLatency
)
{
this
.
setLatency
(
staticLatency
);
}
/**
* Sets the static latency which is expected in millseconds. That is, if
* <code>staticLatency</code> is set to 10, the simulator will translate it
* into simulation units as follows: staticLatency *
* Simulator.MILLISECOND_UNIT.
*
* @param staticLatency
* the static latency in milliseconds.
*/
public
void
setLatency
(
long
staticLatency
)
{
this
.
propagationDelay
=
staticLatency
;
}
/**
...
...
@@ -60,13 +60,13 @@ public class SimpleStaticLatencyModel implements LatencyStrategy {
*/
protected
double
getDistance
(
AbstractNetLayer
nlSender
,
AbstractNetLayer
nlReceiver
){
Posi
tion
ps
=
nlSender
.
getNetPosition
();
Posi
tion
pr
=
nlReceiver
.
getNetPosition
();
Loca
tion
ps
=
nlSender
.
getNetPosition
();
Loca
tion
pr
=
nlReceiver
.
getNetPosition
();
return
ps
.
getD
istance
(
pr
);
return
ps
.
d
istance
To
(
pr
);
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy#getMessagePropagationDelay(de.tud.kom.p2psim.api.network.NetMessage, de.tud.kom.p2psim.impl.network.AbstractNetLayer, de.tud.kom.p2psim.impl.network.AbstractNetLayer, de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB)
...
...
@@ -85,6 +85,6 @@ public class SimpleStaticLatencyModel implements LatencyStrategy {
@Override
public
void
writeBackToXML
(
BackWriter
bw
)
{
bw
.
writeTime
(
"propagationDelay"
,
propagationDelay
);
}
}
}
}
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment