46
TUTORIAL MININET

TUTORIAL MININET

Embed Size (px)

Citation preview

TUTORIAL MININET

Introducción

Es una plataforma para la emulación de redes. Permite la creación de hosts, switches, controladores y links en una única máquina física o virtual.

Vm-mininet Descargue la imagen de la máquina virtual del siguiente link: http://mirror.pop-rs.rnp.br/openflow/vm-mininetut.ova •  En el LAB-Universidad de Cuenca Acender a la carpeta

\\172.16.48.2\install-arq\CursoOpenflow\ Todos los archivos necesarios están aí USUARIO: Administrador CONTRASENHA: Dfeuc2012

X11

•  Si esta ejecutando la machina virtual en Windows o Linux necesita instalar el X11 o otro X-Manager Para Windows es necesario instalar Xming Para MacOSX es necesario instalar XQuartz

VM-mininet Solo haga click en el archivo .OVA O… Vá al menú File, y seleccionar la opción import y en el menu seguiente, seleccionar la imagen .ova descargada, y selecione next.

Vm-mininet

Selecione a opção import e espere até que a importação seja concluida. Si quiera ponga más memoria RAM

Configuraciones iniciales

Virtual Box: l  Antes de poner en marcha la máquina virtual ir a Configuracion → sistema → processador y marcar la opción enable PAE/NX si no estea, este paso es necesario para que posteriormente nos sea posible utilizar xterm. l 

Configuraciones iniciales

•  Inicie la VM

•  Una vez realizado esto acceder a la máquina Virtual de forma remota con (ssh)

Sudo ssh -Y -p2222 openflow@localhost (A opção -Y serve para permitir o xforwarding para o uso do xterm)

•  Si usa Putty o otro cliente ssh es necesario habilitar el acesso de X11 para la session ssh

Configuraciones Windows/Putty

Configuraciones Windows/Putty

Cómo usar el Mininet (checkout)

1.  Dispara la VM-Openflow en VirtualBox (play) 2.  Dispara X11 (Xming) 3.  Dispara SSH (Putty) 4.  Hace Login en La VM-Openflow (user:openflow

contraseña:openflow) 5.  Intenta ejecutar a “xterm” y vea se na ventana

si abre 6.  Si llegaste ai esta listo!!! Si no vuelve al paso 1 7.  Si ni así es conseguido llama al instructor

EL MININET

Leyenda

Hx → Host Sx → Switch Cx → Controller

$ → comando en shell # → comandos como root Mininet> → comandos dentro de mininet

Utilizando Mininet

$Sudo mn Inicia mininet con una topología default con 1 switch, 1 controlador y 2 hosts.

Dentro de mininet use los comandos nodes y net para ver los nodos y sus enlaces.

Utilizando mininet Syntaxys:

mininet>[nodo] comando l  Colocando el nodo frente a un comando, indicamos que el comando esta siendo ejecutado en aquel nodo

l  Es posible utilizar el nombre del nodo para sustituir la IP.

mininet>h2 ping -c5 h3

Utilizando o mininet

mininet>exit Salir de mininet

mininet>xterm [nodo] Abre un terminal para el nodo.

mininet>link [node1][node2][up or down] Crea o elimina un o link entre dos nodos

mininet>pingall Prueba conectividad entre dos nodos

mininet>help Ayuda, muestra lista de comandos de

mininet #mn -c

Limpia la topología

Comandos:

Topología

A continuación se explicarán 4 tipos de topologias que pueden ser utilizadas en Mininet: •  single, •  linear, •  tree y •  custom.

Topologías

Single Un switch conectado a N hosts. Se crea con el siguiente comando: $sudo mn --topo single,N N es el número de hosts deseados.

Topologia

Linear Cada switch se conecta con otro de forma linear, y cada switch tiene un host conectado. $sudo mn --topo linear,N N será el número de switches y hosts.

Topologia

Tree

Crea una topologia de arbor con profundidad N y anchura M.

$sudo mn --topo tree,depth=n,fanout=m

Topologia Custom

Para topologias customizadas es necesario crear un archivo en python con su topología.

$sudo mn --custom mytopo.py --topo mytopo

Las topologías customizadas se quedan en ./mininet/custom

Topología

Arquivo mytopo.py from mininet.topo import Topo, Node class MyTopo( Topo ): def __init__( self, enable_all = True ): # Add default members to class. super( MyTopo, self ).__init__() # Set Node IDs for hosts and switches Switch1 = 1 Switch2 = 2 Switch3 = 3 Switch4 = 4 Host1 = 5 Host2 = 6 Host3 = 7 Host4 = 8 Host5 = 9 # Add nodes self.add_node( Switch1, Node( is_switch=True ) ) self.add_node( Switch2, Node( is_switch=True ) ) self.add_node( Switch3, Node( is_switch=True ) ) self.add_node( Switch4, Node( is_switch=True ) )

self.add_node( Host1, Node( is_switch=False ) ) self.add_node( Host2, Node( is_switch=False ) ) self.add_node( Host3, Node( is_switch=False ) ) self.add_node( Host4, Node( is_switch=False ) ) self.add_node( Host5, Node( is_switch=False ) ) # Add edges self.add_edge( Host1, Switch1 ) self.add_edge( Host2, Switch1 ) self.add_edge( Switch1, Switch2 ) self.add_edge( Switch1, Switch3 ) self.add_edge( Switch2, Switch4 ) self.add_edge( Switch3, Switch4 ) self.add_edge( Switch4, Host3 ) self.add_edge( Switch4, Host4 ) self.add_edge( Switch4, Host5 ) # Consider all switches and hosts 'on' self.enable_all() topos = { 'mytopo': ( lambda: MyTopo() ) }

Ejemplo topología customizada:

Topologia

Para Cargar las configuraciones de los hosts de un archivo.

#mytopo-cli py "CONFIGURANDO IPS DOS HOSTS...." h5 ifconfig h5-eth0 10.0.0.5/24 h6 ifconfig h6-eth0 10.0.0.6/24 h7 ifconfig h7-eth0 10.0.0.7/24 h8 ifconfig h8-eth0 10.0.0.8/24 h9 ifconfig h9-eth0 10.0.0.9/24 py "CONFIGURANDO ROTAS DEFAULT...." h5 route add default h5-eth0 h6 route add default h6-eth0 h7 route add default h7-eth0 h8 route add default h8-eth0 h9 route add default h9-eth0 py "=== REDE CONFIGURADA ===" net dump

Configuración de nuevas topologías:

#mn --pre [arquivo]

mininet>source [script]

Para cargar un script en python para ser ejecutado en mininet

Aplicaciones gráficas

Sudo ~/mininet/examples/miniedit.py

Aplicaciones gráficas

Sudo ~/mininet/examples/consoles.py

Switch

Switch implementado en userspace, pasa entre el modo usuario y el kernel a cada salto.

User space

$Sudo mn --switch user

switch Openvswitch:

Más dificil de implementar por ser basado em kernel, entretanto tiene una performace mucho mayor.

$Sudo mn --switch ovsk

Controlador

$sudo mn --controller remote --ip [ip] --port [porta]

Inicia el nox escuchando un controlador externo

$sudo -E mn --controller nox_pysw

Inicia el nox utilizando la aplicación pyswitch

Controlador

El controlador que iremos utilizar como ejemplo és NOX, un controlador echo en C y python. Para empezarlo precisamos estar el la pasta de su núcleo, el nox_core (./noxcore/build/src).

Controlador

Para ejecutarlo: $./nox_core -v -i ptcp: “porta” “nome_do_modelo” La puerta default que el controlador escucha es la 6633, y el modelo adoptado para los testes fue una modificación de lo pyswitch.py

Inserción de Flujos - Dpctl

El comando dpctl permite la inserción, visualización y remoción de las tablas de flujos en los switches, entre otros. Para visualizar el estado de los switches, el dpid y mac de las suyas interfaces podremos usar la opción show. $dpctl show Para visualizar la tabla de flujos usamos la opción dump-flow. $dpctl dump-flows

Dpctl

Para la inserción de un flujo manualmente podemos usar a opción add-flow, que debe ser seguida por la coneción, flujo y ación. $ dpctl add-flow tcp:127.0.0.1:6634 in_port=1,actions=output:2 Podemos remover los flujos de un switch con la opción del-flows. $ dpctl del-flows tcp:127.0.0.1:6634

Topologia usada

Algoritmo y código usados

se switch = 1 { se in_port = 1,entonces outport = 3 se in_port = 3,entonces outport = 1 se in_port = 2,entonces outport = 4 se in_port = 4,entonces outport = 2 } se switch = 2 { se in_port = 1,entonces out_port = 2 se in_port = 2,entonces out_port = 1 } se switch = 3 { se in_port = 1,entonces out_port = 2 se in_port = 2,entonces out_port = 1

if dpid == 1: if inport == 1: flow = { core.IN_PORT : 1 } actions = [[openflow.OFPAT_OUTPUT, [0, 3]]] elif inport == 3: flow = { core.IN_PORT : 3 } actions = [[openflow.OFPAT_OUTPUT, [0, 1]]] elif inport == 2: flow = { core.IN_PORT : 2 } actions = [[openflow.OFPAT_OUTPUT, [0, 4]]] elif inport == 4: flow = { core.IN_PORT : 4 } actions = [[openflow.OFPAT_OUTPUT, [0, 2]]]

Algoritmo usado

se switch = 1 { se in_port = 1,entonces outport = 3 se in_port = 3,entonces outport = 1 se in_port = 2,entonces outport = 4 se in_port = 4,entonces outport = 2 } se switch = 2 { se in_port = 1,entonces out_port = 2 se in_port = 2,entonces out_port = 1 } se switch = 3 { se in_port = 1,entonces out_port = 2 se in_port = 2,entonces out_port = 1

elif dpid == 2 or dpid == 3: if inport == 1: flow = { core.IN_PORT : 1 } actions = [[openflow.OFPAT_OUTPUT, [0, 2]]] elif inport == 2: flow = { core.IN_PORT : 2 } actions = [[openflow.OFPAT_OUTPUT, [0, 1]]]

Algoritmo usado

elif dpid == 4: if ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.9': flow = { core.NW_DST : extract_flow(packet)['nw_dst'] } actions = [[openflow.OFPAT_OUTPUT, [0, 5]]] if ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.7': flow = { NW_DST : extract_flow(packet)['nw_dst'] } actions = [[openflow.OFPAT_OUTPUT, [0, 3]]]

} se switch = 4 { se ip_destino = 10.0.0.9, out_port = 5 se ip origem 10.0.0.9 {

se ip_destino = 10.0.0.7,entonces out_port = 3 se ip_destino = 10.0.0.8,entonces out_port = 4 se ip_destino = 10.0.0.5,entonces out_port = 1 se ip_destino = 10.0.0.6,entonces out_port = 2

Código usado

if ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.8': flow = { core.NW_DST : extract_flow(packet)['nw_dst'] } actions = [[openflow.OFPAT_OUTPUT, [0, 4]]] if ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.5': flow = { core.NW_DST : extract_flow(packet)['nw_dst'] } actions = [[openflow.OFPAT_OUTPUT, [0, 1]]] if ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.6': flow = { core.NW_DST : extract_flow(packet)['nw_dst'] } actions = [[openflow.OFPAT_OUTPUT, [0, 2]]]

} se switch = 4 { se ip_destino = 10.0.0.9, out_port = 5 se ip origem 10.0.0.9 {

se ip_destino = 10.0.0.7,entonces out_port = 3 se ip_destino = 10.0.0.8,entonces out_port = 4 se ip_destino = 10.0.0.5,entonces out_port = 1 se ip_destino = 10.0.0.6,entonces out_port = 2

Código usado se in_port = 1 e ip_destino = 10.0.0.7,entonces out_port = 3 se in_port = 3 e ip_destino = 10.0.0.5,entonces out_port = 1 se in_port = 2 e ip_destino = 10.0.0.8,entonces out_port = 4 se in_port = 4 e ip_destino = 10.0.0.6,entonces out_port = 2

elif inport == 1 and ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.7': flow = { core.NW_DST : extract_flow(packet)['nw_dst'], core.IN_PORT : 1 } actions = [[openflow.OFPAT_OUTPUT, [0, 3]]] elif inport == 3 and ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.5': flow = { core.NW_DST : extract_flow(packet)['nw_dst'], core.IN_PORT : 3 } actions = [[openflow.OFPAT_OUTPUT, [0, 1]]] elif inport == 2 and ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.8': flow = { core.NW_DST : extract_flow(packet)['nw_dst'], core.IN_PORT : 2 } actions = [[openflow.OFPAT_OUTPUT, [0, 4]]] elif inport == 4 and ip_to_str(extract_flow(packet)['nw_dst']) == '10.0.0.6': flow = { core.NW_DST : extract_flow(packet)['nw_dst'], core.IN_PORT : 4 } actions = [[openflow.OFPAT_OUTPUT, [0, 2]]]

caso contrario envía un paquete para todas las puertas retorna da funcion

} instala los flujos

Código usado se in_port = 1 e ip_destino = 10.0.0.7,entonces out_port = 3 se in_port = 3 e ip_destino = 10.0.0.5,entonces out_port = 1 se in_port = 2 e ip_destino = 10.0.0.8,entonces out_port = 4 se in_port = 4 e ip_destino = 10.0.0.6,entonces out_port = 2

} instala los flujos

inst.install_datapath_flow(dpid, flow, CACHE_TIMEOUT, openflow.OFP_FLOW_PERMANENT, actions, bufid, prioridade, inport, buf)

else inst.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport)

return

caso contrario envía un paquete para todas las puertas retorna de la función

Fluxos dpctl s1 dpctl add-flow tcp:127.0.0.1:6634 in_port=1,priority=1,idle_timeout=0,actions=output:3 s1 dpctl add-flow tcp:127.0.0.1:6634 in_port=3,priority=1,idle_timeout=0,actions=output:1 s1 dpctl add-flow tcp:127.0.0.1:6634 in_port=2,priority=1,idle_timeout=0,actions=output:4 s1 dpctl add-flow tcp:127.0.0.1:6634 in_port=4,priority=1,idle_timeout=0,actions=output:2 s2 dpctl add-flow tcp:127.0.0.1:6635 in_port=1,priority=1,idle_timeout=0,actions=output:2 s2 dpctl add-flow tcp:127.0.0.1:6635 in_port=2,priority=1,idle_timeout=0,actions=output:1 s3 dpctl add-flow tcp:127.0.0.1:6636 in_port=1,priority=1,idle_timeout=0,actions=output:2 s3 dpctl add-flow tcp:127.0.0.1:6636 in_port=2,priority=1,idle_timeout=0,actions=output:1 s4 dpctl add-flow tcp:127.0.0.1:6637 ip,nw_dst=10.0.0.9,priority=10,idle_timeout=0,actions=output:5 s4 dpctl add-flow tcp:127.0.0.1:6637 in_port=1,idle_timeout=1200,priority=1,idle_timeout=0,actions=output:3 s4 dpctl add-flow tcp:127.0.0.1:6637 in_port=3,idle_timeout=1200,priority=1,idle_timeout=0,actions=output:1 s4 dpctl add-flow tcp:127.0.0.1:6637 in_port=2,idle_timeout=0,priority=1,actions=output:4 s4 dpctl add-flow tcp:127.0.0.1:6637 in_port=4,idle_timeout=0,priority=1,actions=output:2 s4 dpctl add-flow tcp:127.0.0.1:6637 ip,nw_src=10.0.0.9,nw_dst=10.0.0.5,priority=10,idle_timeout=0,actions=output:1 s4 dpctl add-flow tcp:127.0.0.1:6637 ip,nw_src=10.0.0.9,nw_dst=10.0.0.6,priority=10,idle_timeout=0,actions=output:2 s4 dpctl add-flow tcp:127.0.0.1:6637 ip,nw_src=10.0.0.9,nw_dst=10.0.0.7,priority=10,idle_timeout=0,actions=output:3 s4 dpctl add-flow tcp:127.0.0.1:6637 ip,nw_src=10.0.0.9,nw_dst=10.0.0.8,priority=10,idle_timeout=0,actions=output:4

Exercício

Empieza mininet con la topología mytopo.py en ./mininet/custom e insiera os flujos dpctl do slide anterior. Tente pingar todos os nodos e ver se están se comunicando como deberían? Apuntamiento: El archivo flujos-dpctl ya estan con flujos . Use el comando source nombe-del-archivo para cargar-lo.

Exercício

Porque los flujos de h9 no funcionaran correctamente?

Ejercicio

Adiciona los flujos arp abajo y haga la prueba otra vez. s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,nw_dst=10.0.0.9,actions=output:5 s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,in_port=2,nw_dst=10.0.0.8,actions=output:4 s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,in_port=1,nw_dst=10.0.0.7,actions=output:3 s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,in_port=4,nw_dst=10.0.0.6,actions=output:2 s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,in_port=3,nw_dst=10.0.0.5,actions=output:1 s4 dpctl add-flow tcp:127.0.0.1:6637 priority=1,idle_timeout=0,arp,in_port=5,actions=flood

Y ahora? Verifique la tabla arp de los hosts y mira se están correctas.

Exercício

Abra la misma topología en el mininet y ejecute el nox usando el modelo pyswitch.py. Teste la conectividad de los hosts. Para empezar lo nox vá en ./noxcore/build/src/ y use el comando ./nox_core -v -i ptcp: pyswitch

Referencias

http://yuba.stanford.edu/foswiki/bin/view/OpenFlow/Mininet

http://www.openflow.org/wk/index.php/OpenFlow_Tutorial

Dudas?

[email protected]