packet lib: packet class supports get_protocol method

returns a list of protocols that matches to the specified protocol.

Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Isaku Yamahata 2013-06-10 15:58:56 +09:00 committed by FUJITA Tomonori
parent 178b1dd2bc
commit 6d414d0cdd

View File

@ -87,6 +87,14 @@ class Packet(object):
self.protocols.append(proto)
def get_protocols(self, protocol):
"""Returns a list of protocols that matches to the specified protocol.
"""
if isinstance(protocol, packet_base.PacketBase):
protocol = protocol.__class__
assert issubclass(protocol, packet_base.PacketBase)
return [p for p in self.protocols if isinstance(p, protocol)]
def next(self):
try:
p = self.protocols[self.protocol_idx]