-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MEC Platform initial implementation (#74)
## MEC Platform - Mp1 interface following ETSI MEC standard - Mm5 REST interface - Mm5 REST python client - Basic DynDNS using Flask+dnsmasq - Service registry is based on YAKS - Script for generate a simple LXD Container with the platform
- Loading branch information
Showing
24 changed files
with
478 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
sudo ip link del mecbuildbr | ||
sudo ip link add mecbuildbr type bridge | ||
sudo ip link set mecbuildbr up | ||
|
||
|
||
|
||
lxc profile copy default mecp | ||
lxc profile device add mecp eth1 nic nictype=bridged parent=mecbuildbr | ||
lxc launch images:ubuntu/bionic plat -p mecp | ||
sleep 3; | ||
lxc file push ./ocaml/mec_platform/etc/10-lxc.yaml plat/etc/netplan/10-lxc.yaml | ||
lxc exec plat -- netplan apply | ||
sleep 3; | ||
lxc exec plat -- sudo apt update -qq | ||
lxc exec plat -- sudo apt install curl -y | ||
lxc exec plat -- sudo useradd -m mec | ||
lxc exec plat -- usermod -aG sudo mec | ||
lxc exec plat -- echo "mec ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null | ||
lxc exec plat -- mkdir -p /etc/fos/utils/mec | ||
lxc exec plat -- mkdir -p /etc/fos/utils/ | ||
lxc exec plat -- curl -L -o /tmp/yaks.tar.gz https://www.dropbox.com/s/g4tnzvjwlx3zcr2/yaksd.tar.gz | ||
lxc exec plat -- tar -xzvf /tmp/yaks.tar.gz -C /etc/fos | ||
lxc exec plat -- rm -rf /tmp/yaks.tar.gz | ||
lxc file push ./ocaml/mec_platform/_build/default/me_platform/me_platform.exe plat/etc/fos/utils/platform | ||
lxc file push -r ./python/dyndns plat/etc/fos/utils | ||
lxc exec plat -- sudo chown mec:mec -R /etc/fos | ||
|
||
lxc file push ../../etc/yaks.service plat/lib/systemd/system/ | ||
lxc file push ../../etc/yaks.target plat/lib/systemd/system/ | ||
lxc file push ./ocaml/mec_platform/etc/mec_platform.service plat/lib/systemd/system/ | ||
lxc file push ./python/dyndns/etc/dyndns.service plat/lib/systemd/system/ | ||
lxc exec plat -- sudo apt install libev-dev libssl-dev nginx dnsmasq python3 python3-pip -y | ||
lxc exec plat -- sudo pip3 install flask psutil | ||
|
||
lxc file push ./ocaml/mec_platform/etc/nginx plat/etc/nginx/sites-available/default | ||
lxc file push ./ocaml/mec_platform/etc/dnsmasq plat/etc/default/dnsmasq | ||
lxc file push ./python/dyndns/etc/mec.conf plat/etc/dnsmasq.d/mec.conf | ||
lxc file push ./ocaml/mec_platform/etc/ip_replace.sh plat/tmp/ | ||
|
||
lxc exec plat -- touch /tmp/dynhosts | ||
lxc exec plat -- chmod 0666 /tmp/dynhosts | ||
lxc exec plat -- /tmp/ip_replace.sh | ||
|
||
lxc exec plat -- systemctl stop nginx | ||
lxc exec plat -- systemctl stop dnsmasq | ||
|
||
lxc exec plat -- systemctl daemon-reload | ||
lxc exec plat -- systemctl enable dnsmasq | ||
lxc exec plat -- systemctl enable nginx | ||
lxc exec plat -- systemctl enable yaks | ||
lxc exec plat -- systemctl enable mec_platform | ||
lxc exec plat -- systemctl enable dyndns | ||
|
||
lxc exec plat -- systemctl start dnsmasq | ||
lxc exec plat -- systemctl start nginx | ||
lxc exec plat -- systemctl start yaks | ||
lxc exec plat -- systemctl start mec_platform | ||
lxc exec plat -- systemctl start dyndns |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
network: | ||
version: 2 | ||
ethernets: | ||
eth0: {dhcp4: true} | ||
|
||
eth1: | ||
addresses : [192.168.11.254/24] | ||
dhcp4: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file has five functions: | ||
# 1) to completely disable starting dnsmasq, | ||
# 2) to set DOMAIN_SUFFIX by running `dnsdomainname` | ||
# 3) to select an alternative config file | ||
# by setting DNSMASQ_OPTS to --conf-file=<file> | ||
# 4) to tell dnsmasq to read the files in /etc/dnsmasq.d for | ||
# more configuration variables. | ||
# 5) to stop the resolvconf package from controlling dnsmasq's | ||
# idea of which upstream nameservers to use. | ||
# For upgraders from very old versions, all the shell variables set | ||
# here in previous versions are still honored by the init script | ||
# so if you just keep your old version of this file nothing will break. | ||
DNSMASQ_USER='mec' | ||
#DOMAIN_SUFFIX=`dnsdomainname` | ||
#DNSMASQ_OPTS="--conf-file=/etc/dnsmasq.alt" | ||
|
||
# Whether or not to run the dnsmasq daemon; set to 0 to disable. | ||
ENABLED=1 | ||
|
||
# By default search this drop directory for configuration options. | ||
# Libvirt leaves a file here to make the system dnsmasq play nice. | ||
# Comment out this line if you don't want this. The dpkg-* are file | ||
# endings which cause dnsmasq to skip that file. This avoids pulling | ||
# in backups made by dpkg. | ||
CONFIG_DIR=/etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new | ||
|
||
# If the resolvconf package is installed, dnsmasq will use its output | ||
# rather than the contents of /etc/resolv.conf to find upstream | ||
# nameservers. Uncommenting this line inhibits this behaviour. | ||
# Note that including a "resolv-file=<filename>" line in | ||
# /etc/dnsmasq.conf is not enough to override resolvconf if it is | ||
# installed: the line below must be uncommented. | ||
#IGNORE_RESOLVCONF=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
ip -4 -o addr show dev eth0 | awk '{split($4,a,"/");print a[1]}' | xargs -i sed -i -e "s/ip/{}/g" /etc/nginx/sites-available/default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[unit] | ||
Description = Eclipse fog05 MEC DynDNS service | ||
After=yaks.target | ||
|
||
|
||
[Service] | ||
Type=simple | ||
PIDFile=/var/fos/platform.pid | ||
ExecStart = /etc/fos/utils/platform | ||
KillMode=process | ||
Restart=on-failure | ||
User=mec | ||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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; | ||
location / { | ||
|
||
proxy_pass http://127.0.0.1:8091; | ||
} | ||
} | ||
|
||
server { | ||
listen ip:9999; | ||
#server_name dyndns.platfrom.mec; | ||
location / { | ||
proxy_pass http://127.0.0.1:9999; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
open Httpaf | ||
open Httpaf_lwt_unix | ||
open Lwt.Infix | ||
|
||
|
||
|
||
module DynDNS = struct | ||
|
||
type t = { | ||
address : string; | ||
port : int; | ||
base_uri : string; | ||
(* sock : Lwt_unix.file_descr; *) | ||
addr_info : Unix.addr_info; | ||
} | ||
|
||
|
||
|
||
let read_body body = | ||
let p,c = Lwt.wait () in | ||
let fullb = Faraday.create 65535 in | ||
let rec on_read buffer ~off ~len = | ||
if len > 0 then | ||
begin | ||
Faraday.write_bigstring ~off ~len fullb buffer; | ||
Body.schedule_read body ~on_eof ~on_read; | ||
end | ||
else | ||
on_eof (); | ||
and on_eof () = | ||
Faraday.close fullb; | ||
Lwt.wakeup_later c (Faraday.serialize_to_string fullb); | ||
in | ||
Body.schedule_read body ~on_eof ~on_read; | ||
p | ||
|
||
|
||
let do_request uri meth header body self = | ||
let sock = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in | ||
let p,c = Lwt.wait () in | ||
let error_handler _ = | ||
Logs.err (fun m -> m "This is a DNS client error"); | ||
Lwt.wakeup c "" | ||
in | ||
let response_handler _ resp_body = | ||
let _ = (read_body resp_body >>= fun body -> | ||
Logs.debug (fun m -> m "Body is %s" body); | ||
Lwt.wakeup_later c (body); | ||
Lwt_unix.close sock) | ||
in () | ||
(* Create only one sck *) | ||
in | ||
let%lwt _ = Lwt_unix.connect sock self.addr_info.Unix.ai_addr in | ||
let headers = Headers.of_list ([ | ||
"Content-Length", (string_of_int (String.length body)); | ||
"Connection", "keep-alive"; | ||
] @ header) | ||
in | ||
let request_body = Client.request ~error_handler ~response_handler sock (Request.create ~headers meth uri) in | ||
Body.write_string request_body body; | ||
Body.close_writer request_body; | ||
let%lwt res = p in | ||
Lwt.return res | ||
|
||
let get_dns_rules self = | ||
let uri = self.base_uri ^ "/record" in | ||
let%lwt resp = do_request uri `GET [] "" self in | ||
let r = Dns_types.get_response_of_string resp in | ||
Lwt.return r.result | ||
|
||
let add_dns_rule self ip name = | ||
let uri = self.base_uri ^ "/record" in | ||
let body = (Dns_types.string_of_dns_record {ip; name}) ^ "\n" in | ||
let%lwt resp = do_request uri `PUT [] body self in | ||
let _ = Dns_types.add_remove_response_of_string resp in | ||
Lwt.return_unit | ||
|
||
let remove_dns_rule self ip name = | ||
let uri = self.base_uri ^ "/record" in | ||
let body = Dns_types.string_of_dns_record {ip; name} in | ||
let%lwt resp = do_request uri `DELETE [] body self in | ||
let _ = Dns_types.add_remove_response_of_string resp in | ||
Lwt.return_unit | ||
|
||
let create address port base_uri = | ||
let%lwt addr_info = Lwt_unix.getaddrinfo address (string_of_int port) [Unix.(AI_FAMILY PF_INET)] >>= fun al -> Lwt.return @@ List.hd al in | ||
Lwt.return {address; port; base_uri; addr_info} | ||
|
||
let destroy _ = | ||
Lwt.return_unit | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
|
||
module DynDNS : sig | ||
|
||
type t | ||
|
||
val create : string -> int -> string -> t Lwt.t | ||
|
||
val get_dns_rules : t -> Dns_types.dns_record list Lwt.t | ||
|
||
val add_dns_rule: t -> string -> string -> unit Lwt.t | ||
|
||
val remove_dns_rule: t -> string -> string -> unit Lwt.t | ||
|
||
val destroy : t -> unit Lwt.t | ||
|
||
end |
Oops, something went wrong.