527 lines
21 KiB
HTML
527 lines
21 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>CORE</title>
|
|
<link rel="stylesheet" type="text/css" href="static/bootstrap.min.css">
|
|
<link rel="stylesheet" type="text/css" href="static/vis.min.css">
|
|
<link rel="stylesheet" type="text/css" href="static/core.css">
|
|
</head>
|
|
<body>
|
|
<div class="container-fluid d-flex flex-column p-0">
|
|
<nav class="navbar navbar-expand navbar-dark bg-dark mb-2">
|
|
<div class="navbar-brand mb-0 h1">
|
|
<img src="static/core-icon.png"/>
|
|
<span>CORE</span>
|
|
</div>
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nb-content"
|
|
aria-controls="nb-content" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
|
|
<div class="collapse navbar-collapse" id="nb-content">
|
|
<ul class="navbar-nav mr-auto">
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="nb-file" role="button" data-toggle="dropdown"
|
|
aria-haspopup="true" aria-expanded="false">
|
|
File
|
|
</a>
|
|
<div class="dropdown-menu" aria-labelledby="nb-file">
|
|
<a class="dropdown-item" href="#">Open File</a>
|
|
<a class="dropdown-item" href="#">Save File</a>
|
|
</div>
|
|
</li>
|
|
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="nb-session" role="button" data-toggle="dropdown"
|
|
aria-haspopup="true" aria-expanded="false">
|
|
Sessions
|
|
</a>
|
|
<div class="dropdown-menu" aria-labelledby="nb-session">
|
|
<a id="new-session-button" class="dropdown-item" href="#">New</a>
|
|
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#sessions-modal">View</a>
|
|
</div>
|
|
</li>
|
|
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" id="nb-help" role="button" data-toggle="dropdown"
|
|
aria-haspopup="true" aria-expanded="false">
|
|
Help
|
|
</a>
|
|
<div class="dropdown-menu" aria-labelledby="nb-help">
|
|
<a class="dropdown-item" href="https://github.com/coreemu/core">GitHub</a>
|
|
<a class="dropdown-item" href="http://coreemu.github.io/core/">Documentation</a>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
|
|
<span id="session-id" class="navbar-text p-2 mr-3">Session #</span>
|
|
<div>
|
|
<span id="node-display" class="navbar-text p-2">Create:</span>
|
|
<img id="node-select" src="static/router.svg"/>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="row col">
|
|
<div class="col-3 col-xl-2">
|
|
<div class="btn-group-vertical w-100" role="group" aria-label="Side Menu">
|
|
<button id="run-button" type="button" class="btn btn-success">Start</button>
|
|
<button id="link-button" type="button" class="btn btn-secondary" data-toggle="button">Link Mode</button>
|
|
<div class="btn-group dropright node-buttons" role="group">
|
|
<button id="menu-nodes" type="button" class="btn btn-secondary dropdown-toggle"
|
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
Nodes
|
|
</button>
|
|
<div class="dropdown-menu" aria-labelledby="menu-nodes">
|
|
<a class="dropdown-item" href="#" data-node="0" data-model="router">Router</a>
|
|
<a class="dropdown-item" href="#" data-node="0" data-model="host">Host</a>
|
|
<a class="dropdown-item" href="#" data-node="0" data-model="PC">PC</a>
|
|
<a class="dropdown-item" href="#" data-node="0" data-model="mdr">MDR</a>
|
|
</div>
|
|
</div>
|
|
<div class="btn-group dropright node-buttons" role="group">
|
|
<button id="menu-devices" type="button" class="btn btn-secondary dropdown-toggle"
|
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
Devices
|
|
</button>
|
|
<div class="dropdown-menu" aria-labelledby="menu-devices">
|
|
<a class="dropdown-item" href="#" data-node="5">Hub</a>
|
|
<a class="dropdown-item" href="#" data-node="4">Switch</a>
|
|
<a class="dropdown-item" href="#" data-node="6">WLAN</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="info-card" class="card text-white bg-dark mt-3 invisible">
|
|
<div id="info-card-header" class="card-header">Selected Title</div>
|
|
<div class="card-body p-0">
|
|
<table id="info-card-table" class="table mb-0">
|
|
<tbody>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="core-network" class="col">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% include 'sessions_modal.html' %}
|
|
{% include 'nodeedit_modal.html' %}
|
|
{% include 'linkedit_modal.html' %}
|
|
|
|
<ul id="node-context" class="list-group context d-none">
|
|
<a class="list-group-item list-group-item-action" href="#" data-option="edit">Edit Node</a>
|
|
<a class="list-group-item list-group-item-action" href="#" data-option="services">Services</a>
|
|
</ul>
|
|
|
|
<ul id="edge-context" class="list-group context d-none">
|
|
<a class="list-group-item list-group-item-action" href="#" data-option="edit">Edit Link</a>
|
|
</ul>
|
|
|
|
<script src="static/jquery-3.3.1.min.js"></script>
|
|
<script src="static/popper.min.js"></script>
|
|
<script src="static/bootstrap.min.js"></script>
|
|
<script src="static/vis.min.js"></script>
|
|
<script src="static/socket.io.js"></script>
|
|
<script src="static/coreip.js"></script>
|
|
<script src="static/corerest.js"></script>
|
|
<script src="static/corenetwork.js"></script>
|
|
|
|
<script>
|
|
const $linkButton = $('#link-button');
|
|
const $nodeButtons = $('.node-buttons a');
|
|
const $sessionId = $('#session-id');
|
|
const $nodeDisplay = $('#node-display');
|
|
const $sessionsModal = $('#sessions-modal');
|
|
const $sessionsTable = $('#sessions-table');
|
|
const $runButton = $('#run-button');
|
|
const $infoCard = $('#info-card');
|
|
const $infoCardTable = $('#info-card-table');
|
|
const $infoCardHeader = $('#info-card-header');
|
|
const $nodeSelect = $('#node-select');
|
|
const $newSessionButton = $('#new-session-button');
|
|
const $nodeContext = $('#node-context');
|
|
const $edgeContext = $('#edge-context');
|
|
const $nodeEditModal = $('#nodeedit-modal');
|
|
const $nodeEditButton = $('#nodeedit-button');
|
|
const $linkEditModal = $('#linkedit-modal');
|
|
const $linkEditButton = $('#linkedit-button');
|
|
|
|
function formToJson($form) {
|
|
const formData = {};
|
|
$form.serializeArray().map(function (x) {
|
|
let value = x.value;
|
|
if (value === '') {
|
|
value = null;
|
|
} else if (!isNaN(value)) {
|
|
value = parseInt(value);
|
|
}
|
|
formData[x.name] = value;
|
|
});
|
|
return formData;
|
|
}
|
|
|
|
// initial core setup
|
|
const coreRest = new CoreRest();
|
|
const coreNetwork = new CoreNetwork('core-network', coreRest);
|
|
coreNetwork.initialSession()
|
|
.then(function (session) {
|
|
joinSession(session);
|
|
})
|
|
.catch(function (err) {
|
|
console.log('initial session error: ', err);
|
|
});
|
|
|
|
function setRunButton(start) {
|
|
console.log('set run button: ', start);
|
|
const $runButton = $('#run-button');
|
|
$runButton.removeClass('btn-danger btn-success');
|
|
if (start) {
|
|
$runButton.text('Start');
|
|
$runButton.addClass('btn-success');
|
|
$linkButton.removeAttr('disabled');
|
|
coreNetwork.enableNodeCreation(true);
|
|
} else {
|
|
$runButton.text('Stop');
|
|
$runButton.addClass('btn-danger');
|
|
$linkButton.removeClass('active');
|
|
$linkButton.attr('disabled', 'disabled');
|
|
coreNetwork.enableNodeCreation(false);
|
|
coreNetwork.linkMode(false);
|
|
}
|
|
}
|
|
|
|
function addInfoTable(name, value) {
|
|
let $nameCell = $('<td>', {text: name});
|
|
let $valueCell = $('<td>', {text: value});
|
|
const $row = $('<tr>').append([$nameCell, $valueCell]);
|
|
$infoCardTable.find('tbody').append($row);
|
|
}
|
|
|
|
function joinSession(session) {
|
|
$sessionId.text(`Session: ${session.id}`);
|
|
const isStartEnabled = session.state !== SessionStates.runtime;
|
|
setRunButton(isStartEnabled);
|
|
}
|
|
|
|
// handle network clicks
|
|
coreNetwork.network.on('click', function (properties) {
|
|
console.log('click properties: ', properties);
|
|
$nodeContext.addClass('d-none');
|
|
$edgeContext.addClass('d-none');
|
|
|
|
$infoCard.removeClass('visible invisible');
|
|
if (properties.nodes.length === 1) {
|
|
const nodeId = properties.nodes[0];
|
|
const node = coreNetwork.getCoreNode(nodeId);
|
|
$infoCardHeader.text(node.name);
|
|
$infoCard.addClass('visible');
|
|
$infoCardTable.find('tbody tr').remove();
|
|
addInfoTable('Model', node.model);
|
|
addInfoTable('X', node.x);
|
|
addInfoTable('Y', node.y);
|
|
for (let interfaceId in node.interfaces) {
|
|
const interface = node.interfaces[interfaceId];
|
|
console.log('node interface: ', interface);
|
|
addInfoTable('Interface', `eth${interface.id}`);
|
|
if (interface.ip4) {
|
|
addInfoTable('IP4', `${interface.ip4}/${interface.ip4mask}`);
|
|
}
|
|
if (interface.ip6) {
|
|
addInfoTable('IP6', `${interface.ip6}/${interface.ip6mask}`);
|
|
}
|
|
}
|
|
} else if (properties.edges.length === 1) {
|
|
const edgeId = properties.edges[0];
|
|
const edge = coreNetwork.edges.get(edgeId);
|
|
const link = edge.link;
|
|
const nodeOne = coreNetwork.getCoreNode(link.nodeOne);
|
|
const nodeTwo = coreNetwork.getCoreNode(link.nodeTwo);
|
|
console.log('clicked edge: ', link);
|
|
$infoCard.addClass('visible');
|
|
$infoCardHeader.text('Edge');
|
|
$infoCardTable.find('tbody tr').remove();
|
|
addInfoTable(nodeOne.name, null);
|
|
const interfaceOne = link.interfaceOne;
|
|
if (interfaceOne) {
|
|
addInfoTable('Interface', `eth${interfaceOne.id}`);
|
|
if (interfaceOne.ip4) {
|
|
addInfoTable('IP4', `${interfaceOne.ip4}/${interfaceOne.ip4mask}`);
|
|
}
|
|
if (interfaceOne.ip6) {
|
|
addInfoTable('IP6', `${interfaceOne.ip6}/${interfaceOne.ip6mask}`);
|
|
}
|
|
}
|
|
addInfoTable(nodeTwo.name, null);
|
|
const interfaceTwo = link.interfaceTwo;
|
|
if (interfaceTwo) {
|
|
addInfoTable('Interface', `eth${interfaceTwo.id}`);
|
|
if (interfaceTwo.ip4) {
|
|
addInfoTable('IP4', `${interfaceTwo.ip4}/${interfaceTwo.ip4mask}`);
|
|
}
|
|
if (interfaceTwo.ip6) {
|
|
addInfoTable('IP6', `${interfaceTwo.ip6}/${interfaceTwo.ip6mask}`);
|
|
}
|
|
}
|
|
addInfoTable('Bandwidth', edge.link.bandwidth);
|
|
addInfoTable('Delay', edge.link.delay);
|
|
addInfoTable('Duplicate', edge.link.duplicate);
|
|
addInfoTable('Loss', edge.link.loss);
|
|
addInfoTable('Jitter', edge.link.jitter);
|
|
} else {
|
|
$infoCard.addClass('invisible');
|
|
}
|
|
});
|
|
|
|
coreNetwork.network.on('oncontext', function (properties) {
|
|
console.log('context event: ', properties);
|
|
properties.event.preventDefault();
|
|
$nodeContext.addClass('d-none');
|
|
$edgeContext.addClass('d-none');
|
|
|
|
const location = properties.pointer.DOM;
|
|
const x = properties.event.pageX;
|
|
const y = properties.event.pageY;
|
|
|
|
const nodeId = coreNetwork.network.getNodeAt(location);
|
|
if (nodeId) {
|
|
const node = coreNetwork.nodes.get(nodeId);
|
|
console.log('context node: ', node);
|
|
$nodeContext.data('node', nodeId);
|
|
$nodeContext.css({
|
|
position: 'absolute',
|
|
left: x,
|
|
top: y
|
|
});
|
|
$nodeContext.removeClass('d-none');
|
|
} else {
|
|
const edgeId = coreNetwork.network.getEdgeAt(location);
|
|
if (edgeId) {
|
|
const edge = coreNetwork.edges.get(edgeId);
|
|
console.log('context edge: ', edge);
|
|
$edgeContext.data('edge', edgeId);
|
|
$edgeContext.css({
|
|
position: 'absolute',
|
|
left: x,
|
|
top: y
|
|
});
|
|
$edgeContext.removeClass('d-none');
|
|
}
|
|
}
|
|
});
|
|
|
|
$nodeContext.click(function (event) {
|
|
$nodeContext.addClass('d-none');
|
|
console.log('node context click: ', event);
|
|
const nodeId = $nodeContext.data('node');
|
|
const node = coreNetwork.nodes.get(nodeId).coreNode;
|
|
const $target = $(event.target);
|
|
const option = $target.data('option');
|
|
console.log('node context: ', nodeId, option);
|
|
if (option === 'edit') {
|
|
$nodeEditModal.data('node', nodeId);
|
|
$nodeEditModal.find('.modal-title').text(`Edit Node: ${node.name}`);
|
|
$nodeEditModal.find('#node-name').val(node.name);
|
|
$nodeEditModal.modal('show');
|
|
}
|
|
});
|
|
|
|
$nodeEditButton.click(function () {
|
|
const $form = $nodeEditModal.find('form');
|
|
const formData = formToJson($form);
|
|
console.log('node edit data: ', formData);
|
|
const nodeId = $nodeEditModal.data('node');
|
|
const node = coreNetwork.nodes.get(nodeId);
|
|
if (formData.name) {
|
|
node.label = formData.name;
|
|
node.coreNode.name = formData.name;
|
|
coreNetwork.nodes.update(node);
|
|
}
|
|
$nodeEditModal.modal('hide');
|
|
});
|
|
|
|
$edgeContext.click(function (event) {
|
|
$edgeContext.addClass('d-none');
|
|
console.log('edge context click: ', event);
|
|
const edgeId = $edgeContext.data('edge');
|
|
const edge = coreNetwork.edges.get(edgeId);
|
|
const link = edge.link;
|
|
const $target = $(event.target);
|
|
const option = $target.data('option');
|
|
console.log('edge context: ', edgeId, option);
|
|
if (option === 'edit') {
|
|
// populate form with current link data
|
|
$linkEditModal.data('link', edgeId);
|
|
$linkEditModal.find('#link-bandwidth').val(link.bandwidth);
|
|
$linkEditModal.find('#link-delay').val(link.delay);
|
|
$linkEditModal.find('#link-per').val(link.loss);
|
|
$linkEditModal.find('#link-dup').val(link.duplicate);
|
|
$linkEditModal.find('#link-jitter').val(link.jitter);
|
|
|
|
// set modal name and show
|
|
$linkEditModal.find('.modal-title').text('Edit Edge');
|
|
$linkEditModal.modal('show');
|
|
}
|
|
});
|
|
|
|
$linkEditButton.click(function () {
|
|
const $form = $linkEditModal.find('form');
|
|
const formData = {};
|
|
$form.serializeArray().map(function (x) {
|
|
let value = x.value;
|
|
if (value === '') {
|
|
value = null;
|
|
} else if (!isNaN(value)) {
|
|
value = parseInt(value);
|
|
}
|
|
formData[x.name] = value;
|
|
});
|
|
console.log('link edit data: ', formData);
|
|
const edgeId = $linkEditModal.data('link');
|
|
const edge = coreNetwork.edges.get(edgeId);
|
|
const link = edge.link;
|
|
|
|
link.bandwidth = formData.bandwidth;
|
|
link.delay = formData.delay;
|
|
link.duplicate = formData.duplicate;
|
|
link.loss = formData.loss;
|
|
link.jitter = formData.jitter;
|
|
|
|
coreRest.isRunning()
|
|
.then(function (isRunning) {
|
|
if (isRunning) {
|
|
const linkEdit = link.json();
|
|
linkEdit.interface_one = linkEdit.interface_one.id;
|
|
linkEdit.interface_two = linkEdit.interface_two.id;
|
|
return coreRest.editLink(linkEdit);
|
|
}
|
|
})
|
|
.then(function (response) {
|
|
console.log('link edit success');
|
|
})
|
|
.catch(function (err) {
|
|
console.log('error editing link: ', err);
|
|
});
|
|
|
|
$linkEditModal.modal('hide');
|
|
});
|
|
|
|
$newSessionButton.click(function () {
|
|
coreNetwork.newSession()
|
|
.then(function (session) {
|
|
joinSession(session);
|
|
})
|
|
.catch(function (err) {
|
|
console.log('error creating new session: ', err);
|
|
});
|
|
});
|
|
|
|
$sessionsTable.on('click', 'td', function (event) {
|
|
const sessionId = $(this).parent('tr').data('session');
|
|
console.log('clicked session to join: ', sessionId);
|
|
if (sessionId === coreRest.currentSession) {
|
|
console.log('same session, not changing');
|
|
} else {
|
|
coreNetwork.joinSession(sessionId)
|
|
.then(function (session) {
|
|
joinSession(session);
|
|
$sessionsModal.modal('hide');
|
|
})
|
|
.catch(function (err) {
|
|
console.log('join session error: ', err);
|
|
});
|
|
}
|
|
});
|
|
|
|
$linkButton.click(function () {
|
|
const linkMode = !$(this).hasClass('active');
|
|
coreNetwork.linkMode(linkMode);
|
|
$(this).blur();
|
|
});
|
|
|
|
$runButton.click(function () {
|
|
const $this = $(this);
|
|
const start = $this.text() === 'Start';
|
|
if (start) {
|
|
coreNetwork.start()
|
|
.then(function () {
|
|
setRunButton(false);
|
|
})
|
|
.catch(function (err) {
|
|
console.log('start error: ', err);
|
|
});
|
|
} else {
|
|
coreRest.shutdownSession()
|
|
.then(function (response) {
|
|
console.log('shutdown session: ', response);
|
|
setRunButton(true);
|
|
})
|
|
.catch(function (err) {
|
|
console.log('shutdown error: ', err);
|
|
});
|
|
}
|
|
});
|
|
|
|
$nodeButtons.click(function () {
|
|
const $this = $(this);
|
|
const nodeType = $this.data('node');
|
|
const model = $this.data('model');
|
|
console.log('node creation: ', nodeType, model);
|
|
console.log('clicked: ', this);
|
|
coreNetwork.setNodeMode(nodeType, model);
|
|
const currentType = CoreNodeHelper.getDisplay(coreNetwork.nodeType);
|
|
const defaultType = CoreNodeHelper.getDisplay(CoreNodeHelper.defaultNode);
|
|
let nodeName = currentType.name;
|
|
if (currentType.display === defaultType.display) {
|
|
nodeName = coreNetwork.nodeModel;
|
|
}
|
|
const icon = CoreNodeHelper.icons[nodeName];
|
|
$nodeSelect.attr('src', icon);
|
|
});
|
|
|
|
// show sessions
|
|
$sessionsModal.on('shown.bs.modal', function () {
|
|
console.log('show sessions');
|
|
$sessionsTable.find('tbody tr').remove();
|
|
coreRest.getSessions()
|
|
.then(function (response) {
|
|
const sessions = response.sessions;
|
|
for (let session of sessions) {
|
|
console.log('show sessions: ', session);
|
|
const $idCell = $('<td>', {text: session.id});
|
|
const $nodeCell = $('<td>', {text: session.nodes});
|
|
const stateName = coreRest.getStateName(session.state);
|
|
const $stateCell = $('<td>', {text: stateName});
|
|
const $row = $('<tr>', {class: 'session-join', 'data-session': session.id});
|
|
$row.append([$idCell, $nodeCell, $stateCell]);
|
|
$sessionsTable.find('tbody').append($row);
|
|
}
|
|
})
|
|
.catch(function (err) {
|
|
console.log('error getting sessions: ', err);
|
|
});
|
|
});
|
|
|
|
console.log('connecting to ws');
|
|
const ws = io.connect();
|
|
ws.on('connection', function () {
|
|
console.log('connected!');
|
|
});
|
|
ws.on('error', function (error) {
|
|
console.log(error);
|
|
});
|
|
|
|
ws.on('info', function (data) {
|
|
console.log(data.message);
|
|
});
|
|
|
|
ws.on('node', function (data) {
|
|
console.log(data);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|