def test_delivery_failover_route(self):
        """#467: Will ensure a failover route will deliver the message"""

        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        wrong_port = self.AckServer.getHost().port + 1000
        route = FailoverMORoute([TransparentFilter()], [
            HttpConnector(id_generator(),
                          'http://127.0.0.1:%s/send' % wrong_port),
            HttpConnector(
                id_generator(),
                'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
        ])
        yield self.prepareRoutingsAndStartConnector(source_connector, route)

        # Send a data_sm from the SMSC
        pdu = DataSM(
            source_addr='1234',
            destination_addr='4567',
            message_payload='any content',
        )
        yield self.triggerDataSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_delivery_failover_route(self):
        """#467: Will ensure a failover route will deliver the message"""

        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        wrong_port = self.AckServer.getHost().port + 1000
        route = FailoverMORoute([TransparentFilter()], [
            HttpConnector(id_generator(), 'http://127.0.0.1:%s/send' % wrong_port),
            HttpConnector(id_generator(), 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)])
        yield self.prepareRoutingsAndStartConnector(source_connector, route)

        # Send a deliver_sm from the SMSC
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='any content',
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_long_content_delivery_UDH_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Build a UDH
        baseUdh = []
        baseUdh.append(struct.pack('!B', 5))  # Length of User Data Header
        baseUdh.append(struct.pack('!B',
                                   0))  # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
        baseUdh.append(struct.pack('!B', 3))  # Length of the header, excluding the first two fields; equal to 03
        baseUdh.append(struct.pack('!B', int(id_generator(size=2, chars=string.digits))))  # msg_ref_num
        baseUdh.append(struct.pack('!B', 3))  # total_segments

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT, [EsmClassGsmFeatures.UDHI_INDICATOR_SET]),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        udh_part1 = copy.deepcopy(baseUdh)
        pdu_part2 = copy.deepcopy(basePdu)
        udh_part2 = copy.deepcopy(baseUdh)
        pdu_part3 = copy.deepcopy(basePdu)
        udh_part3 = copy.deepcopy(baseUdh)
        udh_part1.append(struct.pack('!B', 1))  # segment_seqnum
        pdu_part1.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part1.params['short_message'] = ''.join(
            udh_part1) + '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part2.append(struct.pack('!B', 2))  # segment_seqnum
        pdu_part2.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part2.params['short_message'] = ''.join(
            udh_part2) + '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part3.append(struct.pack('!B', 3))  # segment_seqnum
        pdu_part3.params['more_messages_to_send'] = MoreMessagesToSend.NO_MORE_MESSAGES
        pdu_part3.params['short_message'] = ''.join(udh_part3) + '__3rd_part_end.'
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['from'], [basePdu.params['source_addr']])
        self.assertEqual(receivedHttpReq['to'], [basePdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq['content'], [
            pdu_part1.params['short_message'][6:] + pdu_part2.params['short_message'][6:] + pdu_part3.params[
                                                                                                'short_message'][6:]])
        self.assertEqual(receivedHttpReq['binary'], [binascii.hexlify(
            pdu_part1.params['short_message'][6:] + pdu_part2.params['short_message'][6:] + pdu_part3.params[
                                                                                                'short_message'][6:])])
        self.assertEqual(receivedHttpReq['origin-connector'], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_unordered_long_content_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            sar_total_segments=3,
            sar_msg_ref_num=int(id_generator(size=2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params[
            'short_message'] = '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part1.params['sar_segment_seqnum'] = 1
        pdu_part2.params[
            'short_message'] = '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part2.params['sar_segment_seqnum'] = 2
        pdu_part3.params['short_message'] = '__3rd_part_end.'
        pdu_part3.params['sar_segment_seqnum'] = 3
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part3, pdu_part2])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['from'],
                         [basePdu.params['source_addr']])
        self.assertEqual(receivedHttpReq['to'],
                         [basePdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq['content'], [
            pdu_part1.params['short_message'] +
            pdu_part2.params['short_message'] +
            pdu_part3.params['short_message']
        ])
        self.assertEqual(receivedHttpReq['binary'], [
            binascii.hexlify(pdu_part1.params['short_message'] +
                             pdu_part2.params['short_message'] +
                             pdu_part3.params['short_message'])
        ])
        self.assertEqual(receivedHttpReq['origin-connector'],
                         [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
Example #5
0
    def test_unordered_long_content_delivery_HttpConnector(self):
        yield self.connect("127.0.0.1", self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a data_sm from the SMSC
        basePdu = DataSM(
            source_addr="1234",
            destination_addr="4567",
            message_payload="",
            sar_total_segments=3,
            sar_msg_ref_num=int(id_generator(size=2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params[
            "message_payload"
        ] = "__1st_part_with_153_char________________________________________________________________________________________________________________________________."
        pdu_part1.params["sar_segment_seqnum"] = 1
        pdu_part2.params[
            "message_payload"
        ] = "__2nd_part_with_153_char________________________________________________________________________________________________________________________________."
        pdu_part2.params["sar_segment_seqnum"] = 2
        pdu_part3.params["message_payload"] = "__3rd_part_end."
        pdu_part3.params["sar_segment_seqnum"] = 3
        yield self.triggerDataSmFromSMSC([pdu_part1, pdu_part3, pdu_part2])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 6)
        self.assertEqual(receivedHttpReq["from"], [basePdu.params["source_addr"]])
        self.assertEqual(receivedHttpReq["to"], [basePdu.params["destination_addr"]])
        self.assertEqual(
            receivedHttpReq["content"],
            [
                pdu_part1.params["message_payload"]
                + pdu_part2.params["message_payload"]
                + pdu_part3.params["message_payload"]
            ],
        )
        self.assertEqual(receivedHttpReq["origin-connector"], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
Example #6
0
    def test_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='any content',
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['from'], [pdu.params['source_addr']])
        self.assertEqual(receivedHttpReq['to'], [pdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq['content'], [pdu.params['short_message']])
        self.assertEqual(receivedHttpReq['binary'], [binascii.hexlify(pdu.params['short_message'])])
        self.assertEqual(receivedHttpReq['origin-connector'], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_delivery_HttpConnector_message_payload_when_short_message_empty(self):
        """Related to #470
        Consider 'message_payload' when 'short_message' is empty"""
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        assert_content = 'Some content'
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            message_payload=assert_content
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['content'], [assert_content])
        self.assertEqual(receivedHttpReq['binary'], [binascii.hexlify(assert_content)])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='any content',
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['from'], [pdu.params['source_addr']])
        self.assertEqual(receivedHttpReq['to'],
                         [pdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq['content'],
                         [pdu.params['short_message']])
        self.assertEqual(receivedHttpReq['binary'],
                         [binascii.hexlify(pdu.params['short_message'])])
        self.assertEqual(receivedHttpReq['origin-connector'],
                         [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def prepareRoutingsAndStartConnector(self, connector):
        self.AckServerResource.render_GET = mock.Mock(
            wraps=self.AckServerResource.render_GET)

        # Prepare for routing
        connector.port = self.SMSCPort.getHost().port
        c2_destination = HttpConnector(
            id_generator(),
            'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
        # Set the route
        yield self.moroute_add(DefaultRoute(c2_destination), 0)

        # Now we'll create the connector 1 from which we'll receive DeliverSm PDUs before
        # throwing to http
        yield self.SMPPClientManagerPBProxy.connect('127.0.0.1',
                                                    self.CManagerPort)
        c1Config = SMPPClientConfig(id=connector.cid, port=connector.port)
        yield self.SMPPClientManagerPBProxy.add(c1Config)

        # Start the connector
        yield self.SMPPClientManagerPBProxy.start(connector.cid)
        # Wait for 'BOUND_TRX' state
        while True:
            ssRet = yield self.SMPPClientManagerPBProxy.session_state(
                connector.cid)
            if ssRet == 'BOUND_TRX':
                break
            else:
                time.sleep(0.2)
Example #10
0
    def test_delivery_HttpConnector(self):
        yield self.connect("127.0.0.1", self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a data_sm from the SMSC
        pdu = DataSM(source_addr="1234", destination_addr="4567", message_payload="any content")
        yield self.triggerDataSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEquals(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 6)
        self.assertEqual(receivedHttpReq["from"], [pdu.params["source_addr"]])
        self.assertEqual(receivedHttpReq["to"], [pdu.params["destination_addr"]])
        self.assertEqual(receivedHttpReq["content"], [pdu.params["message_payload"]])
        self.assertEqual(receivedHttpReq["origin-connector"], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def prepareRoutingsAndStartConnector(self, connector, route=None, route_order=1):
        self.AckServerResource.render_GET = mock.Mock(wraps=self.AckServerResource.render_GET)

        # Prepare for routing
        connector.port = self.SMSCPort.getHost().port

        # Set the route
        if route is None:
            c2_destination = HttpConnector(id_generator(), 'http://127.0.0.1:%s/send' % self.AckServer.getHost().port)
            yield self.moroute_add(DefaultRoute(c2_destination), 0)
        else:
            yield self.moroute_add(route, route_order)

        # Now we'll create the connector 1 from which we'll receive DeliverSm PDUs before
        # throwing to http
        yield self.SMPPClientManagerPBProxy.connect('127.0.0.1', self.CManagerPort)
        c1Config = SMPPClientConfig(id=connector.cid, port=connector.port)
        yield self.SMPPClientManagerPBProxy.add(c1Config)

        # Start the connector
        yield self.SMPPClientManagerPBProxy.start(connector.cid)
        # Wait for 'BOUND_TRX' state
        while True:
            ssRet = yield self.SMPPClientManagerPBProxy.session_state(connector.cid)
            if ssRet == 'BOUND_TRX':
                break
            else:
                yield waitFor(0.2)
    def test_unordered_long_content_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            sar_total_segments=3,
            sar_msg_ref_num=int(id_generator(size=2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params[
            'short_message'] = '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part1.params['sar_segment_seqnum'] = 1
        pdu_part2.params[
            'short_message'] = '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part2.params['sar_segment_seqnum'] = 2
        pdu_part3.params['short_message'] = '__3rd_part_end.'
        pdu_part3.params['sar_segment_seqnum'] = 3
        yield self.triggerDeliverSmFromSMSC([pdu_part2, pdu_part1, pdu_part3])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq['from'], [basePdu.params['source_addr']])
        self.assertEqual(receivedHttpReq['to'], [basePdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq['content'], [
            pdu_part1.params['short_message'] + pdu_part2.params['short_message'] + pdu_part3.params['short_message']])
        self.assertEqual(receivedHttpReq['binary'], [binascii.hexlify(
            pdu_part1.params['short_message'] + pdu_part2.params['short_message'] + pdu_part3.params['short_message'])])
        self.assertEqual(receivedHttpReq['origin-connector'], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
Example #13
0
    def provision_user_connector(self, add_route = True):
        # provision user
        g1 = Group(1)
        yield self.group_add(g1)        
        self.c1 = SmppClientConnector(id_generator())
        u1_password = '******'
        self.u1 = User(1, g1, 'username', u1_password)
        yield self.user_add(self.u1)

        # provision route
        if add_route:
            yield self.mtroute_add(DefaultRoute(self.c1), 0)
Example #14
0
    def setUp(self):
        SMPPClientTestCases.setUp(self)

        # Provision a user and default route into RouterPB
        # Add throughput limit on user
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.foo.mt_credential.setQuota('smpps_throughput', 2)
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user = self.foo, defaultroute = self.defaultroute)

        self.stats = SMPPServerStatsCollector().get(cid = self.smpps_config.id)
Example #15
0
    def setUp(self):
        SMPPClientTestCases.setUp(self)

        # Provision a user and default route into RouterPB
        # Add throughput limit on user
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.foo.mt_credential.setQuota('smpps_throughput', 2)
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)

        self.stats = SMPPServerStatsCollector().get(cid=self.smpps_config.id)
Example #16
0
    def provision_user_connector(self, add_route = True):
        # provision user
        g1 = Group(1)
        yield self.group_add(g1)
        self.c1 = SmppClientConnector(id_generator())
        u1_password = '******'
        self.u1 = User(1, g1, 'username', u1_password)
        yield self.user_add(self.u1)

        # provision route
        if add_route:
            yield self.mtroute_add(DefaultRoute(self.c1), 0)
Example #17
0
    def setUp(self):
        SMPPClientTestCases.setUp(self)

        # Provision a user and default route into RouterPB
        # Add throughput limit on user
        self.foo = User("u1", Group("test"), "username", "password")
        self.foo.mt_credential.setQuota("smpps_throughput", 2)
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)

        self.user = self.routerpb_factory.getUser("u1")
Example #18
0
    def setUp(self):
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        self.routerpb_config = RouterPBConfig()

        # Instanciate RouterPB but will not launch a server
        # we only need the instance to access its .users attribute
        # for authentication
        self.routerpb_factory = RouterPB(self.routerpb_config, persistenceTimer=False)

        # Provision a user and default route into RouterPB
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user = self.foo, defaultroute = self.defaultroute)
Example #19
0
    def setUp(self):
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        self.routerpb_config = RouterPBConfig()

        # Instanciate RouterPB but will not launch a server
        # we only need the instance to access its .users attribute
        # for authentication
        self.routerpb_factory = RouterPB(self.routerpb_config, persistenceTimer=False)

        # Provision a user and default route into RouterPB
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)
Example #20
0
    def prepareRoutingsAndStartConnector(self, connector):
        self.AckServerResource.render_GET = mock.Mock(wraps=self.AckServerResource.render_GET)

        # Prepare for routing
        connector.port = self.SMSCPort.getHost().port
        c2_destination = HttpConnector(id_generator(), "http://127.0.0.1:%s/send" % self.AckServer.getHost().port)
        # Set the route
        yield self.moroute_add(DefaultRoute(c2_destination), 0)

        # Now we'll create the connector 1 from which we'll receive DataSM PDUs before
        # throwing to http
        yield self.SMPPClientManagerPBProxy.connect("127.0.0.1", self.CManagerPort)
        c1Config = SMPPClientConfig(id=connector.cid, port=connector.port)
        yield self.SMPPClientManagerPBProxy.add(c1Config)

        # Start the connector
        yield self.SMPPClientManagerPBProxy.start(connector.cid)
        # Wait for 'BOUND_TRX' state
        while True:
            ssRet = yield self.SMPPClientManagerPBProxy.session_state(connector.cid)
            if ssRet == "BOUND_TRX":
                break
            else:
                time.sleep(0.2)
Example #21
0
    def test_long_content_delivery_UDH_HttpConnector(self):
        yield self.connect("127.0.0.1", self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Build a UDH
        baseUdh = []
        baseUdh.append(struct.pack("!B", 5))  # Length of User Data Header
        baseUdh.append(
            struct.pack("!B", 0)
        )  # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
        baseUdh.append(struct.pack("!B", 3))  # Length of the header, excluding the first two fields; equal to 03
        baseUdh.append(struct.pack("!B", int(id_generator(size=2, chars=string.digits))))  # msg_ref_num
        baseUdh.append(struct.pack("!B", 3))  # total_segments

        # Send a data_sm from the SMSC
        basePdu = DataSM(
            source_addr="1234",
            destination_addr="4567",
            message_payload="",
            esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT, [EsmClassGsmFeatures.UDHI_INDICATOR_SET]),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        udh_part1 = copy.deepcopy(baseUdh)
        pdu_part2 = copy.deepcopy(basePdu)
        udh_part2 = copy.deepcopy(baseUdh)
        pdu_part3 = copy.deepcopy(basePdu)
        udh_part3 = copy.deepcopy(baseUdh)
        udh_part1.append(struct.pack("!B", 1))  # segment_seqnum
        pdu_part1.params["more_messages_to_send"] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part1.params["message_payload"] = (
            "".join(udh_part1)
            + "__1st_part_with_153_char________________________________________________________________________________________________________________________________."
        )
        udh_part2.append(struct.pack("!B", 2))  # segment_seqnum
        pdu_part2.params["more_messages_to_send"] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part2.params["message_payload"] = (
            "".join(udh_part2)
            + "__2nd_part_with_153_char________________________________________________________________________________________________________________________________."
        )
        udh_part3.append(struct.pack("!B", 3))  # segment_seqnum
        pdu_part3.params["more_messages_to_send"] = MoreMessagesToSend.NO_MORE_MESSAGES
        pdu_part3.params["message_payload"] = "".join(udh_part3) + "__3rd_part_end."
        yield self.triggerDataSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_GET.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 6)
        self.assertEqual(receivedHttpReq["from"], [basePdu.params["source_addr"]])
        self.assertEqual(receivedHttpReq["to"], [basePdu.params["destination_addr"]])
        self.assertEqual(
            receivedHttpReq["content"],
            [
                pdu_part1.params["message_payload"][6:]
                + pdu_part2.params["message_payload"][6:]
                + pdu_part3.params["message_payload"][6:]
            ],
        )
        self.assertEqual(receivedHttpReq["origin-connector"], [source_connector.cid])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
    def test_long_content_delivery_UDH_SmppsConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        yield self.prepareRoutingsAndStartConnector()

        # Bind
        yield self.smppc_factory.connectAndBind()

        # Install mocks
        self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(
            wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

        # Build a UDH
        baseUdh = []
        baseUdh.append(struct.pack('!B', 5))  # Length of User Data Header
        baseUdh.append(
            struct.pack('!B', 0)
        )  # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
        baseUdh.append(
            struct.pack('!B', 3)
        )  # Length of the header, excluding the first two fields; equal to 03
        baseUdh.append(
            struct.pack('!B',
                        int(id_generator(size=2,
                                         chars=string.digits))))  # msg_ref_num
        baseUdh.append(struct.pack('!B', 3))  # total_segments

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT,
                               [EsmClassGsmFeatures.UDHI_INDICATOR_SET]),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        udh_part1 = copy.deepcopy(baseUdh)
        pdu_part2 = copy.deepcopy(basePdu)
        udh_part2 = copy.deepcopy(baseUdh)
        pdu_part3 = copy.deepcopy(basePdu)
        udh_part3 = copy.deepcopy(baseUdh)
        udh_part1.append(struct.pack('!B', 1))  # segment_seqnum
        pdu_part1.params[
            'more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part1.params['short_message'] = ''.join(
            udh_part1
        ) + '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part2.append(struct.pack('!B', 2))  # segment_seqnum
        pdu_part2.params[
            'more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part2.params['short_message'] = ''.join(
            udh_part2
        ) + '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part3.append(struct.pack('!B', 3))  # segment_seqnum
        pdu_part3.params[
            'more_messages_to_send'] = MoreMessagesToSend.NO_MORE_MESSAGES
        pdu_part3.params['short_message'] = ''.join(
            udh_part3) + '__3rd_part_end.'
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        self.assertEqual(
            self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 3)
        # First received pdu
        received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            0][0][0]
        self.assertEqual(received_pdu_1.seqNum, 1)
        self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_1.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_1.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_1.params['esm_class'],
                         basePdu.params['esm_class'])
        self.assertEqual(received_pdu_1.params['short_message'][6:],
                         pdu_part1.params['short_message'][6:])
        # Second received pdu
        received_pdu_2 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            1][0][0]
        self.assertEqual(received_pdu_2.seqNum, 2)
        self.assertEqual(received_pdu_2.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_2.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_2.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_2.params['esm_class'],
                         basePdu.params['esm_class'])
        self.assertEqual(received_pdu_2.params['short_message'][6:],
                         pdu_part2.params['short_message'][6:])
        # Third received pdu
        received_pdu_3 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            2][0][0]
        self.assertEqual(received_pdu_3.seqNum, 3)
        self.assertEqual(received_pdu_3.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_3.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_3.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_3.params['esm_class'],
                         basePdu.params['esm_class'])
        self.assertEqual(received_pdu_3.params['short_message'][6:],
                         pdu_part3.params['short_message'][6:])

        # Unbind and disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        yield self.stopSmppClientConnectors()
    def test_long_content_delivery_SAR_SmppsConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        yield self.prepareRoutingsAndStartConnector()

        # Bind
        yield self.smppc_factory.connectAndBind()

        # Install mocks
        self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(
            wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            sar_total_segments=3,
            sar_msg_ref_num=int(id_generator(size=2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params[
            'short_message'] = '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part1.params['sar_segment_seqnum'] = 1
        pdu_part2.params[
            'short_message'] = '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part2.params['sar_segment_seqnum'] = 2
        pdu_part3.params['short_message'] = '__3rd_part_end.'
        pdu_part3.params['sar_segment_seqnum'] = 3
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        self.assertEqual(
            self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 3)
        # First received pdu
        received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            0][0][0]
        self.assertEqual(received_pdu_1.seqNum, 1)
        self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_1.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_1.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_1.params['short_message'],
                         pdu_part1.params['short_message'])
        self.assertEqual(received_pdu_1.params['sar_segment_seqnum'],
                         pdu_part1.params['sar_segment_seqnum'])
        # Second received pdu
        received_pdu_2 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            1][0][0]
        self.assertEqual(received_pdu_2.seqNum, 2)
        self.assertEqual(received_pdu_2.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_2.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_2.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_2.params['short_message'],
                         pdu_part2.params['short_message'])
        self.assertEqual(received_pdu_2.params['sar_segment_seqnum'],
                         pdu_part2.params['sar_segment_seqnum'])
        self.assertNotEqual(received_pdu_2.params['short_message'],
                            received_pdu_1.params['short_message'])
        self.assertNotEqual(received_pdu_2.params['sar_segment_seqnum'],
                            received_pdu_1.params['sar_segment_seqnum'])
        # Third received pdu
        received_pdu_3 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[
            2][0][0]
        self.assertEqual(received_pdu_3.seqNum, 3)
        self.assertEqual(received_pdu_3.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_3.params['source_addr'],
                         basePdu.params['source_addr'])
        self.assertEqual(received_pdu_3.params['destination_addr'],
                         basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_3.params['short_message'],
                         pdu_part3.params['short_message'])
        self.assertEqual(received_pdu_3.params['sar_segment_seqnum'],
                         pdu_part3.params['sar_segment_seqnum'])
        self.assertNotEqual(received_pdu_3.params['short_message'],
                            received_pdu_2.params['short_message'])
        self.assertNotEqual(received_pdu_3.params['sar_segment_seqnum'],
                            received_pdu_2.params['sar_segment_seqnum'])

        # Unbind and disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        yield self.stopSmppClientConnectors()
Example #24
0
    def test_long_content_delivery_UDH_SmppsConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        yield self.prepareRoutingsAndStartConnector()

        # Bind
        yield self.smppc_factory.connectAndBind()

        # Install mocks
        self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

        # Build a UDH
        baseUdh = []
        baseUdh.append(struct.pack('!B', 5)) # Length of User Data Header
        baseUdh.append(struct.pack('!B', 0)) # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
        baseUdh.append(struct.pack('!B', 3)) # Length of the header, excluding the first two fields; equal to 03
        baseUdh.append(struct.pack('!B', int(id_generator(size = 2, chars=string.digits)))) # msg_ref_num
        baseUdh.append(struct.pack('!B', 3)) # total_segments

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr = '1234',
            destination_addr = '4567',
            short_message = '',
            esm_class = EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT, [EsmClassGsmFeatures.UDHI_INDICATOR_SET]),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        udh_part1 = copy.deepcopy(baseUdh)
        pdu_part2 = copy.deepcopy(basePdu)
        udh_part2 = copy.deepcopy(baseUdh)
        pdu_part3 = copy.deepcopy(basePdu)
        udh_part3 = copy.deepcopy(baseUdh)
        udh_part1.append(struct.pack('!B', 1)) # segment_seqnum
        pdu_part1.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part1.params['short_message'] = ''.join(udh_part1)+'__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part2.append(struct.pack('!B', 2)) # segment_seqnum
        pdu_part2.params['more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES
        pdu_part2.params['short_message'] = ''.join(udh_part2)+'__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        udh_part3.append(struct.pack('!B', 3)) # segment_seqnum
        pdu_part3.params['more_messages_to_send'] = MoreMessagesToSend.NO_MORE_MESSAGES
        pdu_part3.params['short_message'] = ''.join(udh_part3)+'__3rd_part_end.'
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 3)
        # First received pdu
        received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[0][0][0]
        self.assertEqual(received_pdu_1.seqNum, 1)
        self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_1.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_1.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_1.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_1.params['short_message'][6:], pdu_part1.params['short_message'][6:])
        # Second received pdu
        received_pdu_2 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[1][0][0]
        self.assertEqual(received_pdu_2.seqNum, 2)
        self.assertEqual(received_pdu_2.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_2.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_2.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_2.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_2.params['short_message'][6:], pdu_part2.params['short_message'][6:])
        # Third received pdu
        received_pdu_3 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[2][0][0]
        self.assertEqual(received_pdu_3.seqNum, 3)
        self.assertEqual(received_pdu_3.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_3.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_3.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_3.params['esm_class'], basePdu.params['esm_class'])
        self.assertEqual(received_pdu_3.params['short_message'][6:], pdu_part3.params['short_message'][6:])

        # Unbind and disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        yield self.stopSmppClientConnectors()
Example #25
0
    def test_long_content_delivery_SAR_SmppsConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        yield self.prepareRoutingsAndStartConnector()

        # Bind
        yield self.smppc_factory.connectAndBind()

        # Install mocks
        self.smppc_factory.lastProto.PDUDataRequestReceived = mock.Mock(wraps=self.smppc_factory.lastProto.PDUDataRequestReceived)

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr = '1234',
            destination_addr = '4567',
            short_message = '',
            sar_total_segments = 3,
            sar_msg_ref_num = int(id_generator(size = 2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params['short_message'] = '__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part1.params['sar_segment_seqnum'] = 1
        pdu_part2.params['short_message'] = '__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part2.params['sar_segment_seqnum'] = 2
        pdu_part3.params['short_message'] = '__3rd_part_end.'
        pdu_part3.params['sar_segment_seqnum'] = 3
        yield self.triggerDeliverSmFromSMSC([pdu_part1, pdu_part2, pdu_part3])

        # Run tests
        self.assertEqual(self.smppc_factory.lastProto.PDUDataRequestReceived.call_count, 3)
        # First received pdu
        received_pdu_1 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[0][0][0]
        self.assertEqual(received_pdu_1.seqNum, 1)
        self.assertEqual(received_pdu_1.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_1.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_1.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_1.params['short_message'], pdu_part1.params['short_message'])
        self.assertEqual(received_pdu_1.params['sar_segment_seqnum'], pdu_part1.params['sar_segment_seqnum'])
        # Second received pdu
        received_pdu_2 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[1][0][0]
        self.assertEqual(received_pdu_2.seqNum, 2)
        self.assertEqual(received_pdu_2.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_2.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_2.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_2.params['short_message'], pdu_part2.params['short_message'])
        self.assertEqual(received_pdu_2.params['sar_segment_seqnum'], pdu_part2.params['sar_segment_seqnum'])
        self.assertNotEqual(received_pdu_2.params['short_message'], received_pdu_1.params['short_message'])
        self.assertNotEqual(received_pdu_2.params['sar_segment_seqnum'], received_pdu_1.params['sar_segment_seqnum'])
        # Third received pdu
        received_pdu_3 = self.smppc_factory.lastProto.PDUDataRequestReceived.call_args_list[2][0][0]
        self.assertEqual(received_pdu_3.seqNum, 3)
        self.assertEqual(received_pdu_3.id, pdu_types.CommandId.deliver_sm)
        self.assertEqual(received_pdu_3.params['source_addr'], basePdu.params['source_addr'])
        self.assertEqual(received_pdu_3.params['destination_addr'], basePdu.params['destination_addr'])
        self.assertEqual(received_pdu_3.params['short_message'], pdu_part3.params['short_message'])
        self.assertEqual(received_pdu_3.params['sar_segment_seqnum'], pdu_part3.params['sar_segment_seqnum'])
        self.assertNotEqual(received_pdu_3.params['short_message'], received_pdu_2.params['short_message'])
        self.assertNotEqual(received_pdu_3.params['sar_segment_seqnum'], received_pdu_2.params['sar_segment_seqnum'])

        # Unbind and disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        yield self.stopSmppClientConnectors()