Skip to content

Commit

Permalink
#309: added node type P4 Switch in Slice Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxue1123 committed Apr 16, 2024
1 parent 22cdf8a commit 9e791f9
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fabric-portal",
"version": "1.6.4",
"version": "1.6.5",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.32",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
content="FABRIC Portal"
/>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Fabric Portal</title>
<title>FABRIC Portal</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
9 changes: 7 additions & 2 deletions src/components/SliceViewer/SideNodes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SideNodes extends React.Component {
}

handleAddNode = () => {
// support types: 'VM', 'Facility'
// support types: 'VM', 'Facility', 'P4 Switch'
if (this.state.nodeType === "VM") {
const { selectedSite, nodeName, core, ram, disk,
imageType, selectedImageRef, nodeComponents, BootScript } = this.state;
Expand All @@ -127,6 +127,10 @@ class SideNodes extends React.Component {
bandwidth: 0,
vlan: ""
})
} else if (this.state.nodeType === "Switch") {
const { selectedSite, nodeName } = this.state;
this.props.onSwitchAdd(selectedSite.name, nodeName);
this.setState({ nodeName: "" })
}
}

Expand Down Expand Up @@ -385,10 +389,11 @@ class SideNodes extends React.Component {
>
<option value="VM">VM</option>
<option value="Facility">Facility Port</option>
<option value="Switch">P4 Switch</option>
</select>
</div>
{
nodeType === "VM" && <div className="form-group slice-builder-form-group col-md-6">
["VM", "Switch"].includes(nodeType) && <div className="form-group slice-builder-form-group col-md-6">
<label htmlFor="inputNodeName" className="slice-builder-label">
Node Name
<OverlayTrigger
Expand Down
2 changes: 1 addition & 1 deletion src/components/SliceViewer/SingleComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class SingleComponent extends Component {
<option value="GPU">GPU</option>
<option value="SmartNIC">SmartNIC</option>
<option value="SharedNIC">SharedNIC</option>
{/* <option value="FPGA">FPGA</option> */}
<option value="FPGA">FPGA</option>
<option value="NVME">NVME</option>
<option value="Storage">Storage</option>
</select>
Expand Down
12 changes: 12 additions & 0 deletions src/pages/NewSliceForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ class NewSliceForm extends React.Component {
this.setState({ sliceNodes: newSliceNodes, sliceLinks: newSliceLinks});
}

handleSwitchAdd = (site, name) => {
const { graphID, sliceNodes, sliceLinks } = this.state;
const node = {
"type": "Switch",
"site": site,
"name": name
};
const { newSliceNodes, newSliceLinks } = builder.addSwitch(node, graphID, sliceNodes, sliceLinks);
this.setState({ sliceNodes: newSliceNodes, sliceLinks: newSliceLinks});
}

handleLinkAdd = (type, name) => {
const { selectedCPs, graphID, sliceNodes, sliceLinks } = this.state;
const { newSliceNodes, newSliceLinks} = builder.addLink(type, name, selectedCPs, graphID, sliceNodes, sliceLinks);
Expand Down Expand Up @@ -494,6 +505,7 @@ class NewSliceForm extends React.Component {
nodes={sliceNodes}
onVMAdd={this.handleVMAdd}
onFacilityAdd={this.handleFacilityAdd}
onSwitchAdd={this.handleSwitchAdd}
projectTags={projectTags}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/portalData.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.6.4",
"version": "1.6.5",
"defaultFacility": "FABRIC",
"facilityOptions": ["FABRIC"],
"keyLimit": 10,
Expand Down
67 changes: 67 additions & 0 deletions src/utils/sliceBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,73 @@ const addFacility = (node, graphID, nodes, links) => {
return { newSliceNodes: clonedNodes, newSliceLinks: clonedLinks }
}

const addSwitch = (node, graphID, nodes, links) => {
let clonedNodes = _.clone(nodes);
let clonedLinks = _.clone(links);

const switch_id = generateID(nodes);
let switch_link_id = generateID(links);
// 1. add Switch node
// 2. add 8 port node and 'connects' link
const relevantNodeIDs = [];
const relevantLinkIDs = [];
for (let i = 1; i < 9; i++) {
relevantNodeIDs.push(switch_id + i);
relevantLinkIDs.push(switch_link_id, switch_link_id + i)
}

const p4switch = {
"id": switch_id,
"GraphID": graphID,
"NodeID": uuidv4(),
"Class": "NetworkNode",
"Name": node.name,
"Type": "Switch",
"Site": node.site,
"StitchNode": "false",
"layout": JSON.stringify({
"relevantNodeIDs": relevantNodeIDs,
"relevantLinkIDs": relevantLinkIDs
})
}

clonedNodes.push(p4switch);

for (let i = 1; i < 9; i++) {
const switch_port = {
"id": switch_id + i,
"GraphID": graphID,
"NodeID": uuidv4(),
"Class": "ConnectionPoint",
"Name": `${node.name}-int`,
"Type": "FacilityPort",
"Capacities": JSON.stringify(node.capacities),
"Labels": JSON.stringify({
"vlan": node.labels ? node.labels.vlan : 0
}),
"StitchNode": "false",
"layout": JSON.stringify({
"site": node.site,
"connectFrom": switch_id,
"connectLinkIdAsTarget": switch_id + i
})
}

const switch_connects_port = {
"label": "connects",
"Class": "connects",
"id": switch_link_id + i - 1,
"source": switch_id,
"target": switch_id + i,
}

clonedNodes.push(switch_port);
clonedLinks.push(switch_connects_port)
}
// return sliceNodes and sliceLinks.
return { newSliceNodes: clonedNodes, newSliceLinks: clonedLinks }
}

// async, await for adding network service
// 1. add a Network Service Node and its Connection Points
// 2. add two 'connects' links: cpID1 - NS.cp1 and NS.cp2 - cpID2
Expand Down

0 comments on commit 9e791f9

Please sign in to comment.