为了使对网络中异常流量的检测具有一定的主动性,例如实时的获取网络中的流表项,查阅论文和资料,提供以下几个思路。
ovs-ofctl用来控制OVS作为OpenFlow交换机工作时候的流表内容。
ovs-ofctl dump-flows mybridge可以实时的获取mybridge交换机下的流表项,利用 > 输出获取到的实时信息到txt文件中,方便我们的后续的读取。
拓扑建立后在交换机上运行bash脚本。
#!/bin/bash
ovs-ofctl dump-flows s1 >test.txt
查看test.txt文件
root@lxx-ubuntu16:~/mininet/mininet/examples# bash test.sh
root@lxx-ubuntu16:~/mininet/mininet/examples# cat test.txt
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=1480.695s, table=0, n_packets=71, n_bytes=7649, idle_age=366, priority=0 actions=CONTROLLER:65535
[1]这篇论文使用了类似的方法。
利用ryu.app.ofctl_rest可以使我们通过网页访问交换机流表项。
ryu.app.ofctl_rest的官方介绍,有关中文介绍可以查看这篇文章。
启动ofctl_rest.py和控制器后,连接拓扑,浏览器访问http://127.0.0.1:8080/stats/flow/1便可查看JSON化的流表项信息。
{
"1": [
{
"actions": [
"OUTPUT:CONTROLLER"
],
"idle_timeout": 0,
"cookie": 0,
"packet_count": 51,
"hard_timeout": 0,
"byte_count": 5717,
"duration_sec": 123,
"duration_nsec": 82000000,
"priority": 0,
"length": 80,
"flags": 0,
"table_id": 0,
"match": {}
}
]
}
通过控制器对交换机发起流表查询命令(具体操作目前未知),查看某些博客后发现似乎是控制器中调用restAPI编写函数进行信息收集展示。源代码注释以及实例如下:
# REST API
#
# Retrieve the switch stats
#
# get the list of all switches
# GET /stats/switches
#
def get_switches(self):
item = self.path+ '/stats/switches'
tmpres = os.popen('curl %s -s' % item).readlines()
ss = tmpres[0][:-1]
ss = ss[1:]
sl = ss.split(', ')
return (sl)
[1]王晓瑞,庄雷,胡颖,王国卿,马丁,景晨凯.SDN环境下基于BP神经网络的DDoS攻击检测方法[J].计算机应用研究,2018,35(03):911-915.
RYU实战,REST API流表控制
ovs-ofctl 官方文档学习笔记
https://blog.csdn.net/manml/article/details/78496778
RYU实验笔记(一):多RYU控制器连接拓扑以及相关流表操作