Modify endpoint registry to not require layer 2 fields 00/8200/1
authorRob Adams <readams@readams.net>
Fri, 20 Jun 2014 22:04:27 +0000 (15:04 -0700)
committerRob Adams <readams@readams.net>
Fri, 20 Jun 2014 22:24:26 +0000 (15:24 -0700)
Add forwarding model to policy
Update InheritanceUtils to include forwarding model

Change-Id: Id895ef3aa86caaf6c59021efb8480ac7058df485
Signed-off-by: Rob Adams <readams@readams.net>
groupbasedpolicy/pom.xml
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/endpoint/EndpointRegistry.java
groupbasedpolicy/src/main/java/org/opendaylight/groupbasedpolicy/resolver/internal/InheritanceUtils.java
groupbasedpolicy/src/main/yang/common.yang
groupbasedpolicy/src/main/yang/endpoint.yang
groupbasedpolicy/src/main/yang/policy.yang

index 2fed4c403d20c26d3344bf118e309e1dde032760..8a3263349c8a02af46d506814de0299972e84f60 100644 (file)
     </dependency>
   </dependencies>
 
-  <!-- Project reporting -->
-  <reporting>
-    <plugins>
-      <!-- Code coverage analysis -->
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>cobertura-maven-plugin</artifactId>
-        <version>2.6</version>
-      </plugin>
-    </plugins>
-  </reporting>
-
   <!-- project build -->
   <build>
     <plugins>
           <manifestLocation>${project.basedir}/META-INF</manifestLocation>
         </configuration>
       </plugin>
-      <!-- Code coverage analysis -->
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>cobertura-maven-plugin</artifactId>
-        <version>2.6</version>
-       <configuration>
-          <instrumentation>
-           <excludes>
-             <exclude>org/opendaylight/yang/**/*.class</exclude>
-             <exclude>org/opendaylight/controller/config/yang/**/*.class</exclude>
-           </excludes>
-         </instrumentation>
-       </configuration>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <redirectTestOutputToFile>true</redirectTestOutputToFile>
-         <!-- needed for cobertura -->
+          <!-- needed for cobertura -->
           <argLine>-XX:-UseSplitVerifier</argLine>
         </configuration>
       </plugin>
           </execution>
         </executions>
       </plugin>
+      <!-- Code coverage analysis -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>cobertura-maven-plugin</artifactId>
+        <version>2.6</version>
+        <configuration>
+          <instrumentation>
+            <excludes>
+              <exclude>org/opendaylight/yang/**/*.class</exclude>
+              <exclude>org/opendaylight/controller/config/yang/**/*.class</exclude>
+            </excludes>
+          </instrumentation>
+        </configuration>
+      </plugin>
       <plugin>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>yang-maven-plugin</artifactId>
       </plugin>
     </plugins>
   </build>
+
+  <!-- Project reporting -->
+  <reporting>
+    <plugins>
+      <!-- Code coverage analysis -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>cobertura-maven-plugin</artifactId>
+        <version>2.6</version>
+      </plugin>
+    </plugins>
+  </reporting>
 </project>
index 818c6c3be526651f92e6ebcaee79dc693354480a..f6a5fa072c1436b4a39e14f5f26962005e891773 100644 (file)
@@ -37,7 +37,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupCondition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupConditionKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
@@ -111,7 +112,7 @@ public class EndpointRegistry implements AutoCloseable, EndpointService {
             .build();
     
         EndpointKey key = 
-                new EndpointKey(ep.getL2Namespace(), ep.getMacAddress());
+                new EndpointKey(ep.getL2Context(), ep.getMacAddress());
         InstanceIdentifier<Endpoint> iid = 
                 InstanceIdentifier.builder(Endpoints.class)
                     .child(Endpoint.class, key)
@@ -126,10 +127,10 @@ public class EndpointRegistry implements AutoCloseable, EndpointService {
             for (L3Address l3addr : input.getL3Address()) {
                 t = dataProvider.beginTransaction();
                 EndpointL3Key key3 = new EndpointL3Key(l3addr.getIpAddress(), 
-                                                       l3addr.getL3Namespace());
+                                                       l3addr.getL3Context());
                 EndpointL3 ep3 = new EndpointL3Builder(input)
                     .setIpAddress(key3.getIpAddress())
-                    .setL3Namespace(l3addr.getL3Namespace())
+                    .setL3Context(l3addr.getL3Context())
                     .setTimestamp(timestamp)
                     .build();
                 InstanceIdentifier<EndpointL3> iid_l3 = 
@@ -150,40 +151,37 @@ public class EndpointRegistry implements AutoCloseable, EndpointService {
     @Override
     public Future<RpcResult<Void>>
         unregisterEndpoint(UnregisterEndpointInput input) {
-        EndpointKey key = 
-                new EndpointKey(input.getL2Namespace(), input.getMacAddress());
-        InstanceIdentifier<Endpoint> iid = 
-                InstanceIdentifier.builder(Endpoints.class)
-                    .child(Endpoint.class, key).build();
-        DataObject dao = dataProvider.readOperationalData(iid);
-
         Collection<RpcError> errors = new ArrayList<>();
-        
-        if (dao != null && dao instanceof Endpoint) {
-            Endpoint ep = (Endpoint)dao;
-            
-            if (ep.getL3Address() != null) {
-                for (L3Address l3addr : ep.getL3Address()) {
-                    EndpointL3Key key3 = 
-                            new EndpointL3Key(l3addr.getIpAddress(), 
-                                              l3addr.getL3Namespace());
-                    InstanceIdentifier<EndpointL3> iid_l3 = 
-                            InstanceIdentifier.builder(Endpoints.class)
-                                .child(EndpointL3.class, key3)
-                                .build();
-                    DataModificationTransaction t =
-                            dataProvider.beginTransaction();
-                    t.removeOperationalData(iid_l3);
-                    docommit(t, iid_l3.toString(), "unregister", errors);
-                }
-            }
-            
+
+        for (L2 l2a : input.getL2()) {
+            EndpointKey key = 
+                    new EndpointKey(l2a.getL2Context(), 
+                                    l2a.getMacAddress());
+            InstanceIdentifier<Endpoint> iid = 
+                    InstanceIdentifier.builder(Endpoints.class)
+                    .child(Endpoint.class, key).build();
             DataModificationTransaction t =
                     dataProvider.beginTransaction();
             t.removeOperationalData(iid);
             docommit(t, iid.toString(), "unregister", errors);
         }
 
+        if (input.getL3() != null) {
+            for (L3 l3addr : input.getL3()) {
+                EndpointL3Key key3 = 
+                        new EndpointL3Key(l3addr.getIpAddress(), 
+                                          l3addr.getL3Context());
+                InstanceIdentifier<EndpointL3> iid_l3 = 
+                        InstanceIdentifier.builder(Endpoints.class)
+                        .child(EndpointL3.class, key3)
+                        .build();
+                DataModificationTransaction t =
+                        dataProvider.beginTransaction();
+                t.removeOperationalData(iid_l3);
+                docommit(t, iid_l3.toString(), "unregister", errors);
+            }
+        }
+
         // note that deleting an object that doesn't exist is fine.
         RpcResult<Void> result = Rpcs.<Void>getRpcResult(errors.isEmpty(), 
                                                          errors);
index 25ba19c1514536df703b77e368aa77f30fc3358b..0ba4ccd991289d1ae7b323f830185dd0eb966ae6 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.LabelName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.QualityMatcherName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.QualityName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RequirementMatcherName;
@@ -129,6 +130,10 @@ public class InheritanceUtils {
             .setContract(ImmutableList.copyOf(resolvedContracts.values()))
             .setContractRef(unresolvedTenant.getContractRef())
             .setSubjectFeatureInstances(unresolvedTenant.getSubjectFeatureInstances())
+            .setL3Context(unresolvedTenant.getL3Context())
+            .setL2BridgeDomain(unresolvedTenant.getL2BridgeDomain())
+            .setL2FloodDomain(unresolvedTenant.getL2FloodDomain())
+            .setSubnet(unresolvedTenant.getSubnet())
             .build();
     }
 
@@ -163,6 +168,7 @@ public class InheritanceUtils {
                 new HashMap<>();
         HashMap<SelectorName, ProviderNamedSelector> resolvedPns = 
                 new HashMap<>();
+        NetworkDomainId domain = unresolvedEg.getNetworkDomain();
 
         if (unresolvedEg.getConsumerTargetSelector() != null) {
             for (ConsumerTargetSelector s : unresolvedEg.getConsumerTargetSelector()) {
@@ -184,6 +190,7 @@ public class InheritanceUtils {
                 resolvePns(unresolvedTenant, unresolvedEg, s, resolvedPns);
             }
         }
+        
 
         if (parent != null) {
             if (parent.getConsumerTargetSelector() != null) {
@@ -210,6 +217,9 @@ public class InheritanceUtils {
                         resolvedPns.put(pns.getName(), pns);
                 }
             }
+            if (domain == null) {
+                domain = parent.getNetworkDomain();
+            }
         }
 
         // Note: do not set parent, or any of the values that only exist
@@ -221,6 +231,7 @@ public class InheritanceUtils {
             .setConsumerNamedSelector(ImmutableList.copyOf(resolvedCns.values()))
             .setProviderTargetSelector(ImmutableList.copyOf(resolvedPts.values()))
             .setProviderNamedSelector(ImmutableList.copyOf(resolvedPns.values()))
+            .setNetworkDomain(domain)
             .build();
         resolvedEgs.put(resolvedEg.getId(), resolvedEg);
     }
index d5c2e231e841a46ae1119c856a0fa2d27aaaa5c1..c28d9a8f5475c09e1f7c4eea82a60268f72aef83 100644 (file)
@@ -78,14 +78,39 @@ module gbp-common {
     // Unique object IDs
     // *****************
 
-    typedef l2-namespace-id {
+    typedef network-domain-id {
         type unique-id;
-        description "An unique ID for a layer 2 namespace";
+        description "A unique ID for a network domain";
+    }
+    
+    typedef subnet-id {
+        type network-domain-id;
+        description "A unique ID for a subnet";
     }
 
-    typedef l3-namespace-id {
-        type unique-id;
-        description "A unique ID for a layer 3 namespace";
+    typedef context-id {
+        type network-domain-id;
+        description "A unique ID for a forwarding context";
+    }
+
+    typedef l2-context-id {
+        type context-id;
+        description "A unique ID for a layer 2 context";
+    }
+
+    typedef l2-bridge-domain-id {
+        type l2-context-id;
+        description "A unique ID for a bridge domain";
+    }
+
+    typedef l2-flood-domain-id {
+        type l2-context-id;
+        description "A unique ID for a flood domain";
+    }
+
+    typedef l3-context-id {
+        type context-id;
+        description "A unique ID for a layer 3 context";
     }
 
     typedef tenant-id {
index e7bff67acdeef710687494fc02d3dc9db6647cd8..1ec39ac48983617e67fd39193da4ce8d0a31d0c9 100644 (file)
@@ -16,43 +16,55 @@ module endpoint {
             "Initial revision.";
     }
 
-    // A base type for an end point
-    grouping endpoint-fields {
-        description "An endpoint and its associated metadata";
-        leaf tenant {
-            type gbp-common:tenant-id;
+    grouping l2-key {
+        description 
+            "The fields that identify an endpoint by a layer 2 address";
+        leaf l2-context {
+            type gbp-common:l2-context-id;
+            description 
+                "The context for the layer 2 address for this endpoint";
+        }
+        leaf mac-address {
+            type yang:mac-address;
+            description 
+                "The MAC address for the endpoint";
+        }
+    }
+
+    grouping l3-key {
+        description 
+            "The fields that identify an endpoint by a layer 3 address";
+        leaf l3-context {
+            type gbp-common:l3-context-id;
             mandatory true;
             description 
-                "The tenant with which this endpoint is associated";
+                "The context for this layer 3 address";
         }
-        leaf l2-namespace {
-            type gbp-common:l2-namespace-id;
+        leaf ip-address {
+            type inet:ip-address;
             mandatory true;
             description 
-                "The namespace for the layer 2 address for this endpoint";
+                "The actual IP address for the endpoint";
         }
-        leaf mac-address {
-            type yang:mac-address;
+    }
+
+    // A base type for an end point
+    grouping endpoint-fields {
+        description "An endpoint and its associated metadata";
+        leaf tenant {
+            type gbp-common:tenant-id;
             mandatory true;
             description 
-                "The MAC address for the endpoint";
+                "The tenant with which this endpoint is associated";
         }
+
+        uses l2-key;
+
         list l3-address {
             description
                 "All the layer 3 addresses associated with this endpoint";
-            key "l3-namespace ip-address";
-            leaf l3-namespace {
-                type gbp-common:l3-namespace-id;
-                mandatory true;
-                description 
-                    "The namespace for this layer 3 address";
-            }
-            leaf ip-address {
-                type inet:ip-address;
-                mandatory true;
-                description 
-                    "The actual IP address for the endpoint";
-            }
+            key "l3-context ip-address";
+            uses l3-key;
             leaf ip-prefix {
                 type inet:ip-prefix;
                 description 
@@ -108,7 +120,7 @@ module endpoint {
                 "Endpoints indexed by layer 2 addreses.  When modifying
                  data here, you must also modify data in the
                  endpoints-l3 list as well.";
-            key "l2-namespace mac-address";
+            key "l2-context mac-address";
             uses endpoint-fields;
         }
 
@@ -118,13 +130,13 @@ module endpoint {
                  data here, you must also modify data in the endpoints
                  list as well.";
 
-            key "l3-namespace ip-address";
+            key "l3-context ip-address";
 
-            leaf l3-namespace {
-                type gbp-common:l3-namespace-id;
+            leaf l3-context {
+                type gbp-common:l3-context-id;
                 mandatory true;
                 description 
-                    "The namespace for this layer 3 address";
+                    "The context for this layer 3 address";
             }
             leaf ip-address {
                 type inet:ip-address;
@@ -159,20 +171,16 @@ module endpoint {
     }
 
     rpc unregister-endpoint {
-        description "Unregister an endpoint from the registry.";
+        description "Unregister an endpoint or endpoints from the registry.";
 
         input {
-            leaf l2-namespace {
-                type gbp-common:l2-namespace-id;
-                mandatory true;
-                description 
-                    "The namespace for the layer 2 address for this endpoint";
+            list l2 {
+                key "l2-context mac-address";
+                uses l2-key;
             }
-            leaf mac-address {
-                type yang:mac-address;
-                mandatory true;
-                description 
-                    "The MAC address for the endpoint";
+            list l3 {
+                key "l3-context ip-address";
+                uses l3-key;
             }
         }
     }
index d7b91fe97de0e86589ca3c9528b36b18b33fc27d..38fda67b8d9e16cdf9419cd029f78e36b01dc4e0 100644 (file)
@@ -5,6 +5,7 @@ module policy {
     prefix "gbp-policy";
 
     import gbp-common {prefix gbp-common;}
+    import ietf-inet-types {prefix inet;}
 
     description 
         "This module defines the group-based policy configuration 
@@ -228,6 +229,41 @@ module policy {
         }
     }
 
+    // ************************
+    // Network domains grouping
+    // ************************
+
+    grouping network-domain {
+        description
+            "A base type for network domains.  Network domains 
+             represent some logical grouping or namespace of
+             network addresses.";
+        leaf name {
+            description 
+                "A human-readable name for the network domain.";
+            type gbp-common:name;
+        }
+        leaf description {
+            description 
+                "A human-readable description for the context.";
+            type gbp-common:description;
+        }
+    }
+
+    grouping forwarding-context {
+        description "A base type for forwarding contexts.";
+        uses network-domain;
+    }
+
+    grouping l2-context {
+        description 
+            "A base type for layer 2 contexts.  Layer 2 contexts
+             represent a namespace or logical grouping of layer 2
+             addresses.";
+
+        uses forwarding-context;
+    }
+
     // ************************
     // Endpoint group groupings
     // ************************
@@ -670,6 +706,92 @@ module policy {
                 type gbp-common:description;
             }
 
+            // ***************
+            // Network domains
+            // ***************
+
+            list l3-context {
+                description
+                    "A layer 3 context represents a namespace for layer 3
+                     addresses.  It represents a domain inside which endpoints
+                     can communicate with requiring any address translation.";
+
+                key "id";
+                uses forwarding-context;
+
+                leaf id {
+                    description 
+                        "A unique ID for the layer 3 context";
+                    type gbp-common:l3-context-id;
+                }
+            }
+            
+            list l2-bridge-domain {
+                description 
+                    "A layer 2 bridge domain represents a domain in which 
+                     layer 2 communication is possible when allowed by policy.";
+                key "id";
+                uses l2-context;
+
+                leaf id {
+                    description "A unique ID for the bridge domain";
+                    type gbp-common:l2-bridge-domain-id;
+                }
+
+                leaf parent {
+                    description 
+                        "The layer 3 context that contains this bridge domain";
+                    type leafref {
+                        path "/tenants/tenant/l3-context/id";
+                    }
+                }
+            }
+
+            list l2-flood-domain {
+                description 
+                    "A layer 2 flood domain represents a domain in which 
+                     layer 2 broadcast and multicast is allowed.";
+                key "id";
+                uses l2-context;
+
+                leaf id {
+                    description "A unique ID for the flood domain";
+                    type  gbp-common:l2-flood-domain-id;
+                }
+
+                leaf parent {
+                    description 
+                        "The bridge domain that contains this flood domain";
+                    type leafref {
+                        path "/tenants/tenant/l2-bridge-domain/id";
+                    }
+                }
+            }
+
+            list subnet {
+                description
+                    "An IP subnet associated with a layer 2 or layer 3 
+                     context.";
+                key "id";
+                uses network-domain;
+                
+                leaf id {
+                    description "A unique ID for the subnet";
+                    type gbp-common:subnet-id;
+                }
+
+                leaf parent {
+                    description 
+                        "The forwarding context that contains this subnet";
+                    type gbp-common:context-id;
+                }
+
+                leaf ip-prefix {
+                    description "The IP prefix that defines the subnet";
+                    type inet:ip-prefix;
+                }
+            }
+
             // ***************
             // Endpoint groups
             // ***************
@@ -802,6 +924,14 @@ module policy {
                     uses provider-selection-relator;
                 }
 
+                leaf network-domain {
+                    description 
+                        "The network domain associated with this endpoint
+                         group.  The network domain controls which endpoints 
+                         are addressible by the endpoints in the group.";
+                    type gbp-common:network-domain-id;
+                }
+
                 leaf parent {
                     description 
                         "Parent endpoint group from which we inherit"; 
@@ -1161,6 +1291,4 @@ module policy {
             }
         }
     }
-
-    // XXX - TODO - model forwarding model
-}
+}
\ No newline at end of file