root/trunk/FlowParser/sFlow5.py

Revision 1, 1.8 kB (checked in by ixs, 16 years ago)

initial checkin of RH revision

  • Property svn:executable set to *
Line 
1 #
2 # Copyright (C) 2007-2008 Red Hat, Inc.
3 # Author: Andreas Thienemann <athienem@redhat.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Library General Public License as published by
7 # the Free Software Foundation; version 2 only
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Library General Public License for more details.
13 #
14 # You should have received a copy of the GNU Library General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Copyright 2004, 2005 Red Hat, Inc.
18 #
19 # AUTHOR: Andreas Thienemann <athienem@redhat.com>
20 #
21
22 import sys
23 import struct
24 import xdrlib
25 import IPy
26 import FlowHandler
27 import pprint
28 import binascii
29 #import logging
30 import thread
31
32
33 #logging.info('sFlow9 protocol disector loaded')
34
35
36
37
38 class Sflow5Parser(FlowHandler.AbstractFlowParser):
39     name = 'sflow5'
40
41     def SnmpRefresh():
42         '''Call this with thread.start_new_thread(SnmpRefresh, (args))'''
43
44     def parse(self):
45
46         flow_decode = []
47
48         xu = xdrlib.Unpacker(self.pkgdata)
49
50         # The flow header
51         # Version (uint), IP Version (uint), Agent IP,sysUpTime (int),
52         # UNIX Secs (int), Sequence Number (int), Source ID (int)
53         flow_hdr = list((xu.unpack_uint(), xu.unpack_uint()))
54         if flow_hdr[1] == 1:
55             flow_hdr.append(IPy.IP(xu.unpack_uint()).strNormal())
56         elif flow_hdr[1] == 2:
57            flow_hdr.append(IPy.IP(xu.unpack_fopaque(16)).strNormal())
58         flow_hdr.extend(list((xu.unpack_uint(), xu.unpack_uint(), xu.unpack_uint(), xu.unpack_uint())))
59
60         print flow_hdr
61
Note: See TracBrowser for help on using the browser.