Setup and Initialization
Speedtest-enabled Test Agent
The Test Agent that is to be used for the Speedtest measurements must be accessible from the web client performing the Speedtest. In most cases, this means it must be accessible over the internet.
ALLOWED_ORIGINS Setting for REST API
In order for Speedtest to work, the Speedtest web page needs to be able to access the REST
API. This means we must add the hostname at which the Speedtest web page is hosted to the
ALLOWED_ORIGINS
settings. If this is not done, the web browser will deny access to the REST
API.
On your Control Center instance, open the
file /etc/netrounds/restol.conf
and add this setting:
ALLOWED_ORIGINS=https://<hostname>
where <hostname>
is the Fully Qualified Domain Name (FQDN) where the
Speedtest web page is hosted.
To learn about how the ALLOWED_ORIGINS
setting works, read this article:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
To understand the big picture regarding Cross-Origin Resource Sharing (CORS), you will find this article helpful: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Web Server Redirection from HTTPS to HTTP
Since the Speedtest feature in Paragon Active Assurance uses the unencrypted HTTP protocol
for maximum performance, it is important that any web client loading the page
uses http://
in the URL.
However, when linking to this page, or when the protocol http://
is
omitted by the user in the address bar, web browsers will default to https://
,
which will cause issues with the Speedtest page.
For this reason, the built-in Speedtest feature in Paragon Active Assurance has a rewrite
rule in the Apache config to redirect any https://
requests to
http://
for the Speedtest page.
It is recommended that you add such a rewrite rule for your custom Speedtest web page as well. See the following subsections.
Hosting the Custom Speedtest Web Page with Control Center
If you are hosting your custom Speedtest web page on the same web server as Control
Center, you can edit the file /etc/apache2/sites-available/netrounds-ssl.conf
.
Below is the rewrite rule for the built-in Speedtest page:
## Rewrite rules RewriteEngine On RewriteRule ^/[^/]+/speedtest(?:-flash|-websocket)?/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R]
So to add a similar rule for the example web page you would write:
RewriteRule ^/static/speedtest_demo/example.html$ http://%{HTTP_HOST}%{REQUEST_URI} [R]
If you upgrade Control Center to a new version, this file will be overwritten, so you will have to re-add this rule after the upgrade.
Hosting the Custom Speedtest Web Page on a Separate Web Server
If you are hosting the custom Speedtest web page on a different web server than the one where Control Center is hosted, please refer to your web server documentation on how to add a similar rewrite rule.
Including the Speedtest Library
The Speedtest library needs to be included and initialized in the HTML file. In
example.html
this is done as follows:
<script src='static/js/Speedtest.js'></script> <script src='static/js/SpeedtestLib.js'></script> <script src='static/js/script.js'></script> <script type='text/javascript'> var account = 'dev'; var apiUrl = 'https://<rest_hostname>/rest'; var workerScriptPath = 'static/js/SpeedtestWorker.js'; initSpeedtest(apiUrl, workerScriptPath, account); </script>
Explanations:
var account = 'dev'
− Short name of the account in Paragon Active Assurance.var apiUrl = 'https://<rest_hostname>/rest'
− Replace this with the URL to the Paragon Active Assurance REST API.var workerScriptPath = 'static/js/SpeedtestWorker.js'
− Path where the worker script will be accessible.
Initializing Speedtest
In the file static/js/script.js
, initSpeedtest
sets up
the callback functions, which will handle the Speedtest responses.
function initSpeedtest(apiUrl, workerScriptPath, account) { speedtest = new SpeedtestLib(apiUrl, workerScriptPath, account); speedtest.setSnapshotResponse(resultSpeed); speedtest.setResultResponse(resultDelay); speedtest.setFailureResponse(failureHandler); speedtest.setSuccessResponse(successHandler); speedtest.getServers(setServerDropdown); speedtest.getCategories(setCategoryDropdown);
The argument for each speedtest.
function should be a callback function
which handles the data sent by SpeedtestLib.
speedtest.setSnapshotResponse(resultSpeed)
− partial results for the upload/download part of the test; sent during the test runspeedtest.setResultResponse(resultDelay)
− partial results for the TCP/ICMP Ping part of the test; sent during the test runspeedtest.setFailureResponse(failureHandler)
− sending the report to Control Center failedspeedtest.setSuccessResponse(successHandler)
− sending the report to Control Center succeededspeedtest.getServers(setServerDropdown)
− list of available servers was fetchedspeedtest.getCategories(setCategoryDropdown)
− list of available Speedtest categories was fetched
For example, the setServerDropdown
callback function populates the
available servers in the user interface:
function setServerDropdown(serverList) { serverList['items'].forEach(function(server) { var option = document.createElement('option'); option.text = server['name']; var serverString = server['test_agent_id'] + ':' + server['interface'] + ' ' + server['ip'] + ' ' + server['port'] + ' ' + server['test_length'] + ' ' + server['tcp_sessions']; option.value = serverString; document.getElementById('dropdown-server').add(option); }); }
Here, serverList
is provided by SpeedtestLib.
For the other callback functions, please refer to static/js/script.js
.