我正在尝试为YANG模块(ieee802-dot1q-bridge.yang)编写插件。 不幸的是,我在尝试正确设置订户方面遇到了困难,因为我必须正确地合并名称空间。
这是我的代码:
#include <stdio.h>
#include <syslog.h>
#include "sysrepo.h"
#include "sysrepo/values.h"
#include "sysrepo/plugins.h"
static int
module_change_cb(sr_session_ctx_t *session, const char *module_name, sr_notif_event_t event, void *private_ctx)
{
SRP_LOG_DBG_MSG("turing-machine configuration has changed.");
printf("in module change cb\n");
return SR_ERR_OK;
}
static int
bridge_state_cb(const char *xpath, sr_val_t **values, size_t *values_cnt,
uint64_t request_id, const char *original_xpath, void *private_ctx)
{
return 1;
sr_val_t *vals;
int rc;
printf("setting a new value\n");
sr_new_values(1, &vals);
if (SR_ERR_OK != rc) {
return rc;
}
sr_val_set_xpath(&vals[0], "/ieee802-dot1q-bridge/bridges/bridge/name");
vals[0].type = SR_STRING_T;
vals[0].data.string_val = "Test";
*values = vals;
*values_cnt = 1;
return SR_ERR_OK;
}
int
sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx)
{
printf("initializinig:\n");
sr_subscription_ctx_t *subscription = NULL;
int rc = SR_ERR_OK;
printf("try first subscription\n");
rc = sr_module_change_subscribe(session, "ieee802-dot1q-bridge:bridges", module_change_cb, NULL,
0, SR_SUBSCR_DEFAULT, &subscription);
if (SR_ERR_OK != rc) {
goto error;
} else {
printf("subscription ok!\n");
}
printf("Trying state data subscription...\n");
rc = sr_dp_get_items_subscribe(session, "/ieee802-dot1q-bridge:bridges", bridge_state_cb, NULL,
SR_SUBSCR_DEFAULT, &subscription);
if (rc != SR_ERR_OK) {
goto error;
} else {
printf("state data subscription ok!\n");
}
//printf("Erfolgreiche initialisierung");
SRP_LOG_DBG_MSG("plugin initialized successfully");
/* set subscription as our private context */
*private_ctx = subscription;
return SR_ERR_OK;
error:
SRP_LOG_ERR("ieee802-dot1q-bridge plugin initialization failed: %s", sr_strerror(rc));
sr_unsubscribe(session, subscription);
return rc;
}
void
sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_ctx)
{
sr_unsubscribe(session, private_ctx);
SRP_LOG_DBG_MSG("bridge plugin cleanup finished.");
}
我包括了初始化和清除所需的功能。错误似乎是订户中的XPATH设置不正确。
sr_module_change_subscribe(session, "ieee802-dot1q-bridge:bridges", module_change_cb, NULL,
0, SR_SUBSCR_DEFAULT, &subscription);
我认为我需要以某种方式包含名称空间,该名称空间称为urn:ieee:std:802.1Q:yang:ieee802-dot1q-bridge。不幸的是,我没有在sysrepo文档中找到方法。我在ncclient中寻找类似名称空间dict的东西,但没有找到任何东西。
如何正确设置名称空间? 有没有更简单的方法为sysrepo提供启动数据?我不想修改yang模型。