mirror of
https://github.com/Telecominfraproject/wlan-cloud-loadsim.git
synced 2026-01-09 05:21:39 +00:00
Fixing API
This commit is contained in:
@@ -13,26 +13,6 @@
|
||||
|
||||
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% auxiliary types
|
||||
|
||||
-record (version_matrix_map, {
|
||||
'DATE' = <<"Mon Nov 2 09">> :: term(),
|
||||
'FIRMWARE' = <<"0.1.0-0-notgit-development">> :: term(),
|
||||
'FW_BUILD' = <<"0">> :: term(),
|
||||
'FW_COMMIT' = <<"notgit">> :: term(),
|
||||
'FW_IMAGE_ACTIVE' = <<"ea8300-2020-11-02-pending-97ebe9d">> :: term(),
|
||||
'FW_IMAGE_INACTIVE' = <<"unknown">> :: term(),
|
||||
'FW_PROFILE' = <<"development">> :: term(),
|
||||
'FW_VERSION' = <<"0.1.0">> :: term(),
|
||||
'HOST' = <<"runner@72477083da86">> :: term(),
|
||||
'OPENSYNC' = <<"2.0.5.0">> :: term(),
|
||||
'core' = <<"2.0.5.0/0/notgit">> :: term(),
|
||||
'vendor/tip' = <<"0.1.0/0/notgit">> :: term()
|
||||
}).
|
||||
|
||||
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% the tables
|
||||
|
||||
|
||||
447
priv/www/demo.html
Normal file
447
priv/www/demo.html
Normal file
@@ -0,0 +1,447 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="icon" href="assets/favicon.ico" type="image/x-icon" />
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>OWLS</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
|
||||
|
||||
<style>
|
||||
html, body, #app {
|
||||
height: 100%;
|
||||
}
|
||||
#app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.controls {
|
||||
background: #e9ecef;
|
||||
}
|
||||
.actions {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(96px, 144px);
|
||||
grid-gap: 0.5rem;
|
||||
}
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 40% 60%;
|
||||
grid-gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
.output {
|
||||
background: var(--bs-light);
|
||||
white-space: pre;
|
||||
max-width: 100%;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="controls d-flex p-3">
|
||||
|
||||
<div class="col p-3">
|
||||
<h1 class="h3">^(OvO)^ OWLS</h1>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="loadCas()">Import CA</button>
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="newSimulation()">Create Simulation</button>
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="sendAction('prepare')">Prepare Assets</button>
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="sendAction('push')">Push Simulation</button>
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="sendAction('start')">Start Simulation</button>
|
||||
<button class="btn btn-sm btn-secondary"
|
||||
v-on:click="sendAction('stop')">Stop Simulation</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
|
||||
<h2 class="h5">API</h2>
|
||||
|
||||
<fieldset class="form-grid p-3">
|
||||
|
||||
<label class="form-label" for="apiBase">API base</label>
|
||||
<div class="d-flex">
|
||||
<input type="text" name="apiBase" v-model="apiBase" class="form-control form-control-sm w-75" />
|
||||
<button class="btn btn-sm btn-secondary w-25" v-on:click="setup()">Set</button>
|
||||
</div>
|
||||
|
||||
<label class="form-label">Current Simulation</label>
|
||||
<div><select class="form-select form-select-sm" v-model="simulation" v-on:change="selectSimulation()">
|
||||
<option value=""></option>
|
||||
<option v-for="(simulation, index) in simulations" :key="index" v-bind:value="simulation">{{ simulation }}</option>
|
||||
</select></div>
|
||||
|
||||
</fieldset>
|
||||
<fieldset class="form-grid border border-secondary p-3">
|
||||
|
||||
<label class="form-label">Name</label>
|
||||
<div><input type="text" class="form-control form-control-sm" v-model="form.name"/></div>
|
||||
|
||||
<label class="form-label">CA</label>
|
||||
<div><select class="form-select form-select-sm" v-model="form.caname"><option v-for="(ca, index) in cas" :key="index" v-bind:value="ca">{{ ca }}</option></select></div>
|
||||
|
||||
<label class="form-label">Number of Devices</label>
|
||||
<div><input type="number" class="form-control form-control-sm" v-model="form.num_devices" /></div>
|
||||
|
||||
<label class="form-label">Server Name</label>
|
||||
<div><input type="text" class="form-control form-control-sm" v-model="form.server"/></div>
|
||||
|
||||
<label class="form-label">Port</label>
|
||||
<div><input type="number" class="form-control form-control-sm" v-model="form.port" /></div>
|
||||
|
||||
<button class="btn btn-secondary btn-sm" v-on:click="saveSimulation()">Save</button>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col p-3">
|
||||
|
||||
<p>Nodes</p>
|
||||
<ul>
|
||||
<li v-for="(node, index) in nodes">{{ node }}</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="p-3">
|
||||
|
||||
<div id="charts"></div>
|
||||
|
||||
<h2 class="h3">Output</h2>
|
||||
<div class="output">
|
||||
<code v-for="(msg, index) in output" :key="index">{{ msg }}</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!--
|
||||
start of scripts
|
||||
-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha256-t9UJPrESBeG2ojKTIcFLPGF7nHi2vEc7f5A2KpH/UBU=" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/vue@3.0.4/dist/vue.global.js"></script>
|
||||
<!-- temporary stats for stream testing -->
|
||||
<script src="_tmp-stats.js"></script>
|
||||
<script>
|
||||
const App = {
|
||||
data() {
|
||||
return {
|
||||
apiBase: 'http://localhost:9090',
|
||||
apiPrefix: '/api/v1',
|
||||
output: [],
|
||||
socket: null,
|
||||
socketOpen: false,
|
||||
wss: 'ws://localhost:9090/ws',
|
||||
msg: 'Hello World',
|
||||
nodes: null,
|
||||
cas: [],
|
||||
simulations: [],
|
||||
simulationNew: false,
|
||||
simulation: null,
|
||||
form: {
|
||||
name: null,
|
||||
caname: null,
|
||||
num_devices: null,
|
||||
server: null,
|
||||
port: null,
|
||||
nodes: null,
|
||||
},
|
||||
// stream suff
|
||||
nodesDict: {},
|
||||
nodesData: [],
|
||||
charts: [],
|
||||
streamInterval: null,
|
||||
streamIntervalTime: 250,
|
||||
streamTimeSince: 0,
|
||||
streamOn: false,
|
||||
streamIndex: 0,
|
||||
}
|
||||
},
|
||||
created: function() {
|
||||
console.log('App loaded');
|
||||
|
||||
// default to server url
|
||||
if( window.location.protocol !== 'file:' )
|
||||
this.apiBase = `${window.location.protocol}//${window.location.host}`;
|
||||
|
||||
this.nodes = new Set();
|
||||
|
||||
this.setup();
|
||||
|
||||
},
|
||||
methods: {
|
||||
|
||||
setup: function() {
|
||||
this.loadCas();
|
||||
this.loadNodes();
|
||||
this.getSimulations();
|
||||
},
|
||||
|
||||
setupWebsocket: function() {
|
||||
if( !this.wss ) {
|
||||
console.log('Missing websocket URL');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('Starting websocket...');
|
||||
this.socket = new WebSocket(this.wss);
|
||||
|
||||
this.socket.onmessage = (event) => {
|
||||
console.log(event);
|
||||
// try to pull data into a basic chart
|
||||
if( event.data && event.data.value ) {
|
||||
this.testLogKernel( event.data );
|
||||
} else {
|
||||
this.output.push(JSON.parse(event.data));
|
||||
}
|
||||
}
|
||||
|
||||
this.socket.onopen = (event) => {
|
||||
console.log(event);
|
||||
this.output.push('Websocket opened');
|
||||
this.socketOpen = true;
|
||||
}
|
||||
|
||||
this.socket.onclose = (event) => {
|
||||
this.output.push('Websocket closed');
|
||||
this.socketOpen = false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
closeWebsocket: function() {
|
||||
if( this.socket )
|
||||
this.socket.close();
|
||||
},
|
||||
|
||||
// send a msg through the socket...
|
||||
send: function() {
|
||||
console.log(`Sending message '${this.msg}'...`);
|
||||
// should check if socket is good before
|
||||
this.socket.send(this.msg)
|
||||
},
|
||||
|
||||
loadCas: function() {
|
||||
const location = `${this.apiBase}${this.apiPrefix}/cas`;
|
||||
fetch( location )
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if( data.Data && data.Data.CAs ) {
|
||||
this.cas = data.Data.CAs;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
loadNodes: function() {
|
||||
|
||||
},
|
||||
|
||||
getSimulations: function() {
|
||||
const location = `${this.apiBase}${this.apiPrefix}/simulations`;
|
||||
fetch( location )
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
this.simulations = data.Data.Simulations;
|
||||
this.simulation = this.simulations[0];
|
||||
this.selectSimulation();
|
||||
});
|
||||
},
|
||||
|
||||
// clear form for empty mode
|
||||
newSimulation() {
|
||||
this.simulation = '';
|
||||
this.simulationNew = true;
|
||||
Object.keys(this.form).forEach((k) => {
|
||||
this.form[k] = null;
|
||||
});
|
||||
},
|
||||
|
||||
selectSimulation() {
|
||||
const sim = this.simulation;
|
||||
// if user selects empty, it's a "new" sim
|
||||
if( !sim ) {
|
||||
this.newSimulation();
|
||||
}
|
||||
const location = this.apiBase + this.apiPrefix + `/simulations/${sim}`;
|
||||
fetch( location )
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
if( data && data.name ) {
|
||||
this.simulationNew = false;
|
||||
let keys = Object.keys(this.form);
|
||||
keys.forEach( (k) => {
|
||||
console.log(data[k])
|
||||
if( data[k] !== undefined )
|
||||
this.form[k] = data[k];
|
||||
});
|
||||
// rudimentary way to load nodes (/nodes empty)
|
||||
if(data.nodes) {
|
||||
data.nodes.forEach( n => {
|
||||
this.nodes.add(n);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
saveSimulation: function() {
|
||||
let id = this.simulation ? this.simulation : this.form.name;
|
||||
if( !id ) {
|
||||
console.log('Missing simulation name');
|
||||
return;
|
||||
}
|
||||
// [temp] take first node if possible...
|
||||
if( !this.form.nodes ) {
|
||||
this.form.nodes = [this.nodes[0]];
|
||||
}
|
||||
this.apiPost( `/simulations/${id}`, this.form )
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
if( response.name ) {
|
||||
if(this.simulationNew) {
|
||||
this.simulationNew = false;
|
||||
this.simulations.append(response.name);
|
||||
this.simulation = response.name;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// prepare assets
|
||||
sendAction: function( action ) {
|
||||
// action requires sim to be created
|
||||
if( !this.simulation ) {
|
||||
console.log('Must select a simulation');
|
||||
return;
|
||||
}
|
||||
// allowed actions
|
||||
const actions = [ 'prepare', 'push', 'start', 'stop' ];
|
||||
if( !actions.includes(action) ) {
|
||||
console.log(`Invalid action ${action}`);
|
||||
return;
|
||||
}
|
||||
let payload = {
|
||||
"action": action,
|
||||
"simulation": this.simulation,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "stagger",
|
||||
"value": "10/2000"
|
||||
}
|
||||
]
|
||||
};
|
||||
this.apiPost(`/actions`, payload)
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
});
|
||||
},
|
||||
|
||||
apiPost: async function( path, payload ) {
|
||||
const url = `${this.apiBase}${this.apiPrefix}${path}`;
|
||||
const response = await fetch( url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify( payload )
|
||||
} );
|
||||
return response.json();
|
||||
},
|
||||
|
||||
// generic get
|
||||
apiGet: function(path) {
|
||||
const location = this.apiBase + path + "?details=1";
|
||||
fetch( location )
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
this.output = [];
|
||||
this.output.push(data);
|
||||
});
|
||||
},
|
||||
|
||||
fakeStream: function() {
|
||||
if( this.streamInterval ) {
|
||||
console.log('Stopping fake stream...');
|
||||
clearInterval( this.streamInterval );
|
||||
this.streamOn = false;
|
||||
} else {
|
||||
console.log('Starting fake stream...');
|
||||
this.streamInterval = setInterval(() => {
|
||||
if( this.streamIndex + 1 >= window.tmpStats.length ) {
|
||||
this.streamIndex = 0;
|
||||
}
|
||||
this.testLogKernel(window.tmpStats[ this.streamIndex ]);
|
||||
this.streamIndex++;
|
||||
this.streamTimeSince = this.streamIntervalTime * this.streamIndex;
|
||||
}, this.streamIntervalTime);
|
||||
this.streamOn = true;
|
||||
}
|
||||
},
|
||||
|
||||
testLogKernel: function( data ) {
|
||||
let idx = null;
|
||||
if( !data.node ) {
|
||||
return;
|
||||
}
|
||||
if( data.node in this.nodesDict ) {
|
||||
idx = this.nodesDict[data.node];
|
||||
} else {
|
||||
idx = this.nodes.length;
|
||||
this.nodesData.push([]);
|
||||
this.nodesDict[data.node] = idx;
|
||||
// canvas for chart
|
||||
const el = document.createElement('canvas');
|
||||
el.setAttribute('id', `chart-${idx}`);
|
||||
const charts = document.getElementById('charts');
|
||||
charts.appendChild(el);
|
||||
const chart = new Chart(el, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: data.node,
|
||||
data: this.nodesData[idx],
|
||||
}]
|
||||
},
|
||||
});
|
||||
this.charts.push( chart );
|
||||
}
|
||||
if( data.value && data.value.kernel_utilization ) {
|
||||
console.log(data.value.kernel_utilization);
|
||||
this.charts[idx].data.datasets[0].data.push(data.value.kernel_utilization);
|
||||
this.charts[idx].data.labels.push( this.streamTimeSince );
|
||||
this.charts[idx].update();
|
||||
} else {
|
||||
console.log('No kernel utilization');
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
computed: {
|
||||
fakeStreamLabel: function() {
|
||||
return this.streamOn ? 'Stop Fake Stream' : 'Start Fake Stream'
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Vue.createApp(App).mount('#app')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -21,7 +21,8 @@
|
||||
-define(MAKER_LOOKUP_TABLE_FILENAME,"maker_lookup_table.ets").
|
||||
|
||||
%% API
|
||||
-export([start_link/0,creation_info/0,refresh/0,refresh/2,get_all/0,lookup_oui/1,lookup_vendor/1,get_an_oui/0,get_ouis/0,get_vendors/0]).
|
||||
-export([start_link/0,creation_info/0,refresh/0,refresh/2,get_all/0,lookup_oui/1,lookup_vendor/1,
|
||||
get_an_oui/0,get_ouis/0,get_vendors/0,lookup_oui_from_mac/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
||||
@@ -64,16 +65,23 @@ get_vendors()->
|
||||
gen_server:call(?SERVER,get_vendors).
|
||||
|
||||
-spec lookup_oui(OUI:: string() | binary()) -> {ok,Vendor::binary()} | generic_error().
|
||||
lookup_oui(OUI) when is_list(OUI) ->
|
||||
gen_server:call(?SERVER,{lookup_oui,list_to_binary(OUI)});
|
||||
lookup_oui(OUI) when is_binary(OUI) ->
|
||||
gen_server:call(?SERVER,{lookup_oui,OUI}).
|
||||
lookup_oui(OUI)->
|
||||
gen_server:call(?SERVER,{lookup_oui,utils:safe_binary(OUI)}).
|
||||
|
||||
-spec lookup_oui_from_mac(OUI:: string() | binary()) -> {ok,Vendor::binary()} | generic_error().
|
||||
lookup_oui_from_mac(OUI)->
|
||||
try
|
||||
<<X1,X2,$:,X3,X4,$:,X5,X6,_/binary>> = utils:safe_binary(OUI),
|
||||
ProperOUI = list_to_binary(string:to_upper([X1,X2,X3,X4,X5,X6])),
|
||||
gen_server:call(?SERVER,{lookup_oui,ProperOUI})
|
||||
catch
|
||||
_:_ ->
|
||||
{ error, invalid_mac_address_format }
|
||||
end.
|
||||
|
||||
-spec lookup_vendor(Vendor::string() | binary() ) -> {ok,[ OUI::binary() ] } | generic_error().
|
||||
lookup_vendor(Vendor) when is_list(Vendor)->
|
||||
gen_server:call(?SERVER,{lookup_vendor,list_to_binary(Vendor)});
|
||||
lookup_vendor(Vendor) when is_binary(Vendor)->
|
||||
gen_server:call(?SERVER,{lookup_vendor,Vendor}).
|
||||
lookup_vendor(Vendor)->
|
||||
gen_server:call(?SERVER,{lookup_vendor,utils:safe_binary(Vendor)}).
|
||||
|
||||
%% @doc Spawns the server and registers the local name (unique)
|
||||
-spec(start_link() ->
|
||||
|
||||
@@ -495,12 +495,18 @@ create_table ('Wifi_Associated_Clients',APC,Store) ->
|
||||
create_table ('DHCP_leased_IP',APC,Store) ->
|
||||
NM = proplists:get_value(name,APC),
|
||||
lists:foldl( fun(MAC,N)->
|
||||
ets:insert(Store, #'DHCP_leased_IP'{
|
||||
Vendor = case oui_server:lookup_oui_from_mac(MAC) of
|
||||
{ok,X} -> X;
|
||||
_ -> <<"unknown">>
|
||||
end,
|
||||
|
||||
ets:insert(Store, #'DHCP_leased_IP'{
|
||||
'**key_id**' = utils:uuid_b(),
|
||||
'_version' = [<<"uuid">>, utils:uuid_b()],
|
||||
hostname = iolist_to_binary([proplists:get_value(name,APC),"_",integer_to_list(N)]),
|
||||
inet_addr = iolist_to_binary(["192.168.1.",integer_to_list(N+1)]),
|
||||
hwaddr = MAC,
|
||||
vendor_class = Vendor,
|
||||
device_name = iolist_to_binary([NM,".SimClient_",integer_to_list(N+1)])
|
||||
}),
|
||||
N+1
|
||||
|
||||
Reference in New Issue
Block a user