From 5fd538ee7f968941c9394014e215e578c181d9f8 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Fri, 5 Oct 2012 19:01:52 +0900 Subject: [PATCH] packet lib: make Packet class iterator Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/packet.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ryu/lib/packet/packet.py b/ryu/lib/packet/packet.py index c7963af7..93553404 100644 --- a/ryu/lib/packet/packet.py +++ b/ryu/lib/packet/packet.py @@ -22,6 +22,7 @@ class Packet(object): super(Packet, self).__init__() self.data = data self.protocols = [] + self.protocol_idx = 0 self.parsed_bytes = 0 if self.data: # Do we need to handle non ethernet? @@ -55,3 +56,16 @@ class Packet(object): for p in self.protocols: if p.__class__.__name__ == name: return p + + def next(self): + try: + p = self.protocols[self.protocol_idx] + except: + self.protocol_idx = 0 + raise StopIteration + + self.protocol_idx += 1 + return p + + def __iter__(self): + return self