From: Suchi Raman Date: Tue, 10 Dec 2013 20:26:57 +0000 (-0500) Subject: * Moved all l2 forwarding services based on OF to a separate OSGi X-Git-Tag: jenkins-affinity-bulk-release-prepare-only-1~10 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=e24d68b40036d798089f3abc9147c67a0227b1a4;p=affinity.git * Moved all l2 forwarding services based on OF to a separate OSGi service/bundle (flatl2). * Flatl2 is for demo/test purposes only. In real released editions (eg., base vs. virtualization) other bundles must provide equivalent functionality. * Flatl2 has NB API methods to add affinity induced flow settings, and clear them. Also possible to enable/disable particular affinity link flow settings by name. * Switched to using flow rules manager API (instead of FPS). * AffinityManager is only a metadata repository. Signed-off-by: Suchi Raman Conflicts: l2agent/src/main/java/org/opendaylight/affinity/l2agent/L2Agent.java Signed-off-by: Suchi Raman --- diff --git a/affinity/api/pom.xml b/affinity/api/pom.xml index 922421a..0cdcbc8 100644 --- a/affinity/api/pom.xml +++ b/affinity/api/pom.xml @@ -45,7 +45,8 @@ 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 ${project.basedir}/META-INF diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttribute.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttribute.java new file mode 100644 index 0000000..6ae7da8 --- /dev/null +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttribute.java @@ -0,0 +1,73 @@ +package org.opendaylight.affinity.affinity; + +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Represents the attribute associated with an affinity link. + */ +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public abstract class AffinityAttribute implements Serializable { + private static final long serialVersionUID = 1L; + private static final Logger logger = LoggerFactory.getLogger(AffinityAttribute.class); + @XmlElement + protected AffinityAttributeType type; + private transient boolean isValid = true; + + /* Dummy constructor for JAXB */ + public AffinityAttribute() { + } + + public AffinityAttributeType getType() { + return type; + } + + /** + * Returns the id of this action + * + * @return String + */ + public String getId() { + return type.getId(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.calculateConsistentHashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AffinityAttribute other = (AffinityAttribute) obj; + if (type != other.type) { + return false; + } + return true; + } + + @Override + public String toString() { + return type.toString(); + } + +} diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttributeType.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttributeType.java new file mode 100644 index 0000000..965ab56 --- /dev/null +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityAttributeType.java @@ -0,0 +1,26 @@ +package org.opendaylight.affinity.affinity; + +/** + * The enumeration of affinity attributes. + */ +public enum AffinityAttributeType { + SET_DENY("deny"), + SET_PATH_REDIRECT("set_path_redirect"); + + String id; + + private AffinityAttributeType(String id) { + this.id = id; + } + public String getId() { + return id; + } + public int calculateConsistentHashCode() { + if (this.id != null) { + return this.id.hashCode(); + } else { + return 0; + } + } + +} diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityLink.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityLink.java index aa95f58..da92365 100644 --- a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityLink.java +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/AffinityLink.java @@ -34,6 +34,7 @@ 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 org.opendaylight.affinity.affinity.AffinityAttribute; @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) @@ -46,17 +47,24 @@ public class AffinityLink implements Cloneable, Serializable { AffinityGroup fromGroup; @XmlElement AffinityGroup toGroup; + + // Keep at most one affinity attribute per type. + private HashMap attrlist; + + // xxx @XmlElement String affinityAttribute; @XmlElement String affinityWaypoint; public AffinityLink() { + attrlist = new HashMap(); } public AffinityLink(String name, AffinityGroup fromGroup, AffinityGroup toGroup) { this.name = name; this.fromGroup = fromGroup; this.toGroup = toGroup; + attrlist = new HashMap(); } public String getName() { return this.name; @@ -70,16 +78,42 @@ public class AffinityLink implements Cloneable, Serializable { public void setToGroup(AffinityGroup toGroup) { this.toGroup = toGroup; } - public void setAttribute(String attribute) { - this.affinityAttribute = attribute; + public void addAttribute(AffinityAttribute attr) { + if (attr != null) { + System.out.println("Printing affinity attribute: " + attr.type); + attrlist.put(attr.type, attr); + } + } + public HashMap 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. public void setWaypoint(String wpaddr) { - this.affinityWaypoint = wpaddr; + SetPathRedirect redirect = new SetPathRedirect(); + redirect.addWaypoint(NetUtils.parseInetAddress(wpaddr)); + + /* Add this service chain to this affinity link. */ + addAttribute((AffinityAttribute) redirect); + } + + public AffinityAttribute getWaypoint() { + return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT); } - public String getWaypoint() { - return this.affinityWaypoint; + + public boolean isDeny() { + return attrlist.containsKey(AffinityAttributeType.SET_DENY); + } + + // Drop flows matching this affinity link + public void setDeny() { + SetDeny deny = new SetDeny(); + addAttribute(deny); } public String getAttribute() { return this.affinityAttribute; diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IAffinityManager.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IAffinityManager.java index 2af466c..d389622 100644 --- a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IAffinityManager.java +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IAffinityManager.java @@ -12,6 +12,7 @@ import java.net.InetAddress; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.HashMap; import java.util.concurrent.ConcurrentMap; import java.util.Set; import java.util.Collection; @@ -27,8 +28,7 @@ import org.opendaylight.controller.sal.flowprogrammer.Flow; import org.opendaylight.affinity.affinity.AffinityLink; /** - * Primary purpose of this interface is to provide methods for - * applications to set affinity configuration. + * Interface to class for maintaining affinity configuration. */ public interface IAffinityManager { @@ -53,13 +53,18 @@ public interface IAffinityManager { public List> getAllFlowsByHost(AffinityLink al); public List> getAllFlowsByAffinityIdentifier(AffinityLink al); + /** + * Returns a map of groupname, derived from affinity link name, to + * the list of flow objects corresponding to that link. This + * should be a consistent snapshot of all configured objects. + */ + public HashMap>getAllFlowGroups(); - /* Program the nf service chain for this affinity link. */ - /* Methods to add and enable network service chains. */ - public Status addNfchain(AffinityLink al); - public Status enableRedirect(AffinityLink al) throws Exception; - public Status disableRedirect(AffinityLink al) throws Exception; + // For each flowgroup, there is a list of attributes. This api + // call fetches this 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>getAllAttributes(); - // public Status addFlowRulesForRedirect(AffinityLink al) throws Exception; - // public Status pushFlowRule(InetAddress from, InetAddress to, byte [] mac); + public List getFlowlist(AffinityLink al); } diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IFlatL2AffinityManager.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IFlatL2AffinityManager.java new file mode 100644 index 0000000..6963fa1 --- /dev/null +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/IFlatL2AffinityManager.java @@ -0,0 +1,38 @@ +/* + * 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; + +} diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetDeny.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetDeny.java new file mode 100644 index 0000000..f5213e2 --- /dev/null +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetDeny.java @@ -0,0 +1,18 @@ +package org.opendaylight.affinity.affinity; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Represent the action of dropping matched flows. + */ +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class SetDeny extends AffinityAttribute { + private static final long serialVersionUID = 1L; + + public SetDeny() { + type = AffinityAttributeType.SET_DENY; + } +} diff --git a/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetPathRedirect.java b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetPathRedirect.java new file mode 100644 index 0000000..3e87d11 --- /dev/null +++ b/affinity/api/src/main/java/org/opendaylight/affinity/affinity/SetPathRedirect.java @@ -0,0 +1,72 @@ +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 SetPathRedirect extends AffinityAttribute { + private static final long serialVersionUID = 1L; + @XmlElement + private List waypointList; + + public SetPathRedirect() { + type = AffinityAttributeType.SET_PATH_REDIRECT; + waypointList = new ArrayList(); + } + + public List getWaypointList() { + return this.waypointList; + } + + public void addWaypoint(InetAddress ipaddr) { + waypointList.add(ipaddr); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + for (InetAddress address: waypointList) { + 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; + } + SetPathRedirect other = (SetPathRedirect) obj; + /* xxx check first element. */ + InetAddress address = waypointList.get(0); + List otherlist = other.getWaypointList(); + return waypointList.equals(otherlist); + } + + @Override + public String toString() { + String string = type + "["; + for (InetAddress address: waypointList) { + string = string + address.toString(); + } + string = string + "]"; + return string; + } +} + + + diff --git a/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/Activator.java b/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/Activator.java index 2c7d1d6..904c17a 100644 --- a/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/Activator.java +++ b/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/Activator.java @@ -100,32 +100,14 @@ public class Activator extends ComponentActivatorAbstractBase { // 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( - NFchainAgent.class).setCallbacks( - "setNFchainAgent", "unsetNFchainAgent") - .setRequired(true)); - c.add(createContainerServiceDependency(containerName) - .setService(IFlowProgrammerService.class) - .setCallbacks("setFlowProgrammerService", "unsetFlowProgrammerService") - .setRequired(true)); c.add(createContainerServiceDependency(containerName).setService( IClusterContainerServices.class).setCallbacks( "setClusterContainerService", "unsetClusterContainerService").setRequired(true)); + + // hosttracker is used to return the HostNodeConnector corresponding to an affinity ID. c.add(createContainerServiceDependency(containerName).setService(IfIptoHost.class) .setCallbacks("setHostTracker", "unsetHostTracker").setRequired(true)); - c.add(createContainerServiceDependency(containerName) - .setService(ISwitchManager.class) - .setCallbacks("setSwitchManager", "unsetSwitchManager") - .setRequired(true)); - c.add(createContainerServiceDependency(containerName).setService( - IAffinityManagerAware.class).setCallbacks( - "setAffinityManagerAware", "unsetAffinityManagerAware") - .setRequired(false)); } } } diff --git a/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java b/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java index 6e01bd7..edf37fe 100644 --- a/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java +++ b/affinity/implementation/src/main/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImpl.java @@ -8,23 +8,6 @@ package org.opendaylight.affinity.affinity.internal; - -import org.opendaylight.yang.gen.v1.affinity.rev130925.AffinityService; -import org.opendaylight.yang.gen.v1.affinity.rev130925.HostEndpoint; -import org.opendaylight.yang.gen.v1.affinity.rev130925.host_endpoint.L2address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; - -import org.opendaylight.yang.gen.v1.affinity.rev130925.CreategroupInput; -import org.opendaylight.yang.gen.v1.affinity.rev130925.AddendpointInput; - -import java.util.concurrent.Future; -import org.opendaylight.controller.sal.common.util.Futures; -import org.opendaylight.controller.sal.common.util.Rpcs; - -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; - - import java.io.FileNotFoundException; import java.io.IOException; import java.io.ObjectInputStream; @@ -67,9 +50,7 @@ import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.configuration.IConfigurationContainerAware; -//import org.opendaylight.controller.forwardingrulesmanager.FlowEntry; -//import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager; -import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService; +import org.opendaylight.controller.hosttracker.IfIptoHost; import org.opendaylight.controller.sal.flowprogrammer.Flow; import org.opendaylight.controller.sal.utils.IPProtocols; @@ -98,7 +79,6 @@ import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.NetUtils; -import org.opendaylight.controller.hosttracker.IfIptoHost; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -106,16 +86,10 @@ import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.affinity.affinity.AffinityGroup; import org.opendaylight.affinity.affinity.AffinityLink; import org.opendaylight.affinity.affinity.AffinityIdentifier; +import org.opendaylight.affinity.affinity.AffinityAttributeType; +import org.opendaylight.affinity.affinity.AffinityAttribute; import org.opendaylight.affinity.affinity.IAffinityManager; import org.opendaylight.affinity.affinity.IAffinityManagerAware; - -import org.opendaylight.controller.hosttracker.IfIptoHost; -import org.opendaylight.controller.hosttracker.IfNewHostNotify; -import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; -import org.opendaylight.controller.switchmanager.ISwitchManager; -import org.opendaylight.affinity.l2agent.IfL2Agent; -import org.opendaylight.affinity.nfchainagent.NFchainAgent; -import org.opendaylight.affinity.nfchainagent.NFchainconfig; import org.opendaylight.affinity.affinity.InetAddressMask; import org.slf4j.Logger; @@ -124,22 +98,17 @@ import org.slf4j.LoggerFactory; /** * Affinity configuration. */ -public class AffinityManagerImpl implements IAffinityManager, AffinityService, IfNewHostNotify, +public class AffinityManagerImpl implements IAffinityManager, IConfigurationContainerAware, IObjectReader, ICacheUpdateAware { private static final Logger log = LoggerFactory.getLogger(AffinityManagerImpl.class); private static String ROOT = GlobalConstants.STARTUPHOME.toString(); private static final String SAVE = "Save"; + + // write all objects to a single file. private String affinityLinkFileName = null; private String affinityGroupFileName = null; - // private IForwardingRulesManager ruleManager; - private IFlowProgrammerService programmer = null; - private NFchainAgent nfchainagent = null; - private ISwitchManager switchManager = null; - private IfL2Agent l2agent = null; - private IfIptoHost hostTracker = null; - private ConcurrentMap affinityGroupList; private ConcurrentMap affinityLinkList; private ConcurrentMap configSaveEvent; @@ -148,13 +117,13 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I private final Set affinityManagerAware = Collections .synchronizedSet(new HashSet()); - private byte[] MAC; private static boolean hostRefresh = true; private int hostRetryCount = 5; private IClusterContainerServices clusterContainerService = null; private String containerName = GlobalConstants.DEFAULT.toString(); private boolean isDefaultContainer = true; private static final int REPLACE_RETRY = 1; + private IfIptoHost hostTracker; private static short REDIRECT_IPSWITCH_PRIORITY = 3; @@ -258,89 +227,6 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I } - void setHostTracker(IfIptoHost h) { - log.info("Setting hosttracker {}", h); - this.hostTracker = h; - } - - void unsetHostTracker(IfIptoHost h) { - if (this.hostTracker.equals(h)) { - this.hostTracker = null; - } - } - /* public void setForwardingRulesManager( - IForwardingRulesManager forwardingRulesManager) { - log.debug("Setting ForwardingRulesManager"); - this.ruleManager = forwardingRulesManager; - } - - public void unsetForwardingRulesManager( - IForwardingRulesManager forwardingRulesManager) { - if (this.ruleManager == forwardingRulesManager) { - this.ruleManager = null; - } - } - */ - public void setFlowProgrammerService(IFlowProgrammerService s) - { - this.programmer = s; - } - - public void unsetFlowProgrammerService(IFlowProgrammerService s) { - if (this.programmer == s) { - this.programmer = null; - } - } - - void setNFchainAgent(NFchainAgent s) - { - log.info("Setting nfchainagent {}", s); - this.nfchainagent = s; - } - - void unsetNFchainAgent(NFchainAgent s) { - if (this.nfchainagent == s) { - this.nfchainagent = null; - } - } - - void setL2Agent(IfL2Agent s) - { - log.info("Setting l2agent {}", s); - this.l2agent = s; - } - - void unsetL2Agent(IfL2Agent s) { - if (this.l2agent == s) { - this.l2agent = null; - } - } - - void setSwitchManager(ISwitchManager s) - { - this.switchManager = s; - } - - void unsetSwitchManager(ISwitchManager s) { - if (this.switchManager == s) { - this.switchManager = null; - } - } - - /* - public void setForwardingRulesManager( - IForwardingRulesManager forwardingRulesManager) { - this.ruleManager = forwardingRulesManager; - } - - public void unsetForwardingRulesManager( - IForwardingRulesManager forwardingRulesManager) { - if (this.ruleManager == forwardingRulesManager) { - this.ruleManager = null; - } - } - */ - public Status addAffinityLink(AffinityLink al) { boolean putNewLink = false; @@ -367,14 +253,6 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I return new Status(StatusCode.SUCCESS); } - /* public byte [] InetAddressToMAC(InetAddress inetAddr) { - // HostNodeConnector - log.debug("Find {} -> {} using hostTracker {}", inetAddr, host, hostTracker); - byte [] dst_mac = host.getDataLayerAddressBytes(); - return dst_mac; - } - */ - public Status removeAffinityLink(String name) { affinityLinkList.remove(name); return new Status(StatusCode.SUCCESS); @@ -478,13 +356,11 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I public ArrayList getAllElementsByAffinityIdentifier(AffinityGroup ag) { return ag.getAllElements(); } - @Override public List getAllElementsByHost(AffinityGroup ag) { List hostList= new ArrayList(); for (AffinityIdentifier h : ag.getAllElements()) { - /* TBD: Do not assume this to be an InetAddress. */ h.print(); if (hostTracker != null) { Host host1 = hostTracker.hostFind((InetAddress) h.get()); @@ -514,7 +390,6 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I } return hostPairList; } - @Override public List> getAllFlowsByAffinityIdentifier(AffinityLink al) { List> hostPairList= new ArrayList>(); @@ -532,24 +407,6 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I return hostPairList; } - private void notifyHostUpdate(HostNodeConnector host, boolean added) { - if (host == null) { - return; - } - log.info("Host update received (new = {}).", added); - } - - @Override - public void notifyHTClient(HostNodeConnector host) { - notifyHostUpdate(host, true); - } - - @Override - public void notifyHTClientHostRemoved(HostNodeConnector host) { - notifyHostUpdate(host, false); - } - - @Override public Status saveConfiguration() { return saveAffinityConfig(); @@ -650,16 +507,27 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I log.debug("Cluster Service set for affinity mgr"); this.clusterContainerService = s; } - + void unsetClusterContainerService(IClusterContainerServices s) { if (this.clusterContainerService == s) { log.debug("Cluster Service removed for affinity mgr!"); this.clusterContainerService = null; } } - + + void setHostTracker(IfIptoHost h) { + log.info("Setting hosttracker {}", h); + this.hostTracker = h; + } + + void unsetHostTracker(IfIptoHost h) { + if (this.hostTracker.equals(h)) { + this.hostTracker = null; + } + } + /* Add a nfchain config for this affinity link. */ - List getFlowlist(AffinityLink al) { + public List getFlowlist(AffinityLink al) { InetAddress from = null, to = null; log.info("get flowlist affinity link = {}", al.getName()); @@ -706,59 +574,26 @@ public class AffinityManagerImpl implements IAffinityManager, AffinityService, I } return flowlist; } - - /* From affinity link, create a nfc config. Pass this nfc config to nfchainagent. */ - public Status addNfchain(AffinityLink al) { - List flowlist = getFlowlist(al); - InetAddress waypoint = NetUtils.parseInetAddress(al.getWaypoint()); - NFchainconfig nfcc = new NFchainconfig(al.getName(), flowlist, waypoint); - String key = al.getName(); - nfchainagent.addNfchain(key, nfcc); - log.info("Added nfchain {}", al.getName()); - return new Status(StatusCode.SUCCESS); + + public HashMap>getAllFlowGroups() { + HashMap> flowgroups = new HashMap>(); + for (AffinityLink al: getAllAffinityLinks()) { + List flowlist = getFlowlist(al); + flowgroups.put(al.getName(), flowlist); + } + return flowgroups; } - public Status enableRedirect(AffinityLink al) throws Exception { - String nfccname = al.getName(); - return nfchainagent.enable(nfccname); - } - - public Status disableRedirect(AffinityLink al) throws Exception { - String nfccname = al.getName(); - return nfchainagent.disable(nfccname); - } + public HashMap>getAllAttributes() { + HashMap>attributes = + new HashMap>(); - public Status removeNfchain(AffinityLink al) throws Exception { - String nfccname = al.getName(); - return nfchainagent.removeNfchain(nfccname); + + for (AffinityLink al: getAllAffinityLinks()) { + HashMap pergroupattrs = al.getAttributeList(); + attributes.put(al.getName(), pergroupattrs); + } + return attributes; } - - - /* public methods for the yang service. */ - public Future> creategroup(CreategroupInput input) { - AffinityGroup ag1 = new AffinityGroup(input.getName()); - - /* Correctly translate between status fields. */ - Status ret = addAffinityGroup(ag1); - RpcResult result = Rpcs. getRpcResult(true, null, Collections. emptySet()); - return Futures.immediateFuture(result); - } - public Future> addendpoint(AddendpointInput input) { - AffinityGroup ag = getAffinityGroup(input.getGroupname()); - RpcResult result; - - if (ag != null) { - HostEndpoint endpoint = input.getEndpoint(); - L2address l2address = endpoint.getL2address(); - Ipv4Prefix l3address = endpoint.getL3address(); - - /* ag.addL2address(); */ - ag.addInetMask(l3address.toString()); - result = Rpcs. getRpcResult(true, null, Collections. emptySet()); - } else { - result = Rpcs. getRpcResult(false, null, Collections. emptySet()); - } - return Futures.immediateFuture(result); - } } diff --git a/affinity/implementation/src/test/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImplTest.java b/affinity/implementation/src/test/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImplTest.java index 403f0b5..98170a4 100644 --- a/affinity/implementation/src/test/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImplTest.java +++ b/affinity/implementation/src/test/java/org/opendaylight/affinity/affinity/internal/AffinityManagerImplTest.java @@ -118,12 +118,12 @@ public class AffinityManagerImplTest { /* Test the get methods. */ /* Get all members as hosts */ - System.out.println("Affinity group (as Hosts) = " + ag1.getName()); - List hostlist = affinitymgr.getAllElementsByHost(ag1); + // System.out.println("Affinity group (as Hosts) = " + ag1.getName()); + // List hostlist = affinitymgr.getAllElementsByHost(ag1); - for (Host h : hostlist) { - System.out.println("host = " + h.getNetworkAddressAsString()); - } + // for (Host h : hostlist) { + // System.out.println("host = " + h.getNetworkAddressAsString()); + //} /* Get all members as affinity identifiers */ System.out.println("Affinity group (as Affinity Identifiers) = " + ag1.getName()); diff --git a/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java b/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java index 73bca80..6839e28 100644 --- a/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java +++ b/affinity/northbound/src/main/java/org/opendaylight/affinity/affinity/northbound/AffinityNorthbound.java @@ -229,7 +229,8 @@ public class AffinityNorthbound { Status ret = affinityManager.addAffinityLink(al1); if (!ret.isSuccess()) { - throw new InternalServerErrorException(ret.getDescription()); + // throw new InternalServerErrorException(ret.getDescription()); + log.error("Create affinity link {}", ret); } return Response.status(Response.Status.CREATED).build(); } @@ -273,52 +274,22 @@ public class AffinityNorthbound { log.info("Set waypoint address (link)" + affinityLinkName + " (waypoint ip) " + waypointIP); AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName); - al1.setWaypoint(waypointIP); - try { - affinityManager.addNfchain(al1); - } catch (Exception e) { - String message = "An error occurred during flow programming."; - log.error(message, e); - } + al1.setWaypoint(waypointIP); return Response.status(Response.Status.CREATED).build(); } - @Path("/{containerName}/link/{affinityLinkName}/enable") - @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 enableLink( - @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("Enable (link) " + affinityLinkName); - - AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName); - try { - affinityManager.enableRedirect(al1); - } catch (Exception e) { - String message = "An error occurred during flow programming."; - log.error(message, e); - } - return Response.status(Response.Status.CREATED).build(); - } + /** + * Mark this affinity link with "deny". + * + * @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}/disable") + @Path("/{containerName}/link/{affinityLinkName}/deny/") @PUT @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(Response.class) @@ -326,10 +297,10 @@ 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 disableLink( + public Response setLinkDeny( @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); @@ -340,15 +311,10 @@ public class AffinityNorthbound { throw new ServiceUnavailableException("Affinity Manager " + RestMessages.SERVICEUNAVAILABLE.toString()); } - log.info("Disable (link) " + affinityLinkName); + log.info("Set deny (link)" + affinityLinkName); AffinityLink al1 = affinityManager.getAffinityLink(affinityLinkName); - try { - affinityManager.disableRedirect(al1); - } catch (Exception e) { - String message = "An error occurred during flow programming."; - log.error(message, e); - } + al1.setDeny(); return Response.status(Response.Status.CREATED).build(); } @@ -465,6 +431,36 @@ public class AffinityNorthbound { return new AffinityGroupList(affinityManager.getAllAffinityGroups()); } + + + @Path("/{containerName}/affinity-links") + @GET + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(AffinityLinkList.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) { + + // if (!isValidContainer(containerName)) { + // throw new ResourceNotFoundException("Container " + containerName + " does not exist."); + //} + + 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 Manager " + + RestMessages.SERVICEUNAVAILABLE.toString()); + } + log.info("list all links"); + return new AffinityLinkList(affinityManager.getAllAffinityLinks()); + } + /** @Path("/{containerName}/") @GET diff --git a/l2agent/pom.xml b/l2agent/pom.xml deleted file mode 100644 index 4cdd22c..0000000 --- a/l2agent/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - 4.0.0 - - - org.opendaylight.affinity - affinityParent - 0.4.1-SNAPSHOT - .. - - - l2agent - 0.4.1-SNAPSHOT - bundle - - - - - org.apache.felix - maven-bundle-plugin - 2.3.6 - true - - - - org.opendaylight.controller.sal.core, - org.opendaylight.controller.sal.utils, - org.opendaylight.controller.sal.packet, - org.opendaylight.controller.sal.match, - org.opendaylight.controller.sal.action, - org.opendaylight.controller.sal.flowprogrammer, - org.opendaylight.controller.switchmanager, - org.apache.felix.dm, - org.osgi.service.component, - org.slf4j - - - org.opendaylight.affinity.l2agent - - - org.opendaylight.affinity.l2agent.Activator - - - ${project.basedir}/META-INF - - - - - - - org.opendaylight.controller - switchmanager - 0.4.0-SNAPSHOT - - - org.opendaylight.controller - sal - 0.5.0-SNAPSHOT - - - diff --git a/l2agent/src/main/java/org/opendaylight/affinity/l2agent/Activator.java b/l2agent/src/main/java/org/opendaylight/affinity/l2agent/Activator.java deleted file mode 100644 index 2549dcb..0000000 --- a/l2agent/src/main/java/org/opendaylight/affinity/l2agent/Activator.java +++ /dev/null @@ -1,98 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, 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.l2agent; - -import java.util.Hashtable; -import java.util.Dictionary; -import org.apache.felix.dm.Component; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; -import org.opendaylight.controller.sal.packet.IListenDataPacket; -import org.opendaylight.controller.sal.packet.IDataPacketService; -import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService; -import org.opendaylight.controller.switchmanager.ISwitchManager; - -public class Activator extends ComponentActivatorAbstractBase { - protected static final Logger logger = LoggerFactory - .getLogger(Activator.class); - - /** - * Function called when the activator starts just after some - * initializations are done by the - * ComponentActivatorAbstractBase. - * - */ - public void init() { - - } - - /** - * Function called when the activator stops just before the - * cleanup done by ComponentActivatorAbstractBase - * - */ - public void destroy() { - - } - - /** - * Function that is used to communicate to dependency manager the - * list of known implementations for services inside a container - * - * - * @return An array containing all the CLASS objects that will be - * instantiated in order to get an fully working implementation - * Object - */ - public Object[] getImplementations() { - Object[] res = { L2Agent.class }; - return res; - } - - /** - * Function that is called when configuration of the dependencies - * is required. - * - * @param c dependency manager Component object, used for - * configuring the dependencies exported and imported - * @param imp Implementation class that is being configured, - * needed as long as the same routine can configure multiple - * implementations - * @param containerName The containerName being configured, this allow - * also optional per-container different behavior if needed, usually - * should not be the case though. - */ - public void configureInstance(Component c, Object imp, String containerName) { - if (imp.equals(L2Agent.class)) { - // export the services - Dictionary props = new Hashtable(); - props.put("salListenerName", "L2Agent"); - c.setInterface(new String[] { IListenDataPacket.class.getName(), - IfL2Agent.class.getName() }, props); - - // register dependent modules - c.add(createContainerServiceDependency(containerName).setService( - ISwitchManager.class).setCallbacks("setSwitchManager", - "unsetSwitchManager").setRequired(true)); - - c.add(createContainerServiceDependency(containerName).setService( - IDataPacketService.class).setCallbacks( - "setDataPacketService", "unsetDataPacketService") - .setRequired(true)); - - c.add(createContainerServiceDependency(containerName).setService( - IFlowProgrammerService.class).setCallbacks( - "setFlowProgrammerService", "unsetFlowProgrammerService") - .setRequired(true)); - } - } -} diff --git a/l2agent/src/main/java/org/opendaylight/affinity/l2agent/IfL2Agent.java b/l2agent/src/main/java/org/opendaylight/affinity/l2agent/IfL2Agent.java deleted file mode 100644 index e7e28ae..0000000 --- a/l2agent/src/main/java/org/opendaylight/affinity/l2agent/IfL2Agent.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, 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 - */ - -/* - * Copyright (c) 2013 Plexxi, Inc. and others. All rights reserved. - */ - - -package org.opendaylight.affinity.l2agent; - -import java.net.InetAddress; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Node; - -public interface IfL2Agent { - - public NodeConnector lookup_output_port(Node node, byte [] dstMAC); - -} diff --git a/l2agent/src/test/java/org/opendaylight/l2agent/L2AgentTest.java b/l2agent/src/test/java/org/opendaylight/l2agent/L2AgentTest.java deleted file mode 100644 index d08c4e7..0000000 --- a/l2agent/src/test/java/org/opendaylight/l2agent/L2AgentTest.java +++ /dev/null @@ -1,29 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, 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.l2agent; - - -import junit.framework.TestCase; - -import org.junit.Assert; -import org.junit.Test; - -public class L2AgentTest extends TestCase { - - @Test - public void testL2AgentCreation() { - - L2Agent ah = null; - ah = new L2Agent(); - Assert.assertTrue(ah != null); - - } - -} diff --git a/nfchain/api/pom.xml b/nfchain/api/pom.xml deleted file mode 100644 index 00e6454..0000000 --- a/nfchain/api/pom.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - 4.0.0 - - org.opendaylight.affinity - affinityParent - 0.4.1-SNAPSHOT - ../.. - - - org.opendaylight.affinity - nfchain.api - 0.4.1-SNAPSHOT - bundle - - - scm:git:ssh://git.opendaylight.org:29418/affinity.git - scm:git:ssh://git.opendaylight.org:29418/affinity.git - - - - 0.5.9-SNAPSHOT - 0.5.8-SNAPSHOT - UTF-8 - 1.7 - 1.7 - 2.4.0 - http://nexus.opendaylight.org/content - - - - - - - org.apache.felix - maven-bundle-plugin - 2.3.6 - true - - - org.opendaylight.yangtools - yang-maven-plugin - ${yang.version} - - - - generate-sources - - - src/main/yang - - - - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl - - - target/generated-sources/sal - - - - true - - - - - - org.opendaylight.yangtools - maven-sal-api-gen-plugin - ${yang.codegen.version} - jar - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - generate-sources - - add-source - - - - target/generated-sources/sal - - - - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.opendaylight.yangtools - - - yang-maven-plugin - - - [0.5,) - - - - generate-sources - - - - - - - - - - - - - - - - - - - - org.opendaylight.controller.model - model-inventory - 1.0-SNAPSHOT - - - - org.opendaylight.yangtools - yang-binding - ${yang.version} - - - org.opendaylight.yangtools - yang-common - ${yang.version} - - - org.opendaylight.yangtools.model - ietf-inet-types - 2010.09.24-SNAPSHOT - - - org.opendaylight.yangtools.model - ietf-yang-types - 2010.09.24-SNAPSHOT - - - - org.opendaylight.yangtools.model - opendaylight-l2-types - 2013.08.27.1-SNAPSHOT - - - org.opendaylight.controller.model - model-flow-base - 1.0-SNAPSHOT - - - - diff --git a/nfchain/api/src/main/yang/nfchain.yang b/nfchain/api/src/main/yang/nfchain.yang deleted file mode 100644 index 68bce28..0000000 --- a/nfchain/api/src/main/yang/nfchain.yang +++ /dev/null @@ -1,87 +0,0 @@ -module nfchain { - namespace "urn:opendaylight:affinity:nfchain"; - prefix nfchain; - - import ietf-inet-types { prefix inet; } - import ietf-yang-types { prefix yang; } - import yang-ext { prefix ext; } - import opendaylight-inventory {prefix inv;} - import opendaylight-l2-types { prefix l2types; } - import opendaylight-flow-types { prefix flow-types; } - - revision "2013-10-20" { - description "Initial revision of affinity model to be reviewed"; - } - - //************************************************** - // Gateway hosting the network function. - //************************************************** - grouping gateway { - leaf id { - type string; - } - // xxx address is an IP prefix. - leaf location { - description "Inet address"; - type inet:ipv4-prefix; - } - } - - // Each nf chain has an id, a flowspec and a list of gateways. - grouping chain { - leaf name { - type string; - } - - list flow { - uses flow-types:flow; - } - - list gateway { - key id; - ext:context-instance "gateway-context"; - uses gateway; - } - } - - // Container for all nf_chain objects - container nfdb { - list chain { - key id; - ext:context-instance "chain-context"; - uses chain; - } - } - - identity gateway-context; - - typedef gateway-ref { - type instance-identifier; - } - - // nf chain reference. - typedef chain-ref { - type instance-identifier; - } - identity chain-context; - - //************************************************** - // Add a chain to the service. - //************************************************** - rpc addchain { - input { - container chain { - uses chain; - } - } - } - - rpc enablechain { - input { - leaf chain { - type chain-ref; - } - } - } - -} diff --git a/nfchain/impl/pom.xml b/nfchain/impl/pom.xml deleted file mode 100644 index e6f4a32..0000000 --- a/nfchain/impl/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - 4.0.0 - - - - org.opendaylight.affinity - affinityParent - 0.4.1-SNAPSHOT - ../.. - - - org.opendaylight.affinity - nfchain-impl - 0.4.1-SNAPSHOT - bundle - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL - - - - - - - org.apache.felix - maven-bundle-plugin - 2.3.6 - true - - - org.opendaylight.affinity.nfchain.provider.Activator - - - - - - - - - ${project.groupId} - nfchain.api - ${project.version} - - - org.opendaylight.affinity - nfchainagent - 0.4.1-SNAPSHOT - - - org.opendaylight.controller - sal-compability - 1.0-SNAPSHOT - - - org.opendaylight.controller - hosttracker - 0.4.1-SNAPSHOT - - - org.opendaylight.controller - sal-binding-api - 1.0-SNAPSHOT - - - org.opendaylight.controller - sal-common-util - 1.0-SNAPSHOT - - - diff --git a/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/Activator.java b/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/Activator.java deleted file mode 100644 index 8cd2801..0000000 --- a/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/Activator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, 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 - */ - -/* - * Copyright (c) 2013 Plexxi, Inc. and others. All rights reserved. - */ - -package org.opendaylight.affinity.nfchain.provider; - -import java.util.Dictionary; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Set; -import java.util.Collection; -import java.util.Collections; - -import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; - -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.hosttracker.IfIptoHost; -import org.opendaylight.controller.hosttracker.IfNewHostNotify; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.NfchainService; - -public class Activator extends AbstractBindingAwareProvider { - protected static final Logger log = LoggerFactory - .getLogger(Activator.class); - - private ProviderContext providerContext; - private NfchainManager nfcmgr; - - public Activator() { - nfcmgr = new NfchainManager(); - } - - @Override - public void onSessionInitiated(ProviderContext session) { - log.info("Provider session initialized"); - - this.providerContext = session; - nfcmgr.setNotificationProvider(session.getSALService(NotificationProviderService.class)); - providerContext.addRpcImplementation(NfchainService.class, nfcmgr); - } - - @Override - public Collection getImplementations() { - return Collections.emptySet(); - } - - @Override - public Collection getFunctionality() { - return Collections.emptySet(); - } -} diff --git a/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/NfchainManager.java b/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/NfchainManager.java deleted file mode 100644 index e900152..0000000 --- a/nfchain/impl/src/main/java/org/opendaylight/affinity/nfchain/provider/NfchainManager.java +++ /dev/null @@ -1,128 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, 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.nfchain.provider; - -import java.util.Collections; -import java.util.List; -import java.util.ArrayList; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; -import org.opendaylight.controller.sal.common.util.Futures; -import org.opendaylight.controller.sal.common.util.Rpcs; - -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.NfchainService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.NfchainData; -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.NfdbBuilder; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.chain.Gateway; -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.Nfdb; -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.NfdbBuilder; - - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.AddchainInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.EnablechainInput; - -import org.opendaylight.affinity.nfchainagent.NFchainconfig; - -import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.packet.BitBufferHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.hosttracker.IfIptoHost; -import org.opendaylight.controller.hosttracker.IfNewHostNotify; - - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.addchain.input.Chain; -import java.net.InetAddress; -import org.opendaylight.controller.sal.compability.ToSalConversionsUtils; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.affinity.nfchain.rev131020.chain.Flow; - -/** - * NfchainManager -- sends flow programming rules to flow programming service. - */ -public class NfchainManager implements NfchainService, NfchainData { - private static final long serialVersionUID = 1L; - protected static final Logger log = LoggerFactory.getLogger(NfchainManager.class); - - private NotificationProviderService notificationProvider; - private Future> currentTask; - - public NfchainManager() { - } - - @Override - public Nfdb getNfdb() { - NfdbBuilder builder = new NfdbBuilder(); - return builder.build(); - } - - /** - * Convert API Flow objects to flow programmer flow objects. - */ - List fromAPIFlowlist(List fl) { - List flowlist = new ArrayList(); - - for (Flow f: fl) { - org.opendaylight.controller.sal.flowprogrammer.Flow fp_flow = ToSalConversionsUtils.toFlow(f); - flowlist.add(fp_flow); - } - return flowlist; - } - - /** - * addchain synchronous. - */ - @Override - public Future> addchain(AddchainInput input) { - // TODO Auto-generated method stub - Chain chain = input.getChain(); - - List flowlist = fromAPIFlowlist(chain.getFlow()); - List gatewaylist = chain.getGateway(); - String name = chain.getName(); - - if (gatewaylist.size() > 1) { - log.info("addNfchain function chain has {} elements", gatewaylist.size()); - } else { - - log.info("add gateway - Received input chain = {}, gateway = {}.", input.getChain(), chain.getGateway()); - Gateway gw = gatewaylist.get(0); - InetAddress ip = ToSalConversionsUtils.inetAddressFrom(gw.getLocation()); - NFchainconfig nfcc = new NFchainconfig(name, flowlist, ip); - /* nfchainagent.addNfchain(); */ - } - RpcResult result = Rpcs. getRpcResult(true, null, Collections. emptySet()); - return Futures.immediateFuture(result); - } - - @Override - public Future> enablechain(EnablechainInput input) { - log.info("enable chain"); - - RpcResult result = Rpcs. getRpcResult(true, null, Collections. emptySet()); - return Futures.immediateFuture(result); - } - - public void setNotificationProvider(NotificationProviderService salService) { - this.notificationProvider = salService; - } -} diff --git a/nfchain/pom.xml b/nfchain/pom.xml deleted file mode 100644 index fe28724..0000000 --- a/nfchain/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - 4.0.0 - - org.opendaylight.affinity - affinityParent - 0.4.1-SNAPSHOT - - - pom - org.opendaylight.affinity - nfchain - 0.4.1-SNAPSHOT - - - scm:git:ssh://git.opendaylight.org:29418/affinity.git - scm:git:ssh://git.opendaylight.org:29418/affinity.git - - - - api - impl - - diff --git a/nfchainagent/pom.xml b/nfchainagent/pom.xml deleted file mode 100644 index a116037..0000000 --- a/nfchainagent/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - 4.0.0 - - org.opendaylight.affinity - affinityParent - 0.4.1-SNAPSHOT - .. - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - - - org.opendaylight.affinity - nfchainagent - 0.4.1-SNAPSHOT - bundle - - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - - org.opendaylight.controller.sal.utils, - org.opendaylight.controller.sal.core, - org.opendaylight.controller.forwardingrulesmanager, - org.opendaylight.controller.hosttracker, - org.opendaylight.controller.hosttracker.hostAware, - org.opendaylight.controller.switchmanager, - org.opendaylight.controller.clustering.services, - org.opendaylight.controller.sal.action, - org.opendaylight.controller.sal.flowprogrammer, - org.opendaylight.controller.sal.match, - org.opendaylight.controller.sal.packet, - org.opendaylight.controller.sal.routing, - org.opendaylight.controller.topologymanager, - org.apache.commons.lang3.builder, - org.opendaylight.affinity.l2agent, - org.junit;resolution:=optional, - org.slf4j, - org.apache.felix.dm, - javax.xml.bind.annotation - - - org.opendaylight.affinity.nfchainagent - - - org.opendaylight.affinity.nfchainagent.Activator - - - ${project.basedir}/META-INF - - - - - - - org.opendaylight.controller - hosttracker - 0.4.0-SNAPSHOT - - - junit - junit - ${junit.version} - - - org.opendaylight.affinity - l2agent - 0.4.1-SNAPSHOT - - - org.opendaylight.affinity - affinity - 0.4.1-SNAPSHOT - - - diff --git a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/Activator.java b/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/Activator.java deleted file mode 100644 index ce95957..0000000 --- a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/Activator.java +++ /dev/null @@ -1,105 +0,0 @@ - -/* - * Copyright (c) 2013 Cisco Systems, 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 - */ - -/* Network function chaining service. */ -package org.opendaylight.affinity.nfchainagent; - -import java.util.Hashtable; -import java.util.Dictionary; -import org.apache.felix.dm.Component; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; -import org.opendaylight.controller.sal.packet.IListenDataPacket; -import org.opendaylight.controller.sal.packet.IDataPacketService; -import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService; -import org.opendaylight.controller.switchmanager.ISwitchManager; - -import org.opendaylight.controller.hosttracker.IfIptoHost; -import org.opendaylight.affinity.l2agent.IfL2Agent; -import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService; -//import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager; - -public class Activator extends ComponentActivatorAbstractBase { - protected static final Logger logger = LoggerFactory - .getLogger(Activator.class); - - /** - * Function called when the activator starts just after some - * initializations are done by the - * ComponentActivatorAbstractBase. - * - */ - public void init() { - - } - - /** - * Function called when the activator stops just before the - * cleanup done by ComponentActivatorAbstractBase - * - */ - public void destroy() { - - } - - /** - * Function that is used to communicate to dependency manager the - * list of known implementations for services inside a container - * - * - * @return An array containing all the CLASS objects that will be - * instantiated in order to get an fully working implementation - * Object - */ - public Object[] getImplementations() { - Object[] res = { NFchainAgent.class }; - return res; - } - - /** - * Function that is called when configuration of the dependencies - * is required. - * - * @param c dependency manager Component object, used for - * configuring the dependencies exported and imported - * @param imp Implementation class that is being configured, - * needed as long as the same routine can configure multiple - * implementations - * @param containerName The containerName being configured, this allow - * also optional per-container different behavior if needed, usually - * should not be the case though. - */ - public void configureInstance(Component c, Object imp, String containerName) { - if (imp.equals(NFchainAgent.class)) { - // export the services - Dictionary props = new Hashtable(); - props.put("salListenerName", "NFchainAgent"); - c.setInterface(new String[] { NFchainAgent.class.getName() }, props); - - // register dependent modules - c.add(createContainerServiceDependency(containerName) - .setService(IfL2Agent.class) - .setCallbacks("setL2Agent", "unsetL2Agent") - .setRequired(true)); - c.add(createContainerServiceDependency(containerName).setService(IfIptoHost.class) - .setCallbacks("setHostTracker", "unsetHostTracker").setRequired(true)); - - c.add(createContainerServiceDependency(containerName).setService( - ISwitchManager.class).setCallbacks("setSwitchManager", - "unsetSwitchManager").setRequired(true)); - - c.add(createContainerServiceDependency(containerName).setService( - IFlowProgrammerService.class).setCallbacks( - "setFlowProgrammerService", "unsetFlowProgrammerService") - .setRequired(true)); - } - } -} diff --git a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainAgent.java b/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainAgent.java deleted file mode 100644 index ebabdaa..0000000 --- a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainAgent.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2013 Plexxi, Inc. 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.nfchainagent; - -import java.lang.Short; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.opendaylight.controller.sal.utils.NetUtils; -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.affinity.affinity.IAffinityManager; -import org.opendaylight.controller.hosttracker.IfIptoHost; -import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector; -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.flowprogrammer.Flow; -import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService; -import org.opendaylight.controller.sal.action.Action; -import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.match.Match; -import org.opendaylight.controller.sal.match.MatchField; -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.packet.address.EthernetAddress; - -import org.opendaylight.affinity.l2agent.IfL2Agent; -import org.opendaylight.controller.switchmanager.ISwitchManager; - -import java.io.Serializable; - -public class NFchainAgent implements Serializable { - - private static final Logger log = LoggerFactory.getLogger(NFchainAgent.class); - private IFlowProgrammerService programmer = null; - private IfL2Agent l2agent = null; - private IfIptoHost hostTracker = null; - private ISwitchManager switchManager = null; - - private HashMap allconfigs; - - void init() { - log.debug("INIT called!"); - } - - void destroy() { - log.debug("DESTROY called!"); - } - - void start() { - log.debug("START called!"); - } - - void started(){ - } - - void stop() { - log.debug("STOP called!"); - } - - void setHostTracker(IfIptoHost h) { - log.info("Setting hosttracker {}", h); - this.hostTracker = h; - } - - void unsetHostTracker(IfIptoHost h) { - if (this.hostTracker.equals(h)) { - this.hostTracker = null; - } - } - public void setFlowProgrammerService(IFlowProgrammerService s) - { - this.programmer = s; - } - - public void unsetFlowProgrammerService(IFlowProgrammerService s) { - if (this.programmer == s) { - this.programmer = null; - } - } - void setL2Agent(IfL2Agent s) - { - log.info("Setting l2agent {}", s); - this.l2agent = s; - } - - void unsetL2Agent(IfL2Agent s) { - if (this.l2agent == s) { - this.l2agent = null; - } - } - - void setSwitchManager(ISwitchManager s) - { - this.switchManager = s; - } - - void unsetSwitchManager(ISwitchManager s) { - if (this.switchManager == s) { - this.switchManager = null; - } - } - - public Status addNfchain(String key, NFchainconfig nfcc) { - String name; - - if (allconfigs == null) { - allconfigs = new HashMap(); - } - /* xxx compute changelist and push flow changes. */ - if (allconfigs.containsKey(key)) { - return new Status(StatusCode.CONFLICT, - "NFchain with the specified name already configured."); - } - NFchainconfig oldcfg = allconfigs.get(key); - if (oldcfg == null) { - if (allconfigs.put(key, nfcc) == null) { - return new Status(StatusCode.SUCCESS); - } - } - return new Status(StatusCode.CONFLICT, - "Unknown error during addNFchain."); - } - - /** - * add flow rules for set of flows in nfchainconfig. Do this for - * each node connector in the network proactively. - */ - public Status addrules(Node node, NFchainconfig nfcc) throws Exception { - List flowlist = nfcc.getFlowList(); - for (Flow f: flowlist) { - HostNodeConnector wphost = (HostNodeConnector) hostTracker.hostFind(nfcc.getWaypointIP()); - List actions = new ArrayList(); - /* Look up the output port leading to the waypoint. */ - NodeConnector dst_connector = l2agent.lookup_output_port(node, wphost.getDataLayerAddressBytes()); - - log.debug("Waypoint direction added: node {} and connector {}", node, dst_connector); - if (dst_connector != null) { - f.setActions(actions); - f.addAction(new Output(dst_connector)); - log.debug("flow push add flow = {} to node = {} ", f, node); - Status status = programmer.addFlow(node, f); - if (!status.isSuccess()) { - log.debug("Error during addFlow: {} on {}. The failure is: {}", - f, node, status.getDescription()); - } - } - } - return new Status(StatusCode.SUCCESS); - } - - - - /** - * remove flow rules for set of flows in nfchainconfig. Do this for - * each node connector in the network proactively. - */ - public Status removerules(Node node, NFchainconfig nfcc) throws Exception { - List flowlist = nfcc.getFlowList(); - for (Flow f: flowlist) { - HostNodeConnector wphost = (HostNodeConnector) hostTracker.hostFind(nfcc.getWaypointIP()); - List actions = new ArrayList(); - /* Look up the output port leading to the waypoint. */ - NodeConnector dst_connector = l2agent.lookup_output_port(node, wphost.getDataLayerAddressBytes()); - - log.debug("Waypoint settings removed: node {} and connector {}", node, dst_connector); - if (dst_connector != null) { - f.setActions(actions); - f.addAction(new Output(dst_connector)); - log.debug("flow push remove flow = {} to node = {} ", f, node); - Status status = programmer.removeFlow(node, f); - if (!status.isSuccess()) { - log.debug("Error during removeFlow: {} on {}. The failure is: {}", - f, node, status.getDescription()); - } - } - } - return new Status(StatusCode.SUCCESS); - } - - - public Status removeNfchain(String key) { - if (allconfigs != null) { - allconfigs.remove(key); - } - return new Status(StatusCode.SUCCESS); - } - - /** - * Enable the nfchain by programming flow rules on its behalf. - */ - public Status enable(String cfgname) throws Exception { - /* Get all node connectors. */ - Set nodes = switchManager.getNodes(); - NFchainconfig cfg = allconfigs.get(cfgname); - - Status success = new Status(StatusCode.SUCCESS); - Status notfound = new Status(StatusCode.NOTFOUND); - Status ret; - - if (nodes == null) { - log.debug("No nodes in network."); - return success; - } - - /* Send this flow rule to all nodes in the network. */ - for (Node node: nodes) { - ret = addrules(node, cfg); - } - return new Status(StatusCode.SUCCESS); - } - - /** - * Remove openflow rules added earlier. Restore default routing via standard L2 learning methods. - */ - public Status disable(String cfgname) throws Exception { - /* Get all node connectors. */ - Set nodes = switchManager.getNodes(); - NFchainconfig cfg = allconfigs.get(cfgname); - - Status success = new Status(StatusCode.SUCCESS); - Status notfound = new Status(StatusCode.NOTFOUND); - Status ret; - - if (nodes == null) { - log.debug("No nodes in network."); - return success; - } - - /* Send this flow rule to all nodes in the network. */ - for (Node node: nodes) { - ret = removerules(node, cfg); - } - return new Status(StatusCode.SUCCESS); - } -} - diff --git a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainconfig.java b/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainconfig.java deleted file mode 100644 index 0a7211e..0000000 --- a/nfchainagent/src/main/java/org/opendaylight/affinity/nfchainagent/NFchainconfig.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.opendaylight.affinity.nfchainagent; - -import org.opendaylight.controller.sal.utils.NetUtils; -import java.io.Serializable; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.List; -import java.util.ArrayList; - -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.SecurityContext; - -import org.codehaus.enunciate.jaxrs.ResponseCode; -import org.codehaus.enunciate.jaxrs.StatusCodes; -import org.codehaus.enunciate.jaxrs.TypeHint; - -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; - -import org.opendaylight.controller.sal.flowprogrammer.Flow; - -/** - * Configuration object representing a network function chain. - * flowlist is the set of flows to be redirected. - * dstIP is the singleton waypoint, representing the waypoint server. - */ - -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) -public class NFchainconfig implements Cloneable, Serializable { - private static final long serialVersionUID = 1L; - - @XmlAttribute - private String name; - @XmlElement - private final List flowlist; - private InetAddress dstIP; - - public NFchainconfig(String name) { - this.name = name; - flowlist = new ArrayList(); - dstIP = null; - } - - // Set the flowlist and destination IP of the network function. - public NFchainconfig(String name, List flowlist, InetAddress dstIP) { - this.name = name; - this.flowlist = flowlist; - this.dstIP = dstIP; - } - - // add a flow to the flowlist. - public Status addFlow(Flow f) { - flowlist.add(f); - return new Status(StatusCode.SUCCESS); - } - - public List getFlowList() { - return this.flowlist; - } - public InetAddress getWaypointIP() { - return this.dstIP; - } - public void print() { - System.out.println("Printing NFchain config " + this.name); - for (Flow value : flowlist) { - System.out.println("flow is " + value); - } - } - public String getName() { - return name; - } -} - - diff --git a/pom.xml b/pom.xml index 6ef738b..d58eb1e 100644 --- a/pom.xml +++ b/pom.xml @@ -46,11 +46,11 @@ -Xmx1024m -XX:MaxPermSize=256m 1.5.0 3.6.0.RELEASE + 0.5.1-SNAPSHOT affinity/api - affinity/yang affinity/implementation affinity/integrationtest affinity/northbound @@ -58,8 +58,8 @@ analytics/implementation analytics/integrationtest analytics/northbound - l2agent - nfchainagent + flatl2 + flatl2/northbound