you can do something like: if arp.arp in Packet(msg.data): a = arp.arp(...) if a in Packet(msg.data):
>>> from ryu.lib.packet import packet >>> from ryu.lib.packet import arp >>> a = arp.arp_ip(1, 0, 0, 0, 0) >>> p = packet.Packet() >>> p.protocols = [a] >>> arp.arp in p True >>> a in p True Signed-off-by: Isaku Yamahata <yamah...@valinux.co.jp> --- ryu/lib/packet/packet.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ryu/lib/packet/packet.py b/ryu/lib/packet/packet.py index da1077b..a40202f 100644 --- a/ryu/lib/packet/packet.py +++ b/ryu/lib/packet/packet.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import inspect + from . import packet_base from . import ethernet @@ -110,3 +112,9 @@ class Packet(object): def __len__(self): return len(self.protocols) + + def __contains__(self, protocol): + if (inspect.isclass(protocol) and + issubclass(protocol, packet_base.PacketBase)): + return protocol in [p.__class__ for p in self.protocols] + return protocol in self.protocols -- 1.7.10.4 ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. A cloud service to automate IT design, transition and operations 2. Dashboards that offer high-level views of enterprise services 3. A single system of record for all IT processes http://p.sf.net/sfu/servicenow-d2d-j _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel