Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a common yang-library code #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CC:=$(CROSS_COMPILE)gcc
LD:=$(CROSS_COMPILE)ld
PKG_CONFIG ?= pkg-config
APTERYX_PATH ?=
PYANG = pyang --plugindir . -p ./models

ABI_VERSION=1.4
CFLAGS := $(CFLAGS) -g -O2
Expand All @@ -45,9 +46,9 @@ endif
EXTRA_CFLAGS += -DHAVE_LIBXML2 $(shell $(PKG_CONFIG) --cflags libxml-2.0 jansson)
EXTRA_LDFLAGS += $(shell $(PKG_CONFIG) --libs libxml-2.0 jansson)

all: libapteryx-xml.so libapteryx-schema.so apteryx/xml.so
all: libapteryx-xml.so libapteryx-schema.so apteryx/xml.so models/ietf-yang-library.xml

libapteryx-schema.so.$(ABI_VERSION): schema.o sch_xpath.o sch_conditions.o
libapteryx-schema.so.$(ABI_VERSION): schema.o sch_xpath.o sch_conditions.o sch_yang_library.o
@echo "Creating library "$@""
$(Q)$(CC) -shared $(LDFLAGS) -o $@ $^ $(EXTRA_LDFLAGS) -Wl,-soname,$@

Expand Down Expand Up @@ -87,6 +88,9 @@ TEST_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(TEST_ARGS):;@:)
endif

models/ietf-yang-library.xml: models/ietf-yang-library.yang
$(PYANG) -f apteryx-xml $< > $@

test: unittest
@echo "Running XML unit tests"
$(Q)$(call apteryxd,unittest -u$(TEST_ARGS))
Expand All @@ -95,6 +99,7 @@ test: unittest
install: all
$(Q)install -d $(DESTDIR)/etc/apteryx/schema
$(Q)install -D -m 0644 apteryx.xsd $(DESTDIR)/etc/apteryx/schema/
$(Q)install -D -m 0644 models/ietf-yang-library.xml $(DESTDIR)/etc/apteryx/schema/
$(Q)install -d $(DESTDIR)/$(PREFIX)/$(LIBDIR)
$(Q)install -D libapteryx-xml.so.$(ABI_VERSION) $(DESTDIR)/$(PREFIX)/$(LIBDIR)/
$(Q)install -D libapteryx-schema.so.$(ABI_VERSION) $(DESTDIR)/$(PREFIX)/$(LIBDIR)/
Expand All @@ -107,6 +112,6 @@ install: all

clean:
@echo "Cleaning..."
@rm -fr libapteryx-schema.so* libapteryx-xml.so* apteryx/xml.so unittest *.o
@rm -fr libapteryx-schema.so* libapteryx-xml.so* apteryx/xml.so unittest *.o models/ietf-yang-library.xml

.PHONY: all clean
23 changes: 23 additions & 0 deletions apteryx-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ typedef struct _sch_loaded_model
char *version;
char *features;
char *deviations;
char *filename;
bool loaded;
} sch_loaded_model;

/* Schema */
Expand All @@ -54,6 +56,7 @@ typedef void sch_ns;
sch_instance *sch_load (const char *path);
sch_instance *sch_load_with_model_list_filename (const char *path,
const char *model_list_filename);
sch_instance *sch_load_model_list_yang_library (const char *path);
void sch_free (sch_instance * instance);
sch_node *sch_lookup (sch_instance * instance, const char *path);
sch_node *sch_lookup_with_ns (sch_instance * instance, sch_ns *ns, const char *path);
Expand Down Expand Up @@ -138,6 +141,26 @@ void sch_check_condition (sch_node *node, GNode *root, int flags, char **path, c
bool sch_apply_conditions (sch_instance * instance, sch_node * schema, GNode *node, int flags);
bool sch_trim_tree_by_depth (sch_instance *instance, sch_node *schema, GNode *node, int flags, int rdepth);

#define YANG_LIBRARY_CONTROL_PATH "/yang-library-control"
#define YANG_LIBRARY_CONTROL_STATE YANG_LIBRARY_CONTROL_PATH "/state"
#define YANG_LIBRARY_MOD_SET_COMMON_MOD "/yang-library/module-set/common/module"

/* A server-generated identifier of the contents of the '/yang-library' tree. */
#define YANG_LIBRARY_CONTENT_ID "/yang-library/content-id"

typedef enum
{
YANG_LIBRARY_S_NONE = 0, /* Zero state */
YANG_LIBRARY_S_CREATED = 1, /* yang-library databse entry created */
YANG_LIBRARY_S_LOADING = 2, /* yang-library models being loaded */
YANG_LIBRARY_S_READY = 3, /* yang-library models fully loaded */
} yang_library_state;

void yang_library_control_set_state (int state);
volatile int yang_library_control_get_state (void);
void yang_library_add_model_information (sch_loaded_model *loaded);
void yang_library_create (sch_instance *schema);

#ifdef APTERYX_XML_JSON
#include <jansson.h>
json_t *sch_gnode_to_json (sch_instance * instance, sch_node * schema, GNode * node, int flags);
Expand Down
117 changes: 117 additions & 0 deletions models/ietf-datastores.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
module ietf-datastores {
yang-version 1.1;
namespace "urn:ietf:params:xml:ns:yang:ietf-datastores";
prefix ds;

organization
"IETF Network Modeling (NETMOD) Working Group";

contact
"WG Web: <https://datatracker.ietf.org/wg/netmod/>

WG List: <mailto:[email protected]>

Author: Martin Bjorklund
<mailto:[email protected]>

Author: Juergen Schoenwaelder
<mailto:[email protected]>

Author: Phil Shafer
<mailto:[email protected]>

Author: Kent Watsen
<mailto:[email protected]>

Author: Rob Wilton
<[email protected]>";

description
"This YANG module defines a set of identities for identifying
datastores.

Copyright (c) 2018 IETF Trust and the persons identified as
authors of the code. All rights reserved.

Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject to
the license terms contained in, the Simplified BSD License set
forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(https://trustee.ietf.org/license-info).

This version of this YANG module is part of RFC 8342
(https://www.rfc-editor.org/info/rfc8342); see the RFC itself
for full legal notices.";

revision 2018-02-14 {
description
"Initial revision.";
reference
"RFC 8342: Network Management Datastore Architecture (NMDA)";
}

/*
* Identities
*/

identity datastore {
description
"Abstract base identity for datastore identities.";
}

identity conventional {
base datastore;
description
"Abstract base identity for conventional configuration
datastores.";
}

identity running {
base conventional;
description
"The running configuration datastore.";
}

identity candidate {
base conventional;
description
"The candidate configuration datastore.";
}

identity startup {
base conventional;
description
"The startup configuration datastore.";
}

identity intended {
base conventional;
description
"The intended configuration datastore.";
}

identity dynamic {
base datastore;
description
"Abstract base identity for dynamic configuration datastores.";
}

identity operational {
base datastore;
description
"The operational state datastore.";
}

/*
* Type definitions
*/

typedef datastore-ref {
type identityref {
base datastore;
}
description
"A datastore identity reference.";
}
}
Loading
Loading