Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface version encoding #194

Closed
rnesytov opened this issue Feb 14, 2020 · 4 comments · Fixed by #196
Closed

Interface version encoding #194

rnesytov opened this issue Feb 14, 2020 · 4 comments · Fixed by #196

Comments

@rnesytov
Copy link

Python 3.8.1
naz 0.7.7
MacOS 10.15.3

Hi. I tried to test my application, which uses naz over this simulator and got problems with bind stage.

With this example you can reproduce the problem:

import asyncio
import naz

loop = asyncio.get_event_loop()
broker = naz.broker.SimpleBroker(maxsize=1000)
cli = naz.Client(
    smsc_host="smscsim.melroselabs.com",
    smsc_port=2775,
    system_id="178895",
    password="ZDANDZ",
    broker=broker
)

# queue messages to send
for i in range(0, 4):
    print("submit_sm round:", i)

    msg = naz.protocol.SubmitSM(
            short_message="Hello World-{0}".format(str(i)),
            log_id="myid12345",
            source_addr="254722111111",
            destination_addr="12559498"
        )
    loop.run_until_complete(
       cli.send_message(msg)
)

try:
    # 1. connect to the SMSC host
    # 2. bind to the SMSC host
    # 3. send any queued messages to SMSC
    # 4. read any data from SMSC
    # 5. continually check the state of the SMSC
    tasks = asyncio.gather(
        cli.connect(),
        cli.tranceiver_bind(),
        cli.dequeue_messages(),
        cli.receive_data(),
        cli.enquire_link(),
    )
    loop.run_until_complete(tasks)
except Exception as e:
    print("exception occured. error={0}".format(str(e)))
finally:
    loop.run_until_complete(cli.unbind())
    loop.stop()

Here logs

 ~/zvooq/ZSMPP  .venv   master ● ?  python -m zsmpp.test                                                                                          ✓ 
submit_sm round: 0
{"timestamp": "2020-02-13 19:21:10,032", "event": "naz.Client.send_message", "stage": "start", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,033", "event": "naz.Client.send_message", "stage": "end", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
submit_sm round: 1
{"timestamp": "2020-02-13 19:21:10,033", "event": "naz.Client.send_message", "stage": "start", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,033", "event": "naz.Client.send_message", "stage": "end", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
submit_sm round: 2
{"timestamp": "2020-02-13 19:21:10,033", "event": "naz.Client.send_message", "stage": "start", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,033", "event": "naz.Client.send_message", "stage": "end", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
submit_sm round: 3
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.send_message", "stage": "start", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.send_message", "stage": "end", "log_id": "myid12345", "smpp_command": "submit_sm", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.connect", "stage": "start", "log_id": "mywyh6tde632xev0l", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.tranceiver_bind", "stage": "start", "log_id": "9elhcr2mn1lb1o9ut", "smpp_command": "bind_transceiver", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.send_data", "stage": "start", "smpp_command": "bind_transceiver", "log_id": "9elhcr2mn1lb1o9ut", "msg": "\u0000\u0000\u0000,\u0000\u0000\u0000\t\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002178895\u0000{REDACTED}\u0000\u0000\u0000\u0000\u0000\"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", "connection_lost": true, "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,034", "event": "naz.Client.send_data", "stage": "end", "smpp_command": "bind_transceiver", "log_id": "9elhcr2mn1lb1o9ut", "msg": "\u0000\u0000\u0000,\u0000\u0000\u0000\t\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002178895\u0000{REDACTED}\u0000\u0000\u0000\u0000\u0000\"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", "current_session_state": "CLOSED", "error": "smpp_command `bind_transceiver` cannot be sent to SMSC when the client session state is `CLOSED`", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
NoneType: None
{"timestamp": "2020-02-13 19:21:10,040", "event": "naz.Client.tranceiver_bind", "stage": "end", "log_id": "9elhcr2mn1lb1o9ut", "smpp_command": "bind_transceiver", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,040", "event": "naz.Client.dequeue_messages", "stage": "start", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,040", "event": "naz.Client.dequeue_messages", "stage": "start", "current_session_state": "CLOSED", "state": "awaiting naz to change session state to `BOUND_TRX`. sleeping for 30.00 seconds", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,040", "event": "naz.Client.receive_data", "stage": "start", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,040", "event": "naz.Client.receive_data", "stage": "end", "state": "naz is yet to bind to SMSC. sleeping for 30.00 seconds", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:10,195", "event": "naz.Client.connect", "stage": "end", "log_id": "mywyh6tde632xev0l", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
^[[3{"timestamp": "2020-02-13 19:21:40,042", "event": "naz.Client.dequeue_messages", "stage": "start", "current_session_state": "OPEN", "state": "awaiting naz to change session state to `BOUND_TRX`. sleeping for 30.00 seconds", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,042", "event": "naz.Client.re_establish_conn_bind", "stage": "start", "smpp_command": "", "log_id": "", "connection_lost": false, "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,042", "event": "naz.Client.connect", "stage": "start", "log_id": "yc46202hgd4rtij6d", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,113", "event": "naz.Client.connect", "stage": "end", "log_id": "yc46202hgd4rtij6d", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,113", "event": "naz.Client.tranceiver_bind", "stage": "start", "log_id": "ms2vf2u2kvils8som", "smpp_command": "bind_transceiver", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,113", "event": "naz.Client.send_data", "stage": "start", "smpp_command": "bind_transceiver", "log_id": "ms2vf2u2kvils8som", "msg": "\u0000\u0000\u0000,\u0000\u0000\u0000\t\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0003178895\u0000{REDACTED}\u0000\u0000\u0000\u0000\u0000\"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", "connection_lost": false, "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,114", "event": "naz.Client.send_data", "stage": "end", "smpp_command": "bind_transceiver", "log_id": "ms2vf2u2kvils8som", "msg": "\u0000\u0000\u0000,\u0000\u0000\u0000\t\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0003178895\u0000{REDACTED}\u0000\u0000\u0000\u0000\u0000\"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,114", "event": "naz.Client.tranceiver_bind", "stage": "end", "log_id": "ms2vf2u2kvils8som", "smpp_command": "bind_transceiver", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,114", "event": "naz.Client.re_establish_conn_bind", "stage": "end", "smpp_command": "", "log_id": "", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,114", "event": "naz.Client.receive_data", "stage": "start", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
^R
^[[{"timestamp": "2020-02-13 19:21:40,350", "event": "naz.Client.command_handlers", "stage": "start", "smpp_command": "bind_transceiver_resp", "log_id": "ms2vf2u2kvils8som", "command_status": 13, "state": "Bind Failed", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
NoneType: None
{"timestamp": "2020-02-13 19:21:40,351", "event": "naz.Client.receive_data", "stage": "end", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}
{"timestamp": "2020-02-13 19:21:40,351", "event": "naz.Client.receive_data", "stage": "start", "smsc_host": "smscsim.melroselabs.com", "system_id": "178895", "client_id": "OZAXH1X2V0E6I0JWS", "pid": 48254}

Via Wireshark I found that version in the packet is zero
image

Now let's look at this code

+ struct.pack(">I", self.interface_version)

">L" means that will be used 4 octets, but SMPP v3.4 documentation says that interface_version should be size of 1 octet (also as addr_ton and addr_npi).
So, I think, here should be struct.pack(">B", self.interface_version).

But it doesn't help.
After that fix, I got version 2.2 in the BindTranceiver message.
image

Looks like default interface_version should be 0x34

>>> import struct
>>> struct.pack(">B", 34).hex()
'22'
>>> struct.pack(">B", 0x34).hex()
'34'
@komuw
Copy link
Owner

komuw commented Feb 15, 2020

thanks. Will look into it.

@komuw
Copy link
Owner

komuw commented Feb 15, 2020

Note to self;

  • go through the entire source code and look for all the places where we use struct.pack() and struct.unpack() and make sure that the format[1] characters we are using are in line with those specified in the v3.4 smpp specification.
  • go through source code and ensure we are using the correct interger format/hex(0x34 in place of 34)
  1. https://docs.python.org/3.7/library/struct.html#format-characters

@komuw
Copy link
Owner

komuw commented Feb 15, 2020

@Profx5 hi, would you mind trying out this beta version: https://pypi.org/project/naz/0.7.8b0/
and letting me know if there are any issues with it.

@rnesytov
Copy link
Author

@komuw, I tested this version, and it works well, thank you!

komuw added a commit that referenced this issue Feb 16, 2020
What:
- Fix a bug where `naz` was not formatting 1octet integers correctly

Why:
- Fixes: #194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants