cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1030
Views
0
Helpful
6
Replies

Setting case using econfd_mappi

simothuk
Cisco Employee
Cisco Employee

Hi,

 

How to set case for any yang model that has choice using econfd_mappi [Erlang]?

 

Yang Model:

 choice transport {
            mandatory true;
            case tcp {
              container tcp {
                leaf address {
                  type inet:host;
                 }
                leaf port {
                  type inet:port-number;
                  default "514";
                }
              }
            }
            case udp {
              container udp {
                leaf address {
                  type inet:host;
                }
                leaf port {
                  type inet:port-number;
                  default "514";
                }
              }
            }
Code snippet for setting case.
set_case(Tctx, Path, Choice, Case, None) ->
    M = ec_genet_server:tctx_maapi_sock(Tctx),
    TH = ec_genet_server:tctx_maapi_thandle(Tctx),
    ?LOGERR("HIT INSIDE SET CASE"),
    case econfd_maapi:set_case(M, TH, Path, Choice, Case) of
        {ok, RawVal} ->
            RawVal;
        {error, {1,_ErrMsg}} ->
            None;
        {error, ErrMsg} ->
            ?LOGERR("maapi:set_case() returned an error", ErrMsg),
            throw({error, {ec_genet, set_case, ErrMsg, Path, Choice}})
    end.

 

Following is the error.

2019-05-23::15:27:28.728 [error;''] ec_genet_server:279 LOG Caught exception in set_case mapping function

 CallmapError=error

 CallmapReason=undef

 Trace=[{econfd_maapi,set_case,

                      [{client,<0.9174.2>},

                       290,

                       [{<<"123">>},

                        destination,remote,'log-actions',

                        ['http://cisco/openroadm/syslog'|syslog]],

                       [transport],

                       tcp],

                      []},

        {ec_genet,set_case,5,[{file,"ec_genet.erl"},{line,187}]},

        {ec_genet_server,process_mapping_override_@,5,

                         [{file,"ec_genet_server.erl"},{line,434}]},

        {ec_genet_server,process_mapping_override,5,

                         [{file,"ec_genet_server.erl"},{line,395}]},

        {ec_genet_server,process_mapping_fexists,5,

                         [{file,"ec_genet_server.erl"},{line,357}]},

        {ec_genet_server,process_mapping_@,5,

                         [{file,"ec_genet_server.erl"},{line,332}]},

        {ec_genet_server,process_mapping,5,

                         [{file,"ec_genet_server.erl"},{line,330}]},

        {ec_genet_server,set_case,4,[{file,"ec_genet_server.erl"},{line,261}]},

        {econfd_daemon,proto_callback,5,

                       [{file,"econfd_daemon.erl"},{line,1501}]},

        {econfd_daemon,confd_fd_ready,2,

                       [{file,"econfd_daemon.erl"},{line,1102}]},

        {econfd_daemon,worker,1,[{file,"econfd_daemon.erl"},{line,1933}]},

        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]

6 Replies 6

Jan Lindblad
Cisco Employee
Cisco Employee

Hard to say what is going wrong based on only this information. Would be interesting to check your mapping function and that the path and choice path is correct. What YANG is outside choice transport?

We are using an intermediate model to access the data, called East model. 

 

Please find attached the complete yang model.

 

Following is the mapping code.

 

Here get_case is hardcoded with default UDP case.

 

% Returning UDP as default value, refer comment above the function.
[[transport],{Destname},'destination', 'remote', 'log-actions' ,?HL_SYS_ROOT] ->
    #mappings{get_case=fun(_,_,_,_) -> udp end, set_case=fun set_transport_syslog/5};

 

 

set_transport_syslog(Tctx,Path,Choice, Case,None) ->
    ?LOGERR("INSIDE TRANSPORT SET"),
    EastPath = get_east_model_path_syslog(Path),  
   Del = ec_genet:delete_if_exists(Tctx, EastPath),
   Cre = ec_genet:create_if_nonexist(Tctx, EastPath),
   ?LOGERR("BEFORE SETCASE"),
   ?LOGERR("CHOICE", Choice),
   ?LOGERR("CASE", Case),
   ec_genet:set_case(Tctx, EastPath, Choice, Case, None).
set_case(Tctx, Path, Choice, Case, None) ->
    M = ec_genet_server:tctx_maapi_sock(Tctx),
    TH = ec_genet_server:tctx_maapi_thandle(Tctx),
    ?LOGERR("HIT INSIDE SET CASE"),
    case econfd_maapi:set_case(M, TH, Path, Choice, Case) of
        {ok, RawVal} ->
            RawVal;
        {error, {1,_ErrMsg}} ->
            None;
        {error, ErrMsg} ->
            ?LOGERR("maapi:set_case() returned an error", ErrMsg),
            throw({error, {ec_genet, set_case, ErrMsg, Path, Choice}})
    end.

 

tbjurman
Cisco Employee
Cisco Employee

There's no econfd_maapi:set_case. Did you mean econfd_cdb:set_case?

I am referring to econf_mappi:set_case. How to set case if there is no econfd_mappi:set_case ? I can use econfd_mappi:get_case for getting the case value.

There is no need to do anything like explicit set_case. Most probably (depending on how your models look like) you can just ignore the set_case callback, because it will be followed by set_elem or the like for a node inside that case - if you handle that and if that node is mapped to the right case in your LL (native) data model, it should be enough.

For configuration data you don't need to explicitly set a case, it's done implicitly by NSO as soon as you create or set any data node under a case. NSO also makes sure that anything previously set under another case is deleted. The same reasoning goes with delete. When you delete everything under a case NSO will automatically make the default case (if any) the active one, or if there are no default case no case will be active.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: