SONiC Yang model support for Mirror (#7877)

#### Why I did it
Created SONiC Yang model for Mirror.
Tables: MIRROR_SESSION

#### How I did it

Defined Yang models for COPP based on Guideline doc:
https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md
and
https://github.com/Azure/sonic-utilities/blob/master/doc/Command-Reference.md

#### How to verify it
'''
============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /sonic/src/sonic-yang-models, inifile:
plugins: cov-2.6.0
collected 3 items

tests/test_sonic_yang_models.py ..                                       [ 66%]
tests/yang_model_tests/test_yang_model.py .                              [100%]

=============================== warnings summary ===============================

module: sonic-mirror-session
  +--rw sonic-mirror-session
     +--rw MIRROR_SESSION
        +--rw MIRROR_SESSION_LIST* [name]
           +--rw name         string
           +--rw type?        string
           +--rw src_ip?      inet:ipv4-address
           +--rw dst_ip?      inet:ipv4-address
           +--rw gre_type?    string
           +--rw dscp?        uint8
           +--rw ttl?         uint8
           +--rw queue?       uint8
           +--rw dst_port?    -> /port:sonic-port/PORT/PORT_LIST/name
           +--rw src_port?    union
           +--rw direction?   string

'''
This commit is contained in:
rupesh-k 2021-12-03 00:22:01 +05:30 committed by Judy Joseph
parent 6f406b91ba
commit 90b74d5280
5 changed files with 729 additions and 0 deletions

View File

@ -103,6 +103,7 @@ setup(
'./yang-models/sonic-mgmt_interface.yang',
'./yang-models/sonic-mgmt_port.yang',
'./yang-models/sonic-mgmt_vrf.yang',
'./yang-models/sonic-mirror-session.yang',
'./yang-models/sonic-ntp.yang',
'./yang-models/sonic-nat.yang',
'./yang-models/sonic-pbh.yang',

View File

@ -1409,6 +1409,27 @@
"pfc_to_pg_map" : "pfc_prio_to_pg_map2",
"pfc_enable" : "3,4"
}
},
"MIRROR_SESSION": {
"erspan": {
"dscp": "10",
"dst_ip": "11.1.1.1",
"gre_type": "0x1234",
"queue": "0",
"src_ip": "10.1.1.1",
"ttl": "10",
"type": "ERSPAN"
},
"span": {
"direction": "RX",
"type": "SPAN",
"dst_port": "Ethernet2",
"src_port": [
"Ethernet3",
"Ethernet4"
]
}
}
},
"SAMPLE_CONFIG_DB_UNKNOWN": {

View File

@ -0,0 +1,81 @@
{
"MIRROR_ERSPAN_ENTRY_WITH_VALID_VALUES": {
"desc": "Configuring ERSPAN entry with valid values."
},
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid type",
"eStrKey": "InvalidValue"
},
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP": {
"desc": "Configurinng ERSPAN entry with invalid dst_ip",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid dst_ip",
"eStrKey" : "When"
},
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP": {
"desc": "Configurinng ERSPAN entry with invalid src_ip",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid src_ip",
"eStrKey" : "When"
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid GRE type",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_GRE_WRONG_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid GRE type",
"eStrKey" : "When"
},
"MIRROR_ERSPAN_ENTRY_WRONG_DSCP": {
"desc": "Configurinng ERSPAN entry with invalid dscp",
"eStr" : "Invalid dscp value"
},
"MIRROR_ERSPAN_ENTRY_WRONG_DSCP_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid dscp",
"eStrKey" : "When"
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL": {
"desc": "Configurinng ERSPAN entry with invalid ttl",
"eStr": "Invalid TTL value"
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid ttl",
"eStrKey" : "When"
},
"MIRROR_ERSPAN_ENTRY_VALID_SRC_PORT": {
"desc": "Configurinng ERSPAN entry with valid source port"
},
"MIRROR_ERSPAN_ENTRY_VALID_SRC_PORTCHANNEL": {
"desc": "Configurinng ERSPAN entry with valid source portchannel"
},
"MIRROR_ERSPAN_ENTRY_INVALID_SRC_PORT": {
"desc": "Configurinng ERSPAN entry with invalid source port",
"eStrKey" : "InvalidValue"
},
"MIRROR_SPAN_ENTRY_WITH_VALID_VALUES": {
"desc": "Configurinng SPAN entry with valid source and destination ports"
},
"MIRROR_SPAN_ENTRY_INVALID_DST_PORT": {
"desc": "Configurinng SPAN entry with invalid destination ports",
"eStrKey" : "InvalidValue"
},
"MIRROR_SPAN_ENTRY_INVALID_DST_PORT_TYPE": {
"desc": "Configurinng SPAN entry with invalid destination ports",
"eStrKey" : "When"
},
"MIRROR_SPAN_ENTRY_VALID_DST_PORT_CPU": {
"desc": "Configurinng SPAN entry with valid destination port CPU"
},
"MIRROR_SPAN_ENTRY_INVALID_SRC_PORT": {
"desc": "Configurinng SPAN entry with invalid destination ports",
"eStrKey" : "InvalidValue"
},
"MIRROR_SPAN_ENTRY_INVALID_DIRECTION": {
"desc": "Configurinng SPAN entry with invalid direction",
"eStrKey": "InvalidValue"
}
}

View File

@ -0,0 +1,446 @@
{
"MIRROR_ERSPAN_ENTRY_WITH_VALID_VALUES": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "Invalid",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "1001::1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "SPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "1001::1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "SPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_GRE_WRONG_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "SPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_DSCP": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "64"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_DSCP_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "SPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "63"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10",
"ttl": "65"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_TTL_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "SPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10",
"ttl": "63"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_VALID_SRC_PORT": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"alias": "eth0",
"description": "Ethernet0",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet0",
"speed": 25000
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10",
"ttl": "63",
"src_port": [
"Ethernet0"
]
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_VALID_SRC_PORTCHANNEL": {
"sonic-portchannel:sonic-portchannel": {
"sonic-portchannel:PORTCHANNEL": {
"PORTCHANNEL_LIST": [
{
"admin_status": "up",
"name": "PortChannel5"
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10",
"ttl": "63",
"src_port": [
"PortChannel5"
]
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_INVALID_SRC_PORT": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x1234",
"dscp": "10",
"ttl": "63",
"src_port": [
"Ethernet0"
]
}
]
}
}
},
"MIRROR_SPAN_ENTRY_WITH_VALID_VALUES": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"alias": "eth0",
"description": "Ethernet0",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet0",
"speed": 25000
},
{
"admin_status": "up",
"alias": "eth1",
"description": "Ethernet4",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet4",
"speed": 25000
},
{
"admin_status": "up",
"alias": "eth1",
"description": "Ethernet8",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet8",
"speed": 25000
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "SPAN",
"dst_port": "Ethernet0",
"src_port": [
"Ethernet4",
"Ethernet8"
],
"direction": "RX"
}
]
}
}
},
"MIRROR_SPAN_ENTRY_INVALID_DST_PORT": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "SPAN",
"dst_port": "Ethernet0"
}
]
}
}
},
"MIRROR_SPAN_ENTRY_INVALID_DST_PORT_TYPE": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"alias": "eth0",
"description": "Ethernet0",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet0",
"speed": 25000
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "ERSPAN",
"dst_port": "Ethernet0"
}
]
}
}
},
"MIRROR_SPAN_ENTRY_VALID_DST_PORT_CPU": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "SPAN",
"dst_port": "CPU"
}
]
}
}
},
"MIRROR_SPAN_ENTRY_INVALID_SRC_PORT": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"alias": "eth0",
"description": "Ethernet0",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet0",
"speed": 25000
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "SPAN",
"dst_port": "Ethernet0",
"src_port": [
"Ethernet4"
]
}
]
}
}
},
"MIRROR_SPAN_ENTRY_INVALID_DIRECTION": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"alias": "eth0",
"description": "Ethernet0",
"lanes": "1",
"mtu": 9000,
"name": "Ethernet0",
"speed": 25000
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "span",
"type": "SPAN",
"dst_port": "Ethernet0",
"direction":"RXX"
}
]
}
}
}
}

View File

@ -0,0 +1,180 @@
module sonic-mirror-session {
yang-version 1.1;
namespace "http://github.com/Azure/sonic-mirror-session";
prefix sms;
import ietf-inet-types {
prefix inet;
}
import sonic-port {
prefix port;
}
import sonic-portchannel {
prefix lag;
}
description
"SONiC Mirror session yang model";
revision 2021-06-15 {
description
"Initial revision.";
}
typedef session_type {
type enumeration {
enum ERSPAN {
description "ERSPAN session";
}
enum SPAN {
description "SPAN session";
}
}
}
typedef session_direction {
type enumeration {
enum RX {
description "RX direction";
}
enum TX {
description "TX direction";
}
enum BOTH {
description "Both RX and TX direction";
}
}
}
container sonic-mirror-session {
container MIRROR_SESSION {
list MIRROR_SESSION_LIST {
key "name";
leaf name {
type string {
pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,31})';
length 1..32 {
error-message "Invalid mirror session name";
error-app-tag session-name-invalid;
}
}
description
"Mirror session name.";
}
leaf type {
type session_type;
default "ERSPAN";
description
"Mirror session type.";
}
leaf src_ip {
when "current()/../type = 'ERSPAN'";
type inet:ipv4-address;
description
"ERSPAN source ip. This IP will be set as source ip in
outer header of mirrored frame ";
}
leaf dst_ip {
when "current()/../type = 'ERSPAN'";
type inet:ipv4-address;
description
"ERSPAN destination ip. Mirrored frames will be routed to this destination.
This IP will be set as destination ip in outer header of mirrored frame ";
}
leaf gre_type {
when "current()/../type = 'ERSPAN'";
type string {
pattern "0[xX][0-9a-fA-F]*";
length 1..6 {
error-message "Invalid GRE type";
error-app-tag gre-type-invalid;
}
}
default 0x88be;
description
"ERSPAN outer header GRE type.";
}
leaf dscp {
when "current()/../type = 'ERSPAN'";
type uint8 {
range "0..63" {
error-message "Invalid dscp value";
error-app-tag dscp-invalid;
}
}
description
"ERSPAN outer header DSCP value. Mirrored frames will be sent with configured DSCP value";
}
leaf ttl {
when "current()/../type = 'ERSPAN'";
type uint8 {
range "0..63" {
error-message "Invalid TTL value";
error-app-tag ttl-invalid;
}
}
description
"ERSPAN outer header TTL value. Mirrored frames will be sent with configured TTL value";
}
leaf queue {
type uint8;
description
"ERSPAN Queue. Mirrored frames will be sent to this queue";
}
leaf dst_port {
when "current()/../type = 'SPAN'";
type union {
type leafref {
path "/port:sonic-port/port:PORT/port:PORT_LIST/port:name";
}
type string {
pattern "CPU";
}
}
description
"Destination port configuration for port mirroring(SPAN).";
}
leaf-list src_port {
type union {
type leafref {
path "/port:sonic-port/port:PORT/port:PORT_LIST/port:name";
}
type leafref {
path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name";
}
}
description
"Source port configuration for mirroring. Can be configured for both SPAN/ERSPAN.
Supports both port and port-channel as arguments";
}
leaf direction {
type session_direction;
default "BOTH";
description
"Direction configuration for mirroring. Can be configured for both SPAN/ERSPAN.
Supports rx/tx/both as direction config.
RX: Captures frames ingressing on source port.
TX: Captures frames egressing on source port.
BOTH: Captures frames ingressing or egressing on source port.";
}
}
}
}
}