// SPDX-FileCopyrightText: 2021 Open Networking Foundation
//
// SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

module aether-subscriber {
  namespace "http://opennetworking.org/aether/subscriber";
  prefix sub;

  import apn-profile{ prefix apn; }
  import qos-profile{ prefix qos; }
  import up-profile{ prefix up; }
  import access-profile{ prefix ap; }
  import security-profile{ prefix sec; }
  import enterprise{ prefix ent; }  
  import ietf-yang-types{ prefix ietf; }

  organization "Open Networking Foundation.";
  contact "Scott Baker";
  description "To generate JSON from this use command
    pyang -f jtoxx test1.yang | python3 -m json.tool > test1.json
    Copied from YangUIComponents project";

  revision "2020-10-22" {
    description "An Aether Subscriber";
    reference "RFC 6087";
  }

  typedef mcc {
      type uint32 {
        range 0..999;
      }
  }

  typedef mnc {
      type uint32 {
        range 0..999;
      }
  }

  typedef tac {
      type uint32 {
        range 0..99999999;
      }
  }

  container subscriber {
    description "The top level container";

    list ue {
      key "id";
      description
        "List of subscriber devices";

      leaf id {
        description "identifier for this subscriber, typically a UUID";
        type ietf:uuid;
      }

      leaf display-name {
        type string {
            length 1..80;
        }
        description "display name to use in GUI or CLI";
      }      

      choice imsi {
        case wildcard {
          leaf imsi-wildcard {
            type string {
              length 1..15;
            }
          }
        }
        case range {
          leaf imsi-range-from {
            type uint64;
          }
          leaf imsi-range-to {
            type uint64;
          }
        }
      }

      container serving-plmn {
        leaf mcc {
          type mcc;
          description "mobile country code";
        }
        leaf mnc {
          type mnc;
          description "mobile network code";
        }
        leaf tac {
          type tac;
          description "type allocation code";
        }
      }

      leaf requested-apn {
        type string {
            length 0..31;
        }
        description "requested access point name";
      }

      leaf priority {
        type uint32 {
          range 0..1000;
        }
        default 0;
        description
          "Priority for this subscriber range";
      }

      leaf enabled {
        type boolean;
        default false;
        description
          "Enable or disable this ue";
      }

      leaf enterprise {
        type leafref {
          path "/ent:enterprise/ent:enterprise/ent:id";
        }              
        description
          "Link to enterprise that owns this UE range";
      }

      container profiles {
        leaf apn-profile {
          type leafref {
            path "/apn:apn-profile/apn:apn-profile/apn:id";
          }
          description
            "Link to apn profile";
        }
        leaf up-profile {
          type leafref {
            path "/up:up-profile/up:up-profile/up:id";
          }          
          description
            "Link to user plane profile";
        }
        leaf qos-profile {
          type leafref {
            path "/qos:qos-profile/qos:qos-profile/qos:id";
          }              
          description
            "Link to qos profile";
        }
        list access-profile {
          key "access-profile";
          leaf access-profile {
            type leafref {
              path "/ap:access-profile/ap:access-profile/ap:id";
            }            
            description
                "Link to access profile";
          }
          leaf allowed {
            type boolean;
            default true;
            description
              "Allow or disallow this ue to use this access profile";
          }
        }
        leaf security-profile {
          type leafref {
            path "/sec:security-profile/sec:security-profile/sec:id";
          }              
          description
            "Link to security profile";
        }
      }
    }
  } 
}
