Subject: [netmod] bidirectional links

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 25 Jun 2010 17:29:34 +0200

Hi,

I am now trying to translate our old RELAX NG data model for a simple
router to YANG and I ran into this trouble:

It would be natural to have a module for interfaces and another for
packet filters. However, I need a link from an interface to a packet
filter chain, but also vice versa - an interface may be assigned a
particular packet filter chain and, on the other hand, a packet filter
rule may have an incoming interface as one of the match criteria.

YANG "leafref" type would be quite effective for this purpose, but the
problem is that I need to refer (via the 'path' statement) to a leaf in
the "packet-filters" module tree from the "interfaces" module and vice
versa, something like

module interfaces {
  ...
  prefix "if";
  import packet-filters {
    prefix pf;
  }
  ...
  leaf filter-in {
    type leafref {
      path "/pf:packet-filters/pf:packet-filter-chain/pf:name";
    }
  }
  ...
}

module packet-filters {  
  ...
  prefix "pf";
  import interfaces {
    prefix if;
  }
  ...
  leaf match-interface {
    type leafref {
      path "/if:interfaces/if:device/if:name";
    }
  }
  ...
}

This of course is not allowed in YANG because of the circular import,
but I see no other way how to get mutual access from one module to
another and back. Any ideas?

Lada 

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Andy Bierman <[email-masked]>
Date: Fri, 25 Jun 2010 11:46:41 -0700

> another and back. Any ideas?

SQL tools deal with this by mapping INT primary keys.
Elixir has a ManytoMany macro that may sort of apply here.

What if you had a 3rd module for the mapping relation?

module pfif-mapping {
   ...
   import interfaces { prefix if; }
   import packet-filters { prefix pf; }

   list pfif-map {
       key "filter-in match-interface";

       leaf filter-in {
          type leafref {

It is a bit clumsy to need a 3rd YANG module, but this happens a lot
in C code as well to avoid an #include loop.

> Lada 

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Sat, 26 Jun 2010 08:41:05 +0200

>            path "/if:interfaces/if:device/if:name";

This is possible but then I will need such ad hoc modules for links
between interfaces and individual routing protocols, route filters etc.,
so it can get a bit unwieldy.

> in C code as well to avoid an #include loop.

YANG import actually doesn't import anything, it's just a handle to the
stuff in the other module. I am thinking about possible consequences -
could it make any harm to allow the circular imports?

Lada
 
-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Martin Bjorklund <[email-masked]>
Date: Mon, 28 Jun 2010 08:30:14 +0200 (CEST)

Hi,

Ladislav Lhotka <[email-masked]> wrote:
> versa

One way to solve this is to let the packet-filter module augment the
interface module:

module interfaces {
  namespace "urn:example:if";
  prefix "if";

  container interfaces {
    list interface {
      key name;

      leaf name {
        type string;
      }
    }
  }
}

module packet-filters {  
  namespace "urn:example:pf";
  prefix "pf";

  import interfaces {
    prefix if;
  }

  augment "/if:interfaces/if:interface" {
    leaf filter-in {
      type leafref {
        path "/pf:packet-filters/pf:packet-filter-chain/pf:name";
      }
    }
  }
  
  container packet-filters {
    list packet-filter-chain {
      key name;

      leaf name {
        type string;
      }
 
      leaf match-interface {
        type leafref {
          path "/if:interfaces/if:interface/if:name";
        }
      }
    }
  }
}

/martin