1 package org.opendaylight.affinity.affinity;
3 import org.opendaylight.controller.sal.utils.NetUtils;
4 import java.io.Serializable;
5 import java.net.InetAddress;
6 import java.net.UnknownHostException;
8 import java.util.HashMap;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.controller.sal.utils.Status;
13 import org.opendaylight.controller.sal.utils.StatusCode;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.PUT;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.core.Context;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.SecurityContext;
28 import org.codehaus.enunciate.jaxrs.ResponseCode;
29 import org.codehaus.enunciate.jaxrs.StatusCodes;
30 import org.codehaus.enunciate.jaxrs.TypeHint;
32 import javax.xml.bind.annotation.XmlAccessType;
33 import javax.xml.bind.annotation.XmlAccessorType;
34 import javax.xml.bind.annotation.XmlAttribute;
35 import javax.xml.bind.annotation.XmlElement;
36 import javax.xml.bind.annotation.XmlRootElement;
38 import com.fasterxml.jackson.annotation.JsonIgnore;
39 import org.opendaylight.affinity.affinity.AffinityAttribute;
42 @XmlAccessorType(XmlAccessType.NONE)
43 public class AffinityLink implements Cloneable, Serializable {
44 private static final long serialVersionUID = 1L;
49 AffinityGroup fromGroup;
51 AffinityGroup toGroup;
53 // Keep at most one affinity attribute per type.
55 private HashMap<AffinityAttributeType, AffinityAttribute> attrlist;
57 public AffinityLink() {
58 attrlist = new HashMap<AffinityAttributeType, AffinityAttribute>();
60 public AffinityLink(String name, AffinityGroup fromGroup, AffinityGroup toGroup) {
62 this.fromGroup = fromGroup;
63 this.toGroup = toGroup;
64 attrlist = new HashMap<AffinityAttributeType, AffinityAttribute>();
66 public String getName() {
69 public void setName(String name) {
72 public void setFromGroup(AffinityGroup fromGroup) {
73 this.fromGroup = fromGroup;
75 public void setToGroup(AffinityGroup toGroup) {
76 this.toGroup = toGroup;
78 public void addAttribute(AffinityAttribute attr) {
80 attrlist.put(attr.type, attr);
84 public HashMap<AffinityAttributeType, AffinityAttribute> getAttributeList() {
88 /* Set the waypoint address, if the attribute is "redirect" */
89 public void setWaypoint(String wpaddr) {
90 SetPathRedirect redirect = new SetPathRedirect();
91 redirect.addWaypoint(NetUtils.parseInetAddress(wpaddr));
93 /* Add this service chain to this affinity link. */
94 addAttribute((AffinityAttribute) redirect);
97 /* Get the waypoint address */
99 public AffinityAttribute getWaypoint() {
100 return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
103 // Unset the waypoint attribute.
104 public void unsetWaypoint() {
105 attrlist.remove(AffinityAttributeType.SET_PATH_REDIRECT);
108 // Add tap attribute.
109 public void addTap(String ipaddr) {
110 // Check if a tap attribute is already available on this link.
111 // If not, create one and add IP address to it.
112 AffinityAttributeType aatype = AffinityAttributeType.SET_TAP;
113 SetTap tap = (SetTap) attrlist.get(aatype);
119 tap.addTap(NetUtils.parseInetAddress(ipaddr));
121 /* Add this tap set to the affinity link. */
122 addAttribute((AffinityAttribute) tap);
125 // Add tap configuration.
126 public void removeTap(String ipaddr) {
127 // Check if a tap attribute is already available on this link.
128 AffinityAttributeType aatype = AffinityAttributeType.SET_TAP;
129 SetTap tap = (SetTap) attrlist.get(aatype);
131 // tap attribute exists. Remove IP address from its list of IP adresses.
133 tap.removeTap(NetUtils.parseInetAddress(ipaddr));
137 /* tbd requires nb method. */
139 public List<InetAddress> getTapList() {
140 // Check if a tap attribute is already available on this link.
141 SetTap tap = (SetTap) attrlist.get(AffinityAttributeType.SET_TAP);
143 return tap.getTapList();
148 public boolean isDeny() {
149 return attrlist.containsKey(AffinityAttributeType.SET_DENY);
152 // Mark this with "deny"
153 public void setDeny() {
154 SetDeny deny = new SetDeny();
158 // Remove "deny" marking if it exists
159 public void unsetDeny() {
160 attrlist.remove(AffinityAttributeType.SET_DENY);
163 // Mark this with "isolate"
164 public void setIsolate() {
165 SetPathIsolate iso = new SetPathIsolate();
168 public void unsetIsolate() {
169 attrlist.remove(AffinityAttributeType.SET_PATH_ISOLATE);
172 public AffinityGroup getFromGroup() {
173 return this.fromGroup;
175 public AffinityGroup getToGroup() {
179 public String toString() {
180 String output = this.name;
182 if (attrlist != null) {
183 for (AffinityAttribute a: attrlist.values()) {
184 output = output + "attr: " + a.toString() + "; ";