diff --git a/daemon/core/coreobj.py b/daemon/core/coreobj.py index 742f0e89..f42600c3 100644 --- a/daemon/core/coreobj.py +++ b/daemon/core/coreobj.py @@ -578,6 +578,7 @@ class PyCoreNet(PyCoreObj): delay=netif.getparam("delay"), bandwidth=netif.getparam("bw"), dup=netif.getparam("duplicate"), + per=netif.getparam("loss"), jitter=netif.getparam("jitter") ) @@ -595,6 +596,7 @@ class PyCoreNet(PyCoreObj): delay=netif.getparam("delay"), bandwidth=netif.getparam("bw"), dup=netif.getparam("duplicate"), + per=netif.getparam("loss"), jitter=netif.getparam("jitter") ) netif.swapparams('_params_up') diff --git a/daemon/core/emulator/coreemu.py b/daemon/core/emulator/coreemu.py index 6712227c..fdb005c4 100644 --- a/daemon/core/emulator/coreemu.py +++ b/daemon/core/emulator/coreemu.py @@ -83,6 +83,7 @@ def link_config(network, interface, link_options, devname=None, interface_two=No if not nodeutils.is_node(network, [NodeTypes.EMANE, NodeTypes.PHYSICAL]): config["devname"] = devname + logger.info("configuring link for network(%s): %s", network.name, config) network.linkconfig(**config) diff --git a/daemon/core/netns/nodes.py b/daemon/core/netns/nodes.py index a225eb6f..1e12c425 100644 --- a/daemon/core/netns/nodes.py +++ b/daemon/core/netns/nodes.py @@ -264,6 +264,7 @@ class PtpNet(LxBrNet): delay=if1.getparam("delay"), bandwidth=if1.getparam("bw"), dup=if1.getparam("duplicate"), + per=if1.getparam("loss"), jitter=if1.getparam("jitter"), interface1_id=if1.node.getifindex(if1), interface1_mac=if1.hwaddr, @@ -291,6 +292,7 @@ class PtpNet(LxBrNet): delay=if1.getparam("delay"), bandwidth=if1.getparam("bw"), dup=if1.getparam("duplicate"), + per=if1.getparam("loss"), jitter=if1.getparam("jitter"), unidirectional=1, interface1_id=if2.node.getifindex(if2), diff --git a/webapp/app.py b/webapp/app.py index 5ca17fa1..9593b261 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -1,5 +1,4 @@ import os - from functools import wraps from threading import Lock @@ -12,7 +11,7 @@ from flask_socketio import emit from core import logger from core.emulator.coreemu import CoreEmu -from core.emulator.emudata import InterfaceData, IpPrefixes +from core.emulator.emudata import InterfaceData from core.emulator.emudata import LinkOptions from core.emulator.emudata import NodeOptions from core.enumerations import EventTypes @@ -357,9 +356,41 @@ def add_link(session_id): link_options.key = options_data.get("key") link_options.opaque = options_data.get("opaque") - link_options = LinkOptions() session.add_link(node_one, node_two, interface_one, interface_two, link_options=link_options) + return jsonify(), 201 + +@app.route("/sessions//links", methods=["PUT"]) +@synchronized +def edit_link(session_id): + session = coreemu.sessions.get(session_id) + if not session: + return jsonify(error="session does not exist"), 404 + + data = request.get_json() + + node_one = data.get("node_one") + node_two = data.get("node_two") + interface_one = data.get("interface_one") + interface_two = data.get("interface_two") + + options_data = data.get("options") + link_options = LinkOptions() + if options_data: + link_options.delay = options_data.get("delay") + link_options.bandwidth = options_data.get("bandwidth") + link_options.session = options_data.get("session") + link_options.per = options_data.get("per") + link_options.dup = options_data.get("dup") + link_options.jitter = options_data.get("jitter") + link_options.mer = options_data.get("mer") + link_options.burst = options_data.get("burst") + link_options.mburst = options_data.get("mburst") + link_options.unidirectional = options_data.get("unidirectional") + link_options.key = options_data.get("key") + link_options.opaque = options_data.get("opaque") + + session.update_link(node_one, node_two, link_options, interface_one, interface_two) return jsonify(), 201 diff --git a/webapp/static/corenetwork.js b/webapp/static/corenetwork.js index 5cbc97de..8d0acb2c 100644 --- a/webapp/static/corenetwork.js +++ b/webapp/static/corenetwork.js @@ -119,6 +119,11 @@ class CoreLink { this.nodeTwo = nodeTwo; this.interfaceOne = interfaceOne; this.interfaceTwo = interfaceTwo; + this.bandwidth = null; + this.delay = null; + this.loss = null; + this.duplicate = null; + this.jitter = null; } json() { @@ -126,7 +131,14 @@ class CoreLink { node_one: this.nodeOne, node_two: this.nodeTwo, interface_one: this.interfaceOne, - interface_two: this.interfaceTwo + interface_two: this.interfaceTwo, + options: { + bandwidth: this.bandwidth, + delay: this.delay, + per: this.loss, + dup: this.duplicate, + jitter: this.jitter + } } } } @@ -313,6 +325,11 @@ class CoreNetwork { } const link = new CoreLink(fromNode.id, toNode.id, interfaceOne, interfaceTwo); + link.bandwidth = linkData.bandwidth; + link.delay = linkData.delay; + link.duplicate = linkData.dup; + link.loss = linkData.per; + link.jitter = linkData.jitter; this.links[linkId] = link; const edge = { diff --git a/webapp/static/corerest.js b/webapp/static/corerest.js index 9e4a1b9e..2fa75ce4 100644 --- a/webapp/static/corerest.js +++ b/webapp/static/corerest.js @@ -81,6 +81,10 @@ class CoreRest { return await postJson(`/sessions/${this.currentSession}/links`, link); } + async editLink(link) { + return await putJson(`/sessions/${this.currentSession}/links`, link); + } + async getLinks(nodeId) { return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/links`) } diff --git a/webapp/templates/index.html b/webapp/templates/index.html index cd52a359..38897c77 100644 --- a/webapp/templates/index.html +++ b/webapp/templates/index.html @@ -11,7 +11,7 @@
@@ -113,12 +113,12 @@ {% include 'nodeedit_modal.html' %} {% include 'linkedit_modal.html' %} -