Commit 2e94ea6a authored by uahhx's avatar uahhx

sync

TODO: pseudographics
look into buffer behaviour
parent 3fbf3094
......@@ -6,7 +6,8 @@ public class DataPacket {
private int originNode;
private static int packetIDCounter = 0; //just for behavioral evaluation (beeva)
private int packetID;
private int latencyCounter;
private int latencyCounter = 0;
private int lastCounter = 1;
private int timeStamp; //for beeva, but also used by global timestamp strategy
//private boolean isControlPacket; //might want to implement just unsing a bool later on, for info it might be better to use the enum though
......@@ -19,25 +20,25 @@ public class DataPacket {
UNPROCESSED, PROCESSED, REJECTED, DROP
}
public DataPacket(int originNode, int timeStamp) {
initDataPacket(originNode, timeStamp, messageType.REGULAR, messageState.UNPROCESSED);
public DataPacket(int originNode, int latency, int timeStamp) {
initDataPacket(originNode, latency, timeStamp, messageType.REGULAR, messageState.UNPROCESSED);
}
public DataPacket(int originNode, int timeStamp, messageType mType) {
initDataPacket(originNode, timeStamp, mType, messageState.UNPROCESSED);
public DataPacket(int originNode, int latency, int timeStamp, messageType mType) {
initDataPacket(originNode, latency, timeStamp, mType, messageState.UNPROCESSED);
}
public DataPacket(int originNode, int timeStamp, messageType mType, messageState mState) {
initDataPacket(originNode, timeStamp, mType, mState);
public DataPacket(int originNode, int latency, int timeStamp, messageType mType, messageState mState) {
initDataPacket(originNode, latency, timeStamp, mType, mState);
}
private void initDataPacket(int originNode, int timeStamp, messageType mType, messageState mState) {
private void initDataPacket(int originNode, int latency, int timeStamp, messageType mType, messageState mState) {
this.originNode = originNode;
this.mType = mType;
this.packetID = mType == messageType.REGULAR ? packetIDCounter++ : -1;
this.mState = mState;
this.timeStamp = timeStamp;
resetLatencyCounter();
resetLatencyCounter(latency);
}
public messageType getMType() {
......@@ -61,7 +62,12 @@ public class DataPacket {
}
public void resetLatencyCounter() {
latencyCounter = FunnelNet.packetLatency;
resetLatencyCounter(lastCounter);
}
public void resetLatencyCounter(int latency) {
lastCounter = latency;
latencyCounter = latency;
}
public boolean decrementLatencyCounter() {
......
......@@ -7,27 +7,24 @@ import FunnelNetSim.Strategies.Strategy;
public class FunnelNet {
//TODO: de-static that mess
public final Strategy strategy;
private Strategy strategy;
private int cycleCounter = 0;
public static final int packetLatency = 1; //in cycles
public static final int controlPacketSize = 1; //for slinkyBuffer. warning: if this changes from 1, handling of sending multiple segments has to be implemented
public final int packetLatency = 1; //in cycles
//public static final int dataWidth = 64/8; //dataWidth in number of segments per transmission. this should be a round number even if it wasn't forced by type.
public static final int bufferSize = 8; //max # of packets per buffer
public static final int bufferSize = 3; //max # of packets per buffer
//public static final int bufferSize = 4 + packetLatency*2; //max # of packets per buffer
public final int realTimeConstraint = 10000; //RTC in ns
public final int nodeClock = 125; //node Clockspeed in MHz
public final int rtcCycles = (realTimeConstraint*nodeClock)/1000;
public static final int numDownConnections = 1;//7; //total number of connections is this+1
private static final int numSlaves = 1; //7*7*7*7;
private static int numLayers; //0 based!
private static final int minNetLayers = 5;
private int numDownConnections = 1;//7; //total number of connections is this+1
private int numSlaves = 1; //7*7*7*7;
private int numLayers; //0 based!
private int minNetLayers = 5;
public MasterNode master = null;
public HashSet<NetNode> netNodes = new HashSet<NetNode>();
......@@ -35,12 +32,24 @@ public class FunnelNet {
public HashSet<Node> allNodes = new HashSet<Node>();
public static int packetCounter = 0;
public FunnelNet(Strategy strategy, int numSlaves, int numDownConnections, int minNetLayers) {
initFunnelNet(strategy, numSlaves, numDownConnections, minNetLayers);
}
public FunnelNet(Strategy strategy) { //for now no numUpConnections
initFunnelNet(strategy, numSlaves, numDownConnections, minNetLayers);
}
private void initFunnelNet(Strategy strategy, int numSlaves, int numDownConnections, int minNetLayers) {
this.strategy = strategy;
this.numSlaves = numSlaves;
this.numDownConnections = numDownConnections;
this.minNetLayers = minNetLayers;
createNet();
System.out.println("Number of Layers: " + numLayers);
System.out.println("Number of Slaves: " + numSlaves);
master.listTree();
}
private void createNet() {
......@@ -108,10 +117,14 @@ public class FunnelNet {
}
}
public static int getNumLayers() {
public int getNumLayers() {
return numLayers;
}
public int getNumDownConnections() {
return numDownConnections;
}
public int getCycleCounter() {
return cycleCounter;
}
......@@ -123,4 +136,8 @@ public class FunnelNet {
curNode.tick();
return cycleCounter++;
}
public Strategy getStrategy() {
return this.strategy;
}
}
\ No newline at end of file
......@@ -36,7 +36,8 @@ public abstract class Node {
public Node(int layerNumber, int nodeNumber, FunnelNet parentNet) {
this.layerNumber = layerNumber;
this.nodeNumber = nodeNumber;
this.strategy = parentNet.strategy.makeNew();
this.strategy = parentNet.getStrategy().makeNew();
this.strategy.setParentNode(this);
this.parentNet = parentNet;
}
......@@ -61,9 +62,9 @@ public abstract class Node {
this.subIncomingLines = new ArrayList<LinkedList<DataPacket>>(subNeighbors.length);
this.superBuffers = new ArrayList<SlinkyBuffer<DataPacket>>(subNeighbors.length);
for (int i = 0; i < subNeighbors.length; i++) {
subBuffers.add(new SlinkyBuffer<DataPacket>());
subBuffers.add(new SlinkyBuffer<DataPacket>(parentNet.packetLatency));
subIncomingLines.add(new LinkedList<DataPacket>());
superBuffers.add(new SlinkyBuffer<DataPacket>());
superBuffers.add(new SlinkyBuffer<DataPacket>(parentNet.packetLatency));
subSendEnableM[i] = true; //initially all slaves are able to send
}
......@@ -142,14 +143,17 @@ public abstract class Node {
int subSelect = strategy.selectForwardingSub(subFrontRow);
if(subSelect >= 0) {
if(subSelect >= 0 && 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;
}
return (subSelect >= 0 && subSelect < subFrontRow.length) ? subFrontRow[subSelect] : null;
return null;
//return (subSelect >= 0 && subSelect < subFrontRow.length) ? subFrontRow[subSelect] : null;
}
......@@ -162,8 +166,9 @@ public abstract class Node {
int superIncDest = superIncoming != null ? getLocalOrigin(superIncoming.getOrigin()) : -1;
SlinkyBuffer<DataPacket> curSubBuf;
SlinkyBuffer<DataPacket> curSuperBuf;
DataPacket selectedMessage = null;
DataPacket selectedMessage;
for (int i = 0; i < subNeighbors.length; i++) {
selectedMessage = null;
curSubBuf = subBuffers.get(i);
curSuperBuf = superBuffers.get(i);
......@@ -181,7 +186,7 @@ public abstract class Node {
curSubBuf.add(subIncoming[i]);
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.getCycleCounter(), DataPacket.messageType.STOPSTART); //send StartStop K-Flagged segment.
selectedMessage = new DataPacket(-1, parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.STOPSTART); //send StartStop K-Flagged segment.
}
else if (!curSuperBuf.isEmpty() || superIncDest == i) {
selectedMessage = curSuperBuf.isEmpty() ? superIncoming : curSuperBuf.takeFromBuffer();
......@@ -193,10 +198,11 @@ public abstract class Node {
curSuperBuf.add(superIncoming);
superIncoming = null;
if (curSuperBuf.limitReached())
System.out.println("a superbuffer ran over! this should not be happening!"); //NOTE: use this <PLACE> to check super buffer fill state later (implement buffer.size())
System.out.println("a superbuffer hit limit! this should not be happening!"); //NOTE: use this <PLACE> to check super buffer fill state later (implement buffer.size())
}
if (selectedMessage != null)
send(selectedMessage, subNeighbors[i]);
}
}
......@@ -205,7 +211,10 @@ public abstract class Node {
}*/
private int getLocalOrigin(int globalOrigin) {
return globalOrigin / (int)Math.pow(FunnelNet.numDownConnections, FunnelNet.getNumLayers() - 1 - layerNumber); //TODO: make sure the power is correct
int divider = (int)Math.pow(parentNet.getNumDownConnections(), parentNet.getNumLayers() - layerNumber - 2);
//int reduced = globalOrigin % (divider*parentNet.getNumDownConnections());
return (globalOrigin % (divider*parentNet.getNumDownConnections())) / divider;
//return globalOrigin / (int)Math.pow(parentNet.getNumDownConnections(), parentNet.getNumLayers() - layerNumber - 2); //TODO: make sure the power is correct
}
public void send(DataPacket message, Node target) {
......@@ -248,7 +257,7 @@ public abstract class Node {
}
LinkedList<DataPacket> incomingLine = subNumber < 0 ? superIncomingLine : subIncomingLines.get(subNumber);
message.resetLatencyCounter();
message.resetLatencyCounter(parentNet.packetLatency);
incomingLine.addFirst(message);
if (SimHost.verbose)
System.out.println(nodeID() + " receiving Message no. " + message.getPacketID() + " from " + (subNumber < -1 ? "unconnected" : (subNumber == -1 ? superNeighbor.nodeID() : (subNumber >= 0 ? subNeighbors[subNumber].nodeID() : subNumber))));
......
......@@ -19,7 +19,7 @@ public class SlaveNode extends Node {
public void tick() {
super.tick();
if (superIncoming != null)
System.out.println("Message no. " + superIncoming.getPacketID() + " from " + superIncoming.getOrigin() +
System.out.println("--------- Message no. " + superIncoming.getPacketID() + " from " + superIncoming.getOrigin() +
" returned to " + getNodeNumber() + " after " + (parentNet.getCycleCounter()-superIncoming.getTimeStamp()) + " cycles");
}
......@@ -31,14 +31,14 @@ public class SlaveNode extends Node {
public boolean createPacket() {
if (superBuffers.isEmpty() && superSendEnableS) {
DataPacket newPacket = new DataPacket(this.getNodeNumber(), parentNet.getCycleCounter(), DataPacket.messageType.REGULAR);
DataPacket newPacket = new DataPacket(this.getNodeNumber(), parentNet.packetLatency, parentNet.getCycleCounter(), DataPacket.messageType.REGULAR);
send(newPacket, superNeighbor);
if (SimHost.verbose)
System.out.println("created new Packet");
return true;
}
if (SimHost.verbose)
System.out.println("could not create new Packet!");
System.out.println("!!!!!!!!! could not create new Packet!");
return false;
}
......
......@@ -7,9 +7,12 @@ import java.util.LinkedList;
public class SlinkyBuffer<T> {
private LinkedList<T> buffer;
private final int latency;
private boolean hitLimit = false;
public SlinkyBuffer() {
public SlinkyBuffer(int latency) {
this.buffer = new LinkedList<T>();
this.latency = latency;
}
/**
......@@ -56,9 +59,15 @@ public class SlinkyBuffer<T> {
*/
public boolean limitReached() {
//return buffer.size() + 2*FunnelNet.packetLatency -1 >= FunnelNet.bufferSize; //this actually makes it hit the buffer limit, better be careful around that
boolean result = buffer.size() + 2*FunnelNet.packetLatency >= FunnelNet.bufferSize;
if (result && SimHost.verbose)
System.out.println(this.toString() + " reached its limit");
boolean result = buffer.size() + 2*latency >= FunnelNet.bufferSize;
if (SimHost.verbose) {
if (result && !hitLimit)
System.out.println("######### " + this.toString() + " reached its limit");
else if (!result && hitLimit)
System.out.println("$$$$$$$$$ " + this.toString() + " clear again");
}
hitLimit = result;
return result;
}
......
......@@ -2,6 +2,7 @@ package FunnelNetSim;
import FunnelNetSim.Nodes.Node;
import FunnelNetSim.Nodes.SlaveNode;
import FunnelNetSim.Strategies.GlobalTimeStamp;
import FunnelNetSim.Strategies.TestStrategy;
public class SimHost {
......@@ -13,13 +14,14 @@ public class SimHost {
}
private static void run() {
FunnelNet net = new FunnelNet(new TestStrategy());
net.master.listTree();
//FunnelNet net = new FunnelNet(new TestStrategy());
//FunnelNet net = new FunnelNet(new TestStrategy(), 8, 2, 1);
FunnelNet net = new FunnelNet(new GlobalTimeStamp(), 4, 2, 1);
int a = 2;
int b = a+30;
int c = b+30;
int b = a+1;
int c = b+20;
net.master.getSubNeighbors()[0].lockNodeToggle();
//net.master.getSubNeighbors()[0].lockNodeToggle();
for (int i = 0; i < a; i++) {
System.out.println(net.tickNet());
......@@ -33,7 +35,7 @@ public class SimHost {
System.out.println(cycleNo);
}
net.master.getSubNeighbors()[0].lockNodeToggle();
//net.master.getSubNeighbors()[0].lockNodeToggle();
for (int i = b; i < c; i++) {
System.out.println(net.tickNet());
......
package FunnelNetSim.Strategies;
import FunnelNetSim.DataPacket;
import FunnelNetSim.SimHost;
public class GlobalTimeStamp extends Strategy {
@Override
public int selectForwardingSub(DataPacket[] frontRow) {
DataPacket oldest;
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 = curPacket;
oldest = i;
oldestStamp = curPacket.getTimeStamp();
}
}
return i;//packet.setMState(DataPacket.messageState.REJECTED);
//return i;
}
return -1;
return oldest;
}
@Override
......
......@@ -20,4 +20,7 @@ public abstract class Strategy {
}
public void setParentNode(Node node) {
parentNode = node;
};
}
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