Download - 話題のOpenFlowをフル活用! OpenVNetで仮想ネットワークを実現しよう!
話題のOpenFlowをフル活用! OpenVNetで仮想ネットワークを!
実現しよう!
株式会社あくしゅ 横川晃
!1
自己紹介
• 名前: 横川 晃(よこかわ あきら)
• 株式会社あくしゅ
• 好きなこと: スポーツ、旅行、語学
• Twitter: @_akira_ @oO_akira_Oo
• Facebook: akira.yokokawa
!2
もくてき
• OpenFlowってどんなものかわかるようになる
• フローがよめるようになる
• OpenVNetの仕組みが大体わかるようになる
!3
・L2とL3の簡単なおさらい ・OpenFlowってなに? * OpenFlowのしくみについて * 周辺技術の紹介 ・OpenVNet開発について - 経緯 - 設計・実装 ・OpenVNetテストについて ・OpenVNet今後の計画
Agenda
!4
OSI参照モデル
物理層
データリンク層
ネットワーク層
トランスポート層
セッション層
プレゼンテーション層
アプリケーション層
IPなど
TCP, UDP
Ethernet, PPPなど
!5
OSI参照モデル
データリンク層
ネットワーク層 IPなど
Ethernet, PPPなど
第2層、第3層に関して 実際のネットワーク機器上ではどんな動きをするのか 軽くおさらいします
のちに説明する、OpenVNetの仕組みを理解する上でも役立ちます
!6
第2層:データリンク層
• Ethernet frameと呼ばれる下記のデータを扱う
Payload FCSEthertypeMAC (source)
MAC (destination)
46~1500バイト 4バイト2バイト6バイト6バイト
!7
L2スイッチの挙動
• MACアドレスとポートの一覧を保持する • 初めはからっぽ
1 2 3 4
IP = X MAC = A
AB
MACアドレス ポート番号
IP = Y MAC = B
!8
L2スイッチの挙動
1 2 3 4
AB
MACアドレス ポート番号
IP = X MAC = A
パケットが届くとMACアドレスとポート番号のペアを 記憶する
!9
A 1
L2スイッチの挙動
1 2 3 4
AB
MACアドレス ポート番号
A 1
IP = Y MAC = B
他のマシンがスイッチにつながった場合も 同様にしてMACアドレスとポート番号を記憶
B 3
!10
L2スイッチの挙動
1 2 3 4
AB
MACアドレス ポート番号
A 1
MACアドレステーブルの情報に従い フレームを送信するポートを決定する
B 3
!11
Bへパケットを送信
第3層:ネットワーク層
Payload FCSEthertypeMAC (source)
MAC (destination)
46~1500バイト 4バイト2バイト6バイト6バイト
PayloadTCP ヘッダ
IP ヘッダ
20バイト 20バイト 40~1460バイト
!12
L3ルータの挙動
1 2 3 4
A B
192.168.1.0/24 192.168.2.0/24
宛先 ルータ ホップ ポート
192.168.1.0 - 0 1
192.168.2.0 - 0 4
• 宛先IPアドレスを読み宛先ネットワークを決定
• ルーティングテーブルを参照し送信先を決定
!13
複数ルータ間の挙動
1 2 3 4
A B
192.168.1.0/24 192.168.2.0/24
宛先 ルータ ホップ ポート
192.168.1.0 - 0 1
192.168.2.0 210.99.47.1 1 4
1 2 3 4130.82.12.1 210.99.47.1
宛先 ルータ ホップ ポート
192.168.2.0 - 0 4
192.168.1.0 130.82.12.1 1 1
ダイナミックルーティングの場合 EGP等で経路情報を交換
!14
まとめ• L2:スイッチではMACアドレスを基に制御
• MACアドレスとポートのペアをキャッシュ
• L3:ルータではIPアドレスを基に制御
• ルーティングテーブルを参照して送信先決定
つづいてOpenFlowの説明に移ります
!15
What is OpenFlow?
• 2009年スタンフォード大での研究が発端
• http://archive.openflow.org/wp/2009/12/openflow-1-0-released/
• ONF(Open Networking Foundation)が管理
• OpenFlowスイッチをプログラムするプロトコル
• 今まで中のソフトウェアは非公開
• ソフトウェアが外出しになってプログラムできる
!16
OpenFlow Versioning History• 1.0 - 2009年12月31日
• 1.1 - 2011年2月28日
• 1.2 - 2011年12月5日
• 1.3 - 2012年6月25日
• 1.4 - 2013年10月15日
OpenVNetは1.3に対応
!17
OpenFlow: プロトコルの説明
OpenFlowスイッチに対してOpenFlowプロトコル でやりとりしスイッチの挙動をプログラム
• セキュアチャンネルでコントローラとスイッチを接続
• OpenFlowバージョンの確認
• スイッチの情報の確認
• パケットの受信
• フローの更新!18
セキュアチャンネルでコントローラとスイッチを接続
抜粋The switch must be able to establish communication with a controller at a user-configurable (but otherwise fixed) IP address, using a user-specified port. If the switch knows the IP address of the controller, the switch initiates a standard TLS or TCP connection to the controller.
出典:OpenFlow Switch Specification version 1.3.0
1 2 3 OpenFlowコントローラ
tcp://192.168.2.102:6379
!19
セキュアチャンネルでコントローラとスイッチを接続
A typical OpenFlow controller manages multiple OpenFlow channels, each one to a different OpenFlow switch. An OpenFlow switch may have one OpenFlow channel to a single controller, or multiple channels for reliability, each to a different controller.
1 2 3 OpenFlowコントローラ2
OpenFlowコントローラ1
1 2 3
出典:OpenFlow Switch Specification version 1.3.0
複数コントローラ、スイッチの構成も可能
!20
OpenFlowバージョンの確認When an OpenFlow connection is first established, each side of the connection must immediately send an OFPT_HELLO message with the version field set to the highest OpenFlow protocol version supported by the sender.
出典:OpenFlow Switch Specification version 1.3.0
1 2 3 OpenFlowコントローラ
バージョン 1.3
バージョン 1.3
サポートしてる最新のバージョンを教えあう
!21
スイッチの情報の確認Features: The controller may request the capabilities of a switch by sending a features request; the switch must respond with a features reply that specifies the capabilities of the switch. This is commonly performed upon establishment of the OpenFlow channel.
出典:OpenFlow Switch Specification version 1.3.0
1 2 3 OpenFlowコントローラ
FEATURE_REQUEST
FEATURE_REPLY
• Datapath ID • ポートの一覧など
Datapath?スイッチとかブリッジと同じと思ってください
!22
パケットの受信When packets are received by the datapath and sent to the controller, they use the OFPT_PACKET_IN message:
出典:OpenFlow Switch Specification version 1.3.0
1 2 3 OpenFlowコントローラ
PACKET_IN
• data … パケットの中身
• reason … なんでpacket_inしたか
• match … どのポートから入ったのかなど
• cookie … フロー毎につけられるIDのようなもの!23
フローの更新
1 2 3 OpenFlowコントローラ
FLOW_MOD
PACKET_OUT
フローの更新はFLOW_MODメッセージでやりとり
PACKET_OUTで受け取ったパケットを戻す
フローってどんな感じになってるのか?!24
[root@itest1 ~]# ovs-ofctl dump-flows br0 NXST_FLOW reply (xid=0x4): cookie=0x900000000000000, duration=11102.212s, table=0, n_packets=5551, n_bytes=288652, idle_age=1, priority=1,tun_id=0 actions=drop cookie=0x900000000000000, duration=11102.211s, table=0, n_packets=0, n_bytes=0, idle_age=11102, priority=2,in_port=CONTROLLER actions=write_metadata:0x4040000000000/0x40c0000000000 cookie=0x500000000000003, duration=11101.919s, table=0, n_packets=0, n_bytes=0, idle_age=11101, priority=2,in_port=3 actions=write_metadata:0x700040000000007/0xff000c007fffffff cookie=0x5000000fffffffe, duration=11101.919s, table=0, n_packets=0, n_bytes=0, idle_age=11101, priority=2,in_port=LOCAL actions=write_metadata:0x40000000000/0xc0000000000 cookie=0x900000000000000, duration=11102.211s, table=0, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=write_metadata:0x80000000000/0xc0000000000 cookie=0x500000000000296, duration=11102.049s, table=3, n_packets=0, n_bytes=0, idle_age=11102, priority=30,in_port=662 actions=drop cookie=0x900000000000000, duration=11102.212s, table=3, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop cookie=0x900000000000000, duration=11102.212s, table=4, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop cookie=0xc00001300000001, duration=11101.729s, table=6, n_packets=0, n_bytes=0, idle_age=11101, priority=30,dl_src=02:01:00:00:00:01 actions=write_metadata:0x700000000000001/0xff0000007fffffff cookie=0x900000000000000, duration=11102.212s, table=6, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop cookie=0x900000000000000, duration=11102.212s, table=7, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop cookie=0x900000000000000, duration=11102.212s, table=8, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop cookie=0x900000000000000, duration=11102.212s, table=9, n_packets=0, n_bytes=0, idle_age=11102, priority=0 actions=drop
!25
cookie=0x500000000000296, duration=11102.049s, table=3, n_packets=0, n_bytes=0, idle_age=11102, priority=30,in_port=662 actions=drop
match action
matchの条件に該当したパケットに対して、 actionで指定されている処理を適用する このフローの場合はパケットを破棄する
!26
フローの例:その1
cookie=0x900000000000000, duration=85917.793s, table=0, n_packets=0, n_bytes=0, priority=2,in_port=2 actions=goto_table:7
match in_port=2
action actions=goto_table:7
2番ポートからパケットが入ってきたら、 7番テーブルへ処理を移す
OpenVNetではテーブルごとに処理したい内容を分けてる!27
フローの例:その2
cookie=0xc00001200000001, duration=85916.453s, table=10, n_packets=42960, n_bytes=2233920, priority=10,metadata=0x700000000000001/0xff0000007fffffff actions=drop
matchmetadata=0x700000000000001/0xff0000007fffffff
actionactions=drop
value mask
!28
フローの例:その3
metadata=0x700000000000001/0xff0000007fffffff
value mask64ビットのレジスタ
metadata & mask == value
Pipeline processing instructions allow packets to be sent to subsequent tables for further processing and allow information, in the form of metadata, to be communicated between tables.
!29
metadata
出典:OpenFlow Switch Specification version 1.3.0
OpenFlow Switches
• いろんなOpenFlowスイッチ
• ソフトウェア実装
• Open vSwitch
• OpenVNetではこれつかってる
!30
OpenFlow Controller
• OpenFlowをしゃべるプログラム
• OpenVNetでもコントローラを定義
• Tremaというフレームワークをつかっている
!31
Trema
• C言語で開発
• Rubyから利用できるフレームワーク
• 開発元:NEC
• GitHub上で管理
• https://github.com/trema/trema
!32
# -*- coding: utf-8 -*- !require 'racket' require 'trema/actions' require 'trema/instructions' require 'trema/messages' !module Vnet::Openflow ! class Controller < Trema::Controller include TremaTasks include Celluloid::Logger include Vnet::Constants::Openflow ! def features_reply(dpid, message) info "features_reply from %#x." % dpid ! datapath = datapath(dpid) || raise("No datapath found.") datapath.switch.async.features_reply(message) end !! def port_status(dpid, message) debug "port_status from %#x." % dpid ! datapath = datapath(dpid) datapath.switch.async.port_status(message) if datapath && datapath.switch end ! def packet_in(dpid, message) dp_info = dp_info(dpid) return unless dp_info ! case message.cookie >> COOKIE_PREFIX_SHIFT when COOKIE_PREFIX_INTERFACE dp_info.interface_manager.async.packet_in(message) when COOKIE_PREFIX_TRANSLATION dp_info.translation_manager.async.packet_in(message) when COOKIE_PREFIX_ROUTE_LINK dp_info.router_manager.async.packet_in(message) when COOKIE_PREFIX_SERVICE dp_info.service_manager.async.packet_in(message) when COOKIE_PREFIX_CONNECTION dp_info.connection_manager.async.packet_in(message) end end !33
OpenVNetの設計・実装
!34
What is OpenVNet?
• Spin-off project from Wakame-vdc
• 5 developers
• 2279 commits
• Written in Ruby
• 16512 LOCs (5257 LOCs test codes)
• Started March 2013
���35
Why OpenVNet?
• There are many products offering network virtualization but not free
• Is there any product to freely try out network virtualization?
• Wakame-vdc offers network virtualization
• Extract virtual network functionality from Wakame-vdc to make an independent package
���36
Advantages of OpenVNet
• Users can create complex networks on top of OpenVNet
• Keep the physical networks simple
Reduce the maintaining cost of the physical networks
• Edge-overlay architecture enables creating complex multi-tenant networks
No need expensive network switches
• e.g.) quickly preparing an isolated network for experiment
Freely and easily create/destroy networks
���37
Internal Architecture of OpenVNet
���38
Network model of datacenter
Internet
Datacenter network
Physical/Virtual server clusters
DNAT / LB
SNAT DHCP DNS
���39
Deployment of agent program
Internet
Datacenter network
Physical/Virtual server clusters
DNAT / LB
SNAT DHCP DNS
Deploy agents for packet control
agent agent agent
agent agent agent
���40
Message queue
Internet
Datacenter network
Physical/Virtual server clusters
DNAT / LB
SNAT DHCP DNS
agent agent agent
agent agent agent
Queue
Agents communicate to each other through message queue system
���41
Components of OpenVNet
Internet
Datacenter network
Servers
vna vna vna
vna vna vna
Queue
vnmgr
vnapivnctl
DB
OpenFlow Controller
(Trema-edge)
vnaOpenFlow Switch
(OpenvSwitch 1.10.0)
OpenFlow 1.3
http
mysql
zeromq
���42
Components of OpenVNetvna (virtual network agent)
vnmgr (virtual network manager)
vnapi (virtual network API)
Agent
other components
• Configure OpenvSwitch (version 1.10.0)
• Include an OpenFlow controller implemented with Trema-edge
• Manage the datacenter network
• Provide database access back-ended by MySQL
• Command vna to do some specific actions e.g.) update flows
• WebAPI to talk to vnmgr
vnctl (virtual network controller)
• Command line interface to use vnapi���43
Network model of datacenter
Internet
Datacenter network
External network
WAN edge network
Datacenter physical network
LAN edge network
Physical/Virtual server clusters
General servers
Appliance servers
Storage servers
Resources
DNAT / LB
SNAT DHCP DNS
���44
Deployment
External network
WAN edge network
Datacenter physical network
LAN edge network
General servers
Appliance servers
Storage servers
Resources
Open vSwitch
eth0 eth1
VM
vna Open vSwitch
eth0 eth1
VM
vna
public line
management line
A dedicated line for management
Packets for the service go through the public line
���45
MAC2MAC
Open vSwitch
eth0 eth1
vnaOpen
vSwitch
eth0 eth1
vna
public line
Suppose that both VM1 and VM2 exist on the same virtual network
VM2VM1
MAC = 00:00:00:00:01 IP = 10.102.0.10
virtual network1
MAC = 00:00:00:00:02 IP = 10.102.0.11
���46
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
virtual network1 !VM1 = 00:00:00:00:01 VM2 = 00:00:00:00:02
both vna know that VM1 and VM2 exist on virtual network1
���47
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
VM1 sends ARP request
src_ip = 10.102.0.10 dst_ip = 10.102.0.11 src_mac = 00:00:00:00:00:01 dst_mac = ff:ff:ff:ff:ff:ff
���48
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Open vSwitch broadcasts the packet
src_ip = 10.102.0.10 dst_ip = 10.102.0.11 src_mac = 00:00:00:00:00:01 dst_mac = ff:ff:ff:ff:ff:ff
���49
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
The other hosts receive the packet
src_ip = 10.102.0.10 dst_ip = 10.102.0.11 src_mac = 00:00:00:00:00:01 dst_mac = ff:ff:ff:ff:ff:ff
���50
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Open vSwitch checks the src_mac, then it founds the packet is of virtual network1
!src_mac = 00:00:00:00:00:01
���51
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Remember src_mac in case of other packets whose destination is 00:00:00:00:00:01
!dst_mac = 00:00:00:00:00:01 ⇛ output:eth0
���52
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Forward a packet according to the network
src_ip = 10.102.0.10 dst_ip = 10.102.0.11 src_mac = 00:00:00:00:00:01 dst_mac = ff:ff:ff:ff:ff:ff
���53
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
ARP reply comes in the Open vSwitch
src_ip = 10.102.0.11 dst_ip = 10.102.0.10 src_mac = 00:00:00:00:00:02 dst_mac = 00:00:00:00:00:01
���54
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Open vSwitch knows that the packet should be forwarded to eth0
src_ip = 10.102.0.11 dst_ip = 10.102.0.10 src_mac = 00:00:00:00:00:02 dst_mac = 00:00:00:00:00:01
!dst_mac = 00:00:00:00:00:01 ⇛ output:eth0
���55
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
The packet is forwarded from eth0
src_ip = 10.102.0.11 dst_ip = 10.102.0.10 src_mac = 00:00:00:00:00:02 dst_mac = 00:00:00:00:00:01
���56
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
The another host receives the ARP reply packet
src_ip = 10.102.0.11 dst_ip = 10.102.0.10 src_mac = 00:00:00:00:00:02 dst_mac = 00:00:00:00:00:01
���57
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Remember the source mac address
dst_mac = 00:00:00:00:00:02 ⇛ output:eth0
���58
MAC2MAC
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Output the packet to the specific VM
src_ip = 10.102.0.11 dst_ip = 10.102.0.10 src_mac = 00:00:00:00:00:02 dst_mac = 00:00:00:00:00:01
���59
GRE Tunnel
Open vSwitch
eth0 eth1
VM1
vnaOpen
vSwitch
eth0 eth1
VM2
vna
public line
Open vSwitch
eth0 eth1
VM3
vna
L3 switch
Prepare GRE tunnels in case of L3 routing required
Use MAC2MAC over GRE tunnels
GRE tunnel
���60
Security Groups
L3レベルでパケットのフォワーディングルールを 設定できる。
• ユーザによるルールの設定
• コネクショントラッキング
• リファレンスを用いたルール指定
OpenVNetで実装されているファイヤーウォール
!61
ユーザによるルールの設定
プロトコル、ポート、IPアドレスを指定する
tcp:22:10.1.0.0/24
udp:53:192.168.2.100
icmp:-1:0.0.0.0
• 10.1.0.0/24のネットワークからtcp22番ポートのアクセスを受け付ける
• 192.168.2.100からudp53番ポートのアクセスを受け付ける
• 全てのicmpパケットを受け付ける(ポート番号はなんでもいい)!62
ユーザによるルールの設定
インスタンスのNICに対してuuidを指定する
tcp:22:10.0.0.0/24
udp:53:192.168.2.100
icmp:-1:0.0.0.0
VM1eth0VM2
eth0
同じセキュリティグループに 所属する
sg-test1
!63
ユーザによるルールの設定
ルールはフローとしてdatapathに設定される
tcp:22:10.0.0.0/24
udp:53:192.168.2.100
icmp:-1:0.0.0.0
VM1eth0
VM2eth0
Open vSwitch
eth0 eth1
vna
同じグループ間は 通信可能
!64
コネクショントラッキング
tcp:22:10.0.0.0/24
udp:53:192.168.2.100
icmp:-1:0.0.0.0
VM1eth0
VM2eth0
10.0.0.10 10.0.0.11
sg-test2sg-test1
ルールなし
ssh49617 22
!65
コネクショントラッキング
VM1eth0
VM2eth0
10.0.0.10 10.0.0.11
Open vSwitch
vna
コントローラで2つのフローを作成する
tcp,dl_src=00:18:51:e5:33:66,nw_src=10.0.0.10,nw_dst=10.0.0.11,tp_src=49617,tp_dst=22 actions=goto_table:TABLE_NETWORK_SRC_CLASSIFIER(20)
tcp,metadata=TYPE_INTERFACE(0x1),dl_dst=00:18:51:e5:33:66,nw_src=10.0.0.11,nw_dst=10.0.0.10,tp_src=22,tp_dst=49617 actions=goto_table:TABLE_OUT_PORT_INTERFACE_INGRESS(90)
10.0.0.10から11への接続を許可するフロー
10.0.0.11から10への接続を許可するフロー
!66
OpenVNetのテストについて• インスタンス同士の疎通確認がしたい
• openvnet-testspec • RSpecで記述
• https://github.com/axsh/openvnet-testspec
!67
OpenVNetのテストについて
• ymlによるDBの管理
• シナリオベースでの疎通確認
• 同datapathにいるインスタンス同士
• remote datapathにいる場合
• L3を超える場合とそうでない場合
• vnet同士のルーティング
• セキュリティグループ
• VNetEdge!68
Jenkinsでのジョブ管理
!69
ジョブの流れ
Jenkins Master
Slave3
Slave2
Slave1 br0 br1
VM1 VM2 VM3
Unit test rpmbuild
create repo
integration test
ssh
GRE tunnel
!70
!71
HipChat Notification• 社内で使っているChatツール - https://www.hipchat.com
• Jenkinsがジョブの結果を通知
Wakame Users Groupへのおさそい
• Wakame-vdcとかOpenVNetについての勉強会です
• 2014年7月25日(金)19:00より
• 株式会社KDDI ウェブコミュニケーションズ様 (麹町)
!72
http://wakameusersgroup.org