What are presence types?ΒΆ

According to RFC 6020, YANG supports two styles of containers. One is for organizing hierarchy. Another type (called ‘presence container’) is for representing configuration data. For instance the existence of presence container ssh indicates the capability to log in to the device using SSH. Let us consider a presence node prefix-list-entries in Cisco-IOS-XR-ipv4-acl-cfg.yang. This node is generated as a YDK struct shown below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Ipv4AclAndPrefixList_Prefixes_Prefix
// Name of a prefix list
type Ipv4AclAndPrefixList_Prefixes_Prefix struct {
    EntityData types.CommonEntityData
    YFilter yfilter.YFilter

    // This attribute is a key. Prefix list name - max 32 characters. The type is
    // string.
    PrefixListName interface{}

    // Sequence of entries forming a prefix list.
    PrefixListEntries Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries
}

// Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries
// Sequence of entries forming a prefix list
// This type is a presence type.
type Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries struct {
    EntityData types.CommonEntityData
    YFilter yfilter.YFilter
    YPresence bool

    // A prefix list entry; either a description (remark) or a prefix to match
    // against. The type is slice of
    // Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries_PrefixListEntry.
    PrefixListEntry []Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries_PrefixListEntry
}

Since the existence of container prefix-list-entries itself represents configuration data, YDK does not instantiate an instance of Ipv4AclAndPrefixList_Prefixes_Prefix_PrefixListEntries with the YPresence attribute. The user needs manually instantiate and assign this object as follows:

1
2
pref := Ipv4AclAndPrefixList_Prefixes_Prefix{}
pref.PrefixListEntries.YPresence = true