Bài viết này sẽ Giới Thiệu Về Fauce. Nếu bạn cần hỗ trợ, xin vui lòng liên hệ VinaHost qua Hotline 1900 6046 ext.3, email về support@vinahost.vn hoặc chat với VinaHost qua livechat https://livechat.vinahost.vn/chat.php.
1. Faucet là gì?
Faucet được giới thiệu là một bộ điều khiển OpenFlow mã nguồn mở nhỏ gọn, cho phép các nhà phát triển có thể vận hành hệ thống mạng giống như các cục máy chủ clusters.
Các tính năng điều khiển network (giao thức định tuyến, tìm kiếm hàng xóm – neighbor discovery, thuật toán chuyển mạch) sẽ được chuyển sang chạy độc lập trên các máy chủ vật lý hoặc hạ tầng ảo hóa hypervisor hoặc nền tảng cloud.
Dễ dàng quản lý, kiểm tra, vận hành, bảo trì và mở rộng bằng các công cụ quản lý hệ thống mới nhất.
So với các thiết bị Cisco, Juniper truyền thống, các tính năng liệt kể ở trên sẽ được hãng assem firmware vào phần cứng của thiết bị.
2. Gauge là gì?
Faucet gồm 2 bộ điều khiển OpenFlow chính, gồm Faucet (đã giới thiệu ở trên) và Gauge.
Faucet có chức năng kiểm soát các trạng thái forwarding và switch state. Ví dụ trạng thái của các host PC bên trong, có thể monitor Graph thông qua Prometheus
Gauge có chức năng kết nối các switch và giám sát port và flow state (đẩy các metric sang Prometheus hoặc InfluxDB để lưu trữ time-series). Sau đó có thể dùng các dashboard của Grafana để query vào database table và đọc metric từ đó ra.
Mô hình gồm các thành phần cơ bản của 1 SDN Faucet:
3. Cài đặt Faucet
Có nhiều cách cài đặt faucet bao gồm:
+ Cài thông qua apt package manager trên debian/ubuntu/raspbian/raspberry
+ Cài thông qua docker (Khuyến cáo cho người dùng có kinh nghiệm sử dụng docker)
+ Cài thông qua pip package của python 3.5+
Ở bài viết này, mình hướng dẫn các bạn cài thông qua tool apt, cách cài còn có thể tham khảo và test ở link sau:
https://docs.faucet.nz/en/latest/installation.html
Chạy các lệnh sau để cài đặt gói faucet-all-in-one, bao gồm các thành phần sau:
Component | Purpose |
faucet | Network controller |
gauge | Monitoring controller |
prometheus | Monitoring system & time series database |
grafana | Monitoring dashboard |
Nếu bạn chưa cần test tới prometheus và grafana. Có thể disable 2 daemon services này đi.
# Install faucet, prometheus sudo apt-get install curl gnupg apt-transport-https lsb-release echo "deb https://packagecloud.io/faucetsdn/faucet/$(lsb_release -si | awk '{print tolower($0)}')/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/faucet.list sudo curl -1sLf https://packagecloud.io/faucetsdn/faucet/gpgkey -o /etc/apt/trusted.gpg.d/faucet.asc sudo apt-get update sudo apt-get install faucet-all-in-one
Sau khi cài đặt hoàn tất, ta kiểm tra xem các service đã start và mở port trên máy chủ, hình dưới cho thấy server ryu-manager (faucet) và prometheus đã hoạt động và public các port dịch vụ ra bên ngoài:
root@ubuntu:~# ss -lntp | column -t State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:9302 *:* users:(("ryu-manager",pid=9552,fd=6)) LISTEN 0 128 *:22 *:* users:(("sshd",pid=1364,fd=3)) LISTEN 0 50 *:9303 *:* users:(("ryu-manager",pid=9607,fd=6)) LISTEN 0 50 *:6653 *:* users:(("ryu-manager",pid=9552,fd=7)) LISTEN 0 50 *:6654 *:* users:(("ryu-manager",pid=9607,fd=7)) LISTEN 0 128 :::9090 :::* users:(("prometheus",pid=9113,fd=5)) LISTEN 0 128 :::9100 :::* users:(("prometheus-node",pid=9420,fd=6)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=1364,fd=4))
Cài đặt thêm gói openvswitch để hoạt động với faucet:
# Install Open vSwitch
sudo apt-get install openvswitch-switch
Sau khi đã cài đặt đủ các thành phần để sử dụng, ta tiến hành tạo bài lab đơn giản để test thử tính năng và cách hoạt động của Faucet
Mô hình đầu tiên:
+ Tạo 1 openvswitch
+ Tạo vlan 100
+ Tạo 2 host, đặt IP cho 2 host
+ Join 2 host vào cùng card br0 và ping kết nối
Backup lại file config faucet
root@ubuntu:~# cp /etc/faucet/faucet.yaml{,.backup}
Add 2 function sau vào cuối file ~/.bashrc và run lệnh: source ~/.bashrc
# Run command inside network namespace as_ns () { NAME=$1 NETNS=faucet-${NAME} shift sudo ip netns exec ${NETNS} $@
}
# Create network namespace
create_ns () { NAME=$1 IP=$2 NETNS=faucet-${NAME} sudo ip netns add ${NETNS} sudo ip link add dev veth-${NAME} type veth peer name veth0 netns ${NETNS} sudo ip link set dev veth-${NAME} up as_ns ${NAME} ip link set dev lo up [ -n "${IP}" ] && as_ns ${NAME} ip addr add dev veth0 ${IP} as_ns ${NAME} ip link set dev veth0 up }
Bây giờ chúng ta sẽ chạy lệnh commandline để tạo host1, host2, gán IP, tạo bridge0 như mô hình trên:
# Tạo host 1, host 2 và gán IP cho host
create_ns host1 192.168.0.1/24 create_ns host2 192.168.0.2/24 Configure Open vSwitch
Tạo openvswitch Bridge0 và gán 2 port tương ứng 2 host 1-2
sudo ovs-vsctl add-br br0 \ -- set bridge br0 other-config:datapath-id=0000000000000001 \ -- set bridge br0 other-config:disable-in-band=true \ -- set bridge br0 fail_mode=secure \ -- add-port br0 veth-host1 -- set interface veth-host1 ofport_request=1 \ -- add-port br0 veth-host2 -- set interface veth-host2 ofport_request=2 \ -- set-controller br0 tcp:127.0.0.1:6653 tcp:127.0.0.1:6654
Lúc này file config faucet.yaml sẽ giống như bên dưới:
include: - acls.yaml vlans: office: vid: 100 description: "office network" #routers: # router-office-guest: # vlans: [office, guest] # dps: sw1: dp_id: 0x1 hardware: "Open vSwitch" interfaces: 1: name: "host1" description: "host1 network namespace" native_vlan: office 2: name: "host2" description: "host2 network namespace" native_vlan: office
Sau khi edit file config faucet, cần dùng tool để kiểm tra định dạng file config có lỗi không trước khi thực hiện reload service
root@ubuntu:~# check_faucet_config /etc/faucet/faucet.yaml
Nếu file config bị lỗi syntax sẽ xuất thông báo ra terminal, ngược lại sẽ show 1 list thông báo dạng json là bạn đang cấu hình đúng.
Nếu xuất thông báo lỗi, chúng ta có thể truy cập đường dẫn sau để kiểm tra output error và nắm được chuyện gì đang xảy ra trong hệ thống
root@ubuntu:~# tail /var/log/openvswitch/ovs-vswitchd.log
hoặc
root@ubuntu:~# tail /var/log/faucet/faucet.log
…
Jul 31 22:49:24 faucet.valve INFO DPID 1 (0x1) sw1 L2 learned on Port 1 7a:96:b9:65:3d:03 (L2 type 0x0806, L2 dst ff:ff:ff:ff:ff:ff, L3 src 192.168.0.1, L3 dst 192.168.0.2) Port 1 VLAN 100 (1 hosts total)
Jul 31 22:49:24 faucet.valve INFO DPID 1 (0x1) sw1 L2 learned on Port 2 9a:3c:01:3a:da:a4 (L2 type 0x0806, L2 dst 7a:96:b9:65:3d:03, L3 src 192.168.0.2, L3 dst 192.168.0.1) Port 2 VLAN 100 (2 hosts total)
…
Mọi thứ có vẻ ổn, thực hiện ping test từ host1 sang host2, như vậy là thành công:
root@ubuntu:~# as_ns host1 ping 192.168.0.2 PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data. 64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.865 ms 64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=0.053 ms 64 bytes from 192.168.0.2: icmp_seq=3 ttl=64 time=0.061 ms ^C --- 192.168.0.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1998ms rtt min/avg/max/mdev = 0.053/0.326/0.865/0.381 ms
Ngoài ra có thể test băng thông bằng tool iperf3 huyền thoại:
root@ubuntu:/etc/faucet# as_ns host1 iperf3 --server --daemon root@ubuntu:/etc/faucet# as_ns host2 iperf3 --client 192.168.0.1 Connecting to host 192.168.0.1, port 5201 [ 4] local 192.168.0.2 port 38794 connected to 192.168.0.1 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 2.46 GBytes 21.2 Gbits/sec 0 467 KBytes [ 4] 1.00-2.00 sec 2.52 GBytes 21.7 Gbits/sec 0 467 KBytes [ 4] 2.00-3.00 sec 2.68 GBytes 23.1 Gbits/sec 0 527 KBytes [ 4] 3.00-4.00 sec 2.61 GBytes 22.5 Gbits/sec 0 527 KBytes [ 4] 4.00-5.00 sec 2.58 GBytes 22.1 Gbits/sec 0 585 KBytes [ 4] 5.00-6.00 sec 2.64 GBytes 22.7 Gbits/sec 0 585 KBytes [ 4] 6.00-7.00 sec 2.61 GBytes 22.4 Gbits/sec 61 454 KBytes [ 4] 7.00-8.00 sec 2.61 GBytes 22.5 Gbits/sec 0 513 KBytes [ 4] 8.00-9.00 sec 2.31 GBytes 19.8 Gbits/sec 227 426 KBytes [ 4] 9.00-10.00 sec 2.30 GBytes 19.8 Gbits/sec 365 349 KBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-10.00 sec 25.3 GBytes 21.8 Gbits/sec 653 sender [ 4] 0.00-10.00 sec 25.3 GBytes 21.8 Gbits/sec receiver
Mô hình thứ 2: test access control list
+ Tạo 1 openvswitch
+ Tạo vlan 100
+ Tạo 4 host, đặt IP cho 4 host
+ Join 4 host vào cùng card br0 và ping kết nối
+ Limit 1 trong 4 host không thể ping tới 3 host còn lại
Chúng ta tạo thêm host3 và host4:
root@ubuntu:~# create_ns host3 192.168.0.3/24 root@ubuntu:~# create_ns host4 192.168.0.4/24
# Gán 2 port br0 tới 2 host vừa tạo thêm
root@ubuntu:~# sudo ovs-vsctl add-port br0 veth-host3 -- set interface veth-host3 ofport_request=3 \ > -- add-port br0 veth-host4 -- set interface veth-host4 ofport_request=4
Thêm nội dung vào block dps trong file faucet.yaml
dps: sw1: dp_id: 0x1 hardware: "Open vSwitch" interfaces: .... 3: name: "host3" native_vlan: office acls_in: [block-ping, allow-all] 4: name: "host4" native_vlan: office acls: block-ping: - rule: dl_type: 0x800 # IPv4 ip_proto: 1 # ICMP actions: allow: False - rule: dl_type: 0x86dd # IPv6 ip_proto: 58 # ICMPv6 actions: allow: False allow-all: - rule: actions: allow: True
Kiểm tra syntax faucet:
check_faucet_config /etc/faucet/faucet.yaml
Reload dịch vụ:
systemctl reload faucet
Lúc này đứng từ host 1 không thể ping tới host 3 nhưng có thể ping 2 host còn lại bình thường:
# ping host 3 root@ubuntu:~# as_ns host1 ping 192.168.0.3 PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data. ^C --- 192.168.0.3 ping statistics --- 8 packets transmitted, 0 received, 100% packet loss, time 7056ms
# ping host 2 root@ubuntu:~# as_ns host1 ping 192.168.0.2 -c 1 PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data. 64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.632 ms --- 192.168.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.632/0.632/0.632/0.000 ms # ping host 4 root@ubuntu:~# as_ns host1 ping 192.168.0.4 -c 1 PING 192.168.0.4 (192.168.0.4) 56(84) bytes of data. 64 bytes from 192.168.0.4: icmp_seq=1 ttl=64 time=0.320 ms --- 192.168.0.4 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.320/0.320/0.320/0.000 ms Mô hình thứ 3: testing Vlan và ACL trên Vlan + Tạo 1 openvswitch + Tạo vlan 100, 200, 300 + Tạo 9 host và đặt IP + Limit ping vlan 300 theo chiều IN
Topo mạng như sau:
Các mode của Vlan:
- Native: packet gửi đến switch với no tag 802.1Q
- Tagged: packet gửi đến switch với tag 802.1Q
- Mixed: kết hợp cả 2 native và tagged mode trên cùng port
Các lệnh khởi tạo openvswitch và các vhost:
root@ubuntu:~# cleanup root@ubuntu:~# create_ns host1 192.168.0.1/24 root@ubuntu:~# create_ns host2 192.168.0.2/24 root@ubuntu:~# sudo ovs-vsctl add-br br0 \ > -- set bridge br0 other-config:datapath-id=0000000000000001 \ > -- set bridge br0 other-config:disable-in-band=true \ > -- set bridge br0 fail_mode=secure \ > -- add-port br0 veth-host1 -- set interface veth-host1 ofport_request=1 \ > -- add-port br0 veth-host2 -- set interface veth-host2 ofport_request=2 \ > -- set-controller br0 tcp:127.0.0.1:6653 tcp:127.0.0.1:6654 root@ubuntu:~# create_ns host3 0.0.0.0 root@ubuntu:~# create_ns host4 0.0.0.0 root@ubuntu:~# add_tagged_interface host3 100 192.168.0.3/24 root@ubuntu:~# add_tagged_interface host4 100 192.168.0.4/24 root@ubuntu:~# create_ns host5 192.168.2.5/24 root@ubuntu:~# create_ns host6 192.168.2.6/24 root@ubuntu:~# create_ns host7 0.0.0.0 root@ubuntu:~# create_ns host8 0.0.0.0 root@ubuntu:~# add_tagged_interface host7 300 192.168.3.7/24 root@ubuntu:~# add_tagged_interface host8 300 192.168.3.8/24
# Ở host 9, ta sẽ tạo đường trunk và add cả 3 vlan 100, 200, 300 cho host9
root@ubuntu:~# create_ns host9 0.0.0.0 root@ubuntu:~# add_tagged_interface host9 100 192.168.0.9/24 root@ubuntu:~# add_tagged_interface host9 200 192.168.2.9/24 root@ubuntu:~# add_tagged_interface host9 300 192.168.3.9/24 root@ubuntu:~# sudo ovs-vsctl add-port br0 veth-host3 -- set interface veth-host3 ofport_request=3 \ > -- add-port br0 veth-host4 -- set interface veth-host4 ofport_request=4 \ > -- add-port br0 veth-host5 -- set interface veth-host5 ofport_request=5 \ > -- add-port br0 veth-host6 -- set interface veth-host6 ofport_request=6 \ > -- add-port br0 veth-host7 -- set interface veth-host7 ofport_request=7 \ > -- add-port br0 veth-host8 -- set interface veth-host8 ofport_request=8 \ > -- add-port br0 veth-host9 -- set interface veth-host9 ofport_request=9
Cấu hình faucet.yaml
include: - acls.yaml vlans: vlan100: vid: 100 description: "office network" vlan200: vid: 200 vlan300: vid: 300 acls_in: [block-ping] # Apply ACL only on vlan300 #routers: # router-office-guest: # vlans: [office, guest] # dps: sw1: dp_id: 0x1 hardware: "Open vSwitch" interfaces: 1: name: "host1" description: "host2 network namespace" native_vlan: vlan100 2: name: "host2" description: "host2 network namespace" native_vlan: vlan100 3: name: "host3" tagged_vlans: [vlan100] 4: name: "host4" tagged_vlans: [vlan100] 5: name: "host5" native_vlan: vlan200 6: name: "host6" native_vlan: vlan200 7: name: "host7" tagged_vlans: [vlan300] 8: name: "host8" tagged_vlans: [vlan300] 9: name: "host9" tagged_vlans: [vlan100,vlan200,vlan300] acls: block-ping: - rule: dl_type: 0x800 # IPv4 ip_proto: 1 # ICMP actions: allow: False - rule: dl_type: 0x86dd # IPv6 ip_proto: 58 # ICMPv6 actions: allow: False allow-all: - rule: actions: allow: True
Kiểm tra syntax faucet:
check_faucet_config /etc/faucet/faucet.yaml
Reload dịch vụ:
systemctl reload faucet
Testing:
- Ping kiểm tra kết nối trong nội bộ các vlan (yêu cầu phải hoạt động bình thường)
root@ubuntu:~# as_ns host1 ping 192.168.0.2 -c 1 PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data. 64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=1.14 ms --- 192.168.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 1.145/1.145/1.145/0.000 ms root@ubuntu:~# as_ns host3 ping 192.168.0.4 PING 192.168.0.4 (192.168.0.4) 56(84) bytes of data. 64 bytes from 192.168.0.4: icmp_seq=1 ttl=64 time=0.646 ms ^C --- 192.168.0.4 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.646/0.646/0.646/0.000 ms root@ubuntu:~# as_ns host5 ping 192.168.2.6 -c 1 PING 192.168.2.6 (192.168.2.6) 56(84) bytes of data. 64 bytes from 192.168.2.6: icmp_seq=1 ttl=64 time=0.859 ms --- 192.168.2.6 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.859/0.859/0.859/0.000 ms
Vlan 300 không thể ping được do lúc đầu chúng ta đã apply ACL deny gói tin ICMP
root@ubuntu:~# as_ns host7 ping 192.168.3.8 -c 1 PING 192.168.3.8 (192.168.3.8) 56(84) bytes of data. From 192.168.3.7 icmp_seq=1 Destination Host Unreachable
--- 192.168.3.8 ping statistics --- 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
- Ping kết nối từ trong nội bộ vlan, từ host1 untagged tới host3 tagged
root@ubuntu:~# as_ns host1 ping 192.168.0.3 PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data. 64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=0.497 ms
--- 192.168.0.3 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.497/0.497/0.497/0.000 ms
- Ping kết nối từ host1(native Vlan100) tới host5 (native Vlan 200) (không thể kết nối do ta chưa thực hiện định tuyến giữa các Vlan)
root@ubuntu:~# as_ns host5 ip address add 192.168.0.5 dev veth0 root@ubuntu:~# as_ns host1 ping 192.168.0.5 -c 1 PING 192.168.0.5 (192.168.0.5) 56(84) bytes of data. --- 192.168.0.5 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms
- Ping từ các host ở các vlan khác nhau tới host9 (yêu cầu phải hoạt động được do host9 đã được add link trunk)
root@ubuntu:~# as_ns host1 ping 192.168.0.9 -c 1 PING 192.168.0.9 (192.168.0.9) 56(84) bytes of data. 64 bytes from 192.168.0.9: icmp_seq=1 ttl=64 time=0.599 ms
--- 192.168.0.9 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms root@ubuntu:~# as_ns host5 ping 192.168.2.9 -c 1 PING 192.168.2.9 (192.168.2.9) 56(84) bytes of data. 64 bytes from 192.168.2.9: icmp_seq=1 ttl=64 time=0.838 ms --- 192.168.2.9 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.838/0.838/0.838/0.000 ms
# Host 7 sẽ không thể ping tới IP 192.168.3.9 của host9 do đã apply ACL deny ICMP trên Vlan 300
root@ubuntu:~# as_ns host7 ping 192.168.3.9 -c 1 PING 192.168.3.9 (192.168.3.9) 56(84) bytes of data. From 192.168.3.7 icmp_seq=1 Destination Host Unreachable
--- 192.168.3.9 ping statistics --- 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
Khi thực hiện comment dòng acls_in: [block-ping] trong file faucet.yaml và reload service, chúng ta có thể ping từ host7 (vlan 300) tới host9 (vlan 300) bình thường:
root@ubuntu:~# as_ns host7 ping 192.168.3.9 -c 1 PING 192.168.3.9 (192.168.3.9) 56(84) bytes of data. 64 bytes from 192.168.3.9: icmp_seq=1 ttl=64 time=0.862 ms --- 192.168.3.9 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.862/0.862/0.862/0.000 ms
Chúc bạn thực hiện thành công!
THAM KHẢO CÁC DỊCH VỤ TẠI VINAHOST
>> SERVER – COLOCATION – CDN
>> HOSTING
>> WEBSITE
>> TÊN MIỀN