Example #1
0
    def sendPDU(self, pdu):
        twistedSMPPClientProtocol.sendPDU(self, pdu)

        # Stats:
        self.factory.stats.set('last_sent_pdu_at', datetime.now())
        if pdu.id == CommandId.enquire_link:
            self.factory.stats.set('last_sent_elink_at', datetime.now())
Example #2
0
    def connectionMade(self):
        twistedSMPPClientProtocol.connectionMade(self)
        self.factory.stats.set('connected_at', datetime.now())
        self.factory.stats.inc('connected_count')

        self.log.info("Connection made to %s:%s", self.config().host, self.config().port)

        self.factory.connectDeferred.callback(self)
Example #3
0
    def connectionMade(self):
        twistedSMPPClientProtocol.connectionMade(self)
        self.factory.stats.set('connected_at', datetime.now())
        self.factory.stats.inc('connected_count')

        self.log.info("Connection made to %s:%s", self.config().host, self.config().port)

        self.factory.connectDeferred.callback(self)
Example #4
0
    def doPDURequest(self, reqPDU, handler):
        twistedSMPPClientProtocol.doPDURequest(self, reqPDU, handler)

        # Stats
        if reqPDU.commandId == CommandId.enquire_link:
            self.factory.stats.set('last_received_elink_at', datetime.now())
        elif reqPDU.commandId == CommandId.deliver_sm:
            self.factory.stats.inc('deliver_sm_count')
        elif reqPDU.commandId == CommandId.data_sm:
            self.factory.stats.inc('data_sm_count')
Example #5
0
    def sendPDU(self, pdu):
        twistedSMPPClientProtocol.sendPDU(self, pdu)

        # Stats:
        self.factory.stats.set('last_sent_pdu_at', datetime.now())
        if pdu.commandId == CommandId.enquire_link:
            self.factory.stats.set('last_sent_elink_at', datetime.now())
            self.factory.stats.inc('elink_count')
        elif pdu.commandId == CommandId.submit_sm:
            self.factory.stats.inc('submit_sm_request_count')
Example #6
0
    def doPDURequest(self, reqPDU, handler):
        twistedSMPPClientProtocol.doPDURequest(self, reqPDU, handler)

        # Stats
        if reqPDU.commandId == CommandId.enquire_link:
            self.factory.stats.set('last_received_elink_at', datetime.now())
        elif reqPDU.commandId == CommandId.deliver_sm:
            self.factory.stats.inc('deliver_sm_count')
        elif reqPDU.commandId == CommandId.data_sm:
            self.factory.stats.inc('data_sm_count')
Example #7
0
 def getProtocolObject(self):
     smpp = SMPPClientProtocol()
     config = SMPPClientConfig(
         host='localhost',
         port = 82,
         username = '',
         password = '',
     )
     smpp.config = Mock(return_value=config)
     return smpp
Example #8
0
    def sendPDU(self, pdu):
        twistedSMPPClientProtocol.sendPDU(self, pdu)

        # Stats:
        self.factory.stats.set('last_sent_pdu_at', datetime.now())
        if pdu.commandId == CommandId.enquire_link:
            self.factory.stats.set('last_sent_elink_at', datetime.now())
            self.factory.stats.inc('elink_count')
        elif pdu.commandId == CommandId.submit_sm:
            self.factory.stats.inc('submit_sm_request_count')
Example #9
0
    def claimSeqNum(self):
        seqNum = twistedSMPPClientProtocol.claimSeqNum(self)

        self.factory.stats.set('last_seqNum_at', datetime.now())
        self.factory.stats.set('last_seqNum', seqNum)

        return seqNum
Example #10
0
    def claimSeqNum(self):
        seqNum = twistedSMPPClientProtocol.claimSeqNum(self)

        self.factory.stats.set('last_seqNum_at', datetime.now())
        self.factory.stats.set('last_seqNum', seqNum)

        return seqNum
Example #11
0
    def PDUResponseReceived(self, pdu):
        twistedSMPPClientProtocol.PDUResponseReceived(self, pdu)

        if pdu.commandId == CommandId.submit_sm_resp:
            if pdu.status == CommandStatus.ESME_RTHROTTLED:
                self.factory.stats.inc('throttling_error_count')
            elif pdu.status != CommandStatus.ESME_ROK:
                self.factory.stats.inc('other_submit_error_count')
            else:
                # We got a ESME_ROK
                self.factory.stats.inc('submit_sm_count')
Example #12
0
    def sendDataRequest(self, pdu):
        """If pdu has a 'vendor_specific_bypass' tag, it will be deleted before sending it

        This is a workaround to let Jasmin accepts messages with vendor TLVs but not forwarding them
        to upstream connectors.

        Related to #325
        """
        if pdu.commandId == CommandId.submit_sm and 'vendor_specific_bypass' in pdu.params:
            del pdu.params['vendor_specific_bypass']

        return twistedSMPPClientProtocol.sendDataRequest(self, pdu)
Example #13
0
    def sendDataRequest(self, pdu):
        """If pdu has a 'vendor_specific_bypass' tag, it will be deleted before sending it

        This is a workaround to let Jasmin accepts messages with vendor TLVs but not forwarding them
        to upstream connectors.

        Related to #325
        """
        if pdu.commandId == CommandId.submit_sm and 'vendor_specific_bypass' in pdu.params:
            del pdu.params['vendor_specific_bypass']

        return twistedSMPPClientProtocol.sendDataRequest(self, pdu)
Example #14
0
 def cancelOutboundTransactions(self, err):
     """Cancels LongSubmitSmTransactions when cancelling OutboundTransactions
     """
     twistedSMPPClientProtocol.cancelOutboundTransactions(self, err)
     self.cancelLongSubmitSmTransactions(err)
Example #15
0
 def bindAsTransceiver(self):
     """This is a different signature where msgHandler is taken from factory
     """
     return twistedSMPPClientProtocol.bindAsTransceiver(
         self, self.factory.msgHandler)
Example #16
0
    def bindSucceeded(self, result, nextState):
        self.factory.stats.set('bound_at', datetime.now())
        self.factory.stats.inc('bound_count')

        return twistedSMPPClientProtocol.bindSucceeded(self, result, nextState)
Example #17
0
    def connectionLost(self, reason):
        twistedSMPPClientProtocol.connectionLost(self, reason)

        self.factory.stats.set('disconnected_at', datetime.now())
        self.factory.stats.inc('disconnected_count')
Example #18
0
 def __init__( self ):
     twistedSMPPClientProtocol.__init__(self)
     
     self.longSubmitSmTxns = {}
Example #19
0
    def doSendRequest(self, pdu, timeout):
        if self.connectionCorrupted:
            raise SMPPClientConnectionCorruptedError()
        if not isinstance( pdu, PDURequest ) or pdu.requireAck is None:
            raise SMPPClientError("Invalid PDU to send: %s" % pdu)

        if pdu.commandId == CommandId.submit_sm:
            # Start a LongSubmitSmTransaction if pdu is a long submit_sm and send multiple
            # pdus, each with an OutboundTransaction
            # - Every OutboundTransaction is closed upon receiving the correct submit_sm_resp
            # - Every LongSubmitSmTransaction is closed upong closing all included OutboundTransactions
            
            # UDH is set ?
            UDHI_INDICATOR_SET = False
            if hasattr(pdu.params['esm_class'], 'gsmFeatures'):
                for gsmFeature in pdu.params['esm_class'].gsmFeatures:
                    if str(gsmFeature) == 'UDHI_INDICATOR_SET':
                        UDHI_INDICATOR_SET = True
            
            # Discover any splitting method, otherwise, it is a single SubmitSm
            if 'sar_msg_ref_num' in pdu.params:
                splitMethod = 'sar'
            elif UDHI_INDICATOR_SET and pdu.params['short_message'][:3] == '\x05\x00\x03':
                splitMethod = 'udh'
            else:
                splitMethod = None
            
            if splitMethod is not None:
                partedSmPdu = pdu
                first = True
                
                # Iterate through parted PDUs
                while True:
                    partedSmPdu.seqNum = self.claimSeqNum()

                    # Set LongSubmitSm tracking flags in pdu:
                    partedSmPdu.LongSubmitSm = {'msg_ref_num': None, 'total_segments': None, 'segment_seqnum': None}
                    if splitMethod == 'sar':
                        # Using SAR options:
                        partedSmPdu.LongSubmitSm['msg_ref_num'] = partedSmPdu.params['sar_msg_ref_num']
                        partedSmPdu.LongSubmitSm['total_segments'] = partedSmPdu.params['sar_total_segments']
                        partedSmPdu.LongSubmitSm['segment_seqnum'] = partedSmPdu.params['sar_segment_seqnum']
                    elif splitMethod == 'udh':
                        # Using UDH options:
                        partedSmPdu.LongSubmitSm['msg_ref_num'] = struct.unpack('!B', pdu.params['short_message'][3])[0]
                        partedSmPdu.LongSubmitSm['total_segments'] = struct.unpack('!B', pdu.params['short_message'][4])[0]
                        partedSmPdu.LongSubmitSm['segment_seqnum'] = struct.unpack('!B', pdu.params['short_message'][5])[0]

                    self.preSubmitSm(partedSmPdu)
                    self.sendPDU(partedSmPdu)
                    # Not like parent protocol's sendPDU, we don't return per pdu
                    # deferred, we'll return per transaction deferred instead
                    self.startOutboundTransaction(partedSmPdu, timeout).addCallbacks(
                                                                                     self.endLongSubmitSmTransaction, 
                                                                                     self.endLongSubmitSmTransactionErr
                                                                                     )
                    
                    # Start a transaction using the first parted PDU
                    if first:
                        first = False
                        txn = self.startLongSubmitSmTransaction(partedSmPdu, timeout)
    
                    try:
                        # There still another PDU to go for
                        partedSmPdu = partedSmPdu.nextPdu
                    except AttributeError:
                        break
    
                return txn
            else:
                self.preSubmitSm(pdu)
        
        return twistedSMPPClientProtocol.doSendRequest(self, pdu, timeout)
Example #20
0
    def onPDURequest_enquire_link(self, reqPDU):
        twistedSMPPClientProtocol.onPDURequest_enquire_link(self, reqPDU)

        self.factory.stats.set('last_received_elink_at', datetime.now())
Example #21
0
    def enquireLinkTimerExpired(self):
        twistedSMPPClientProtocol.enquireLinkTimerExpired(self)

        self.factory.stats.set('last_sent_elink_at', datetime.now())
Example #22
0
    def doPDURequest(self, reqPDU, handler):
        twistedSMPPClientProtocol.doPDURequest(self, reqPDU, handler)

        # Stats
        if reqPDU.id == CommandId.enquire_link:
            self.factory.stats.set('last_received_elink_at', datetime.now())
Example #23
0
    def connectionLost(self, reason):
        twistedSMPPClientProtocol.connectionLost(self, reason)

        self.factory.stats.set('disconnected_at', datetime.now())
        self.factory.stats.inc('disconnected_count')
Example #24
0
    def __init__(self):
        twistedSMPPClientProtocol.__init__(self)

        self.longSubmitSmTxns = {}
Example #25
0
    def connectionMade(self):
        twistedSMPPClientProtocol.connectionMade(self)
        self.log.info("Connection made to %s:%s" % (self.factory.config.host, self.factory.config.port))

        self.factory.connectDeferred.callback(self)
Example #26
0
    def doSendRequest(self, pdu, timeout):
        if self.connectionCorrupted:
            raise SMPPClientConnectionCorruptedError()
        if not isinstance(pdu, PDURequest) or pdu.requireAck is None:
            raise SMPPClientError("Invalid PDU to send: %s" % pdu)

        if pdu.commandId == CommandId.submit_sm:
            # Start a LongSubmitSmTransaction if pdu is a long submit_sm and send multiple
            # pdus, each with an OutboundTransaction
            # - Every OutboundTransaction is closed upon receiving the correct submit_sm_resp
            # - Every LongSubmitSmTransaction is closed upong closing all included OutboundTransactions
            #
            # Update 20150709 #234:
            # If the pdu has no nextPdu attribute then it may be a part of a long message not managed
            # by Jasmin: it may come from SMPPs already parted, in this case Jasmin must pass the
            # message as is without starting LongSubmitSmTransaction.
            # The downside of this behaviour is that each part of the message will be logged in a single
            # line in messages.log

            # UDH is set ?
            UDHI_INDICATOR_SET = False
            if hasattr(pdu.params['esm_class'], 'gsmFeatures'):
                for gsmFeature in pdu.params['esm_class'].gsmFeatures:
                    if str(gsmFeature) == 'UDHI_INDICATOR_SET':
                        UDHI_INDICATOR_SET = True
                        break

            # Discover any splitting method, otherwise, it is a single SubmitSm
            if 'sar_msg_ref_num' in pdu.params:
                splitMethod = 'sar'
            elif UDHI_INDICATOR_SET and pdu.params[
                    'short_message'][:3] == '\x05\x00\x03':
                splitMethod = 'udh'
            else:
                splitMethod = None

            if splitMethod is not None and hasattr(pdu, 'nextPdu'):
                partedSmPdu = pdu
                first = True

                # Iterate through parted PDUs
                while True:
                    partedSmPdu.seqNum = self.claimSeqNum()

                    # Set LongSubmitSm tracking flags in pdu:
                    partedSmPdu.LongSubmitSm = {
                        'msg_ref_num': None,
                        'total_segments': None,
                        'segment_seqnum': None
                    }
                    if splitMethod == 'sar':
                        # Using SAR options:
                        partedSmPdu.LongSubmitSm[
                            'msg_ref_num'] = partedSmPdu.params[
                                'sar_msg_ref_num']
                        partedSmPdu.LongSubmitSm[
                            'total_segments'] = partedSmPdu.params[
                                'sar_total_segments']
                        partedSmPdu.LongSubmitSm[
                            'segment_seqnum'] = partedSmPdu.params[
                                'sar_segment_seqnum']
                    elif splitMethod == 'udh':
                        # Using UDH options:
                        partedSmPdu.LongSubmitSm[
                            'msg_ref_num'] = struct.unpack(
                                '!B', pdu.params['short_message'][3])[0]
                        partedSmPdu.LongSubmitSm[
                            'total_segments'] = struct.unpack(
                                '!B', pdu.params['short_message'][4])[0]
                        partedSmPdu.LongSubmitSm[
                            'segment_seqnum'] = struct.unpack(
                                '!B', pdu.params['short_message'][5])[0]

                    self.preSubmitSm(partedSmPdu)
                    self.sendPDU(partedSmPdu)
                    # Unlike parent protocol's sendPDU, we don't return per pdu
                    # deferred, we'll return per transaction deferred instead
                    self.startOutboundTransaction(
                        partedSmPdu, timeout).addCallbacks(
                            self.endLongSubmitSmTransaction,
                            self.endLongSubmitSmTransactionErr)

                    # Start a transaction using the first parted PDU
                    if first:
                        first = False
                        txn = self.startLongSubmitSmTransaction(
                            partedSmPdu, timeout)

                    try:
                        # There still another PDU to go for
                        partedSmPdu = partedSmPdu.nextPdu
                    except AttributeError:
                        break

                return txn
            else:
                self.preSubmitSm(pdu)

        return twistedSMPPClientProtocol.doSendRequest(self, pdu, timeout)
Example #27
0
 def bindAsTransceiver(self):
     """This is a different signature where msgHandler is taken from factory
     """
     return twistedSMPPClientProtocol.bindAsTransceiver(self, self.factory.msgHandler)    
Example #28
0
    def sendPDU(self, pdu):
        twistedSMPPClientProtocol.sendPDU(self, pdu)

        self.factory.stats.set('last_sent_pdu_at', datetime.now())
Example #29
0
 def cancelOutboundTransactions(self, error):
     """Cancels LongSubmitSmTransactions when cancelling OutboundTransactions
     """
     twistedSMPPClientProtocol.cancelOutboundTransactions(self, error)
     self.cancelLongSubmitSmTransactions(error)
Example #30
0
    def connectionMade(self):
        twistedSMPPClientProtocol.connectionMade(self)
        self.log.info("Connection made to %s:%s" %
                      (self.factory.config.host, self.factory.config.port))

        self.factory.connectDeferred.callback(self)
Example #31
0
    def bindSucceeded(self, result, nextState):
        self.factory.stats.set('bound_at', datetime.now())
        self.factory.stats.inc('bound_count')

        return twistedSMPPClientProtocol.bindSucceeded(self, result, nextState)