rubyで創るopenflowネットワーク - llまつり

44
インターネットマルチフィード株式会社 技術部 川上 雄也 (@yuyarin) 2013/08/24 LLまつり

Upload: yuya-rin

Post on 15-Jan-2015

12.744 views

Category:

Technology


5 download

DESCRIPTION

Rubyで創るOpenFlowネットワーク - LLまつり 2013/08/24 Sat 14:30 JST http://ll.jus.or.jp/2013/program.html#ruby_openflow LLプログラマ向けの発表です

TRANSCRIPT

  • 1. (@yuyarin) 2013/08/24 LL

2. 2 1. (2) 2. SDNOpenFlow(10) 3. Trema(8) reference 3. 3 (@yuyarin) 20084 20114 NTT 20118 JPNAP 10/100GbE(L2)DWDMBGP JANOG30&31InteropTokyo2012&2013 wakamonog, 4. 4 Ruby 5. 5 6. 6 SDN48 Software Defined Network 7. 7 (CLI)(NMS) Control Plane Data Plane App/Service Control Plane Data Plane App/Service Control Plane Data Plane App/Service CLI/NMS/Tool Router/Switch Router/Switch Router/Switch 8. 8SDN API Agent Data Plane Switch API Agent Data Plane SwitchAgent Data Plane Switch Controller CLI/NMS/Tool Controller 9. 9SDN 10. 10 SDN OpenFlow 11. 11 OpenFlow 12. 12 13. 13 ` L2 MAC MAC Ethernet Type VLAN ID VLAN Priority IP IP IP Protocol L3 L4 14. 14 Forward L2SW STPflood Drop Set-Queue (Enqueue) Modify-Field VLAN 15. 15 MACVLAN IDIP Packet-In Packet-Out 16. 16Forward OFCForward OFSWForward Agent Data Plane OFSwitch Agent Data Plane OFSwitchAgent Data Plane OFSwitch Controller OFController FlowTable FlowMod Forward FlowMod 17. 17Packet-InPacket-Out OFCPacket-InOFC OFC Packet-Out Agent Data Plane OFSwitch Agent Data Plane OFSwitchAgent Data Plane OFSwitch Controller OFController FlowTable Forward FlowMod Packet-In Packet-Out 18. 18OpenFlow OpenFlow L2L4 19. 19OpenFlow (1) OpenFlow MAC NextHopARPMAC L2SW 20. 20OpenFlow (2) OFSW Packet-In OFCPacket-InHW IPv41 3 21. 21OpenFlow / 22. 22OpenFlow Ver. Framework 1.0 NOX(C++), POX(Python), Trema(C, Ruby), Floodlight(Java) 1.1 1.2 POX1.2(Python) 1.3 Trema-edge(C, Ruby), Floodlight(Java) 23. 23 Trema 24. 24 Whats Trema? Full-Stack OpenFlow Framework in Ruby and C 25. 25Why Trema? Trema 26. 26 Trema TeX Ruby 27. 27 TremaOpenFlow Trema OpenFlow 1.0 Ruby 1.8.7 http://trema.github.io/trema/ Trema-edge OpenFlow 1.3 Ruby 2.0.0-p0 @Ubuntu12.04 64-bit https://github.com/trema/trema-edge 28. 28 Trema-edge 1. Ubuntu 12.04 (64-bit) 2. RVM curl -L https://get.rvm.io | bash -s stable 3. sudo apt-get install gcc make libsqlite3-dev libpcap-dev libssl-dev git 4. trema-edgeclone git clone https://github.com/trema/trema-edge.git cd trema-edge 5. Ruby 2.0.0-p0 rvm install ruby-2.0.0-p0 rvm use 2.0.0-p0 -default 6. trema-edge bundle install rake ./trema --version 29. 29 Trema trema run -d mycontroller.rb trema run mycontroller.rb -c mynetwork.conf trema send_packets -source host1 -dest host2 trema show_stats host1 -r 30. 30 require MyNetworkLib class MyController < Controller periodic_timer_event: , def end ... private def end ... end 31. 31 handler start switch_ready OF switch_disconnected OF packet_in Packet-In flow_removed port_status 32. 32 handler send_flow_mod_add send_flow_mod_delete send_flow_mod_modify send_packet_out Packet-Out 33. 33 class MyController < Controller def switch_ready datapath_id action = SendOutPort.new( port_number: OFPP_CONTROLLER, max_len: OFPCML_NO_BUFFER ) apply_ins = ApplyAction.new( actions: [ action ] ) send_flow_mod_add( datapath_id, priority: OFP_LOW_PRIORITY, buffer_id: OFP_NO_BUFFER, instructions: [ apply_ins ] ) end def packet_in datapath_id, message # ... send_flow_mod_add( datapath_id, :match => Match.new( :in_port => message.in_port, ...), :actions => [ StripVlanHeader.new, SendOutPort.new(port_no) ] ) send_packet_out( datapath_id, :packet_in => message ) end # ... end Packet-In Packet-In Packet-In 34. 34MACL2 (1/2) class LearningSwitch < Controller def start @fdb = FDB.new end def switch_ready datapath_id action = SendOutPort.new( port_number: OFPP_CONTROLLER, max_len: OFPCML_NO_BUFFER ) ins = ApplyAction.new( actions: [ action ] ) send_flow_mod_add( datapath_id, priority: OFP_LOW_PRIORITY, buffer_id: OFP_NO_BUFFER, flags: OFPFF_SEND_FLOW_REM, instructions: [ ins ] ) end def packet_in datapath_id, message @fdb.learn message.eth_src, message.in_port port_no = @fdb.port_no_of( message.eth_dst ) if port_no flow_mod datapath_id, message, port_no packet_out datapath_id, message, port_no else flood datapath_id, message end end MAC Packet-Out Packet-In 35. 35MACL2 (2/2) private def flow_mod datapath_id, message, port_no action = SendOutPort.new( port_number: port_no ) ins = Instructions::ApplyAction.new( actions: [ action ] ) send_flow_mod_add( datapath_id, match: ExactMatch.from( message ), instructions: [ ins ]) end def packet_out datapath_id, message, port_no action = Actions::SendOutPort.new( port_number: port_no ) send_packet_out( datapath_id, packet_in: message, actions: [ action ] ) end def flood datapath_id, message packet_out datapath_id, message, OFPP_ALL end end 36. 36 trema_switch( "lsw" ) { datapath_id "0xabc" } vhost ("host1") { ip "192.168.0.1" netmask "255.255.0.0" mac "00:00:00:01:00:01" } vhost ("host2") { ip "192.168.0.2" netmask "255.255.0.0" mac "00:00:00:01:00:02" } link "host1", "lsw:1" link "host2", "lsw:2" Open vSwitch lsw Trema Controller phost host1 phost host2 1 2 37. 37 describe RepeaterHub do it "" do network { vswitch( "switch" ) { dpid "0xabc" } vhost( "host1" ) { promisc "on" } vhost( "host2" ) { promisc "on" } vhost( "host3" ) { promisc "on" } link "switch", "host1" link "switch", "host2" link "switch", "host3" }.run( RepeaterHub ) { send_packets "host1", "host2" # host2 host3 vhost( "host2" ).stats( :rx ).should have( 1 ).packets vhost( "host3" ).stats( :rx ).should have( 1 ).packets } end end 38. 38 39. 39 40. 40 Client1 192.168.0.1 Client2 192.168.0.2 Client3 192.168.0.3 Client4 192.168.0.4 Client5 192.168.0.5 Server1 10.0.0.1 00:00:00:00:00:01 Server2 10.0.0.1 00:00:00:00:00:01 Server3 10.0.0.1 00:00:00:00:00:01 LB Trema 41. 41 IPMAC Ethernet/IP IP 7 8-bit (backet-size 256) 42. 42demo 43. 43Ruby 44. 44