13ece140f7cdb6e70db1fed446e84ec9ad08f494
[groupbasedpolicy.git] / groupbasedpolicy / src / main / yang / model / policy.yang
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 module policy {
10     yang-version 1;
11
12     namespace "urn:opendaylight:groupbasedpolicy:policy";
13     prefix "gbp-policy";
14
15     import gbp-common {prefix gbp-common;}
16     import ietf-inet-types {prefix inet;}
17
18     description
19         "This module defines the group-based policy configuration
20          model.";
21
22     revision "2014-04-21" {
23         description
24             "Initial revision.";
25     }
26
27     // ***************
28     // Label groupings
29     // ***************
30
31     grouping label {
32         description
33             "Labels are used for matching contracts to endpoint groups
34              through selectors and targets, as well as determining how
35              those contracts will be applied.  See more detailed
36              documentation for qualities, conditions, requirements,
37              and capabilities.";
38
39         leaf description {
40             description "A human-readable description for the label";
41             type gbp-common:description;
42         }
43         leaf inclusion-rule {
44             description "Specify how inheritance will work for this label";
45             default include;
46
47             type enumeration {
48                 enum include {
49                     description
50                         "This label will be included normally in the
51                          matching.";
52                 }
53                 enum exclude {
54                     description
55                         "This label will be excluded from the
56                          matching.  This allows removing labels that
57                          would have otherwise been included because of
58                          inheritence rules.";
59                 }
60             }
61         }
62     }
63
64     grouping quality-base {
65         description "Base type for qualities and matcher qualities.";
66         leaf name {
67             description "A user-visible name for the quality";
68             type gbp-common:quality-name;
69             mandatory true;
70         }
71         uses label;
72     }
73
74     grouping has-qualities {
75         description "An object with a list of qualities";
76         list quality {
77             description
78                 "A quality is a label which selects which selects the
79                  contracts that are in scope.  Another name for
80                  'quality' could be 'attribute' or 'characteristic.'
81                  Qualities can be scoped to either a specific contract
82                  or to a target within that contract.
83
84                  Contracts are matched to provider and consumer
85                  endpoint groups based on the selectors in those
86                  endpoint groups that match the quality.
87
88                  Qualities for a contract are inherited from the
89                  enclosing contract.
90
91                  Qualities for a target with a given name are
92                  inherited both from the enclosing parent contract and
93                  from any targets with the same name within the
94                  enclosing parent contract.";
95
96             key name;
97             uses quality-base;
98         }
99     }
100
101     grouping requirement-base {
102         description "Base type for requirements and matcher requirements.";
103         leaf name {
104             description "A user-visible name for the requirement";
105             type gbp-common:requirement-name;
106             mandatory true;
107         }
108         uses label;
109     }
110
111     grouping has-requirements {
112         list requirement {
113             description
114                 "A requirement is a label that, along with capabilities,
115                  selects how contracts are applied by selecting the
116                  applicable subjects within that contract.
117                  Requirements represent the fact that an endpoint
118                  group requires that some specific functionality be
119                  provided to it in order to function.
120
121                  Requirements scoped to an endpoint group (as well as
122                  any parent endpoint groups) are inherited by all of
123                  that group's contract selectors.  Contract selectors
124                  also inherit requirements from any contract selectors
125                  in the parent groups that have with matching names.
126
127                  Note that requirements play no role in choosing which
128                  contracts apply; they only affect how the contracts
129                  that are chosen will be interpreted.";
130
131             key name;
132             uses requirement-base;
133         }
134     }
135
136     grouping capability-base {
137         description "Base type for capabilities and matcher capabilities.";
138         leaf name {
139             description "A user-visible name for the capability";
140             type gbp-common:capability-name;
141             mandatory true;
142         }
143         uses label;
144     }
145
146     grouping has-capabilities {
147         list capability {
148             description
149                 "A capability is a label that, along with requirements,
150                  selects how contracts are applied by selecting the
151                  applicable subjects within that contract.
152                  Capabilities are specific pieces of functionality
153                  that can be exposed to other endpoint groups that may
154                  meet functional requirements of those endpoint
155                  groups.
156
157                  Capabilities scoped to an endpoint group (as well as
158                  any parent endpoint groups) are inherited by all of
159                  that group's contract selectors.  Contract selectors
160                  also inherit capabilities from any contract selectors
161                  in the parent groups that have matching names.
162
163                  Note that capabilities play no role in choosing which
164                  contracts apply; they only affect how the contracts
165                  that are chosen will be interpreted.";
166
167             key "name";
168             uses capability-base;
169         }
170     }
171
172     grouping has-conditions {
173         list condition {
174             description
175                 "A condition is a state label for endpoints that can
176                  change over time.  As conditions change for certain
177                  endpoints, this can affect which subjects are in
178                  scope as determined by how the clauses in the
179                  contract match against the requirements and
180                  capabilities for the endpoint group, and the
181                  conditions for the endpoints.";
182
183             key "name";
184             leaf name {
185                 description "A user-visible name for the condition";
186                 type gbp-common:condition-name;
187                 mandatory true;
188             }
189             uses label;
190         }
191     }
192
193     grouping matcher {
194         description
195             "A matcher allows matching against labels.  This is used
196              to both to match contracts to endpoint groups by matching
197              on qualities, and then to match against subjects in the
198              contract by matching on requirements, capabilities, and
199              conditions.";
200
201         leaf match-type {
202             description
203                 "Specify how many of the labels must match.  If not
204                  specified, defaults to 'all'.";
205             type enumeration {
206                 enum all {
207                     description
208                         "All specified labels must match.";
209                 }
210                 enum any {
211                     description
212                         "At least one of the specified labels must match.";
213                 }
214                 enum none {
215                     description
216                         "None of the specified labels can match.";
217                 }
218             }
219         }
220     }
221
222     grouping has-condition-matchers {
223         description "Objects with condition matchers";
224         list condition-matcher {
225             description "Match against conditions on endpoints.";
226
227             key "name";
228             leaf name {
229                 description
230                     "A name for the condition matcher";
231                 type gbp-common:condition-matcher-name;
232                 mandatory true;
233             }
234
235             uses matcher;
236             uses has-conditions;
237         }
238     }
239
240     grouping has-endpoint-identification-constraints {
241         container endpoint-identification-constraints {
242             description
243                 "Identify endpoints via other attributes other than conditions.
244                 These can be things such as ip-prefix, vlan, mpls label etc. These
245                 things are intended to be explicity stated, and should not contain
246                 references to other objects like endpointsIDs.";
247             container l3-endpoint-identification-constraints {
248                 list prefix-constraint {
249                     key ip-prefix;
250                     leaf ip-prefix {
251                         type inet:ip-prefix;
252                     }
253                 }
254             }
255         }
256     }
257
258     // ************************
259     // Network domains grouping
260     // ************************
261
262     grouping network-domain {
263         description
264             "A base type for network domains.  Network domains
265              represent some logical grouping or namespace of
266              network addresses.";
267         leaf name {
268             description
269                 "A human-readable name for the network domain.";
270             type gbp-common:name;
271         }
272         leaf description {
273             description
274                 "A human-readable description for the context.";
275             type gbp-common:description;
276         }
277     }
278
279     grouping forwarding-context {
280         description "A base type for forwarding contexts.";
281         uses network-domain;
282     }
283
284     grouping l2-context {
285         description
286             "A base type for layer 2 contexts.  Layer 2 contexts
287              represent a namespace or logical grouping of layer 2
288              addresses.";
289
290         uses forwarding-context;
291     }
292
293     // ************************
294     // Endpoint group groupings
295     // ************************
296
297     grouping relator {
298         description
299             "Relators allow contracts and endpoint groups to be related
300              to each other through a matching process.  See target,
301              selection-relator, target-selector, and named-selector
302              for more information.";
303     }
304
305     grouping selection-relator {
306         description
307             "Selection relators allow endpoint groups to select
308              contracts based on their name or on their qualities.";
309         uses relator;
310
311         leaf name {
312             description "A name for the selector";
313             type gbp-common:selector-name;
314             mandatory true;
315         }
316     }
317
318     grouping consumer-selection-relator {
319         description
320             "A selection relator for matching contracts to meet
321              endpoint group requirements.  See consumer-named-selector
322              and consumer-target-selector for more details.";
323         uses selection-relator;
324         uses has-requirements;
325     }
326
327     grouping provider-selection-relator {
328         description
329             "A selection relator for matching contracts to meet
330              endpoint group requirements.  See provider-named-selector
331              and provider-named-selector for more details.";
332         uses selection-relator;
333         uses has-capabilities;
334     }
335
336     grouping named-selector {
337         description
338             "A named selector selects a contract based on the name of
339              the contract.  Once the contract is selected, the
340              requirements and capabilities are used to select specific
341              subjects within that contract.  Named selectors are the
342              simplest way to select a contract.  If you need a more
343              advanced selector, see the target selector.
344
345              There are two kinds of named selector: consumer named
346              selectors and provider named selectors.  Consumer named
347              selectors select contracts to meet requirements for the
348              endpoint group, and provider named selectors select
349              contracts to provide capabilities for the endpoint group.";
350
351         leaf-list contract {
352             description "Specific contracts to select.";
353             type leafref {
354                 path "/tenants/tenant/contract/id";
355             }
356         }
357     }
358
359     grouping target-selector {
360         description
361             "Target selectors select contracts for the endpoint group.
362              First, the quality matchers are used to select the
363              contracts.  Then, the requirements and capabilities are
364              used to select specific subjects within that contract.
365              Target selectors are an advanced method for selecting
366              contracts; for a simpler method, see the named selector.
367
368              There are two kinds of target selectors: consumer target
369              selectors and provider target selectors.  Consumer target
370              selectors select contracts to meet requirements for the
371              endpoint group, and provider target selectors select
372              contracts to provide capabilities to other endpoint
373              groups.";
374
375         list quality-matcher {
376             description
377                 "A quality matcher is used in a target selector to
378                  match against the qualities in a contract target.
379                  You can specify a list of qualities to match against.
380                  You can choose whether all qualities listed must
381                  match or if a match can be made with any of the
382                  qualities.";
383
384             key "name";
385             leaf name {
386                 description "A unique name for the quality matcher";
387                 type gbp-common:quality-matcher-name;
388                 mandatory true;
389             }
390
391             uses matcher;
392
393             list matcher-quality {
394                 description
395                     "A matcher quality is a quality with a target name
396                      field used in quality matchers.  The name of the
397                      matcher quality matches against qualities in
398                      contract targets.";
399
400                 key name;
401                 uses quality-base;
402
403                 leaf target-namespace {
404                     description
405                         "The name of the target to match.  This allows
406                          us to specify that we want to match only
407                          qualities scoped to a particular target name.
408
409                          This parameter is optional; if not specified,
410                          use an inherited target name if it exists, or
411                          match against any target name.";
412
413                     type gbp-common:target-name;
414                 }
415             }
416         }
417     }
418
419     // ******************
420     // Contract groupings
421     // ******************
422
423     grouping has-direction {
424         description "Object that have a directionality.";
425         leaf direction {
426             default bidirectional;
427             type enumeration {
428                 enum in {
429                     description
430                         "Applies to traffic into provider endpoint group";
431                 }
432                 enum out {
433                     description
434                         "Applies to traffic out of provider endpoint group";
435                 }
436                 enum bidirectional {
437                     description
438                         "Applies to traffic in both directions";
439                 }
440             }
441         }
442     }
443
444     grouping subject-feature-instance {
445         description
446             "Specific instances of subject features with
447              parameters filled in.";
448         list parameter-value {
449             key "name";
450             leaf name {
451                 type gbp-common:parameter-name;
452                 mandatory true;
453             }
454             leaf string-value {
455                 type string;
456             }
457             leaf int-value {
458                 type int64;
459             }
460             container range-value {
461                 leaf min {
462                     type int64;
463                     mandatory true;
464                 }
465                 leaf max {
466                     type int64;
467                     mandatory true;
468                 }
469             }
470         }
471     }
472
473     grouping has-order {
474         description "Objects containing an order parameter";
475         leaf order {
476             description
477                 "Specify the ordering of an ordered list
478                  of elements.";
479             type int32 {
480                 range "0..max";
481             }
482         }
483     }
484
485     grouping has-classifier-refs {
486         description "Objects containing lists of classifier references";
487
488         list classifier-ref {
489             key "name";
490             description
491                 "A reference to classifier instance that is used to match
492                  traffic traveling between the endpoint groups that
493                  form the contract.";
494
495             leaf name {
496                 description "A unique name for this classifier reference";
497                 type gbp-common:classifier-name;
498                 mandatory true;
499             }
500
501             leaf instance-name {
502                 description "The name of the classifier instance";
503                 type leafref {
504                     path "/tenants/tenant/subject-feature-instances/classifier-instance/name";
505                 }
506                 mandatory true;
507             }
508
509             leaf connection-tracking {
510                 description
511                     "Set up connection tracking for this classifier,
512                      which allows the traffic in the reverse direction
513                      as connections are established.  This enables
514                      rules that allow connections to be initiated only
515                      from one side, but once initiated the two sides
516                      can communicate for that connection.";
517
518                 default normal;
519                 type enumeration {
520                     enum normal {
521                         description
522                             "Match only traffic matching the classifier
523                              strictly";
524                     }
525                     enum reflexive {
526                         description
527                             "Additionally match reverse traffic for
528                              connections";
529                     }
530                 }
531             }
532
533             uses has-direction;
534         }
535     }
536
537     grouping has-action-refs {
538         description "Objects containing lists of action references";
539
540         list action-ref {
541             description
542                 "A reference to an action defined in the subject
543                  feature instances for the tenant.";
544
545             key name;
546             leaf name {
547                 description "The name of the action instance";
548                 type leafref {
549                     path "/tenants/tenant/subject-feature-instances/action-instance/name";
550                 }
551                 mandatory true;
552             }
553             uses has-order;
554         }
555     }
556
557     grouping subject-feature-definition {
558         description
559             "Base type for subject feature definitions.";
560
561         leaf description {
562             description "A user-readable description";
563             type gbp-common:description;
564         }
565
566         list parameter {
567             description
568                 "A parameter for the feature that can be
569                  passed in.";
570             key "name";
571             leaf name {
572                 description "A user-visible name for the parameter";
573                 type gbp-common:parameter-name;
574                 mandatory true;
575             }
576             leaf description {
577                 description
578                     "A user-visible description of the meaning of
579                      the parameter.";
580                 type gbp-common:description;
581             }
582             leaf type {
583                 description "The type of the parameter";
584                 default string;
585                 type enumeration {
586                     enum string {
587                         description "A string-valued parameter";
588                     }
589                     enum int {
590                         description "An integer-valued parameter";
591                     }
592                     enum range {
593                         description "An integer-range parameter";
594                     }
595                 }
596             }
597             leaf is-required {
598                 description "Specify whether the parameter is
599                              required for correct operation.";
600                 default optional;
601                 type enumeration {
602                     enum required {
603                         description "The parameter is required";
604                     }
605                     enum optional {
606                         description "The parameter is optional";
607                     }
608                 }
609             }
610         }
611
612         leaf fallback-behavior {
613             description
614                 "Set the behavior when the underlying infrastructure
615                  is unable to support a particular feature.";
616             type enumeration {
617                 enum strict {
618                     description
619                         "A fatal exception MUST be raised which will
620                          render the enclosing subject inactive.";
621                 }
622                 enum allow-fallback {
623                     description
624                         "The infrastructure MAY fall back to using
625                          a parent definition of this feature, and
626                          instread raise a nonfatal exception.";
627                 }
628             }
629         }
630     }
631
632     // ********************
633     // Global Configuration
634     // ********************
635
636     container subject-feature-definitions {
637         description
638             "Contains configuration for the set of actions and
639              classifiers that can be defined for a subject.  This is
640              be specific to the capabilities of the underlying
641              infrastructure, so the policy model does not define the
642              specific semantics.
643
644              The definitions here provide a generic parameterized base
645              that can be extended by more specific definitions.
646              Extensions must apply all the semantics from their parent
647              object as well as any additional semantics.  If the
648              underlying infrastructure is unable to support a
649              particular feature, it MUST trigger an exception that
650              will render the enclosing subject inactive until the
651              exception is resolved.  If the fallback-behavior
652              parameter is set to 'allow-fallback', the infrastructure
653              MAY instead apply the parent subject feature and instead
654              raise a nonfatal exception.";
655
656         config true;
657
658         list classifier-definition {
659             description
660                 "A classifier is used to match traffic traveling between
661                  the endpoint groups that form the contract.
662                  Classifier definitions can define parameters that
663                  will need to be filled in when a particular rule
664                  references it.";
665
666             key "id";
667             uses subject-feature-definition;
668
669             leaf id {
670                 description "A unique ID for the classifier definition";
671                 type gbp-common:classifier-definition-id;
672                 mandatory true;
673             }
674
675             leaf name {
676                 description
677                     "A user-visible name for the classifier definition";
678                 type gbp-common:classifier-name;
679             }
680
681             leaf parent {
682                 description
683                     "Parent classifier definition from which we inherit";
684                 type leafref {
685                     path "/subject-feature-definitions/classifier-definition/id";
686                 }
687             }
688         }
689
690         list action-definition {
691             description
692                 "A action to be applied to traffic across endpoint
693                  groups.  Action definitions can define parameters
694                  that will need to be filled in when a particular rule
695                  references it.";
696
697             key "id";
698             uses subject-feature-definition;
699
700             leaf id {
701                 description "A unique ID for the action";
702                 type gbp-common:action-definition-id;
703                 mandatory true;
704             }
705
706             leaf name {
707                 description "A user-visible name for the action";
708                 type gbp-common:action-name;
709             }
710
711             leaf parent {
712                 description
713                     "Parent action definition from which we inherit";
714                 type leafref {
715                     path "/subject-feature-definitions/action-definition/id";
716                 }
717             }
718         }
719     }
720
721     // *******
722     // Tenants
723     // *******
724
725     container tenants {
726         description "The list of all known tenants";
727
728         config true;
729
730         list tenant {
731             description
732                 "A tenant is a domain of administration which is
733                  logically separate from other tenants.  Most policy
734                  is defined in the context of a particular tenant";
735
736             key "id";
737             leaf id {
738                 description "A unique ID for the tenant";
739                 mandatory true;
740                 type gbp-common:tenant-id;
741             }
742             leaf name {
743                 description "A user-visible name for the tenant";
744                 type gbp-common:name;
745             }
746             leaf description {
747                 description "A user-readable description for the tenant";
748                 type gbp-common:description;
749             }
750
751             // ***************
752             // Network domains
753             // ***************
754
755             list l3-context {
756                 description
757                     "A layer 3 context represents a namespace for layer 3
758                      addresses.  It represents a domain inside which endpoints
759                      can communicate with requiring any address translation.";
760
761                 key "id";
762                 uses forwarding-context;
763
764                 leaf id {
765                     description
766                         "A unique ID for the layer 3 context";
767                     type gbp-common:l3-context-id;
768                 }
769             }
770
771             list l2-bridge-domain {
772                 description
773                     "A layer 2 bridge domain represents a domain in which
774                      layer 2 communication is possible when allowed by policy.";
775                 key "id";
776                 uses l2-context;
777
778                 leaf id {
779                     description "A unique ID for the bridge domain";
780                     type gbp-common:l2-bridge-domain-id;
781                 }
782
783                 leaf parent {
784                     description
785                         "The layer 3 context that contains this bridge domain";
786                     type leafref {
787                         path "/tenants/tenant/l3-context/id";
788                     }
789                 }
790             }
791
792             list l2-flood-domain {
793                 description
794                     "A layer 2 flood domain represents a domain in which
795                      layer 2 broadcast and multicast is allowed.";
796                 key "id";
797                 uses l2-context;
798
799                 leaf id {
800                     description "A unique ID for the flood domain";
801                     type  gbp-common:l2-flood-domain-id;
802                 }
803
804                 leaf parent {
805                     description
806                         "The bridge domain that contains this flood domain";
807                     type leafref {
808                         path "/tenants/tenant/l2-bridge-domain/id";
809                     }
810                 }
811             }
812
813             list subnet {
814                 description
815                     "An IP subnet associated with a layer 2 or layer 3
816                      context.";
817                 key "id";
818                 uses network-domain;
819
820                 leaf id {
821                     description "A unique ID for the subnet";
822                     type gbp-common:subnet-id;
823                 }
824
825                 leaf parent {
826                     description
827                         "The forwarding context that contains this subnet";
828                     type gbp-common:context-id;
829                 }
830
831                 leaf ip-prefix {
832                     description "The IP prefix that defines the subnet";
833                     type inet:ip-prefix;
834                 }
835                 leaf virtual-router-ip {
836                     description
837                         "IP address to use for a virtual gateway router
838                          for the subnet, if desired.";
839                     type inet:ip-address;
840                 }
841                 list gateways {
842                     description
843                         "External gateways for subnets we serve, 
844                         includes prefixes for static routing";
845                     key "gateway";
846                     leaf gateway {
847                         type inet:ip-address;
848                     }
849                     list prefixes {
850                         key "prefix";
851                         leaf prefix {
852                             type inet:ip-prefix;
853                         }
854                     }
855                     
856                 }
857             }
858
859             // ***************
860             // Endpoint groups
861             // ***************
862
863             list endpoint-group {
864                 description
865                     "Endpoint groups are sets of endpoints that share a
866                      common set of policies.  Endpoint groups are
867                      matched to contracts using selectors, contracts
868                      determine which endpoints can communicate and in
869                      what way.
870
871                      Endpoint groups have both requirements and
872                      capabilities, which represent specific pieces of
873                      functionality that are exposed at the boundary of
874                      those groups.  Requirements represent some
875                      specific functionality that is needed for the
876                      endpoints in the endpoint group to function.
877                      Correspondingly, capabilities are pieces of
878                      functionality that the endpoints in the endpoint
879                      group can provide to other endpoints.
880
881                      Contracts can be selected through either a named
882                      selector, which matches specific contracts by
883                      name, or by a target selector which will match
884                      contracts by matching its list of qualities to
885                      the list of qualities for a target on the
886                      contract.  The contract selectors choose which
887                      contracts are in scope.  Note that requirements
888                      and capabilities are not used when choosing which
889                      contracts are in scope; these are used to
890                      determine how a contract will be interpreted.
891
892                      There are two broad category of selectors:
893                      provider selectors and consumer selectors.  The
894                      provider selectors allow selecting contracts that
895                      allow the endpoint group to expose its
896                      capabilities.  The consumer selectors allow
897                      selecting contracts which allow the endpoint
898                      group to meet its requirements.";
899
900                 key "id";
901
902                 leaf id {
903                     mandatory true;
904                     type gbp-common:endpoint-group-id;
905                 }
906
907                 leaf name {
908                     description
909                         "A user-visible name for the endpoint group";
910                     type gbp-common:name;
911                 }
912                 leaf description {
913                     description
914                         "A human-readable description for the endpoint
915                          group.";
916                     type gbp-common:description;
917                 }
918                 uses has-requirements;
919                 uses has-capabilities;
920
921                 leaf intra-group-policy {
922                     description
923                         "Governs how traffic within the endpoint group
924                          should be handled.";
925                     default allow;
926                     type enumeration {
927                         enum allow {
928                             description
929                                 "Traffic between two endpoints in the group
930                                  is always allowed";
931                         }
932                         enum require-contract {
933                             description
934                                 "Traffic between two endpoints in the group
935                                  is allowed only when a contract exists to
936                                  allow it explicitly";
937                         }
938                     }
939                 }
940
941                 list consumer-named-selector {
942                     description
943                         "Consumer named selectors are named selectors
944                          that select contracts to meet the
945                          requirements of the endpoint group.
946
947                          The consumer named selector selects a
948                          contract based on the name of the contract.
949                          Once the contract is selected, the
950                          requirements are used to select specific
951                          subjects within that contract.";
952
953                     key "name";
954                     uses named-selector;
955                     uses consumer-selection-relator;
956                 }
957
958                 list provider-named-selector {
959                     description
960                         "Provider named selectors are named selectors
961                          that select contracts to provide capabilties
962                          to other endpoint group.
963
964                          The provider named selector selects a
965                          contract based on the name of the contract.
966                          Once the contract is selected, the capabilies
967                          are used to select specific subjects within
968                          that contract.";
969
970                     key "name";
971                     uses named-selector;
972                     uses provider-selection-relator;
973                 }
974
975                 list consumer-target-selector {
976                     description
977                         "Consumer target selectors are target selectors
978                          that select contracts to meet the requirements
979                          of the endpoint group.
980
981                          The consumer target selector selects a
982                          contract using the quality matchers to match
983                          against the qualities specified on the
984                          contract targets.  Once the contract is
985                          selected, the requirements are used to select
986                          specific subjects within that contract.";
987
988                     key "name";
989                     uses target-selector;
990                     uses consumer-selection-relator;
991                 }
992
993                 list provider-target-selector {
994                     description
995                         "Provider target selectors are target selectors
996                          that select contracts to provide capabilties
997                          to other endpoint group.
998
999                          The provider target selector selects a
1000                          contract using the quality matchers to match
1001                          against the qualities specified on the
1002                          contract targets.  Once the contract is
1003                          selected, the capabilities are used to select
1004                          specific subjects within that contract.";
1005
1006                     key "name";
1007                     uses target-selector;
1008                     uses provider-selection-relator;
1009                 }
1010
1011                 leaf network-domain {
1012                     description
1013                         "The network domain associated with this endpoint
1014                          group.  The network domain controls which endpoints
1015                          are addressible by the endpoints in the group.";
1016                     type gbp-common:network-domain-id;
1017                 }
1018
1019                 leaf parent {
1020                     description
1021                         "Parent endpoint group from which we inherit";
1022
1023                     type leafref {
1024                         path "/tenants/tenant/endpoint-group/id";
1025                     }
1026                 }
1027             }
1028
1029             list external-implicit-group {
1030                 description
1031                     ".";
1032
1033                 key "id";
1034
1035                 leaf id {
1036                     mandatory true;
1037                     type gbp-common:endpoint-group-id;
1038                 }
1039                 // Fields to be determined and completed before Code Freeze
1040
1041             }
1042             // *************************
1043             // Subject feature instances
1044             // *************************
1045
1046             container subject-feature-instances {
1047                 description
1048                     "Contains instances of subject features.  Subject
1049                      feature instances reference a subject feature
1050                      definition but fill in the required parameters so
1051                      that they can be easily references elsewhere.";
1052
1053                 list classifier-instance {
1054                     description "XXX";
1055
1056                     key "name";
1057                     leaf name {
1058                         description "A name for the classifier instance";
1059                         type gbp-common:classifier-name;
1060                         mandatory true;
1061                     }
1062                     leaf classifier-definition-id {
1063                         type leafref {
1064                             path "/subject-feature-definitions/classifier-definition/id";
1065                         }
1066                     }
1067                     uses subject-feature-instance;
1068                 }
1069
1070                 list action-instance {
1071                     description "XXX";
1072
1073                     key "name";
1074                     leaf name {
1075                         description "A name for the action instance";
1076                         type gbp-common:action-name;
1077                         mandatory true;
1078                     }
1079                     leaf action-definition-id {
1080                         type leafref {
1081                             path "/subject-feature-definitions/action-definition/id";
1082                         }
1083                     }
1084                     uses subject-feature-instance;
1085                 }
1086             }
1087
1088             // *********
1089             // Contracts
1090             // *********
1091
1092             list contract {
1093                 description
1094                     "Contracts contain a set of subjects that describe
1095                      the communication allowed between endpoints in
1096                      endpoint groups.  Contracts are matched to endpoint
1097                      groups by selectors.";
1098
1099                 key "id";
1100                 leaf id {
1101                     description "A unique ID for the contract";
1102                     type gbp-common:contract-id;
1103                     mandatory true;
1104                 }
1105
1106                 leaf description {
1107                     description
1108                         "A human-readable description for the contract.";
1109                     type gbp-common:description;
1110                 }
1111
1112                 // *******
1113                 // Relator
1114                 // *******
1115
1116                 uses has-qualities;
1117
1118                 list target {
1119                     description
1120                         "Targets on a contract allow grouping sets of qualities
1121                          together, as well as providing a namespace for
1122                          the qualities that are matched.";
1123
1124                     key "name";
1125                     leaf name {
1126                         description
1127                             "The name for this target.  This can also be used
1128                              by quality matchers as a namespace for qualities.";
1129                         type gbp-common:target-name;
1130                         mandatory true;
1131                     }
1132
1133                     uses relator;
1134                     uses has-qualities;
1135                 }
1136
1137                 // ********************
1138                 // Clauses and subjects
1139                 // ********************
1140
1141                 list subject {
1142                     description
1143                         "Subjects define rules to allow traffic to flow
1144                          between endpoints in different endpoint
1145                          groups.  No communication is allowed unless a
1146                          subject allows that communication.
1147
1148                          After a contract has been selected, clauses
1149                          in that contract match against the
1150                          requirements, capabilities, and conditions
1151                          that apply to the endpoints or endpoint
1152                          groups that are participating in the
1153                          contract.  Clauses that match each point to a
1154                          subject which then becomes active.
1155
1156                          An active subject can then apply its rules to
1157                          the traffic between the endpoints.";
1158
1159                     key "name";
1160                     leaf name {
1161                         description "A name for the subject";
1162                         type gbp-common:subject-name;
1163                         mandatory true;
1164                     }
1165
1166                     list rule {
1167                         description
1168                             "A rule is applied to traffic between
1169                              endpoints in different endpoint groups.
1170                              Rules match against the traffic using
1171                              classifiers, and then apply actions to
1172                              the traffic for matching rules.
1173
1174                              Rules are applied in order according to
1175                              their order parameter.  Only the first
1176                              matching rule will apply.  When multiple
1177                              subjects are active, the order on each
1178                              subject will determine which subjects are
1179                              applied first, and all their rules will
1180                              take effect before the rules of any
1181                              subjects with a higher order value.  When
1182                              subjects have the same order value, then
1183                              they will apply in lexicographic order by
1184                              subject name.";
1185
1186                         key "name";
1187                         leaf name {
1188                             description "A name for the rule";
1189                             type gbp-common:rule-name;
1190                             mandatory true;
1191                         }
1192
1193                         uses has-classifier-refs;
1194                         uses has-action-refs;
1195                         uses has-order;
1196                     }
1197
1198                     uses has-order;
1199                 }
1200
1201                 list clause {
1202                     description
1203                         "Clauses are used to determine which subjects are
1204                          active once a contract is selected using the
1205                          contract selectors.
1206
1207                          Clauses are activated by matching against
1208                          requirements on the consumer endpoint group,
1209                          capabilities on the provider endpoint group, and
1210                          conditions on the individual endpoints in the
1211                          endpoint group.";
1212                     key "name";
1213                     leaf name {
1214                         type gbp-common:clause-name;
1215                         mandatory true;
1216                     }
1217                     // ********
1218                     // Matchers
1219                     // ********
1220
1221                     container consumer-matchers {
1222                         description
1223                             "Matchers that apply to the consumer endpoint
1224                              group.";
1225
1226                         // GIC mutually OR'd within role
1227                         choice group-identification-constraints {
1228                             description "Returns Groups which match, MUTALLY OR within role. Must be Either/Or";
1229
1230                             case group-name-constraint-case {
1231                                 list group-name-constraint {
1232                                     key endpoint-group-name;
1233                                     leaf endpoint-group-name {
1234                                         type gbp-common:name;
1235                                     }
1236                                 }
1237                             }
1238                             case group-requirement-constraint-case {
1239                                 list requirement-matcher {
1240                                     description
1241                                         "Match against requirements in the consumer
1242                                          endpoint group.";
1243
1244                                     key "name";
1245                                     leaf name {
1246                                         description
1247                                             "A name for the requirement matcher";
1248                                         type gbp-common:requirement-matcher-name;
1249                                         mandatory true;
1250                                     }
1251
1252                                     uses matcher;
1253                                     list matcher-requirement {
1254                                         description
1255                                             "A matcher requirement is a
1256                                              requirement with a selector name
1257                                              field used in requirement
1258                                              matchers.  The name of the
1259                                              matcher requirement matches
1260                                              against requirements in endpoint
1261                                              groups.";
1262
1263                                         key name;
1264                                         uses requirement-base;
1265
1266                                         leaf selector-namespace {
1267                                             description
1268                                                 "The name of the selector to
1269                                                  match.  This allows us to
1270                                                  specify that we want to match
1271                                                  only requirements scoped to a
1272                                                  particular selector name.
1273
1274                                                  This parameter is optional;
1275                                                  if not specified, use an
1276                                                  inherited selector namespace
1277                                                  if it exists, or match
1278                                                  against any selector name.";
1279
1280                                             type gbp-common:selector-name;
1281                                         }
1282                                     }
1283                                 }
1284                             }
1285
1286                             case group-any-case {
1287                                 container group-any {
1288
1289                                     description
1290                                         "A presence container stating that, if this exists,
1291                                         the role matcher will match on any group.";
1292                                     presence "This matches any group";
1293                                 }
1294                             }
1295                         }
1296
1297
1298
1299                         uses has-condition-matchers;
1300
1301                         uses has-endpoint-identification-constraints;
1302                     }
1303
1304                     container provider-matchers {
1305                         description
1306                             "Matchers that apply to the provider endpoint
1307                              group";
1308
1309                         // GIC mutually OR'd within role
1310                         choice group-identification-constraints {
1311                             description "Returns Groups which match, MUTALLY OR within role. Must be Either/Or";
1312
1313                             case group-name-constraint-case {
1314                                 list group-name-constraint {
1315                                     key endpoint-group-name;
1316                                     leaf endpoint-group-name {
1317                                         type gbp-common:name;
1318                                     }
1319                                 }
1320                             }
1321                             case group-capability-constraint-case {
1322                                 list capability-matcher {
1323                                     description
1324                                         "Match against capabilities in the provider
1325                                          endpoint group.";
1326
1327                                     key "name";
1328                                     leaf name {
1329                                         description
1330                                             "A name for the capability matcher";
1331                                         type gbp-common:capability-matcher-name;
1332                                         mandatory true;
1333                                     }
1334
1335                                     uses matcher;
1336
1337                                     list matcher-capability {
1338                                         description
1339                                             "A matcher capability is a
1340                                              capability with a selector
1341                                              name field used in capability
1342                                              mat  chers.  The name of the
1343                                              matcher capability matches
1344                                              against capabilities in
1345                                              endpoint groups.";
1346
1347                                         key name;
1348                                         uses capability-base;
1349
1350                                         leaf selector-namespace {
1351                                             description
1352                                                 "The name of the selector to
1353                                                  match.  This allows us to
1354                                                  specify that we want to match
1355                                                  only capabilities scoped to a
1356                                                  particular selector name.
1357
1358                                                  This parameter is optional;
1359                                                  if not specified, use an
1360                                                  inherited selector namespace
1361                                                  if it exists, or match
1362                                                  against any selector name.";
1363
1364                                             type gbp-common:selector-name;
1365                                         }
1366                                     }
1367                                 }
1368                             }
1369                             case group-any-case {
1370                                 container group-any {
1371                                     presence "any";
1372                                 }
1373                             }
1374                         }
1375
1376                         uses has-condition-matchers;
1377
1378                         uses has-endpoint-identification-constraints;
1379                     }
1380
1381                     container any-matchers {
1382                         description
1383                             "Matchers that apply to either provider endpoint group or consumer endpoint group.";
1384                         // TODO fill this out, may need additional groupings so as to not confuse capability or requirement.
1385                    }
1386
1387                     // ******************
1388                     // Subject References
1389                     // ******************
1390
1391                     leaf-list subject-refs {
1392                         description
1393                             "The subjects that will be activated if this
1394                              clause matches.";
1395
1396                         type leafref {
1397                             path "/tenants/tenant/contract/subject/name";
1398                         }
1399                     }
1400                 }
1401
1402                 // ***********
1403                 // Inheritance
1404                 // ***********
1405
1406                 leaf parent {
1407                     description "Parent contract from which we inherit";
1408
1409                     type leafref {
1410                         path "/tenants/tenant/contract/id";
1411                     }
1412                 }
1413             }
1414
1415             list contract-ref {
1416                 description
1417                     "Contract references allow forming contracts
1418                      between endpoint groups in different tenants.
1419                      Once the contract reference is created, it is
1420                      then possible to match against the contract using
1421                      selectors as though it were a local tenant.
1422
1423                      Endpoint groups in the local tenant can serve
1424                      only as consumers of the contract.  Once the
1425                      contract is matched, consumer matchers will apply
1426                      to requirements and conditions in the local
1427                      tenant, and provider matchers will apply against
1428                      capabilities and conditions in the referenced
1429                      tenant.";
1430
1431                 key contract-id;
1432
1433                 leaf tenant-id {
1434                     description
1435                         "The tenant ID of the tenant containing the
1436                          contract.";
1437                     type leafref {
1438                         path "/tenants/tenant/id";
1439                     }
1440                 }
1441                 leaf contract-id {
1442                     description "The contract ID of the contract.";
1443
1444                     type leafref {
1445                         path "/tenants/tenant/contract/id";
1446                     }
1447                 }
1448             }
1449         }
1450     }
1451 }