Skip to content

Commit

Permalink
MEC Related Tests and helpers (#79)
Browse files Browse the repository at this point in the history
## MEC 
- Added docker files for Multi-access Edge Application Orchestrator to facilitate his deployment
- Fixed bugs in both MEC Platform and MEAO with respect to data stored in the registry and response format
- Added tests for Mm1 interface and Mm5 interface, that validates both Client and Servers
- Fixed bug in the logging of errors in MEAO
  • Loading branch information
gabrik committed May 10, 2019
1 parent 757aca2 commit 2f91dde
Show file tree
Hide file tree
Showing 21 changed files with 760 additions and 194 deletions.
12 changes: 12 additions & 0 deletions src/utils/docker/Dockerfile-meao
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ubuntu:xenial

LABEL authors="Gabriele Baldoni"

RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install libev-dev libssl-dev libgmp-dev -y

copy ./ocaml/mec_meao_mepmv/_build/default/meao/meao.exe /root/meao

EXPOSE 8071

CMD /root/meao -vv
12 changes: 12 additions & 0 deletions src/utils/docker/Dockerfile-yaks
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ubuntu:xenial

LABEL authors="Gabriele Baldoni"

RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install libev-dev libssl-dev curl -y && \
DEBIAN_FRONTEND=noninteractive curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/g4tnzvjwlx3zcr2/yaksd.tar.gz && \
tar -xzvf /tmp/yaks.tar.gz -C /root/

EXPOSE 7887

CMD /root/yaksd
29 changes: 29 additions & 0 deletions src/utils/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'
volumes:
fog05-meao-yaks:
fog05-meao:

networks:
netMEAO:
external:
name: fog05-meaonet

services:
fog05-meao-yaks:
image: fog05/yaks
# ports:
# - "7887:7887"
networks:
- netMEAO
fog05-meao:
image: fog05/meao
networks:
- netMEAO
environment:
YAKS_HOST: fog05-meao-yaks
YAKS_PORT: 7887
ports:
- "8071:8071"
depends_on:
- fog05-meao-yaks

102 changes: 102 additions & 0 deletions src/utils/generate_mec_orchestrator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash


# INSTALL SNAPD - LXD - DOCKER
# CREATE MEAO/YAKS container (DOCKER)
# CREATE TEST MEC Container (LXD)

# docker swarm init --advertise-addr 192.168.100.134

POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-t|--test)
TEST=true
shift;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done

docker image rm fog05/yaks --force
docker image rm fog05/meao --force

make -C ocaml/mec_meao_mepmv clean
make -C ocaml/mec_meao_mepmv

docker network rm fog05-meaonet
docker network create -d overlay --attachable fog05-meaonet


sg docker -c "docker build . -f ./docker/Dockerfile-yaks -t fog05/yaks --no-cache"
sg docker -c "docker build . -f ./docker/Dockerfile-meao -t fog05/meao --no-cache"

docker stack deploy -c ./docker/docker-compose.yaml meao


if [ $TEST ]
then
make -C ocaml/mec_platform clean
make -C ocaml/mec_platform
./generate_mec_platform.sh
MEC_IP=$(lxc list -c4 --format json plat | jq -r '.[0].state.network.eth0.addresses[0].address')
PL="{\"platformId\":\"testp\", \"endpoint\":{\"uris\":[\"/exampleAPI/mm5/v1\"], \"alternative\":{},\"addresses\":[{\"host\":\"$MEC_IP\",\"port\":8091}]}}"
curl -X POST http://127.0.1:8071/exampleAPI/mm1/v1/platforms -d "$PL"
fi






# lxc launch images:ubuntu/bionic meao
# sleep 3;

# lxc exec meao -- sudo apt update -qq
# lxc exec meao -- sudo apt install curl -y
# lxc exec meao -- sudo useradd -m mec
# lxc exec meao -- usermod -aG sudo mec
# lxc exec meao -- echo "mec ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null
# lxc exec meao -- mkdir -p /etc/fos/utils/mec
# lxc exec meao -- mkdir -p /etc/fos/utils/
# lxc exec meao -- curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/g4tnzvjwlx3zcr2/yaksd.tar.gz
# lxc exec meao -- tar -xzvf /tmp/yaks.tar.gz -C /etc/fos
# lxc exec meao -- rm -rf /tmp/yaks.tar.gz
# lxc file push ./ocaml/mec_meao_mepmv/_build/default/meao/meao.exe meao/etc/fos/utils/meao
# lxc exec meao -- sudo chown mec:mec -R /etc/fos

# lxc file push ../../etc/yaks.service meao/lib/systemd/system/
# lxc file push ../../etc/yaks.target meao/lib/systemd/system/
# lxc file push ./ocaml/mec_meao_mepmv/etc/mec_meao.service meao/lib/systemd/system/
# lxc exec meao -- sudo apt install libev-dev libssl-dev nginx -y

# lxc file push ./ocaml/mec_meao_mepmv/etc/nginx meao/etc/nginx/sites-available/default
# lxc file push ./ocaml/mec_meao_mepmv/etc/ip_replace.sh meao/tmp/

# lxc exec meao -- /tmp/ip_replace.sh

# lxc exec meao -- systemctl stop nginx

# lxc exec meao -- systemctl daemon-reload
# lxc exec meao -- systemctl enable nginx
# lxc exec meao -- systemctl enable yaks
# lxc exec meao -- systemctl enable mec_meao

# lxc exec meao -- systemctl start nginx
# lxc exec meao -- systemctl start yaks
# lxc exec meao -- systemctl start mec_meao

# # lxc list -c4 --format json plat

# MEAOIP=$(lxc list -c4 --format csv meao | cut -d' ' -f1)

# sudo iptables -t nat -A PREROUTING -i lo -p tcp --dport 8071 -j DNAT --to $MEAOIP:8071

# echo "export MEAO=127.0.0.1:8071/exampleAPI/mm1/v1" >> ~/.profile

# export MEAO="127.0.0.1:8071/exampleAPI/mm1/v1"
File renamed without changes.
8 changes: 0 additions & 8 deletions src/utils/ocaml/mec_meao_mepmv/etc/10-lxc.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions src/utils/ocaml/mec_meao_mepmv/etc/dnsmasq

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[unit]
Description = Eclipse fog05 MEC DynDNS service
Description = Eclipse fog05 MEC Orchestrator service
After=yaks.target


[Service]
Type=simple
PIDFile=/var/fos/platform.pid
ExecStart = /etc/fos/utils/platform
PIDFile=/var/fos/meao.pid
ExecStart = /etc/fos/utils/meao
KillMode=process
Restart=on-failure
User=mec
Expand Down
22 changes: 4 additions & 18 deletions src/utils/ocaml/mec_meao_mepmv/etc/nginx
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
server {
listen 192.168.11.254:8081;
#server_name mp1.platfrom.mec;
location / {
proxy_pass http://127.0.0.1:8081;
}
}


server {
listen ip:8091;
#server_name mm5.platform.mec;
listen ip:8071;
#server_name mm1.meao.mec;
location / {

proxy_pass http://127.0.0.1:8091;
proxy_pass http://127.0.0.1:8071;
}
}

server {
listen ip:9999;
#server_name dyndns.platfrom.mec;
location / {
proxy_pass http://127.0.0.1:9999;
}
}
50 changes: 20 additions & 30 deletions src/utils/ocaml/mec_meao_mepmv/meao/Mm1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ module Mm1 = struct
let respond_created reqd headers s =
let headers = Headers.add headers "Connection" "close" in
Reqd.respond_with_string reqd (Response.create ~headers `Created) s;
Logs.debug (fun m -> m "[Mm1] : Replied OK with %s" s)
Logs.debug (fun m -> m "[Mm1] : Replied Created with %s" s)

let respond_bad_request reqd headers s =
let headers = Headers.add headers "Connection" "close" in
Reqd.respond_with_string reqd (Response.create ~headers `Bad_request) s
Reqd.respond_with_string reqd (Response.create ~headers `Bad_request) s;
Logs.debug (fun m -> m "[Mm1] : Replied Bad Request with %s" s)


let respond_forbidden reqd headers s =
let headers = Headers.add headers "Connection" "close" in
Reqd.respond_with_string reqd (Response.create ~headers `Forbidden) s
Reqd.respond_with_string reqd (Response.create ~headers `Forbidden) s;
Logs.debug (fun m -> m "[Mm1] : Replied Forbidden with %s" s)

let respond_not_found reqd headers s =
let headers = Headers.add headers "Connection" "close" in
Reqd.respond_with_string reqd (Response.create ~headers `Not_found) s
Reqd.respond_with_string reqd (Response.create ~headers `Not_found) s;
Logs.debug (fun m -> m "[Mm1] : Replied Not Found with %s" s)


let error_handler ?request:_ error start_response =
Expand All @@ -91,7 +94,7 @@ module Mm1 = struct


let on_err reqd (ex:exn) =
Logs.debug (fun m -> m "[Mm1] : Exception %s" (Printexc.to_string ex) );
Logs.debug (fun m -> m "[Mm1] : Exception %s raised %s" (Printexc.to_string ex) (Printexc.get_backtrace () ));
let problem_details = Rest_types.string_of_error_response @@ {problem_details = { err_type = "bad_request"; title=(Printexc.to_string ex); status=0; detail=""; instance=""}} in
respond_bad_request reqd (Headers.of_list ["Content-Type", "application/json"]) problem_details
(* let internal_error msg =
Expand Down Expand Up @@ -247,7 +250,7 @@ module Mm1 = struct
Logs.debug (fun m -> m "[Mm1] : GET Applications");
let apps = MEAO.get_applications platform_id self.core in
let f apps =
let res = List.map (fun e -> Yojson.Safe.from_string @@ Rest_types.string_of_app_info e) apps |> fun x -> Yojson.Safe.to_string @@ (`List x) in
let res = Rest_types.string_of_application_info_list_response {application_info = apps} in
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res
in
Lwt.on_any apps f (on_err reqd);
Expand All @@ -260,12 +263,12 @@ module Mm1 = struct
let app = read_body reqd
>>= fun string_appd -> Lwt.return @@ MEC_Types.appd_descriptor_of_string string_appd
>>= fun appd -> MEAO.add_application platform_id appd self.core
>>= fun appid -> Lwt.return (appid,appd)
>>= fun app_info -> Lwt.return (Apero.Option.get app_info.app_instance_id, app_info)
in
let f app =
let appid, appd = app in
let app_uri = make_app_url self.prefix appid in
let res = MEC_Types.string_of_appd_descriptor appd in
let res = Rest_types.string_of_application_info_response {application_info = appd} in
respond_created reqd (Headers.of_list ["Content-Type", "application/json"; "location", app_uri]) res
in
(* Should be Lwt.on_any *)
Expand All @@ -283,7 +286,7 @@ module Mm1 = struct
let app = MEAO.get_application_by_uuid platform_id app_instance_id self.core in
let f app =
(match app with
| Some app -> let res = Rest_types.string_of_app_info app in
| Some app -> let res = Rest_types.string_of_application_info_response {application_info = app} in
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res
| None ->
Logs.debug (fun m -> m "[Mm1] : Not found application %s" app_instance_id);
Expand All @@ -297,10 +300,10 @@ module Mm1 = struct
let app = read_body reqd
>>= fun string_appd -> Lwt.return @@ MEC_Types.appd_descriptor_of_string string_appd
>>= fun appd -> MEAO.add_application platform_id appd self.core
>>= fun _ -> Lwt.return appd
>>= fun appi -> Lwt.return appi
in
let f app =
let res = MEC_Types.string_of_appd_descriptor app in
let res = Rest_types.string_of_application_info_response {application_info = app} in
respond_created reqd (Headers.of_list ["Content-Type", "application/json"]) res
in
(* Should be Lwt.on_any *)
Expand All @@ -322,11 +325,7 @@ module Mm1 = struct
Logs.debug (fun m -> m "[Mm1] : GET DNS Rules for %s" app_instance_id);
let rules = MEAO.get_dns_rules_for_application platform_id app_instance_id self.core in
let f rules =
let res = rules
|> List.map (fun e -> Rest_types.create_dns_rule_response ~dns_rule:e ())
|> List.map (fun e -> Yojson.Safe.from_string @@ Rest_types.string_of_dns_rule_response e)
|> fun x -> Yojson.Safe.to_string @@ (`List x)
in
let res = Rest_types.string_of_dns_rule_list_response {dns_rule = rules} in
Logs.debug (fun m -> m "[Mm1] : DNS Rules for %s -> %s" app_instance_id res);
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res
in
Expand Down Expand Up @@ -406,11 +405,7 @@ module Mm1 = struct
Logs.debug (fun m -> m "[Mm1] : GET Traffic Rules for %s" app_instance_id);
let rules = MEAO.get_traffic_rules_for_application platform_id app_instance_id self.core in
let f rules =
let res = rules
|> List.map (fun e -> Rest_types.create_traffic_rule_response ~traffic_rule:e ())
|> List.map (fun e -> Yojson.Safe.from_string @@ Rest_types.string_of_traffic_rule_response e)
|> fun x -> Yojson.Safe.to_string @@ (`List x)
in
let res = Rest_types.string_of_traffic_rule_list_response {traffic_rule = rules} in
Logs.debug (fun m -> m "[Mm1] : Traffic Rules for %s -> %s" app_instance_id res);
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res;
in
Expand Down Expand Up @@ -477,7 +472,8 @@ module Mm1 = struct
| `DELETE ->
Logs.debug (fun m -> m "[Mm1] : DELETE Traffic Rule %s for %s" traffic_rule_id app_instance_id );
let subid = MEAO.remove_traffic_rule_for_application platform_id app_instance_id traffic_rule_id self.core in
let f _ =
let f subid =
Logs.debug (fun m -> m "Traffic rule %s removed from %s" subid app_instance_id);
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) ""
in
Lwt.on_any subid f (on_err reqd);
Expand Down Expand Up @@ -531,10 +527,7 @@ module Mm1 = struct
| [] -> nsvcs)
in
let svcs = filt_map svcs [] in
let res = List.map (fun e ->
Yojson.Safe.from_string @@ Rest_types.string_of_service_info_response {service_info = e}
) svcs |> fun x -> Yojson.Safe.to_string @@ (`List x)
in
let res = Rest_types.string_of_service_info_list_response {service_info = svcs} in
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res
in
(* Should be Lwt.on_any *)
Expand Down Expand Up @@ -608,10 +601,7 @@ module Mm1 = struct
Logs.debug (fun m -> m "[Mm1] : GET Transports");
let txs = MEAO.get_transports platform_id self.core in
let f txs =
let res =List.map (fun e ->
Yojson.Safe.from_string @@ Rest_types.string_of_transport_info_response {transport_info = e}
) txs |> fun x -> Yojson.Safe.to_string @@ (`List x)
in
let res = Rest_types.string_of_transport_info_list_response {transport_info = txs} in
respond_ok reqd (Headers.of_list ["Content-Type", "application/json"]) res
in
Lwt.on_any txs f (on_err reqd);
Expand Down
Loading

0 comments on commit 2f91dde

Please sign in to comment.