Skip to content

Commit

Permalink
Add rumprun demo apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-mcleod committed Jul 4, 2017
1 parent 87fa72d commit cd17c31
Show file tree
Hide file tree
Showing 35 changed files with 1,950 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Kconfig
Expand Up @@ -24,6 +24,7 @@ menu "Libraries"
source "libs/libsel4muslcsys/Kconfig"
source "libs/libsel4muslccamkes/Kconfig"
source "libs/libsel4platsupport/Kconfig"
source "libs/libsel4allocman/Kconfig"
source "libs/libsel4utils/Kconfig"
source "libs/libcpio/Kconfig"
source "libs/libelf/Kconfig"
Expand All @@ -37,6 +38,7 @@ menu "Libraries"
source "libs/libsel4simple/Kconfig"
source "libs/libsel4simple-default/Kconfig"
source "libs/libsel4bga/Kconfig"
source "libs/rumprun/Kconfig"
endmenu

menu "Applications"
Expand Down Expand Up @@ -95,6 +97,9 @@ menu "Applications"
source "apps/pit/Kconfig"
source "apps/testsyscalls/Kconfig"
source "apps/alignment/Kconfig"
source "apps/rumprun_pthreads/Kconfig"
source "apps/rumprun_hello/Kconfig"
source "apps/rumprun_ethernet/Kconfig"
endmenu

source "tools/camkes/Kconfig"
Expand Down
16 changes: 16 additions & 0 deletions apps/rumprun_ethernet/Kbuild
@@ -0,0 +1,16 @@
#
# Copyright 2017, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#



apps-$(CONFIG_APP_RUMPRUN_ETHERNET) += rumprun_ethernet
rumprun_ethernet: rumprun libsel4muslccamkes libsel4camkes
19 changes: 19 additions & 0 deletions apps/rumprun_ethernet/Kconfig
@@ -0,0 +1,19 @@
#
# Copyright 2017, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#



config APP_RUMPRUN_ETHERNET
bool "rumprun ethernet CAmkES application"
default n
help
A simple rumprun app that reverses strings over a TCP connection
32 changes: 32 additions & 0 deletions apps/rumprun_ethernet/Makefile
@@ -0,0 +1,32 @@
#
# Copyright 2017, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#

TARGETS := $(notdir ${SOURCE_DIR}).cdl
ADL := rumprun_ethernet.camkes
TEMPLATES += ../../projects/global-components/templates

PROJECT_BASE := $(PWD)
RUMPRUN_BASE_DIR := $(PWD)/libs/rumprun


all: default

include TimeServer/TimeServer.mk
include SerialServer/SerialServer.mk
include PCIConfigIO/PCIConfigIO.mk

include ${SOURCE_DIR}/components/rump_ether/rump_ether.mk
include ${SOURCE_DIR}/components/reverse_string/server.mk



include ${PWD}/tools/camkes/camkes.mk
14 changes: 14 additions & 0 deletions apps/rumprun_ethernet/README
@@ -0,0 +1,14 @@
<!--
Copyright 2017, Data61
Commonwealth Scientific and Industrial Research Organisation (CSIRO)
ABN 41 687 119 230.

This software may be distributed and modified according to the terms of
the BSD 2-Clause license. Note that NO WARRANTY is provided.
See "LICENSE_BSD2.txt" for details.

@TAG(DATA61_BSD)
-->

This application demonstrates a simple TCP echo program that runs in a
rumprun unikernel instance on CAmkES on seL4.
39 changes: 39 additions & 0 deletions apps/rumprun_ethernet/components/reverse_string/server.c
@@ -0,0 +1,39 @@
/*
* Copyright 2017, Data61
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
* ABN 41 687 119 230.
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(DATA61_BSD)
*/

#include <camkes.h>
#include <buffer.h>
#include <string.h>
#include <stdio.h>

int run(void) {

char *buffer_str = (char*)buffer;
while(true) {
/* Wait for event */
ev_wait();
printf("Got string: %s\n", buffer_str);

int len = strnlen(buffer_str, REVERSE_STRING_MAX_LEN);
for (int i = 0; i < len / 2; ++i) {
int swap_idx = len - i - 1;
char tmp = buffer_str[i];
buffer_str[i] = buffer_str[swap_idx];
buffer_str[swap_idx] = tmp;
}

/* Signal to client that we are finished */
ev1_emit();
}

return 0;
}
22 changes: 22 additions & 0 deletions apps/rumprun_ethernet/components/reverse_string/server.camkes
@@ -0,0 +1,22 @@

/*
* Copyright 2017, Data61
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
* ABN 41 687 119 230.
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(DATA61_BSD)
*/

#include <buffer.h>

component Server {
control;
dataport Buf(REVERSE_STRING_BUFSIZE) buffer;
consumes SomethingHappenedEvent ev;
emits SomethingHappenedEvent ev1;

}
19 changes: 19 additions & 0 deletions apps/rumprun_ethernet/components/reverse_string/server.mk
@@ -0,0 +1,19 @@
#
# Copyright 2017, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#

CURRENT_DIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))


Server_CFILES := ${CURRENT_DIR}/server.c
Server_HFILES := $(patsubst ${SOURCE_DIR}/%,%,$(wildcard ${SOURCE_DIR}/include/*.h))

CAMKES_FLAGS += --cpp-flag=-I${SOURCE_DIR}/include
26 changes: 26 additions & 0 deletions apps/rumprun_ethernet/components/rump_ether/rump_ether.camkes
@@ -0,0 +1,26 @@
/*
* Copyright 2017, Data61
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
* ABN 41 687 119 230.
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(DATA61_BSD)
*/

#include <rumprun_camkes.h>
#include <buffer.h>

import <rumprun.camkes>;

component rumprun_ether {
RUMPRUN_COMPONENT_DEFINITION()
uses PCIConfig pci_config;
consumes IRQ eth_irq;
dataport Buf(REVERSE_STRING_BUFSIZE) camkes_buffer;
emits SomethingHappenedEvent camkes_ev;
consumes SomethingHappenedEvent camkes_ev1;

}
26 changes: 26 additions & 0 deletions apps/rumprun_ethernet/components/rump_ether/rump_ether.mk
@@ -0,0 +1,26 @@
#
# Copyright 2017, Data61
# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
# ABN 41 687 119 230.
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(DATA61_BSD)
#

CURRENT_DIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST})))

include ${RUMPRUN_BASE_DIR}/platform/sel4/rumprunlibs.mk

cfiles := $(wildcard ${CURRENT_DIR}/tcp_server.c)
CAMKES_FLAGS += --cpp-flag=-I${RUMPRUN_BASE_DIR}/platform/sel4/camkes/


rumprun_ether_rumpbin := hello

hello: $(cfiles)
echo ${CURRENT_DIR}
$(RUMPRUN_CC) -I${CURRENT_DIR}/../../include $^ -o $@ -lpthread

112 changes: 112 additions & 0 deletions apps/rumprun_ethernet/components/rump_ether/tcp_server.c
@@ -0,0 +1,112 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 Mathias Buus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/* Modifications made by Data61 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <buffer.h>

#define on_error(...) { fprintf(stderr, __VA_ARGS__); fflush(stderr); exit(1); }


/* XXX: CAmkES symbols that are linked in after this file is compiled.
They need to be marked as weak and this is the current hacky way it is done */
extern void *camkes_buffer;
void camkes_ev_emit(void);
void camkes_ev1_wait(void);
#pragma weak camkes_buffer
#pragma weak camkes_ev_emit
#pragma weak camkes_ev1_wait


int main (int argc, char *argv[]) {
if (argc < 2) on_error("Usage: %s [port]\n", argv[0]);

char *buffer_str = (char*)camkes_buffer;

snprintf(buffer_str, REVERSE_STRING_MAX_LEN, "Hello, World!");

printf("Sending string: %s\n", buffer_str);

/* Signal the string reverse server and wait for response */
camkes_ev_emit();
camkes_ev1_wait();

printf("%s\n", buffer_str);


int port = atoi(argv[1]);

int server_fd, client_fd, err;
struct sockaddr_in server, client;
char buf[REVERSE_STRING_BUFSIZE];

server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd < 0) on_error("Could not create socket\n");

server.sin_family = AF_INET;
server.sin_port = htons(port);
server.sin_addr.s_addr = htonl(INADDR_ANY);

int opt_val = 1;
setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt_val, sizeof opt_val);

err = bind(server_fd, (struct sockaddr *) &server, sizeof(server));
if (err < 0) on_error("Could not bind socket\n");

err = listen(server_fd, 128);
if (err < 0) on_error("Could not listen on socket\n");

printf("Server is listening on %d\n", port);

/* In a loop we wait for connections from clients */
while (1) {
socklen_t client_len = sizeof(client);
client_fd = accept(server_fd, (struct sockaddr *) &client, &client_len);

if (client_fd < 0) on_error("Could not establish new connection\n");

/* In a loop we wait for messages from the client, reverse the string
and then respond to the client */
while (1) {
int read = recv(client_fd, buf, REVERSE_STRING_BUFSIZE, 0);
if (!read) break; // done reading
if (read < 0) on_error("Client read failed\n");
buf[read] = 0;
snprintf(buffer_str, read +1, buf);
camkes_ev_emit();
camkes_ev1_wait();

err = send(client_fd, buffer_str, read, 0);
if (err < 0) on_error("Client write failed\n");
}
}

return 0;
}
17 changes: 17 additions & 0 deletions apps/rumprun_ethernet/include/buffer.h
@@ -0,0 +1,17 @@
/*
* Copyright 2017, Data61
* Commonwealth Scientific and Industrial Research Organisation (CSIRO)
* ABN 41 687 119 230.
*
* This software may be distributed and modified according to the terms of
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
* See "LICENSE_BSD2.txt" for details.
*
* @TAG(DATA61_BSD)
*/

#pragma once

#define REVERSE_STRING_BUFSIZE 4096
#define REVERSE_STRING_END_IDX (REVERSE_STRING_BUFSIZE - 1)
#define REVERSE_STRING_MAX_LEN (REVERSE_STRING_END_IDX - 1)

0 comments on commit cd17c31

Please sign in to comment.