sábado, 15 de março de 2014

Webservices no POX

Para o suporte de Webservices no POX, o módulo openflow.webservice deve ser carregado junto do controlador:
./pox.py log.level --DEBUG  web.webcore openflow.webservice samples.pretty_log
Note que neste exemplo o módulo forwarding.l2_learning não foi carregado, ou seja, o POX não instalará fluxos no switches OF automaticamente para eles se comportarem como "switches"
Se você rodar o mininet em uma outra janela, os hosts não irão se pingar, pois não existem fluxos instalados no controlador:
sudo mn --controller remote  (um switch e dois hosts)
Para instalar um fluxo no switch, envie via curl (em outra janela) o seguinte comando para o controlador, que transformará o switch OF  em um HUB, permitindo a comunicação entre os hosts:
curl -i -X POST -d '{"method":"set_table","params":{"dpid":"00-00-00-00-00-01","flows":[{"actions":[{"type":"OFPAT_OUTPUT","port":"OFPP_ALL"}],"match":{}}]},"id":0}' http://127.0.0.1:8000/OF/
Agora o pingall do mininet deverá funcionar.
Para verificar os fluxos instalados no switch 1:
curl -i -X POST -d '{"method":"get_flow_stats","params":{"dpid":"00-00-00-00-00-01"},"id":0}' http://127.0.0.1:8000/OF/

Um outro exemplo é

./pox.py log.level --DEBUG forwarding.l2_learning web.webcore openflow.webservice
Note que o módulo forwarding.l2_learning também foi carregado, ou seja, não será necessário instalar fluxos via curl.

Rode o mininet em outra janela:
sudo mn --topo linear,4 --controller remote (quatro switches em linha, 1 host por switch)

Por exemplo, para ver os fluxos instalados no switch 4 após um pingall no mn, o comando é:
curl -i -X POST -d '{"method":"get_flow_stats","params":{"dpid":"00-00-00-00-00-04"},"id":0}' http://127.0.0.1:8000/OF/

Para listar os switches instalados no controlador:
curl -i -X POST -d '{"method":"get_switches", "id":0}' http://127.0.0.1:8000/OF/

Este post abaixo, do site http://www.noxrepo.org/2012/09/pox-web-interfaces/  diz que o melhor modo de se utilizar webservices é com o módulo ajax_transport, pois a comunicação do POX com a aplicação é bidirecional, avisando a aplicação quando há a entrada de um pacote no switch :
"The other major way to work with OpenFlow over the web is via the OpenFlow messenger service (openflow.of_service) coupled with one of the messenger’s web transports (e.g., ajax_transport). This is what POXDesk does — you can use it as an example if you want to check it out. As far as I recall, the only real reason to do this now is that it supports notifications like packet_ins."

Um comentário: