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.latency;
import java.util.Random;
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.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
public class SimpleVariableLatencyModel extends SimpleStaticLatencyModel {
private long variation = -1;
private Random rnd = Randoms.getRandom(SimpleVariableLatencyModel.class);
public SimpleVariableLatencyModel(long base, long variation,
Random generator) {
super(base);
this.variation = variation;
this.rnd = (generator != null) ? generator : rnd;
}
public SimpleVariableLatencyModel() {
super(-1l);
}
/**
* Sets the base.
*
* @param base the new base
*/
public void setBase(long base) {
this.setLatency(base);
}
/**
* Sets the variation.
*
* @param variation the new variation
*/
public void setVariation(long variation) {
this.variation = variation;
}
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.modular.st.latency.SimpleStaticLatencyModel#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) * ((rnd.nextDouble() - 0.5)
* propagationDelay * variation * Time.MILLISECOND));
}
}
/*
* 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.st.LatencyStrategy;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Returns a fixed propagation delay.
*
* Parameters: propagationDelay(long, simulation time units)
*
* @author Leo Nobach
*
*/
public class StaticLatency implements LatencyStrategy {
private long propagationDelay = 10 * Time.MILLISECOND; // 10 ms
@Override
public long getMessagePropagationDelay(NetMessage msg,
AbstractNetLayer nlSender, AbstractNetLayer nlReceiver,
NetMeasurementDB db) {
return propagationDelay;
}
public void setPropagationDelay(long delay) {
this.propagationDelay = delay;
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeTime("propagationDelay", propagationDelay);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.network.modular.st.latency;
import java.util.Random;
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.Randoms;
// TODO: Auto-generated Javadoc
/**
* The Class StaticLatencyWithVariance.
*/
public class StaticLatencyWithVariance implements LatencyStrategy {
/** The propagation delay. */
private long propagationDelay;
/** The double variance. */
private long doubleVariance;
private Random rnd = Randoms.getRandom(StaticLatencyWithVariance.class);
/* (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("latency", propagationDelay);
bw.writeTime("variance", doubleVariance / 2);
}
/* (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) {
if (doubleVariance == 0) {
return propagationDelay;
} else {
return propagationDelay
+ Math.round(((rnd.nextDouble() - 0.5) * doubleVariance));
}
}
/**
* Sets the variance.
*
* @param variance the new variance
*/
public void setVariance(long variance) {
// *2 to save one computational step in getLatency
this.doubleVariance = variance * 2;
}
/**
* Sets the latency.
*
* @param propagationDelay the new latency
*/
public void setLatency(long latency) {
this.propagationDelay = latency;
}
}
/*
* 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.packetSizing;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tud.kom.p2psim.impl.network.modular.st.PacketSizingStrategy;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* Returns a packet size that adds the 20-byte IPv4 header to the payload length of the network message.
* @author Leo Nobach
*
*/
public class IPv4Header implements PacketSizingStrategy {
static final int IPV4_HDR_SZ = 20;
@Override
public long getPacketSize(Message payload, NetID receiver, NetID sender,
NetProtocol netProtocol, int noOfFragments) {
return payload.getSize() + noOfFragments*IPV4_HDR_SZ; //for every fragment a header is needed
}
@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.packetSizing;
import de.tud.kom.p2psim.api.network.NetProtocol;
import de.tud.kom.p2psim.impl.network.modular.st.PacketSizingStrategy;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* Returns the packet length that is equal to the payload length (no header at all).
* @author Leo Nobach
*
*/
public class NoHeader implements PacketSizingStrategy {
@Override
public long getPacketSize(Message payload, NetID receiver, NetID sender,
NetProtocol netProtocol, int noOfFragments) {
return payload.getSize();
}
@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.ploss;
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.PLossStrategy;
/**
* No packet loss will occur at all (except possible packet loss in the traffic control strategy)
* @author Leo Nobach
*
*/
public class NoPacketLoss implements PLossStrategy {
@Override
public boolean shallDrop(NetMessage msg, AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver, NetMeasurementDB db) {
return false;
}
@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.ploss;
import java.util.Random;
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.db.NetMeasurementDB.SummaryRelation;
import de.tud.kom.p2psim.impl.network.modular.st.PLossStrategy;
import de.tud.kom.p2psim.impl.util.logging.SimLogger;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* Applies a packet loss as measured by the PingEr project
*
* @author Leo Nobach
*
*/
public class PingERPacketLoss implements PLossStrategy {
Random rand = Randoms.getRandom(PingERPacketLoss.class);
static Logger log = SimLogger.getLogger(PingERPacketLoss.class);
@Override
public boolean shallDrop(NetMessage msg, AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver, NetMeasurementDB db) {
if (db == null) throw new IllegalArgumentException("The PingER packet loss strategy can not access any network " +
"measurement database. You may not have loaded it in the config file.");
SummaryRelation sumRel = db.getMostAccurateSummaryRelation(nlSender.getDBHostMeta(), nlReceiver.getDBHostMeta());
if (sumRel == null) throw new AssertionError("No summary relation could be found for " + nlSender + " - " + nlReceiver);
// If the message consists of multiple fragments, the loss probability
// will be the probability that all fragments have arrived, and
// every fragment itself has the probability of "sumRel.getpLoss()" to be dropped
double prob = 1d - Math.pow(1d - sumRel.getpLoss() * 0.01, msg.getNoOfFragments());
log.debug("Dropping with probability " + prob + ", fragments " + msg.getNoOfFragments());
return rand.nextDouble() < prob;
}
@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.ploss;
import java.util.Random;
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.PLossStrategy;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* Applies a static packet loss of a given ratio.
* Parameters: ratio (double from 0 to 1)
*
* @author Leo Nobach
*
*/
public class StaticPacketLoss implements PLossStrategy {
private double ratio = 0.005d; //default value 0.5%
Random rand = Randoms.getRandom(StaticPacketLoss.class);
@Override
public boolean shallDrop(NetMessage msg, AbstractNetLayer nlSender,
AbstractNetLayer nlReceiver, NetMeasurementDB db) {
// If the message consists of multiple fragments, the loss probability
// will be the probability that all fragments have arrived, and
// every fragment has the probability of "ratio" to be dropped
if (ratio <= 0d) return false;
return rand.nextDouble() < 1d - Math.pow(1d - ratio, msg.getNoOfFragments());
}
/**
* The average ratio of packets lost (of all packets sent).
* Value between 0 and 1, not in percent!
*
* To be used by the XML configurator.
*
* @param ratio
*/
public void setRatio(double ratio) {
if (ratio < 0 || ratio > 1) throw new IllegalArgumentException("The packet loss ratio must be a value between 0 and 1.");
this.ratio = ratio;
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeSimpleType("ratio", ratio);
}
}
package de.tud.kom.p2psim.impl.network.modular.st.positioning;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Random;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.util.positioning.GeoSpherePosition;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
public class AppJobberPositioning implements PositioningStrategy {
private String path = "appjobber.csv";
private ArrayList<GeoSpherePosition> positions = null;
private Random rnd = Randoms.getRandom(AppJobberPositioning.class);
@Override
public Position getPosition(
SimHost host,
NetMeasurementDB db,
NetMeasurementDB.Host hostMeta) {
if (db != null || hostMeta != null) {
throw new IllegalArgumentException("FootprintPositioning is incompatible with the NetMeasurementDB");
}
if (positions == null)
readDb();
if (positions.isEmpty())
throw new AssertionError("used all avilable locations");
int index = rnd.nextInt(positions.size());
return positions.remove(index);
}
private void readDb() {
positions = new ArrayList<GeoSpherePosition>();
try {
FileInputStream fis = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
for (String line = br.readLine(); line != null; line = br.readLine()) {
String parts[] = line.split(";");
if (parts.length != 2)
throw new RuntimeException("database broken");
// coordinates in database seem to be in "wrong" order (longitude, latitude)
String lat = parts[1].replace('"', ' ').trim();
String lon = parts[0].replace('"', ' ').trim();
positions.add(new GeoSpherePosition(Double.parseDouble(lat), Double.parseDouble(lon)));
}
} catch (FileNotFoundException e) {
throw new RuntimeException("could not read appjobber database: file not found");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("could not read appjobber database: encoding troubles");
} catch (IOException e) {
throw new RuntimeException("could not read appjobber database: IO error");
}
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeSimpleType("path", path);
}
public void setPath(String path) {
this.path = path;
}
public String getPath() {
return path;
}
}
/*
* 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.positioning;
import java.util.List;
import java.util.Vector;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
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.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector;
/**
* Applies the (virtual) GNP position as the host's position
*
* @author Leo Nobach
*
*/
public class GNPPositioning implements PositioningStrategy {
@Override
public Position getPosition(SimHost host, NetMeasurementDB db,
NetMeasurementDB.Host hostMeta) {
if (hostMeta == null)
throw new IllegalStateException(
"The GNP positioning strategy needs a measurement database to work properly.");
return new GNPPosition(hostMeta);
}
public static class GNPPosition extends PositionVector implements Position {
private List<Double> coords;
public GNPPosition(NetMeasurementDB.Host hostMeta) {
super(2);
this.coords = hostMeta.getCoordinates();
super.setEntry(0, coords.get(0));
super.setEntry(1, coords.get(1));
}
@Override
public double getDistance(Position netPosition) {
if (!(netPosition instanceof PositionVector))
throw new AssertionError(
"Can not calculate distances between different position classes: "
+ this.getClass() + " and "
+ netPosition.getClass());
PositionVector other = (PositionVector) netPosition;
List<Double> otherCoords = new Vector<Double>();
otherCoords.add(other.getEntry(0));
otherCoords.add(other.getEntry(1));
return GNPToolkit.getDistance(this.coords, otherCoords);
}
@Override
public int getTransmissionSize() {
return coords.size() * 8; // * double
}
public List<Double> getCoords() {
return coords;
}
@Override
public GNPPosition clone() {
return this; // no need to clone
}
}
@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.positioning;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
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.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector;
/**
* Applies a geographical position as defined by the GeoIP project.
*
* Based on code from the GeoLocationOracle (unknown author, Gerald Klunker?) in the GNP net layer
* @author Leo Nobach
*
*/
public class GeographicalPositioning implements PositioningStrategy {
@Override
public GeographicalPosition getPosition(
SimHost host,
NetMeasurementDB db,
de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.Host hostMeta) {
if (hostMeta == null) throw new IllegalArgumentException("The geographical positioner can not access the required measurement database, which is not set.");
return new GeographicalPosition(hostMeta);
}
public class GeographicalPosition extends PositionVector implements
Position {
private double latitude;
private double longitude;
public GeographicalPosition(NetMeasurementDB.Host hostMeta) {
super(2);
latitude = hostMeta.getLatitude();
longitude = hostMeta.getLongitude();
super.setEntry(0, hostMeta.getLongitude());
super.setEntry(1, hostMeta.getLatitude());
}
/**
* Calculates the distance in meters (m) from one host to another,
* using the Haversine formula. The squashed shape of the earth into account
* (approximately)
*
*/
@Override
public double getDistance(Position netPosition) {
if (!(netPosition instanceof PositionVector))
throw new AssertionError(
"Can not calculate the distance between two different position classes: "
+ this.getClass() + " and " + netPosition.getClass());
PositionVector other = (PositionVector) netPosition;
return GeoToolkit.getDistance(this.latitude, this.longitude,
other.getEntry(1), other.getEntry(0));
}
@Override
public double getAngle(Position target) {
throw new AssertionError(
"getAngle is not defined for this Position-Type");
}
@Override
public int getTransmissionSize() {
return 16; // 2 * double
}
public GeographicalPosition clone() {
return this; // no clone needed
}
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
\ 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.positioning;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.placement.PositionDistribution;
/**
* Positioning on a 2D-Plane, used for all Movement-Enabled Routing-Scenarios
*
* @author Bjoern Richerzhagen
* @version 1.0, 04/25/2011
*/
public class PlanePositioning implements PositioningStrategy {
private PositionDistribution distribution;
@Override
public void writeBackToXML(BackWriter bw) {
// nothing to configure here
}
@Override
public Position getPosition(
SimHost host,
NetMeasurementDB db,
de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.Host hostMeta) {
if (distribution == null) {
throw new AssertionError(
"You have to specify an IPositionDistribution when using DeviceDependentPositioning!");
}
return distribution.getNextPosition();
}
/**
* Specify a Distribution for Positions of Hosts
*
* @param distribution
*/
public void setPositionDistribution(PositionDistribution distribution) {
this.distribution = distribution;
}
}
/*
* 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.positioning;
import java.util.Random;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.network.simple.SimpleSubnet;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* Implementation of the <code>NetPosition</code> interface representing a two
* dimensional point in euclidian space.
*
* @author Sebastian Kaune
* @author Konstantin Pussep
* @version 3.0, 11/29/2007
*
*/
public class SimpleEuclidianPositioning implements PositioningStrategy {
Random rnd = Randoms.getRandom(SimpleEuclidianPositioning.class);
/* (non-Javadoc)
* @see de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy#getPosition(de.tud.kom.p2psim.api.common.Host, de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB, de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB.Host)
*/
@Override
public Position getPosition(
SimHost host,
NetMeasurementDB db,
NetMeasurementDB.Host hostMeta) {
return new SimpleEuclidianPosition(rnd.nextDouble()
* SimpleSubnet.SUBNET_HEIGHT, rnd.nextDouble()
* SimpleSubnet.SUBNET_WIDTH);
}
public class SimpleEuclidianPosition extends PositionVector implements Position {
private double xPos;
private double yPos;
/**
* Constructs a two dimensional euclidian point
*
* @param xPos
* @param yPos
*/
public SimpleEuclidianPosition(double xPos, double yPos) {
super(xPos, yPos);
this.xPos = xPos;
this.yPos = yPos;
}
/**
* for clone
*
* @param old
*/
protected SimpleEuclidianPosition(SimpleEuclidianPosition old) {
this(old.xPos, old.yPos);
}
/*
* (non-Javadoc)
*
* @see
* de.tud.kom.p2psim.api.network.NetPosition#getDistance(de.tud.kom.
* p2psim .api.network.NetPosition)
*/
public double getDistance(Position ep) {
double xDiff = 0;
double yDiff = 0;
SimpleEuclidianPosition point = (SimpleEuclidianPosition) ep;
if (Math.abs(xPos - point.getXPos()) > SimpleSubnet.SUBNET_WIDTH / 2) {
if (xPos < point.getXPos()) {
xDiff = xPos + SimpleSubnet.SUBNET_WIDTH - point.getXPos();
} else {
xDiff = point.getXPos() + SimpleSubnet.SUBNET_WIDTH - xPos;
}
} else {
xDiff = Math.abs(xPos - point.getXPos());
}
if (Math.abs(this.yPos - point.getYPos()) > SimpleSubnet.SUBNET_HEIGHT / 2) {
if (this.yPos < point.getYPos()) {
yDiff = yPos + SimpleSubnet.SUBNET_HEIGHT - point.getYPos();
} else {
yDiff = point.getYPos() + SimpleSubnet.SUBNET_HEIGHT - yPos;
}
} else {
yDiff = Math.abs(yPos - point.getYPos());
}
return Math.pow(Math.pow(xDiff, 2) + Math.pow(yDiff, 2), 0.5);
}
@Override
public double getAngle(Position target) {
throw new AssertionError("getAngle is not defined for this Position-Type");
}
@Override
public int getTransmissionSize() {
return 16; // 2 * double
}
/**
* Get the position of the point in the X axis.
*
* @return the X position.
*/
public double getXPos() {
return this.xPos;
}
/**
* Get the position of the point in the Y axis.
*
* @return the Y position.
*/
public double getYPos() {
return this.yPos;
}
@Override
public SimpleEuclidianPosition clone() {
return new SimpleEuclidianPosition(this);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof SimpleEuclidianPosition))
return false;
SimpleEuclidianPosition point2 = (SimpleEuclidianPosition) o;
return point2.xPos == this.xPos && point2.yPos == this.yPos;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
int result = 17;
long yHash = Double.doubleToLongBits(yPos);
long xHash = Double.doubleToLongBits(xPos);
result *= 37 + (int) (yHash ^ (yHash >>> 32));
result *= 37 + (int) (xHash ^ (xHash >>> 32));
return result;
}
}
@Override
public void writeBackToXML(BackWriter bw) {
// None.
}
}
/*
* 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.positioning;
import java.util.Random;
import de.tud.kom.p2psim.api.common.Position;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.network.modular.st.PositioningStrategy;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* Applies a uniformly-distributed random position on a 2-or multi-dimensional
* torus surface. Parameters: torusDimensionSize(double), noOfDimensions(int)
*
* @author Leo Nobach
*
*/
public class TorusPositioning implements PositioningStrategy {
private int noOfDimensions = 2;
double torusDimensionSize = 1d;
double halfTorusDimensionSize = 0.5d;
Random rand = Randoms.getRandom(TorusPosition.class);
@Override
public Position getPosition(SimHost host, NetMeasurementDB db,
NetMeasurementDB.Host hostMeta) {
double[] rawPos = getRawTorusPositionFor(host);
assert rawPos.length == noOfDimensions : "The raw torus position returned by getRawTorusPositionFor(Host) does not return an array of length "
+ noOfDimensions
+ ", instead it returns one with the length "
+ rawPos.length;
return new TorusPosition(rawPos);
}
/**
* May be overridden for more detailled torus positioning.
*
* @param host
* @return
*/
protected double[] getRawTorusPositionFor(SimHost host) {
double[] result = new double[noOfDimensions];
for (int i = 0; i < noOfDimensions; i++)
result[i] = rand.nextDouble() * halfTorusDimensionSize * 2;
return result;
}
/**
* To be set by the configurator.
*
* @param noOfDimensions
*/
public void setNoOfDimensions(int noOfDimensions) {
this.noOfDimensions = 2;
}
/**
* To be set by the configurator.
*
* @param torusDimensionSize
*/
public void setTorusDimensionSize(double torusDimensionSize) {
this.torusDimensionSize = torusDimensionSize;
this.halfTorusDimensionSize = torusDimensionSize * 0.5d;
}
public class TorusPosition extends PositionVector implements Position {
TorusPosition(double[] rawPos) {
super(rawPos);
}
@Override
public double getDistance(Position netPosition) {
if (!(netPosition instanceof PositionVector))
throw new AssertionError(
"Can not calculate distances between different position classes: "
+ this.getClass() + " and "
+ netPosition.getClass());
TorusPosition other = (TorusPosition) netPosition;
double accuDistanceSq = 0;
for (int i = 0; i < getDimensions(); i++) {
double distDim = getEntry(i) - other.getEntry(i);
if (distDim > halfTorusDimensionSize) {
// we wrap the torus
distDim = torusDimensionSize - distDim;
} else if (distDim < -halfTorusDimensionSize) {
// we wrap the torus, other way
distDim = -torusDimensionSize + distDim;
}
accuDistanceSq += distDim * distDim;
}
return Math.sqrt(accuDistanceSq);
}
@Override
public int getTransmissionSize() {
return 8 * getDimensions(); // 2 * double
}
public double[] getRawPos() {
return asDoubleArray();
}
@Override
public TorusPosition clone() {
return new TorusPosition(asDoubleArray());
}
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeSimpleType("torusDimensionSize", torusDimensionSize);
bw.writeSimpleType("torusDimensionSize", torusDimensionSize);
}
}
/*
* 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.trafCtrl;
import de.tud.kom.p2psim.impl.util.BackToXMLWritable;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
*
* A traffic queue that will drop packets, if they would have to wait longer than a certain
* amount of time before they would BEGIN to be transferred.
*
* Parameters: maxTimeSend(simulation time units), maxTimeReceive(simulation time units).
*
* @author Leo Nobach
*
*/
public class BoundedTrafficQueue extends InfiniteTrafficQueue implements BackToXMLWritable {
long maxTimeSend = 3 * Time.SECOND;
long maxTimeReceive = 3 * Time.SECOND;
protected boolean isTooLongSend(long waitTime) {
return waitTime > maxTimeSend;
}
protected boolean isTooLongRcv(long waitTime) {
return waitTime > maxTimeReceive;
}
/**
* Sets the maximum time a message may (begin to) be
* sent after the send request attempt.
* @param maxTimeSend
*/
public void setMaxTimeSend(long maxTimeSend) {
this.maxTimeSend = maxTimeSend;
}
/**
* Sets the maximum time a message may (begin to) be received
* after the receive request attempt.
* @param maxTimeReceive
*/
public void setMaxTimeReceive(long maxTimeReceive) {
this.maxTimeReceive = maxTimeReceive;
}
@Override
public void writeBackToXML(BackWriter bw) {
bw.writeTime("maxTimeSend", maxTimeSend);
bw.writeTime("maxTimeReceive", maxTimeReceive);
}
}
/*
* 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.trafCtrl;
import org.apache.log4j.Logger;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.st.TrafficControlStrategy;
import de.tud.kom.p2psim.impl.util.LiveMonitoring;
import de.tud.kom.p2psim.impl.util.livemon.AvgAccumulatorTime;
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;
/**
* A traffic queue that enqueues packets, if the sender attempts to send too
* fast, or if the receiver receives packets too fast. This component may
* increase the total latency of the message delivery. The size of the queue is
* unlimited. The advantage is that no packet ever gets dropped by this
* component, but mind that this may cause large message latencies and a high
* memory consumption during simulation.
*
* @author Leo Nobach
*
*/
public class InfiniteTrafficQueue implements TrafficControlStrategy {
private static Logger log = SimLogger.getLogger(InfiniteTrafficQueue.class);
static AvgAccumulatorTime qSizeStat = new AvgAccumulatorTime(
"Net: Traffic Control Queue Size", 50);
public InfiniteTrafficQueue() {
LiveMonitoring.addProgressValueIfNotThere(qSizeStat);
}
@Override
public void onSendRequest(final ISendContext ctx, final NetMessage msg,
NetID receiver) {
TrafficControlMeta meta = getTrafficControlMeta(ctx);
long cur = Time.getCurrentTime();
long nx = meta.getNextFreeSendingTime();
long sendTime = Math.max(cur, nx);
if (isTooLongSend(sendTime - cur)) {
ctx.dropMessage(msg);
} else {
Event.scheduleWithDelay(sendTime - Time.getCurrentTime(),
new EventHandler() {
@Override
public void eventOccurred(Object se, int type) {
ctx.sendSubnet(msg);
}
}, null, 0);
long nextFreeSendingTime = sendTime
+ Math.round(msg.getSize() / ctx.getMaxBW().getUpBW()
* Time.SECOND);
meta.setNextFreeSendingTime(nextFreeSendingTime);
long delayTime = (sendTime - cur);
log.debug("Delaying message " + msg
+ " at the sender's traffic queue for " + delayTime
+ ". The next message may be sent at "
+ nextFreeSendingTime);
qSizeStat.newVal(delayTime);
}
}
/**
* Returns whether the sending traffic queue is too long
*
* @param waitTime
* @return
*/
protected boolean isTooLongSend(long waitTime) {
return false;
}
@Override
public void onReceive(final IReceiveContext ctx, final NetMessage message) {
TrafficControlMeta meta = getTrafficControlMeta(ctx);
long cur = Time.getCurrentTime();
long nx = meta.getNextFreeArrivingTime();
long arriveTime = Math.max(cur, nx);
long msgTransfFinishTimeLocal = arriveTime
+ Math.round(message.getSize() / ctx.getMaxBW().getDownBW()
* Time.SECOND);
long msgTransfFinishTimeGlobal = arriveTime
+ Math.round(message.getSize()
/ Math.min(ctx.getBandwidthOfSender().getUpBW(), ctx
.getMaxBW().getDownBW()) * Time.SECOND);
// The time the message would be transferred by the receiver and the
// sender, assuming a stream.
if (isTooLongRcv(arriveTime - cur)) {
ctx.dropMessage(message);
} else {
Event.scheduleWithDelay(
msgTransfFinishTimeGlobal - Time.getCurrentTime(),
new EventHandler() {
@Override
public void eventOccurred(Object se, int type) {
ctx.arrive(message);
}
}, null, 0);
long delayTime = (msgTransfFinishTimeGlobal - cur);
log.debug("Delaying message "
+ message
+ " at the receiver's traffic queue for "
+ delayTime
+ " (w.r.t. to the time it is fully transferred to the endpoint). "
+ "The next message may be received at "
+ msgTransfFinishTimeLocal);
meta.setNextFreeArrivingTime(msgTransfFinishTimeLocal);
qSizeStat.newVal(delayTime);
}
}
protected boolean isTooLongRcv(long waitTime) {
return false;
}
private TrafficControlMeta getTrafficControlMeta(IContext ctx) {
TrafficControlMeta result = (TrafficControlMeta) ctx
.getTrafCtrlMetadata();
if (result == null) {
result = new TrafficControlMeta();
ctx.setTrafCtrlMetadata(result);
}
return result;
}
static class TrafficControlMeta {
long nextFreeSendingTime = -1;
long nextFreeArrivingTime = -1;
public long getNextFreeSendingTime() {
return nextFreeSendingTime;
}
public void setNextFreeSendingTime(long nextFreeSendingTime) {
this.nextFreeSendingTime = nextFreeSendingTime;
}
public long getNextFreeArrivingTime() {
return nextFreeArrivingTime;
}
public void setNextFreeArrivingTime(long nextFreeArrivingTime) {
this.nextFreeArrivingTime = nextFreeArrivingTime;
}
}
@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.trafCtrl;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.modular.st.TrafficControlStrategy;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* No traffic control applied at all, the hosts have virtually unlimited bandwidth.
*
* @author Leo Nobach
*
*/
public class NoTrafficControl implements TrafficControlStrategy {
@Override
public void onSendRequest(ISendContext ctx, NetMessage msg, NetID receiver) {
ctx.sendSubnet(msg);
}
@Override
public void onReceive(IReceiveContext ctx, NetMessage message) {
ctx.arrive(message);
}
@Override
public void writeBackToXML(BackWriter bw) {
//No simple/complex types to write back
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.network.modular.subnet;
import de.tud.kom.p2psim.impl.network.modular.ModularNetMessage;
public class PacketTooLateException extends Exception {
private ModularNetMessage msg;
public PacketTooLateException(ModularNetMessage msg) {
this.msg = msg;
}
public ModularNetMessage getMessageWhichIsTooLate() {
return msg;
}
}
/*
* 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.subnet;
import de.tud.kom.p2psim.api.network.NetLayer;
import de.tud.kom.p2psim.api.network.NetMessage;
import de.tud.kom.p2psim.impl.network.IPv4NetID;
import de.tud.kom.p2psim.impl.network.modular.AbstractModularSubnet;
import de.tud.kom.p2psim.impl.network.modular.IStrategies;
import de.tud.kom.p2psim.impl.network.modular.ModularNetLayer;
import de.tud.kom.p2psim.impl.network.modular.ModularNetMessage;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Simple Subnet (former ModularSubnet), default if no Subnet is specified.
* Subnets allow for routing of messages and different transmission paths like
* for example WiFi and Ad-Hoc. This subnet implements the "big cloud"
* assumption and specifies no network topology. Nevertheless, it provides
* support for different Device types.
*
* @author Leo Nobach (moved into this package and slightly modified by Bjoern
* Richerzhagen)
*/
public class SimpleModularSubnet extends AbstractModularSubnet {
public SimpleModularSubnet(IStrategies strategies) {
super(strategies);
}
@Override
public void send(NetMessage message) {
final ModularNetMessage msg = (ModularNetMessage) message;
// Broadcast
if (msg.getReceiver().equals(IPv4NetID.LOCAL_BROADCAST)) {
throw new AssertionError(
"The SimpleModularSubnet does not support Broadcast! "
+ "(Target IP must not be LOCAL_BROADCAST)");
}
// At this point, the network message may only contain a UDP transport
// message,
// this is asserted by the network layer calling this method.
final ModularNetLayer nlSender = getNetLayer(msg.getSender());
final ModularNetLayer nlReceiver = getNetLayer(msg.getReceiver());
// drop or not?
if (shallBeDropped(msg, nlSender, nlReceiver)) {
return;
}
// receive time?
long rcvTime = getRcvTime(msg, nlSender, nlReceiver);
Event.scheduleWithDelay(rcvTime - Time.getCurrentTime(),
new EventHandler() {
@Override
public void eventOccurred(Object se, int type) {
nlReceiver.receive(msg, nlSender);
}
}, null, 0);
}
@Override
public void writeBackToXML(BackWriter bw) {
// no types to write back
}
@Override
protected void netLayerWentOnline(NetLayer net) {
// nothing to do here.
}
@Override
protected void netLayerWentOffline(NetLayer net) {
// nothing to do here.
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
-->
</head>
<body bgcolor="white">
Package where different network implementations are located.
</body>
</html>
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