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

initialized clean Simonstrator-PeerfactSim.KOM-repository to FINALLY get rid...

initialized clean Simonstrator-PeerfactSim.KOM-repository to FINALLY get rid of huge blob objects and ancient history that is not relevant to the simonstrator-branch of PeerfactSim.KOM
parents
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
/**
* <p>
* Determines the jitter that shall be used for a given network message.
* </p>
* <p>
* Jitter is the variation of the message propagation delay in a network.
* In the Modular Net Layer, the total time the message is delayed is defined as the message propagation delay
* (defined by the LatencyStrategy) plus the jitter (defined by this class), plus the time the message stays in
* sender and receiver queues defined by the traffic control strategy (if the
* traffic control mechanism delays the messages at all).
* </p>
*
* @author Leo Nobach
*
*/
public interface JitterStrategy extends ModNetLayerStrategy {
/**
* Returns the jitter that shall be used for the given network message.
*
* @param cleanMsgPropagationDelay : the message propagation delay that was previously calculated by the LatencyStrategy
* @param msg : the network message that shall be jittered
* @param nlSender : the network layer of the sender
* @param nlReceiver : the network layer of the receiver
* @param db : the network measurement database (may be null if none set)
* @return the jitter in simulation time units
*/
public long getJitter(long cleanMsgPropagationDelay, NetMessage msg,
ModularNetLayer nlSender, ModularNetLayer nlReceiver,
NetMeasurementDB db);
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
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;
/**
* This strategy defines the message propagation delay of a given network message. This is the
* total time the network message is delayed minus the jitter, minus the time the message stays in
* sender and receiver queues defined by the traffic control strategy (if the
* traffic control mechanism delays the messages at all).
*
*
* @author Leo Nobach
*
*/
public interface LatencyStrategy extends ModNetLayerStrategy {
/**
* <p>
* Returns the message propagation delay in simulation time units. This is the
* total time the network message is delayed minus the jitter, minus the time the message stays in
* sender and receiver queues defined by the traffic control strategy (if the
* traffic control mechanism delays the messages at all).
* </p>
* <p>
* Note that the message to be delayed may be split into multiple IP fragments, please
* implement an appropriate propagation delay.
* </p>
*
* @param msg , the message to be delayed
* @param nlSender , the sender's network layer
* @param nlReceiver , the receiver's network layer
* @param db , the measurement database
*
* @return the message propagation delay in simulation time units.
*/
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db);
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
import de.tud.kom.p2psim.impl.util.BackToXMLWritable;
/**
* Marker interface for modular network layer strategies
* @author Leo Nobach
*
*/
public interface ModNetLayerStrategy extends BackToXMLWritable {
//Marker interface
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
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;
/**
* Strategy to determine whether a given packet shall be dropped or not.
*
* Packet Loss at the Network Layer can have many causes, like interference on the
* physical layer or congestion in intermediate routers which causes them to drop
* subsequent packets.
*
* @author Leo Nobach
*
*/
public interface PLossStrategy extends ModNetLayerStrategy {
/**
* Returns if the given network message shall be dropped because of network layer
* packet loss.
*
* @param msg : the message to be dropped or not
* @param nlSender : the sender's network layer of the message
* @param nlReceiver : the receiver's network layer of the message
* @param db : the network measurement database
* @return whether the network message shall be dropped or not
*/
public boolean shallDrop(NetMessage msg, AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver, NetMeasurementDB db);
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* A packet sizing strategy determines the size of a network layer message.
* @author Leo Nobach
*
*/
public interface PacketSizingStrategy extends ModNetLayerStrategy {
/**
* Returns the sum of the size of all fragments of the network message containing "payload".
* @param payload
* @param receiver
* @param sender
* @param netProtocol
* @param noOfFragments
* @return
*/
public long getPacketSize(Message payload, NetID receiver, NetID sender,
NetProtocol netProtocol, int noOfFragments);
}
/*
* Copyright (c) 2005-2011 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.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;
/**
* This strategy determines an abstract network position of a given host
* (like 2-dimensional, geographical or GNP)
*
* @author Leo Nobach
*
*/
public interface PositioningStrategy extends ModNetLayerStrategy {
/**
* Returns the position of the host. Can be any object extending NetPosition.
* If the host is mobile, a position stub object may be returned,
* where the current position can be requested at any simulation time.
* @param host
* @param db
* @param hostMeta
* @return
*/
public Position getPosition(
SimHost host,
NetMeasurementDB db,
NetMeasurementDB.Host hostMeta);
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tudarmstadt.maki.simonstrator.api.component.network.Bandwidth;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* If we would simply delay every message that is being sent, every peer
* would be able to send an unlimited amount of data in any time interval,
* not caring about bandwidth that is available. This is inappropriate for
* a realistic network layer behavior.
*
* In the network layers of PeerfactSim, a bandwidth is assigned to every host.
* We can use this bandwidth to control the incoming and outgoing traffic of
* every peer, using different strategies.
*
* Note that the send context and the receive context of a network layer
* access the same traffic control metadata object.
*
* @author Leo Nobach
*
*/
public interface TrafficControlStrategy extends ModNetLayerStrategy {
/**
* Called whenever the sender is online and attempts to send a packet to someone.
* Note that at the end of this method, the network message must either be
* sent through the subnet, dropped (use ctx for that), or the sending or dropping action must be
* scheduled at the simulator in the future.
* @param modularNetLayer
*
* @param ctx, the sending context of the receiver's network layer
* @param msg, the network message that has to be sent.
* @param receiver, the receiver of the current network message.
* @param protocol, the network protocol that is used.
*/
public void onSendRequest(ISendContext ctx, NetMessage msg, NetID receiver);
public interface ISendContext extends IContext {
/**
* Sends the message through the given subnet. Note that the message will reside the time given in
* the current latency model, and additionally the packet might wait in the receiver's traffic control
* given by this strategy.
* @param netMsg
*/
public void sendSubnet(NetMessage netMsg);
/**
* Drops the current message caused by the current traffic control strategy (not only the packet loss strategy decides
* about packets that will be dropped).
* @param netMsg
*/
public void dropMessage(NetMessage netMsg);
}
/**
* Called whenever the receiver is online and attempts to receive a packet from the subnet.
* Note that at the end of this method, the network message must either arrive,
* be dropped (use ctx for that), or the arriving or dropping action must be scheduled at the simulator in the future.
* @param modularNetLayer
*
* @param ctx, the sending context of the receiver's network layer
* @param msg, the network message that has to be sent.
* @param receiver, the receiver of the current network message.
* @param protocol, the network protocol that is used.
*/
public void onReceive(IReceiveContext ctx, NetMessage message);
public interface IReceiveContext extends IContext {
/**
* Lets the message arrive at the given receiver network layer.
* given by this strategy.
* @param netMsg
*/
public void arrive(NetMessage netMsg);
/**
* Drops the current message caused by the current traffic control strategy (not only the packet loss strategy decides
* about packets that will be dropped).
* @param netMsg
*/
public void dropMessage(NetMessage netMsg);
/**
* Returns the bandwidth of the sender that has sent the packet, this is sometimes useful by the receiver traffic control.
* @return
*/
public Bandwidth getBandwidthOfSender();
}
public interface IContext {
/**
* Returns the traffic control metadata from the network layer of the current receiver(IReceiveContext) or sender(ISendContext). Note that the
* metadata object may be null if never set before.
* @return
*/
public Object getTrafCtrlMetadata();
/**
* Sets the traffic control metadata on the network layer of the current receiver(IReceiveContext) or sender(ISendContext) to the given object o.
* @param trafCtrlMetadata
*/
public void setTrafCtrlMetadata(Object trafCtrlMetadata);
/**
* Returns the current maximum bandwidth of the context
* @return
*/
public Bandwidth getMaxBW();
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.fragmenting;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tud.kom.p2psim.impl.network.modular.st.FragmentingStrategy;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
*
* The fragmenting is used as defined by IPv4
* Based on code from Sebastian Kaune
*
* @author Leo Nobach
*
*/
public class IPv4Fragmenting implements FragmentingStrategy {
public static final double MTU_MINUS_HEADER_SIZE = 1480; //1500 - 20
@Override
public int getNoOfFragments(Message payload, NetID receiver, NetID sender,
NetProtocol netProtocol) {
return (int) Math.ceil(payload.getSize() / MTU_MINUS_HEADER_SIZE);
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.fragmenting;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tud.kom.p2psim.impl.network.modular.st.FragmentingStrategy;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* No fragmenting is used at all. This will never split up messages,
* no matter how large they may get.
*
* @author Leo Nobach
*
*/
public class NoFragmenting implements FragmentingStrategy {
@Override
public int getNoOfFragments(Message payload, NetID receiver, NetID sender,
NetProtocol netProtocol) {
return 1;
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.jitter;
import java.util.Random;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.JitterStrategy;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Applies a jitter that is equally distributed from 0 to max.
*
* Parameters: max (long)
*
* @author Leo Nobach
*
*/
public class EqualDistJitter implements JitterStrategy {
public long max = 5 * Time.MILLISECOND;
Random rand = Randoms.getRandom(EqualDistJitter.class);
@Override
public long getJitter(long cleanMsgPropagationDelay, NetMessage msg,
ModularNetLayer nlSender, ModularNetLayer nlReceiver,
NetMeasurementDB db) {
return Math.round(rand.nextDouble() * max);
}
/**
* Sets the maximum jitter in simulation time units.
* @param maxJitter
*/
public void setMax(long maxJitter) {
this.max = maxJitter;
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeTime("max", max);
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.jitter;
import java.util.Random;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.JitterStrategy;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Applies a jitter that is log-normally distributed.
*
* Parameters: mu (double, unit in msec)
* Parameters: sigma (double, unit in msec)
*
* @author Leo Nobach
*
*/
public class LognormalJitter implements JitterStrategy {
LognormalDist dist = null;
Random rand = Randoms.getRandom(LognormalJitter.class);
private double mu = 1; //Default value
private double sigma = 0.6; //Default value
@Override
public long getJitter(long cleanMsgPropagationDelay, NetMessage msg,
ModularNetLayer nlSender, ModularNetLayer nlReceiver,
NetMeasurementDB db) {
if (dist == null) {
dist = new LognormalDist(mu, sigma);
}
return Math.round(dist.inverseF(rand.nextDouble()) * Time.MILLISECOND);
}
/**
* Sets the mu parameter (Unit is msec)
* @param mu
*/
public void setMu(double mu) {
this.mu = mu;
}
/**
* Sets the sigma parameter (Unit is msec)
* @param sigma
*/
public void setSigma(double sigma) {
this.sigma = sigma;
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeSimpleType("mu", mu);
bw.writeSimpleType("sigma", sigma);
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.jitter;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.JitterStrategy;
/**
* Applies no jitter at all.
* @author Leo Nobach
*
*/
public class NoJitter implements JitterStrategy {
@Override
public long getJitter(long cleanMsgPropagationDelay, NetMessage msg,
ModularNetLayer nlSender, ModularNetLayer nlReceiver,
NetMeasurementDB db) {
return 0;
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.jitter;
import java.util.Random;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.SummaryRelation;
import de.tud.kom.p2psim.impl.network.modular.st.JitterStrategy;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Applies a jitter with parameters derived from the PingER project.
* Requires the network measurement database containing PingER measurements.
*
* @author Leo Nobach
*
*/
public class PingErJitter implements JitterStrategy {
Random rand = Randoms.getRandom(PingErJitter.class);
@Override
public long getJitter(long cleanMsgPropagationDelay, NetMessage msg,
ModularNetLayer nlSender, ModularNetLayer nlReceiver,
NetMeasurementDB db) {
if (db == null) throw new IllegalArgumentException("The PingEr jitter strategy can not access any network " +
"measurement database. You may not have loaded it in the config file.");
SummaryRelation rel = db.getMostAccurateSummaryRelation(nlSender.getDBHostMeta(), nlReceiver.getDBHostMeta());
return Math.round(rel.tGetJitterLnDist().inverseF(rand.nextDouble())
* 0.5 * Time.MILLISECOND);
// divided by 2 because we have the RTT jitter, but want the delay jitter
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
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;
/** Applies a latency derived from the geographical distance of two hosts.
* The latency is. 31ms * 0.01ms/km * distance between the hosts in km.
*
* Based on GeographicalLatency.
*
* @author Andreas Hemel
*
*/
public class FootprintLatency implements LatencyStrategy {
protected static final double geoDistFactor = 0.00001d;
protected static final long staticPart = 31;
@Override
public long getMessagePropagationDelay(
NetMessage msg,
AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
if (db != null) {
throw new IllegalArgumentException("FootprintLatency is incompatible with the NetMeasurementDB");
}
double distance = nlSender.getNetPosition().getDistance(nlReceiver.getNetPosition());
return (staticPart + Math.round(geoDistFactor * distance))
* Time.MILLISECOND;
}
@Override
public void writeBackToXML(BackWriter bw) {
//throw new UnsupportedOperationException();
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.latency;
import java.util.List;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.AbstractNetLayer;
import de.tud.kom.p2psim.impl.network.modular.common.GNPToolkit;
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;
/**
* Returns the message propagation delay derived from the distance between the GNP coordinates of two hosts.
* Requires the network measurement database in order to work.
*
* @author Leo Nobach
*
*/
public class GNPLatency implements LatencyStrategy {
@Override
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
if (db == null) throw new IllegalArgumentException("The GNP latency strategy can not access any network " +
"measurement database. You may not have loaded it in the config file.");
List<Double> sndCoords = nlSender.getDBHostMeta().getCoordinates();
List<Double> rcvCoords = nlReceiver.getDBHostMeta().getCoordinates();
return (long) (GNPToolkit.getDistance(sndCoords, rcvCoords) * 0.5 * Time.MILLISECOND);
// divided by 2 because we have the RTT, but want the delay
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.latency;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.AbstractNetLayer;
import de.tud.kom.p2psim.impl.network.modular.common.GeoToolkit;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Applies a latency derived from the geographical distance of two hosts.
* The latency is. 31ms * 0.01ms/km * distance between the hosts in km.
*
* @author Leo Nobach
*
*/
public class GeographicalLatency implements LatencyStrategy {
static Logger log = SimLogger.getLogger(GeographicalLatency.class);
@Override
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
if (db == null) throw new IllegalArgumentException("The Geographical Latency strategy can not access any network " +
"measurement database. You may not have loaded it in the config file.");
NetMeasurementDB.Host hSender = nlSender.getDBHostMeta();
NetMeasurementDB.Host hReceiver = nlReceiver.getDBHostMeta();
double distance = GeoToolkit.getDistance(hSender.getLatitude(), hSender.getLongitude(), hReceiver.getLatitude(), hReceiver.getLongitude());
log.debug("Distance between " + nlSender + " and " + nlReceiver + " is " + distance + " meters.");
return Math.round(getStaticPart(msg, nlSender, nlReceiver, db)
+ (getGeoDistFactor() * distance) * Time.MILLISECOND);
}
protected double getGeoDistFactor() {
return 0.00001d;
}
protected double getStaticPart(NetMessage msg, AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver, NetMeasurementDB db) {
return 31d;
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.latency;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import org.apache.commons.math.MathException;
import org.apache.commons.math.distribution.NormalDistributionImpl;
import org.apache.log4j.Logger;
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.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Returns a normal distributed latency.<br>
* If the variance to big, so that exists negative delay, then will be returned
* the mean delay.
*
* Parameters: propagationMeanDelay:long (in Simulation time units) <br>
* standardDeviation:long (in Simulation time units)
*
* @author Christoph Muenker
* @version 1.0, 04/07/2011
*/
public class NormalDistributionLatency implements LatencyStrategy {
private static Logger log = SimLogger
.getLogger(NormalDistributionLatency.class);
private Random rnd = Randoms.getRandom(NormalDistributionLatency.class);
/**
* The size of precomputed delays
*/
private static final int DELAY_SIZE = 10000;
/**
* The mean delay
*/
private long propagationMeanDelay = 10 * Time.MILLISECOND; // 10
// ms
/**
* The standard deviation
*/
private long standardDeviation = 2 * Time.MICROSECOND; // 2ms
private NormalDistributionImpl normalDistribution = new NormalDistributionImpl(
propagationMeanDelay, standardDeviation);
/**
* The precomputed delays
*/
private List<Long> delays = null;
@Override
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
if (delays == null) {
createDelays(DELAY_SIZE);
}
return delays.get(rnd.nextInt(DELAY_SIZE));
}
/**
* Precompute the delays.
*
* @param size
* The number of delays, which should be computed and stored in
* delays.
*/
private void createDelays(int size) {
if (propagationMeanDelay < standardDeviation) {
log.warn("Bad Configuration! It is possible, that huge delays are negative and consequently this values will be set to the mean delay value.");
}
log.info("Create " + size + " precomputed delays");
delays = new Vector<Long>(size);
for (int i = 0; i < size; i++) {
long delay = 0;
try {
delay = (long) normalDistribution
.inverseCumulativeProbability(rnd.nextDouble());
} catch (MathException e) {
log.error(
"MathException, check your parameteres for NormalDistributionLatency class...",
e);
throw new RuntimeException();
}
if (delay <= 0) {
log.debug("Set delay to propagationMeanDelay ("
+ propagationMeanDelay + ") because it has the value "
+ delay);
delay = propagationMeanDelay;
}
delays.add(delay);
}
log.info("Finished, to create delays");
}
public void setPropagationMeanDelay(long delay) {
if (delay < 0) {
throw new RuntimeException(
"Bad PropagationMeanDelay. It should be positiv!");
}
this.propagationMeanDelay = delay;
this.normalDistribution = new NormalDistributionImpl(
this.propagationMeanDelay, this.standardDeviation);
}
public void setStandardDeviation(long standardDeviation) {
this.standardDeviation = standardDeviation;
this.normalDistribution = new NormalDistributionImpl(
this.propagationMeanDelay, this.standardDeviation);
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeTime("propagationMeanDelay", propagationMeanDelay);
bw.writeTime("standardDeviation", standardDeviation);
}
}
/*
* Copyright (c) 2005-2011 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.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.db.NetMeasurementDB.SummaryRelation;
import de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Returns the message propagation delay derived from the PingEr project.
* Requires the network measurement database in order to work.
*
* @author Leo Nobach
*
*/
public class PingErLatency implements LatencyStrategy {
@Override
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
if (db == null) throw new IllegalArgumentException("The PingEr latency strategy can not access any network " +
"measurement database. You may not have loaded it in the config file.");
SummaryRelation rel = db.getMostAccurateSummaryRelation(nlSender.getDBHostMeta(), nlReceiver.getDBHostMeta());
return Math.round(rel.getMinRtt() * 0.5 * Time.MILLISECOND);
// divided by 2 because we have the RTT, but want the delay
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.latency;
import java.util.Random;
import org.apache.log4j.Logger;
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;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy;
import de.tud.kom.p2psim.impl.network.simple.SimpleSubnet;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
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
*
*/
public class SimpleLatencyModel implements LatencyStrategy {
private final static Logger log = SimLogger.getLogger(SimpleLatencyModel.class);
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.
*
* @param sender the sender
* @param receiver the receiver
* @return the distance
*/
public double getDistance(NetLayer sender, NetLayer receiver) {
Position ps = sender.getNetPosition();
Position pr = receiver.getNetPosition();
return ps.getDistance(pr);
}
/**
* Calc static delay.
*
* @param receiver the receiver
* @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);
}
@Override
public long getMessagePropagationDelay(NetMessage msg, AbstractNetLayer nlSender, AbstractNetLayer nlReceiver, NetMeasurementDB db) {
double distance = getDistance( nlSender, nlReceiver);
double staticDelay = Time.MILLISECOND
* this.calcStaticDelay(nlReceiver, distance);
int f = (rnd.nextInt(10) + 1);
long latency = Math.round(f * staticDelay * 0.1);
log.debug("Latency " + nlSender + " -> " + nlReceiver + ": " + latency);
return latency;
}
@Override
public void writeBackToXML(BackWriter bw) {
// None.
}
}
\ No newline at end of file
/*
* Copyright (c) 2005-2011 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.impl.network.modular.st.latency;
import de.tud.kom.p2psim.api.common.Position;
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;
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;
}
/**
* Gets the distance.
*
* @param nlSender the nl sender
* @param nlReceiver the nl receiver
* @return the distance
*/
protected double getDistance(AbstractNetLayer nlSender, AbstractNetLayer nlReceiver){
Position ps = nlSender.getNetPosition();
Position pr = nlReceiver.getNetPosition();
return ps.getDistance(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)
*/
@Override
public long getMessagePropagationDelay(NetMessage msg, AbstractNetLayer nlSender, AbstractNetLayer nlReceiver, NetMeasurementDB db) {
return (long) (getDistance(nlSender, nlReceiver) * propagationDelay * Time.MILLISECOND);
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.util.BackToXMLWritable#writeBackToXML(de.tud.kom.p2psim.impl.util.BackToXMLWritable.BackWriter)
*/
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeTime("propagationDelay", propagationDelay);
}
}
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