Example #1
0
File: stack.py Project: vbohinc/sdp
    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
Example #2
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
Example #3
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
Example #4
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
Example #5
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