Skip to content

Commit 9b59ee0

Browse files
authored
[ssip]: Add YANG model (#10992)
- Why I did it To implement Syslog Source IP feature based on HLD: sonic-net/SONiC#1002 - How I did it Added the relevant yang model - How to verify it Added unit test Signed-off-by: Nazarii Hnydyn <nazariig@nvidia.com>
1 parent e9fee86 commit 9b59ee0

File tree

4 files changed

+202
-9
lines changed

4 files changed

+202
-9
lines changed

src/sonic-yang-models/tests/files/sample_config_db.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,21 @@
426426
"2001:aa:aa::aa": {}
427427
},
428428
"SYSLOG_SERVER" : {
429-
"10.13.14.17": {},
430-
"20.1.1.1": {},
431-
"2001:aa:aa::aa": {}
429+
"10.13.14.17": {
430+
"source": "1.1.1.1",
431+
"port": "514",
432+
"vrf": "default"
433+
},
434+
"20.1.1.1": {
435+
"source": "1.1.1.1",
436+
"port": "514",
437+
"vrf": "mgmt"
438+
},
439+
"2001:aa:aa::aa": {
440+
"source": "1111::1111",
441+
"port": "514",
442+
"vrf": "Vrf_blue"
443+
}
432444
},
433445
"CABLE_LENGTH": {
434446
"AZURE": {

src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
{
2+
"SYSLOG_SERVER_VALID": {
3+
"desc": "Configure SYSLOG_SERVER."
4+
},
5+
"SYSLOG_SERVER_INVALID_SOURCE": {
6+
"desc": "Configure invalid SOURCE in SYSLOG_SERVER.",
7+
"eStrKey": "InvalidValue"
8+
},
9+
"SYSLOG_SERVER_SOURCE_IP_FAMILY_MISMATCH": {
10+
"desc": "Configure SOURCE IP family mismatch in SYSLOG_SERVER.",
11+
"eStrKey": "Must"
12+
},
13+
"SYSLOG_SERVER_INVALID_PORT": {
14+
"desc": "Configure invalid PORT in SYSLOG_SERVER.",
15+
"eStrKey": "InvalidValue"
16+
},
17+
"SYSLOG_SERVER_INVALID_VRF": {
18+
"desc": "Configure invalid VRF in SYSLOG_SERVER.",
19+
"eStrKey": "InvalidValue"
20+
},
21+
"SYSLOG_SERVER_DISABLED_MGMT_VRF": {
22+
"desc": "Configure disabled management VRF in SYSLOG_SERVER.",
23+
"eStrKey": "Must"
24+
},
225
"SYSLOG_SERVER_TEST": {
326
"desc": "Load syslog server table with ipv4 address as syslog servers."
427
},
@@ -14,5 +37,4 @@
1437
"desc": "Load syslog server table with invalid ipv6 address as syslog server.",
1538
"eStrKey": "InvalidValue"
1639
}
17-
18-
}
40+
}

src/sonic-yang-models/tests/yang_model_tests/tests_config/syslog.json

+109
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,113 @@
11
{
2+
"SYSLOG_SERVER_VALID": {
3+
"sonic-syslog:sonic-syslog": {
4+
"sonic-syslog:SYSLOG_SERVER": {
5+
"SYSLOG_SERVER_LIST": [
6+
{
7+
"server_address": "100.0.0.1",
8+
"source": "1.1.1.1",
9+
"port": "514",
10+
"vrf": "default"
11+
},
12+
{
13+
"server_address": "200.0.0.1",
14+
"source": "1.1.1.1",
15+
"port": "514",
16+
"vrf": "mgmt"
17+
},
18+
{
19+
"server_address" : "2000::1",
20+
"source": "1111::1111",
21+
"port": "514",
22+
"vrf": "Vrf-Data"
23+
}
24+
]
25+
}
26+
},
27+
"sonic-mgmt_vrf:sonic-mgmt_vrf": {
28+
"sonic-mgmt_vrf:MGMT_VRF_CONFIG": {
29+
"sonic-mgmt_vrf:vrf_global": {
30+
"mgmtVrfEnabled": "true"
31+
}
32+
}
33+
},
34+
"sonic-vrf:sonic-vrf": {
35+
"sonic-vrf:VRF": {
36+
"VRF_LIST": [
37+
{
38+
"name": "Vrf-Data"
39+
}
40+
]
41+
}
42+
}
43+
},
44+
"SYSLOG_SERVER_INVALID_SOURCE": {
45+
"sonic-syslog:sonic-syslog": {
46+
"sonic-syslog:SYSLOG_SERVER": {
47+
"SYSLOG_SERVER_LIST": [
48+
{
49+
"server_address": "100.0.0.1",
50+
"source": "invalid_value"
51+
}
52+
]
53+
}
54+
}
55+
},
56+
"SYSLOG_SERVER_SOURCE_IP_FAMILY_MISMATCH": {
57+
"sonic-syslog:sonic-syslog": {
58+
"sonic-syslog:SYSLOG_SERVER": {
59+
"SYSLOG_SERVER_LIST": [
60+
{
61+
"server_address": "100.0.0.1",
62+
"source": "1111::1111"
63+
}
64+
]
65+
}
66+
}
67+
},
68+
"SYSLOG_SERVER_INVALID_PORT": {
69+
"sonic-syslog:sonic-syslog": {
70+
"sonic-syslog:SYSLOG_SERVER": {
71+
"SYSLOG_SERVER_LIST": [
72+
{
73+
"server_address": "100.0.0.1",
74+
"port": "65536"
75+
}
76+
]
77+
}
78+
}
79+
},
80+
"SYSLOG_SERVER_INVALID_VRF": {
81+
"sonic-syslog:sonic-syslog": {
82+
"sonic-syslog:SYSLOG_SERVER": {
83+
"SYSLOG_SERVER_LIST": [
84+
{
85+
"server_address": "100.0.0.1",
86+
"vrf": "invalid_value"
87+
}
88+
]
89+
}
90+
}
91+
},
92+
"SYSLOG_SERVER_DISABLED_MGMT_VRF": {
93+
"sonic-syslog:sonic-syslog": {
94+
"sonic-syslog:SYSLOG_SERVER": {
95+
"SYSLOG_SERVER_LIST": [
96+
{
97+
"server_address": "100.0.0.1",
98+
"vrf": "mgmt"
99+
}
100+
]
101+
}
102+
},
103+
"sonic-mgmt_vrf:sonic-mgmt_vrf": {
104+
"sonic-mgmt_vrf:MGMT_VRF_CONFIG": {
105+
"sonic-mgmt_vrf:vrf_global": {
106+
"mgmtVrfEnabled": "false"
107+
}
108+
}
109+
}
110+
},
2111
"SYSLOG_SERVER_TEST": {
3112
"sonic-syslog:sonic-syslog": {
4113
"sonic-syslog:SYSLOG_SERVER": {

src/sonic-yang-models/yang-models/sonic-syslog.yang

+54-4
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,72 @@ module sonic-syslog {
99
prefix inet;
1010
}
1111

12+
import sonic-mgmt_vrf {
13+
prefix mvrf;
14+
}
15+
16+
import sonic-vrf {
17+
prefix vrf;
18+
}
19+
20+
description "Syslog YANG Module for SONiC OS: remote syslog logging";
21+
22+
revision 2022-04-18 {
23+
description "Initial revision.";
24+
}
25+
26+
typedef vrf-device {
27+
description "Represents syslog VRF device";
28+
type enumeration {
29+
enum default;
30+
enum mgmt;
31+
}
32+
}
33+
1234
container sonic-syslog {
1335

1436
container SYSLOG_SERVER {
1537

16-
description "SYSLOG SERVER part of config_db.json";
38+
description "SYSLOG_SERVER part of config_db.json";
1739

1840
list SYSLOG_SERVER_LIST {
1941

2042
key "server_address";
2143

2244
leaf server_address {
23-
description "syslog server ip address";
45+
description "Syslog server IP address";
46+
type inet:ip-address;
47+
}
48+
49+
leaf source {
50+
description "Syslog source IP address";
2451
type inet:ip-address;
52+
must "(contains(current(), '.') and contains(../server_address, '.'))
53+
or (contains(current(), ':') and contains(../server_address, ':'))";
54+
}
55+
56+
leaf port {
57+
description "Syslog server UDP port";
58+
type inet:port-number;
59+
}
60+
61+
leaf vrf {
62+
description "Syslog VRF device";
63+
type union {
64+
type leafref {
65+
path "/vrf:sonic-vrf/vrf:VRF/vrf:VRF_LIST/vrf:name";
66+
}
67+
type vrf-device;
68+
}
69+
must "(current() != 'mgmt')
70+
or (/mvrf:sonic-mgmt_vrf/mvrf:MGMT_VRF_CONFIG/mvrf:vrf_global/mvrf:mgmtVrfEnabled = 'true')";
2571
}
26-
} /* end of list SYSLOG_SERVER_LIST */
2772

28-
} /* end of container SYSLOG_SERVER */
73+
}
74+
/* end of list SYSLOG_SERVER_LIST */
75+
}
76+
/* end of container SYSLOG_SERVER */
2977
}
78+
/* end of container sonic-syslog */
3079
}
80+
/* end of module sonic-syslog */

0 commit comments

Comments
 (0)