Subject: [yang-doctors] defining constants in yang

From: Sudeepto Roy <[email-masked]>
Date: Thu, 2 Feb 2017 18:12:36 +0530

Hi,

I am trying to define "max" as a constant so that it can be reused
later for other definitions too.
I looked at an example from the site but i could not figure out where
"max" is defined. can you please help me with this example, as in how
to define a constant so that it can be reused later on.

http://www.yang-central.org/twiki/bin/view/Main/YangExamplesNetconfStateHtml

<leaf name="session-id">
    <type name="uint32">
        <range value="1..max"/>
    </type>
</leaf>

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Thu, 2 Feb 2017 14:05:39 +0100

Hi,

the "max" in your example is not a constant; it is a part of the range
statement and always refers to the maximum value of the type being
restricted. See section 9.2.4 of RFC 7950.

YANG does not have a concept of constants.

/js

On Thu, Feb 02, 2017 at 06:12:36PM +0530, Sudeepto Roy wrote:
> _______________________________________________
> yang-doctors mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/yang-doctors

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1 | 28759 Bremen | Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>

---

From: Sudeepto Roy <[email-masked]>
Date: Thu, 2 Feb 2017 18:51:10 +0530

Hi Juergen,

Thanks for the quick answer.

so my requirement is something like this.

#define   VARIABLE_MAX_SIZE  256
char variable[VARIABLE_MAX_SIZE +1];
<<<

Can you help me with the yang equivalent for this.

Regards,
Sudeepto Roy

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 2 Feb 2017 14:39:36 +0100

> On 2 Feb 2017, at 14:21, Sudeepto Roy <[email-masked]> wrote:
> 
> Hi Juergen,
> 

As Juergen wrote, YANG has no support for this. What you can do is to write the module in YIN syntax and define the constant as an XML entity.

Lada

--
Ladislav Lhotka, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67

---

From: Sudeepto Roy <[email-masked]>
Date: Thu, 02 Feb 2017 13:40:56 +0000

Thank you for the clarification.

On Thu 2 Feb, 2017, 7:09 PM Ladislav Lhotka, <[email-masked]> wrote:

> As Juergen wrote, YANG has no support for this. What you can do is to
> write the module in YIN syntax and define the constant as an XML entity.
>
> Lada
>
> >
> > Regards,
> > Sudeepto Roy
> >
> >
> >
> >

Regards,
Sudeepto Kumar Roy

sent from a phone

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Thu, 2 Feb 2017 15:04:21 +0100

> Can you help me with the yang equivalent for this.

This is likely not what you want, but in principle you can run the C
preprocessor (or even m4) to produce a YANG module with expanded
constants.

That said, there are no many places in YANG where constants really
make much sense. If you want to restrict the range of a type or the
number of list entries, there are ways to do this in YANG proper.
Perhaps it helps if you explain for what purpose you think you need a
named constant.

/js

---

From: Sudeepto Roy <[email-masked]>
Date: Thu, 2 Feb 2017 19:40:47 +0530

Hi,

an example can be:

#define INTERFACE_NAME_SIZE   256

char if_eth0[INERFACE_NAME_SIZE +1];
char if_eth1[INERFACE_NAME_SIZE +1];
char if_eth3[INERFACE_NAME_SIZE +1];

essentially by changing just the "INERFACE_NAME_SIZE", i can change
the size for the arrays used for the interface.

right now i would have to exactly know which interface name size needs
a change and accordingly i would need to touch each and every variable
affected.

Regards,
Sudeepto Roy

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Thu, 2 Feb 2017 15:23:42 +0100

Sudeepto,

I understand C coding but this is not what we are doing in YANG. If
you want to restrict the size of a string in YANG, you create a new
type and then you use this restricted type, for example:

typedef ifname {
  type string {
    length "0..256";
  }
}

Note that RFC 7223 does not put a restriction on interface names. If
your implementation has a restriction, the proper thing would be to
write a YANG deviation statement that declares your restriction in
YANG. (See RFC 7950 for details.)

If you have a decent toolset, then the tools would generate the C
definitions that you need out of the YANG definitions.

In short, writing YANG is not the same as writing C code. And it is
generally a good idea to generate C code out of YANG definitions
instead of trying to work the other way round.

/js

---

From: Sudeepto Roy <[email-masked]>
Date: Thu, 2 Feb 2017 21:06:26 +0530

Hi Juergen,

Thanks for your clarification and time on this. :)

Regards,
Sudeepto Roy