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

Initial import from sonic-mgmt-framework repo #10

Merged
merged 4 commits into from
Jun 13, 2020
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
*.code-workspace
build
vendor
__pycache__
*.pyc
*.rdb
*.swp
*.yin
*.tree
translib/ocbinds/ocbinds.go
89 changes: 89 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
################################################################################
# #
# 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. #
# #
################################################################################

TOPDIR := $(abspath .)
BUILD_DIR := build

GOPATH ?= /tmp/go
GO ?= /usr/local/go/bin/go

GO_MOD = go.mod
GO_DEPS = vendor/.done
GO_PATCHES = $(shell find patches -type f)
GOYANG_BIN = $(abspath $(BUILD_DIR)/bin/goyang)

export TOPDIR GO GOPATH

all: models cvl translib

$(GO_MOD):
$(GO) mod init github.com/Azure/sonic-mgmt-common

$(GO_DEPS): $(GO_MOD) $(GO_PATCHES)
$(GO) mod vendor
patches/apply.sh vendor
touch $@

go-deps: $(GO_DEPS)

go-deps-clean:
$(RM) -r vendor

.PHONY: cvl
cvl: $(GO_DEPS)
$(MAKE) -C ./cvl

cvl-all: $(GO_DEPS)
$(MAKE) -C ./cvl all

cvl-clean:
$(MAKE) -C ./cvl clean

cvl-test:
$(MAKE) -C ./cvl gotest

.PHONY: translib
translib: $(GO_DEPS)
$(MAKE) -C ./translib

translib-all: $(GO_DEPS)
$(MAKE) -C ./translib all

translib-clean:
$(MAKE) -C ./translib clean

.PHONY: models
models:
$(MAKE) -C models/yang

models-clean:
$(MAKE) -C models/yang clean

annotgen: $(GOYANG_BIN)

$(GOYANG_BIN): $(GO_DEPS)
cd vendor/github.com/openconfig/goyang && \
$(GO) build -o $@ *.go

clean: models-clean translib-clean cvl-clean
git check-ignore debian/* | xargs -r $(RM) -r
$(RM) -r $(BUILD_DIR)

cleanall: clean go-deps-clean
git clean -fdX tools
3 changes: 3 additions & 0 deletions config/transformer/models_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#List yang models transformer need to load
openconfig-acl.yang
openconfig-acl-annot.yang
72 changes: 72 additions & 0 deletions cvl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
################################################################################
# #
# 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. #
# #
################################################################################

GO?=go
SRC_FILES=$(shell find . -name '*.go' | grep -v '_test.go' | grep -v '/tests/')
TEST_FILES=$(wildcard *_test.go)
TOP_DIR := ..
BUILD_DIR:=$(TOP_DIR)/build/cvl
CVL_PKG=$(TOP_DIR)/build/pkg/linux_amd64/cvl.a

CVL_SCHEMA_DIR = $(BUILD_DIR)/schema
CVL_TEST_DIR = $(TOP_DIR)/build/tests/cvl
CVL_TEST_BIN = $(CVL_TEST_DIR)/cvl.test
CVL_TEST_SCHEMA_DIR = $(CVL_TEST_DIR)/testdata/schema

DEFAULT_TARGETS = deps schema
ifeq ($(NO_TEST_BINS),)
DEFAULT_TARGETS += $(CVL_TEST_BIN) test-schema
endif

default: $(DEFAULT_TARGETS)

all: $(DEFAULT_TARGETS) $(CVL_PKG)

deps:
mkdir -p $(BUILD_DIR)

$(CVL_PKG): $(SRC_FILES)
@echo "Building $@"
$(GO) build -mod=vendor -o $(CVL_PKG) ../cvl

$(CVL_TEST_BIN): $(TEST_FILES) $(SRC_FILES) | test-schema
cp -r testdata/*.json $(@D)/testdata
$(GO) test -mod=vendor -cover -coverpkg=../cvl,../cvl/internal/util,../cvl/internal/yparser -c ../cvl -o $@

.PHONY: schema
schema:
$(MAKE) -C schema

test-schema: | schema
$(MAKE) -C testdata/schema
cp $(CVL_SCHEMA_DIR)/*.yin $(CVL_TEST_SCHEMA_DIR)/

tests:
$(MAKE) -C tests

gotest:schema test-schema
CVL_CFG_FILE=$(abspath .)/conf/cvl_cfg.json CVL_SCHEMA_PATH=$(CVL_TEST_SCHEMA_DIR) tests/run_test.sh

clean:
$(MAKE) -C tests clean
$(MAKE) -C schema clean
$(MAKE) -C testdata/schema clean
$(RM) -r $(CVL_PKG)
$(RM) -r $(CVL_TEST_DIR)

62 changes: 62 additions & 0 deletions cvl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
1. Install latest version of pyang tool.

2. Install libyang from https://github.com/CESNET/libyang along with its dependency.

3. Run 'make' from top level 'cvl' directory.

4. Refer to top level makefile rules for compiling individual targets.

5. 'schema' directory should contain all .yin files

6. On the target the 'schema' directory needs to be present in the same directory where application executable file is present.


Debugging Info:
===============

Below steps need to be done to enable CVL logging.

1. Find the CVL json config file in mgmt-framework docker in switch at "/usr/sbin/cvl_cfg.json" .

2. Change the logging flags from "false" to "true" as below:

{
"TRACE_CACHE": "true",
"TRACE_LIBYANG": "true",
"TRACE_YPARSER": "true",
"TRACE_CREATE": "true",
"TRACE_UPDATE": "true",
"TRACE_DELETE": "true",
"TRACE_SEMANTIC": "true",
"TRACE_SYNTAX": "true",
"__comment1__": "Set LOGTOSTDER to 'true' to log on standard error",
"LOGTOSTDERR": "true",
"__comment2__": "Display log upto INFO level",
"STDERRTHRESHOLD": "INFO",
"__comment3__": "Display log upto INFO level 8",
"VERBOSITY": "8",
"SKIP_VALIDATION": "false",
"SKIP_SEMANTIC_VALIDATION": "false"
}
3. Below environment variables need to be set at the end in /usr/bin/rest-server.sh in mgmt-framework docker.

export CVL_DEBUG=1
export CVL_CFG_FILE=/usr/sbin/cvl_cfg.json

Note : CVL_CFG_FILE enviroment variable can point to other location also.

4. CVL Traces can be enabled both with restart and without mgmt-framework docker restart .

With Restart:
============
Restart mgmt-framework docker after which updated cvl_cfg.json file will be read.

Without Restart:
===============
Issue SIGUSR2 to rest process(kill -SIGUSR2 <pid of rest process inside docker> , to read changed cvl_cfg.json with logging enabled.

5. After following above steps, CVL traces can be seen in syslog file in host container at /var/log/syslog.

6. To disable CVL traces , disable the fields in cvl_cfg.json file and then perform same steps as in Step 4.


20 changes: 20 additions & 0 deletions cvl/conf/cvl_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"TRACE_CACHE": "false",
"TRACE_LIBYANG": "false",
"TRACE_YPARSER": "false",
"TRACE_CREATE": "false",
"TRACE_UPDATE": "false",
"TRACE_DELETE": "false",
"TRACE_SEMANTIC": "false",
"TRACE_SYNTAX": "false",
"__comment1__": "Log trace data when error occurs",
"TRACE_ONERROR": "true",
"__comment2__": "Set LOGTOSTDER to 'true' to log on standard error",
"LOGTOSTDERR": "false",
"__comment3__": "Display log upto INFO level",
"STDERRTHRESHOLD": "ERROR",
"__comment4__": "Display log upto INFO level 8",
"VERBOSITY": "0",
"SKIP_VALIDATION": "false",
"SKIP_SEMANTIC_VALIDATION": "false"
}
Loading