* Cleanup test script.
Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
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>
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 {
@XmlAttribute
private String name;
+
@XmlElement
private final Map<String, AffinityIdentifier> elements;
// 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;
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;
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
attrlist.put(attr.type, attr);
}
}
+ @JsonIgnore
public HashMap<AffinityAttributeType, AffinityAttribute> getAttributeList() {
return this.attrlist;
}
}
/* Get the waypoint address */
+ @JsonIgnore
public AffinityAttribute getWaypoint() {
return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
}
}
/* 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);
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;
/**
* 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) {
@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;
+ }
}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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);
- }
- }
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+}
@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(
AffinityLink al = affinityManager.getAffinityLink(affinityLinkName);
if (al == null) {
throw new ResourceNotFoundException(RestMessages.SERVICEUNAVAILABLE.toString());
- } else {
- return new AffinityLinkNorthbound(al);
- }
+ }
+ return al;
}
/**
@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.");
+ RestMessages.SERVICEUNAVAILABLE.toString());
}
log.info("list all links");
- return new AffinityLinkList(affinityManager.getAllAffinityLinks());
+ return new AffinityLinks(affinityManager.getAllAffinityLinks());
}
/**
<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>
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")
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")
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")
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")
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")
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()