...
 
Commits (2)
  • uahhx's avatar
    fixed Strategies so they don't use subFrontRow anymore · 7c222f05
    uahhx authored
    TODO: enhance packet rejection so it can send elegible packets at the same time. might require dual-channel-ram-like buffers or something idk.
    7c222f05
  • uahhx's avatar
    sync · e5c304d0
    uahhx authored
    NOT RUNNABLE
    fixed small RR Strategy Bug
    made slinkybuffers non general (now only uses datapackets)
    made slinkybuffers take/look take unprocessed
    
    TODO: enhance packet rejection so it can send elegible packets at the same time. might require dual-channel-ram-like buffers or something idk.
    
    !!! make take/look work for processed, too
    e5c304d0
......@@ -6,6 +6,7 @@ import FunnelNetSim.SimHost;
import FunnelNetSim.Strategies.Strategy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
public abstract class Node {
......@@ -19,11 +20,11 @@ public abstract class Node {
protected Node superNeighbor = null;
private Node[] subNeighbors = null;
protected ArrayList<SlinkyBuffer<DataPacket>> superBuffers = null;
protected ArrayList<SlinkyBuffer> superBuffers = null;
private LinkedList<DataPacket> superIncomingLine = null;
protected DataPacket superIncoming = null;
protected ArrayList<SlinkyBuffer<DataPacket>> subBuffers = null;
protected ArrayList<SlinkyBuffer> subBuffers = null;
private ArrayList<LinkedList<DataPacket>> subIncomingLines = null;
protected DataPacket[] subIncoming = null;
//subFirstElement could be skipped by putting the incomings into the buffer and immediatly reading them from there,
......@@ -58,13 +59,13 @@ public abstract class Node {
this.subFrontRow = new DataPacket[subNeighbors.length];
this.subSendEnableM = new boolean[subNeighbors.length];
this.subBuffers = new ArrayList<SlinkyBuffer<DataPacket>>(subNeighbors.length);
this.subBuffers = new ArrayList<SlinkyBuffer>(subNeighbors.length);
this.subIncomingLines = new ArrayList<LinkedList<DataPacket>>(subNeighbors.length);
this.superBuffers = new ArrayList<SlinkyBuffer<DataPacket>>(subNeighbors.length);
this.superBuffers = new ArrayList<SlinkyBuffer>(subNeighbors.length);
for (int i = 0; i < subNeighbors.length; i++) {
subBuffers.add(new SlinkyBuffer<DataPacket>(parentNet.packetLatency, FunnelNet.bufferSize));
subBuffers.add(new SlinkyBuffer(parentNet.packetLatency, FunnelNet.bufferSize));
subIncomingLines.add(new LinkedList<DataPacket>());
superBuffers.add(new SlinkyBuffer<DataPacket>(parentNet.packetLatency, FunnelNet.bufferSize*2));
superBuffers.add(new SlinkyBuffer(parentNet.packetLatency, FunnelNet.bufferSize*2));
subSendEnableM[i] = true; //initially all slaves are able to send
}
......@@ -136,30 +137,17 @@ public abstract class Node {
* @return DataPacket selected for forwarding by the set strategy
*/
protected DataPacket selectFromFrontRow() {
for (int i = 0; i < subNeighbors.length; i++) {
if (subBuffers.get(i).isEmpty())
subFrontRow[i] = subIncoming[i];
else
subFrontRow[i] = subBuffers.get(i).lookAtBuffer();
}
int subSelect = strategy.selectForwardingSub(subFrontRow);
//if(subSelect >= 0 && subSelect < subFrontRow.length) {
if(subSelect >= 0) {
if (subSelect < subFrontRow.length) {
if(subBuffers.get(subSelect).isEmpty())
subIncoming[subSelect] = null;
else
subBuffers.get(subSelect).takeFromBuffer();
DataPacket result = subFrontRow[subSelect];
subFrontRow[subSelect] = null;
return result;
}
else {
return null;
}
int subSelect = strategy.selectForwardingSub(subIncoming, subBuffers);
if(subSelect >= 0 && subSelect < subIncoming.length) {
DataPacket result;
if(subBuffers.get(subSelect).lookAtBuffer() != null) {
result = subIncoming[subSelect];
subIncoming[subSelect] = null;
}
else
result = subBuffers.get(subSelect).takeFromBuffer();
return result;
}
return null;
//return (subSelect >= 0 && subSelect < subFrontRow.length) ? subFrontRow[subSelect] : null;
......@@ -171,8 +159,8 @@ public abstract class Node {
* Warning: Evaluate if it is possible for the super buffers to run over due to start/stop messages' priority
*/
protected void downwardCom() {
SlinkyBuffer<DataPacket> curSubBuf;
SlinkyBuffer<DataPacket> curSuperBuf;
SlinkyBuffer curSubBuf;
SlinkyBuffer curSuperBuf;
DataPacket selectedMessage;
DataPacket superPrev = superIncoming;
int superIncDest = superIncoming == null ? -1 : getLocalOrigin(superIncoming.getOrigin());
......@@ -181,6 +169,17 @@ public abstract class Node {
curSubBuf = subBuffers.get(i);
curSuperBuf = superBuffers.get(i);
//check if a stop has to be sent
if (subSendEnableM[i] && curSubBuf.limitReached()) {
if (superIncoming != null || !superBuffers.get(i).isEmpty() || curSubBuf.getBuffer().getLast().getMState() != DataPacket.messageState.REJECTED) {
subSendEnableM[i] = false;
selectedMessage = new DataPacket(-1, parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.STOPSTART);
}
}
//warning: check if reject first. a reject affects the buffer fill state and the limit hit accordingly
//---------------------------
//check frontRow for packet to be dropped or rejected
if (subFrontRow[i] != null && subFrontRow[i].getMState() != DataPacket.messageState.UNPROCESSED) {
DataPacket message = subFrontRow[i];
......
package FunnelNetSim.Nodes;
import FunnelNetSim.DataPacket;
import FunnelNetSim.FunnelNet;
import FunnelNetSim.SimHost;
import java.util.Iterator;
import java.util.LinkedList;
public class SlinkyBuffer<T> {
private LinkedList<T> buffer;
public class SlinkyBuffer {
private LinkedList<DataPacket> buffer;
private final int latency;
private final int limit;
private final int maxSize;
public static int overfillCount = 0;
public SlinkyBuffer(int latency, int maxSize) {
this.buffer = new LinkedList<T>();
this.buffer = new LinkedList<DataPacket>();
this.latency = latency;
this.maxSize = maxSize;
this.limit = maxSize - (2*latency -1);
......@@ -23,7 +25,7 @@ public class SlinkyBuffer<T> {
* Inserts new packet at the start of the buffer.
* @param newPkt Packet to be insertet at the start of the buffer. Disregards null;
*/
public void add(T newPkt) {
public void add(DataPacket newPkt) {
if (newPkt != null) // && buffer.size() < FunnelNet.bufferSize)
buffer.addFirst(newPkt);
......@@ -39,25 +41,35 @@ public class SlinkyBuffer<T> {
}
/**
* Removes the last element from the buffer and returns it.
* @return Last element of the buffer.
* Removes the last unprocessed element from the buffer and returns it.
* @return Last unprocessed element of the buffer.
*/
public T takeFromBuffer() {
if (buffer.size() <= 0)
return null;
if (SimHost.verbose(2) && buffer.size() == maxSize)
System.out.println("Buffer free again : " + this.toString());
return buffer.removeLast();
public DataPacket takeFromBuffer() {
if (buffer.size() > 0) {
if (SimHost.verbose(2) && buffer.size() == maxSize)
System.out.println("Buffer free again : " + this.toString());
DataPacket lastUnprocessed = lookAtBuffer();
buffer.removeLastOccurrence(lastUnprocessed);
return lastUnprocessed;
}
return null;
}
/**
* Returns the last element of the buffer.
* @return Last element of the buffer.
*/
public T lookAtBuffer() {
if (buffer.size() <= 0)
return null;
return buffer.getLast();
public DataPacket lookAtBuffer() {
if (buffer.size() > 0) {
Iterator<DataPacket> iter = buffer.descendingIterator();
DataPacket curPacket;
do {
curPacket = iter.next();
if (curPacket.getMState() == DataPacket.messageState.UNPROCESSED)
return curPacket;
} while (iter.hasNext());
}
return null;
}
/**
......@@ -82,7 +94,7 @@ public class SlinkyBuffer<T> {
return buffer.isEmpty();
}
public LinkedList<T> getBuffer() {
public LinkedList<DataPacket> getBuffer() {
return buffer;
}
}
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
import java.util.Iterator;
public class GlobalTimeStamp extends Strategy {
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
for (int i = 0; i < frontRow.length; i++) {
DataPacket curPacket = frontRow[i];
if (curPacket != null && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = i;
oldestStamp = curPacket.getTimeStamp();
for (int i = 0; i < subIncomings.length; i++) {
DataPacket curPacket;
Iterator<DataPacket> iter = subBuffers.get(i).getBuffer().descendingIterator();
do {
if (iter.hasNext())
curPacket = iter.next();
else
curPacket = subIncomings[i];
if (curPacket != null && curPacket.getMState() == DataPacket.messageState.UNPROCESSED && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = i;
oldestStamp = curPacket.getTimeStamp();
}
break;
}
}
} while (iter.hasNext() && curPacket != null);
//return i;
}
return oldest;
......
......@@ -2,28 +2,42 @@ package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.FunnelNet;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
import java.util.Iterator;
public class GlobalTimeStampLARRR extends Strategy {
int curRRPointer = 0;
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
for (int i = 0; i < frontRow.length; i++) {
int pointer = (i + curRRPointer) % frontRow.length;
DataPacket curPacket = frontRow[pointer];
if (curPacket != null && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = pointer;
oldestStamp = curPacket.getTimeStamp();
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 (curPacket != null && curPacket.getMState() == DataPacket.messageState.UNPROCESSED && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = pointer;
oldestStamp = curPacket.getTimeStamp();
}
break;
}
}
} while (iter.hasNext() && curPacket != null);
//return i;
}
curRRPointer = (oldest + 1) % frontRow.length;
curRRPointer = (oldest + 1) % subIncomings.length;
return oldest;
}
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
import java.util.Iterator;
public class GlobalTimeStampRR extends Strategy {
int curRRPointer = 0;
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
int oldest = -1;
int oldestStamp = Integer.MAX_VALUE;
for (int i = 0; i < frontRow.length; i++) {
int pointer = (i + curRRPointer) % frontRow.length;
DataPacket curPacket = frontRow[pointer];
if (curPacket != null && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = pointer;
oldestStamp = curPacket.getTimeStamp();
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 (curPacket != null && curPacket.getMState() == DataPacket.messageState.UNPROCESSED && !shouldReject(curPacket)) {
if (curPacket.getTimeStamp() < oldestStamp) {
oldest = pointer;
oldestStamp = curPacket.getTimeStamp();
}
break;
}
}
} while (iter.hasNext() && curPacket != null);
//return i;
}
curRRPointer = (oldest + 1) % frontRow.length;
curRRPointer = (oldest + 1) % subIncomings.length;
return oldest;
}
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
import java.util.Iterator;
public class RoundRobin extends Strategy {
int curRRPointer = 0;
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
for (int i = 0; i < frontRow.length; i++) {
int pointer = (i + curRRPointer) % frontRow.length;
if (frontRow[pointer] != null) {
curRRPointer = (pointer + 1) % frontRow.length;
return pointer;
}
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
int subSelect = -1;
for (int i = 0; i < subIncomings.length; i++) {
int pointer = (i + curRRPointer) % subIncomings.length;
DataPacket curPacket;
Iterator<DataPacket> iter = subBuffers.get(i).getBuffer().descendingIterator();
do {
if (iter.hasNext())
curPacket = iter.next();
else
curPacket = subIncomings[i];
if (curPacket != null && curPacket.getMState() == DataPacket.messageState.UNPROCESSED && !shouldReject(curPacket)) {
if (subSelect < 0)
subSelect = pointer; //do not immediatly return, because some rejection handling might be implemented for RR
break;
}
} while (iter.hasNext() && curPacket != null);
}
return 0;
if (subSelect >= 0)
curRRPointer = (subSelect + 1) % subIncomings.length;
return subSelect;
}
@Override
......
......@@ -2,24 +2,21 @@ package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.Nodes.Node;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
public abstract class Strategy {
protected boolean dropPackets = false;
protected Node parentNode = null;
public abstract int selectForwardingSub(DataPacket[] frontRow);
public abstract int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers);
protected abstract boolean shouldReject(DataPacket packet);
public abstract Strategy makeNew();
//TODO: LOOK AT ME! LOOK AT ALL MAH GLORY!
public int testi(DataPacket[] frontRow) {
return selectForwardingSub(frontRow);
}
public void setParentNode(Node node) {
parentNode = node;
};
......