Have questions? Stuck? Please check our FAQ for some common questions and answers.

This information needs to be updated to reflect move from Buck to Bazel.

The information on this page is based on the following thread: https://groups.google.com/a/onosproject.org/d/topic/onos-dev/ZkfN8_61EJU/discussion


1. Add a new directory in $ONOS_ROOT/models and put YANG files in it.

ubuntu@miyata ~/onos> find models/yang-sample/ -type f
models/yang-sample/src/main/yang/ietf-yang-types.yang
...(some YANG files)...
models/yang-sample/BUCK
models/yang-sample/pom.xml

ubuntu@miyata ~/onos> cat models/yang-sample/BUCK
yang_model(
    app_name = 'org.onosproject.models.yang-sample',
    title = 'YANG Sample Model',
)


2. Add a new directory in apps directory.  Src directory shouldn't be empty. I added a dummy class in src/main/java here.

ubuntu@miyata ~/onos> find apps/yang-sample/ -type f
apps/yang-sample/src/main/java/org/onosproject/sample/DeviceInfo.java
apps/yang-sample/BUCK

ubuntu@miyata ~/onos> cat apps/yang-sample/BUCK
COMPILE_DEPS = [
    '//lib:CORE_DEPS',
    '//models/yang-sample:onos-models-yang-sample',
    '//lib:onos-yang-model',
]

TEST_DEPS = [
    '//lib:TEST_ADAPTERS',
    '//utils/osgi:onlab-osgi-tests',
]

APPS = [
    'org.onosproject.models.yang-sample',
]

osgi_jar_with_tests(
    deps = COMPILE_DEPS,
    test_deps = TEST_DEPS,
)

onos_app(
    app_name = 'org.onosproject.yang-sample',
    title = 'YANG Sample App',
    category = 'YANG',
    url = 'http://onosproject.org',
    description = 'YANG Sample Application',
    required_apps = APPS,
)



3. Add entries in $ONOS_ROOT/modules.def. The target name will be automatically generated by scripts in $ONOS_ROOT/bucklets/.  '/' in the file path is replaced with '-' and '-oar' is added as suffix. (onos/apps/yang-sample -> onos-apps-yang-sample-oar and onos/models/yang-sample -> onos-models-yang-sample-oar).

ubuntu@miyata ~/onos> git diff
diff --git a/modules.defs b/modules.defs
index df4530a..79183cc 100644
--- a/modules.defs
+++ b/modules.defs
@@ -202,12 +202,14 @@ ONOS_APPS = [
     '//apps/network-troubleshoot:onos-apps-network-troubleshoot-oar',
     '//apps/l3vpn:onos-apps-l3vpn-oar',
     '//apps/openroadm:onos-apps-openroadm-oar',
+    '//apps/yang-sample:onos-apps-yang-sample-oar',
 ]

 MODELS = [
     '//models/huawei:onos-models-huawei-oar',
     '//models/openroadm:onos-models-openroadm-oar',
     '//models/l3vpn:onos-models-l3vpn-oar',
+    '//models/yang-sample:onos-models-yang-sample-oar',
 ]

 APP_JARS = [



4. Use built-in buck to build. When we had some errors in build process in try & error, "./bin/buck clean" often solved the cache problem.

ubuntu@miyata ~/onos> ./bin/buck build onos
[-] PROCESSING BUCK FILES...FINISHED 0.1s 🐇
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.4s [100%] (1/1 JOBS, 0 UPDATED, 0 [0.0%] CACHE MISS)

Compiling large YANG files

When compiling large YANG files (>1MB), you may need to increase memory used by JVM.

To specify maximum memoru JVM can use during YANG compilation, add memory pool option like -Xmx4g to $ONOS_ROOT/.buckjavaargs.



5. Java codes were generated based on the YANG files.

ubuntu@miyata ~/onos> find buck-out/gen/models/yang-sample/onos-models-yang-sample-yang\#srcs__yang-gen/ -type f
...(some YANG files)...
buck-out/gen/models/yang-sample/onos-models-yang-sample-yang#srcs__yang-gen/org/onosproject/yang/gen/v1/ietfyangtypes/rev20130715/IetfYangTypes.java
buck-out/gen/models/yang-sample/onos-models-yang-sample-yang#srcs__yang-gen/org/onosproject/yang/gen/v1/ietfyangtypes/rev20130715/package-info.java
buck-out/gen/models/yang-sample/onos-models-yang-sample-yang#srcs__yang-gen/org/onosproject/yang/gen/v1/ietfyangtypes/rev20130715/ietfyangtypes/Timestamp.java
buck-out/gen/models/yang-sample/onos-models-yang-sample-yang#srcs__yang-gen/org/onosproject/yang/gen/v1/ietfyangtypes/rev20130715/ietfyangtypes/Gauge64.java
buck-out/gen/models/yang-sample/onos-models-yang-sample-yang#srcs__yang-gen/org/onosproject/yang/gen/v1/ietfyangtypes/rev20130715/ietfyangtypes/YangIdentifier.java
  • No labels