Skip to content

Correct way to create schema-mount? #2474

@paigeadelethompson

Description

@paigeadelethompson

Hey,

I’ve tried a bunch of ways to do this purely with yang APIs (not even sure if this will work):

#include <libyang/libyang.h>
#include <stdio.h>

int main() {
    struct ly_ctx *ctx = NULL;
    struct lyd_node *tree = NULL;
    const char *data = 
        "<network-instances xmlns=\"urn:ietf:params:xml:ns:yang:ietf-network-instance\">"
        "  <network-instance>"
        "    <name>VRF1</name>"
        "    <instances>"
        "      <instance>"
        "        <name>default</name>"
        "        <type>ni-type:l3vrf</type>"
        "        <!-- Schema Mount Point Here -->"
        "        <routing xmlns=\"urn:ietf:params:xml:ns:yang:ietf-routing\">"
        "          <router-id>1.1.1.1</router-id>"
        "        </routing>"
        "      </instance>"
        "    </instances>"
        "  </network-instance>"
        "</network-instances>";

    // 1. Initialize context
    ly_ctx_new(NULL, 0, &ctx);

    // 2. Load ietf-network-instance and required modules
    ly_ctx_load_module(ctx, "ietf-network-instance", "2019-01-21", NULL);
    // Note: You must also load ietf-routing and ietf-yang-schema-mount

    // 3. Parse data
    if (lyd_parse_xml_mem(ctx, data, LYD_OPT_CONFIG, &tree)) {
        fprintf(stderr, "Error parsing data\n");
        ly_ctx_destroy(ctx);
        return 1;
    }

    printf("Successfully parsed network instance with mounted routing data.\n");

    // Clean up
    lyd_free_all(tree);
    ly_ctx_destroy(ctx);
    return 0;
}

And I’ve had a little luck with the extension callback but I’ve just never been able to figure it out. Moreover I just want to mount ietf-routing, is there an example somewhere ? I guess I don’t mind creating it from a string but it feels a little bit like I’m working against the system too. I also don’t get why they decided to make ietf-routing a mount, but not interfaces? Rather interfaces have a field ‘bind-ni-name’ anyway if someone could just give me a very simple example of how to create a network instance with a ietf-routing payload that will validate I would be very grateful, or point me in the right direction. I imagine if I try to build it by hand again (lost it) maybe I could figure it out but I’m wondering it the point is I can’t or I shouldn’t try for some reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:questionIssue is actually a question.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions