get_protocols returns the list of protocols. This is useful for a
packet including the same protocol multiple times (e.g. tunneling such
GRE). However, it's a rare use case. Instead of
'get_protocols(hoge)[0]', let's do 'get_protocol(hoge)' simply.

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/lib/packet/packet.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ryu/lib/packet/packet.py b/ryu/lib/packet/packet.py
index f21edbe..0661e9b 100644
--- a/ryu/lib/packet/packet.py
+++ b/ryu/lib/packet/packet.py
@@ -97,6 +97,15 @@ class Packet(object):
         assert issubclass(protocol, packet_base.PacketBase)
         return [p for p in self.protocols if isinstance(p, protocol)]
 
+    def get_protocol(self, protocol):
+        """Returns the firstly found protocol that matches to the
+        specified protocol.
+        """
+        result = self.get_protocols(protocol)
+        if len(result) > 0:
+            return result[0]
+        return None
+
     def next(self):
         try:
             p = self.protocols[self.protocol_idx]
-- 
1.7.12.4 (Apple Git-37)


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to