Skip to content

Commit f8a9279

Browse files
Merge branch 'move' of github.com:AndreasAakesson/uplink into uplink
2 parents aa2068e + 7b1fb3d commit f8a9279

11 files changed

Lines changed: 1075 additions & 0 deletions

File tree

lib/uplink/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
include($ENV{INCLUDEOS_PREFIX}/includeos/pre.service.cmake)
9+
10+
# Name of your project
11+
project (uplink)
12+
13+
# Name of your IncludeOS library
14+
set(LIBRARY_NAME "uplink") # => libseed.a
15+
16+
# Source files to be built into your IncludeOS library
17+
set(SOURCES
18+
transport.cpp # ...add more here
19+
ws_uplink.cpp
20+
register_plugin.cpp
21+
)
22+
23+
# Necessary includes to build your library
24+
set(LOCAL_INCLUDES
25+
# "include"
26+
)
27+
28+
# include library build script
29+
include($ENV{INCLUDEOS_PREFIX}/includeos/library.cmake)
30+
31+
32+
# INSTALLATION (OPTIONAL):
33+
34+
# If CMAKE_INSTALL_PREFIX is not set, install to source directory
35+
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
36+
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}") # $ENV{INCLUDEOS_PREFIX}/includeos
37+
endif()
38+
39+
# Where to install library
40+
install(TARGETS ${LIBRARY_NAME} DESTINATION $ENV{INCLUDEOS_PREFIX}/includeos/${ARCH}/plugins)
41+
42+
# Where to install library headers
43+
# NOTE: There is a difference between installing a list of files and a directory
44+
# set(LIBRARY_HEADERS "include/seed")
45+
# install(DIRECTORY ${LIBRARY_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

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)