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
This commit is contained in:
Max 2018-11-26 19:03:54 +01:00
parent 217837cf55
commit 1c668f2c47
1 changed files with 17 additions and 2 deletions

View File

@ -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