Methods for using yang based service. 67/2667/1
authorSuchi Raman <suchi.raman@plexxi.com>
Tue, 12 Nov 2013 14:28:11 +0000 (09:28 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Tue, 12 Nov 2013 14:28:11 +0000 (09:28 -0500)
Yang will provide just the northbound interface (rpcs and notifications).
The state maintained by AffinityManager will remain unchanged.
Builds fine.

Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
affinity/implementation/pom.xml
affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java
affinity/yang/pom.xml
affinity/yang/src/main/yang/affinity-config.yang [deleted file]
affinity/yang/src/main/yang/affinity.yang [new file with mode: 0644]

index f6e6336ef109f65474e2c8936ff4abd0ed2e47e0..681bd90a28995be0b712713122ef85c64a80c46c 100644 (file)
         <configuration>
           <instructions>
             <Import-Package>
+              org.opendaylight.controller.sal.common.util, 
+              org.opendaylight.yang.gen.v1.affinity.rev130925, 
+              org.opendaylight.yang.gen.v1.affinity.rev130925.addendpoint.input, 
+              org.opendaylight.yang.gen.v1.affinity.rev130925.host_endpoint, 
+              org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924, 
+              org.opendaylight.yangtools.yang.common,
               org.opendaylight.affinity.affinity,
               org.opendaylight.affinity.l2agent,
               org.opendaylight.affinity.nfchainagent, 
       <artifactId>sal</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-common-util</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>forwardingrulesmanager</artifactId>
       <artifactId>l2agent</artifactId>
       <version>0.4.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.affinity</groupId>
+      <artifactId>model</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.affinity</groupId>
       <artifactId>nfchainagent</artifactId>
       <version>0.4.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools.model</groupId>
+      <artifactId>ietf-inet-types</artifactId>
+      <version>2010.09.24-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>
index dee91d57c395dad1fde90dc78ecd6d654b789c57..6e01bd703e0d2ce0618f6c3bc373f8d75296b797 100644 (file)
@@ -8,6 +8,23 @@
 
 package org.opendaylight.affinity.affinity.internal;
 
+
+import org.opendaylight.yang.gen.v1.affinity.rev130925.AffinityService;
+import org.opendaylight.yang.gen.v1.affinity.rev130925.HostEndpoint;
+import org.opendaylight.yang.gen.v1.affinity.rev130925.host_endpoint.L2address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+
+import org.opendaylight.yang.gen.v1.affinity.rev130925.CreategroupInput;
+import org.opendaylight.yang.gen.v1.affinity.rev130925.AddendpointInput;
+
+import java.util.concurrent.Future;
+import org.opendaylight.controller.sal.common.util.Futures;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -107,7 +124,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Affinity configuration.
  */
-public class AffinityManagerImpl implements IAffinityManager, IfNewHostNotify,
+public class AffinityManagerImpl implements IAffinityManager, AffinityService, IfNewHostNotify,
                                             IConfigurationContainerAware, IObjectReader, ICacheUpdateAware<Long, String> {
     private static final Logger log = LoggerFactory.getLogger(AffinityManagerImpl.class);
 
@@ -716,4 +733,32 @@ public class AffinityManagerImpl implements IAffinityManager, IfNewHostNotify,
         return nfchainagent.removeNfchain(nfccname);
     }
 
+
+   /* public methods for the yang service. */
+   public Future<RpcResult<Void>> creategroup(CreategroupInput input) {
+       AffinityGroup ag1 = new AffinityGroup(input.getName());
+       
+       /* Correctly translate between status fields. */
+       Status ret = addAffinityGroup(ag1);
+       RpcResult<Void> result = Rpcs.<Void> getRpcResult(true, null, Collections.<RpcError> emptySet());
+       return Futures.immediateFuture(result);
+   }
+    
+   public Future<RpcResult<Void>> addendpoint(AddendpointInput input) {
+       AffinityGroup ag = getAffinityGroup(input.getGroupname());
+       RpcResult<Void> result;
+
+       if (ag != null) {
+           HostEndpoint endpoint = input.getEndpoint();
+           L2address l2address = endpoint.getL2address();
+           Ipv4Prefix l3address = endpoint.getL3address();
+           
+           /*   ag.addL2address(); */
+           ag.addInetMask(l3address.toString());
+           result = Rpcs.<Void> getRpcResult(true, null, Collections.<RpcError> emptySet());
+       } else {
+           result = Rpcs.<Void> getRpcResult(false, null, Collections.<RpcError> emptySet());
+       }
+       return Futures.immediateFuture(result);
+   }
 }
index 9273805555345c794845f97bb11acdb667fc839c..cd794467381b1417c300c6936f834811f4cbd156 100644 (file)
@@ -16,7 +16,7 @@
     <groupId>org.opendaylight.affinity</groupId>
     <artifactId>model</artifactId>
     <version>1.0-SNAPSHOT</version>
-    <packaging>jar</packaging>
+    <packaging>bundle</packaging>
 
     <properties>
         <yang.version>0.5.9-SNAPSHOT</yang.version>
diff --git a/affinity/yang/src/main/yang/affinity-config.yang b/affinity/yang/src/main/yang/affinity-config.yang
deleted file mode 100644 (file)
index cb0e0a2..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-module affinity-config { 
-    namespace "urn:opendaylight:affinity";
-    prefix affinity;
-
-    import ietf-inet-types { prefix inet; }
-    import ietf-yang-types { prefix yang; }
-    import yang-ext { prefix ext; }
-    import opendaylight-inventory {prefix inv;}
-    import opendaylight-l2-types { prefix l2types; }
-
-    revision "2013-09-25" {
-       description "Initial revision of affinity model to be reviewed";
-    }
-
-
-  //**************************************************
-  // Switch + port. Access port on a physical switch. 
-  // Includes access port on a hypervisor ovswitch to which a VM is connected.
-  //**************************************************
-  grouping endpoint {
-      leaf switch-port {
-         type inv:node-connector-id;
-      }
-  }
-
-  //**************************************************
-  // Affinity address domain: This represents a domain (i.e, set) of one or
-  // more addresses. An affinity address may not always have a corresponding
-  // endpoint on the network, for example, an address domain representing 
-  // external addresses, or north-south traffic in a data center). Here the 
-  // IP address domain representing such external addresses does not map to 
-  // endpoints or node connectors on the network. 
-  //
-  // Affinity address domains specify one or more of the following: 
-  // layer 2 address (vlan + mac range)
-  // layer 3 address (IP prefix)
-  //**************************************************
-
-   grouping address-domain {
-       // l2-domain-address is vlan + MAC address range
-       container l2-address {
-          leaf vlan-id {
-              type l2types:vlan-id; 
-          }
-          container mac-address-range {
-              uses mac-address-range;
-          }
-       }
-
-       // l3-domain-address is IPv4 prefix
-       leaf l3-address {
-          type inet:ipv4-prefix;
-       }
-   }       
-
-   grouping mac-address-range {
-       leaf start-address {
-          type yang:mac-address;
-       }
-       leaf end-address {
-          type yang:mac-address;
-       }
-   }
-
-   typedef group-ref {
-       type instance-identifier;
-   }
-   
-   typedef link-ref {
-       type instance-identifier;
-   }
-   
-   grouping element {
-       leaf id {
-          type string;
-       }
-       choice element {
-          description "affinity element";
-          case endpoint {
-                  uses endpoint;
-              }
-              
-              case address-domain {
-                      uses address-domain;
-                  }
-       }
-   }      
-   //**************************************************
-   // Affinity group
-   //**************************************************
-    grouping group {
-       leaf id {
-           type string;
-       }   
-       list element {
-           key id;
-           uses element;
-       }
-    }
-
-    //**************************************************
-    // Affinity link connects one group (from group) to another (to
-    // group). It represents a set of flows that start from the source group
-    // and end in the destination group.  An affinity link has attributes
-    // (policies) attached to it that represent how these flows must be
-    // handled. An affinity link also has directionality associated with
-    // it. A bidirectional affinity link is equivalent to two unidirectional
-    // affinity links, one in each direction.
-    //**************************************************
-    grouping link {
-       leaf id {
-           type string;
-       }
-       leaf from-group {
-           type group-ref;
-       }
-       leaf to-group {
-           type group-ref;
-       }
-       container attribute {
-           uses attribute; 
-       }
-    }
-
-    grouping access-control-rule {
-        leaf proto {
-            type string; // "tcp" or "udp"
-        }
-        leaf port-number {   
-            type inet:port-number;
-        }
-        // permit flag - false here means no access to be allowed for
-        // flows in the affinity link matching the traffic spec.
-        leaf permit {
-            type boolean; 
-        }
-    }
-
-    grouping access-control {
-        list rules {
-            key id;
-            uses access-control-rule;
-        }
-    }
-
-    typedef level {
-        type enumeration {
-            enum high;
-            enum medium;
-            enum low;
-        }
-    }
-
-    //**************************************************
-    // Affinity attribute. Each is expanded in their own grouping construct below. 
-    //**************************************************
-    // Various types of affinity topologies. Used in union 'attribute'. 
-
-    // Affinity attribute. 
-    grouping attribute {
-        leaf id {
-            type string;
-        }
-        choice attribute-type {
-            description "affinity attribute";
-            case isolate-path {
-                 container isolate-path {
-                     uses isolate-path;
-                 }
-            }
-            case shortest-path {
-                    container shortest-path {
-                        uses shortest-path;
-                    }
-            }
-            case bandwidth-optimized-path {
-                    container bandwidth-optimized-path {
-                        uses bandwidth-optimized-path;
-                    }
-            }
-           // Redirect through service chain. 
-           case redirect-path {
-                   leaf redirect-path  {
-                       type network-service-chain-ref;
-                   }
-           }
-           // Apply access control to selected flows. 
-           case access-control {
-                   container access-control {
-                        uses access-control;
-                   }
-           }           
-           // Assign a priority
-           case set-priority {
-                    leaf priority {
-                        type level;
-                   }
-            }          
-       }
-    }
-
-
-    // Isolate flows according to certain constraints. 
-    grouping isolate-path {
-        leaf max-flows-per-link {
-            type uint16;
-        }
-        leaf strict {
-            type boolean;
-        }
-    }
-
-    // Route through shortest path 
-    grouping shortest-path {
-        leaf max-flows-per-link {
-            type uint16;
-        }
-        leaf strict {
-            type boolean;
-        }
-    }
-   
-    // bandwidth optimized path
-    grouping bandwidth-optimized-path {
-        leaf max-link-oversubscription-percent {
-            type uint16;
-        }
-        leaf strict {
-            type boolean;
-        }
-    }
-
-    //**************************************************
-    // Network service chain configuration. 
-    //**************************************************
-    typedef network-service-chain-ref {
-        type instance-identifier;
-    }
-    
-    grouping network-service-chain {
-       leaf id {
-           type string;
-       }   
-       list service-chain {
-           key id;
-           uses network-service-function;
-       }
-    }
-
-    //**************************************************
-    // Network-service-function represented by one of the following
-    // types of addresses.
-    //**************************************************
-    grouping network-service-function {
-       leaf id {
-           type string;
-       }
-       // Address is either an IP address, MAC address, or switch/port. 
-       leaf location {
-           description "Mac or Inet address";
-           type union {
-               type inv:node-connector-id;
-               type yang:mac-address;
-               type inet:ip-address;
-           }
-       }
-    }
-
-    // Main container that represents the complete set of affinity
-    // groups and links. Each set is represented as a YANG list with 'id'
-    // as the key. List contains affinity group and affinity link objects
-    // defined above.
-    container config {
-       list group {
-           key id;
-           ext:context-instance "group-context";
-           uses group;
-       }
-       list link {
-           key id;
-           ext:context-instance "link-context";
-           uses link;
-       }
-    }
-
-    //******************************
-    // RPCs to create affinity groups, add endpoints and address domains. 
-    //******************************
-    rpc create-group {
-       input {
-           uses group;
-       }
-       output {
-           leaf status {
-               type string;
-           }
-       }
-    }
-
-    rpc add-endpoint {
-       input {
-           leaf endpoint {
-               type inv:node-connector-id;
-           }
-       }
-       output {
-           leaf status {
-               type string;
-           }
-       }
-    }
-
-    rpc add-domain {
-       input {
-           container domain {
-               uses address-domain;
-           }
-       }    
-       output {
-           leaf status {
-               type string;
-           }
-       }
-    }
-
-    rpc get-groups {
-       output {
-           list group {
-           key id;
-           uses group;
-           }
-       }
-    }
-    rpc get-links;
-    rpc get-group;
-    rpc get-link;
-
-    rpc get-stats-per-link;
-
-    //**************************************************
-    // Notifications 
-    //**************************************************
-    notification new-endpoint;
-    notification new-domain;
-    notification modify-attribute;
-
-}
-
-
diff --git a/affinity/yang/src/main/yang/affinity.yang b/affinity/yang/src/main/yang/affinity.yang
new file mode 100644 (file)
index 0000000..4ef4ccd
--- /dev/null
@@ -0,0 +1,176 @@
+module affinity { 
+    namespace "affinity";
+    prefix affinity;
+
+    import ietf-inet-types { prefix inet; }
+    import ietf-yang-types { prefix yang; }
+    import yang-ext { prefix ext; }
+    import opendaylight-inventory {prefix inv;}
+    import opendaylight-l2-types { prefix l2types; }
+
+    revision "2013-09-25" {
+       description "Initial revision of affinity model to be reviewed";
+    }
+
+
+  //**************************************************
+  // Switch + port. Access port on a physical switch. 
+  //**************************************************
+  grouping switch_endpoint {
+      leaf switch-port {
+         type inv:node-connector-id;
+      }
+  }
+
+  //**************************************************
+  // Affinity address domain: This represents a domain (i.e, set) of one or
+  // more addresses. An affinity address may not always have a corresponding
+  // endpoint on the network, for example, an address domain representing 
+  // external addresses, or north-south traffic in a data center). Here the 
+  // IP address domain representing such external addresses does not map to 
+  // endpoints or node connectors on the network. 
+  //
+  // Affinity address domains specify one or more of the following: 
+  // layer 2 address (vlan + mac range)
+  // layer 3 address (IP prefix)
+  //**************************************************
+
+  // xxx  -- Includes access port on a hypervisor ovswitch to which a VM is connected.
+   grouping host_endpoint {
+       container l2address {
+          leaf vlan {
+              type l2types:vlan-id; 
+          }
+          leaf mac {
+              type yang:mac-address;
+          }
+       }
+
+       // l3-domain-address is IPv4 prefix
+       leaf l3address {
+          type inet:ipv4-prefix;
+       }
+   }       
+
+   typedef group-ref {
+       type instance-identifier;
+   }
+   
+   typedef link-ref {
+       type instance-identifier;
+   }
+   
+   //**************************************************
+   // Affinity group
+   //**************************************************
+    grouping group {
+       leaf id {
+           type string;
+       }   
+       list endpoints {
+           key id;
+           uses host_endpoint;
+       }
+    }
+
+    //**************************************************
+    // Affinity link connects one group (from group) to another (to
+    // group). It represents a set of flows that start from the source group
+    // and end in the destination group.  An affinity link has attributes
+    // (policies) attached to it that represent how these flows must be
+    // handled. An affinity link also has directionality associated with
+    // it. A bidirectional affinity link is equivalent to two unidirectional
+    // affinity links, one in each direction.
+    //**************************************************
+    grouping link {
+       leaf id {
+           type string;
+       }
+       leaf from-group {
+           type group-ref;
+       }
+       leaf to-group {
+           type group-ref;
+       }
+       container attribute {
+           uses attribute; 
+       }
+    }
+
+    //**************************************************
+    // Affinity attribute. Each is expanded in their own grouping construct below. 
+    //**************************************************
+    // Various types of affinity topologies. Used in union 'attribute'. 
+
+    // Affinity attribute. xxx add case statements for each type later. 
+    grouping attribute {
+        leaf attribute-type {   
+            description "affinity attribute";
+            type string;
+        }
+    }
+
+    // Main container that represents the complete set of affinity
+    // groups and links. Each set is represented as a YANG list with 'id'
+    // as the key. List contains affinity group and affinity link objects
+    // defined above.
+    container config {
+       list group {
+           key id;
+           ext:context-instance "group-context";
+           uses group;
+       }
+       list link {
+           key id;
+           ext:context-instance "link-context";
+           uses link;
+       }
+    }
+
+    //******************************
+    // RPCs to create affinity groups, add endpoints and address domains. 
+    //******************************
+    rpc creategroup {
+       input {
+            leaf name {
+                type string;
+            }
+       }
+    }
+
+    rpc addendpoint {
+       input {
+            leaf groupname {
+                type string;
+            }
+           container endpoint {
+               uses host_endpoint;
+           }
+       }
+    }
+
+/*
+    rpc getgroups {
+       output {
+           list group {
+           key id;
+           uses group;
+           }
+       }
+    }
+    rpc get-links;
+    rpc get-group;
+    rpc get-link;
+
+    rpc get-stats-per-link;
+
+    //**************************************************
+    // Notifications 
+    //**************************************************
+    notification new-endpoint;
+    notification new-domain;
+    notification modify-attribute;
+*/
+}
+
+