Additional affinity APIs. 88/4288/1
authorSuchi Raman <suchi.raman@plexxi.com>
Thu, 16 Jan 2014 07:38:54 +0000 (02:38 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Thu, 16 Jan 2014 07:38:54 +0000 (02:38 -0500)
Examples in affinity.py.

Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
15 files changed:
affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttributeType.java
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/SetPathIsolate.java [new file with mode: 0644]
affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetTap.java [new file with mode: 0644]
affinity/api/src/test/java/org/opendaylight/affinity/affinity/AffinityGroupTest.java
affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java
affinity/implementation/src/test/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImplTest.java
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityGroupList.java
affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java
flatl2/src/main/java/org/opendaylight/affinity/flatl2/FlatL2AffinityImpl.java
scripts/affinity.py
scripts/demo.py
scripts/stats.py

index 965ab56f89a9c3c5b4450bf24fecc95fda36e0dc..bd55c80077b65a264865e67f694d613f69892dfb 100644 (file)
@@ -5,6 +5,8 @@ package org.opendaylight.affinity.affinity;
  */
 public enum AffinityAttributeType {
     SET_DENY("deny"),
+    SET_TAP("set_tap"),
+    SET_PATH_ISOLATE("set_path_isolate"),
     SET_PATH_REDIRECT("set_path_redirect");
 
     String id;
index df0626321351505891a44a8754cd569f8a88e9b9..770274759c1f26c1c82784fdb08913c3ae6fba7a 100644 (file)
@@ -94,12 +94,17 @@ public class AffinityGroup implements Cloneable, Serializable {
     public Integer size() {
        return (elements.size());
     }
-    public void print() {
-       System.out.println("Printing affinity group " + this.name);
+
+    @Override
+    public String toString() {
+        String output = this.name;
+
        for (AffinityIdentifier value : elements.values()) {
-           value.print();
+           output = output + ", " + value;
        }
+        return output;
     }
+
     public String getName() {
        return name;
     }
index b3ce11162105224b4e02145aa9cd218215c133ff..5ac72d3e0789e053b6285421964ee89bab2e175b 100644 (file)
@@ -22,9 +22,6 @@ public class AffinityIdentifier<T> implements Serializable, Cloneable {
     public String getName(String name) {
        return (this.name);
     }
-    public void print() {
-       System.out.println(name);
-    }
     public String toString() {
        return "AffinityIdentifier [name= " + this.name + " value= " + value.toString() + "]";
     }
index 351e9865a14c193f517a879ff90a5ef2225c7025..e41f459fab998ae58fe98e26ef5c55df0f9b944e 100644 (file)
@@ -52,12 +52,6 @@ public class AffinityLink implements Cloneable, Serializable {
     @XmlElement
     private HashMap<AffinityAttributeType, AffinityAttribute> attrlist;
     
-    // xxx 
-    @XmlElement 
-    String affinityAttribute;
-    @XmlElement 
-    String affinityWaypoint;
-
     public AffinityLink() {
         attrlist = new HashMap<AffinityAttributeType, AffinityAttribute>();
     }
@@ -81,20 +75,14 @@ public class AffinityLink implements Cloneable, Serializable {
     }
     public void addAttribute(AffinityAttribute attr) {
         if (attr != null) {
-            System.out.println("Printing affinity attribute: " + attr.type);
             attrlist.put(attr.type, attr);
         }
     }
     public HashMap<AffinityAttributeType, AffinityAttribute> getAttributeList() {
        return this.attrlist;
     }
-
-    /* Set the waypoint address, if the attribute is "redirect" */
-    public void setAttribute(String attribute) {
-       this.affinityAttribute = attribute;
-    }
     
-    // Create a service chain of one waypoint. 
+    /* Set the waypoint address, if the attribute is "redirect" */
     public void setWaypoint(String wpaddr) {
         SetPathRedirect redirect = new SetPathRedirect();
         redirect.addWaypoint(NetUtils.parseInetAddress(wpaddr));
@@ -103,13 +91,53 @@ public class AffinityLink implements Cloneable, Serializable {
         addAttribute((AffinityAttribute) redirect);
     }
 
-    // Unset the waypoint address.
-    public void unsetWaypoint() {        
+    /* Get the waypoint address */
+    public AffinityAttribute getWaypoint() {
+       return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
+    }
+    
+    // Unset the waypoint attribute.
+    public void unsetWaypoint() {
         attrlist.remove(AffinityAttributeType.SET_PATH_REDIRECT);
     }
 
-    public AffinityAttribute getWaypoint() {
-       return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
+    // Add tap attribute. 
+    public void addTap(String ipaddr) {
+        // Check if a tap attribute is already available on this link. 
+        // If not, create one and add IP address to it. 
+        AffinityAttributeType aatype = AffinityAttributeType.SET_TAP;
+        SetTap tap = (SetTap) attrlist.get(aatype);
+
+        if (tap == null) {
+            tap = new SetTap();
+        }
+        // add a tap server
+        tap.addTap(NetUtils.parseInetAddress(ipaddr));
+        
+        /* Add this tap set to the affinity link. */
+        addAttribute((AffinityAttribute) tap);
+    }
+
+    // Add tap configuration. 
+    public void removeTap(String ipaddr) {
+        // Check if a tap attribute is already available on this link. 
+        AffinityAttributeType aatype = AffinityAttributeType.SET_TAP;
+        SetTap tap = (SetTap) attrlist.get(aatype);
+        
+        // tap attribute exists. Remove IP address from its list of IP adresses. 
+        if (tap != null) {
+            tap.removeTap(NetUtils.parseInetAddress(ipaddr));
+        }
+    }
+
+    /* tbd requires nb method. */
+    public List<InetAddress> getTapList() {
+        // Check if a tap attribute is already available on this link. 
+        SetTap tap = (SetTap) attrlist.get(AffinityAttributeType.SET_TAP);
+        if (tap != null) {
+            return tap.getTapList();
+        }
+        return null;
     }
     
     public boolean isDeny() {
@@ -126,9 +154,16 @@ public class AffinityLink implements Cloneable, Serializable {
     public void unsetDeny() {
         attrlist.remove(AffinityAttributeType.SET_DENY);
     }
-    public String getAttribute() {
-       return this.affinityAttribute;
+
+    // Mark this with "isolate"
+    public void setIsolate() {
+        SetPathIsolate iso = new SetPathIsolate();
+        addAttribute(iso);
+    }
+    public void unsetIsolate() {
+        attrlist.remove(AffinityAttributeType.SET_PATH_ISOLATE);
     }
+
     public AffinityGroup getFromGroup() {
        return this.fromGroup;
     }
diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetPathIsolate.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetPathIsolate.java
new file mode 100644 (file)
index 0000000..c0378f0
--- /dev/null
@@ -0,0 +1,23 @@
+package org.opendaylight.affinity.affinity;
+
+import java.net.InetAddress;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class SetPathIsolate extends AffinityAttribute {
+    private static final long serialVersionUID = 1L;
+
+    public SetPathIsolate() {
+        type = AffinityAttributeType.SET_PATH_ISOLATE;
+    }
+}
+
+
+
diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetTap.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetTap.java
new file mode 100644 (file)
index 0000000..6a27446
--- /dev/null
@@ -0,0 +1,78 @@
+package org.opendaylight.affinity.affinity;
+
+import java.net.InetAddress;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class SetTap extends AffinityAttribute {
+    private static final long serialVersionUID = 1L;
+    @XmlElement
+    private List<InetAddress> tapList;
+
+    public SetTap() {
+        type = AffinityAttributeType.SET_TAP;
+        tapList = new ArrayList<InetAddress>();
+    }
+
+    public List<InetAddress> getTapList() {
+        return this.tapList;
+    }
+
+    // Must be in the same L2 domain. 
+    public void addTap(InetAddress ipaddr) {
+        tapList.add(ipaddr);
+    }
+
+    // Must be in the same L2 domain. 
+    public void removeTap(InetAddress ipaddr) {
+        tapList.remove(ipaddr);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        for (InetAddress address: tapList) {
+            result = prime * result + ((address == null) ? 0 : address.hashCode());
+        }
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        SetTap other = (SetTap) obj;
+        /* xxx check first element. */
+        InetAddress address = tapList.get(0);
+        List<InetAddress> otherlist = other.getTapList();
+        return tapList.equals(otherlist);
+    }
+
+    @Override
+    public String toString() {
+        String string = type + "[";
+        for (InetAddress address: tapList) {
+            string = string + " -> " + address.toString();
+        }
+        string = string +  "]";
+        return string;
+    }
+}
+
+
+
index 2469c8c56dbef1dc29f6e3be7a7ff9439f4c6d06..8de1105c05bdf2501161aa8f582f7555fa20b93f 100644 (file)
@@ -45,7 +45,6 @@ public class AffinityGroupTest extends TestCase {
        al1.setFromGroup(ag1);
        al1.setToGroup(ag2);
        al1.setName("link1");
-       al1.setAttribute("redirect");
         al1.setWaypoint("20.0.0.11");
 
        // Add a self loop for ag2.
@@ -53,11 +52,9 @@ public class AffinityGroupTest extends TestCase {
        al2.setFromGroup(ag2);
        al2.setToGroup(ag2);
        al2.setName("link2");
-       al2.setAttribute("hopcount");
 
-       System.out.println("Affinity group size is " + ag1.size());
+       System.out.println("Affinity group= " + ag1.toString() + "elements= " + ag1.size());
         Assert.assertTrue(ag1.size() == 2);
-       ag1.print();
     }
 }
 
index 6f15051b5b45d9b6095912f501fe5365080c8272..6acb48d9afde31ce8d300f75e805dba596d61460 100644 (file)
@@ -125,7 +125,7 @@ public class AffinityManagerImpl implements IAffinityManager,
     private static final int REPLACE_RETRY = 1;
     private IfIptoHost hostTracker;
 
-    private static short REDIRECT_IPSWITCH_PRIORITY = 3;
+    private static short AFFINITY_RULE_PRIORITY = 3;
 
     public enum ReasonCode {
         SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF(
@@ -361,7 +361,7 @@ public class AffinityManagerImpl implements IAffinityManager,
        List<Host> hostList= new ArrayList<Host>();
 
        for (AffinityIdentifier h : ag.getAllElements()) {
-           h.print();
+            log.debug("host = {}", h);
            if (hostTracker != null) {
                Host host1 = hostTracker.hostFind((InetAddress) h.get());
                hostList.add(host1);
@@ -568,7 +568,7 @@ public class AffinityManagerImpl implements IAffinityManager,
             /* Set other fields. */
             match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());  
             Flow flow = new Flow(match, null);
-            flow.setPriority(REDIRECT_IPSWITCH_PRIORITY);
+            flow.setPriority(AFFINITY_RULE_PRIORITY);
             flowlist.add(flow);
         }
        return flowlist;
index 98170a496e99d4f48fa2d35664ac4c5f68c41042..22d5368adbd2912da75ee256dec1a8d82d6c177f 100644 (file)
@@ -43,7 +43,7 @@ public class AffinityManagerImplTest {
        Status ret2 = ag1.add("10.0.0.20");
        Assert.assertTrue(ret2.isSuccess());
 
-       ag1.print();
+       System.out.println(ag1.toString());
 
        // Add an invalid element. 
        Status ret3 = ag1.add("10");
@@ -60,19 +60,16 @@ public class AffinityManagerImplTest {
        al1.setFromGroup(ag1);
        al1.setToGroup(ag2);
        al1.setName("link1");
-       al1.setAttribute("isolate");
 
        // Add a self loop for ag2.
        AffinityLink al2 = new AffinityLink("link2", ag2, ag2);
        al2.setFromGroup(ag2);
        al2.setToGroup(ag2);
        al2.setName("link2");
-       al2.setAttribute("hopcount");
 
-       System.out.println("Affinity group size is " + ag1.size());
+       System.out.println("Affinity group " + ag1.toString() + ", elements=" + ag1.size());
         Assert.assertTrue(ag1.size() == 2);
-       ag1.print();
-
+        
         Status result;
        result = affinitymgr.addAffinityGroup(ag1);
         Assert.assertTrue(result.isSuccess());
@@ -97,7 +94,6 @@ public class AffinityManagerImplTest {
        al3.setFromGroup(ag3);
        al3.setToGroup(ag4);
        al3.setName("link3");
-       al3.setAttribute("redirect");
         al3.setWaypoint("20.0.0.11");
         
        result = affinitymgr.addAffinityGroup(ag3);
@@ -128,9 +124,11 @@ public class AffinityManagerImplTest {
        /* Get all members as affinity identifiers */
        System.out.println("Affinity group (as Affinity Identifiers) = " + ag1.getName());
        ArrayList<AffinityIdentifier> affylist = affinitymgr.getAllElementsByAffinityIdentifier(ag1);
-       
+
+        String idList = null;
        for (AffinityIdentifier i : affylist) {
-           i.print();
+            idList = idList + i.toString();
+           System.out.println(idList);
        }
 
        /* Get all id pairs for an affinity link */
index b2d9b98217d06e298ac0a8977222f5aa0944c6a8..c5bda4c3078a557f42f29a3589577d6cd00c4823 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.affinity.affinity.AffinityGroup;
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class AffinityGroupList {
-        @XmlElement (name="affinity")
+        @XmlElement 
         List<AffinityGroup> affinityGroupList;
 
         public AffinityGroupList() {
index cb23f1415f3a02eb02f346eebe50fe3ac03fd174..5867a64f37bbfc1388e20511525c5f4c58a0cd60 100644 (file)
@@ -279,6 +279,91 @@ public class AffinityNorthbound {
         }
     }
 
+    /**
+     * Add tap server details to an affinity link. 
+     *
+     * @param containerName
+     *            Name of the Container
+     * @param affinityLinkName
+     *            Name of the new affinity link being added
+     * @param path
+     *            IP address string of a waypoint server or VM
+     * @return Response as dictated by the HTTP Response Status code
+     */
+
+    @Path("/{containerName}/link/{affinityLinkName}/settap/{tapIP}")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+    public Response setLinkTapServer(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityLinkName") String affinityLinkName,
+            @PathParam("tapIP") String tapIP) {
+
+        log.info("Set tap address (link)" + affinityLinkName + " (tap ip) " + tapIP);
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+        al1.addTap(tapIP);
+        log.info("Affinity link is now: {} ", al1.toString());
+        return Response.status(Response.Status.CREATED).build();
+    }
+
+    /**
+     * Add path redirect details to an affinity link. 
+     *
+     * @param containerName
+     *            Name of the Container
+     * @param affinityLinkName
+     *            Name of the new affinity link being added
+     * @param tap
+     *            IP address string of a waypoint server or VM
+     * @return Response as dictated by the HTTP Response Status code
+     */
+
+    @Path("/{containerName}/link/{affinityLinkName}/unsettap/{tapIP}")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+    public Response unsetLinkTapServer(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityLinkName") String affinityLinkName,
+            @PathParam("tapIP") String tapIP) {
+        
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        log.info("Unset tap setting (link) {}, tapIP = {}", affinityLinkName, tapIP);
+
+        AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+        al1.removeTap(tapIP);
+        log.info("Affinity link is now: {} ", al1.toString());
+        return Response.status(Response.Status.CREATED).build();
+    }
+
     /**
      * Add path redirect details to an affinity link. 
      *
@@ -343,7 +428,7 @@ public class AffinityNorthbound {
             @ResponseCode(code = 200, condition = "Operation successful"),
             @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
             @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
-    public Response setLinkWaypoint(
+    public Response unsetLinkWaypoint(
             @PathParam("containerName") String containerName,
             @PathParam("affinityLinkName") String affinityLinkName) {
 
@@ -365,6 +450,86 @@ public class AffinityNorthbound {
     }
 
 
+
+    /**
+     * Add path isolation attribute to a link.
+     *
+     * @param containerName
+     *            Name of the Container
+     * @param affinityLinkName
+     *            Name of the new affinity link being added
+     * @return Response as dictated by the HTTP Response Status code
+     */
+
+    @Path("/{containerName}/link/{affinityLinkName}/setisolate")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+    public Response setLinkIsolate(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityLinkName") String affinityLinkName) {
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        log.info("Set isolate (link)" + affinityLinkName);
+        AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+        al1.setIsolate();
+        log.info("Affinity link is now: {} ", al1.toString());
+        return Response.status(Response.Status.CREATED).build();
+    }
+
+
+    /**
+     * Remove isolation attribute from link. 
+     *
+     * @param containerName
+     *            Name of the Container
+     * @param affinityLinkName
+     *            Name of the new affinity link being added
+     * @return Response as dictated by the HTTP Response Status code
+     */
+
+    @Path("/{containerName}/link/{affinityLinkName}/unsetisolate")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @TypeHint(Response.class)
+    @StatusCodes({
+            @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+    public Response unsetIsolate(
+            @PathParam("containerName") String containerName,
+            @PathParam("affinityLinkName") String affinityLinkName) {
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                                            + containerName);
+        }
+
+        IAffinityManager affinityManager = getIfAffinityManagerService(containerName);
+        if (affinityManager == null) {
+            throw new ServiceUnavailableException("Affinity Manager "
+                                                  + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        log.info("Unset isolate (link)" + affinityLinkName);
+
+        AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+        al1.unsetIsolate();
+        return Response.status(Response.Status.CREATED).build();
+    }
+
     /**
      * Mark this affinity link with "deny". 
      *
index 7b9de3bcc960a5a0b8c2d262ace7271906109d9f..6642cbc511a1a0dbe17cb59c640279211097bcea 100644 (file)
@@ -93,6 +93,7 @@ import org.opendaylight.affinity.affinity.AffinityAttributeType;
 import org.opendaylight.affinity.affinity.AffinityAttribute;
 import org.opendaylight.affinity.affinity.SetDeny;
 import org.opendaylight.affinity.affinity.SetPathRedirect;
+import org.opendaylight.affinity.affinity.SetTap;
 import org.opendaylight.affinity.l2agent.IfL2Agent;
 import org.opendaylight.affinity.l2agent.L2Agent;
 
@@ -310,15 +311,15 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
             log.info("flatl2: {} (#flows={})", groupName, flowgroups.get(groupName).size());
             log.info("flatl2: {} (#attribs={})", groupName, attribs.get(groupName).size());
             for (Flow f: flowlist) {
-                List<Action> actions = calcForwardingActions(node, attribs.get(groupName));
-                // Update flow with actions. 
-                log.info("Adding actions {} to flow {}", actions, f);
-                f.setActions(actions);
                 // Set the flow name based on end points for this flow. 
                 String flowName = null;
                 InetAddress srcIp = (InetAddress) f.getMatch().getField(MatchType.NW_SRC).getValue();
                 InetAddress dstIp = (InetAddress) f.getMatch().getField(MatchType.NW_DST).getValue();
                 flowName = "[" + groupName + ":" + srcIp + ":" + dstIp + "]";
+                List<Action> actions = calcForwardingActions(node, srcIp, dstIp, attribs.get(groupName));
+                // Update flow with actions. 
+                log.info("Adding actions {} to flow {}", actions, f);
+                f.setActions(actions);
                 // Make a flowEntry object. groupName is the policy name, from the affinity link name. Same for all flows in this bundle. 
                 FlowEntry fEntry = new FlowEntry(groupName, flowName, f, node);
                 log.info("Install flow entry {} on node {}", fEntry.toString(), node.toString());
@@ -332,7 +333,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
      * (switch) and the list of configured actions.
      */
 
-    public List<Action> calcForwardingActions(Node node, HashMap<AffinityAttributeType, AffinityAttribute> attribs) {
+    public List<Action> calcForwardingActions(Node node, InetAddress src, InetAddress dst, HashMap<AffinityAttributeType, AffinityAttribute> attribs) {
         List<Action> fwdactions = new ArrayList<Action>();
 
         AffinityAttributeType aatype;
@@ -362,31 +363,59 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
                 // Lookup output port on this node for this destination. 
 
                 // Using L2agent
-                Output output = getRedirectPortL2Agent(node, wp);
+                Output output = getOutputPortL2Agent(node, wp);
                 fwdactions.add(output);
                 // Using simpleforwarding.
-                // Output output = getRedirectPort(node, wp);
+                // Output output = getOutputPort(node, wp);
                 // Controller controller = new Controller();
                 // fwdactions.add(controller);
             }
         }
 
-        // tbd. Apply tap. 
+        // Apply tap 
+        aatype = AffinityAttributeType.SET_TAP;
+
+        SetTap tap = (SetTap) attribs.get(aatype);
+
+        if (tap != null) {
+            log.info("Applying tap affinity.");
+            List<InetAddress> taplist = tap.getTapList();
+            if (taplist != null) {
+                // Only one waypoint server in list. 
+                for (InetAddress tapip: taplist) {
+                    log.info("tap information = {}", tapip);
+                    // Lookup output port on this node for this destination. 
+                    
+                    // Using L2agent
+                    Output output1 = getOutputPortL2Agent(node, tapip);
+                    Output output2 = getOutputPortL2Agent(node, dst);
+                    
+                    fwdactions.add(output1);
+                    fwdactions.add(output2);
+                    
+                    // Using simpleforwarding.
+                    // Output output = getOutputPort(node, wp);
+                    // Controller controller = new Controller();
+                    // fwdactions.add(controller);
+                }
+            }
+        }
+
         return fwdactions;
     }
 
     /** 
-     * Using L2agent, get the redirect port toward this wp (waypoint)
-     * from this node (switch).
+     * Using L2agent, get the output port toward this IP from this
+     * node (switch).
      */
-    public Output getRedirectPortL2Agent(Node node, InetAddress wp) {
+    public Output getOutputPortL2Agent(Node node, InetAddress ip) {
         Output op = null;
 
         if (l2agent != null) {
             /* Look up the output port leading to the waypoint. */
-            HostNodeConnector wphost = (HostNodeConnector) hostTracker.hostFind(wp);
-            log.info("redirect port on node {} toward wphost {}", node, wphost);
-            NodeConnector dst_connector = l2agent.lookup_output_port(node, wphost.getDataLayerAddressBytes());
+            HostNodeConnector host = (HostNodeConnector) hostTracker.hostFind(ip);
+            log.info("output port on node {} toward host {}", node, host);
+            NodeConnector dst_connector = l2agent.lookup_output_port(node, host.getDataLayerAddressBytes());
             if (dst_connector != null) {
                 op = new Output(dst_connector);
             }
@@ -396,7 +425,7 @@ public class FlatL2AffinityImpl implements IfNewHostNotify {
         return op;
     }
 
-    public Output getRedirectPort(Node node, InetAddress wp) {
+    public Output getOutputPort(Node node, InetAddress wp) {
         IHostId id = HostIdFactory.create(wp, null);
         HostNodeConnector hnConnector = this.hostTracker.hostFind(id);
         Node destNode = hnConnector.getnodeconnectorNode();
index 67ebdc348020ddbcf82d51fab3c435a92a5b77c4..e209c59c308ddbd3248a9ba26b184e8aea1a3291 100644 (file)
@@ -77,7 +77,7 @@ def get_all_affinity_groups():
 
 # Tbd
 def get_all_affinity_links(): 
-    print "get all affinity groups"
+    print "get all affinity links"
     get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-links'
     rest_method(get_url, "GET")
 
@@ -105,6 +105,24 @@ def set_deny(setflag='deny'):
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/' + setflag + '/'
     rest_method(put_url, "PUT")
 
+# Add a tap to ipaddress.
+def set_tap(ipaddr):
+    al = 'inflows'
+    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'
+    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/unsettap/' + ipaddr
+    rest_method(put_url, "PUT")
+
+# Set path isolate. 
+def set_path_isolate():
+    al = 'inflows'
+    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")
@@ -134,14 +152,28 @@ def main():
     get_all_affinity_groups()
     list_all_hosts()
 
-    # Set affinity attributes and make sure they are associated with the affinity link. 
-    set_waypoint_address()
-    set_deny('deny')
-    set_deny('permit')
-    get_affinity_link('inflows')
+    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')
+    get_affinity_link('inflows')
     enable_affinity()
-    disable_affinity()
+    unset_tap('10.0.0.4')
+    
+    set_path_isolate()
+    
+    get_affinity_link('inflows')
+    enable_affinity()
+    
+#    disable_affinity()
 
 #    enable_waypoint()
 #    disable_waypoint()
index 474568f205453a32be5cfe4a2902c14603706e0c..74c858d10b1b873b256d31fdba253363d637a475 100644 (file)
@@ -118,7 +118,7 @@ def main():
 
     m = WaypointMonitor(Stats.TYPE_SUBNET, subnet="10.0.0.0/31")
     m.set_waypoint("10.0.0.2")
-    m.set_large_flow_threshold(500) # 2000 bytes
+    m.set_large_flow_threshold(2000) # 2000 bytes
     m.start()
 
     # Register signal-handler to catch SIG_INT
index cb1c17dae0e3e0c88d17363932793f8455a65820..096da966255752967a054b7fa0acd76171d2be16 100644 (file)
@@ -47,8 +47,8 @@ class Stats:
             self.stats = analytics.stats_link(self.al, False)
             self.protocol_stats = analytics.all_stats_link(self.al, False)
         elif (self.stat_type == Stats.TYPE_SUBNET):
-            self.stats = analytics.stats_subnet("null/null", self.subnet, False)
-            self.protocol_stats = analytics.all_stats_subnet("null/null", self.subnet, False)
+            self.stats = analytics.stats_subnet("null/null", self.subnet, True)
+            self.protocol_stats = analytics.all_stats_subnet("null/null", self.subnet, True)
         try:
             is_fast = self.handle_rate_ewma()
             is_big = self.check_large_flow()