Skip to content
Open
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
93 changes: 93 additions & 0 deletions models/yang/annotations/openconfig-system-annot.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
module openconfig-system-annot {
yang-version "1";

namespace "http://openconfig.net/yang/system-annot";
prefix "oc-sys-annot";

import sonic-extensions { prefix sonic-ext; }
import openconfig-system { prefix oc-sys; }

organization
"SONiC";

contact
"SONiC";

description
"OpenConfig System YANG annotations for SONiC.
Maps OpenConfig System model (including AAA) to SONiC native configuration.";

revision 2024-01-01 {
description
"Initial revision.";
}

deviation /oc-sys:system/oc-sys:aaa {
deviate add {
sonic-ext:subtree-transformer "aaa_subtree_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authentication {
deviate add {
sonic-ext:table-name "AAA";
sonic-ext:key-transformer "aaa_authentication_key_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:config/oc-sys:authentication-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_auth_method_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authentication/oc-sys:state/oc-sys:authentication-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_auth_method_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authorization {
deviate add {
sonic-ext:table-name "AAA";
sonic-ext:key-transformer "aaa_authorization_key_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authorization/oc-sys:config/oc-sys:authorization-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_authz_method_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:authorization/oc-sys:state/oc-sys:authorization-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_authz_method_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:accounting {
deviate add {
sonic-ext:table-name "AAA";
sonic-ext:key-transformer "aaa_accounting_key_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:accounting/oc-sys:config/oc-sys:accounting-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_acct_method_xfmr";
}
}

deviation /oc-sys:system/oc-sys:aaa/oc-sys:accounting/oc-sys:state/oc-sys:accounting-method {
deviate add {
sonic-ext:field-name "login";
sonic-ext:field-transformer "aaa_acct_method_xfmr";
}
}
}
2 changes: 1 addition & 1 deletion translib/common_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var cmnAppInfo = appInfo{appType: reflect.TypeOf(CommonApp{}),

func init() {

register_model_path := []string{"/sonic-", "*"} // register YANG model path(s) to be supported via common app
register_model_path := []string{"/sonic-", "/openconfig-system:system/aaa", "*"} // register YANG model path(s) to be supported via common app
for _, mdl_pth := range register_model_path {
err := register(mdl_pth, &cmnAppInfo)

Expand Down
86 changes: 86 additions & 0 deletions translib/common_app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2024 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. //
// //
////////////////////////////////////////////////////////////////////////////////

package translib

import (
"testing"
)

// TestOpenConfigAaaPathRouting validates that OpenConfig AAA paths
// are routed to an app module through the getAppModuleInfo function.
func TestOpenConfigAaaPathRouting(t *testing.T) {
tests := []struct {
name string
path string
}{
{"AAA root path", "/openconfig-system:system/aaa"},
{"AAA authentication path", "/openconfig-system:system/aaa/authentication"},
{"AAA authentication config path", "/openconfig-system:system/aaa/authentication/config"},
{"AAA authorization path", "/openconfig-system:system/aaa/authorization"},
{"AAA accounting path", "/openconfig-system:system/aaa/accounting"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
appInfo, err := getAppModuleInfo(tt.path)
if err != nil {
t.Errorf("getAppModuleInfo(%s) returned error: %v", tt.path, err)
return
}
if appInfo == nil {
t.Errorf("getAppModuleInfo(%s) returned nil appInfo", tt.path)
return
}
// Verify that an app module was found for this path
if appInfo.appType == nil {
t.Errorf("getAppModuleInfo(%s) returned appInfo with nil appType", tt.path)
}
})
}
}

// TestSonicPathRouting validates that SONiC paths are routed to an app module.
func TestSonicPathRouting(t *testing.T) {
tests := []struct {
name string
path string
}{
{"Sonic AAA path", "/sonic-system-aaa:sonic-system-aaa/AAA"},
{"Sonic port path", "/sonic-port:sonic-port/PORT"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
appInfo, err := getAppModuleInfo(tt.path)
if err != nil {
t.Errorf("getAppModuleInfo(%s) returned error: %v", tt.path, err)
return
}
if appInfo == nil {
t.Errorf("getAppModuleInfo(%s) returned nil appInfo", tt.path)
return
}
// Verify that an app module was found for this path
if appInfo.appType == nil {
t.Errorf("getAppModuleInfo(%s) returned appInfo with nil appType", tt.path)
}
})
}
}
Loading