EditWYSIWYGAttachPrintable
r1 - 2007-11-15 - 13:44:52 - MartinBjoerklundYou are here: TWiki >  Main Web > YangExamples > InetTypesHtml
module inet-types {

    // XXX namespace to be allocated by IANA

    namespace "urn:ietf:params:xml:ns:yang:inet-types";
    prefix "inet";

    organization
        "YANG Language Design Team";

    contact
        "Martin Bjorklund (Editor) ";

    description
        "This module contains standard derived YANG types
         for Internet addresses and related things.";

    revision 2007-10-02 {
        description "Initial revision.";
    }

    /*
     * collection of protocol field related types
     */

    typedef ip-version {
        type enumeration {
            enum unknown {
                value 0; 
                description
                   "An unknown or unspecified version of the 
                    Internet protocol.";
            }
            enum ipv4 {
                value 1;
                description
                   "The IPv4 protocol as defined in RFC 791.";
            }
            enum ipv6 {
                value 2;
                description
                   "The IPv6 protocol as defined in RFC 2460.";
            }
        }
        description
           "This value represents the version of the IP protocol.";
        reference
           "RFC 791 (STD 5), RFC 2460";
    }

    typedef dscp {
        type uint8 {
            range "0..63";
        }
        description
           "The dscp type represents a Differentiated Services
            Code-Point that may be used for marking a traffic
            stream.";
        reference 
           "RFC 3289, RFC 2474, RFC 2780";
    }

    typedef flow-label {
        type uint32 {
            range "0..1048575";
        }
        description
           "The flow-label type represents flow identifier or 
            Flow Label in an IPv6 packet header that may be 
            used to discriminate traffic flows.";
        reference
           "RFC 2460";
    }

    typedef port-number {
        type uint16 {
            range "1..65535";
        }
        description
           "The port-number type represents a 16-bit port
            number of an Internet transport layer protocol
            such as UDP, TCP, DCCP or SCTP. Port numbers are
            assigned by IANA.  A current list of all 
            assignments is available from
            .

            Note that the value zero is not a valid port
            number. A union type might be used in situations
            where the value zero is meaningful.";
        reference
           "RFC 4001";
    }
    
    /*
     * collection of autonomous system related types
     */

    typedef asn {
        type uint32;
        description
           "The asn type represents autonomous system numbers which
            identify an Autonomous System (AS). An AS is a set of
            routers under a single technical administration, using an
            interior gateway protocol and common metrics to route
            packets within the AS, and using an exterior gateway
            protocol to route packets to other ASs'. IANA maintains
            the AS number space and has delegated large parts to the
            regional registries.

            Autonomous system numbers are currently limited to 16 bits
            (0..65535). There is however work in progress to enlarge
            the autonomous system number space to 32 bits. This
            textual convention therefore uses an uint32 base type
            without a range restriction in order to support a larger
            autonomous system number space.";
        reference
           "RFC 1771, RFC 1930, RFC 4001";
    }

    /*
     * collection of IP address and hostname related types
     */

    typedef ip-address {
        type union {
            type inet:ipv4-address;
            type inet:ipv6-address;
        }
        description
           "The ip-address type represents an IP address and
            is IP version neutral. The format of the textual
            representations implies the IP version.";
    }

    typedef ipv4-address {
        type string {
            pattern 
               '(([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}'
             + '([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'
             + '(%[\p{N}\p{L}]+)?';
        }
        description
           "The ipv4-address type represents an IPv4 address in
            dotted-quad notation. The IPv4 address may include
            a zone index, separated by a % sign.";
    }

    typedef ipv6-address {
        type string {
            pattern
               /* full */
               '((([0-9a-fA-F]{1,4}:){7})([0-9a-fA-F]{1,4})'
            +  '(%[\p{N}\p{L}]+)?)'
               /* mixed */
            +  '|((([0-9a-fA-F]{1,4}:){6})(([0-9]{1,3}\.'
            +      '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))'
            +   '(%[\p{N}\p{L}]+)?)'
              /* shortened */
            + '|((([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*(::)'
            +   '(([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*'
            +   '(%[\p{N}\p{L}]+)?)'
              /* shortened mixed */
            + '((([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*(::)'
            +  '(([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*'
            +  '(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))'
            +   '(%[\p{N}\p{L}]+)?)';
        }
        description
           "The ipv6-address type represents an IPv6 address in
            full, mixed, shortened and shortened mixed notation.
            The IPv6 address may include a zone index, separated
            by a % sign.";
    }

    typedef ip-prefix {
        type union {
            type inet:ipv4-prefix;
            type inet:ipv6-prefix;
        }
        description
           "The ip-prefix type represents an IP prefix and
            is IP version neutral. The format of the textual
            representations implies the IP version.";
    }

    typedef ipv4-prefix {
        type string {
            pattern 
               '(([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.){3}'
             + '([0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'
             + '/\p{N}+';
        }
        description
           "The ipv4-prefix type represents an IPv4 address prefix.
            The prefix length is given by the number following the
            slash character and must be less than or equal 32. 
            Values larger than 32 should be treated as 32.

            A prefix length value of n corresponds to an IP address
            mask which has n contiguous 1-bits from the most
            significant bit (MSB) and all other bits set to 0.

            The IPv4 address represented in dotted quad notation 
            should have all bits that do not belong to the prefix
            set to zero.";
    }

    typedef ipv6-prefix {
        type string {
            pattern
               /* full */
               '((([0-9a-fA-F]{1,4}:){7})([0-9a-fA-F]{1,4})'
            +  '/\p{N}+)'
               /* mixed */
            +  '|((([0-9a-fA-F]{1,4}:){6})(([0-9]{1,3}\.'
            +      '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))'
            +   '/\p{N}+)'
               /* shortened */
            +  '|((([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*(::)'
            +   '(([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*'
            +   '/\p{N}+)'
               /* shortened mixed */
            + '((([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*(::)'
            +  '(([0-9a-fA-F]{1,4}:)*([0-9a-fA-F]{1,4}))*'
            +  '(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))'
            +   '/\p{N}+)';
        }
        description
           "The ipv6-prefix type represents an IPv6 address prefix.
            The prefix length is given by the number following the
            slash character and must be less than or equal 128. 
            Values larger than 128 should be treated as 128.

            A prefix length value of n corresponds to an IP address
            mask which has n contiguous 1-bits from the most
            significant bit (MSB) and all other bits set to 0.

            The IPv6 address represented in dotted quad notation 
            should have all bits that do not belong to the prefix
            set to zero.";
    }

    typedef domain-name {
        type string {
            pattern '([\p{L}\p{N}]+\.)*[\p{L}\p{N}]';
        }
        description
           "The domain-name type represents a DNS domain
            name. The name SHOULD be fully qualified
            whenever possible.

            The description clause of objects using the
            domain-name type MUST describe how (and when)
            these names are resolved to IP addresses.

            Note that the resolution of a domain-name value 
            may require to query multiple DNS records (e.g.,
            A for IPv4 and AAAA for IPv6).  The order of the
            resolution process and which DNS record takes
            precedence depends on the configuration of the
            resolver.";
        reference
           "RFC 1034";
    }

    typedef host {
        type union {
            type inet:ip-address;
            type inet:domain-name;
        }
        description
           "The host type represents either an IP address
            or a DNS domain name.";
    }

}
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions...
 
YANG
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback