大网数据广告活动
服务器运维问答

How to parse OpenFlow packets using tcpdump capture file programmatically

· 52CE 我爱测

I am working with OpenFlow packets and am analyzing the network via tcpdump. Currently, I use the WireShark GUI to parse the generated capture file and it does serve my need. However, I was wondering whether WireShark has an API …

问题原文

原帖链接 · spiritusozeans · CC BY-SA 3.0

I am working with OpenFlow packets and am analyzing the network via tcpdump.

Currently, I use the WireShark GUI to parse the generated capture file and it does serve my need.

However, I was wondering whether WireShark has an API so the same can be done via a script rather than the GUI (I'm essentially aiming to extract certain OpenFlow parameters and automate the process of checking my system)

已采纳解答

原帖链接 · spiritusozeans · CC BY-SA 3.0

The command line alternative to WireShark is tshark (similar in function to tcpdump).

This blog had enough to get me started.

A sample tshark capture command goes as follows (say you want to monitor the interface eth0):

sudo tshark -i eth0

We can add capture filters along with the command as well:

sudo tshark -i eth0 "port 6633"

This command will capture all traffic to or from port 6633 (the default port of OpenFlow controllers)

Simply capturing the traffic is not enough. To analyze the capture via a program, we need to first convert the capture into an easily understandable format. Enter XML.

sudo tshark -i eth0 -T pdml > dump.xml  

This outputs the capture file as an xml file with all the packets along with their various attributes as tags.

This can be subsequently parsed using any standard xml parser.

A couple extra things I tweaked: I scrapped the "port 6633". And added a -n option (addresses are not resolved). The additional packets which are captured as a result may always be filtered out by the xml parser. Since my application gave a slight importance to the timestamps of various packets, I did not want to cause additional delays due to filtering/resolving. Note that I may be terribly wrong in my reasoning here (it was just a hunch). Each packet has a timestamp added to it by the network adapter when the device receives the same. It is therefore more than likely that using such tricks wouldn't affect the time stamp at all.

My final command was therefore:

sudo tshark -n -i eth0 -T pdml > dump.xml

ADDITIONAL NOTE: If you are habituated to use WireShark to debug OpenFlow packets, you probably use the display filter: "of". This however is not a valid capture filter which is required by tshark (capture filters are similar to those used in tcpdump)

PS: Drop me a line if you need the xml parser (I used python)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-06-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。