...
 
Commits (2)
  • uahhx's avatar
    sync · 658c6c52
    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
    658c6c52
  • uahhx's avatar
    RC0 · 14fdf514
    uahhx authored
    think everything's fixed
    
    TODO: test stuff? :)
    add local timestamp
    14fdf514
......@@ -182,7 +182,7 @@ public class FunnelNet {
public HashSet<DataPacket> bufferedContents() {
HashSet<DataPacket> packets = new HashSet<DataPacket>();
for (Node node : allNodes) {
for (SlinkyBuffer<DataPacket> buffer : node.getSubBuffers()) {
for (SlinkyBuffer buffer : node.getSubBuffers()) {
packets.addAll(buffer.getBuffer());
}
for (LinkedList<DataPacket> incLine : node.getSubIncomingLines()) {
......@@ -192,7 +192,7 @@ public class FunnelNet {
if (inc != null)
packets.add(inc);
}
for (SlinkyBuffer<DataPacket> buffer : node.getSuperBuffers()) {
for (SlinkyBuffer buffer : node.getSuperBuffers()) {
packets.addAll(buffer.getBuffer());
}
if (node.getSuperIncoming() != null)
......
......@@ -132,24 +132,23 @@ public abstract class Node {
}
/**
* Builds an array containing the first elements of all incoming lines, returns the DataPacket selected by the set strategy
* Returns the DataPacket selected for forwarding by the set strategy
* !! Removes the selected DataPacket from its source in the process !!
* @return DataPacket selected for forwarding by the set strategy
*/
protected DataPacket selectFromFrontRow() {
int subSelect = strategy.selectForwardingSub(subIncoming, subBuffers);
DataPacket result = null;
if(subSelect >= 0 && subSelect < subIncoming.length) {
DataPacket result;
if(subBuffers.get(subSelect).lookAtBuffer() != null) {
if(subBuffers.get(subSelect).isEmpty(true)) {
result = subIncoming[subSelect];
subIncoming[subSelect] = null;
}
else
result = subBuffers.get(subSelect).takeFromBuffer();
return result;
result = subBuffers.get(subSelect).takeFromBuffer(true);
}
return null;
return result;
//return (subSelect >= 0 && subSelect < subFrontRow.length) ? subFrontRow[subSelect] : null;
}
......@@ -162,64 +161,68 @@ public abstract class Node {
SlinkyBuffer curSubBuf;
SlinkyBuffer curSuperBuf;
DataPacket selectedMessage;
DataPacket superPrev = superIncoming;
int superIncDest = superIncoming == null ? -1 : getLocalOrigin(superIncoming.getOrigin());
for (int i = 0; i < subNeighbors.length; i++) {
selectedMessage = null;
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) {
//priority 3: drop or reject dead packets if possible. has to be checked first, because it prevents priority 1 event
//adding the incoming to the buffer before this step would be easier, but not hardware analogue
{
DataPacket curSubInc = subIncoming[i];
DataPacket curPacket = curSubBuf.lookAtBuffer();
if (curPacket == null && curSubInc != null)//improve me
curPacket = curSubInc;
if (curPacket != null && curPacket.getMState() != DataPacket.messageState.UNPROCESSED) {
boolean drop = true;
//can't reject if forwarding downward packets
if ((superIncoming == null || superIncDest != i) && curSuperBuf.isEmpty() && curPacket.getMState() == DataPacket.messageState.REJECTED) {
selectedMessage = curPacket;
}
else if (curPacket.getMState() == DataPacket.messageState.DROP)
;
else
drop = false;
if (drop) {
if (curPacket == curSubInc)
subIncoming[i] = null;
else
curSubBuf.takeFromBuffer();
}
}
}
//add incoming to buffer if it isn't already null or nulled aka used by something else
curSubBuf.add(subIncoming[i]);
subIncoming[i] = null;
if (selectedMessage == null) {
//priority 1: send stop if required
if (subSendEnableM[i] && curSubBuf.limitReached()) {
subSendEnableM[i] = false;
selectedMessage = new DataPacket(-1, parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.STOPSTART);
}
//priority 2: forward messages from super
else {
if (curSuperBuf.isEmpty() && superIncDest == i) {
selectedMessage = superIncoming;
superIncoming = null;
}
else
selectedMessage = curSuperBuf.takeFromBuffer(); //returns null if buffer empty, so being cheeky with that
}
}
//priority 4: send start if free
if (selectedMessage == null && !subSendEnableM[i] && !curSubBuf.limitReached()) {
subSendEnableM[i] = true;
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];
if (subIncoming[i] == message)
subIncoming[i] = null;
else
// subBuffers.get(i).takeFromBuffer(); //todo: remove obsolete
curSubBuf.takeFromBuffer();
if (message.getMState() == DataPacket.messageState.REJECTED)
selectedMessage = message;
subFrontRow[i] = null; //just to make sure.
}
curSubBuf.add(subIncoming[i]); //if a packet got rejected, the limit reached check in the following if statement is not necessary. but also, this always needs to be added if it wasn't null or nulled!
subIncoming[i] = null;
//add unnulled (aka unsent) incoming to buffer, update buffer limit state if necessary
if (selectedMessage == null) {
if (curSubBuf.limitReached() == subSendEnableM[i]) { //if the limit is reached and the sub is currently allowed to send (or vice versa), send control packet
subSendEnableM[i] = !curSubBuf.limitReached();
selectedMessage = new DataPacket(-1, parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.STOPSTART); //send StartStop K-Flagged segment.
if(SimHost.verbose(2)) {
if(SimHost.verbose(1))
System.out.println(nodeID() + " SubBuffer no." + i + (subSendEnableM[i] ? " free again" : " reached limit"));
else if (superIncDest == i)
parentNet.printMe("!!!!! This blocked message " + (curSuperBuf.isEmpty() ? superIncoming.getPacketID() : curSuperBuf.lookAtBuffer().getPacketID()));
}
}
//forward super messages downward
else if (!curSuperBuf.isEmpty() || superIncDest == i) {
// boolean skipBuffer = curSuperBuf.isEmpty();
// selectedMessage = skipBuffer ? superIncoming : curSuperBuf.takeFromBuffer();
if (!curSuperBuf.isEmpty())
selectedMessage = curSuperBuf.takeFromBuffer();
else if (superIncDest == i) {
selectedMessage = superIncoming;
superIncoming = null;
}
}
}
//add unsent super message to buffer
if (superIncDest == i && superIncoming != null) {
if (superIncDest == i) { // superIncoming != null not necessary, buffer checks it
curSuperBuf.add(superIncoming);
superIncoming = null;
if (curSuperBuf.limitReached())
......@@ -326,7 +329,7 @@ public abstract class Node {
return this.superSendEnableS;
}
public ArrayList<SlinkyBuffer<DataPacket>> getSuperBuffers() {
public ArrayList<SlinkyBuffer> getSuperBuffers() {
return superBuffers;
}
......@@ -338,7 +341,7 @@ public abstract class Node {
return superIncoming;
}
public ArrayList<SlinkyBuffer<DataPacket>> getSubBuffers() {
public ArrayList<SlinkyBuffer> getSubBuffers() {
return subBuffers;
}
......
......@@ -45,27 +45,44 @@ public class SlinkyBuffer {
* @return Last unprocessed element of the buffer.
*/
public DataPacket takeFromBuffer() {
return takeFromBuffer(false);
}
/**
* Removes the last unprocessed element from the buffer and returns it.
* @return Last unprocessed element of the buffer.
*/
public DataPacket takeFromBuffer(boolean onlyUnprocessed) {
if (buffer.size() > 0) {
if (SimHost.verbose(2) && buffer.size() == maxSize)
System.out.println("Buffer free again : " + this.toString());
DataPacket lastUnprocessed = lookAtBuffer();
DataPacket lastUnprocessed = lookAtBuffer(onlyUnprocessed);
buffer.removeLastOccurrence(lastUnprocessed);
return lastUnprocessed;
}
return null;
}
/**
* Returns the last element of the buffer.
* @return Last element of the buffer.
*/
public DataPacket lookAtBuffer() {
return lookAtBuffer(false);
}
/**
* Returns the last element of the buffer.
* @return Last element of the buffer.
*/
public DataPacket lookAtBuffer(boolean onlyUnprocessed) {
if (buffer.size() > 0) {
Iterator<DataPacket> iter = buffer.descendingIterator();
DataPacket curPacket;
do {
curPacket = iter.next();
if (curPacket.getMState() == DataPacket.messageState.UNPROCESSED)
if (!onlyUnprocessed || curPacket.getMState() == DataPacket.messageState.UNPROCESSED || curPacket.getMState() == DataPacket.messageState.PROCESSED)
return curPacket;
} while (iter.hasNext());
}
......@@ -90,8 +107,16 @@ public class SlinkyBuffer {
return result;
}
public boolean isEmpty() {
return buffer.isEmpty();
return isEmpty(false);
}
public boolean isEmpty(boolean onlyUnprocessed) {
if (onlyUnprocessed)
return lookAtBuffer(onlyUnprocessed) == null;
else
return buffer.isEmpty();
}
public LinkedList<DataPacket> getBuffer() {
......
......@@ -94,6 +94,8 @@ public class SimHost {
if (cycleNo % 1000 == 0) {
System.out.println(cycleNo +": Average RT: " + net.cumulativeRT / (float)net.successfulPacketCounter + ", # LivePackets: " + net.livePackets.size());
}
// if (cycleNo == 10)
// net.slavesNodes.iterator().next().createPacket();
HashSet<DataPacket> packetCopy = (HashSet<DataPacket>)net.livePackets.clone();
packetCopy.removeAll(net.bufferedContents());
if (packetCopy.size() > prevUnbuf) {
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.Nodes.SlinkyBuffer;
import java.util.ArrayList;
public class TestStrategy extends Strategy {
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
for (int i = 0; i < frontRow.length; i++) {
DataPacket packet = frontRow[i];
public int selectForwardingSub(DataPacket[] subIncomings, ArrayList<SlinkyBuffer> subBuffers) {
for (int i = 0; i < subIncomings.length; i++) {
DataPacket packet = subBuffers.get(i).takeFromBuffer(true);
if (packet == null)
packet = subIncomings[i];
if (packet != null)
return i;//packet.setMState(DataPacket.messageState.REJECTED);
//return i;
//return i;
}
return -1;
}
......