Skip to content

Commit 8b8da0d

Browse files
authored
Merge pull request #1430 from AndreasAakesson/uplink
Uplink
2 parents ec089de + 18de6e0 commit 8b8da0d

13 files changed

Lines changed: 1070 additions & 2 deletions

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ if(libmana)
199199
add_subdirectory(lib/mana)
200200
endif(libmana)
201201

202+
option(libuplink "Build and install uplink" ON)
203+
if(libuplink)
204+
set(libliveupdate ON) # dependent
205+
add_subdirectory(lib/uplink)
206+
endif(libuplink)
207+
202208
option(libliveupdate "Build and install LiveUpdate" ON)
203209
if(libliveupdate)
204210
add_subdirectory(lib/LiveUpdate)

lib/uplink/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 2.8.9)
2+
3+
add_definitions(-DARCH_${ARCH})
4+
add_definitions(-DARCH="${ARCH}")
5+
6+
include_directories(${INCLUDEOS_ROOT}/api/posix)
7+
include_directories(${LIBCXX_INCLUDE_DIR})
8+
include_directories(${NEWLIB_INCLUDE_DIR})
9+
include_directories(${INCLUDEOS_ROOT}/src/include)
10+
include_directories(${INCLUDEOS_ROOT}/api)
11+
include_directories(${INCLUDEOS_ROOT}/mod/GSL/)
12+
13+
#dependencies
14+
include_directories(${INCLUDEOS_ROOT}/lib/LiveUpdate)
15+
include_directories(${INCLUDEOS_ROOT}/mod/rapidjson/include)
16+
17+
set(LIBRARY_NAME "uplink")
18+
19+
set(SOURCES
20+
transport.cpp
21+
ws_uplink.cpp
22+
register_plugin.cpp
23+
)
24+
25+
add_library(${LIBRARY_NAME} STATIC ${SOURCES})
26+
27+
install(TARGETS ${LIBRARY_NAME} DESTINATION includeos/${ARCH}/plugins)

lib/uplink/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# uplink

lib/uplink/common.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#pragma once
19+
#ifndef UPLINK_INFO_HPP
20+
#define UPLINK_INFO_HPP
21+
22+
#include <common>
23+
#define MYINFO(X,...) INFO("Uplink",X,##__VA_ARGS__)
24+
25+
#endif

lib/uplink/register_plugin.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include "ws_uplink.hpp"
19+
#include "common.hpp"
20+
#include <os>
21+
22+
namespace uplink {
23+
24+
static std::unique_ptr<WS_uplink> uplink{nullptr};
25+
26+
27+
void on_panic(const char* why){
28+
if (uplink)
29+
uplink->panic(why);
30+
}
31+
32+
33+
void setup_uplink()
34+
{
35+
MYINFO("Setting up WS uplink");
36+
37+
try {
38+
auto& en0 = net::Super_stack::get<net::IP4>(0);
39+
40+
uplink = std::make_unique<WS_uplink>(en0);
41+
42+
OS::on_panic(uplink::on_panic);
43+
44+
}catch(const std::exception& e) {
45+
MYINFO("Uplink initialization failed: %s ", e.what());
46+
MYINFO("Rebooting");
47+
OS::reboot();
48+
}
49+
}
50+
51+
} // < namespace uplink
52+
53+
#include <kernel/os.hpp>
54+
__attribute__((constructor))
55+
void register_plugin_uplink(){
56+
OS::register_plugin(uplink::setup_uplink, "Uplink");
57+
}

lib/uplink/starbase/CMakeLists.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
cmake_minimum_required(VERSION 2.8.9)
2+
3+
# IncludeOS install location
4+
if (NOT DEFINED ENV{INCLUDEOS_PREFIX})
5+
set(ENV{INCLUDEOS_PREFIX} /usr/local)
6+
endif()
7+
8+
# Use toolchain (if needed)
9+
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
10+
11+
12+
# Name of your project
13+
project (starbase)
14+
15+
# Human-readable name of your service
16+
set(SERVICE_NAME "IncludeOS Starbase")
17+
18+
# Name of your service binary
19+
set(BINARY "starbase")
20+
21+
# Source files to be linked with OS library parts to form bootable image
22+
set(SOURCES
23+
service.cpp # ...add more here
24+
)
25+
26+
#
27+
# Service CMake options
28+
# (uncomment to enable)
29+
#
30+
31+
# MISC:
32+
33+
# To add your own include paths:
34+
# set(LOCAL_INCLUDES ".")
35+
36+
# Adding memdisk (expects my.disk to exist in current dir):
37+
# set(MEMDISK ${CMAKE_SOURCE_DIR}/my.disk)
38+
39+
# DRIVERS / PLUGINS:
40+
41+
set(DRIVERS
42+
virtionet
43+
vmxnet3
44+
)
45+
46+
set(PLUGINS
47+
uplink
48+
autoconf
49+
)
50+
51+
# THIRD PARTY LIBRARIES:
52+
53+
set(LIBRARIES
54+
libliveupdate.a # path to full library
55+
)
56+
57+
58+
# include service build script
59+
include($ENV{INCLUDEOS_PREFIX}/includeos/post.service.cmake)

lib/uplink/starbase/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"net" : [["10.0.0.42", "255.255.255.0", "10.0.0.1", "10.0.0.1"]],
3+
"uplink" : {
4+
"url" : "10.0.0.1:9090",
5+
"token" : "kappa123",
6+
"reboot" : true
7+
}
8+
}

lib/uplink/starbase/service.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include <service>
19+
#include <cstdio>
20+
#include <net/inet4>
21+
22+
#include <kernel/pci_manager.hpp>
23+
#include <hw/pci_device.hpp>
24+
#include <kernel/cpuid.hpp>
25+
26+
#define MYINFO(X,...) INFO("Starbase",X,##__VA_ARGS__)
27+
28+
void Service::start(const std::string&)
29+
{
30+
MYINFO("booted");
31+
32+
// Print some useful netstats every 30 secs
33+
Timers::periodic(5s, 30s, [] (uint32_t) {
34+
auto& inet = net::Inet4::stack();
35+
MYINFO("TCP STATUS:\n%s\n", inet.tcp().status().c_str());
36+
});
37+
38+
auto detected_features = CPUID::detect_features_str();
39+
40+
MYINFO("Detected %lu CPU features:", detected_features.size());
41+
42+
for (auto f : detected_features)
43+
printf("%s %s", f, f == detected_features.back() ? "" : ", ");
44+
45+
printf("\n");
46+
}

lib/uplink/transport.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#include "transport.hpp"
19+
#include "common.hpp"
20+
21+
namespace uplink {
22+
23+
Header Header::parse(const char* data)
24+
{
25+
Expects(data != nullptr);
26+
return Header{
27+
static_cast<Transport_code>(data[0]),
28+
*(reinterpret_cast<const uint32_t*>(&data[1]))
29+
};
30+
}
31+
32+
Transport_parser::Transport_parser(Transport_complete cb)
33+
: on_complete{std::move(cb)}, on_header{nullptr}, transport_{nullptr}
34+
{
35+
Expects(on_complete != nullptr);
36+
}
37+
38+
void Transport_parser::parse(const char* data, size_t len)
39+
{
40+
if(transport_ != nullptr)
41+
{
42+
transport_->load_cargo(data, len);
43+
}
44+
else
45+
{
46+
transport_ = std::make_unique<Transport>(Header::parse(data));
47+
48+
if(on_header)
49+
on_header(transport_->header());
50+
51+
len -= sizeof(Header);
52+
53+
transport_->load_cargo(data + sizeof(Header), len);
54+
}
55+
56+
if(transport_->is_complete())
57+
on_complete(std::move(transport_));
58+
}
59+
60+
}
61+

0 commit comments

Comments
 (0)