mncc_sock.py: distinguish traffic frames

Change-Id: I996513e433bb57f12a4030391697f4e87e6ff938
changes/56/11156/1
Vadim Yanitskiy 4 years ago
parent 8a8b422dcf
commit c43f321e6e
  1. 29
      mncc_sock.py
  2. 4
      mncc_test.py

@ -26,6 +26,10 @@ class mncc_msg_common:
def is_rtp(self):
return self.msg_type in (mncc.MNCC_RTP_CREATE,
mncc.MNCC_RTP_CONNECT, mncc.MNCC_RTP_FREE)
def is_frame(self):
return self.msg_type in (mncc.GSM_TCHF_FRAME,
mncc.GSM_TCHH_FRAME, mncc.GSM_TCHF_FRAME_EFR,
mncc.GSM_TCH_FRAME_AMR, mncc.GSM_BAD_FRAME)
class mncc_msg(mncc.gsm_mncc, mncc_msg_common):
def __str__(self):
@ -39,6 +43,28 @@ class mncc_hello_msg(mncc.gsm_mncc_hello, mncc_msg_common):
def __unicode__(self):
return u'mncc_hello_msg(version=0x%04x)' % (self.version)
class mncc_data_frame_msg(mncc.gsm_data_frame, mncc_msg_common):
def __str__(self):
return 'mncc_data_frame(type=0x%04x, codec=%s, callref=%u)' \
% (self.msg_type, self.codec_str(), self.callref)
def __unicode__(self):
return u'mncc_data_frame(type=0x%04x, codec=%s, callref=%u)' \
% (self.msg_type, self.codec_str(), self.callref)
def codec_str(self):
if self.msg_type == mncc.GSM_TCHF_FRAME:
return "FR"
elif self.msg_type == mncc.GSM_TCHH_FRAME:
return "HR"
elif self.msg_type == mncc.GSM_TCHF_FRAME_EFR:
return "EFR"
elif self.msg_type == mncc.GSM_TCH_FRAME_AMR:
return "AMR"
elif self.msg_type == mncc.GSM_BAD_FRAME:
return "(BFI)"
else:
return "(???)"
class mncc_rtp_msg(mncc.gsm_mncc_rtp, mncc_msg_common):
def __str__(self):
return 'mncc_rtp_msg(type=0x%04x, callref=%u, ip=%x, port=%u)' % (self.msg_type, self.callref, self.ip, self.port)
@ -83,6 +109,9 @@ class MnccSocketBase(object):
if ms.is_rtp():
ms = mncc_rtp_msg()
ms.receive(data)
elif ms.is_frame():
ms = mncc_data_frame_msg()
ms.receive(data)
elif ms.msg_type == mncc.MNCC_SOCKET_HELLO:
ms = mncc_hello_msg()
ms.receive(data)

@ -35,6 +35,10 @@ class MnccActor(pykka.ThreadingActor):
def mncc_rx_thread(mncc_sock):
while 1:
msg = mncc_sock.recv()
if msg.is_frame():
print("Dropping traffic frame: %s" % msg)
continue
print "MnccActor RxMNCC %s, broadcasting to Call FSMs" % msg
# we simply broadcast to all calls
pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg}, GsmCallFsm)

Loading…
Cancel
Save