From 1c668f2c4746c852a2ac9454db374e65bc13617d Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 26 Nov 2018 19:03:54 +0100 Subject: [PATCH] ctrl: add function to skip TRAP messages This allows to easy skip TRAP messages when we do not want to process them (for example when waiting for REPLY to a single command). Update documentation and version accordingly. Change-Id: I51ce207c19a1ca96c3e2af7d5efd64f79b02fbb4 --- osmopy/osmo_ipa.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/osmopy/osmo_ipa.py b/osmopy/osmo_ipa.py index c371023..f957f41 100755 --- a/osmopy/osmo_ipa.py +++ b/osmopy/osmo_ipa.py @@ -2,7 +2,7 @@ # -*- mode: python-mode; py-indent-tabs-mode: nil -*- """ /* - * Copyright (C) 2016 sysmocom s.f.m.c. GmbH + * Copyright (C) 2016-2018 sysmocom s.f.m.c. GmbH * * All Rights Reserved * @@ -28,7 +28,7 @@ class IPA(object): """ Stateless IPA protocol multiplexer: add/remove/parse (extended) header """ - version = "0.0.6" + version = "0.0.7" TCP_PORT_OML = 3002 TCP_PORT_RSL = 3003 # OpenBSC extensions: OSMO, MGCP_OLD @@ -114,6 +114,21 @@ class IPA(object): return struct.unpack('>HBB', data[:4]) + (data[4:], ) # length, protocol, extension, data return dlen, proto, None, data[3:] # length, protocol, _, data + def skip_traps(self, data): + """ + Take one or more ctrl messages and data and return first non-TRAP message or None + """ + if data == None or len(data) == 0: + return None + + (head, tail) = self.split_combined(data) + (length, _, _, payload) = self.del_header(head) + # skip over broken messages as well as TRAPs + if length == 0 or payload[:(length + 3)].decode('utf-8').startswith(self.CTRL_TRAP): + return self.skip_traps(tail) + + return head + def split_combined(self, data): """ Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where 'rest' contains