Changeset 1463:8f6c77f24b1a in freeDiameter for contrib/tools/csv_to_fd
- Timestamp:
- Mar 9, 2020, 8:28:04 PM (3 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/tools/csv_to_fd
r1461 r1463 1 1 #!/usr/bin/env python 2 # vim: set fileencoding=utf-8 :3 2 4 3 """ … … 11 10 - Name: 12 11 AVP Name. String, validated as ALPHA *(ALPHA / DIGIT / "-") 12 per RFC 6733 section 3.2. 13 13 - Code: 14 14 AVP Code. Integer, 0..4294967295. … … 16 16 Section in relevant standard. String. 17 17 - DataType: 18 AVP Data Type. String, validated per Per RFC 6733 § 4.2 and § 4.3. 18 AVP Data Type. String, validated per basic and derived types in: 19 - RFC 6733 section 4.2 20 - RFC 6733 section 4.3 21 - RFC 7155 section 4.1 19 22 - Must, May, ShouldNot, MustNot: 20 23 Flags, possibly comma or space separated: M, V … … 56 59 ] 57 60 61 DERIVED_TO_BASE = { 62 'Address': 'OctetString', # RFC 6733 section 4.3.1 63 'Time': 'OctetString', # RFC 6733 section 4.3.1 64 'UTF8String': 'OctetString', # RFC 6733 section 4.3.1 65 'DiameterIdentity': 'OctetString', # RFC 6733 section 4.3.1 66 'DiameterURI': 'OctetString', # RFC 6733 section 4.3.1 67 'Enumerated': 'Integer32', # RFC 6733 section 4.3.1 68 'IPFilterRule': 'OctetString', # RFC 6733 section 4.3.1 69 'QoSFilterRule': 'OctetString', # RFC 7155 section 4.1.1 70 } 71 72 # See https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers 58 73 VENDOR_TO_NAME = { 59 74 0: '', … … 67 82 """Store an AVP row.""" 68 83 69 # Regex to validate avp-name per RFC 6733 §3.2,84 # Regex to validate avp-name per RFC 6733 section 3.2, 70 85 # with changes: 71 86 # - Allow avp-name to start with numbers (for 3GPP) … … 100 115 if (self.code < 0 or self.code > 4294967295): 101 116 raise ValueError('Invalid AVP code {}'.format(self.code)) 102 if self.datatype not in (117 if (self.datatype not in ( 103 118 'OctetString', 'Integer32', 'Integer64', 'Unsigned32', 104 'Unsigned64', 'Float32', 'Float64', 'Grouped', 105 'Address', 'Time', 'UTF8String', 'DiameterIdentity', 106 'DiameterURI', 'Enumerated', 'IPFilterRule', 107 ): 119 'Unsigned64', 'Float32', 'Float64', 'Grouped') 120 and self.datatype not in DERIVED_TO_BASE): 108 121 raise ValueError('Invalid AVP data type "{}"'.format( 109 122 self.datatype)) … … 202 215 203 216 COMMENT_WIDTH = 64 204 205 DERIVED_TO_BASE = {206 'Address': 'OctetString',207 'Time': 'OctetString',208 'UTF8String': 'OctetString',209 'DiameterIdentity': 'OctetString',210 'DiameterURI': 'OctetString',211 'Enumerated': 'Integer32',212 'IPFilterRule': 'OctetString',213 }214 217 215 218 def __init__(self): … … 236 239 # TODO: add trailing comma? 237 240 self.add('\t\t\tAVP_TYPE_{}\t/* base type of data */'.format( 238 self.DERIVED_TO_BASE.get( 239 avp.datatype, avp.datatype).upper())) 241 DERIVED_TO_BASE.get(avp.datatype, avp.datatype).upper())) 240 242 self.add('\t\t};') 241 243 avp_type = 'NULL' … … 252 254 self.add('\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);') 253 255 avp_type = "type" 254 elif avp.datatype in self.DERIVED_TO_BASE:256 elif avp.datatype in DERIVED_TO_BASE: 255 257 avp_type = '{}_type'.format(avp.datatype) 256 258 self.add('\t\tCHECK_dict_new(DICT_AVP, &data, {}, NULL);'.format(
Note: See TracChangeset
for help on using the changeset viewer.