Libioth (Slides)
Total Page:16
File Type:pdf, Size:1020Kb
libioth The definitive API for the Internet of Threads Renzo Davoli – Michael Goldweber "niversit$ o% Bolo&na '(taly) – *avier "niver#it$ (Cin!innati, "SA) ,irt-alS.-are Micro/ernel DevRoo0 1 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 (nternet of Thread# (IoTh) service1.company.com → 2001:1:2::1 service2.company.com → 2001:1:2::2 host.company.com→11.12.13.14 processes service3.company.com → 2001:1:2::3 2 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 IoTh vs Iold What is an end-node o% the (nternet4 (t depends on what is identified b$ an (P addre##. ● (nternet o% 1hreads – (oTh – 7roce##e#8threads are a-tonomou# nodes of the (nternet ● (nternet o% 9e&ac$ Devi!es 'in brie% (-old in this presentation) – (nternet o% :ost# – Internet of ;etwork Controller#. – (nternet o% ;a0e#5a!e# 2 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 7,M – IoTh - </ernel 4 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 7,M – IoTh - </ernel ● icro/ernel, Internet o% Threads, Partial Virtual a!hines have the co00on goal to create independent code units i05lementing services ● 1hey are all against monolithic i05lementation# ● 1he challenge o% this talk is to !reate !ontacts, e>5loit paralleli#0#+ that allow to share res-lts, A7I, code. = © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 Network Sta!/ ● API to application layer TCP-IP stack TCP UDP IPv4 IPv6 ICMP(v4,v6) ● API (NPI) to data-link – (e.g. libioth uses VDE: libvdeplug) ? © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 IoTh & </ernel User process User process TCP-IP stack TCP UDP TCP/IP stack process IPv4 IPv6 ICMP(v4,v6) TCP-IP stack TCP UDP IPv4 IPv6 ICMP(v4,v6) Data-link network server Data-link network server @ © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 A7( to the A55 9a$er ● Co05lete – All o5# !urrentl$ available 0ust be #-55orted ● Usable – S$nta> 0-#t be !onsistent with the 0aCor standard# ● Minimal/Clean – Avoid -sele## or d-5li!ated o5# B © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 A7I re.-ire0ent# ● Confi&uration !all# – Create – Delete a sta!k in#tan!e – Config-re 5ara0eters 'as (P address-e#+ routing et!) ● Co00-ni!ation calls – open8!lose a !o00unication end5oint – send8re!eive8#et-&et o5tions D © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 API design !hoice#E 1- Sta!/ creation/deletion ● A #ta!/ is identified b$ a de#!riptor o% t$5e: – struct ioth * ● Sta!/ CreationE struct ioth *ioth_newstack(const char *stack, const char *vnl); struct ioth *ioth_newstackl(const char *stack, const char *vnl, ... /* (char *) NULL */); struct ioth *ioth_newstackv(const char *stack, const char *vnlv[]); – ioth_newstack for one inter%a!e (or none i% vnl==NULL), the other# are for 0ore inter%a!e#. – 1he strin& stack sele!ts the sta!/ im5le0entation+ loaded a# a plu&in. – vnl stand# for “,irtual Networ/ Lo!atorG+ it sele!ts the VDH networ/ to conne!t the virtual inter%a!e'#). ● Sta!/ deletionE int ioth_delstack(struct ioth *iothstack); 10 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 API design !hoice#E 2- Com0-nication ● Creation o% a !o00-ni!ation endpointE int ioth_msocket(struct ioth *stack, int domain, int type, int protocol); – (t e>tends socket(2)+ it allows the choi!e o% the sta!/ – (t ret-rns a real 6le de#!ri5tor that can be used in poll(2), select(2) or si0ilar ● %or ever$thin& el#e... Ber/eley So!/et# ioth_close, ioth_bind, ioth_connect, ioth_listen, ioth_accept, ioth_getsockname, ioth_getpeername, ioth_setsockopt, ioth_getsockopt, ioth_shutdown, ioth_ioctl, ioth_fcntl, ioth_read, ioth_readv, ioth_recv, ioth_recvfrom, ioth_recvmsg, ioth_write, ioth_writev, ioth_send ioth_sendto and ioth_sendmsg – have the sa0e signat-re and f-n!tionalities o% their !o-nter5art witho-t the ioth_ 5refi> 11 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 API design !hoice#E 2- Confi&-ration ● ;o more calls neededI ● ;et confi&-ration via AFK;H19(;K so!/et# ● As de6ned in: – RFC 2=4D - 9inux Netlink as an (7 Servi!es 7roto!ol ● Helper libs are provided as services using the API (e.g. nlinline+ or iothconf). 12 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 H>ampleE #end F!iao\nG #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char *argv[]) { struct sockaddr_in dst = { .sin_family = AF_INET, .sin_port = htons(5000), .sin_addr.s_addr = inet_addr("10.0.0.2") }; int fd = socket(AF_INET, SOCK_DGRAM, 0); sendto(fd, "ciao\n", 5, 0, (void *) &dst, sizeof(dst)); close(fd); } 12 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 H>a05le: ioth #end Fciao\nG #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <ioth.h> int main(int argc, char *argv[]) { struct ioth *stack = ioth_newstack("vdestack", "vde:///tmp/hub"); struct in_addr myaddr = {.s_addr = inet_addr("10.0.0.1")}; int ifindex = ioth_if_nametoindex(stack, "vde0"); ioth_ipaddr_add(stack, AF_INET, &myaddr, 24, ifindex); ioth_linksetupdown(stack, ifindex, 1); struct sockaddr_in dst = { .sin_family = AF_INET, .sin_port = htons(5000), .sin_addr.s_addr = inet_addr("10.0.0.2") }; int fd = ioth_msocket(stack, AF_INET, SOCK_DGRAM, 0); ioth_sendto(fd, "ciao\n", 5, 0, (void *) &dst, sizeof(dst)); ioth_close(fd); } 14 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 The way to libioth... ● … ha# been long ● 9ibioth -#e# a nu0ber o% !on!e5t and #o%tware tool#/librarie# develo5ed at ,irtualS.uare. ● ";(* 5hilo#o5h$ basedE – Hach tool/librar$ or !on!e5t does one thing and tries to do it well – 1ool/libraries or !on!e5ts have been desi&ned to intero5erate. 1= © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 The way to libioth... ● ,irt-al Distrib-ted Ethernet (,DH) ● Jd-serdata ● 9ibv5oll and v5oll devi!e ● ;linline ● 9ibnl. ● ,-os: v-netioth ● ,de#ta!/ ● 7i!o>net ● ... 1? © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 1he wa$ to libiothN N has %-rther destinations... ● Iothcon% ● Iothdns ● ... 1@ © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 ,DEE virt-al distributed ethernet ● libvdepl-& #-pported b$ – , E .em-8/v0, virtualbo>, -#er-mode lin-> – ;a0es5a!esE vden# – networ/ #ta!/ lib#E vde#ta!/+ 5i!o>net, lwi5v? 1B © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 ,DH5lug API ';7()E ● A ,DE !onnection end5oint is identi6ed b$ a de#criptor o% t$5eE – VDECONN * ● A ,DE networ/ is identi6ed b$ a #trin&E the ,irt-al ;etwork 9ocator. e.&.E null:// switch:///tmp/myswitch vxvde://234.0.0.1 vde:///var/run/sw1 slirp:// tap://tap4 ● 1he A7( i#E VDECONN *vde_open(char *vnl, char *description, NULL); ssize_t vde_send(VDECONN *conn, const void *buf, size_t len, int flags); ssize_t vde_recv(VDECONN *conn, void *buf, size_t len, int flags); int vde_datafd(VDECONN *conn); // for poll/select, test for new packet availability int vde_ctlfd(VDECONN *conn); // for poll/select, test for conn shutdown int vde_close(VDECONN *conn); – vde_open: de#!ription is %or debu&&ing+ !an be o0itted, the third ar& is %or ba!/ward# !o05atibilit$. – vde_send, vde_recv: the la#t ar& flags i# reserved %or %-t-re develo50ents. Set to 0. 1D © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 Some ,DE 5lugin# 20 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 A note about the e>amples... Intere#ted reader# can find the co0plete #e.ence o% com0and# to set up the #!enarios o% the e>ample# o% the followin& #lide# in the tutorial se!tion o% ,irtual#.-areO# wikiE http:88wi/i.virtual#.-are.or& 21 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 ,DE e>a05le 22 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 ,DE namespaces 22 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 (nternet of Thread# 24 © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 libioth 2= © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 2? © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 %d-serdata ● A##ociate u#er data to file de#!riptor# ● 9ibioth can #ele!t the sta!/ instan!e %ro0 the file de#!riptor ● The si&nature o% all the calls of the Ber/ele$ so!/et A7I is pre#erved. ● Pnly m#oc/et ha# one e>tra ar&-0ent. 2@ © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 vpoll ● libiothO# 6le de#!ri5tors !an be -#ed in 5oll+ #ele!t, 55oll, 5#ele!t, e5ollN ● A wa$ to &enerate arbitrar$ 5oll events was 0i##in& ● libv5oll uses a /ernel 0odule to 5rovide a !o05lete #-55ort 'or i05le0ents an e0ulation able to 0ana&e 7P99(;+ 7P99P"T and 5artiall$ 7P99:"7) 2B © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 nlinline ● ;etwor/ sta!/# are &enerally !on#idered a# #ervi!es provided by the /ernel. So there are !o00ands to !on6&-re the sta!/# li/e ipro-te or the old i%!on6&. ● A librar$ providin& %-n!tion# to con6&-re a #ta!/ wa# 0i##in& ● nlinline i# a li&ht library on inline f-n!tion# 5rovidin& a!!es# to all the ba#i! !on6&-ration o5# (add/del an inter%a!e, set an inter%a!e u58down+ add/del I7 addre##es+ add/del ro-tes). (t u#e# netlin/ a# des!ribed in RJC2=4D. 2D © 2021 Davoli-Goldweber libioth. CC-BY-SA 4.0 libnl. ● ;etwor/ stac/s are generall$ considered as servi!es 5rovided b$ the /ernel. A librar$ able to de!ode !onfiguration re.ue#ts via netlink was mi#sing. ● libnl. for&e# and de!odes rt-netlink 0e##ages both at client and at server side. ● (t al#o provide# an e0ulation la$er to s-55ort de5re!ated (though still used b$ &lib!) netdevi!e ioctl.