Exemplo n.º 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
Exemplo n.º 2
0
    def app_handler(self, consumed, message):
        """
        Watch out for application-Id 0
        DPR/DWR will also show up in here
        """

        print("app_handler %d %d" % (message.application_id,message.command_code))
        print("length %d" % message.message_length)
        #watchdog, don't send it up the stack
        if message.application_id == 0 and \
           message.command_code == 280:
            if message.request_flag:
                answ = message.createAnswer()
                tmp = DiameterAVP()
                tmp.setCode(268)
                tmp.setMandatory(True)
                tmp.setInteger32(2001)
                answ.addAVP(tmp)
                self.stack.sendByPeer(self.peer, answ, False)
            return

        self.stack.handleIncomingMessage(self.peer, message)
Exemplo n.º 3
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
Exemplo n.º 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
Exemplo n.º 5
0
    def addOriginHostRealm(self, msg):
        origin_host = DiameterAVP()
        origin_host.setCode(264)
        origin_host.setMandatory(True)
        origin_host.setOctetString(self.identity)
        msg.addAVP(origin_host)

        origin_realm = DiameterAVP()
        origin_realm.setCode(296)
        origin_realm.setMandatory(True)
        origin_realm.setOctetString(self.realm)
        msg.addAVP(origin_realm)
Exemplo n.º 6
0
    def send_cer(self, consumed, message):
        msg = self.stack.createRequest(0, 257)
        # vendorid
        tmp = DiameterAVP()
        tmp.setCode(266)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.vendor_id)
        msg.addAVP(tmp)

        # productname
        tmp = DiameterAVP()
        tmp.setCode(269)
        tmp.setMandatory(True)
        tmp.setOctetString(self.stack.product_name)
        msg.addAVP(tmp)

        # firmware
        tmp = DiameterAVP()
        tmp.setCode(267)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.firmware_revision)
        msg.addAVP(tmp)

        # host ip
        tmp = DiameterAVP()
        tmp.setCode(257)
        tmp.setMandatory(True)
        tmp.setIPV4(self.stack.ip4_address)
        msg.addAVP(tmp)

        # get supported vendors from stack
        for vendor in self.stack.supported_vendors:
            supp = DiameterAVP()
            supp.setCode(265)
            supp.setMandatory(True)
            supp.setInteger32(vendor)
            msg.addAVP(supp)

        # get applications from stack
        for apps in [self.stack.auth_apps, self.stack.acct_apps]:
            for app in apps:
                # Build *-Application-Id AVP
                app_id = DiameterAVP()
                if apps == self.stack.auth_apps:
                    # App is for authentication, so use Auth-Application-Id AVP code
                    app_id.setCode(258)
                    _log.debug("CER Auth-Application-Id %d", app[1])
                else:
                    # App is for accounting, so use Acct-Application-Id AVP code
                    app_id.setCode(259)
                    _log.debug("CER Acct-Application-Id %d", app[1])
                app_id.setMandatory(True)
                app_id.setInteger32(app[1])

                if app[0]:
                    tmp = DiameterAVP()
                    tmp.setCode(260)
                    tmp.setMandatory(True)
                    # vendor
                    v = DiameterAVP()
                    v.setCode(266)
                    v.setMandatory(True)
                    v.setInteger32(app[0])
                    tmp.addAVP(v)
                    tmp.addAVP(app_id)
                    msg.addAVP(tmp)
                else:
                    msg.addAVP(app_id)

        _log.debug("Send CEA")
        self.stack.sendByPeer(self.peer, msg, False)

        self.run = self.receive_cea
Exemplo n.º 7
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
Exemplo n.º 8
0
    def send_cer(self, consumed, message):
        msg = self.stack.createRequest(0, 257)
        #vendorid
        tmp = DiameterAVP()
        tmp.setCode(266)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.vendor_id)
        msg.addAVP(tmp)

        #productname
        tmp = DiameterAVP()
        tmp.setCode(269)
        tmp.setMandatory(True)
        tmp.setOctetString(self.stack.product_name)
        msg.addAVP(tmp)

        #firmware
        tmp = DiameterAVP()
        tmp.setCode(267)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.firmware_revision)
        msg.addAVP(tmp)

        #host ip
        tmp = DiameterAVP()
        tmp.setCode(257)
        tmp.setMandatory(True)
        tmp.setIPV4(self.stack.ip4_address)
        msg.addAVP(tmp)

        #get supported vendors from stack
        for vendor in self.stack.supported_vendors:
            supp = DiameterAVP()
            supp.setCode(265)
            supp.setMandatory(True)
            supp.setInteger32(vendor)
            msg.addAVP(supp)

        #get applications from stack
        for apps in [self.stack.auth_apps, self.stack.acct_apps]:
            for app in apps:
                # Build *-Application-Id AVP
                app_id = DiameterAVP()
                if apps == self.stack.auth_apps:
                    # App is for authentication, so use Auth-Application-Id AVP code
                    app_id.setCode(258)
                else:
                    # App is for accounting, so use Acct-Application-Id AVP code
                    app_id.setCode(259)
                app_id.setMandatory(True)
                app_id.setInteger32(app[1])
    
                if app[0]:
                    tmp = DiameterAVP()
                    tmp.setCode(260)
                    tmp.setMandatory(True)
                    #vendor
                    v = DiameterAVP()
                    v.setCode(266)
                    v.setMandatory(True)
                    v.setInteger32(app[0])
                    tmp.addAVP(v)
                    tmp.addAVP(app_id)
                    msg.addAVP(tmp)
                else:
                    msg.addAVP(app_id)

        self.stack.sendByPeer(self.peer, msg, False)

        self.run = self.receive_cea
Exemplo n.º 9
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
Exemplo n.º 10
0
    def addOriginHostRealm(self, msg):
        origin_host = DiameterAVP()
        origin_host.setCode(264)
        origin_host.setMandatory(True)
        origin_host.setOctetString(self.identity)
        msg.addAVP(origin_host)

        origin_realm = DiameterAVP()
        origin_realm.setCode(296)
        origin_realm.setMandatory(True)
        origin_realm.setOctetString(self.realm)
        msg.addAVP(origin_realm)
Exemplo n.º 11
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
Exemplo n.º 12
0
    def send_cer(self, consumed, message):
        msg = self.stack.createRequest(0, 257)
        #vendorid
        tmp = DiameterAVP()
        tmp.setCode(266)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.vendor_id)
        msg.addAVP(tmp)

        #productname
        tmp = DiameterAVP()
        tmp.setCode(269)
        tmp.setMandatory(True)
        tmp.setOctetString(self.stack.product_name)
        msg.addAVP(tmp)

        #firmware
        tmp = DiameterAVP()
        tmp.setCode(267)
        tmp.setMandatory(True)
        tmp.setInteger32(self.stack.firmware_revision)
        msg.addAVP(tmp)

        #host ip
        tmp = DiameterAVP()
        tmp.setCode(257)
        tmp.setMandatory(True)
        tmp.setIPV4(self.stack.ip4_address)
        msg.addAVP(tmp)

        #get applications from stack
        apps = self.stack.applications.keys()
        for app in apps:
            #acct
            acc = DiameterAVP()
            acc.setCode(259)
            acc.setMandatory(True)
            acc.setInteger32(app[1])
            #auth
            auth = DiameterAVP()
            auth.setCode(258)
            auth.setMandatory(True)
            auth.setInteger32(app[1])

            if app[0]:
                tmp = DiameterAVP()
                tmp.setCode(260)
                tmp.setMandatory(True)
                #vendor
                v = DiameterAVP()
                v.setCode(266)
                v.setMandatory(True)
                v.setInteger32(app[0])
                tmp.addAVP(v)
                tmp.addAVP(auth)
                tmp.addAVP(acc)
                msg.addAVP(tmp)
                msg.addAVP(v)
            else:
                msg.addAVP(auth)
                msg.addAVP(acc)

        self.stack.sendByPeer(self.peer, msg, False)

        self.run = self.receive_cea