2. Mobile Convergence Laboratory
YANG
‣YANG is a data modeling language for the definition of data sent over the NETCONF
network configuration protocol.
‣The name is an acronym for “Yet Another Next Generation”.
‣The data modeling language can be used to model both configuration data as well as state
data of network elements.
‣The language being protocol independent can then be converted into any encoding format,
e.g. XML or JSON, that the network configuration protocol supports.
‣YANG is a modular language representing data structures in an XML tree format.
‣YANG data models can use XPATH expressions to define constraints on the elements of a
YANG data model.
Mobile Convergence Laboratory
2
4. Mobile Convergence Laboratory
YANG
Mobile Convergence Laboratory
‣YANG is Data modeling language
‣Tree structure
‣Data and Types.
• Configuration Data
• State data
4
5. Mobile Convergence Laboratory
YANG 저장형태
Mobile Convergence Laboratory
‣ YANG 모듈은 .yang 파일로 작성된다.
‣ YANG 파일은 관리하는 지정된 경로의 yin 파일에 xml 형식으로 저장한다.
‣ 관리하는 실제 값들은 네트워크 디바이스의 datastore 경로에 xml 형태로 데이터들을 저장한다.
5
9. Mobile Convergence Laboratory
YANG Module Contents
Mobile Convergence Laboratory
Header information
Imports & Includes
Type definitions
Configuration & Operational
data declarations
Action (RPC) & Notification declarations
9
10. Mobile Convergence Laboratory
Imports & Includes
Mobile Convergence Laboratory
Fragment
A.yang
Fragment
B.yang
Fragment
C.yang
Fragment
D.yang
Fragment
E.yang
Module X Namespace Module Y Namespace
import
include
includeinclude Submodule Z Namespace
Fragment
F.yang
10
13. Mobile Convergence Laboratory
YANG Base Types
Mobile Convergence Laboratory
‣YANG의 모든 데이터들은 데이터 타입을 가져야만 한다.
‣데이터 타입들은 base type 혹은 derived type이다.
• Derived type은 typedef 혹은 grouping으로 정의한다.
• Base Type은 20개 이상을 기본적으로 제공한다.
Type Name Meaning
int8/16/32/64 Integer
uint8/16/32/64 Unsigned Integer
Decimal64 Non-integer
String Unicode string
Enumeration Set of alternatives
Boolean True of false
Bits Boolean array
Binary Binary BLOB
Leafref Reference “pointer”
Identityref Unique identity
Empty No value, void
… and more
13
14. Mobile Convergence Laboratory
Types Statement
Mobile Convergence Laboratory
‣ 기존에 흔히 사용하는것 처럼 type define이 가능하다.
‣ type define 뿐만 아니라 type restrict 역시 가능하다.
typedef percent {
type uint16 {
range “0 .. 100”;
}
description “Percentage”;
}
14
15. Mobile Convergence Laboratory
Types Statement (Cont’d)
Mobile Convergence Laboratory
• Integers • Strings
typedef my-base-int32-type {
type int32 {
range “1..4 | 10..20”;
}
}
typedef derived-int32 {
type my-base-int32-type {
range “11..max”;
}
}
typedef my-base-str-type {
type string {
length “1..255”;
}
}
typedef derived-str {
type my-base-str-type {
length “11 | 42..max”;
pattern “[0-0a-fA-F]*”;
}
}
15
16. Mobile Convergence Laboratory
Types Statement (Cont’d)
Mobile Convergence Laboratory
• Union Statement
typedef threshold {
description “Threshold value in percent”;
type union {
type uint16 {
range “0..100”;
}
type enumeration {
enum disabled {
description “No threshold”;
}
}
}
}
*유니언 타입 멤버중 한개만이 이 데이터를 나타낸다
16
17. Mobile Convergence Laboratory
Types Statement (Cont’d)
Mobile Convergence Laboratory
• Grouping Statement
grouping target {
leaf address {
type inet:ip-address;
}
leaf port {
type inet:port-number;
}
}
container peer {
container destination {
uses target;
}
}
17
18. Mobile Convergence Laboratory
Types Statement (Cont’d)
Mobile Convergence Laboratory
• Grouping Statement
grouping target {
leaf address {
type inet:ip-address;
}
leaf port {
type inet:port-number;
}
}
*refine도 할 수 있다.
container servers {
container http {
uses target {
refine port {
default 80;
}
}
}
}
18
19. Mobile Convergence Laboratory
Common YANG Types
Mobile Convergence Laboratory
‣ 많이 사용되는 데이터 타입들은 고맙게도 RFC 6021에서
정의 되어 있고, 제공을 한다.
• 사용하기 위해선 import 한 후에 해야한다.
import “ietf-yang-types” {
prefix yang;
}
사용하기 위해선 아래와 같이 사용하면된다.
type yang:counter64
counter32/64 ipv4-address
gauge32/64 ipv6-address
object-identifier ip-prefix
date-and-time ipv4-prefix
timeticks ipv6-prefix
timestamp domain-name
phys-address uri
ip-version mac-address
flow-label bridgeid
port-number vlanid
ip-address … and more
19
21. Mobile Convergence Laboratory
Leaf Statement
Mobile Convergence Laboratory
‣ 특정 타입을 가지는 하나의 Data 값.
‣ child 노드를 가지지 않는다.
leaf host-name {
type string;
mandatory true;
config true;
description “Hostname for this system”;
}
leaf cpu-temp {
type int32;
units degrees-celsius;
config false;
description “Current temperature in CPU”;
}
21
22. Mobile Convergence Laboratory
Attributes for leaf
Mobile Convergence Laboratory
config
Whether this leaf is configurable value (“true”) or operational value (“false”).
Inherited from parent container if not specified
default Specifies default value for this leaf. Implies that leaf is optional
mandatory Whether the leaf is mandatory (“true”) or optional (“false”)
must XPath constraint that will be enforced for this leaf
type The data type (and range etc) of this leaf
when Conditional leaf, only present if Path expression is true
description Human readable definition and help text for this leaf
reference Human readable reference to some other element or spec
units Human readable unit specification (e.g. Hz, MB/s, )
status Whether this leaf is “current”, “deprecated” or “obsolete”
22
23. Mobile Convergence Laboratory
Container Statement
Mobile Convergence Laboratory
‣ 관련된 leaf 혹은 container 들끼리의
group인 데이터 타입.
container system {
container services {
container ssh {
presence “Enables SSH”;
description “blahblah”;
// more leafs, container and etc.
}
}
}
23
24. Mobile Convergence Laboratory
Leaf-list Statement
Mobile Convergence Laboratory
‣ 특정 타입을 가지는 하나의 Data 값.
‣ child 노드를 가지지 않는다.
‣ list 형태로 여러개를 가질 수 있다.
leaf-list domain-search {
type string;
ordered-by user;
description “List of domain names to search”;
}
24
25. Mobile Convergence Laboratory
List Statement
Mobile Convergence Laboratory
‣ List구조를 가진다.
‣ Key가 존재.
‣ Key를 이용해 리스트의 data에 접근할 수 있다.
( e.g. /user[uid=‘1000’]/name = yang)
‣ Unique를 이용해서 유일한 값을 가지게 할 수도 있다.
‣ Multiple key도 가능.
list user {
key uid;
unique name;
leaf name {
type string;
}
leaf uid {
type uint32;
}
leaf full-name {
type string;
}
leaf class {
type string;
default viewer;
}
}
25
26. Mobile Convergence Laboratory
Leafref
Mobile Convergence Laboratory
‣ 이미 존재하는 다른 leaf를 참조하는 pointer 타입.
‣ A valid leafref는 절대로 null 이나 empty가 될 수 없지
만, pearent leaf가 optional 할 수 있다.
‣ leafref로 지정된 값은 지워지거나 이름이 바뀌면 안된다.
‣ system이 leafref의 validity를 자동적으로 체크한다.
‣ XPath Operator도 사용이 가능하다
(e.g. path “/client[ip=current()/../v-ip]/port”)
container user {
list network-ifname {
key ifname;
leaf ifname {
type leafref {
path “/interface/name”;
}
}
}
26
28. Mobile Convergence Laboratory
RPC Statement
Mobile Convergence Laboratory
‣ input 과 output parameter를 정해
RPC를 정의할 수 있다.
rpc activate-software-image {
input {
leaf image {
type binary;
}
}
output {
leaf status {
type string;
}
}
}
28
29. Mobile Convergence Laboratory
Notification Statement
Mobile Convergence Laboratory
‣ output만이 존재한다.
‣ 여러 parameter 를 이용해 정의.
notification config-change {
description “blahblah”
leaf operator-name {
type string;
}
leaf-list change{
type instance-identifier;
}
}
29
31. Mobile Convergence Laboratory
Must Statement
Mobile Convergence Laboratory
‣ 반드시 정의되어야 하는 조건이 있을 때 사용한다.
leaf max-weight {
type uint32 {
range “0..1000”;
}
default 100;
must “sum(/sys:sys/interface[enabled = ‘true’]/weight) < current()” {
error-message “The total weight exceeds the configured max
weight”
}
}
31
32. Mobile Convergence Laboratory
Augment Statement
Mobile Convergence Laboratory
‣ 기존의 정의된 list에 추가하려할 때 사용한다.
augment /sys:system/sys:user {
leaf expire {
type yang:date-and-time;
}
}
32
33. Mobile Convergence Laboratory
When Statement
Mobile Convergence Laboratory
‣ 조건문을 추가해주는 용도.
augment /sys:system/sys:user {
when “sys:class = ‘whell’ “;
leaf shell {
type string;
}
}
33
34. Mobile Convergence Laboratory
Choice Statement
Mobile Convergence Laboratory
‣ 여러 종류의 leaf 들을 사용할 수 있게 해준다.
choice transfer-method {
leaf transfer-interval {
description “Frequency at which file transfer happens”;
type uint16 {
range “15..2880”;
}
units minutes;
}
leaf transfer-on-commit {
description “Frequency at which file transfer happens”;
type empty;
}
}
34
35. Mobile Convergence Laboratory
Identity Statement
Mobile Convergence Laboratory
module phys-if {
…
identity ethernet {
description “blahblah”;
}
identity eth-1G {
base ethernet;
description “blahblah”;
}
identity eth-10G {
base ethernet;
description “blahblah”;
}
}
35
‣ Identities for modeling families of related enumeration constants
module newer {
…
identity eth-40G {
base phys-if:ethernet;
description “blahblah”;
}
…
leaf eth-type {
type identityref {
base ”phys-if:ethernet”;
description “blahblah”;
}
}
36. Mobile Convergence LaboratoryMobile Convergence Laboratory
‣ hardware 같은 조건들을 mark 하여준다. 한다.
feature has-local-disk {
description
“System has a local file system
that can be used for storing log files”;
}
container system {
container logging {
if-feature has-local-disk;
presence “Logging enabled”;
leaf buffer-size {
type filesize;
}
}
}
36
Feature Statement
37. Mobile Convergence LaboratoryMobile Convergence Laboratory
‣ System should conform to standard YAMs.
deviation /base:system/base:user/base:type {
deviate add {
default “admin”; // new users are ‘admin’ by default
}
}
deviation /base:system/base:name-server {
deviate replace {
max-elements 3;
}
}
37
Deviations