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())
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)
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)
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')
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')
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')
def getProtocolObject(self): smpp = SMPPClientProtocol() config = SMPPClientConfig( host='localhost', port = 82, username = '', password = '', ) smpp.config = Mock(return_value=config) return smpp
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')
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
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
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')
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)
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)
def cancelOutboundTransactions(self, err): """Cancels LongSubmitSmTransactions when cancelling OutboundTransactions """ twistedSMPPClientProtocol.cancelOutboundTransactions(self, err) self.cancelLongSubmitSmTransactions(err)
def bindAsTransceiver(self): """This is a different signature where msgHandler is taken from factory """ return twistedSMPPClientProtocol.bindAsTransceiver( self, self.factory.msgHandler)
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)
def connectionLost(self, reason): twistedSMPPClientProtocol.connectionLost(self, reason) self.factory.stats.set('disconnected_at', datetime.now()) self.factory.stats.inc('disconnected_count')
def __init__( self ): twistedSMPPClientProtocol.__init__(self) self.longSubmitSmTxns = {}
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)
def onPDURequest_enquire_link(self, reqPDU): twistedSMPPClientProtocol.onPDURequest_enquire_link(self, reqPDU) self.factory.stats.set('last_received_elink_at', datetime.now())
def enquireLinkTimerExpired(self): twistedSMPPClientProtocol.enquireLinkTimerExpired(self) self.factory.stats.set('last_sent_elink_at', datetime.now())
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())
def connectionLost(self, reason): twistedSMPPClientProtocol.connectionLost(self, reason) self.factory.stats.set('disconnected_at', datetime.now()) self.factory.stats.inc('disconnected_count')
def __init__(self): twistedSMPPClientProtocol.__init__(self) self.longSubmitSmTxns = {}
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)
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)
def bindAsTransceiver(self): """This is a different signature where msgHandler is taken from factory """ return twistedSMPPClientProtocol.bindAsTransceiver(self, self.factory.msgHandler)
def sendPDU(self, pdu): twistedSMPPClientProtocol.sendPDU(self, pdu) self.factory.stats.set('last_sent_pdu_at', datetime.now())
def cancelOutboundTransactions(self, error): """Cancels LongSubmitSmTransactions when cancelling OutboundTransactions """ twistedSMPPClientProtocol.cancelOutboundTransactions(self, error) self.cancelLongSubmitSmTransactions(error)
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)
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)