org.opendaylight.controller.sal.packet,
org.opendaylight.controller.sal.inventory,
org.opendaylight.controller.sal.flowprogrammer,
- org.codehaus.enunciate.jaxrs,
+ !org.codehaus.enunciate.jaxrs,
org.slf4j
</Import-Package>
</instructions>
AffinityGroup toGroup;
// Keep at most one affinity attribute per type.
+ @XmlElement
private HashMap<AffinityAttributeType, AffinityAttribute> attrlist;
// xxx
addAttribute((AffinityAttribute) redirect);
}
+ // Unset the waypoint address.
+ public void unsetWaypoint() {
+ attrlist.remove(AffinityAttributeType.SET_PATH_REDIRECT);
+ }
+
public AffinityAttribute getWaypoint() {
return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
}
return attrlist.containsKey(AffinityAttributeType.SET_DENY);
}
- // Drop flows matching this affinity link
+ // Mark this with "deny"
public void setDeny() {
SetDeny deny = new SetDeny();
addAttribute(deny);
}
+
+ // Remove "deny" marking if it exists
+ public void unsetDeny() {
+ attrlist.remove(AffinityAttributeType.SET_DENY);
+ }
public String getAttribute() {
return this.affinityAttribute;
}
public AffinityGroup getToGroup() {
return this.toGroup;
}
+ @Override
+ public String toString() {
+ String output = this.name;
+
+ if (attrlist != null) {
+ for (AffinityAttribute a: attrlist.values()) {
+ output = output + "attr: " + a.toString() + "; ";
+ }
+ }
+ return output;
+ }
}
public HashMap<String, List<Flow>>getAllFlowGroups();
// For each flowgroup, there is a list of attributes. This api
- // call fetches this as a hashmap. Key of the outer hashmap is the
+ // call fetches this list as a hashmap. Key of the outer hashmap is the
// name of the affinity link (aka flowgroup). Key for the inner
// hashmap is the affinity attribute type.
public HashMap<String, HashMap<AffinityAttributeType,AffinityAttribute>>getAllAttributes();
+++ /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;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-import java.util.Set;
-import java.util.Collection;
-import java.util.Map.Entry;
-
-import org.opendaylight.controller.sal.core.Host;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-
-import org.opendaylight.affinity.affinity.AffinityLink;
-
-/**
- * Program flows in a flat layer 2 domain.
- */
-public interface IFlatL2AffinityManager {
-
- public Status addNfchain(AffinityLink al);
- public Status enableRedirect(AffinityLink al) throws Exception;
- public Status disableRedirect(AffinityLink al) throws Exception;
-
-}
public String toString() {
String string = type + "[";
for (InetAddress address: waypointList) {
- string = string + address.toString();
+ string = string + " -> " + address.toString();
}
string = string + "]";
return string;
<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,
+ org.opendaylight.affinity.l2agent,
+<!-- org.opendaylight.affinity.nfchainagent, -->
org.opendaylight.controller.clustering.services,
org.opendaylight.controller.configuration,
org.opendaylight.controller.hosttracker,
<artifactId>model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
- <dependency>
+<!-- <dependency>
<groupId>org.opendaylight.affinity</groupId>
<artifactId>nfchainagent</artifactId>
<version>0.4.1-SNAPSHOT</version>
- </dependency>
- <dependency>
+ </dependency> -->
+<!-- <dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-inet-types</artifactId>
<version>2010.09.24-SNAPSHOT</version>
- </dependency>
+ </dependency> -->
</dependencies>
</project>
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.opendaylight.affinity.l2agent.IfL2Agent;
import org.opendaylight.controller.hosttracker.IfIptoHost;
import org.opendaylight.controller.hosttracker.IfNewHostNotify;
-import org.opendaylight.affinity.l2agent.IfL2Agent;
-import org.opendaylight.affinity.nfchainagent.NFchainAgent;
-import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
/**
* AffinityManager Bundle Activator
c.setInterface(new String[] {
IAffinityManager.class.getName(),
ICacheUpdateAware.class.getName(),
- IfNewHostNotify.class.getName(),
IConfigurationContainerAware.class.getName() }, props);
// Now lets add a service dependency to make sure the
// provider of service exists
/* L2agent dependency causes the service to fail activation. tbd. */
+
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IfL2Agent.class)
+ .setCallbacks("setL2Agent", "unsetL2Agent")
+ .setRequired(true));
+
c.add(createContainerServiceDependency(containerName).setService(
IClusterContainerServices.class).setCallbacks(
"setClusterContainerService",
}
}
- /* Add a nfchain config for this affinity link. */
public List<Flow> getFlowlist(AffinityLink al) {
InetAddress from = null, to = null;
List<Flow> flowlist = getFlowlist(al);
flowgroups.put(al.getName(), flowlist);
}
+ for (String a: flowgroups.keySet()) {
+ log.info("Adding {} to flowgroups (# flows={})", a, flowgroups.get(a).size());
+ }
return flowgroups;
}
for (AffinityLink al: getAllAffinityLinks()) {
HashMap<AffinityAttributeType, AffinityAttribute> pergroupattrs = al.getAttributeList();
attributes.put(al.getName(), pergroupattrs);
+ log.info("Adding {} to attributes (# attributes={})", al.getName(), pergroupattrs.values().size());
}
return attributes;
}
--- /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);
+ }
+ }
+ }
+}
}
+ /**
+ * Returns details of an affinity link.
+ *
+ * @param containerName
+ * Name of the Container. The Container name for the base
+ * controller is "default".
+ * @param affinityLinkName
+ * Name of the affinity link being retrieved.
+ * @return affinity link details.
+ */
+ @Path("/{containerName}/link/{affinityLinkName}")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @TypeHint(AffinityLinkNorthbound.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(
+ @PathParam("containerName") String containerName,
+ @PathParam("affinityLinkName") String affinityLinkName) {
+ if (!NorthboundUtils.isAuthorized(
+ getUserName(), containerName, Privilege.READ, 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 "
+ + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ log.info("Get affinity link details" + affinityLinkName);
+ AffinityLink al = affinityManager.getAffinityLink(affinityLinkName);
+ if (al == null) {
+ throw new ResourceNotFoundException(RestMessages.SERVICEUNAVAILABLE.toString());
+ } else {
+ return new AffinityLinkNorthbound(al);
+ }
+ }
+
/**
* Add path redirect details to an affinity link.
*
AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
al1.setWaypoint(waypointIP);
+ 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 wayPoint
+ * IP address string of a waypoint server or VM
+ * @return Response as dictated by the HTTP Response Status code
+ */
+
+ @Path("/{containerName}/link/{affinityLinkName}/unsetwaypoint")
+ @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 setLinkWaypoint(
+ @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 waypoint setting (link)" + affinityLinkName);
+
+ AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+ al1.unsetWaypoint();
return Response.status(Response.Status.CREATED).build();
}
return Response.status(Response.Status.CREATED).build();
}
+
+
+ /**
+ * Remove the "deny" attribute if it exists.
+ * @param containerName
+ * Name of the Container
+ * @param affinityLinkName
+ * Name of the new affinity link being marked.
+ * @return Response as dictated by the HTTP Response Status code
+ */
+
+ @Path("/{containerName}/link/{affinityLinkName}/permit/")
+ @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 unsetLinkDeny(
+ @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 deny (link)" + affinityLinkName);
+
+ AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName);
+ al1.unsetDeny();
+ return Response.status(Response.Status.CREATED).build();
+ }
+
/**
* Add IP addresses to a group.
*
}
void start() {
+ log.info("Analytics manager started.!!!");
}
void started(){
+ log.info("Analytics manager started.!!!");
}
void stop() {
<module>analytics/implementation</module>
<module>analytics/integrationtest</module>
<module>analytics/northbound</module>
+ <module>l2agent</module>
<module>flatl2</module>
<module>flatl2/northbound</module>
</modules>
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"
- put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/setwaypoint/' + wp
+ al = 'inflows'
+ 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'
+ put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/unsetwaypoint'
+ rest_method(put_url, "PUT")
+
+def set_deny(setflag='deny'):
+ al = 'inflows'
+ put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/' + setflag + '/'
rest_method(put_url, "PUT")
-def enable_waypoint():
- put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/enable/'
+#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")
+
+def enable_affinity():
+ put_url = 'http://localhost:8080/affinity/nb/v2/flatl2/default/enableaffinity/'
rest_method(put_url, "PUT")
-def disable_waypoint():
- put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/disable/'
+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.
get_affinity_group('webservers')
get_affinity_group('clients')
+ get_affinity_link('inflows')
get_all_affinity_groups()
list_all_hosts()
+ # Set affinity attributes and make sure they are associated with the affinity link.
set_waypoint_address()
- enable_waypoint()
- disable_waypoint()
+ set_deny('deny')
+ set_deny('permit')
+ get_affinity_link('inflows')
+
+ enable_affinity()
+ disable_affinity()
+
+# enable_waypoint()
+# disable_waypoint()
#if __name__ == "__main__":
# main()
self.http = httplib2.Http(".cache")
self.http.add_credentials("admin", "admin")
self.url_prefix = "http://localhost:8080/affinity/nb/v2/affinity/default/"
+ self.flatl2url_prefix = "http://localhost:8080/affinity/nb/v2/flatl2/default/"
# Add affinity group
def add_affinity_group(self, group_name, **kwargs):
print "Waypoint could not be disabled for link %s" % link_name
return
print "Waypoint disabled for link %s" % link_name
+
+ # Enable all affinity rules
+ def enable_affinity(self):
+ resp, content = self.http.request(self.flatl2url_prefix + "enableaffinity", "PUT")
+ if (resp.status != 201):
+ print "Affinity rules could not be enabled."
+ return
+ print "Affinity rules enabled"
+
+ # Disable all affinity rules
+ def disable_affinity(self):
+ resp, content = self.http.request(self.flatl2url_prefix + "disableaffinity", "PUT")
+ if (resp.status != 201):
+ print "Affinity rules could not be disabled"
+ return
+ print "Affinity rules disabled"
link_name = "inflows"
ac.add_affinity_link(link_name, src_ag_name, dst_ag_name)
ac.add_waypoint(link_name, self.waypoint_address)
- ac.enable_waypoint(link_name)
+# ac.enable_waypoint(link_name)
+ ac.enable_affinity()
did_waypoint = True
- raw_input("[Press Enter to disable waypoint redirection] ")
- ac.disable_waypoint(link_name)
+ raw_input("[Press Enter to disable affinity rules] ")
+ ac.disable_affinity()
+# ac.disable_waypoint(link_name)
time.sleep(1)
def main():