16
16
#include "mgmtd/mgmt.h"
17
17
#include "mgmtd/mgmt_memory.h"
18
18
#include "mgmtd/mgmt_txn.h"
19
+ #include "libyang/libyang.h"
19
20
20
21
#define __dbg (fmt , ...) \
21
22
DEBUGD(&mgmt_debug_txn, "TXN: %s: " fmt, __func__, ##__VA_ARGS__)
@@ -945,10 +946,112 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
945
946
return 0 ;
946
947
}
947
948
949
+
950
+ static void mgmt_print_nb_config_cbs (const char * prefix , struct nb_config_cbs * cfg_chgs )
951
+ {
952
+ struct nb_config_cb * cb , * nxt ;
953
+ struct nb_config_change * chg ;
954
+ char * xpath ;
955
+
956
+ if (!cfg_chgs ) {
957
+ __dbg ("%s: nb_config_cbs is NULL" , prefix );
958
+ return ;
959
+ }
960
+
961
+ __dbg ("%s: nb_config_cbs structure: %p" , prefix , cfg_chgs );
962
+
963
+ if (RB_EMPTY (nb_config_cbs , cfg_chgs )) {
964
+ __dbg ("%s: nb_config_cbs is empty" , prefix );
965
+ return ;
966
+ }
967
+
968
+ RB_FOREACH_SAFE (cb , nb_config_cbs , cfg_chgs , nxt ) {
969
+ chg = (struct nb_config_change * )cb ;
970
+
971
+ __dbg ("%s: Change operation: %d" , prefix , chg -> cb .operation );
972
+ __dbg ("%s: Change nb_node: %p" , prefix , chg -> cb .nb_node );
973
+ if (chg -> cb .nb_node ) {
974
+ __dbg ("%s: Change nb_node schema: %s" , prefix , chg -> cb .nb_node -> snode -> name );
975
+ __dbg ("%s: Change nb_node module: %s" , prefix , chg -> cb .nb_node -> snode -> module -> name );
976
+ }
977
+
978
+ __dbg ("%s: Change dnode: %p" , prefix , chg -> cb .dnode );
979
+ if (chg -> cb .dnode ) {
980
+ __dbg ("%s: Change dnode schema: %s" , prefix , chg -> cb .dnode -> schema -> name );
981
+ __dbg ("%s: Change dnode module: %s" , prefix , chg -> cb .dnode -> schema -> module -> name );
982
+ __dbg ("%s: Change dnode type: %d" , prefix , chg -> cb .dnode -> schema -> nodetype );
983
+
984
+ xpath = lyd_path (chg -> cb .dnode , LYD_PATH_STD , NULL , 0 );
985
+ if (xpath ) {
986
+ __dbg ("%s: Change dnode xpath: %s" , prefix , xpath );
987
+ if (chg -> cb .dnode -> schema -> nodetype & LYD_NODE_TERM ) {
988
+ const char * value = lyd_get_value (chg -> cb .dnode );
989
+ __dbg ("%s: Change dnode value: %s" , prefix , value ? value : "NULL" );
990
+ }
991
+ free (xpath );
992
+ }
993
+ }
994
+ }
995
+ }
996
+
997
+ static void mgmt_print_nb_config (const char * prefix , struct nb_config * nb_config )
998
+ {
999
+ struct lyd_node * dnode ;
1000
+ struct lyd_node * root , * child ;
1001
+ const char * value ;
1002
+ char * xpath ;
1003
+
1004
+ if (!nb_config ) {
1005
+ __dbg ("%s: nb_config is NULL" , prefix );
1006
+ return ;
1007
+ }
1008
+
1009
+ __dbg ("%s: nb_config structure: %p" , prefix , nb_config );
1010
+ __dbg ("%s: nb_config dnode: %p" , prefix , nb_config -> dnode );
1011
+
1012
+ if (!nb_config -> dnode ) {
1013
+ __dbg ("%s: nb_config dnode is NULL" , prefix );
1014
+ return ;
1015
+ }
1016
+
1017
+ __dbg ("%s: nb_config dnode schema: %s" , prefix , nb_config -> dnode -> schema -> name );
1018
+ __dbg ("%s: nb_config dnode module: %s" , prefix , nb_config -> dnode -> schema -> module -> name );
1019
+ __dbg ("%s: nb_config dnode type: %d" , prefix , nb_config -> dnode -> schema -> nodetype );
1020
+
1021
+ /* Print the root node */
1022
+ xpath = lyd_path (nb_config -> dnode , LYD_PATH_STD , NULL , 0 );
1023
+ if (xpath ) {
1024
+ __dbg ("%s: Root node xpath: %s" , prefix , xpath );
1025
+ free (xpath );
1026
+ }
1027
+
1028
+ /* Print all child nodes */
1029
+ LY_LIST_FOR (nb_config -> dnode , root ) {
1030
+ LYD_TREE_DFS_BEGIN (root , child ) {
1031
+ xpath = lyd_path (child , LYD_PATH_STD , NULL , 0 );
1032
+ if (xpath ) {
1033
+ __dbg ("%s: Child node %p xpath: %s" , prefix , child , xpath );
1034
+ //__dbg("%s: Child node schema: %s", prefix, child->schema->name);
1035
+ //__dbg("%s: Child node module: %s", prefix, child->schema->module->name);
1036
+ //__dbg("%s: Child node type: %d", prefix, child->schema->nodetype);
1037
+
1038
+ if (child -> schema -> nodetype & LYD_NODE_TERM ) {
1039
+ value = lyd_get_value (child );
1040
+ __dbg ("%s: Child node value: %s" , prefix , value ? value : "NULL" );
1041
+ }
1042
+
1043
+ free (xpath );
1044
+ }
1045
+ LYD_TREE_DFS_END (root , child );
1046
+ }
1047
+ }
1048
+ }
1049
+
1050
+ extern struct lyd_node * rm_set_src_node ;
948
1051
static int mgmt_txn_prepare_config (struct mgmt_txn_ctx * txn )
949
1052
{
950
1053
struct nb_context nb_ctx ;
951
- struct nb_config * nb_config ;
1054
+ struct nb_config * nb_config , * dst_nb_config ;
952
1055
struct nb_config_cbs changes ;
953
1056
struct nb_config_cbs * cfg_chgs = NULL ;
954
1057
int ret ;
@@ -1013,6 +1116,17 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
1013
1116
goto mgmt_txn_prepare_config_done ;
1014
1117
}
1015
1118
1119
+ if (rm_set_src_node ) {
1120
+ char * xpath = lyd_path (rm_set_src_node , LYD_PATH_STD , NULL , 0 );
1121
+ __dbg ("frr_debug_sonic: dnode %p, xpath %s" , rm_set_src_node , xpath );
1122
+ __dbg ("frr_debug_sonic: node schema: %s" , rm_set_src_node -> schema -> name );
1123
+ __dbg ("frr_debug_sonic: node module: %s" , rm_set_src_node -> schema -> module -> name );
1124
+ free (xpath );
1125
+ }
1126
+ else {
1127
+ __dbg ("frr_debug_sonic: rm_set_src_node is NULL" );
1128
+ }
1129
+ mgmt_print_nb_config ("frr_debug_sonic: SET_CFG src" , nb_config );
1016
1130
/*
1017
1131
* Validate YANG contents of the source DS and get the diff
1018
1132
* between source and destination DS contents.
@@ -1029,13 +1143,17 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
1029
1143
ret = -1 ;
1030
1144
goto mgmt_txn_prepare_config_done ;
1031
1145
}
1146
+ dst_nb_config = mgmt_ds_get_nb_config (
1147
+ txn -> commit_cfg_req -> req .commit_cfg .dst_ds_ctx );
1148
+ mgmt_print_nb_config ("frr_debug_sonic: SET_CFG dst" , dst_nb_config );
1032
1149
1033
1150
nb_config_diff (mgmt_ds_get_nb_config (txn -> commit_cfg_req -> req .commit_cfg
1034
1151
.dst_ds_ctx ),
1035
1152
nb_config , & changes );
1036
1153
cfg_chgs = & changes ;
1037
1154
del_cfg_chgs = true;
1038
1155
1156
+ mgmt_print_nb_config_cbs ("frr_debug_sonic: CONFIG_CHANGES" , cfg_chgs );
1039
1157
if (RB_EMPTY (nb_config_cbs , cfg_chgs )) {
1040
1158
/*
1041
1159
* This means there's no changes to commit whatsoever
0 commit comments