Skip to content

Commit aeb92fb

Browse files
authored
Merge pull request #1459 from fwsGonzo/dev
New auto-configuration scheme
2 parents e53ff22 + 24dc06e commit aeb92fb

21 files changed

Lines changed: 213 additions & 207 deletions

File tree

examples/LiveUpdate/config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"net" : [
3-
["10.0.0.42", "255.255.255.0", "10.0.0.1"]
3+
{
4+
"iface": 0,
5+
"config": "dhcp-with-fallback",
6+
"address": "10.0.0.42",
7+
"netmask": "255.255.255.0",
8+
"gateway": "10.0.0.1"
9+
}
410
]
511
}

examples/STREAM/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
### STREAM: Sustainable Memory Bandwidth in High Performance Computers
22

3+
Using Qemu and the IncludeOS boot program:
34
```
4-
mkdir build
5-
cd build
6-
cmake ..
7-
make
8-
../run.sh stream_example
5+
boot .
96
```
107

118
Output should show estimated memory bandwidth inside virtual machine.

examples/STREAM/vm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"mem" : 1024
2+
"mem" : 256
33
}

examples/acorn/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"net" : [
3+
{
4+
"iface": 0,
5+
"config": "dhcp-with-fallback",
6+
"address": "10.0.0.42",
7+
"netmask": "255.255.255.0",
8+
"gateway": "10.0.0.1"
9+
}
10+
]
11+
}

examples/acorn/disk1/public/app/js/services/cpusage.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
angular.module('acornWebApp')
44
.factory('CPUsage', function() {
55
// CPU usage chart
6-
var date = new Date();
7-
var total_data = ['total'];
6+
var time_data = ['x', new Date()];
7+
var idle_data = ['idle'];
88
var active_data = ['active'];
9-
var time_data = ['x', date];
109

1110
var cpu_usage_chart = {};
1211

@@ -21,17 +20,19 @@ angular.module('acornWebApp')
2120
x: 'x',
2221
columns: [
2322
time_data,
24-
total_data,
23+
idle_data,
2524
active_data
2625
],
2726
colors: {
28-
total: '#3A8BF1',
27+
idle: '#3A8BF1',
2928
active: '#F87E0C'
3029
},
3130
types: {
32-
total: 'area-spline',
33-
active: 'area-spline'
34-
// 'line', 'spline', 'step', 'area', 'area-step' are also available to stack
31+
idle: 'area',
32+
active: 'area'
33+
},
34+
area : {
35+
zerobased: true
3536
}
3637
},
3738
axis: {
@@ -50,12 +51,12 @@ angular.module('acornWebApp')
5051
},
5152
y: {
5253
label: {
53-
text: 'cycles',
54+
text: 'percent',
5455
position: 'outer-middle'
5556
},
5657
tick: {
5758
format: function (d) {
58-
return d + " mill.";
59+
return d + " %";
5960
}
6061
}
6162
}
@@ -68,35 +69,23 @@ angular.module('acornWebApp')
6869
};
6970

7071
CPUsage.prototype.update = function(usage) {
71-
// Showing interval in number of seconds
72-
var interval = usage.interval / 1000000;
7372

74-
if(total_data.length > 20) {
73+
if(idle_data.length > 20) {
7574
// Remove second element in each array (first element is name)
76-
total_data.splice(1, 1);
77-
active_data.splice(1, 1);
7875
time_data.splice(1, 1);
76+
idle_data.splice(1, 1);
77+
active_data.splice(1, 1);
7978
}
8079

81-
var total = usage.total;
82-
var halt = usage.halt;
83-
var active = total - halt;
84-
85-
// Showing cycles in millions
86-
total /= 1000000;
87-
active /= 1000000;
88-
89-
var d = new Date();
90-
91-
total_data.push(total.toFixed(3));
92-
active_data.push(active.toFixed(3));
93-
time_data.push(d);
80+
time_data.push(new Date());
81+
idle_data.push(usage.idle.toFixed(3));
82+
active_data.push(usage.active.toFixed(3));
9483

95-
cpu_usage_chart.axis.labels({x: 'CPU data updated at an interval of ' + interval + ((interval > 1) ? ' seconds' : ' second')});
84+
cpu_usage_chart.axis.labels({x: 'CPU usage over time'});
9685
cpu_usage_chart.load({
9786
columns: [
9887
time_data,
99-
total_data,
88+
idle_data,
10089
active_data
10190
]
10291
});

examples/acorn/service.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Disk_ptr disk;
3636
#include <isotime>
3737
#include <net/inet4>
3838

39-
void Service::start()
39+
static void start_acorn(net::Inet<net::IP4>& inet)
4040
{
4141
/** SETUP LOGGER */
4242
const int LOGBUFFER_LEN = 1024*16;
@@ -45,7 +45,8 @@ void Service::start()
4545
logger_->flush();
4646
logger_->log("LUL\n");
4747

48-
OS::add_stdout([] (const char* data, size_t len) {
48+
OS::add_stdout(
49+
[] (const char* data, size_t len) {
4950
// append timestamp
5051
auto entry = "[" + isotime::now() + "]" + std::string{data, len};
5152
logger_->log(entry);
@@ -55,28 +56,10 @@ void Service::start()
5556

5657
// init the first legit partition/filesystem
5758
disk->init_fs(
58-
[] (fs::error_t err, auto& fs)
59+
[&inet] (fs::error_t err, auto& fs)
5960
{
6061
if (err) panic("Could not mount filesystem...\n");
6162

62-
/** IP STACK SETUP **/
63-
// Bring up IPv4 stack on network interface 0
64-
auto& stack = net::Inet4::ifconfig(5.0,
65-
[] (bool timeout) {
66-
printf("DHCP resolution %s\n", timeout ? "failed" : "succeeded");
67-
if (timeout)
68-
{
69-
/**
70-
* Default Manual config. Can only be done after timeout to work
71-
* with DHCP offers going to unicast IP (e.g. in GCE)
72-
**/
73-
net::Inet4::stack().network_config({ 10,0,0,42 }, // IP
74-
{ 255,255,255,0 }, // Netmask
75-
{ 10,0,0,1 }, // Gateway
76-
{ 8,8,8,8 }); // DNS
77-
}
78-
});
79-
8063
// only works with synchronous disks (memdisk)
8164
list_static_content(disk);
8265

@@ -125,8 +108,8 @@ void Service::start()
125108
dashboard_->add(dashboard::Status::instance());
126109
// Construct component
127110
dashboard_->construct<dashboard::Statman>(Statman::get());
128-
dashboard_->construct<dashboard::TCP>(stack.tcp());
129-
dashboard_->construct<dashboard::CPUsage>(500ms);
111+
dashboard_->construct<dashboard::TCP>(inet.tcp());
112+
dashboard_->construct<dashboard::CPUsage>();
130113
dashboard_->construct<dashboard::Logger>(*logger_, static_cast<size_t>(50));
131114

132115
// Add Dashboard routes to "/api/dashboard"
@@ -154,7 +137,7 @@ void Service::start()
154137

155138

156139
/** SERVER SETUP **/
157-
server_ = std::make_unique<Server>(stack.tcp());
140+
server_ = std::make_unique<Server>(inet.tcp());
158141
// set routes and start listening
159142
server_->set_routes(router).listen(80);
160143

@@ -178,3 +161,15 @@ void Service::start()
178161
}); // < disk
179162

180163
}
164+
165+
void Service::start()
166+
{
167+
auto& inet = net::Super_stack::get<net::IP4>(0);
168+
if (not inet.is_configured())
169+
{
170+
inet.on_config(start_acorn);
171+
}
172+
else {
173+
start_acorn(inet);
174+
}
175+
}

examples/demo_service/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (NOT DEFINED ENV{INCLUDEOS_PREFIX})
55
set(ENV{INCLUDEOS_PREFIX} /usr/local)
66
endif()
77
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
8-
98
project (demo_service)
109

1110
# Human-readable name of your service
@@ -19,19 +18,9 @@ set(SOURCES
1918
service.cpp # ...add more here
2019
)
2120

22-
#
23-
# Service CMake options
24-
# (uncomment to enable)
25-
#
26-
27-
# MISC:
28-
2921
# To add your own include paths:
3022
# set(LOCAL_INCLUDES ".")
3123

32-
# Adding memdisk (expects my.disk to exist in current dir):
33-
# set(MEMDISK ${CMAKE_SOURCE_DIR}/my.disk)
34-
3524
# DRIVERS / PLUGINS:
3625

3726
if ("$ENV{PLATFORM}" STREQUAL "x86_solo5")
@@ -47,10 +36,9 @@ else()
4736
endif()
4837

4938
set(PLUGINS
50-
# syslogd # Syslog over UDP
39+
autoconf # configuration from config.json
5140
# ...others
5241
)
5342

54-
5543
# include service build script
5644
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)

examples/demo_service/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
### IncludeOS Demo Service
22

3+
To start, using boot:
34
```
4-
mkdir build
5-
cd build
6-
cmake ..
7-
make
8-
../run.sh IncludeOS_example
5+
boot .
96
```
107

118
This demo-service should start an instance of IncludeOS that brings up a minimal web service on port 80 with static content.
9+
10+
The default static IP is 10.0.0.42, unless running on a network with DHCP.

examples/demo_service/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"net" : [
3+
{
4+
"iface": 0,
5+
"config": "dhcp-with-fallback",
6+
"address": "10.0.0.42",
7+
"netmask": "255.255.255.0",
8+
"gateway": "10.0.0.1"
9+
}
10+
]
11+
}

examples/demo_service/service.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,12 @@ http::Response handle_request(const http::Request& req)
7979
return res;
8080
}
8181

82-
void Service::start(const std::string&)
82+
void Service::start()
8383
{
84-
// DHCP on interface 0
85-
printf("*** Waiting up to 10 sec. for DHCP... ***\n");
86-
auto& inet = net::Inet4::ifconfig(5.0, [](bool timeout) {
87-
if (timeout) {
88-
printf("*** Falling back to static network config ***\n");
89-
// static IP in case DHCP fails
90-
net::Inet4::stack().network_config(
91-
{ 10,0,0,42 }, // IP
92-
{ 255,255,255,0 }, // Netmask
93-
{ 10,0,0,1 }, // Gateway
94-
{ 10,0,0,1 }); // DNS
95-
}
96-
});
84+
// Get the first IP stack
85+
// It should have configuration from config.json
86+
auto& inet = net::Super_stack::get<net::IP4>(0);
87+
9788
// Print some useful netstats every 30 secs
9889
Timers::periodic(5s, 30s,
9990
[&inet] (uint32_t) {

0 commit comments

Comments
 (0)