Navigation


Changeset 1463:8f6c77f24b1a in freeDiameter


Ignore:
Timestamp:
Mar 9, 2020, 8:28:04 PM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
Message:

csv_to_fd: add QoSFilterRule. style fixes

Support derived type QoSFilterRule from RFC 7155 section 4.1.1
Minor code refactor.
Expand comments, removing UTF-8 chars and encoding requirement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/tools/csv_to_fd

    r1461 r1463  
    11#!/usr/bin/env python
    2 # vim: set fileencoding=utf-8 :
    32
    43"""
     
    1110    - Name:
    1211        AVP Name. String, validated as ALPHA *(ALPHA / DIGIT / "-")
     12        per RFC 6733 section 3.2.
    1313    - Code:
    1414        AVP Code. Integer, 0..4294967295.
     
    1616        Section in relevant standard. String.
    1717    - 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
    1922    - Must, May, ShouldNot, MustNot:
    2023        Flags, possibly comma or space separated: M, V
     
    5659]
    5760
     61DERIVED_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
    5873VENDOR_TO_NAME = {
    5974    0:      '',
     
    6782    """Store an AVP row."""
    6883
    69     # Regex to validate avp-name per RFC 6733 § 3.2,
     84    # Regex to validate avp-name per RFC 6733 section 3.2,
    7085    # with changes:
    7186    # - Allow avp-name to start with numbers (for 3GPP)
     
    100115        if (self.code < 0 or self.code > 4294967295):
    101116            raise ValueError('Invalid AVP code {}'.format(self.code))
    102         if self.datatype not in (
     117        if (self.datatype not in (
    103118                '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):
    108121            raise ValueError('Invalid AVP data type "{}"'.format(
    109122                self.datatype))
     
    202215
    203216    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     }
    214217
    215218    def __init__(self):
     
    236239# TODO: add trailing comma?
    237240        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()))
    240242        self.add('\t\t};')
    241243        avp_type = 'NULL'
     
    252254            self.add('\t\tCHECK_dict_new(DICT_TYPE, &tdata, NULL, &type);')
    253255            avp_type = "type"
    254         elif avp.datatype in self.DERIVED_TO_BASE:
     256        elif avp.datatype in DERIVED_TO_BASE:
    255257            avp_type = '{}_type'.format(avp.datatype)
    256258        self.add('\t\tCHECK_dict_new(DICT_AVP, &data, {}, NULL);'.format(
Note: See TracChangeset for help on using the changeset viewer.