Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Tel354 Sesion 04 SDN Bartra 2023
Tel354 Sesion 04 SDN Bartra 2023
TEL354
Gumercindo Bartra Gardini, M.Sc.Ing.
Grupo de Investigación en Redes Avanzadas (GIRA)
Pontificia Universidad Católica de Perú (PERU)
gbartra@pucp.edu.pe
Network namespaces, Open
vSwitch, Mininet
Contenido
1
1 Linux namespaces
2 Mininet
Mount namespaces: aislar un conjunto de puntos montaje de un sistema de archivos para que sólo
sea accesible desde un grupo de procesos. Procesos en diferentes mount namespaces tendrán
diferentes vistas de la jerarquía del sistema de archivos.
Network namespaces: proporciona aislamiento de los recursos asociados a la red: direcciones IP,
tablas de enrutamiento, directorio /proc/net, etc.
Lleva a h1 el
extremo eth0-h1
$ sudo ip netns add h1
$ sudo ip netns add h2
$ sudo ip netns exec h1 ip link set lo up
$ sudo ip netns exec h2 ip link set lo up $ sudo ip netns exec h1 ip link
$ sudo ip link add eth0-h1 type veth peer name eth0-h2 $ sudo ip netns exec h2 ip link
$ sudo ip link set eth0-h1 netns h1 $ sudo ip netns exec h1 ip address
$ sudo ip link set eth0-h2 netns h2 $ sudo ip netns exec h2 ip address
$ sudo ip netns exec h1 ip address add 10.0.0.1/24 dev eth0-h1 $ sudo ip netns del h1
$ sudo ip netns exec h2 ip address add 10.0.0.2/24 dev eth0-h2 $ sudo ip netns del h2
$ sudo ip netns exec h1 ip link set eth0-h1 up
$ sudo ip netns exec h2 ip link set eth0-h2 up
Configura para eth0-
$ sudo ip netns exec h1 ping 10.0.0.2 h1 dentro de h1 una
dirección IP
Activa eth0-h1
Ejecuta un ping a la dirección IP dentro de h1
de eth0-h2 desde h1
*** S t a r t i n g 1 s w i t c h e s s 1 . . .
*** S t a r t i n g C L I :
mininet>
Se pueden arrancar xterms asociados a las máquinas, por ejemplo, para lanzar un terminal de h1 en una ventana diferente:
mininet> xterm h1
Mininet crea los network namespaces asociados a las máquinas virtuales sin nombre, con un identificador que solo tiene sentido dentro del
namespace actual. Podemos ver que se han creado con los identificadores 0, 1 y 2 dentro del root network namespace:
$ i p netns l i s t - i d
nsid 0
nsid 1
nsid 2
Cada máquina de mininet es un proceso bash dentro de un network namespace donde se definen sus interfaces de red:
$ ps - f p 7826,7828,7830,7835
UID PID PPID C STIME TTY TIME CMD
root 2652 7820 0 11:44 pts/2 00:00:00 bash --norc -is mininet:h1
root 2654 7820 0 11:44 pts/3 00:00:00 bash --norc -is mininet:h2
root 2656 7820 0 11:44 pts/4 00:00:00 bash --norc -is mininet:h3
root 2661 7820 0 11:44 pts/5 00:00:00 bash --norc -is mininet:s1
El contenido del namespace creado, se puede consultar sabiendo el número de proceso, por ejemplo para h1, su pid=2652
$ sudo nsenter - t 2652 - n i p l i n k
1 : l o : <LOOPBACK,UP,LOWER_UP> mtu 65536 q d i s c noqueue s t a t e UNKNOWNmode DEFAULT
group d e f a u l t qlen 1000
l i n k / l o o p b a c k 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00
2 : h1-eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 q d i s c noqueue s t a t e UP mode DE group
d e f a u l t qlen 1000
l i n k / e t h e r 00: 00: 00: 00: 00: 01 brd f f : f f : f f : f f : f f : f f l i n k - n e t n s i d 0
Desde CLI se pueden ejecutar comandos en cada una de las máquinas, anteponiendo el nombre de la
máquina al comando que se desea ejecutar:
mininet> h1 i p l i n k
1 : l o : <LOOPBACK,UP,LOWER_UP> mtu 65536 q d i s c noqueue s t a t e UNKNOWNmode DEFAULT group d e f a u l t qlen 1000
l i n k / l o o p b a c k 00:00:00:00:00:00 brd 00:00:00:00:00:00
2 : h1-eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 q d i s c noqueue s t a t e UP mode DEFAULT group d e f a u l t qlen 1000
l i n k / e t h e r 00:00:00:00:00:01 brd f f : f f : f f : f f : f f : f f l i n k - n e t n s i d 0
mininet> h2 i p l i n k
1 : l o : <LOOPBACK,UP,LOWER_UP> mtu 65536 q d i s c noqueue s t a t e UNKNOWNmode DEFAULT group d e f a u l t qlen 1000
l i n k / l o o p b a c k 00:00:00:00:00:00 brd 00:00:00:00:00:00
2 : h2-eth0@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 q d i s c noqueue s t a t e UP mode DEFAULT group d e f a u l t qlen 1000
l i n k / e t h e r 00:00:00:00:00:02 brd f f : f f : f f : f f : f f : f f l i n k - n e t n s i d 0
mininet> h3 i p l i n k
1 : l o : <LOOPBACK,UP,LOWER_UP> mtu 65536 q d i s c noqueue s t a t e UNKNOWNmode DEFAULT group d e f a u l t qlen 1000
l i n k / l o o p b a c k 00:00:00:00:00:00 brd 00:00:00:00:00:00
2 : h3-eth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 q d i s c noqueue s t a t e UP mode DEFAULT group d e f a u l t qlen 1000
l i n k / e t h e r 00:00:00:00:00:03 brd f f : f f : f f : f f : f f : f f l i n k - n e t n s i d 0
• Información de Datapath
$ s u d o o v s - d p c t l show
system@ovs-syste m :
flows: 0
*** S t a r t i n g 1 s witches s1 . . .
*** S t a r t i n g C L I :
mininet> p i n g a l l
*** P i n g : t e s t i n g ping r e a c h a b i l i t y
h1 - > X X
h2 - > X X
h3 - > X X
*** R e s u l t s : 100% dropped ( 0 / 6 r e c e i v e d )
Al haber instruido a s1 para que se comporte como switch, se puede observar que hay conectividad entre las máquinas:
mininet> p i n g a l l
*** P i n g : t e s t i n g ping r e a c h a b i l i t y
h1 - > h2 h3
h2 - > h1 h3
h3 - > h1 h2
*** R e s u l t s : 0% dropped ( 6 / 6 re c e i v e d )
El switch s1 tiene el funcionamiento normal de un switch: aprendizaje y reenvío:
mininet> sh ov s - a p p c t l fdb/show s1
port VLAN MAC Age
1 0 00:00:00:00:00:01 98
2 0 00:00:00:00:00:02 97
3 0 00:00:00:00:00:03 97
R u l e : table=0 cookie=0 p r i o r i t y = 5 0 0 , i n _ p o r t = 1
OpenFlow actions=o utp ut:2
F i n a l f l o w : unchanged
Megaflow: recirc_id=0,in_port=1,dl_type=0x0000
Datapath a c t i o n s : 1
Para que un ping entre éstas máquinas funcione además hay que instalar la regla que permite reenviar la solicitud de
ARP. Con la acción FLOOD se envía por todos los puertos salvo por donde se recibe. El parámetro nw_proto=1 hace
referencia a la operación ARP, el valor 1 es solicitud y 2 es respuesta.
mininet> sh o v s - o f c t l add-flow s1 dl_type=0x806,nw_proto=1,actions=flood
mininet> p i n g a l l
*** P i n g : t e s t i n g ping r e a c h a b i l i t y h1 - > h2 X
h2 - > h1 X h3 - > X X
*** R e s u l t s : 66% dropped ( 2 / 6 r e c e i v e d )
mininet> sh o v s - o f c t l dump-flows s1
NXST_FLOW r e p l y ( x i d = 0 x 4 ) :
cookie=0x0, duration=543.873s, t a b l e = 0 , n_packets=6, n_bytes=420, idle_a ge=79,
dl_s r c=00:00:00:00:00:01, d l_ds t=00:00:00:00:00:02 a ctions =output:2
cookie=0x0, duration=534.485s, t a b l e = 0 , n_packets=7, n_bytes=462, idle_a ge=79,
dl_s r c=00:00:00:00:00:02, d l_ds t=00:00:00:00:00:01 a ctions =output:1
cookie=0x0, duration=202.094s, t a b l e = 0 , n_packets=13, n_bytes=546, idle_a ge=61, a r p , arp_op=1 actions=FLOOD
mininet> p i n g a l l
*** P i n g : t e s t i n g ping r e a c h a b i l i t y h1 - > h2 h3
h2 - > h1 h3 h3 - > h1 h2
*** R e s u l t s : 0% dropped ( 6 / 6 re c e i v e d )
R u l e : table=0 cookie=0 d l _ s r c = 01: 00: 00: 00: 00: 00/ 01: 00: 00: 00: 00: 00
OpenFlow a c t i o n s = d r o p
F i n a l f l o w : unchanged
Megaflow: r e c i r c _ i d = 0 , i n _ p o r t = 1 , d l _ s r c = 0 1 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 / 0 1 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 , d l _ t y p e = 0 x 0 0 0 0 Datap ath a c t i o n s : drop
El resultado de la ejecución nos muestra:
Bridge: nombre del switch, s1
Flow: características del flujo a probar, en este caso, recibido en puerto 1 con dirección origen=01:11:11:11:11:11
(los campos que no se especifican se quedan en cero)
Rule: regla que se le aplica, en la tabla 0 la regla de descarte de tramas con dirección Ethernet con bit multicast a 1.
Final flow: el flujo resultante no se modifica
Megaflow: descripción del flujo dentro del datapath. Esta información se instala en el datapath para consultar
rápidamente si se puede aplicar el flujo a los paquetes entrantes.(recirc id=0 significa que el paquete acaba de entrar en
el datapath, no ha habido recirculación).
Datapath actions: acción tomada es descartar.
Resubmitted f l o w : i p , i n _ p o r t = 1 , v l a n _ t c i = 0 x 0 0 0 0 , d l _ s r c = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 , d l _ d s t = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ,
nw_src=0.0.0.0,nw_dst=10.0.0.1,nw_proto=0,nw_tos=0,nw_ecn=0,nw_ttl=0
Resubmitted r e g s : reg0=0x0 reg1=0x0 reg2=0x0 reg3=0x0 reg4=0x0 reg5=0x0 reg6=0x0 reg7=0x0
Resubmitted odp: drop
Resubmitted megaflow: r e c i r c _ i d = 0 , i p , i n _ p o r t = 1 , d l _ s r c = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 / 0 1 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ,
nw_dst=10.0.0.1,nw_frag=no
R u l e : tab le=1 cookie=0 i p , n w _ d s t = 1 0 . 0 . 0 . 1
OpenFlow action s=mod _d l_d st:00:00:00:00:00:01,ou tp u t:2
F i n a l flo w: ip,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:00,dl_dst=00:00:00:00:00:01,
nw_src=0.0.0.0,nw_dst=10.0.0.1,nw_proto=0,nw_tos=0,nw_ecn=0,nw_ttl=0
Megaflow: r e c i r c _ i d = 0 , i p , i n _ p o r t = 1 , d l _ s r c = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 / 0 1 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ,
d l_d st=00:00:00:00:00:00,n w_d st=10.0.0.1,n w_frag=n o
Datapath a c t i o n s : s e t ( e t h ( s r c = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 / 0 1 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 , d s t = 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 1 ) ) , 5