On Sat, 26 Jan 2013 15:13:23 +0900 OHMURA Kei <[email protected]> wrote:
> Signed-off-by: OHMURA Kei <[email protected]> > --- > ryu/lib/packet/netflowv5.py | 95 > +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 95 insertions(+) > create mode 100644 ryu/lib/packet/netflowv5.py Great to have netflow support. But not sure whether ryu/lib/packet is the best place. This is not used with raw sockets. This is not used to build a packet? > diff --git a/ryu/lib/packet/netflowv5.py b/ryu/lib/packet/netflowv5.py > new file mode 100644 > index 0000000..cd0b7cf > --- /dev/null > +++ b/ryu/lib/packet/netflowv5.py > @@ -0,0 +1,95 @@ > +# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation. > +# > +# Licensed under the Apache License, Version 2.0 (the "License"); > +# you may not use this file except in compliance with the License. > +# You may obtain a copy of the License at > +# > +# http://www.apache.org/licenses/LICENSE-2.0 > +# > +# Unless required by applicable law or agreed to in writing, software > +# distributed under the License is distributed on an "AS IS" BASIS, > +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > +# implied. > +# See the License for the specific language governing permissions and > +# limitations under the License. > + > +import struct > + > + > +class NetFlowV5(object): > + _PACK_STR = '!HHIIIIBBH' > + _MIN_LEN = struct.calcsize(_PACK_STR) > + > + def __init__(self, version, count, sys_uptime, unix_secs, > + unix_nsecs, flow_sequence, engine_type, engine_id, > + sampling_interval, flows=None): > + self.version = version Better to have NetFlow class instead? The parser generates a version class such as NetFlow5? > + self.count = count > + self.sys_uptime = sys_uptime > + self.unix_secs = unix_secs > + self.unix_nsecs = unix_nsecs > + self.flow_sequence = flow_sequence > + self.engine_type = engine_type > + self.engine_id = engine_id > + self.sampling_interval = sampling_interval > + > + @classmethod > + def parser(cls, buf): > + (version, count, sys_uptime, unix_secs, unix_nsecs, > + flow_sequence, engine_type, engine_id, sampling_interval) = \ > + struct.unpack_from(cls._PACK_STR, buf) > + > + netflow = cls(version, count, sys_uptime, unix_secs, > + unix_nsecs, flow_sequence, engine_type, > + engine_id, sampling_interval) > + offset = cls._MIN_LEN > + netflow.flows = [] > + while len(buf) > offset: > + f = NetFlowV5Flow.parser(buf, offset) > + offset += NetFlowV5Flow._MIN_LEN > + netflow.flows.append(f) > + > + return netflow > + > + def serialize(self): > + pass > + > + > +class NetFlowV5Flow(object): > + _PACK_STR = '!IIIHHIIIIHHxBBBHHBB2x' > + _MIN_LEN = struct.calcsize(_PACK_STR) > + > + def __init__(self, srcaddr, dstaddr, nexthop, input_, output, > + dpkts, doctets, first, last, srcport, dstport, > + tcp_flags, prot, tos, src_as, dst_as, src_mask, > + dst_mask): > + self.srcaddr = srcaddr > + self.dstaddr = dstaddr > + self.nexthop = nexthop > + self.input = input_ > + self.output = output > + self.dpkts = dpkts > + self.doctets = doctets > + self.first = first > + self.last = last > + self.srcport = srcport > + self.dstport = dstport > + self.tcp_flags = tcp_flags > + self.prot = prot > + self.tos = tos > + self.src_as = src_as > + self.dst_as = dst_as > + self.src_mask = src_mask > + self.dst_mask = dst_mask > + > + @classmethod > + def parser(cls, buf, offset): > + (srcaddr, dstaddr, nexthop, input_, output, dpkts, doctets, > + first, last, srcport, dstport, tcp_flags, prot, tos, src_as, > + dst_as, src_mask, dst_mask) = struct.unpack_from( > + cls._PACK_STR, buf, offset) > + f = cls(srcaddr, dstaddr, nexthop, input_, output, dpkts, > + doctets, first, last, srcport, dstport, tcp_flags, > + prot, tos, src_as, dst_as, src_mask, dst_mask) > + > + return f > -- > 1.7.9.5 > > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. ON SALE this month only -- learn more at: > http://p.sf.net/sfu/learnnow-d2d > _______________________________________________ > Ryu-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ryu-devel ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnnow-d2d _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
