* Cleanup json/xml output of API calls. 70/4370/1
authorSuchi Raman <suchi.raman@plexxi.com>
Sat, 18 Jan 2014 14:31:24 +0000 (09:31 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Sat, 18 Jan 2014 14:31:24 +0000 (09:31 -0500)
* Cleanup test script.

Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
12 files changed:
affinity/api/pom.xml
affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityGroup.java
affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityIdentifier.java
affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityLink.java
affinity/api/src/main/java/org/opendaylight/affinity/affinity/InetAddressMask.java
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityGroupList.java
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkList.java [deleted file]
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkNorthbound.java [deleted file]
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinks.java [new file with mode: 0644]
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java
pom.xml
scripts/affinity.py

index 567f0fb9d47969943c985d866a980de6d95ff411..14c15020671af8b7508a0e22e0836986d4a2bff9 100644 (file)
@@ -45,6 +45,9 @@
               org.opendaylight.controller.sal.packet,
               org.opendaylight.controller.sal.inventory,
               org.opendaylight.controller.sal.flowprogrammer,
+              com.fasterxml.jackson.jaxrs.base,
+              com.fasterxml.jackson.jaxrs.json,
+              com.fasterxml.jackson.annotation,
               !org.codehaus.enunciate.jaxrs,
               org.slf4j
             </Import-Package>
       <artifactId>enunciate-core-annotations</artifactId>
       <version>${enunciate.version}</version>
     </dependency> 
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+      <version>${jackson.version}</version>
+    </dependency>
+    
   </dependencies>
 </project>
index 770274759c1f26c1c82784fdb08913c3ae6fba7a..28101f072a3e5ac78daf3d851b85af91600c24e8 100644 (file)
@@ -37,6 +37,8 @@ import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class AffinityGroup implements Cloneable, Serializable {
@@ -44,6 +46,7 @@ public class AffinityGroup implements Cloneable, Serializable {
 
     @XmlAttribute
     private String name;
+
     @XmlElement
     private final Map<String, AffinityIdentifier> elements;
 
@@ -111,9 +114,12 @@ public class AffinityGroup implements Cloneable, Serializable {
 
     // TODO: This should not exist.  It's a replacement for a more
     // robust "is host h a member of this affinity group".
+    @XmlElement(name="endpoints")
     public Set<String> getIPs() {
         return elements.keySet();
     }
+
+    @JsonIgnore
     public ArrayList<AffinityIdentifier> getAllElements() {
         ArrayList<AffinityIdentifier> retvalues = new ArrayList<AffinityIdentifier>(elements.values());
        return retvalues;
index 5ac72d3e0789e053b6285421964ee89bab2e175b..9fb90163b2cf5ca67a44f37f6e4f8d3e90d49a42 100644 (file)
@@ -4,11 +4,22 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
 /* Affinity identifier */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
 public class AffinityIdentifier<T> implements Serializable, Cloneable {
     private static final long serialVersionUID = 1L;
-    private T value;
+
+    @XmlAttribute
     private String name;
+    @XmlAttribute
+    private T value;
 
     public T get() {
         return value;
index e41f459fab998ae58fe98e26ef5c55df0f9b944e..5731c7e8932be68a618580529398a39a2f291f8f 100644 (file)
@@ -34,6 +34,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import org.opendaylight.affinity.affinity.AffinityAttribute;
 
 @XmlRootElement
@@ -78,6 +80,7 @@ public class AffinityLink implements Cloneable, Serializable {
             attrlist.put(attr.type, attr);
         }
     }
+    @JsonIgnore
     public HashMap<AffinityAttributeType, AffinityAttribute> getAttributeList() {
        return this.attrlist;
     }
@@ -92,6 +95,7 @@ public class AffinityLink implements Cloneable, Serializable {
     }
 
     /* Get the waypoint address */
+    @JsonIgnore
     public AffinityAttribute getWaypoint() {
        return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
     }
@@ -131,6 +135,7 @@ public class AffinityLink implements Cloneable, Serializable {
     }
 
     /* tbd requires nb method. */
+    @JsonIgnore
     public List<InetAddress> getTapList() {
         // Check if a tap attribute is already available on this link. 
         SetTap tap = (SetTap) attrlist.get(AffinityAttributeType.SET_TAP);
index b7a052f36963d5b2972fa5f2ec1c3b3588894b75..a76e31d8dec3655b51955a02441ef1e29287e025 100644 (file)
@@ -1,5 +1,10 @@
 package org.opendaylight.affinity.affinity;
 
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import java.io.Serializable;
 import java.net.Inet4Address;
 import java.net.InetAddress;
@@ -14,14 +19,19 @@ import org.slf4j.LoggerFactory;
 /**
  * This class defines an Inet address mask object.
  */
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
 public class InetAddressMask implements Cloneable, Serializable {
-    private String name;
     
+    @XmlAttribute
+    private String name;
+    @XmlElement
     InetAddress networkAddress;
+    @XmlAttribute
     Short mask;
 
     public InetAddressMask() {
-
     }
     /* String addrmask is in the a.b.c.d/m format. */
     public InetAddressMask(String addrmask) {
index c5bda4c3078a557f42f29a3589577d6cd00c4823..c2df47cb6cb3c3ae7b41749b353ad93825cfc6b3 100644 (file)
@@ -20,18 +20,18 @@ import org.opendaylight.affinity.affinity.AffinityGroup;
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class AffinityGroupList {
-        @XmlElement 
-        List<AffinityGroup> affinityGroupList;
-
-        public AffinityGroupList() {
-        }
-        public AffinityGroupList (List<AffinityGroup> aff) {
-            this.affinityGroupList = aff;
-        }
-        public List<AffinityGroup> getAffinityList() {
-                return affinityGroupList;
-        }
-        public void setAffinityList(List<AffinityGroup> aff) {
-                this.affinityGroupList = aff;
-        }
+    @XmlElement 
+    List<AffinityGroup> affinityGroupList;
+    
+    public AffinityGroupList() {
+    }
+    public AffinityGroupList (List<AffinityGroup> aff) {
+        this.affinityGroupList = aff;
+    }
+    public List<AffinityGroup> getAffinityList() {
+        return affinityGroupList;
+    }
+    public void setAffinityList(List<AffinityGroup> aff) {
+        this.affinityGroupList = aff;
+    }
 }
diff --git a/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkList.java b/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkList.java
deleted file mode 100644 (file)
index 487235c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2013 Plexxi, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.affinity.affinity.northbound;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.opendaylight.affinity.affinity.AffinityLink;
-
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.NONE)
-public class AffinityLinkList {
-        @XmlElement (name="affinity")
-        List<AffinityLink> affinityLinkList;
-
-        public AffinityLinkList() {
-        }
-        public AffinityLinkList (List<AffinityLink> aff) {
-            this.affinityLinkList = aff;
-        }
-        public List<AffinityLink> getAffinityList() {
-                return affinityLinkList;
-        }
-        public void setAffinityList(List<AffinityLink> aff) {
-                this.affinityLinkList = aff;
-        }
-}
diff --git a/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkNorthbound.java b/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinkNorthbound.java
deleted file mode 100644 (file)
index 28719f7..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2013 Plexxi, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.affinity.affinity.northbound;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.opendaylight.affinity.affinity.AffinityLink;
-import org.opendaylight.affinity.affinity.AffinityAttribute;
-import org.opendaylight.affinity.affinity.AffinityAttributeType;
-
-// API object to be returned in GET calls.
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.NONE)
-public class AffinityLinkNorthbound {
-        @XmlAttribute 
-        private String name;
-        @XmlElement
-        private List<AffinityAttribute> attrlist;
-    
-        public AffinityLinkNorthbound() {
-        }
-        public AffinityLinkNorthbound(AffinityLink al) {
-            HashMap<AffinityAttributeType, AffinityAttribute> attrs = al.getAttributeList();
-
-            attrlist = new ArrayList<AffinityAttribute>();
-
-            if (attrs != null) {
-                for (AffinityAttribute a: attrs.values()) {
-                    this.attrlist.add(a);
-                }
-            }
-        }
-}
diff --git a/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinks.java b/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityLinks.java
new file mode 100644 (file)
index 0000000..5415c85
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2013 Plexxi, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.affinity.affinity.northbound;
+
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.opendaylight.affinity.affinity.AffinityLink;
+
+@XmlRootElement(name="list")
+@XmlAccessorType(XmlAccessType.NONE)
+public class AffinityLinks {
+    @XmlElement
+    Set<AffinityLink> affinityLinks;
+    
+    // To satisfy JAXB
+    @SuppressWarnings("unused")
+    private AffinityLinks() {
+    }
+    public AffinityLinks (List<AffinityLink> aff) {
+        this.affinityLinks = new HashSet<AffinityLink>();
+        this.affinityLinks.addAll(aff);
+    }
+    public Set<AffinityLink> getAffinityLinks() {
+        return this.affinityLinks;
+    }
+    public void setAffinityLinks(List<AffinityLink> aff) {
+        if (this.affinityLinks != null) {
+            this.affinityLinks.addAll(aff);
+        } else {
+            this.affinityLinks = new HashSet<AffinityLink>();
+            affinityLinks.addAll(aff);
+        }
+        return;
+    }
+    public void setAffinityLinks(Set<AffinityLink> aff) {
+        if (this.affinityLinks != null) {
+            this.affinityLinks.addAll(aff);            
+        } else {
+            this.affinityLinks = aff;
+        }
+        return;
+    }
+}
index 5867a64f37bbfc1388e20511525c5f4c58a0cd60..23fb4c3fe0c1ad73c4e4524cc8868f9b2aea4572 100644 (file)
@@ -249,13 +249,13 @@ public class AffinityNorthbound {
     @Path("/{containerName}/link/{affinityLinkName}")
     @GET
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    @TypeHint(AffinityLinkNorthbound.class)
+    @TypeHint(AffinityLink.class)
     @StatusCodes({
             @ResponseCode(code = 200, condition = "Operation successful"),
             @ResponseCode(code = 404, condition = "The containerName is not found"),
             @ResponseCode(code = 415, condition = "Affinity name is not found"),
             @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
-    public AffinityLinkNorthbound getAffinityLinkDetails(
+    public AffinityLink getAffinityLinkDetails(
             @PathParam("containerName") String containerName,
             @PathParam("affinityLinkName") String affinityLinkName) {
         if (!NorthboundUtils.isAuthorized(
@@ -274,9 +274,8 @@ public class AffinityNorthbound {
         AffinityLink al = affinityManager.getAffinityLink(affinityLinkName);
         if (al == null) {
             throw new ResourceNotFoundException(RestMessages.SERVICEUNAVAILABLE.toString());
-        } else {
-            return new AffinityLinkNorthbound(al);
-        }
+        } 
+        return al;
     }
 
     /**
@@ -727,12 +726,12 @@ public class AffinityNorthbound {
     @Path("/{containerName}/affinity-links")
     @GET
     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    @TypeHint(AffinityLinkList.class)
+    @TypeHint(AffinityLinks.class)
     @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
     @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
     @ResponseCode(code = 404, condition = "The containerName is not found"),
     @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
-    public AffinityLinkList getAllAffinityLinks(@PathParam("containerName") String containerName) {
+    public AffinityLinks getAllAffinityLinks(@PathParam("containerName") String containerName) {
 
         //        if (!isValidContainer(containerName)) {
         //            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
@@ -749,7 +748,7 @@ public class AffinityNorthbound {
                                                   + RestMessages.SERVICEUNAVAILABLE.toString());
         }
         log.info("list all links");
-        return new AffinityLinkList(affinityManager.getAllAffinityLinks());
+        return new AffinityLinks(affinityManager.getAllAffinityLinks());
     }
 
     /**
diff --git a/pom.xml b/pom.xml
index 4f1240221e19c4263b3ebe60ba53178010c5051b..97b652ba067705ac0fcde16ab5f2ace596311635 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
     <exam.version>3.0.0</exam.version>
     <failsafe.version>2.15</failsafe.version>
     <geminiweb.version>2.2.0.RELEASE</geminiweb.version>
-    <jackson.version>1.9.8</jackson.version>
+    <jackson.version>2.3.0</jackson.version>
     <jersey.version>1.17</jersey.version>
     <junit.version>4.10</junit.version>
     <logback.version>1.0.9</logback.version>
       </repository>
     </repositories>
 
-  <pluginRepositories>
-       <pluginRepository>
-           <id>opendaylight-release</id>
-           <name>opendaylight-release</name>
-           <url>http://nexus.opendaylight.org/content/repositories/opendaylight.release/</url>
-       </pluginRepository>
-       <pluginRepository>
-           <id>opendaylight-snapshot</id>
-           <name>opendaylight-snapshot</name>
-           <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
-       </pluginRepository>
-  </pluginRepositories>
-
-
-
+    <pluginRepositories>
+      <pluginRepository>
+        <id>opendaylight-mirror</id>
+        <name>opendaylight-mirror</name>
+        <url>${nexusproxy}/groups/public/</url>
+        <snapshots>
+          <enabled>false</enabled>
+        </snapshots>
+        <releases>
+          <enabled>true</enabled>
+          <updatePolicy>never</updatePolicy>
+        </releases>
+      </pluginRepository>
+      <pluginRepository>
+        <id>opendaylight-release</id>
+        <name>opendaylight-release</name>
+        <url>http://nexus.opendaylight.org/content/repositories/opendaylight.release/</url>
+      </pluginRepository>
+      <pluginRepository>
+        <id>opendaylight-snapshot</id>
+        <name>opendaylight-snapshot</name>
+        <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
+      </pluginRepository>
+    </pluginRepositories>
+    
   <distributionManagement>
     <!-- OpenDayLight Released artifact -->
     <repository>
             <artifactId>maven-scm-provider-svn-commons</artifactId>
             <version>1.7</version>
           </dependency>
+
+          <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+          
+          <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+          
+          <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+          
+          <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-base</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+          
+          <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+          
+          <dependency>
+            <groupId>com.fasterxml.jackson.module</groupId>
+            <artifactId>jackson-module-jaxb-annotations</artifactId>
+            <version>${jackson.version}</version>
+          </dependency>
+
         </dependencies>
       </plugin>
 <!--      <plugin>
index e209c59c308ddbd3248a9ba26b184e8aea1a3291..353ab19e98f00f6561017a588b7ab2ff889954b4 100644 (file)
@@ -21,7 +21,6 @@ def rest_method(url, verb):
 
 
 def list_all_hosts(): 
-
     print "list active hosts"
     put_url = 'http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/active'
     content = rest_method(put_url, "GET")
@@ -36,11 +35,35 @@ def list_all_hosts():
     hostCfg = json.loads(content)
     for host in hostCfg['hostConfig']:
         print host
+
+def get_all_affinity_groups(): 
+    print "get all affinity groups"
+    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-groups'
+    rest_method(get_url, "GET")
+
+# Tbd
+def get_all_affinity_links(): 
+    print "get all affinity links"
+    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-links'
+    rest_method(get_url, "GET")
+
+def get_affinity_group(groupname): 
+    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/' + groupname
+    rest_method(get_url, "GET")
+
+def get_affinity_link(linkname):
+    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + linkname
+    content = rest_method(get_url, "GET")
+    affyLinkCfg = json.loads(content)
+    for key in affyLinkCfg:
+        print "%10s : %s" % (key, affyLinkCfg[key])
+
     
 
-def waypoint_init():
-    # Create two affinity groups
+#     
 
+def client_ws_example():
+    # Create two affinity groups
     print "create web servers group"
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/group/webservers'
     rest_method(put_url, "PUT")
@@ -53,50 +76,20 @@ def waypoint_init():
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/link/inflows/from/clients/to/webservers'
     rest_method(put_url, "PUT")
 
-#    print "add ip to webservers"
-#    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.1'
-#    rest_method(put_url, "PUT")
-
     print "add subnet to webservers"
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/addsubnet/ipprefix/10.0.0.1/mask/31'
     rest_method(put_url, "PUT")
 
-#    print "add ip to webservers"
-#    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.2'
-#    rest_method(put_url, "PUT")
-
     print "add ip to external"    
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.0.0.3'
     rest_method(put_url, "PUT")
 
-
-def get_all_affinity_groups(): 
-    print "get all affinity groups"
-    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-groups'
-    rest_method(get_url, "GET")
-
-# Tbd
-def get_all_affinity_links(): 
-    print "get all affinity links"
-    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-links'
-    rest_method(get_url, "GET")
-
-def get_affinity_group(groupname): 
-    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/' + groupname
-    rest_method(get_url, "GET")
-
-def get_affinity_link(linkname):
-    get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + linkname
-    rest_method(get_url, "GET")
-
-def set_waypoint_address():
-    wp = "10.0.0.2"
-    al = 'inflows'
+# Only one waypoint supported. 
+def set_waypoint_address(al, wp):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/setwaypoint/' + wp
     rest_method(put_url, "PUT")
 
-def unset_waypoint_address():
-    al = 'inflows'
+def unset_waypoint_address(al):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/unsetwaypoint'
     rest_method(put_url, "PUT")
 
@@ -106,14 +99,12 @@ def set_deny(setflag='deny'):
     rest_method(put_url, "PUT")
 
 # Add a tap to ipaddress.
-def set_tap(ipaddr):
-    al = 'inflows'
+def set_tap(al, ipaddr):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/settap/' + ipaddr
     rest_method(put_url, "PUT")
 
 # Add a tap to ipaddress.
-def unset_tap(ipaddr):
-    al = 'inflows'
+def unset_tap(al, ipaddr):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/unsettap/' + ipaddr
     rest_method(put_url, "PUT")
 
@@ -123,14 +114,7 @@ def set_path_isolate():
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/setisolate/'
     rest_method(put_url, "PUT")
 
-#def enable_waypoint():
-#    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/enable/' 
-#    rest_method(put_url, "PUT")
-
-#def disable_waypoint():
-#    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/disable/'
-#    rest_method(put_url, "PUT")
-
+# Re-program the network using OF southbound. 
 def enable_affinity():
     put_url = 'http://localhost:8080/affinity/nb/v2/flatl2/default/enableaffinity/'
     rest_method(put_url, "PUT")
@@ -139,45 +123,51 @@ def disable_affinity():
     put_url = 'http://localhost:8080/affinity/nb/v2/flatl2/default/disableaffinity/'
     rest_method(put_url, "PUT")
 
-# Add waypoint IP to an affinity link.
 def main():
     global h
 
-    waypoint_init()
+    # Create two affinity groups and a link between them. 
+    # Assign attributes. 
+    client_ws_example()
 
     get_affinity_group('webservers')
     get_affinity_group('clients')
     get_affinity_link('inflows')
 
+    print "get_all_affinity_groups..."
     get_all_affinity_groups()
-    list_all_hosts()
+    print "get_all_affinity_links..."
+    get_all_affinity_links()
 
+    set_attr()
+    list_all_hosts()
     return
 
 # Set affinity attributes and make sure they are associated with the affinity link. 
 def set_attr(): 
-#    set_waypoint_address()
-#    set_deny('deny')
-#    set_deny('permit')
-#    set_tap('10.0.0.6')
-#    unset_tap('10.0.0.6')
-    
-    # Test tap affinity.
-    set_tap('10.0.0.4')
+    # Set deny. 
+    set_deny('deny')
     get_affinity_link('inflows')
-    enable_affinity()
-    unset_tap('10.0.0.4')
-    
-    set_path_isolate()
-    
+
+    # Set waypoint and tap. 
+    set_deny('permit')
+    set_waypoint_address('inflows', '10.0.0.2')
+    set_tap('inflows', '10.0.0.6')
+    set_tap('inflows', '10.0.0.4')
+
     get_affinity_link('inflows')
-    enable_affinity()
     
-#    disable_affinity()
-
-#    enable_waypoint()
-#    disable_waypoint()
+    # Change a few affinity attributes and get the new link configuration. 
+    unset_tap('inflows', '10.0.0.6')    
+    print "get_affinity_link..."
+    get_affinity_link('inflows')
 
+    enable_affinity() # Tap to '10.0.0.4'.
+    unset_tap('inflows', '10.0.0.4')
+    set_path_isolate()    
+    get_affinity_link('inflows')
+    enable_affinity() # No action for isolate. Restore normal forwarding. 
+    
 #if __name__ == "__main__":
 #    main()