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

Removed SimLogger-dependency

parent 7d3a9810
package de.tud.kom.p2psim.impl.network.fairshare;
/**
* A Connection connects two distinct Nodes. It is directed, that is, it
* connects a source to a destination. Connections are Comparable in that a
* Connection with a smaller "bid" is smaller than a Connection with a bigger
* "bid" (see {@link #getMinBid()}).
*
* @author Tobias Lauinger
*/
public interface Connection extends Comparable<Connection> {
/**
* Returns one of the end points of this Connection.
*
* @param destination
* true if the sink is to be returned (else the source).
*
* @return the download/upload Node of this Connection.
*/
public Node getNode(boolean destination);
/**
* @return true if this Connection is currently used (false if idle).
*/
public boolean isInUse();
/**
* Resets the state of this Connection for a new, clean run of the fair
* share algorithm. The state that will be cleared is the assigned
* bandwidth.
*/
public void reset();
/**
* @return the bandwidth that has been assigned to this Connection by the
* fair share algorithm. Returns 0 if the bandwidth has not yet been
* determined.
*/
public double getBandwidth();
/**
* @return the minimum bandwidth bid of the two connected Nodes.
*/
public double getMinBid();
/**
* Assigns the given bandwidth to this Connection and updates the source and
* destination Nodes of this Connection.
*
* @param bandwidth
* the bandwidth of this Connection.
*/
public void assignBandwidth(double bandwidth);
}
package de.tud.kom.p2psim.impl.network.fairshare;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
/**
* An implementation of the fair share bandwidth allocation algorithm. TODO
* extend and move to a sensible place.
*
* @author Tobias Lauinger
*/
public class FairShareAlgorithm {
/**
* Runs the fair share algorithm.
*
* NOTE: CHANGED by Peter Heise:
*
* Did not recalculate all links on remove. Now has to called like:
* LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
* receiver.traverseConnections(links, true);
* sender.traverseConnections(links, false);
* fairShare.run(links);
*
*
* @param links
* Collection of all affected links
*/
public void run(LinkedHashSet<Connection> links) {
LinkedList<Connection> sortedLinks = new LinkedList<Connection>(links);
Collections.sort(sortedLinks);
while( !sortedLinks.isEmpty() ) {
Connection min = sortedLinks.remove(0);
min.assignBandwidth(min.getMinBid());
/*
* NOTE: CHANGED by Peter Heise:
* Needs to be recalculated in every iteration so that all flows are fully saturated.
*
* Reference: "Accurate and Efficient Simulation of Bandwidth Dynamics for Peer-To-Peer Overlay Networks"
* by Alexandros Gkogkas, see proposed Algorithm 1.
*
*/
Collections.sort(sortedLinks);
}
}
}
package de.tud.kom.p2psim.impl.network.fairshare;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* An implementation of the Connection interface. TODO to be extended.
*
* @author Tobias Lauinger
*/
public class Link implements Connection {
static Logger log = SimLogger.getLogger(Link.class);
private final Node src;
private final Node dst;
private long lastTime;
private long transferEndTime;
private double bandwidth;
private double oldBandwidth;
private double remainingBytes;
// private double transferedBytes;
private double messageSize;
private long creationTime;
private boolean burstMessage;
private boolean statusChanged;
private final long propagationDelay;
public Link(final Node source, final Node sink, double msgSize,
final long minimumDelay) {
src = source;
dst = sink;
src.addConnection(this, false);
dst.addConnection(this, true);
creationTime = Time.getCurrentTime();
remainingBytes = msgSize;
messageSize = msgSize;
lastTime = creationTime;
burstMessage = false;
statusChanged = false;
propagationDelay = minimumDelay;
}
public long getCreationTime() {
return creationTime;
}
public long getPropagationDelay() {
return propagationDelay;
}
public void addBurstMessage(double msgSize) {
creationTime = Time.getCurrentTime();
remainingBytes = msgSize;
assert (remainingBytes > 0);
messageSize = msgSize;
lastTime = creationTime;
burstMessage = true;
statusChanged = true;
}
@Override
public double getBandwidth() {
return bandwidth;
}
public void calculateNewTransferEndTime() {
long currentTime = Time.getCurrentTime();
long lastTransferInterval = currentTime - lastTime;
lastTime = currentTime;
assert (lastTransferInterval >= 0);
double byteBurst = (lastTransferInterval / (double) Time.SECOND)
* oldBandwidth;
remainingBytes -= byteBurst;
double time = remainingBytes / bandwidth;
transferEndTime = Math.round(time * Time.SECOND) + currentTime;
if (transferEndTime < currentTime)
transferEndTime = currentTime;
// log.info("**************************************************************");
// log.info("Link " + src.getNetID() + " -> " + dst.getNetID() + " @ "
// + Simulator.getCurrentTime());
// log.info("lastTransferInterval (ns): " + lastTransferInterval
// + " | Total bytes: " + messageSize + " | Remaining bytes "
// + remainingBytes);
// log.info("Allocated link bandwidth: " + bandwidth
// + " bytes/s | Transmission duration: " + time
// * Simulator.MILLISECOND_UNIT + " ms");
// log.info("Transfer endtime: " + transferEndTime);
// log.info("**************************************************************");
// log.info("");
statusChanged = false;
assert (creationTime < transferEndTime);
}
public long getTransferEndTime() {
return this.transferEndTime;
}
@Override
public double getMinBid() {
final double bidSrc = src.getCurrentFairShare(false);
final double bidDst = dst.getCurrentFairShare(true);
assert (bidSrc > 0);
assert (bidDst > 0);
if (bidSrc > bidDst) {
return bidDst;
} else {
return bidSrc;
}
}
@Override
public Node getNode(boolean destination) {
if (destination) {
return dst;
} else {
return src;
}
}
@Override
public boolean isInUse() {
return true;
}
public boolean isBurst() {
return burstMessage;
}
public void resetBurst() {
burstMessage = false;
}
@Override
public void reset() {
oldBandwidth = bandwidth;
statusChanged = true;
bandwidth = 0;
}
public boolean hasStatusChanged() {
return statusChanged;
}
@Override
public int compareTo(Connection c) {
if (c instanceof Link)
return ((Double) getMinBid()).compareTo((Double) c.getMinBid());
log.error("Cannot compare Link to " + c.getClass());
return 0;
}
@Override
public void assignBandwidth(final double newBandwidth) {
assert (newBandwidth > 0);
bandwidth = newBandwidth;
src.updateAvailableBandwidth(bandwidth, false);
dst.updateAvailableBandwidth(bandwidth, true);
log.debug("Setting rate to " + newBandwidth + "bytes/sec for " + this);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Link) {
Link aLink = (Link) obj;
if (this.getNode(true).equals(aLink.getNode(true))) {
if (this.getNode(false).equals(aLink.getNode(false))) {
return true;
}
}
}
return false;
}
@Override
public String toString() {
return "Flow[ " + this.src.getNetID() + "(U:"
+ this.src.getCurrentBandwidth().getUpBW() + "/D:"
+ this.src.getCurrentBandwidth().getDownBW() + ")" + "\t"
+ " -> " + this.dst.getNetID() + "(U:"
+ this.dst.getCurrentBandwidth().getUpBW() + "/D:"
+ this.dst.getCurrentBandwidth().getDownBW() + ")" + "\t"
+ " ]";
}
}
package de.tud.kom.p2psim.impl.network.fairshare;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
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.NetProtocol;
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.IPv4NetID;
import de.tud.kom.p2psim.impl.network.fairshare.position.FairshareGnpPosition;
import de.tud.kom.p2psim.impl.network.fairshare.position.GeoLocation;
import de.tud.kom.p2psim.impl.transport.AbstractTransMessage;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* A Node is a participant in a network. It has connections to other Nodes, but
* never to itself. Its incoming and outgoing network bandwidth is restricted.
* It can participate in an algorithm to assign each connection a fair share of
* bandwidth.
*
* @author Tobias Lauinger, Sebastian Kaune, Yue Sheng
*/
public class Node extends AbstractNetLayer implements FlowBasedNetlayer {
private static Logger log = SimLogger.getLogger(Node.class);
private final HashSet<Connection> incomingConnections;
private final HashSet<Connection> outgoingConnections;
private final OptimizedSubnet subnet;
private double unassignedIncomingConnections;
private double unassignedOutgoingConnections;
private final GeoLocation geoLocation;
private final Map<Node, List<NetMessage>> hostQueues;
public Node(SimHost host, final double maxDownBW, final double maxUpBW,
IPv4NetID netID,
FairshareGnpPosition netPosition, GeoLocation geoLoc,
OptimizedSubnet gnpSubNet) {
super(host, netID, new BandwidthImpl(maxDownBW, maxUpBW), netPosition,
null);
subnet = gnpSubNet;
incomingConnections = new LinkedHashSet<Connection>();
outgoingConnections = new LinkedHashSet<Connection>();
geoLocation = geoLoc;
hostQueues = new HashMap<Node, List<NetMessage>>();
subnet.registerNetLayer(this);
}
public void setIncomingBandwidth(double incomingBw) {
getMaxBandwidth().setDownBW(incomingBw);
}
public void setOutgoingBandwidth(double outgoingBw) {
getMaxBandwidth().setUpBW(outgoingBw);
}
/**
* Adds the given Connection to the Connections of this Node. The new
* Connection does not automatically obtain bandwidth; this has to be
* triggered via a run of the fair share algorithm.
*
* @param c
* the Connection to be added.
* @param incoming
* true if the Connection is a download connection.
*/
public void addConnection(Connection c, boolean incoming) {
if (incoming) {
incomingConnections.add(c);
// unassignedIncomingConnections++;
} else {
outgoingConnections.add(c);
// unassignedOutgoingConnections++;
}
}
/**
* Removes the given Connection from the Connections of this Node.
*
* @param c
* the Connection to be removed.
* @param incoming
* true if the Connection is a download connection.
*/
public void removeConnection(Connection c, boolean incoming) {
if (incoming) {
incomingConnections.remove(c);
} else {
outgoingConnections.remove(c);
}
}
/**
* Adds the Connections of this Node, either incoming or outgoing, to the
* given Collection and calls this method on the Nodes on the other sides of
* the Connections, if they were not previously contained in the Collection.
* Also resets the state of the involved Connections and Nodes.
*
* @param c
* the Collection with the Connections that have already been
* visited.
* @param incoming
* true if download Connections are to be followed (which means
* that at the other end of this Node's Connections upload
* Connections will be followed).
*/
public void traverseConnections(Collection<Connection> c, boolean incoming) {
final Collection<Connection> toTraverse;
if (incoming) {
toTraverse = incomingConnections;
} else {
toTraverse = outgoingConnections;
}
this.reset(incoming);
for (final Connection con : toTraverse) {
// add only if in use, traverse only if added
if (con.isInUse() && c.add(con)) {
// reset state of Connection
con.reset(); // TODO will be called twice
// traverse other end of connection
// traverse other type of connections at other end
con.getNode(!incoming).traverseConnections(c, !incoming);
}
}
}
/**
* Resets the state of this Node for a new, clean run of the fair share
* algorithm. The state that will be cleared are the number of assigned
* connections and the currently unassigned incoming and outgoing network
* capacity.
*
* @param incoming
* true if the state for the incoming (download) Connections is
* to be reset (else the outgoing/upload connections).
*/
public void reset(boolean incoming) {
if (incoming) {
getCurrentBandwidth().setDownBW(getMaxBandwidth().getDownBW());
unassignedIncomingConnections = incomingConnections.size();
} else {
getCurrentBandwidth().setUpBW(getMaxBandwidth().getUpBW());
unassignedOutgoingConnections = outgoingConnections.size();
}
}
/**
* Calculates the current fair share of bandwidth for the unassigned
* connections (the available bandwidth divided by the number of unassigned
* connections).
*
* @param incoming
* true if download connections are to be considered, else
* considering upload connections.
* @return the current fair share for the unassigned connections.
*/
public double getCurrentFairShare(boolean incoming) {
// TODO "incoming" not currently used
if (incoming) {
assert unassignedIncomingConnections > 0 : "unassigned download-connections:"
+ unassignedIncomingConnections;
return getCurrentBandwidth().getDownBW()
/ unassignedIncomingConnections;
} else {
assert unassignedOutgoingConnections > 0;
return getCurrentBandwidth().getUpBW()
/ unassignedOutgoingConnections;
}
}
/**
* Updates this Node with the newly assigned bandwidth. It will be
* subtracted from the currently unassigned bandwidth.
*
* @param bandwidth
* the bandwidth that has been assigned to the Connection.
* @param incoming
* true if the updated Connection was a download connection.
*/
public void updateAvailableBandwidth(double bandwidth, boolean incoming) {
double newBandwidth;
if (incoming) {
assert unassignedIncomingConnections > 0;
// unassignedIncomingBandwidth -= bandwidth;
newBandwidth = getCurrentBandwidth().getDownBW() - bandwidth;
getCurrentBandwidth().setDownBW(newBandwidth);
unassignedIncomingConnections--;
} else {
assert unassignedOutgoingConnections > 0;
// unassignedOutgoingBandwidth -= bandwidth;
newBandwidth = getCurrentBandwidth().getUpBW() - bandwidth;
getCurrentBandwidth().setUpBW(newBandwidth);
unassignedOutgoingConnections--;
}
assert newBandwidth >= 0;
}
@Override
protected boolean isSupported(TransProtocol protocol) {
return (protocol.equals(TransProtocol.UDP) || protocol
.equals(TransProtocol.TCP));
}
/**
*
* @return 2-digit country code
*/
public String getCountryCode() {
return geoLocation.getCountryCode();
}
@Override
public void send(Message msg, NetID receiverId, NetProtocol protocol) {
if (isOnline()) {
assert (msg.getSize() >= 0);
assert (isSupported(((AbstractTransMessage) msg).getProtocol()));
NetMessage netMsg = new IPv4Message(msg, receiverId,
this.getLocalInetAddress());
TransProtocol current = ((AbstractTransMessage) msg).getProtocol();
if (current.equals(TransProtocol.UDP)) {
if (hasAnalyzer) {
netAnalyzerProxy
.netMsgEvent(netMsg, getHost(), Reason.SEND);
}
this.subnet.sendUDP(netMsg);
} else if (current.equals(TransProtocol.TCP)) {
Node receiver = subnet.getNetLayer(receiverId);
if (!hostQueues.containsKey(receiver))
hostQueues.put(receiver, new LinkedList<NetMessage>());
List<NetMessage> queuedMessages = hostQueues.get(receiver);
if (queuedMessages.isEmpty()) {
if (hasAnalyzer) {
netAnalyzerProxy.netMsgEvent(netMsg, getHost(),
Reason.SEND);
}
subnet.sendTCPMessage(this, receiver, netMsg.getSize());
}
queuedMessages.add(netMsg);
}
}
}
public boolean isMessageQueueEmpty(Node receiver) {
return hostQueues.get(receiver).isEmpty();
}
public double peekMessageQueue(Node receiver) {
return hostQueues.get(receiver).get(0).getSize();
}
public List<NetMessage> getViewOnMessageQueue(Node receiver) {
return Collections.unmodifiableList(hostQueues.get(receiver));
}
public NetMessage removeMessageFromQueue(Node receiver) {
return hostQueues.get(receiver).remove(0);
}
/**
* Returns the minimum end-to-end propagation delay in microseconds between
* this host, and the host the specified netID belongs to.
*
* @param netId
* the remote netID
* @return -1 if no information available, else the minimum delay (in
* microseconds)
*/
public long getMinimumPropagationDelay(NetID netId) {
if (subnet.getNetLayer(netId) != null)
return subnet.getLatencyModel().getLatency(this,
subnet.getNetLayer(netId));
else
return -1l;
}
@Override
public void goOffline() {
super.goOffline();
hostQueues.clear();
subnet.isOffline(this,
(HashSet<Connection>) outgoingConnections.clone(),
(HashSet<Connection>) incomingConnections.clone());
assert (incomingConnections.size() == 0);
assert (outgoingConnections.size() == 0);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Node) {
Node aNode = (Node) obj;
if (this.getLocalInetAddress().equals(aNode.getNetID())) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return getLocalInetAddress().hashCode();
}
}
package de.tud.kom.p2psim.impl.network.fairshare;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.network.NetLatencyModel;
import de.tud.kom.p2psim.api.network.NetLayer;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Time;
public class OptimizedLatencyModel implements NetLatencyModel {
private static Logger log = SimLogger
.getLogger(OptimizedLatencyModel.class);
@Override
public long getLatency(NetLayer sender, NetLayer receiver) {
Position senderPos = sender.getNetPosition();
Position receiverPos = receiver.getNetPosition();
double minRtt = senderPos.getDistance(receiverPos);
double receiveTime = minRtt / 2.0;
long latency = Math.round(receiveTime * Time.MILLISECOND);
log.info("Propagation Delay for " + sender.getNetID() + " to "
+ receiver.getNetID() + ": " + receiveTime + " ms");
return latency;
}
}
\ No newline at end of file
package de.tud.kom.p2psim.impl.network.fairshare;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.network.fairshare.position.FairshareGnpPosition;
import de.tud.kom.p2psim.impl.network.fairshare.position.GeoLocation;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
public class OptimizedNetLayerFactory implements HostComponentFactory {
private static Logger log = SimLogger
.getLogger(OptimizedNetLayerFactory.class);
private final OptimizedSubnet subnet;
private double downBandwidth;
private double upBandwidth;
private HashMap<IPv4NetID, GnpHostInfo> hostPool;
private HashMap<String, ArrayList<IPv4NetID>> namedGroups;
public OptimizedNetLayerFactory() {
subnet = new OptimizedSubnet();
}
@Override
public Node createComponent(Host phost) {
SimHost host = (SimHost) phost;
Node netLayer = newNetLayer(host, host.getProperties().getGroupID());
return netLayer;
}
/**
* random node form group
*
* @param id
* @return
*/
public Node newNetLayer(SimHost host, String id) {
if (this.namedGroups.containsKey(id)
&& !this.namedGroups.get(id).isEmpty()) {
int size = namedGroups.get(id).size();
IPv4NetID netId = namedGroups.get(id).get(
Randoms.getRandom(OptimizedNetLayerFactory.class).nextInt(
size));
namedGroups.get(id).remove(netId);
return newNetLayer(host, netId);
} else {
throw new IllegalStateException(
"No (more) Hosts are assigned to \"" + id + "\"");
}
}
private Node newNetLayer(SimHost host, IPv4NetID netID) {
FairshareGnpPosition gnpPos = this.hostPool.get(netID).gnpPosition;
GeoLocation geoLoc = this.hostPool.get(netID).geoLoc;
Node nw = new Node(host, downBandwidth, upBandwidth, netID, gnpPos,
geoLoc,
subnet);
hostPool.remove(netID);
return nw;
}
public void setGnpFile(String gnpFileName) {
File gnpFile = new File(gnpFileName);
hostPool = new HashMap<IPv4NetID, GnpHostInfo>();
namedGroups = new HashMap<String, ArrayList<IPv4NetID>>();
log.info("Read hosts from file " + gnpFile);
SAXReader reader = new SAXReader(false);
Document configuration = null;
try {
configuration = reader.read(gnpFile);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Element root = configuration.getRootElement();
assert root.getName().equals("gnp");
for (Object obj : root.elements()) {
Element elem = (Element) obj;
if (elem.getName().equals("GroupLookup")) {
for (Iterator iter = elem.elementIterator("Group"); iter
.hasNext();) {
Element variable = (Element) iter.next();
String id = variable.attributeValue("id");
ArrayList<IPv4NetID> group = new ArrayList<IPv4NetID>();
for (Iterator ipIter = variable.elementIterator("IPs"); ipIter
.hasNext();) {
Element ipElement = (Element) ipIter.next();
String[] ips = ipElement.attributeValue("value").split(
",");
for (int c = 0; c < ips.length; c++)
group.add(new IPv4NetID(Long.parseLong(ips[c])));
}
if (namedGroups.containsKey(id)) {
throw new IllegalStateException(
"Multiple Group Definition in " + gnpFileName
+ " ( Group: " + id + " )");
} else {
namedGroups.put(id, group);
}
}
} else if (elem.getName().equals("Hosts")) {
for (Iterator iter = elem.elementIterator("Host"); iter
.hasNext();) {
Element variable = (Element) iter.next();
// IP-Address
IPv4NetID hostID = new IPv4NetID(Long.parseLong(variable
.attributeValue("ip")));
// GNP-Coordinates
String[] coordinatesS = variable.attributeValue(
"coordinates").split(",");
double[] coordinatesD = new double[coordinatesS.length];
for (int c = 0; c < coordinatesD.length; c++)
coordinatesD[c] = Double.parseDouble(coordinatesS[c]);
FairshareGnpPosition gnpPos = new FairshareGnpPosition(coordinatesD);
// GeoLocation
String continentalArea = variable
.attributeValue("continentalArea");
String countryCode = variable.attributeValue("countryCode");
String region = variable.attributeValue("region");
String city = variable.attributeValue("city");
String isp = variable.attributeValue("isp");
double longitude = Double.parseDouble(variable
.attributeValue("longitude"));
double latitude = Double.parseDouble(variable
.attributeValue("latitude"));
GeoLocation geoLoc = new GeoLocation(continentalArea,
countryCode, region, city, isp, latitude, longitude);
GnpHostInfo hostInfo = new GnpHostInfo(geoLoc, gnpPos);
hostPool.put(hostID, hostInfo);
}
}
}
}
public void setDownBandwidth(double downBandwidth) {
this.downBandwidth = downBandwidth / 8.0;
}
public void setUpBandwidth(double upBandwidth) {
this.upBandwidth = upBandwidth / 8.0;
}
private class GnpHostInfo {
private final FairshareGnpPosition gnpPosition;
private final GeoLocation geoLoc;
public GnpHostInfo(GeoLocation geoLoc, FairshareGnpPosition gnpPos) {
this.gnpPosition = gnpPos;
this.geoLoc = geoLoc;
}
}
}
package de.tud.kom.p2psim.impl.network.fairshare;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.network.NetLatencyModel;
import de.tud.kom.p2psim.api.network.NetLayer;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.AbstractSubnet;
import de.tud.kom.p2psim.impl.network.IPv4Message;
import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
*
* @author Gerald Klunker
* @version 0.1, 17.01.2008
*
*/
public class OptimizedSubnet extends AbstractSubnet implements EventHandler {
private static Logger log = SimLogger.getLogger(OptimizedSubnet.class);
private final NetLatencyModel netLatencyModel;
private final Map<IPv4NetID, Node> nodes;
private final FairShareAlgorithm fairShare;
private final List<Link> links;
private long nextMsgArrival;
private final static int EVENT_RECEIVE = 1;
private final static int EVENT_STATUS = 2;
public OptimizedSubnet() {
nodes = new HashMap<IPv4NetID, Node>();
fairShare = new FairShareAlgorithm();
links = new LinkedList<Link>();
netLatencyModel = new OptimizedLatencyModel();
}
public OptimizedSubnet(NetLatencyModel model) {
nodes = new HashMap<IPv4NetID, Node>();
fairShare = new FairShareAlgorithm();
links = new LinkedList<Link>();
netLatencyModel = model;
}
Node getNetLayer(NetID netId) {
return nodes.get(netId);
}
public NetLatencyModel getLatencyModel() {
return netLatencyModel;
}
/**
* Registers a NetWrapper in the SubNet.
*
* @param wrapper
* The NetWrapper.
*/
@Override
public void registerNetLayer(NetLayer netLayer) {
nodes.put((IPv4NetID) netLayer.getNetID(), (Node) netLayer);
}
@Override
public void eventOccurred(Object content, int type) {
if (type == EVENT_RECEIVE) {
IPv4Message msg = (IPv4Message) content;
Node receiver = nodes.get(msg.getReceiver());
receiver.receive(msg);
} else if (type == EVENT_STATUS) {
if (Time.getCurrentTime() == nextMsgArrival) {
log.debug("New Message arrival at -----------------------------------------------------> "
+ Time.getCurrentTime());
log.debug("Number of Links: " + links.size());
List<Link> obsoleteLinks = new LinkedList<Link>();
boolean error = true;
// Sort Link list by means of earliest transmission end time
Collections.sort(links, new TransferEndTimeComp());
// Dispatch messages and filter obsolete Links
for (Link link : links) {
if (link.getTransferEndTime() > nextMsgArrival) {
assert (!error);
break;
} else {
error = false;
assert (link.getTransferEndTime() == nextMsgArrival);
Node sender = link.getNode(false);
Node receiver = link.getNode(true);
assert (sender.isMessageQueueEmpty(receiver) == false);
NetMessage message = sender
.removeMessageFromQueue(receiver);
Event.scheduleWithDelay(link.getPropagationDelay(),
this, message, EVENT_RECEIVE);
assert (Time.getCurrentTime() - link.getCreationTime() > 0);
log.info(Time.getCurrentTime()
+ ">TCP Message arrived ("
+ message.getSender()
+ " -> "
+ message.getReceiver()
+ ") | "
+ message.getPayload()
+ ") | "
+ message.getPayload().getPayload()
+ " | Transmission time: "
+ ((Time.getCurrentTime() - link
.getCreationTime()) / (double) Time.MILLISECOND)
+ " ms"
+ "; Scheduling for "
+ (Time.getCurrentTime() + link
.getPropagationDelay()) + ".");
link.resetBurst();
boolean anotherMessageInQueue = !sender
.isMessageQueueEmpty(receiver);
if (anotherMessageInQueue) {
link.addBurstMessage(sender
.peekMessageQueue(receiver));
} else {
obsoleteLinks.add(link);
}
}
}
for (Link link : obsoleteLinks) {
if (!link.isBurst()) {
Node sender = link.getNode(false);
Node receiver = link.getNode(true);
links.remove(link);
sender.removeConnection(link, false);
receiver.removeConnection(link, true);
/*
* NOTE: CHANGED by Peter Heise:
*
* Did not recalculate all links on remove. Now has to
* called like.
*/
LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
receiver.traverseConnections(links, true);
sender.traverseConnections(links, false);
fairShare.run(links);
}
}
scheduleNextMessageArrival();
}
}
}
private void scheduleNextMessageArrival() {
nextMsgArrival = Long.MAX_VALUE;
for (Link l : links) {
if (l.hasStatusChanged())
l.calculateNewTransferEndTime();
if (l.getTransferEndTime() < nextMsgArrival)
nextMsgArrival = l.getTransferEndTime();
}
assert (nextMsgArrival >= Time.getCurrentTime()) : "nextMsgArrival is "
+ nextMsgArrival
+ "; current time is "
+ Time.getCurrentTime();
Event.scheduleWithDelay(nextMsgArrival - Time.getCurrentTime(), this,
null, EVENT_STATUS);
}
@Override
public void send(NetMessage msg) {
// TODO Auto-generated method stub
}
public void sendUDP(NetMessage netMsg) {
Node sender = nodes.get(netMsg.getSender());
Node receiver = nodes.get(netMsg.getReceiver());
long end2endDelay = netLatencyModel.getLatency(sender, receiver);
Event.scheduleWithDelay(end2endDelay, this, netMsg, EVENT_RECEIVE);
}
private void printFairShareGraph(String header) {
System.out.println(header);
for (Link link : links) {
System.out.println("Link: " + link.getNode(false).getNetID()
+ " --> " + link.getNode(true).getNetID() + " ("
+ link.getBandwidth() + ")");
}
}
// public boolean isLinkAlreadyEstablished(Node sender, Node receiver) {
// for (Link link : links) {
// if (link.getNode(false).equals(sender) &&
// link.getNode(true).equals(receiver))
// return true;
// }
// return false;
// }
public void sendTCPMessage(Node sender, Node receiver, double messageSize) {
Link link = new Link(sender, receiver, messageSize,
netLatencyModel.getLatency(sender, receiver));
// assert (!isLinkAlreadyEstablished(sender, receiver));
assert (!links.contains(link));
links.add(link);
LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
sender.traverseConnections(links, false);
fairShare.run(links);
log.debug("Sending TCP Message to " + receiver.getNetID()
+ " with latency of "
+ netLatencyModel.getLatency(sender, receiver)
/ Time.MILLISECOND + "ms at " + Time.getCurrentTime()
/ Time.MILLISECOND + "ms, size=" + messageSize + ", rate = "
+ link.getBandwidth());
scheduleNextMessageArrival();
}
public void isOffline(Node offlineNode,
Set<Connection> outgoingConnections,
Set<Connection> incomingConnections) {
// int a = 1;
for (Connection link : outgoingConnections) {
Node otherSide = link.getNode(true);
links.remove(link);
offlineNode.removeConnection(link, false);
otherSide.removeConnection(link, true);
LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
otherSide.traverseConnections(links, true);
fairShare.run(links);
}
for (Connection link : incomingConnections) {
Node otherSide = link.getNode(false);
links.remove(link);
offlineNode.removeConnection(link, true);
LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
otherSide.traverseConnections(links, false);
fairShare.run(links);
}
scheduleNextMessageArrival();
}
public void cancelTransmission(Node sender, Node receiver) {
Link toCancel = null;
for (Link link : links) {
Node src = link.getNode(false);
Node dst = link.getNode(true);
if (src.equals(sender) && dst.equals(receiver)) {
toCancel = link;
break;
}
}
assert (toCancel != null);
NetMessage message = sender.removeMessageFromQueue(receiver);
toCancel.resetBurst();
boolean anotherMessageInQueue = !sender.isMessageQueueEmpty(receiver);
if (anotherMessageInQueue) {
toCancel.addBurstMessage(sender.peekMessageQueue(receiver));
} else {
links.remove(toCancel);
sender.removeConnection(toCancel, false);
receiver.removeConnection(toCancel, true);
LinkedHashSet<Connection> links = new LinkedHashSet<Connection>();
sender.traverseConnections(links, false);
fairShare.run(links);
}
scheduleNextMessageArrival();
}
class TransferEndTimeComp implements Comparator<Link> {
@Override
public int compare(Link o1, Link o2) {
if (o1.getTransferEndTime() < o2.getTransferEndTime()) {
return -1;
} else if (o1.getTransferEndTime() > o2.getTransferEndTime()) {
return +1;
} else {
return 0;
}
}
}
}
\ No newline at end of file
package de.tud.kom.p2psim.impl.network.fairshare.position;
import de.tud.kom.p2psim.api.common.Position;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* 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 FairshareGnpPosition implements Position {
private static final long serialVersionUID = -1103996725403557900L;
private final double[] gnpCoordinates;
private double error = -1.0;
/**
*
* @param gnpCoordinates
* coordinate array for new position
*/
public FairshareGnpPosition(double[] gnpCoordinates) {
super();
this.gnpCoordinates = gnpCoordinates;
}
/**
*
* @param dimension
* @param maxDiversity
*/
public void diversify(double[][] dimension, double maxDiversity) {
for (int c = 0; c < this.gnpCoordinates.length; c++) {
double rand = (2 * maxDiversity * Randoms.getRandom(
FairshareGnpPosition.class)
.nextDouble()) - 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 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];
}
/**
*
* @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[1];
return result;
}
}
@Override
public double getDistance(Position netPosition) {
FairshareGnpPosition coord = (FairshareGnpPosition) netPosition;
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() {
// 2 * size(double)
return 2 * 8;
}
@Override
public double getAngle(Position target) {
throw new AssertionError(
"getAngle is not defined for this Position-Type");
}
@Override
public Position getTarget(double distance, double angle) {
throw new AssertionError(
"getTarget is not defined for this Position-Type");
}
public double[] getCoords() {
return gnpCoordinates;
}
@Override
public FairshareGnpPosition clone() {
return new FairshareGnpPosition(gnpCoordinates);
}
}
package de.tud.kom.p2psim.impl.network.fairshare.position;
public class GeoLocation {
private final String countryCode;
private final String region;
private final String city;
private final String isp;
private final String continentalArea;
private final double latitude;
private final double longitude;
public GeoLocation(String conArea, String countryCode, String region,
String city, String isp, double latitude, double longitude) {
super();
this.continentalArea = conArea;
this.countryCode = countryCode;
this.region = region;
this.city = city;
this.isp = isp;
this.latitude = latitude;
this.longitude = longitude;
}
public String getContinentalArea() {
return continentalArea;
}
public String getCountryCode() {
return countryCode;
}
public String getRegion() {
return region;
}
public String getCity() {
return city;
}
public String getIsp() {
return isp;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
}
/*
* 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.fairshare.position;
import de.tud.kom.p2psim.api.common.Position;
/**
* Implementation of NetPosition for Position and distance measurnment on the
* earth.
*
* @author Gerald Klunker
* @version 0.1, 05.02.2008
*
*/
public class GeographicPosition implements Position {
private final double latitude;
private final double longitude;
/**
*
* @param longitude
* @param latitude
*/
public GeographicPosition(double longitude, double latitude) {
this.longitude = longitude;
this.latitude = latitude;
}
/**
* @return geographical distance in km
*/
@Override
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));
}
/**
*
* @return latitude of position
*/
public double getLatitude() {
return latitude;
}
/**
*
* @return longitude of position
*/
public double getLongitude() {
return longitude;
}
@Override
public int getTransmissionSize() {
// 2 * size(double)
return 2 * 8;
}
@Override
public double getAngle(Position target) {
throw new AssertionError(
"getAngle is not defined for this Position-Type");
}
@Override
public Position getTarget(double distance, double angle) {
throw new AssertionError(
"getTarget is not defined for this Position-Type");
}
public GeographicPosition clone() {
return new GeographicPosition(longitude, latitude);
}
}
......@@ -10,10 +10,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
/**
* The Class DirectedGraph.
*
......@@ -24,9 +20,6 @@ import de.tud.kom.p2psim.impl.util.logging.SimLogger;
*/
public class DirectedGraph {
/** The logger. */
private static Logger log = SimLogger.getLogger(DirectedGraph.class);
/** The flowList: contains all flows in graph. */
private final Collection<FairshareFlow> flowList;
......
package de.tud.kom.p2psim.impl.network.fairshareng;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
......@@ -10,8 +7,6 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public class FairshareFlow implements Comparable<FairshareFlow> {
private static Logger log = SimLogger.getLogger(FairshareFlow.class);
/** The dst. */
private final FairshareNode src, dst;
......
......@@ -20,8 +20,6 @@
package de.tud.kom.p2psim.impl.network.fairshareng;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.AbstractNetLayerFactory;
import de.tud.kom.p2psim.impl.network.IPv4NetID;
......@@ -32,7 +30,6 @@ import de.tud.kom.p2psim.impl.network.modular.st.LatencyStrategy;
import de.tud.kom.p2psim.impl.network.modular.st.PLossStrategy;
import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.network.modular.st.positioning.GNPPositioning;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
......@@ -42,10 +39,6 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
public class FairshareNetLayerFactory extends AbstractNetLayerFactory {
/** The logger. */
private static Logger log = SimLogger
.getLogger(FairshareNetLayerFactory.class);
/** The subnet. */
private final FairshareSubnet subnet;
......@@ -75,9 +68,6 @@ public class FairshareNetLayerFactory extends AbstractNetLayerFactory {
SimHost host = (SimHost) phost;
// create new node here and add to graph
log.debug("createComponent: Creating new node: " + host);
final String groupStr = host.getProperties().getGroupID();
NetMeasurementDB.Host hostMeta;
......
......@@ -6,8 +6,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
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;
......@@ -20,8 +18,9 @@ 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.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
......@@ -30,8 +29,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
public class FairshareNode extends AbstractNetLayer implements
FlowBasedNetlayer {
/** The log. */
private static Logger log = SimLogger.getLogger(FairshareNode.class);
/** The subnet. */
private final FairshareSubnet subnet;
......@@ -168,7 +165,8 @@ public class FairshareNode extends AbstractNetLayer implements
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
log.error("Exception..: sendTCP failed: " + e);
Monitor.log(FairshareNode.class, Level.ERROR,
"Exception..: sendTCP failed. %s", e);
assert(false) : "sendTCP failed: " + e;
}
......@@ -181,14 +179,15 @@ public class FairshareNode extends AbstractNetLayer implements
/*
* Can't throw exception here as send(Message msg, NetID receiverId, NetProtocol protocol) is overwritten.
*/
log.error("Unsupported transport protocol " + tpMsg);
Monitor.log(FairshareNode.class, Level.ERROR,
"Unsupported transport protocol " + tpMsg);
assert (false) : "Unsupported transport protocol " + tpMsg;
}
} else {
log.warn("Host " + this + " is offline.");
Monitor.log(FairshareNode.class, Level.WARN, "Host " + this
+ " is offline.");
}
......
......@@ -25,8 +25,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.analyzer.MessageAnalyzer.Reason;
import de.tud.kom.p2psim.api.analyzer.NetlayerAnalyzer;
import de.tud.kom.p2psim.api.network.NetLayer;
......@@ -41,10 +39,10 @@ import de.tud.kom.p2psim.impl.network.modular.st.latency.GNPLatency;
import de.tud.kom.p2psim.impl.network.modular.st.ploss.NoPacketLoss;
import de.tud.kom.p2psim.impl.transport.AbstractTransMessage;
import de.tud.kom.p2psim.impl.util.BackToXMLWritable;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
......@@ -52,9 +50,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
public class FairshareSubnet extends AbstractSubnet implements EventHandler,
BackToXMLWritable {
// Instantiate the logging facility.
private static Logger log = SimLogger.getLogger(FairshareSubnet.class);
// Actual graph with Nodes.
private final DirectedGraph fullGraph;
......@@ -133,7 +128,8 @@ public class FairshareSubnet extends AbstractSubnet implements EventHandler,
* Can't throw exception here as registerNetLayer is overwritten.
*/
log.error("Registered wrong netlayer with faireshare subnet.");
Monitor.log(FairshareSubnet.class, Level.ERROR,
"Registered wrong netlayer with faireshare subnet.");
assert (false) : "Registered wrong netlayer with fairshare subnet.";
}
......@@ -158,7 +154,8 @@ public class FairshareSubnet extends AbstractSubnet implements EventHandler,
* Can't throw exception here as send(NetMessage msg) is overwritten.
*/
log.error("send(NetMessage msg) is not supported. Use sendUDP or sendTCP instead.");
Monitor.log(FairshareSubnet.class, Level.ERROR,
"send(NetMessage msg) is not supported. Use sendUDP or sendTCP instead.");
assert (false) : "send(NetMessage msg) is not supported. Use sendUDP or sendTCP instead.";
}
......@@ -181,8 +178,8 @@ public class FairshareSubnet extends AbstractSubnet implements EventHandler,
final long latency = this.strategyLatency.getMessagePropagationDelay(netMsg, sender, receiver, getDB());
if (netMsg.getSender().equals(netMsg.getReceiver())) {
log.fatal("Sender and receiver are the same ("
Monitor.log(FairshareSubnet.class, Level.ERROR,
"Sender and receiver are the same ("
+ netMsg.getSender() + ") for msg "
+ netMsg.getPayload().getPayload());
......
......@@ -25,21 +25,16 @@ import java.awt.geom.Point2D;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.network.BandwidthImpl;
import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.network.gnp.topology.GnpPosition;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
public class GnpBitmapNetLayerFactory implements HostComponentFactory {
private static Logger log = SimLogger.getLogger(GnpBitmapNetLayerFactory.class);
private final GnpSubnet subnet;
private final static long DEFAULT_DOWN_BANDWIDTH = 1000l;
......
......@@ -23,8 +23,6 @@ package de.tud.kom.p2psim.impl.network.gnp;
import java.util.Random;
import org.apache.log4j.Logger;
import umontreal.iro.lecuyer.probdist.LognormalDist;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
......@@ -35,13 +33,10 @@ import de.tud.kom.p2psim.api.transport.TransProtocol;
import de.tud.kom.p2psim.impl.network.IPv4Message;
import de.tud.kom.p2psim.impl.network.gnp.topology.CountryLookup;
import de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
public class GnpLatencyModel implements NetLatencyModel {
private static Logger log = SimLogger.getLogger(GnpLatencyModel.class);
public class GnpLatencyModel implements NetLatencyModel {
private Random rnd = Randoms.getRandom(GnpLatencyModel.class);
......@@ -80,7 +75,6 @@ public class GnpLatencyModel implements NetLatencyModel {
Position receiverPos = receiver.getNetPosition();
minRtt = senderPos.getDistance(receiverPos);
}
log.info("Minimum RTT for " + ccSender + " to " + ccReceiver + ": " + minRtt + " ms");
return minRtt;
}
......@@ -94,7 +88,6 @@ public class GnpLatencyModel implements NetLatencyModel {
twoWayLossRate /= 100;
oneWayLossRate = 1 - Math.sqrt(1 - twoWayLossRate);
}
log.debug("Packet Loss Probability for " + ccSender + " to " + ccReceiver + ": " + (oneWayLossRate * 100) + " %");
return oneWayLossRate;
}
......@@ -107,7 +100,6 @@ public class GnpLatencyModel implements NetLatencyModel {
LognormalDist distri = pingErLookup.getJitterDistribution(ccSender, ccReceiver, countryLookup);
randomJitter = distri.inverseF(rnd.nextDouble());
}
log.debug("Random Jitter for " + ccSender + " to " + ccReceiver + ": " + randomJitter + " ms");
return randomJitter;
}
......@@ -119,7 +111,6 @@ public class GnpLatencyModel implements NetLatencyModel {
if (usePingErJitter) {
jitter = pingErLookup.getAverageRtt(ccSender, ccReceiver, countryLookup) - pingErLookup.getMinimumRtt(ccSender, ccReceiver, countryLookup);
}
log.debug("Average Jitter for " + ccSender + " to " + ccReceiver + ": " + jitter + " ms");
return jitter;
}
......@@ -128,7 +119,6 @@ public class GnpLatencyModel implements NetLatencyModel {
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());
log.debug("Error Probability for a " + msg.getPayload().getSize() + " byte UDP Datagram from " + sender.getCountryCode() + " to " + receiver.getCountryCode() + ": " + errorProb * 100 + " %");
return errorProb;
}
......@@ -143,7 +133,6 @@ public class GnpLatencyModel implements NetLatencyModel {
public long getTransmissionDelay(double bytes, double bandwidth) {
double messageTime = bytes / bandwidth;
long delay = Math.round((messageTime * Time.SECOND));
log.debug("Transmission Delay (s): " + messageTime + " ( " + bytes + " bytes / " + bandwidth + " bytes/s )");
return delay;
}
......@@ -152,7 +141,6 @@ public class GnpLatencyModel implements NetLatencyModel {
double randomJitter = getNextJitter(sender, receiver);
double receiveTime = (minRtt + randomJitter) / 2.0;
long latency = Math.round(receiveTime * Time.MILLISECOND);
log.debug("Propagation Delay for " + sender.getCountryCode() + " to " + receiver.getCountryCode() + ": " + receiveTime + " ms");
return latency;
}
......
......@@ -27,11 +27,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.network.BandwidthImpl;
import de.tud.kom.p2psim.api.network.NetLayer;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
/**
*
......@@ -40,9 +37,6 @@ import de.tud.kom.p2psim.impl.util.logging.SimLogger;
*/
public class GnpNetBandwidthManagerEvent extends AbstractGnpNetBandwidthManager {
private static Logger log = SimLogger
.getLogger(GnpNetBandwidthManagerEvent.class);
private Set<GnpNetBandwidthAllocation> tempConnections;
private Map<NetLayer, Set<GnpNetBandwidthAllocation>> tempSenderConnections;
......
......@@ -178,8 +178,6 @@ public class GnpNetLayer extends AbstractNetLayer implements EventHandler {
+ " not supported by this NetLayer implementation.");
} else {
int assignedMsgId = subnet.determineTransMsgNumber(msg);
log.debug("During send: Assigning MsgId " + assignedMsgId
+ " to dropped message");
((AbstractTransMessage) msg).setCommId(assignedMsgId);
if (hasAnalyzer) {
......
......@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
......@@ -39,15 +38,12 @@ import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.network.gnp.topology.CountryLookup;
import de.tud.kom.p2psim.impl.network.gnp.topology.GnpPosition;
import de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
public class GnpNetLayerFactory extends AbstractNetLayerFactory {
private static Logger log = SimLogger.getLogger(GnpNetLayerFactory.class);
private final GnpSubnet subnet;
private HashMap<IPv4NetID, GnpHostInfo> hostPool;
......@@ -109,7 +105,6 @@ public class GnpNetLayerFactory extends AbstractNetLayerFactory {
File gnpFile = new File(gnpFileName);
hostPool = new HashMap<IPv4NetID, GnpHostInfo>();
namedGroups = new HashMap<String, ArrayList<IPv4NetID>>();
log.info("Read hosts from file " + gnpFile);
SAXReader reader = new SAXReader(false);
......
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