module example-sports {

    namespace "http://example.com/example-sports";
    prefix sports;

    import ietf-yang-types {
        prefix yang;
    }

    typedef season {
        type string;
        description
          "The name of a sports season, including the type and the year, e.g,
           'Champions League 2014/2015'.";
    }

    container sports {
        config true;

        list person {
            key "name";
            leaf name {
                type string;
            }
            leaf birthday {
                type yang:date-and-time;
                mandatory true;
            }
        }

        list team {
            key "name";
            leaf name {
                type string;
            }
            list player {
                key "name season";
                unique number;
                leaf name {
                    type leafref {
                        path "/sports/person/name";
                    }
                }
                leaf season {
                    type season;
                }
                leaf number {
                    type uint16;
                    mandatory true;
                }
                leaf scores {
                    type uint16;
                    default 0;
                }
                leaf-list score-list {
                    type uint16;
                }
            }
            leaf protocol {
                type enumeration {
                    enum tcp;
                    enum udp;
                    enum icmp;
                }
                default "tcp";
            }
            leaf vlan-id {
              type union {
                type vid-range-type;
                type enumeration {
                  enum any {
                    value 4095;
                    description
                      "Matches 'any' VLAN in the range 1 to 4094.";
                  }
                }
              }
              mandatory true;
              description
                "VLAN Ids or any";
            }
            
            
        }
        list protocol {
            key "associated-layer-protocol";
            leaf associated-layer-protocol {
                type string;

                description
                  "One of the values of the attribute layerProtocol of the Cpd
                   IE.";
                reference
                  "GS NFV IFA011: Section 7.1.6.8 CpProtocolData information
                   element";
            }
            uses g1;
            uses g2;
        }
    }
    grouping g1 {
        leaf protocoly {
            type enumeration {
                enum tcp;
                enum udp;
                enum icmp;
            }
            default "tcp";
        }
        list ext-cpd {
        	key "k";
        	leaf k {
        		type string;
        	}
            choice cp-connection {
                // no case
                leaf int-virtual-link-desc {
                    type string;
                }
                container int-cpd {
                    leaf vdu-id {
                        type string;
                    }
                    leaf cpd {
                        type string;
                    }
                }
            }
        }
        list case-ext-cpd {
        	key "k";
        	leaf k {
        		type string;
        	}
            choice cp-connection {
                // case
                case a {
                    leaf int-virtual-link-desc {
                        type string;
                    }
                }
                case b {

                    container int-cpd {
                        leaf vdu-id {
                            type string;
                        }
                        leaf cpd {
                            type string;
                        }
                    }
                }
            }
        }

    }
    grouping g2 {
        leaf protocolz {
            type string;
        }
        list port-map {
            key "port-ref";
            leaf port-ref {
                type string;
            }
            choice map-type {
                // no case
                container static-filtering-entries {
                    leaf control-element {
                        type enumeration {
                            enum forward;
                            enum filter;
                        }
                    }
                    leaf connection-identifier {
                        type string;
                    }
                }
                container static-vlan-registration-entries {
                    leaf registrar-admin-control {
                        type enumeration {
                            enum fixed-new-ignored;
                            enum forbidden;
                        }
                    }
                }
            }
        }
    }
    typedef vid-range-type {
      type string {
        pattern
          "([1-9]"+
          "[0-9]{0,3}"+
          "(-[1-9][0-9]{0,3})?"+
          "(,[1-9][0-9]{0,3}(-[1-9][0-9]{0,3})?)*)";
      }
      description
        "A list of VLAN Ids, or non overlapping VLAN ranges, in ascending
        order, between 1 and 4094.
        
        This type is used to match an ordered list of VLAN Ids, or
        contiguous ranges of VLAN Ids. Valid VLAN Ids must be in the range
        1 to 4094, and included in the list in non overlapping ascending
        order.
        
        For example: 1,10-100,250,500-1000";
    }
    typedef vlanid {
      type uint16 {
        range "1..4094";
      }
      description
        "The vlanid type uniquely identifies a VLAN. This is the 12-bit
        VLAN-ID used in the VLAN Tag header. The range is defined by the
        referenced specification. This type is in the value set and its
        semantics equivalent to the VlanId textual convention of the
        SMIv2.";
    }
      
}