blob: 29898e6c538691a22aa95d1f3d095735b468d957 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pankaj Berde6a97eb82013-03-28 12:12:43 -07003import java.util.ArrayList;
4
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07005import net.floodlightcontroller.util.MACAddress;
HIGUCHI Yuta20514902013-06-12 11:24:16 -07006import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
7import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07008import net.onrc.onos.ofcontroller.util.FlowEntryMatch;
9import net.onrc.onos.ofcontroller.util.FlowId;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010
11import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012
13/**
14 * The class representing the Flow Path.
15 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070016public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017 private FlowId flowId; // The Flow ID
18 private CallerId installerId; // The Caller ID of the path installer
19 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070020 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
21 // Flow Entries
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080022
23 /**
24 * Default constructor.
25 */
26 public FlowPath() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080027 dataPath = new DataPath();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080028 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070029
Pankaj Berde6a97eb82013-03-28 12:12:43 -070030 /**
31 * Constructor to instantiate from object in Network Map
32 */
33 public FlowPath(IFlowPath flowObj) {
34 dataPath = new DataPath();
35 this.setFlowId(new FlowId(flowObj.getFlowId()));
36 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
37 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
38 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
39 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
40 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070041 //
42 // Extract the match conditions that are common for all Flow Entries
43 //
44 {
45 FlowEntryMatch match = new FlowEntryMatch();
46 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
47 if (matchEthernetFrameType != null)
48 match.enableEthernetFrameType(matchEthernetFrameType);
49 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
50 if (matchSrcIPv4Net != null)
51 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
52 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
53 if (matchDstIPv4Net != null)
54 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
55 String matchSrcMac = flowObj.getMatchSrcMac();
56 if (matchSrcMac != null)
57 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
58 String matchDstMac = flowObj.getMatchDstMac();
59 if (matchDstMac != null)
60 match.enableDstMac(MACAddress.valueOf(matchDstMac));
61 this.setFlowEntryMatch(match);
62 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070063
64 //
65 // Extract all Flow Entries
66 //
67 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
68 for (IFlowEntry flowEntryObj : flowEntries) {
69 FlowEntry flowEntry = new FlowEntry();
70 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
71 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
72
73 //
74 // Extract the match conditions
75 //
76 FlowEntryMatch match = new FlowEntryMatch();
77 Short matchInPort = flowEntryObj.getMatchInPort();
78 if (matchInPort != null)
79 match.enableInPort(new Port(matchInPort));
80 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
81 if (matchEthernetFrameType != null)
82 match.enableEthernetFrameType(matchEthernetFrameType);
83 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
84 if (matchSrcIPv4Net != null)
85 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
86 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
87 if (matchDstIPv4Net != null)
88 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
89 String matchSrcMac = flowEntryObj.getMatchSrcMac();
90 if (matchSrcMac != null)
91 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
92 String matchDstMac = flowEntryObj.getMatchDstMac();
93 if (matchDstMac != null)
94 match.enableDstMac(MACAddress.valueOf(matchDstMac));
95 flowEntry.setFlowEntryMatch(match);
96
97 //
98 // Extract the actions
99 //
100 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
101 Short actionOutputPort = flowEntryObj.getActionOutput();
102 if (actionOutputPort != null) {
103 FlowEntryAction action = new FlowEntryAction();
104 action.setActionOutput(new Port(actionOutputPort));
105 actions.add(action);
106 }
107 flowEntry.setFlowEntryActions(actions);
108
109 String userState = flowEntryObj.getUserState();
110 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
111 String switchState = flowEntryObj.getSwitchState();
112 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
113 //
114 // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
115 // and FlowEntryErrorState.
116 //
117 this.dataPath().flowEntries().add(flowEntry);
118 }
119 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800120
121 /**
122 * Get the flow path Flow ID.
123 *
124 * @return the flow path Flow ID.
125 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800126 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800127 public FlowId flowId() { return flowId; }
128
129 /**
130 * Set the flow path Flow ID.
131 *
132 * @param flowId the flow path Flow ID to set.
133 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800134 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800135 public void setFlowId(FlowId flowId) {
136 this.flowId = flowId;
137 }
138
139 /**
140 * Get the Caller ID of the flow path installer.
141 *
142 * @return the Caller ID of the flow path installer.
143 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800144 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800145 public CallerId installerId() { return installerId; }
146
147 /**
148 * Set the Caller ID of the flow path installer.
149 *
150 * @param installerId the Caller ID of the flow path installer.
151 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800152 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800153 public void setInstallerId(CallerId installerId) {
154 this.installerId = installerId;
155 }
156
157 /**
158 * Get the flow path's data path.
159 *
160 * @return the flow path's data path.
161 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800162 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800163 public DataPath dataPath() { return dataPath; }
164
165 /**
166 * Set the flow path's data path.
167 *
168 * @param dataPath the flow path's data path to set.
169 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800170 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800171 public void setDataPath(DataPath dataPath) {
172 this.dataPath = dataPath;
173 }
174
175 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700176 * Get the flow path's match conditions common for all Flow Entries.
177 *
178 * @return the flow path's match conditions common for all Flow Entries.
179 */
180 @JsonProperty("flowEntryMatch")
181 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
182
183 /**
184 * Set the flow path's match conditions common for all Flow Entries.
185 *
186 * @param flowEntryMatch the flow path's match conditions common for all
187 * Flow Entries.
188 */
189 @JsonProperty("flowEntryMatch")
190 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
191 this.flowEntryMatch = flowEntryMatch;
192 }
193
194 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800195 * Convert the flow path to a string.
196 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800197 * The string has the following form:
198 * [flowId=XXX installerId=XXX dataPath=XXX]
199 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800200 * @return the flow path as a string.
201 */
202 @Override
203 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800204 String ret = "[flowId=" + this.flowId.toString();
205 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700206 if (dataPath != null)
207 ret += " dataPath=" + this.dataPath.toString();
208 if (flowEntryMatch != null)
209 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800210 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800211 return ret;
212 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700213
214 /**
215 * CompareTo method to order flowPath by Id
216 */
217 @Override
218 public int compareTo(FlowPath f) {
219 return (int) (this.flowId.value() - f.flowId.value());
220 }
221
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800222}