module frr-zebra-route-map {
  yang-version 1.1;
  namespace "http://frrouting.org/yang/zebra-route-map";
  prefix frr-zebra-route-map;

  import ietf-inet-types {
    prefix inet;
  }

  import frr-route-map {
    prefix frr-route-map;
  }

  import frr-route-types {
    prefix frr-route-types;
  }

  organization
    "Free Range Routing";
  contact
    "FRR Users List:       <mailto:frog@lists.frrouting.org>
     FRR Development List: <mailto:dev@lists.frrouting.org>";
  description
    "This module defines zebra route map settings";

  revision 2020-01-02 {
    description
      "Initial revision";
  }

  identity ipv4-prefix-length {
    base frr-route-map:rmap-match-type;
    description
      "Match IPv4 address prefix length";
  }

  identity ipv4-next-hop-prefix-length {
    base frr-route-map:rmap-match-type;
    description
      "Match IPv4 next-hop address prefix length";
  }

  identity ipv6-prefix-length {
    base frr-route-map:rmap-match-type;
    description
      "Match IPv6 address prefix length";
  }

  identity source-instance {
    base frr-route-map:rmap-match-type;
    description
      "Match the protocol's instance number";
  }

  identity source-protocol {
    base frr-route-map:rmap-match-type;
    description
      "Match protocol via which the route was learnt";
  }

  identity src-address {
    base frr-route-map:rmap-set-type;
    description
      "Set IPv4/IPv6 source address for route";
  }

  augment "/frr-route-map:lib"
    + "/frr-route-map:route-map"
    + "/frr-route-map:entry"
    + "/frr-route-map:match-condition"
    + "/frr-route-map:rmap-match-condition"
    + "/frr-route-map:match-condition" {
    case ipv4-prefix-length {
      when "derived-from-or-self(../frr-route-map:condition, 'frr-zebra-route-map:ipv4-prefix-length') or "
         + "derived-from-or-self(../frr-route-map:condition, 'frr-zebra-route-map:ipv4-next-hop-prefix-length')";
      leaf ipv4-prefix-length {
        type uint8 {
          range "0..32";
        }
      }
    }

    case ipv6-prefix-length {
      when "derived-from-or-self(../frr-route-map:condition, 'frr-zebra-route-map:ipv6-prefix-length')";
      leaf ipv6-prefix-length {
        type uint8 {
          range "0..128";
        }
      }
    }

    case source-instance {
      when "derived-from-or-self(../frr-route-map:condition, 'frr-zebra-route-map:source-instance')";
      leaf source-instance {
        type uint8 {
          range "0..255";
        }
      }
    }

    case source-protocol {
      when "derived-from-or-self(../frr-route-map:condition, 'frr-zebra-route-map:source-protocol')";
      leaf source-protocol {
        type frr-route-types:frr-route-types;
      }
    }
  }

  augment "/frr-route-map:lib"
    + "/frr-route-map:route-map"
    + "/frr-route-map:entry"
    + "/frr-route-map:set-action"
    + "/frr-route-map:rmap-set-action"
    + "/frr-route-map:set-action" {
    case src-address {
      when "derived-from-or-self(../frr-route-map:action, 'frr-zebra-route-map:src-address')";
      choice src-address {
        description
          "Value of the source address";
        case ipv4-src-address {
          leaf ipv4-src-address {
            type inet:ipv4-address;
            mandatory true;
          }
        }

        case ipv6-src-address {
          leaf ipv6-src-address {
            type inet:ipv6-address;
            mandatory true;
          }
        }
      }
    }
  }
}
