Change in python/osmo-python-tests[master]: ctrl: add optional TRAP-skipping parameter to split_combined()

Max gerrit-no-reply at lists.osmocom.org
Mon Nov 26 11:19:37 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/11929


Change subject: ctrl: add optional TRAP-skipping parameter to split_combined()
......................................................................

ctrl: add optional TRAP-skipping parameter to split_combined()

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 accordingly.

Change-Id: I51ce207c19a1ca96c3e2af7d5efd64f79b02fbb4
---
M osmopy/osmo_ipa.py
1 file changed, 13 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/29/11929/1

diff --git a/osmopy/osmo_ipa.py b/osmopy/osmo_ipa.py
index 41865c1..822e166 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 @@
     """
     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
@@ -106,18 +106,25 @@
         Strip IPA protocol header correctly removing extension if present
         Returns data length, IPA protocol, extension (or None if not defined for a give protocol) and the data without header
         """
-        if not len(data):
+        if data == None or not len(data):
             return None, None, None, None
         (dlen, proto) = struct.unpack('>HB', data[:3])
         if self.PROTO['OSMO'] == proto or self.PROTO['CCM'] == proto: # there's extension which we have to unpack
             return struct.unpack('>HBB', data[:4]) + (data[4:], ) # length, protocol, extension, data
         return dlen, proto, None, data[3:] # length, protocol, _, data
 
-    def split_combined(self, data):
+    def split_combined(self, data, ignore_traps = False):
         """
-        Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where rest contains remaining messages, first is the single IPA message
+        Split the data which contains multiple concatenated IPA messages into tuple (first, rest) where rest contains
+        remaining messages, first is the single IPA message with. Neither have headers stripped.
+        If ignore_traps parameter is set, than TRAP messages will be discarded.
         """
-        (length, _, _, _) = self.del_header(data)
+        if data == None or len(data) == 0:
+            return None, None
+        (length, _, _, d) = self.del_header(data)
+        if length and ignore_traps:
+            if d[:(length + 3)].decode('utf-8').startswith(self.CTRL_TRAP):
+                return self.split_combined(data[(length + 3):], ignore_traps)
         return data[:(length + 3)], data[(length + 3):]
 
     def tag_serial(self, data):

-- 
To view, visit https://gerrit.osmocom.org/11929
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I51ce207c19a1ca96c3e2af7d5efd64f79b02fbb4
Gerrit-Change-Number: 11929
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181126/bc2ef261/attachment-0001.html>


More information about the gerrit-log mailing list