Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cvl yang cleanup #125

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ install:
$(INSTALL) -d $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -d $(DESTDIR)/usr/sbin/lib/
$(INSTALL) -D $(TOPDIR)/src/cvl/schema/*.yin $(DESTDIR)/usr/sbin/schema/
$(INSTALL) -D $(TOPDIR)/src/cvl/testdata/schema/*.yin $(DESTDIR)/usr/sbin/schema/
cp -rf $(TOPDIR)/build/rest_server/dist/ui/ $(DESTDIR)/rest_ui/
cp -rf $(TOPDIR)/build/cli $(DESTDIR)/usr/sbin/
cp -rf $(TOPDIR)/build/swagger_client_py/ $(DESTDIR)/usr/sbin/lib/
Expand Down
5 changes: 4 additions & 1 deletion src/cvl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ tests:
make -C tests

gotest:
CVL_CFG_FILE=$(abspath .)/conf/cvl_cfg.json CVL_SCHEMA_PATH=$(abspath .)/schema GOPATH=$(GOPATH) tests/run_test.sh
make -C schema
make -C testdata/schema
cp schema/*.yin testdata/schema
CVL_CFG_FILE=$(abspath .)/conf/cvl_cfg.json CVL_SCHEMA_PATH=$(abspath .)/testdata/schema GOPATH=$(GOPATH) tests/run_test.sh

clean:
make -C tests clean
Expand Down
8 changes: 4 additions & 4 deletions src/cvl/cvl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2806,16 +2806,16 @@ func TestBadSchema(t *testing.T) {

if _, err := os.Stat("/usr/sbin/schema"); os.IsNotExist(err) {
//Corrupt some schema file
exec.Command("/bin/sh", "-c", "/bin/cp schema/sonic-port.yin schema/sonic-port.yin.bad" +
" && /bin/sed -i '1 a <junk>' schema/sonic-port.yin.bad").Output()
exec.Command("/bin/sh", "-c", "/bin/cp testdata/schema/sonic-port.yin testdata/schema/sonic-port.yin.bad" +
" && /bin/sed -i '1 a <junk>' testdata/schema/sonic-port.yin.bad").Output()

//Parse bad schema file
if module, _ := yparser.ParseSchemaFile("schema/sonic-port.yin.bad.1"); module != nil { //should fail
if module, _ := yparser.ParseSchemaFile("testdata/schema/sonic-port.yin.bad"); module != nil { //should fail
t.Errorf("Bad schema parsing should fail.")
}

//Revert to
exec.Command("/bin/sh", "-c", "/bin/rm schema/sonic-port.yin.bad").Output()
exec.Command("/bin/sh", "-c", "/bin/rm testdata/schema/sonic-port.yin.bad").Output()
} else {
//Corrupt some schema file
exec.Command("/bin/sh", "-c", "/bin/cp /usr/sbin/schema/sonic-port.yin /usr/sbin/schema/sonic-port.yin.bad" +
Expand Down
7 changes: 6 additions & 1 deletion src/cvl/internal/yparser/yparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ func ParseSchemaFile(modelFile string) (*YParserModule, YParserError) {
//Add child node to a parent node
func(yp *YParser) AddChildNode(module *YParserModule, parent *YParserNode, name string) *YParserNode {

return (*YParserNode)(C.lyd_new((*C.struct_lyd_node)(parent), (*C.struct_lys_module)(module), C.CString(name)))
ret := (*YParserNode)(C.lyd_new((*C.struct_lyd_node)(parent), (*C.struct_lys_module)(module), C.CString(name)))
if (ret == nil) {
TRACE_LOG(INFO_DEBUG, TRACE_YPARSER, "Failed parsing node %s\n", name)
}

return ret
}

//Add child node to a parent node
Expand Down
51 changes: 13 additions & 38 deletions src/cvl/schema/sonic-acl.yang
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ module sonic-acl {
prefix prt;
}

import sonic-portchannel {
prefix spc;
}

import sonic-mirror-session {
prefix sms;
}

import sonic-pf-limits {
prefix spf;
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC ACL";
Expand All @@ -50,13 +42,12 @@ module sonic-acl {
list ACL_TABLE {
key "aclname";

/* must "count(/prt:sonic-port/prt:PORT) > 0"; */

leaf aclname {
type string {
pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,71})';
length 1..72;
}
type string {
pattern '[a-zA-Z0-9]{1}([-a-zA-Z0-9_]{0,71})';
length 1..72;
}
}

leaf policy_desc {
Expand Down Expand Up @@ -84,30 +75,14 @@ module sonic-acl {
}

leaf-list ports {
type union {
type leafref {
path "/prt:sonic-port/prt:PORT/prt:ifname";
}
type leafref {
path "/spc:sonic-portchannel/spc:PORTCHANNEL/spc:name";
}
type leafref {
path "/prt:sonic-port/prt:PORT/prt:ifname";
}
}
}

list ACL_RULE {
key "aclname rulename";
scommon:pf-check "ACL_CheckAclLimits";

/* Limit for number of dynamic ACL rules */
/*must "count(../ACL_RULE) > /spf:sonic-pf-limits/acl/MAX_ACL_RULES" {
error-message "Number of ACL rules reached max platform limit.";
}
must "PRIORITY > /spf:sonic-pf-limits/acl/MAX_PRIORITY" {
error-message "Invalid ACL rule priority.";
}
must "count(../ACL_TABLE) > 0 and count(/prt:sonic-port/prt:PORT) > 0"; //Temporary work-around
*/

leaf aclname {
type leafref {
Expand All @@ -116,7 +91,7 @@ module sonic-acl {
must "(/scommon:operation/scommon:operation != 'DELETE') or " +
"count(current()/../../ACL_TABLE[aclname=current()]/ports) = 0" {
error-message "Ports are already bound to this rule.";
}
}
}

leaf rulename {
Expand All @@ -127,7 +102,7 @@ module sonic-acl {
type uint16 {
range "1..65535"{
error-message "Invalid ACL rule priority.";
}
}
}
}

Expand Down Expand Up @@ -160,16 +135,16 @@ module sonic-acl {
enum NON_IPV6;
}
}

leaf IP_PROTOCOL {
type uint8 {
range "1|2|6|17|46|47|51|103|115";
}
}

leaf ETHER_TYPE {
type string{
pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)"{
type string {
pattern "(0x88CC)|(0x8100)|(0x8915)|(0x0806)|(0x0800)|(0x86DD)|(0x8847)" {
error-message "Invalid ACL Rule Ether Type";
error-app-tag ether-type-invalid;
}
Expand Down
28 changes: 14 additions & 14 deletions src/cvl/schema/sonic-common.yang
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module sonic-common {
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC VLAN";
Expand All @@ -22,18 +22,18 @@ module sonic-common {
}

typedef tagging_mode {
type enumeration {
enum untagged;
enum tagged;
enum priority_tagged;
}
type enumeration {
enum untagged;
enum tagged;
enum priority_tagged;
}
}

typedef admin-status {
type enumeration {
enum up;
enum down;
}
type enumeration {
enum up;
enum down;
}
}

extension custom-handler {
Expand Down Expand Up @@ -63,19 +63,19 @@ module sonic-common {
extension map-list {
description
"If it is a map list";
argument "value"; //
argument "value";
}

extension map-leaf {
description
"Map leaf names";
argument "value"; //
argument "value";
}

extension pf-check {
description
"Platform specific validation";
argument "handler"; //
argument "handler";
}

container operation {
Expand Down
16 changes: 8 additions & 8 deletions src/cvl/schema/sonic-interface.yang
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module sonic-interface {
}

import ietf-inet-types {
prefix inet;
}
prefix inet;
}

import sonic-common {
prefix scommon;
Expand All @@ -19,10 +19,10 @@ module sonic-interface {
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC INTERFACE";
Expand All @@ -38,13 +38,13 @@ module sonic-interface {

leaf portname{
type leafref {
path "/prt:sonic-port/prt:PORT/prt:ifname";
}
path "/prt:sonic-port/prt:PORT/prt:ifname";
}
}

leaf ip_prefix {
mandatory true;
type inet:ip-prefix;
mandatory true;
type inet:ip-prefix;

}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cvl/schema/sonic-mirror-session.yang
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module sonic-mirror-session {
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC MIRROR SESSION";
Expand Down
10 changes: 5 additions & 5 deletions src/cvl/schema/sonic-port.yang
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module sonic-port {
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC VLAN";
Expand All @@ -33,11 +33,11 @@ module sonic-port {
type string {
pattern "Ethernet([1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])"{
error-message "Invalid interface name";
error-app-tag interface-name-invalid;
}
error-app-tag interface-name-invalid;
}
}
}

leaf index {
type uint16;
}
Expand Down
44 changes: 44 additions & 0 deletions src/cvl/testdata/schema/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
################################################################################
# #
# Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or #
# its subsidiaries. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
################################################################################

src_files=$(wildcard *.yang)
out=$(patsubst %.yang, %.yin, $(src_files))
out_ext=$(patsubst %.yang, %.tree, $(src_files))

all:schema

schema: $(out)

%.yin:%.yang
@echo "Generating $@ ..."
@devFile="`echo $< | cut -d . -f1`-dev.yang"; \
if [ -f $$devFile ] ; then devOpt="--deviation-module $$devFile"; fi; \
pyang -p ../../schema/:../../schema/ietf/ -f yin $$devOpt $< -o [email protected]
@xmllint --noblanks [email protected] > $@
@rm -rf [email protected]

%.tree:%.yang
@echo "Generating $@ ..."
@devFile="`echo $< | cut -d . -f1`-dev.yang"; \
if [ -f $$devFile ] ; then devOpt="--deviation-module $$devFile"; fi; \
pyang -p ../../schema/:../../schema/ietf/ -f tree $$devOpt $< -o $@

clean:
@echo "Removing files ..."
rm -rf *.yin
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ module sonic-acl-dev {


organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC ACLi Deviations";
"SONIC ACL Deviations";

revision 2019-05-15 {
description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module sonic-bgp-neighbor {
}

organization
"BRCM";
"SONiC";

contact
"BRCM";
"SONiC";

description
"SONIC BGP NEIGHBOR";
Expand Down
Loading