Commit 1b8f85ce authored by uahhx's avatar uahhx

added local timestamp

TODO: test stuff? :)
parent 14fdf514
......@@ -7,6 +7,7 @@ import FunnelNetSim.Nodes.SlinkyBuffer;
import FunnelNetSim.Strategies.GlobalTimeStamp;
import FunnelNetSim.Strategies.GlobalTimeStampLARRR;
import FunnelNetSim.Strategies.GlobalTimeStampRR;
import FunnelNetSim.Strategies.LocalTimeStampRR;
import FunnelNetSim.Visualizers.PseudoGraphics;
import java.util.HashMap;
......@@ -22,7 +23,7 @@ public class SimHost {
4: master info
5: slave info
*/
public static final byte verboseByte = (0b0001 << 4) + 0b0011;//true;
public static final byte verboseByte = (0b0000 << 4) + 0b0000;//true;
public static boolean verbose(int requiredFlags) {
return (verboseByte & (byte)requiredFlags) >= requiredFlags;
......@@ -87,7 +88,8 @@ public class SimHost {
// FunnelNet net = new FunnelNet(new GlobalTimeStamp(), 65, 2, 0);
// FunnelNet net = new FunnelNet(new GlobalTimeStampRR(), 27*3*3*3, 3, 0);
// FunnelNet net = new FunnelNet(new RoundRobin(), 27*3*3*3, 3, 0);
FunnelNet net = new FunnelNet(new GlobalTimeStampLARRR(), 27*3*3*3, 3, 0);
// FunnelNet net = new FunnelNet(new GlobalTimeStampLARRR(), 27*3*3*3, 3, 0);
FunnelNet net = new FunnelNet(new LocalTimeStampRR(), 27*3*3*3, 3, 0);
int prevUnbuf = 0;
for (int i = 0; i < 1000000; i++) {
int cycleNo = net.tickNet();
......
......@@ -43,7 +43,6 @@ public class GlobalTimeStampLARRR extends Strategy {
@Override
protected boolean shouldReject(DataPacket packet) {
//TODO: implement a predictive rejection (reject if it can't make the trip, based on optimal layer latency
FunnelNet net = parentNode.parentNet;
int age = net.getCycleCounter() - packet.getTimeStamp();
int bestCaseUpward = parentNode.getLayerNumber();
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.FunnelNet;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class LocalTimeStampRR extends Strategy {
int curRRPointer = 0;
int localAgeLimit = -1;
HashMap<DataPacket, Integer> localPacketTimeStamp = new HashMap<DataPacket, Integer>();
/*
this should not depend on the global timestamp and instead have a local time rotation based on the node being ticked
however, in the interest of keeping the strategies decoupled and not creating a large overhead, it is using global timestamp for checking the advance of time
*/
@Override
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
HashSet<DataPacket> removedPackets = new HashSet<DataPacket>(localPacketTimeStamp.keySet());
for (int i = 0; i < subIncomings.length; i++) {
int pointer = (i + curRRPointer) % subIncomings.length;
DataPacket curPacket;
Iterator<DataPacket> iter = subBuffers.get(pointer).getBuffer().descendingIterator();
do {
if (iter.hasNext())
curPacket = iter.next();
else
curPacket = subIncomings[pointer];
if (!localPacketTimeStamp.containsKey(curPacket))
localPacketTimeStamp.put(curPacket, parentNode.parentNet.getCycleCounter());
else
removedPackets.remove(curPacket);
if (curPacket != null && curPacket.getMState() == DataPacket.messageState.UNPROCESSED && !shouldReject(curPacket)) {
if (localPacketTimeStamp.get(curPacket) < oldestStamp) {
oldest = pointer;
oldestStamp = localPacketTimeStamp.get(curPacket);
}
//break; //can't break because removedPackets has to be unbuilt. there is probably a smoother solution, but this is easy and works just the same
}
} while (iter.hasNext() && curPacket != null);
//return i;
}
curRRPointer = (oldest + 1) % subIncomings.length;
for (DataPacket removedPacket : removedPackets)
localPacketTimeStamp.remove(removedPacket);
return oldest;
}
@Override
protected boolean shouldReject(DataPacket packet) {
//calculate age limit when not done already. in a more integrated way, this would just be done once without the need for an always wrong guarding condition
if (localAgeLimit < 0)
setLocalAgeLimit();
if (parentNode.parentNet.getCycleCounter() - localPacketTimeStamp.get(packet) > localAgeLimit) {
packet.setMState(dropPackets ? DataPacket.messageState.DROP : DataPacket.messageState.REJECTED);
return true;
}
return false;
}
@Override
public Strategy makeNew() {
return new LocalTimeStampRR();
}
private void setLocalAgeLimit() {
FunnelNet net = parentNode.parentNet;
int layerTraversals = net.getNumLayers() - 1;
int availableUpwardTime = net.rtcCycles - (layerTraversals * 2);
// int totalWeights = 0;
// for (int i = 0; i < net.getNumLayers() - 1; i++)
// totalWeights += Math.pow(net.getNumDownConnections(), i);
// int localWeight = (int) Math.pow(net.getNumDownConnections(), (net.getNumLayers() - 2) - parentNode.getLayerNumber());
//don't have to calculate stuff, if the numbers already exist :)
int totalWeights = net.netNodes.size() + 1; //+1 because of masternode. basically number of all nodes except the slaves.
int localWeight = net.layerNodes.get((net.getNumLayers() - 2) - parentNode.getLayerNumber()).size();
int selector = 2;
switch (selector) {
case 1: //weighted
localAgeLimit = (int) (availableUpwardTime * (float) localWeight / totalWeights);
break;
case 2: //dampened weighted
{
float dampeningFactor = 0.1f;
float averageWeight = (float)totalWeights / layerTraversals;
localAgeLimit = (int) (availableUpwardTime * ((1 - dampeningFactor) * localWeight + dampeningFactor * averageWeight) / totalWeights);
}
break;
default:
localAgeLimit = availableUpwardTime / layerTraversals;
}
localAgeLimit = localAgeLimit;
}
}
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