cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2433
Views
1
Helpful
10
Replies

converting my yang file into cpp

hariharan.a
Level 1
Level 1

Hi,

If  I were to write a yang file (with any dependent yang modules in say ietf/cisco-ios-xr, etc) and convert that into a cpp file using ydk-cpp, could you please let me know the steps involved ? This will help me to understand ydk-cpp framework better in YANG / CPP usage.

Thanks,

Hari

10 Replies 10

einarnn
Cisco Employee
Cisco Employee

Hari,

You should be able to refer to the instructions at:

https://github.com/CiscoDevNet/ydk-gen

The README.md file for that project tries to take a developer through the steps required to get to generating code from models. Please feel free to give us feedback on issues with the instructions.

We focus on Linux and MacOS environments, so recommend that you don’t try to work on Windows for now.

Cheers,

Einar

Thanks Einar. I am able to make some progress. Stuck in "Thrid Step". Getting Emit Error "Illegal path". I validated the yang file separately with yang validator and its fine.

Error:

-------

(py2)[root@ODLserver ydk-gen]# ./generate.py --cpp --bundle profiles/bundles/pd_0_1_1.json

Processing 1 of 1 /root/ydk-gen/gen-api/.cache/models/pd@0.1.1/pd@2017-10-17.yang

Traceback (most recent call last):

  File "./generate.py", line 369, in <module>

    options.one_class_per_module).generate(options.bundle))

  File "/root/ydk-gen/ydkgen/__init__.py", line 91, in generate

    return self._generate_bundle(description_file)

  File "/root/ydk-gen/ydkgen/__init__.py", line 126, in _generate_bundle

    generated_files = self._print_packages(packages, gen_api_root, curr_bundle)

  File "/root/ydk-gen/ydkgen/__init__.py", line 183, in _print_packages

    generated_files = ydk_printer.emit(bundle_packages, classes_per_source_file)

  File "/root/ydk-gen/ydkgen/printer/language_bindings_printer.py", line 64, in emit

    return self.print_files()

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 50, in print_files

    self._print_module(index, package, size)

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 68, in _print_module

    self._print_cpp_rst_doc(package)

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 132, in _print_cpp_rst_doc

    _walk_n_print(package, self.ydk_doc_dir)

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 130, in _walk_n_print

    _walk_n_print(owned_element, p)

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 126, in _walk_n_print

    _EmitArgs(self.ypy_ctx, named_element, self.identity_subclasses))

  File "/root/ydk-gen/ydkgen/printer/language_bindings_printer.py", line 97, in print_file

    emit_func(emit_args.ctx, emit_args.package, emit_args.extra_args)

  File "/root/ydk-gen/ydkgen/printer/cpp/cpp_bindings_printer.py", line 185, in emit_cpp_doc

    DocPrinter(ctx, 'cpp').print_module_documentation(named_element, identity_subclasses)

  File "/root/ydk-gen/ydkgen/printer/doc/doc_printer.py", line 51, in print_module_documentation

    self._print_class_rst(named_element)

  File "/root/ydk-gen/ydkgen/printer/doc/doc_printer.py", line 105, in _print_class_rst

    clazz, self.lang, identity_subclasses=self.identity_subclasses))

  File "/root/ydk-gen/ydkgen/printer/meta_data_util.py", line 85, in get_class_docstring

    identity_subclasses=id_subclasses)

  File "/root/ydk-gen/ydkgen/printer/meta_data_util.py", line 383, in get_meta_info_data

    raise EmitError('Illegal path')

pyang.error.EmitError

bundle file:

--------------

{

        "name" : "pd",

        "version" : "0.1.1",

        "ydk_version" : "0.6.1",

        "author" : "Packet Design",

        "copyright" : "Packet Design",

        "description" : "YDK bundle for Packet Design models",

        "long_description" : "This YANG Development Kit (YDK) bundle provides APIs for Packet Design YANG Models",

        "models" : {

                "description" : "Each element of the list has details of source files",

                "file" : [

                        "./profiles/bundles/yang/pd/pd@2017-10-17.yang"

                ]

        }

}

pd@2017-10-17.yang

------------------

module pd {

    yang-version "1";

    namespace "urn:ietf:params:xml:ns:yang:pd";

    prefix "pd";

    organization "Packet Design";

    contact "email: hari@packetdesign.com";

    description "This module defines YANG data model

    for service provisioning in Packet Designs

    SDN Platform"

    revision "2017-10-17" {

description "Initial revision";

reference "todo";

    }

    container service {

description "A Packet Design SDN Service";

leaf name {

    type string;

    description "Name of the service";

}

leaf type {

    type enumeration {

enum PLATINUM {

    description "Platinum Service";

}

enum GOLD {

    description "Gold Service";

}

enum SILVER {

    description "Silver Service";

}

    }

    description "Gold, Platinum, Silver";

}

    }

}

If I remove the leaf type enumeration, its able to generate code.

Hi Hari,

I am not able to reproduce this error.

Please see below the git commit of ydk-gen I am at:

~ > git log -1

commit 71a2d6b2f8719379985e65478fc0e44f01e8c6a3

Author: Abhi Keshav <abhirame@cisco.com>

Date:   Sat Oct 7 13:51:30 2017 -0700

Please see below the command line output:

~ > ./generate.py --bundle profiles/bundles/pg.json --cpp -v

YDKGEN_HOME not set. Assuming current directory is working directory.

Resolving file tmp6niquh20.bundle --> /Users/abhirame/Cisco/001/ydk-gen/gen-api/.cache/bundles

Resolving file pd@2017-10-17.yang --> /Users/abhirame/Cisco/001/ydk-gen/gen-api/.cache/models/pd@0.1.1

Parsing file /Users/abhirame/Cisco/001/ydk-gen/gen-api/.cache/models/pd@0.1.1/pd@2017-10-17.yang. Module name: pd. Revision: 2017-10-17

Copying /Users/abhirame/Cisco/001/ydk-gen/sdk/cpp/packages to /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle

Created models archive: /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle/pd@0.1.1.tar.gz

Processing 1 of 1 /Users/abhirame/Cisco/001/ydk-gen/gen-api/.cache/models/pd@0.1.1/pd@2017-10-17.yang

Time taken for code/doc generation:  0 seconds

Creating cpp package...

-- The C compiler identification is AppleClang 8.0.0.8000042

-- The CXX compiler identification is AppleClang 8.0.0.8000042

-- Check for working C compiler: /usr/bin/clang

-- Check for working C compiler: /usr/bin/clang -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: /usr/bin/clang++

-- Check for working CXX compiler: /usr/bin/clang++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

CMake System: MacOS

-- Found Doxygen: /usr/local/bin/doxygen (found version "1.8.13")

-- Configuring done

-- Generating done

-- Build files have been written to: /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle/build

Successfully generated code at /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle.

To build and install, run "make && [sudo] make install" from /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle/build

=================================================

Successfully generated C++ YDK at /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle

Please read /Users/abhirame/Cisco/001/ydk-gen/gen-api/cpp/pd-bundle/README.md for information on how to use YDK

Code generation and installation completed successfully!

Total time taken:  2 seconds



I am in the same version too. Let me try few more things ang get back.

[root@ODLserver ydk-gen]# git log -1

commit 71a2d6b2f8719379985e65478fc0e44f01e8c6a3

Author: Abhi Keshav <abhirame@cisco.com>

Date:   Sat Oct 7 13:51:30 2017 -0700

    Fixes #581 (#594)

   

     * Add additional cpp samples

     * If leaf has same name as parent in path::DataNode, do not skip it

Didnt work. Same error. I also tried with this simple yang model. Looks like ydk doesnt like the enumeration type.

module pd {

    yang-version "1";

    namespace "urn:ietf:params:xml:ns:yang:pd";

    prefix "pd";

    organization "Packet Design";

    contact "email: hari@packetdesign.com";

    description "This module defines YANG data model

    for service provisioning in Packet Designs

    SDN Platform";

    revision "2017-10-17" {

        description "Initial revision";

        reference "todo";

    }

    container service {

        description "A Packet Design SDN Service";

        leaf serviceType {

            type enumeration {

               enum PLATINUM;

            }

        }

    }

}

Strange. I still am not able to reproduce your issue. I tried the exact same command you are trying.

Can you try to clone ydk-gen in a fresh directory and try it out? Perhaps could be some issue with your directory?

Tried the same in a new directory. Still the same issue. Would you mind doing a webex ?

- Hari

Fixed it. I need to do "pip upgrade" inside my python virtualenv to get the correct pip version.

(py2)[root@ODLserver build]# pip --version

pip 9.0.1 from /root/.virtualenvs/py2/lib/python2.7/site-packages (python 2.7)

Glad you were able to resolve it ☺