예제 #1
0
 def __init__(self, avp_code=0, avp_data=None, vendor_id=0, 
              mandatory=0, private=0, level=0, decode_buf=None,
              cmd_etc_instance=None):
     OctetString.__init__(self, avp_code, avp_data, vendor_id, 
                  mandatory, private, level, decode_buf,
                  cmd_etc_instance)
     
     self.avp['AVP_DATA_TYPE'] = "DiameterIdentity"
     
예제 #2
0
 def __init__(self,
              cmd_code     = (),
              avp_code     = 0x00,
              avp_data     = "",
              decode_buf   = None,
              dcc_instance = None):
     OctetString.__init__(self,
                          cmd_code,
                          avp_code,
                          avp_data,
                          decode_buf,
                          dcc_instance)
예제 #3
0
 def __init__(self, avp_code=0, avp_data=None, vendor_id=0, 
              mandatory=0, private=0, level=0, decode_buf=None,
              cmd_etc_instance=None):
     OctetString.__init__(self, avp_code, avp_data, vendor_id, 
                  mandatory, private, level, decode_buf,
                  cmd_etc_instance)
     
     self.avp['AVP_DATA_TYPE'] = "UTF8String"
     
     # 编码时将传入的数据编码为UTF-8格式
     if self.avp['AVP_CODE_STATE'] == "00":
         self.avp['AVP_DATA'] = str(self.utf8encoder(self.avp['AVP_DATA']))
         
         data_length = len(self.avp['AVP_DATA'])
         data_length = (data_length + 3) // 4 * 4
         self.avp['AVP_CODE_OPERATOR'] = "!" + str(data_length) + "s"
예제 #4
0
    def __init__(self, avp_code=0, avp_data=None, vendor_id=0, 
                 mandatory=0, private=0, level=0, decode_buf=None,
                 cmd_etc_instance=None):
        OctetString.__init__(self, avp_code, avp_data, vendor_id, 
                     mandatory, private, level, decode_buf,
                     cmd_etc_instance)
        
        self.avp['AVP_DATA_TYPE'] = "Address"
        
        # 编码时根据传入的IP字符串判断地址族
        if self.avp['AVP_CODE_STATE'] == "00":
            addr_info = getaddrinfo(self.avp['AVP_DATA'], 3868)
            if addr_info[0][0] == AF_INET:
                self.avp['AVP_ADDR_FAMILY'] = 1
            elif addr_info[0][0] == AF_INET6:
                self.avp['AVP_ADDR_FAMILY'] = 2
                
            if self.avp['AVP_ADDR_FAMILY'] == 1:
                self.avp['AVP_CODE_OPERATOR'] = "!h6s"
            elif self.avp['AVP_ADDR_FAMILY'] == 2:
                self.avp['AVP_CODE_OPERATOR'] = "!h18s"
                
            self.avp['AVP_DATA'] = inet_aton(self.avp['AVP_DATA'])
            
        # 可读格式输出模板
        self.print_template = self.make_template("\
${L}AVP_CODE        = [${AVP_CODE}] - ${AVP_NAME} - ${AVP_DATA_TYPE}(\"${AVP_CODE_OPERATOR}\") \n\
${L}AVP_FLAG        = [${AVP_FLAG}] (VENDOR_ID(${AVP_VENDOR_ID})|MANDATORY(${AVP_MANDATORY})|PRIVATE(${AVP_PRIVATE}) \n\
${L}AVP_LENGTH      = [${AVP_LENGTH}] \n\
${L}AVP_VENDOR_ID   = [${AVP_VENDOR_ID}] \n\
${L}AVP_ADDR_FAMILY = [${AVP_ADDR_FAMILY}] \n\
${L}AVP_DATA        = [${AVP_DATA}]\n\
${L}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        
        self.print_detail_template = self.make_template("\
${L}${AVP_CODE_HEX}\n${L}\tAVP_CODE        = [${AVP_CODE}] - ${AVP_NAME} - ${AVP_DATA_TYPE}(\"${AVP_CODE_OPERATOR}\") \n\
${L}${AVP_FLAGS_HEX}\n${L}\tAVP_FLAG        = [${AVP_FLAG}] (VENDOR_ID(${AVP_VENDOR_ID})|MANDATORY(${AVP_MANDATORY})|PRIVATE(${AVP_PRIVATE}) \n\
${L}${AVP_LENGTH_HEX}\n${L}\tAVP_LENGTH      = [${AVP_LENGTH}] \n\
${L}${AVP_VONDER_HEX}\n${L}\tAVP_VENDOR_ID   = [${AVP_VENDOR_ID}] \n\
${L}${AVP_DATA_HEX} \n\
${L}\tAVP_ADDR_FAMILY = [${AVP_ADDR_FAMILY}] \n\
${L}\tAVP_DATA        = [${AVP_DATA}]\n\
${L}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        
        self.simple_print_template = self.make_template("${L}${AVP_NAME}(${AVP_CODE}) = [${AVP_ADDR_FAMILY}][${AVP_DATA}]")
예제 #5
0
    def __init__(self, avp_code=0, avp_data=None, vendor_id=0, 
                 mandatory=0, private=0, level=0, decode_buf=None,
                 cmd_etc_instance=None):
        OctetString.__init__(self, avp_code, avp_data, vendor_id, 
                     mandatory, private, level, decode_buf,
                     cmd_etc_instance)
        
        self.avp['AVP_DATA_TYPE'] = "Time"
        
        self.avp['AVP_TIME_STAMP'] = None
        self.avp['AVP_TIME_STR'] = None
        
        
        # 编码时根据传入的日期格式转化为NTP时间戳
        if self.avp['AVP_CODE_STATE'] == "00":
            self.avp['AVP_TIME_STR']   = self.avp['AVP_DATA']
            self.avp['AVP_DATA']       = self.Time2NTPStamp(self.avp['AVP_DATA'])
            self.avp['AVP_TIME_STAMP'] = self.avp['AVP_DATA']
            
            data_length = len(self.avp['AVP_DATA'])
            data_length = (data_length + 3) // 4 * 4
            self.avp['AVP_CODE_OPERATOR'] = "!" + str(data_length) + "s"
            
        # 可读格式输出模板
        self.print_template = self.make_template("\
${L}AVP_CODE       = [${AVP_CODE}] - ${AVP_NAME} - ${AVP_DATA_TYPE}(\"${AVP_CODE_OPERATOR}\") \n\
${L}AVP_FLAG       = [${AVP_FLAG}] (VENDOR_ID(${AVP_VENDOR_ID})|MANDATORY(${AVP_MANDATORY})|PRIVATE(${AVP_PRIVATE}) \n\
${L}AVP_LENGTH     = [${AVP_LENGTH}] \n\
${L}AVP_VENDOR_ID  = [${AVP_VENDOR_ID}] \n\
${L}AVP_TIME_STAMP = [${AVP_TIME_STAMP}]\n\
${L}AVP_TIME_STR   = [${AVP_TIME_STR}]\n\
${L}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        
        self.print_detail_template = self.make_template("\
${L}${AVP_CODE_HEX}\n${L}\tAVP_CODE       = [${AVP_CODE}] - ${AVP_NAME} - ${AVP_DATA_TYPE}(\"${AVP_CODE_OPERATOR}\") \n\
${L}${AVP_FLAGS_HEX}\n${L}\tAVP_FLAG       = [${AVP_FLAG}] (VENDOR_ID(${AVP_VENDOR_ID})|MANDATORY(${AVP_MANDATORY})|PRIVATE(${AVP_PRIVATE}) \n\
${L}${AVP_LENGTH_HEX}\n${L}\tAVP_LENGTH     = [${AVP_LENGTH}] \n\
${L}${AVP_VONDER_HEX}\n${L}\tAVP_VENDOR_ID  = [${AVP_VENDOR_ID}] \n\
${L}${AVP_DATA_HEX}\n\
${L}\tAVP_TIME_STAMP = [${AVP_TIME_STAMP}]\n\
${L}\tAVP_TIME_STR   = [${AVP_TIME_STR}]\n\
${L}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        
        self.simple_print_template = self.make_template("${L}${AVP_NAME}(${AVP_CODE}) = [${AVP_DATA}]")
예제 #6
0
 def __init__(self,
              cmd_code     = (),
              avp_code     = 0x00,
              avp_data     = "",
              decode_buf   = None,
              dcc_instance = None):
     OctetString.__init__(self,
                          cmd_code,
                          avp_code,
                          avp_data,
                          decode_buf,
                          dcc_instance)
     
     # 编码时根据传入的IP字符串判断地址族
     self.__addr_info = getaddrinfo(self.avp['AVP_DATA'],
                             self.dcc.dcc_def.const.DIAMETE_ADDRESS_PORT)
     
     if self.__addr_info[0][0] == AF_INET:
         self.avp['AVP_ADDR_FAMILY'] = 1
     elif self.__addr_info[0][0] == AF_INET6:
         self.avp['AVP_ADDR_FAMILY'] = 2