
프로덕션 네트워크에서 네트워크 문제 해결을 돕는 OpenFlow 스니퍼
OFP_Sniffer는 문제 해결 및 학습 목적으로 사용되는 OpenFlow 스니퍼입니다.
현재 버전 1.2이며, 모든 OpenFlow 1.0 메시지를 분석하고, InfluxDB, Grafana, Slack과 함께 작동합니다. OpenFlow 1.3은 곧 출시될 OFP_Sniffer 버전 1.3에서 사용 가능합니다.
Linux 셸에서 직접 작동하며, 유선 상이나 libpcap 파일로부터 모든 OpenFlow 메시지를 분석합니다. OFP_Sniffer를 사용하면 X11 또는 Wireshark를 열지 않고도 OpenFlow 메시지와 관련 오류(있는 경우)를 쉽게 추적할 수 있습니다. OFP_Sniffer는 AmLight SDN 배포(www.sdn.amlight.net)를 지원하기 위해 Python 3.6으로 작성되었습니다. AmLight SDN은 Internet2 FlowSpace Firewall, OESS 및 On.Lab ONOS를 사용하며, 이러한 앱들은 테스트되었고 완전히 지원됩니다.
명령줄 인터페이스 도구로서, 몇 가지 입력 매개변수가 있습니다:
# ./ofp_sniffer.py -h
Usage:
./ofp_sniffer.py [-p min|full] [-f pcap_filter] [-F filter_file] [-i dev] [-r pcap_file]
-p : print all TCP/IP headers. Default: min
-f pcap_filter or --pcap-filter=pcap_filter: add a libpcap filter
-F filters_file.json or --filters-file=filters.json
-i interface or --interface=interface. Default: eth0
-r captured.pcap or --src-file=captured.pcap
-T topology.json or --topology-file=topology.json
-w file or --save-to-file=file: save output to file provided
-o or --print-ovs : print using ovs-ofctl format
-h or --help : prints this help
-c or --no-colors: removes colors
-v or --version : prints version
-O WARN:CRIT or --oess-fvd=WARN:CRIT: monitor OESS FVD status
-N or --notify-via-slack: send notifications via Slack. Param is the Slack channel
-S or --enable-statistics: creates statistics
버전 1.0부터는 특정 요구를 처리하기 위한 앱이 지원됩니다. 예를 들어 OESS FVD 메시지 추적, REST를 통한 통계 생성, NMS(예: Zabbix) 통합 등이 있습니다.
More info: https://amlight.net/wp-content/uploads/2015/03/wpeif-2016-ofpsniffer.pdf
##################### 설치 ######################
Requires Python 3.6
git clone https://github.com/amlight/ofp_sniffer.git
cd ofp_sniffer
pip3.6 install -r docs/requirements.txt
sudo ./ofp_sniffer.py
##################### 예제 #########################
아래에 예제가 제공됩니다:
---------------------- -------------------------
| Mininet | | OVS-OFCTL 2.3.0 |
| 192.168.56.101:6634| <-------> | eth1 - 192.168.56.102 |
---------------------- -------------------------
# ovs-ofctl dump-flows tcp:192.168.56.101:6634
cookie=0x0, duration=2183.377s, table=0, n_packets=0, n_bytes=0, idle_age=2183, in_port=1,dl_vlan=2 actions=output:2
# ./ofp_sniffer.py -i eth1 -f " or port 6634"
Sniffing device eth1
2015-09-13 11:47:38.655503 192.168.56.102:37450 -> 192.168.56.101:6634 Size: 74
OpenFlow Version: 1.0(1) Type: Hello(0) Length: 8 XID: 1
1 OpenFlow Hello
2015-09-13 11:47:38.656964 192.168.56.101:6634 -> 192.168.56.102:37450 Size: 74
OpenFlow Version: 1.0(1) Type: Hello(0) Length: 8 XID: 174
174 OpenFlow Hello
2015-09-13 11:47:38.657638 192.168.56.102:37450 -> 192.168.56.101:6634 Size: 86
OpenFlow Version: 1.0(1) Type: Vendor(4) Length: 20 XID: 2
2 OpenFlow Vendor : NICIRA(0x2320)
2 OpenFlow Vendor Data: 12 2
2015-09-13 11:47:38.657870 192.168.56.102:37450 -> 192.168.56.101:6634 Size: 74
OpenFlow Version: 1.0(1) Type: BarrierReq(18) Length: 8 XID: 3
3 OpenFlow Barrier Request
2015-09-13 11:47:38.659270 192.168.56.101:6634 -> 192.168.56.102:37450 Size: 74
OpenFlow Version: 1.0(1) Type: BarrierRes(19) Length: 8 XID: 3
3 OpenFlow Barrier Reply
# ovs-ofctl add-flow tcp:192.168.56.101:6634 "dl_dst=10:00:00:01:20:00,dl_type=0x88bc actions=mod_vlan_vid:14,output:2"
# ./ofp_sniffer.py -i eth1 -f " or port 6634"
2015-09-13 11:49:08.171463 192.168.56.102:37451 -> 192.168.56.101:6634 Size: 154
OpenFlow Version: 1.0(1) Type: FlowMod(14) Length: 88 XID: 2
2 OpenFlow Match - wildcards: 3678439 dl_type: 0x88bc dl_dst: 10:00:00:01:20:00
2 OpenFlow Body - Cookie: 0x00 Command: Add(0) Idle/Hard Timeouts: 0/0 Priority: 32768 Buffer ID: 0xffffffff Out Port: 65535 Flags: Unknown Flag(0)
2 OpenFlow Action - Type: SetVLANID Length: 8 VLAN ID: 14 Pad: 0
2 OpenFlow Action - Type: OUTPUT Length: 8 Port: 2 Max Length: 0
# ovs-ofctl del-flows tcp:192.168.56.101:6634 "dl_type=0x88bc,dl_dst=10:00:00:01:20:00, "
2015-09-13 11:50:43.636925 192.168.56.102:37454 -> 192.168.56.101:6634 Size: 138
OpenFlow Version: 1.0(1) Type: FlowMod(14) Length: 72 XID: 2
2 OpenFlow Match - wildcards: 3678439 dl_type: 0x88bc dl_dst: 10:00:00:01:20:00
2 OpenFlow Body - Cookie: 0x00 Command: Delete(3) Idle/Hard Timeouts: 0/0 Priority: 32768 Buffer ID: 0xffffffff Out Port: 65535 Flags: Unknown Flag(0)
# ovs-ofctl add-flow tcp:192.168.56.101:6634 "dl_dst=10:00:00:01:20:00,dl_type=0x88bc actions=mod_vlan_vid:14,output:2"
2015-09-13 11:52:58.563737 192.168.56.102:37455 -> 192.168.56.101:6634 Size: 154
OpenFlow Version: 1.0(1) Type: FlowMod(14) Length: 88 XID: 2
2 OpenFlow Match - wildcards: 3678439 dl_type: 0x88bc dl_dst: 10:00:00:01:20:00
2 OpenFlow Body - Cookie: 0x00 Command: Add(0) Idle/Hard Timeouts: 0/0 Priority: 32768 Buffer ID: 0xffffffff Out Port: 65535 Flags: Unknown Flag(0)
2 OpenFlow Action - Type: SetVLANID Length: 8 VLAN ID: 14 Pad: 0
2 OpenFlow Action - Type: OUTPUT Length: 8 Port: 2 Max Length: 0
필터 사용:
-F ./filters.json 옵션을 사용하면 몇 가지 옵션이 있습니다:
"rejected_of_types" : 보고 싶지 않은 OpenFlow 메시지 유형을 선택하는 데 사용됩니다. OpenFlow 버전에 따라 다른 필터를 정의할 수 있습니다.
Ethertype별 필터:
PacketOut 또는 PacketIn 메시지로 전송되는 특정 Ethertype을 찾고 있다면, 다른 모든 것을 거부하여 쉽게 시각화할 수 있습니다.
예제:
"filters":{
"ethertypes": {
"lldp" : 0,
"fvd" : 0,
"arp" : 1,
"others": [ "88b5" ]
},
"packetIn_filter": {
"switch_dpid": "any",
"in_port": "any"
},
"packetOut_filter": {
"switch_dpid": "any",
"out_port": "any"
}
}
}
ethertypes 섹션에서 1은 필터, 0은 출력을 의미합니다. 제공된 예제에서는 ARP 메시지가 보이지 않고 OESS FVD와 LLDP는 표시됩니다. "others" 섹션에 Ethertype 16진수(0x 제외)를 추가할 수 있으며, 쉼표(",")로 구분하면 됩니다.
"packetIn_filter": 보고 싶은 PacketIn + LLDP 메시지를 정의하는 데 사용됩니다. 스위치별 및/또는 포트별로 정의할 수 있습니다. 스위치의 경우 사용 중인 애플리케이션에서 보는 datapath_id를 사용해야 합니다. 예를 들어, 일부 앱은 c_id 필드에 of:dpid_id를 채우고, 다른 앱은 dpid:dpid_id를 채웁니다. 포트의 경우 OpenFlow port_id를 사용하며 포트 이름이 아닙니다. 예를 들어, Brocade에서 eth1/1 == 1이면 1을 사용하고 eth1/1을 사용하지 않습니다.
"packetOut_filter": 보고 싶은 PacketOut + LLDP 메시지를 정의하는 데 사용됩니다. 스위치별 및/또는 포트별로 정의할 수 있습니다. 스위치의 경우 사용 중인 애플리케이션에서 보는 datapath_id를 사용해야 합니다. 예를 들어, 일부 앱은 c_id 필드에 of:dpid_id를 채우고, 다른 앱은 dpid:dpid_id를 채웁니다. 포트의 경우 OpenFlow port_id를 사용하며 포트 이름이 아닙니다. 예를 들어, Brocade에서 eth1/1 == 1이면 1을 사용하고 eth1/1을 사용하지 않습니다.
OpenFlow 프록시 지원:
OpenFlow 프록시를 사용할 때, 패킷을 스니핑하기 위해 선택한 인터페이스에 따라 다음 두 가지 가능성 중 하나가 보입니다:
IP_Controller <-> IP_Proxy IP_Proxy <-> IP_Switch
어느 컨트롤러가 어떤 스위치와 통신하는지 연관짓기 어렵습니다. 이 문제 해결을 용이하게 하기 위해 OpenFlow 스니퍼는 자동으로 모든 PacketOut + LLDP 메시지를 모니터링하여 {(IP, port): name_switch} 사전을 생성합니다. 이 경우 docs/topology.json 파일을 변경하십시오. 다음에 스니퍼를 실행하면 IP와 괄호 안에 프록시 뒤의 장치 이름이 표시됩니다. 예제:
2015-12-16 15:37:41.563621 200.0.207.79(andes1):7801 -> 190.103.184.135:6633 Size: 157 Bytes
OpenFlow Version: 1.0(1) Type: PacketIn(10) Length: 103 XID: 0
0 PacketIn: buffer_id: 0xffffffff total_len: 85 in_port: 49 reason: OFPR_NO_MATCH(0) pad: 0
0 Ethernet: Destination MAC: ff:ff:ff:ff:ff:ff Source MAC: de:ad:be:ef:ba:11 Protocol: 0x8100
0 Ethernet: Prio: 0 CFI: 0 VID: 3720
0 LLDP: Chassis Type(1) Length: 7 SubType: 4 ID: of:cc4e249102000000
0 LLDP: Port Type(2) Length: 5 SubType: 2 ID: 2
0 LLDP: TTL(3) Length: 2 Seconds: 120
0 LLDP: END(0) Length: 0
2015-12-16 15:37:41.564414 190.103.184.133(andes1):56132 -> 190.103.187.72:6633 Size: 165 Bytes
OpenFlow Version: 1.0(1) Type: PacketIn(10) Length: 99 XID: 0
0 PacketIn: buffer_id: 0xffffffff total_len: 81 in_port: 49 reason: OFPR_NO_MATCH(0) pad: 0
0 Ethernet: Destination MAC: ff:ff:ff:ff:ff:ff Source MAC: de:ad:be:ef:ba:11 Protocol: 0x8942
0 LLDP: Chassis Type(1) Length: 7 SubType: 4 ID: of:cc4e249102000000
0 LLDP: Port Type(2) Length: 5 SubType: 2 ID: 2
0 LLDP: TTL(3) Length: 2 Seconds: 120
0 LLDP: END(0) Length: 0
이름 (andes1)은 DPID cc4e249126000000을 가진 스위치 "andes1"을 나타냅니다. 예제에 표시된 DPID는 PacketIn 메시지가 예제로 사용되었기 때문에 동일하지 않습니다. PacketIn은 "andes1"의 이웃 스위치의 DPID를 보여줍니다.
이 코드가 도움이 되길 바랍니다.
질문/제안: AmLight Dev Team [email protected]