* Moved all l2 forwarding services based on OF to a separate OSGi
[affinity.git] / affinity / api / src / main / java / org / opendaylight / affinity / affinity / AffinityLink.java
1 package org.opendaylight.affinity.affinity;
2
3 import org.opendaylight.controller.sal.utils.NetUtils;
4 import java.io.Serializable;
5 import java.net.InetAddress;
6 import java.net.UnknownHostException;
7 import java.util.Map;
8 import java.util.HashMap;
9
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;
14
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;
27
28 import org.codehaus.enunciate.jaxrs.ResponseCode;
29 import org.codehaus.enunciate.jaxrs.StatusCodes;
30 import org.codehaus.enunciate.jaxrs.TypeHint;
31
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;
37 import org.opendaylight.affinity.affinity.AffinityAttribute;
38
39 @XmlRootElement
40 @XmlAccessorType(XmlAccessType.NONE)
41 public class AffinityLink implements Cloneable, Serializable {
42     private static final long serialVersionUID = 1L;
43
44     @XmlAttribute
45     private String name;
46     @XmlElement
47     AffinityGroup fromGroup;
48     @XmlElement
49     AffinityGroup toGroup;
50
51     // Keep at most one affinity attribute per type. 
52     private HashMap<AffinityAttributeType, AffinityAttribute> attrlist;
53     
54     // xxx 
55     @XmlElement 
56     String affinityAttribute;
57     @XmlElement 
58     String affinityWaypoint;
59
60     public AffinityLink() {
61         attrlist = new HashMap<AffinityAttributeType, AffinityAttribute>();
62     }
63     public AffinityLink(String name, AffinityGroup fromGroup, AffinityGroup toGroup) {
64         this.name = name;
65         this.fromGroup = fromGroup;
66         this.toGroup = toGroup;
67         attrlist = new HashMap<AffinityAttributeType, AffinityAttribute>();
68     }
69     public String getName() {
70         return this.name;
71     }
72     public void setName(String name) {
73         this.name = name;
74     }
75     public void setFromGroup(AffinityGroup fromGroup) {
76         this.fromGroup = fromGroup;
77     }
78     public void setToGroup(AffinityGroup toGroup) {
79         this.toGroup = toGroup;
80     }
81     public void addAttribute(AffinityAttribute attr) {
82         if (attr != null) {
83             System.out.println("Printing affinity attribute: " + attr.type);
84             attrlist.put(attr.type, attr);
85         }
86     }
87     public HashMap<AffinityAttributeType, AffinityAttribute> getAttributeList() {
88         return this.attrlist;
89     }
90
91     /* Set the waypoint address, if the attribute is "redirect" */
92     public void setAttribute(String attribute) {
93         this.affinityAttribute = attribute;
94     }
95     
96     // Create a service chain of one waypoint. 
97     public void setWaypoint(String wpaddr) {
98         SetPathRedirect redirect = new SetPathRedirect();
99         redirect.addWaypoint(NetUtils.parseInetAddress(wpaddr));
100         
101         /* Add this service chain to this affinity link. */
102         addAttribute((AffinityAttribute) redirect);
103     }
104
105     public AffinityAttribute getWaypoint() {
106         return attrlist.get(AffinityAttributeType.SET_PATH_REDIRECT);
107     }
108     
109     public boolean isDeny() {
110         return attrlist.containsKey(AffinityAttributeType.SET_DENY);
111     }
112
113     // Drop flows matching this affinity link
114     public void setDeny() {
115         SetDeny deny = new SetDeny();
116         addAttribute(deny);
117     }
118     public String getAttribute() {
119         return this.affinityAttribute;
120     }
121     public AffinityGroup getFromGroup() {
122         return this.fromGroup;
123     }
124     public AffinityGroup getToGroup() {
125         return this.toGroup;
126     }
127 }
128