Exemple #1
0
    def createAnswer(self, req, ret_code=None):
        ret = DiameterMessage()
        ret.request_flag = False
        ret.proxiable_flag = req.proxiable_flag
        ret.eTe = req.eTe
        ret.hBh = req.hBh
        ret.application_id = req.application_id
        ret.command_code = req.command_code
  
        if ret_code:
            tmp = DiameterAVP()
            tmp.setCode(268)
            tmp.setMandatory(True)
            tmp.setInteger32(ret_code)
            ret.addAVP(tmp)
  
        self.addOriginHostRealm(ret)

        return ret
Exemple #2
0
    def feed(self, buf, length):
        """Returns the amount of bytes consumed from buf"""
        total_consumed = 0

        # special signal, send it up the stack
        if length == 0:
            self.fsm.run(0, None)
            return 0

        # read error, disconnect
        if length == -1:
            self.fsm.run(-1, None)
            return -1

        # while we have an entire diameter header
        while length >= 20:
            version_length = struct.unpack("!i",buf[:4])[0]
            version = version_length >> 24
            msg_length = (version_length & 0x00ffffff)

            # protocol error, disconnect
            if version != 1:
                pass

            # can't read one entire message
            # caller should buffer
            if msg_length > length:
                return total_consumed

            msg = DiameterMessage()
            consumed = msg.parseFromBuffer(buf)
            self.fsm.run(consumed, msg)

            # protocol error, disconnect
            if consumed <= 0:
                return consumed

            # remove the handled message ready to go round again
            buf = buf[consumed:]
            length -= consumed
            total_consumed += consumed

        return total_consumed
Exemple #3
0
    def feed(self, buf, length):
        """Returns the amount of bytes consumed from buf"""
        total_consumed = 0

        # special signal, send it up the stack
        if length == 0:
            self.fsm.run(0, None)
            return 0

        # read error, disconnect
        if length == -1:
            self.fsm.run(-1, None)
            return -1

        # while we have an entire diameter header
        while length >= 20:
            version_length = struct.unpack("!i", buf[:4])[0]
            version = version_length >> 24
            msg_length = (version_length & 0x00ffffff)

            # protocol error, disconnect
            if version != 1:
                pass

            # can't read one entire message
            # caller should buffer
            if msg_length > length:
                return total_consumed

            msg = DiameterMessage()
            consumed = msg.parseFromBuffer(buf)
            self.fsm.run(consumed, msg)

            # protocol error, disconnect
            if consumed <= 0:
                return consumed

            # remove the handled message ready to go round again
            buf = buf[consumed:]
            length -= consumed
            total_consumed += consumed

        return total_consumed
Exemple #4
0
    def createRequest(self,
                      application,
                      code,
                      auth=False,
                      acct=False,
                      vendor_id=None):
        _log.debug("Creating Diameter message with command code %d", code)
        ret = DiameterMessage()
        ret.request_flag = True
        ret.eTe = self.nextEtE()
        ret.hBh = self.nextHbH()
        ret.application_id = application
        ret.command_code = code

        self.addOriginHostRealm(ret)

        if vendor_id:
            app_container = DiameterAVP()
            app_container.setCode(260)
            app_container.setMandatory(True)
            tmp = DiameterAVP()
            tmp.setCode(266)
            tmp.setMandatory(True)
            tmp.setInteger32(vendor_id)
            app_container.addAVP(tmp)
        else:
            app_container = ret

        if auth:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            app_container.addAVP(tmp)
        elif acct:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            app_container.addAVP(tmp)

        if app_container != ret:
            ret.addAVP(app_container)

        return ret
Exemple #5
0
    def feed(self, buf, length):
        """Returns the amount of bytes consumed from buf"""

        # special signal, send it up the stack
        if length == 0:
            self.fsm.run(0, None)
            return 0

        # read error, disconnect
        if length == -1:
            self.fsm.run(-1, None)
            return -1

        # dont have an entire diameter header yet
        if length < 20:
            return 0

        version_length = struct.unpack("!i",buf[:4])[0]
        version = version_length >> 24
        msg_length = (version_length & 0x00ffffff)

        # protocol error, disconnect
        if version != 1:
            pass

        # can't read one entire message
        # caller should buffer
        if msg_length > length:
            return 0

        msg = DiameterMessage()
        consumed = msg.parseFromBuffer(buf)
        self.fsm.run(consumed, msg)

        # protocol error, disconnect
        if consumed <= 0:
            pass

        return consumed
Exemple #6
0
    def feed(self, buf, length):
        """Returns the amount of bytes consumed from buf"""

        # special signal, send it up the stack
        if length == 0:
            self.fsm.run(0, None)
            return 0

        # read error, disconnect
        if length == -1:
            self.fsm.run(-1, None)
            return -1

        # dont have an entire diameter header yet
        if length < 20:
            return 0

        version_length = struct.unpack("!i",buf[:4])[0]
        version = version_length >> 24
        msg_length = (version_length & 0x00ffffff)

        # protocol error, disconnect
        if version != 1:
            pass

        # can't read one entire message
        # caller should buffer
        if msg_length > length:
            return 0

        msg = DiameterMessage()
        consumed = msg.parseFromBuffer(buf)
        self.fsm.run(consumed, msg)

        # protocol error, disconnect
        if consumed <= 0:
            pass

        return consumed
Exemple #7
0
    def createAnswer(self, req, ret_code=None):
        ret = DiameterMessage()
        ret.request_flag = False
        ret.proxiable_flag = req.proxiable_flag
        ret.eTe = req.eTe
        ret.hBh = req.hBh
        ret.application_id = req.application_id
        ret.command_code = req.command_code
  
        if ret_code:
            tmp = DiameterAVP()
            tmp.setCode(268)
            tmp.setMandatory(True)
            tmp.setInteger32(ret_code)
            ret.addAVP(tmp)
  
        self.addOriginHostRealm(ret)

        return ret
Exemple #8
0
    def createRequest(self, application, code, auth=False, acct=False, vendor_id=None):
        _log.debug("Creating Diameter message with command code %d", code)
        ret = DiameterMessage()
        ret.request_flag = True
        ret.eTe = self.nextEtE()
        ret.hBh = self.nextHbH()
        ret.application_id = application
        ret.command_code = code

        self.addOriginHostRealm(ret)

        if vendor_id:
            app_container = DiameterAVP()
            app_container.setCode(260)
            app_container.setMandatory(True)
            tmp = DiameterAVP()
            tmp.setCode(266)
            tmp.setMandatory(True)
            tmp.setInteger32(vendor_id)
            app_container.addAVP(tmp)
        else:
            app_container = ret

        if auth:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            app_container.addAVP(tmp)
        elif acct:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            app_container.addAVP(tmp)

        if app_container != ret:
            ret.addAVP(app_container)

        return ret
Exemple #9
0
    def createRequest(self, application, code, auth=False, acct=False):
        ret = DiameterMessage()
        ret.request_flag = True
        ret.eTe = self.nextEtE()
        ret.hBh = self.nextHbH()
        ret.application_id = application
        ret.command_code = code

        origin_host = DiameterAVP()
        origin_host.setCode(264)
        origin_host.setMandatory(True)
        origin_host.setOctetString(self.identity)
        ret.addAVP(origin_host)

        origin_realm = DiameterAVP()
        origin_realm.setCode(296)
        origin_realm.setMandatory(True)
        origin_realm.setOctetString(self.realm)
        ret.addAVP(origin_realm)

        if auth:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            ret.addAVP(tmp)
        elif acct:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            ret.addAVP(tmp)

        return ret
Exemple #10
0
    def createRequest(self, application, code, auth=False, acct=False):
        ret = DiameterMessage()
        ret.request_flag = True
        ret.eTe = self.nextEtE()
        ret.hBh = self.nextHbH()
        ret.application_id = application
        ret.command_code = code

        origin_host = DiameterAVP()
        origin_host.setCode(264)
        origin_host.setMandatory(True)
        origin_host.setOctetString(self.identity)
        ret.addAVP(origin_host)

        origin_realm = DiameterAVP()
        origin_realm.setCode(296)
        origin_realm.setMandatory(True)
        origin_realm.setOctetString(self.realm)
        ret.addAVP(origin_realm)

        if auth:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            ret.addAVP(tmp)
        elif acct:
            tmp = DiameterAVP()
            tmp.setCode(258)
            tmp.setMandatory(True)
            tmp.setInteger32(application)
            ret.addAVP(tmp)

        return ret