Skip to content

Commit

Permalink
Merge pull request #5 from deffel/master
Browse files Browse the repository at this point in the history
Added Ethernet Switch.
  • Loading branch information
deffel authored Sep 14, 2023
2 parents 0b22f7a + 0115c99 commit a4cf1ed
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 85 deletions.
5 changes: 5 additions & 0 deletions gui/SelectionMenuPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ var SelectionMenuPolicy = draw2d.policy.figure.SelectionPolicy.extend({
var num_to_delete = parseInt(figure.getName().substring(1));
for (i = 0; i < fpganodes.getSize(); i++) {
var node = fpganodes.get(i);

if (node.NAME != "NodeShape") {
continue;
}

var nodeLabel = node.getLabel();
var nodeNum = parseInt(nodeLabel.getText().substring(1));
// Update all nodes that have greater num than the node to delete.
Expand Down
96 changes: 96 additions & 0 deletions gui/SwitchShape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
SwitchShape = draw2d.shape.basic.Label.extend({
NAME: "SwitchShape",

ORIENTATION_PROPERTIES: Object.freeze({
[OrientationEnum.north]: {
"rotationAngle": 0,
"padding": { left: 25, top: 5, right: 25, bottom: 5 },
"locator": new draw2d.layout.locator.BottomLocator(),
},
[OrientationEnum.east]: {
"rotationAngle": 0,
"padding": { left: 25, top: 5, right: 25, bottom: 5 },
"locator": new draw2d.layout.locator.RightLocator(),
},
[OrientationEnum.south]: {
"rotationAngle": 0,
"padding": { left: 25, top: 5, right: 25, bottom: 5 },
"locator": new draw2d.layout.locator.TopLocator(),
},
[OrientationEnum.west]: {
"rotationAngle": 0,
"padding": { left: 25, top: 5, right: 25, bottom: 5 },
"locator": new draw2d.layout.locator.LeftLocator(),
},
}),

init: function (attr) {
this._super($.extend({}, attr));

this.setText("Ethernet Switch");

// Allows multiple connections.
this.linksToChannel = [];

// Shape for view.
this.connector;
this.isDrawn = false;
let port = this.createPort("hybrid");
port.setName("inout_" + this.id);
// port.setMaxFanOut(1);
// port.on("connect", function () {
// this.setVisible(false);
// }, port);
// port.on("disconnect", function () {
// this.setVisible(true);
// }, port);

// this.orientation = attr.orientation;
this.setOrientation(attr.orientation, false);
// this.getFPGA().channelLayout.add(this);
},

setLinksToChannel: function (partner) {
this.linksToChannel.push(partner);
},

// TODO: update to array structure of switch.
// getLinksToChannel: function () {
// return this.linksToChannel;
// },

setIsDrawn: function (isDrawn) {
this.isDrawn = isDrawn;
},

getIsDrawn: function () {
return this.isDrawn;
},

setConnector: function (connector) {
this.connector = connector;
},

getConnector: function () {
return this.connector;
},

getOrientation: function () {
return this.orientation;
},

setOrientation: function (orientation, repaint = true) {
this.orientation = orientation;
let prop = this.ORIENTATION_PROPERTIES[orientation];
this.getHybridPort(0).setLocator(prop.locator);
this.rotationAngle = prop.rotationAngle;
this.height = 0;
this.setPadding(prop.padding);

if (repaint) {
this.repaint();
}
}
});

199 changes: 131 additions & 68 deletions gui/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ example.Toolbar = Class.extend({
var srun_N_needle = "-N ";
var srun_N = -1;
var fpgalinks = [];
let with_ethernet = false;

// Look for -N argument.
var i = 0;
Expand All @@ -210,17 +211,23 @@ example.Toolbar = Class.extend({
} else {
// -N not available. Pre-process command:

// Pre-process command for "n2fpga.." node id to replace
// with "n00.." node names.
var regFPGA = /(n2fpga\d{2}):(acl[012]{1}):(ch[0123]{1})-(n2fpga\d{2}):(acl[012]{1}):(ch[0123]{1})/g;
// Pre-process command for "n2fpga.." node id to replace with "n.." node names.
var regFPGA = /((n2fpga\d{2}):(acl[012]{1}):(ch[0123]{1})|eth)-((n2fpga\d{2}):(acl[012]{1}):(ch[0123]{1})|eth)/g;
var resultFPGA;
const mapFPGA = new Map();

while ((resultFPGA = regFPGA.exec(srun_raw)) !== null) {
// fpgalinks.push(result);

mapFPGA.set(resultFPGA[1], 1);
mapFPGA.set(resultFPGA[4], 1);
if (resultFPGA[1] != "eth") {
mapFPGA.set(resultFPGA[2], 1);
} else {
with_ethernet = true;
}
if (resultFPGA[5] != "eth") {
mapFPGA.set(resultFPGA[6], 1);
} else {
with_ethernet = true;
}
// console.log(resultFPGA);
}

Expand All @@ -236,27 +243,47 @@ example.Toolbar = Class.extend({

// console.log(srun_raw);


// return ;

// salloc: SPANK_FPGALINK0=n00:acl0:ch3-n00:acl1:ch3 salloc: SPANK_FPGALINK1=n00:acl0:ch2-n00:acl1:ch2 salloc: SPANK_FPGALINK2=n00:acl0:ch0-n00:acl1:ch0 salloc: SPANK_FPGALINK3=n00:acl0:ch1-n00:acl1:ch1

var reg = /(n[01]{1}\d{1}):(acl[012]{1}):(ch[0123]{1})-(n[01]{1}\d{1}):(acl[012]{1}):(ch[0123]{1})/g;
var reg = /((n[01]{1}\d{1}):(acl[012]{1}):(ch[0123]{1})|eth)-((n[01]{1}\d{1}):(acl[012]{1}):(ch[0123]{1})|eth)/g;
var result;
const mapN = new Map();

// result: Array(9) [ "n00:acl0:ch1-n00:acl2:ch0", "n00:acl0:ch1", "n00", "acl0", "ch1", "n00:acl2:ch0", "n00", "acl2", "ch0" ]
while ((result = reg.exec(srun_raw)) !== null) {
fpgalinks.push(result);

mapN.set(result[1], 1);
mapN.set(result[4], 1);
if (result[1] != "eth") {
mapN.set(result[2], 1);
} else {
with_ethernet = true;
}
if (result[5] != "eth") {
mapN.set(result[6], 1);
} else {
with_ethernet = true;
}

// console.log(result);
}

// console.log(mapN.size);
srun_N = mapN.size;
}

// Create Ethernet switch if required.
var eth_switch = null;
if (with_ethernet) {
var pos_y = 20;
var pos_x = 200;

eth_switch = new SwitchShape({ "orientation": OrientationEnum.north })

// create a command for the undo/redo support
var command = new draw2d.command.CommandAdd(this.view, eth_switch, pos_x, pos_y);
this.view.getCommandStack().execute(command);
}

// Create fpganodes.
var fpganodes = [];
var pos_y = 20;
Expand Down Expand Up @@ -697,30 +724,47 @@ example.Toolbar = Class.extend({
var links = full_match.split("-");

// Point 1 (think of source).
// value: n00:acl0:ch0
// value: n00:acl0:ch0 or eth (for Ethernet switch).
var link_p1 = links[0].split(":");
// 0: n00
// 1: acl0
// 2: ch0
// Set the link.
// Get node.
var tnode_p1 = fpganodes[this.getNodeIdFpgalink(link_p1[0])];
// Get FPGA.
var tfpga_p1 = tnode_p1.getFPGAFromFpgalink(link_p1[1]);

// Point 2 (think of destination).
// value: n00:acl0:ch0 or eth (for Ethernet switch).
var link_p2 = links[1].split(":");
// 0: n00
// 1: acl0
// 2: ch0
// Set the link.
// Get node.
var tnode_p2 = fpganodes[this.getNodeIdFpgalink(link_p2[0])];
// Get FPGA.
var tfpga_p2 = tnode_p2.getFPGAFromFpgalink(link_p2[1]);

// Channels to connect. Logic is required to differentiate if
// the channel is between FPGAs or to/from Ethernet switch.
let chan0;
let chan1;

if (link_p1.length == 3) {
// Channel is from FPGA node.
// Get node.
var tnode_p1 = fpganodes[this.getNodeIdFpgalink(link_p1[0])];
// Get FPGA.
var tfpga_p1 = tnode_p1.getFPGAFromFpgalink(link_p1[1]);

// Get channel.
chan0 = tfpga_p1.getChannelFromFpgalink(link_p1[2]);
} else {
// Channel is to ethernet switch.
chan0 = eth_switch;
}

if (link_p2.length == 3) {
// Channel is to FPGA node.

// Get node.
var tnode_p2 = fpganodes[this.getNodeIdFpgalink(link_p2[0])];
// Get FPGA.
var tfpga_p2 = tnode_p2.getFPGAFromFpgalink(link_p2[1]);

chan1 = tfpga_p2.getChannelFromFpgalink(link_p2[2]);
} else {
// Channel is to ethernet switch.
chan1 = eth_switch;
}

// Get channels, connect and draw them.
this.connectChannels(tfpga_p1.getChannelFromFpgalink(link_p1[2]), tfpga_p2.getChannelFromFpgalink(link_p2[2]));
this.connectChannels(chan0, chan1);

// if(link_p1[2] == "ch0") {
// tfpga_p1.getChannelFromFpgalink(link_p1[2]).getConnector().setColor(ColorEnum.red);
Expand All @@ -733,43 +777,62 @@ example.Toolbar = Class.extend({
srun_raw_copy = srun_raw_copy.substring(next_space);
}


// Parse and add fpga links: n00:acl0:ch0-n00:acl1:ch0
//
// Array(7) [ "n00:acl1:ch0-n00:acl1:ch1", "00", "1", "0", "00", "1", "1" ]
for (var i = 0; i < fpgalinks.length; i++) {
// Point 1 (think of source).
// 0: n00
// 1: acl0
// 2: ch0
// Set the link.
// Get node.
var tnode_p1 = fpganodes[this.getNodeIdFpgalink(fpgalinks[i][1])];
// Get FPGA.
var tfpga_p1 = tnode_p1.getFPGAFromFpgalink(fpgalinks[i][2]);
// Point 2 (think of destination).
// 0: n00
// 1: acl0
// 2: ch0
// Set the link.
// Get node.
var tnode_p2 = fpganodes[this.getNodeIdFpgalink(fpgalinks[i][4])];
// Get FPGA.
var tfpga_p2 = tnode_p2.getFPGAFromFpgalink(fpgalinks[i][5]);

// Get channels, connect and draw them.
this.connectChannels(
tfpga_p1.getChannelFromFpgalink(fpgalinks[i][3]),
tfpga_p2.getChannelFromFpgalink(fpgalinks[i][6])
);

// if(link_p1[2] == "ch0") {
// tfpga_p1.getChannelFromFpgalink(link_p1[2]).getConnector().setColor(ColorEnum.red);
// }
}
if (srun_raw.indexOf(srun_fpgalinks_needle) == -1) {
// Array(7) [ "n00:acl1:ch0-n00:acl1:ch1", "00", "1", "0", "00", "1", "1" ]
// Array(9)["n00:acl0:ch1-eth", "n00:acl0:ch1", "n00", "acl0", "ch1", "eth", undefined, undefined, undefined]
for (var i = 0; i < fpgalinks.length; i++) {
// Parse and add fpga links: n00:acl0:ch0-n00:acl1:ch0
var links = fpgalinks[i][0].split("-");

// Point 1 (think of source).
// value: n00:acl0:ch0 or eth (for Ethernet switch).
var link_p1 = links[0].split(":");
// Point 2 (think of destination).
// value: n00:acl0:ch0 or eth (for Ethernet switch).
var link_p2 = links[1].split(":");

// Channels to connect. Logic is required to differentiate if
// the channel is between FPGAs or to/from Ethernet switch.
let chan0;
let chan1;

if (link_p1.length == 3) {
// Channel is from FPGA node.
// Get node.
var tnode_p1 = fpganodes[this.getNodeIdFpgalink(link_p1[0])];
// Get FPGA.
var tfpga_p1 = tnode_p1.getFPGAFromFpgalink(link_p1[1]);

// Get channel.
chan0 = tfpga_p1.getChannelFromFpgalink(link_p1[2]);
} else {
// Channel is to ethernet switch.
chan0 = eth_switch;
}

if (link_p2.length == 3) {
// Channel is to FPGA node.

// Get node.
var tnode_p2 = fpganodes[this.getNodeIdFpgalink(link_p2[0])];
// Get FPGA.
var tfpga_p2 = tnode_p2.getFPGAFromFpgalink(link_p2[1]);

chan1 = tfpga_p2.getChannelFromFpgalink(link_p2[2]);
} else {
// Channel is to ethernet switch.
chan1 = eth_switch;
}

// Get channels, connect and draw them.
this.connectChannels(chan0, chan1);
}
}



},

makeGrid: function (N, width) {
Expand Down Expand Up @@ -873,7 +936,7 @@ example.Toolbar = Class.extend({
// Draw them in View.
//
// Draw connection only ones.
if (!tchannel_p1.getIsDrawn()) {
// if (!tchannel_p1.getIsDrawn()) {
var c = new HoverConnection();

c.setSource(tchannel_p1.getHybridPort(0));
Expand All @@ -883,14 +946,14 @@ example.Toolbar = Class.extend({
tchannel_p1.setConnector(c);
tchannel_p2.setConnector(c);

// Flag both connectors as drawn.
tchannel_p1.setIsDrawn(true);
tchannel_p2.setIsDrawn(true);
// // Flag both connectors as drawn.
// tchannel_p1.setIsDrawn(true);
// tchannel_p2.setIsDrawn(true);

// create a command for the undo/redo support
var command = new draw2d.command.CommandAdd(this.view, c, 0, 0);
this.view.getCommandStack().execute(command);
}
// }
},

arrangeTopology: function (topology_name, fpganodes) {
Expand Down
Loading

0 comments on commit a4cf1ed

Please sign in to comment.