Exemple #1
0
	def test_stats_inc(self):
		stats = SMPPServerStatsCollector().get(cid = 'test_stats_inc')
		self.assertEqual(stats.get('bound_tx_count'), 0)

		stats.inc('bound_tx_count')
		self.assertEqual(stats.get('bound_tx_count'), 1)

		stats.inc('bound_tx_count', 5)
		self.assertEqual(stats.get('bound_tx_count'), 6)
Exemple #2
0
	def test_is_singleton(self):
		i1 = SMPPServerStatsCollector()
		i2 = SMPPServerStatsCollector()
		self.assertEqual(i1, i2)

		i1.get(cid = 'testing').set('bind_rx_count', 100)

		self.assertEqual(i1.get(cid = 'testing').get('bind_rx_count'),
						 i2.get(cid = 'testing').get('bind_rx_count'),
						 )
Exemple #3
0
	def test_get_will_reuse_existent_connector(self):
		c = SMPPServerStatsCollector()
		self.assertTrue('test_get_will_reuse_existent_connector' not in c.connectors)

		i1 = c.get(cid = 'test_get_will_reuse_existent_connector')
		i2 = c.get(cid = 'test_get_will_reuse_existent_connector')
		self.assertEqual(i1, i2)
    def test_02_enquire_link(self):
        self.smppc_config.enquireLinkTimerSecs = 1
        stats = SMPPServerStatsCollector().get(cid=self.smpps_config.id)

        self.assertEqual(stats.get('last_received_elink_at'), 0)

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Wait some secs in order to receive some elinks
        yield waitFor(6)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

        self.assertTrue(type(stats.get('last_received_elink_at')) == datetime)
Exemple #5
0
    def test_02_enquire_link(self):
        self.smppc_config.enquireLinkTimerSecs = 1
        stats = SMPPServerStatsCollector().get(cid = self.smpps_config.id)

        self.assertEqual(stats.get('last_received_elink_at'), 0)

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Wait some secs in order to receive some elinks
        yield waitFor(6)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

        self.assertTrue(type(stats.get('last_received_elink_at')) == datetime)
Exemple #6
0
    def smppsapi(self, arg, opts):
        """As of Jasmin's 0.6 version, there can be only one SMPPs API, the smpp server id
        is set for later evolution to handle multiple APIs, this is why the id is hard coded
        to 'smpps_01'.
        """
        sc = SMPPServerStatsCollector()
        headers = ["#Item", "Value"]

        table = []
        for k, v in sc.get('smpps_01')._stats.iteritems():
            row = []
            row.append('#%s' % k)
            if k[-3:] == '_at':
                row.append(formatDateTime(v))
            else:
                row.append(v)

            table.append(row)

        self.protocol.sendData(tabulate(table, headers, tablefmt="plain", numalign="left").encode('ascii'))
Exemple #7
0
    def smppsapi(self, arg, opts):
        """As of Jasmin's 0.6 version, there can be only one SMPPs API, the smpp server id
        is set for later evolution to handle multiple APIs, this is why the id is hard coded
        to 'smpps_01'.
        """
        sc = SMPPServerStatsCollector()
        headers = ["#Item", "Value"]

        table = []
        for k, v in sc.get('smpps_01').getStats().iteritems():
            row = []
            row.append('#%s' % k)
            if k[-3:] == '_at':
                row.append(formatDateTime(v))
            else:
                row.append(v)

            table.append(row)

        self.protocol.sendData(tabulate(table, headers, tablefmt="plain", numalign="left").encode('ascii'))
Exemple #8
0
	def test_get_will_create_connector(self):
		c = SMPPServerStatsCollector()
		self.assertTrue('test_get_will_create_connector' not in c.connectors)

		c.get(cid = 'test_get_will_create_connector')
		self.assertTrue('test_get_will_create_connector' in c.connectors)
Exemple #9
0
	def test_stats_set(self):
		stats = SMPPServerStatsCollector().get(cid = 'test_stats_set')
		self.assertEqual(stats.get('bind_rx_count'), 0)

		stats.set('bind_rx_count', 2)
		self.assertEqual(stats.get('bind_rx_count'), 2)
Exemple #10
0
    def test_01_smpps_basic(self):
        "A simple test of _some_ stats parameters"
        stats = SMPPServerStatsCollector().get(cid=self.smpps_config.id)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertEqual(stats.get('last_received_pdu_at'), 0)
        self.assertEqual(stats.get('last_sent_pdu_at'), 0)
        self.assertEqual(stats.get('connected_count'), 0)
        self.assertEqual(stats.get('connect_count'), 0)
        self.assertEqual(stats.get('disconnect_count'), 0)
        self.assertEqual(stats.get('bound_trx_count'), 0)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 0)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 0)

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState,
                         SMPPSessionStates.BOUND_TRX)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertTrue(type(stats.get('last_received_pdu_at')) == datetime)
        self.assertTrue(type(stats.get('last_sent_pdu_at')) == datetime)
        self.assertEqual(stats.get('connected_count'), 1)
        self.assertEqual(stats.get('connect_count'), 1)
        self.assertEqual(stats.get('disconnect_count'), 0)
        self.assertEqual(stats.get('bound_trx_count'), 1)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 1)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 0)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState,
                         SMPPSessionStates.UNBOUND)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertTrue(type(stats.get('last_received_pdu_at')) == datetime)
        self.assertTrue(type(stats.get('last_sent_pdu_at')) == datetime)
        self.assertEqual(stats.get('connected_count'), 0)
        self.assertEqual(stats.get('connect_count'), 1)
        self.assertEqual(stats.get('disconnect_count'), 1)
        self.assertEqual(stats.get('bound_trx_count'), 0)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 1)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 1)
class SmppsStatsTestCases(SMPPClientTestCases):
    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)

    @defer.inlineCallbacks
    def test_elink_count(self):
        self.smppc_config.enquireLinkTimerSecs = 1

        # Save the 'before' value
        _elink_count = self.stats.get('elink_count')

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Wait
        yield waitFor(5)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

        # Asserts
        self.assertEqual(_elink_count + 4, self.stats.get('elink_count'))

    @defer.inlineCallbacks
    def test_throttling_error_count(self):
        """In this test it is demonstrated the
        difference between submit_sm_request_count and submit_sm_count:
        * submit_sm_request_count: is the number of submit_sm requested
        * submit_sm_count: is number of submit_sm accepted (replied with ESME_ROK)
        """

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _submit_sm_request_count = self.stats.get('submit_sm_request_count')
        _throttling_error_count = self.stats.get('throttling_error_count')
        _other_submit_error_count = self.stats.get('other_submit_error_count')
        _submit_sm_count = self.stats.get('submit_sm_count')

        # SMPPClient > SMPPServer
        for _ in range(50):
            yield self.smppc_factory.lastProto.sendDataRequest(self.SubmitSmPDU)
            yield waitFor(0.1)

        # Assert after
        self.assertEqual(self.stats.get('submit_sm_request_count'), _submit_sm_request_count + 50)
        self.assertEqual(self.stats.get('other_submit_error_count'), _other_submit_error_count)
        self.assertLess(self.stats.get('throttling_error_count'), _submit_sm_request_count + 50)
        self.assertGreater(self.stats.get('throttling_error_count'), 0)
        self.assertGreater(self.stats.get('submit_sm_count'), _submit_sm_count)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_other_submit_error_count(self):
        """Send a submit_sm wile bound_rx: will get a resp with ESME_RINVBNDSTS
        Will also ensure
        """

        self.smppc_config.bindOperation = 'receiver'

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_RX)

        # Save the 'before' value
        _other_submit_error_count = self.stats.get('other_submit_error_count')
        _throttling_error_count = self.stats.get('throttling_error_count')

        # SMPPClient > SMPPServer
        yield self.smppc_factory.lastProto.sendDataRequest(self.SubmitSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('other_submit_error_count'), _other_submit_error_count + 1)
        self.assertEqual(self.stats.get('throttling_error_count'), _throttling_error_count)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_deliver_sm_count(self):
        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _deliver_sm_count = self.stats.get('deliver_sm_count')

        # SMPPServer > SMPPClient
        yield self.smpps_factory.lastProto.sendDataRequest(self.DeliverSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('deliver_sm_count'), _deliver_sm_count + 1)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_data_sm_count(self):
        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _data_sm_count = self.stats.get('data_sm_count')

        # SMPPServer > SMPPClient
        yield self.smpps_factory.lastProto.sendDataRequest(self.DataSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('data_sm_count'), _data_sm_count + 1)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)
Exemple #12
0
    def test_01_smpps_basic(self):
        "A simple test of _some_ stats parameters"
        stats = SMPPServerStatsCollector().get(cid = self.smpps_config.id)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertEqual(stats.get('last_received_pdu_at'), 0)
        self.assertEqual(stats.get('last_sent_pdu_at'), 0)
        self.assertEqual(stats.get('connected_count'), 0)
        self.assertEqual(stats.get('connect_count'), 0)
        self.assertEqual(stats.get('disconnect_count'), 0)
        self.assertEqual(stats.get('bound_trx_count'), 0)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 0)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 0)

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertTrue(type(stats.get('last_received_pdu_at')) == datetime)
        self.assertTrue(type(stats.get('last_sent_pdu_at')) == datetime)
        self.assertEqual(stats.get('connected_count'), 1)
        self.assertEqual(stats.get('connect_count'), 1)
        self.assertEqual(stats.get('disconnect_count'), 0)
        self.assertEqual(stats.get('bound_trx_count'), 1)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 1)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 0)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

        self.assertTrue(type(stats.get('created_at')) == datetime)
        self.assertTrue(type(stats.get('last_received_pdu_at')) == datetime)
        self.assertTrue(type(stats.get('last_sent_pdu_at')) == datetime)
        self.assertEqual(stats.get('connected_count'), 0)
        self.assertEqual(stats.get('connect_count'), 1)
        self.assertEqual(stats.get('disconnect_count'), 1)
        self.assertEqual(stats.get('bound_trx_count'), 0)
        self.assertEqual(stats.get('bound_rx_count'), 0)
        self.assertEqual(stats.get('bound_tx_count'), 0)
        self.assertEqual(stats.get('bind_trx_count'), 1)
        self.assertEqual(stats.get('bind_rx_count'), 0)
        self.assertEqual(stats.get('bind_tx_count'), 0)
        self.assertEqual(stats.get('unbind_count'), 1)
Exemple #13
0
class SmppsStatsTestCases(SMPPClientTestCases):

    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)

    @defer.inlineCallbacks
    def test_elink_count(self):
        self.smppc_config.enquireLinkTimerSecs = 1

        # Save the 'before' value
        _elink_count = self.stats.get('elink_count')

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Wait
        yield waitFor(5)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

        # Asserts
        self.assertEqual(_elink_count+4, self.stats.get('elink_count'))

    @defer.inlineCallbacks
    def test_throttling_error_count(self):
        """In this test it is demonstrated the
        difference between submit_sm_request_count and submit_sm_count:
        * submit_sm_request_count: is the number of submit_sm requested
        * submit_sm_count: is number of submit_sm accepted (replied with ESME_ROK)
        """

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _submit_sm_request_count = self.stats.get('submit_sm_request_count')
        _throttling_error_count = self.stats.get('throttling_error_count')
        _other_submit_error_count = self.stats.get('other_submit_error_count')
        _submit_sm_count = self.stats.get('submit_sm_count')

        # SMPPClient > SMPPServer
        for _ in range(50):
            yield self.smppc_factory.lastProto.sendDataRequest(self.SubmitSmPDU)
            yield waitFor(0.1)

        # Assert after
        self.assertEqual(self.stats.get('submit_sm_request_count'), _submit_sm_request_count+50)
        self.assertEqual(self.stats.get('other_submit_error_count'), _other_submit_error_count)
        self.assertLess(self.stats.get('throttling_error_count'), _submit_sm_request_count+50)
        self.assertGreater(self.stats.get('throttling_error_count'), 0)
        self.assertGreater(self.stats.get('submit_sm_count'), _submit_sm_count)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_other_submit_error_count(self):
        """Send a submit_sm wile bound_rx: will get a resp with ESME_RINVBNDSTS
        Will also ensure
        """

        self.smppc_config.bindOperation = 'receiver'

        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_RX)

        # Save the 'before' value
        _other_submit_error_count = self.stats.get('other_submit_error_count')
        _throttling_error_count = self.stats.get('throttling_error_count')

        # SMPPClient > SMPPServer
        yield self.smppc_factory.lastProto.sendDataRequest(self.SubmitSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('other_submit_error_count'), _other_submit_error_count+1)
        self.assertEqual(self.stats.get('throttling_error_count'), _throttling_error_count)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_deliver_sm_count(self):
        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _deliver_sm_count = self.stats.get('deliver_sm_count')

        # SMPPServer > SMPPClient
        yield self.smpps_factory.lastProto.sendDataRequest(self.DeliverSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('deliver_sm_count'), _deliver_sm_count+1)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)

    @defer.inlineCallbacks
    def test_data_sm_count(self):
        # Connect and bind
        yield self.smppc_factory.connectAndBind()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.BOUND_TRX)

        # Save the 'before' value
        _data_sm_count = self.stats.get('data_sm_count')

        # SMPPServer > SMPPClient
        yield self.smpps_factory.lastProto.sendDataRequest(self.DataSmPDU)

        # Assert after
        self.assertEqual(self.stats.get('data_sm_count'), _data_sm_count+1)

        # Unbind & Disconnect
        yield self.smppc_factory.smpp.unbindAndDisconnect()
        self.assertEqual(self.smppc_factory.smpp.sessionState, SMPPSessionStates.UNBOUND)