该程序是POX WIKI上的程序,我只是将统计的报文修改了以下,并做了对这个程序运行流程的分析:

1.程序从launch开始运行

2.监听2个事件,如果监听到“FlowStatsReceived”就交由_handle_flowstats_received()来处理,另一个事件同样道理

3.每5s执行以下_time_func(),这是一步实时监视的处理

4._time_func()启动后发送2个状态请求给所有的switch

5.如果监听到上面说的两个事件,就执行相应的handle部分,其中_handle_flowstats_received()部分会统计源IP为“10.0.0.1”的报文字节数,报文数和报文流数量,并将结果输出出来,可以在terminal上看到

ps: of_json的作用是将openflow的数据结构转化为json的友好数据结构

运行方法可以是:

terminal 1:  sudo python topo1.py    ---运行一个任意topo

terminal 2: ./pox.py forwarding.l2_learning flow.stats2  ---运行pox主程序,2层交换程序和流量监控程序

代码如下:

#!/usr/bin/python
# Copyright 2012 William Yu
# wyu@ateneo.edu
#
# This file is part of POX.
#
# POX is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# POX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with POX. If not, see <http://www.gnu.org/licenses/>.
# """
This is a demonstration file created to show how to obtain flow
and port statistics from OpenFlow 1.0-enabled switches. The flow
statistics handler contains a summary of web-only traffic.
""" # standard includes
from pox.core import core
from pox.lib.util import dpidToStr
import pox.openflow.libopenflow_01 as of # include as part of the betta branch
from pox.openflow.of_json import * log = core.getLogger() # handler for timer function that sends the requests to all the
# switches connected to the controller.
def _timer_func ():
for connection in core.openflow._connections.values():
connection.send(of.ofp_stats_request(body=of.ofp_flow_stats_request()))
connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
log.debug("Sent %i flow/port stats request(s)", len(core.openflow._connections)) # handler to display flow statistics received in JSON format
# structure of event.stats is defined by ofp_flow_stats()
def _handle_flowstats_received (event):
stats = flow_stats_to_list(event.stats) # wsc:this step is just for debugging, so it can ba deleted.
log.debug("FlowStatsReceived from %s: %s",
dpidToStr(event.connection.dpid), stats) # Get number of bytes/packets in flows for web traffic only
web_bytes = 0
web_flows = 0
web_packet = 0
for f in event.stats:
if f.match.nw_src == IPAddr("10.0.0.1"):
web_bytes += f.byte_count
web_packet += f.packet_count
web_flows += 1
log.info("Web traffic from %s: %s bytes (%s packets) over %s flows",
dpidToStr(event.connection.dpid), web_bytes, web_packet, web_flows) # handler to display port statistics received in JSON format
def _handle_portstats_received (event):
stats = flow_stats_to_list(event.stats)
log.debug("PortStatsReceived from %s: %s",
dpidToStr(event.connection.dpid), stats) # main functiont to launch the module
def launch ():
from pox.lib.recoco import Timer # attach handsers to listners
core.openflow.addListenerByName("FlowStatsReceived",
_handle_flowstats_received)
core.openflow.addListenerByName("PortStatsReceived",
_handle_portstats_received) # timer set to execute every five seconds
Timer(5, _timer_func, recurring=True)

POX flow_stats2.py analysis by uestc_gremount的更多相关文章

  1. Pox启动及事件产生、监听分析

        ./pox/pox.py , Pox       实例化core=pox.core.initialize(),即为实例化POXCore类(该类是所有组件的交接点,提供组件注册功能),监听cor ...

  2. Burp Suite渗透操作指南 【暴力破解】

    1.1 Intruder高效暴力破解 其实更喜欢称Intruder爆破为Fuzzing.Intruder支持多种爆破模式.分别是:单一字典爆破.多字段相同字典爆破.多字典意义对应爆破.聚合式爆破.最常 ...

  3. SQLChop、SQLWall(Druid)、PHP Syntax Parser Analysis

    catalog . introduction . sqlchop sourcecode analysis . SQLWall(Druid) . PHP Syntax Parser . SQL Pars ...

  4. malware analysis、Sandbox Principles、Design && Implementation

    catalog . 引言 . sandbox introduction . Sandboxie . seccomp(short for secure computing mode): API级沙箱 . ...

  5. Linux Rootkit Sample && Rootkit Defenser Analysis

    目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...

  6. Pox组件

    最近在学习Pox,为了加深印象,对Pox wiki中的Pox组件写了些笔记.   按照组件的功能进行分类:   L2层地址学习.洪泛 forwarding.hub forwarding.l2_lear ...

  7. Computational Methods in Bayesian Analysis

    Computational Methods in Bayesian Analysis Computational Methods in Bayesian Analysis  [Markov chain ...

  8. 巡风源码阅读与分析---view.py

    巡风xunfeng----巡风源码阅读与分析 巡风是一款适用于企业内网的漏洞快速应急.巡航扫描系统,通过搜索功能可清晰的了解内部网络资产分布情况,并且可指定漏洞插件对搜索结果进行快速漏洞检测并输出结果 ...

  9. STREAMING HIVE流过滤 官网例子 注意中间用的py脚本

    Simple Example Use Cases MovieLens User Ratings First, create a table with tab-delimited text file f ...

随机推荐

  1. 【转载】C#使用as关键字将对象转换为指定类型

    在C#的编程开发过程中,很多时候涉及到数据类型的转换,可使用强制转换的方式,不过强制转换数据类型有时候会抛出程序异常错误,可以使用as关键字来进行类型的转换,如果转换成功将返回转换后的对象,如果转换不 ...

  2. 【转载】Response对象的作用以及常用方法属性

    Response对象是Asp.Net应用程序中非常重要的一个内置对象,其作用为负责将服务器执行好的信息输出给客户端,即作用主要为响应客户端请求并将服务器的响应返回给用户,在页面的临时跳转中,也可使用R ...

  3. FICO-错误日志集

    1.F-02报错 System error in routine FI_TAX_CHK_PRICING_DATA error code 13 function builder TAX2 程序 FI_T ...

  4. Java并发 行级锁/字段锁/表级锁 乐观锁/悲观锁 共享锁/排他锁 死锁

    原文地址:https://my.oschina.net/oosc/blog/1620279 前言 锁是防止在两个事务操作同一个数据源(表或行)时交互破坏数据的一种机制. 数据库采用封锁技术保证并发操作 ...

  5. Privacy Description

    This application respects and protects the privacy of all users who use the service. In order to pro ...

  6. 【Zookeeper】基础学习概览【汇总】

    一.概述 1.1 简介 1.2 Zookeeper集群机制 1.3 Zookeeper特性 二.Zookeeper应用场景 三.Zookeeper数据结构 四.Zookeeper安装 五.Java操作 ...

  7. vue + jenkins 自动部署到指定的目录

    1. 首先选择自由风的构建方式 2. 我的源码在gitlab上,在源码管理下,提供仓库URL和凭证,以及gitlab的分支 3. 在构建环境下选择提供Node &npm bin/folder ...

  8. 无线热点登陆认证原理探究---captive portal 什么是Captive Portal

    什么是Captive Portal 大家肯定都连过公共场所的wifi热点,比如麦当劳等地方的.他们的wifi往往一连上去就会弹出一个要求登录或者微信关注之类的页面,只有在这个页面完成操作了才能正常访问 ...

  9. opencv 图片识别

    # -*- coding: utf-8 -*-"""Created on Fri Nov 22 21:35:12 2019 @author: Administrator& ...

  10. ES6中let、const和var的区别

    一.let 1.基本用法 ES6 新增了let命令,用来声明变量. let 的用法类似于 var,但所声明的变量只在 let 命令所在的代码块内有效(一个“{}”相当于一个代码块) { let a = ...