HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 2 | |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 5 | import net.floodlightcontroller.util.MACAddress; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 7 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 8 | import net.onrc.onos.ofcontroller.util.FlowPathFlags; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 9 | |
| 10 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * The class representing the Flow Path. |
| 14 | */ |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 15 | public class FlowPath implements Comparable<FlowPath> { |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 16 | private FlowId flowId; // The Flow ID |
| 17 | private CallerId installerId; // The Caller ID of the path installer |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 18 | private FlowPathFlags flowPathFlags; // The Flow Path flags |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 19 | private DataPath dataPath; // The data path |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 20 | private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all |
| 21 | // Flow Entries |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Default constructor. |
| 25 | */ |
| 26 | public FlowPath() { |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 27 | flowPathFlags = new FlowPathFlags(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 28 | dataPath = new DataPath(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 29 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 30 | |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Constructor to instantiate from object in Network Map |
| 33 | */ |
| 34 | public FlowPath(IFlowPath flowObj) { |
| 35 | dataPath = new DataPath(); |
| 36 | this.setFlowId(new FlowId(flowObj.getFlowId())); |
| 37 | this.setInstallerId(new CallerId(flowObj.getInstallerId())); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 38 | this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags())); |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 39 | this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch())); |
| 40 | this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort())); |
| 41 | this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch())); |
| 42 | this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort())); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 43 | // |
| 44 | // Extract the match conditions that are common for all Flow Entries |
| 45 | // |
| 46 | { |
| 47 | FlowEntryMatch match = new FlowEntryMatch(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 48 | String matchSrcMac = flowObj.getMatchSrcMac(); |
| 49 | if (matchSrcMac != null) |
| 50 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 51 | String matchDstMac = flowObj.getMatchDstMac(); |
| 52 | if (matchDstMac != null) |
| 53 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 54 | Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
| 55 | if (matchEthernetFrameType != null) |
| 56 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 57 | Short matchVlanId = flowObj.getMatchVlanId(); |
| 58 | if (matchVlanId != null) |
| 59 | match.enableVlanId(matchVlanId); |
| 60 | Byte matchVlanPriority = flowObj.getMatchVlanPriority(); |
| 61 | if (matchVlanPriority != null) |
| 62 | match.enableVlanPriority(matchVlanPriority); |
| 63 | String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
| 64 | if (matchSrcIPv4Net != null) |
| 65 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 66 | String matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
| 67 | if (matchDstIPv4Net != null) |
| 68 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 69 | Byte matchIpProto = flowObj.getMatchIpProto(); |
| 70 | if (matchIpProto != null) |
| 71 | match.enableIpProto(matchIpProto); |
| 72 | Byte matchIpToS = flowObj.getMatchIpToS(); |
| 73 | if (matchIpToS != null) |
| 74 | match.enableIpToS(matchIpToS); |
| 75 | Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort(); |
| 76 | if (matchSrcTcpUdpPort != null) |
| 77 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 78 | Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort(); |
| 79 | if (matchDstTcpUdpPort != null) |
| 80 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
| 81 | |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 82 | this.setFlowEntryMatch(match); |
| 83 | } |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 84 | |
| 85 | // |
| 86 | // Extract all Flow Entries |
| 87 | // |
| 88 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 89 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 90 | FlowEntry flowEntry = new FlowEntry(); |
| 91 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId())); |
| 92 | flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid())); |
| 93 | |
| 94 | // |
| 95 | // Extract the match conditions |
| 96 | // |
| 97 | FlowEntryMatch match = new FlowEntryMatch(); |
| 98 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 99 | if (matchInPort != null) |
| 100 | match.enableInPort(new Port(matchInPort)); |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 101 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 102 | if (matchSrcMac != null) |
| 103 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 104 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 105 | if (matchDstMac != null) |
| 106 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 107 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 108 | if (matchEthernetFrameType != null) |
| 109 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 110 | Short matchVlanId = flowEntryObj.getMatchVlanId(); |
| 111 | if (matchVlanId != null) |
| 112 | match.enableVlanId(matchVlanId); |
| 113 | Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority(); |
| 114 | if (matchVlanPriority != null) |
| 115 | match.enableVlanPriority(matchVlanPriority); |
| 116 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 117 | if (matchSrcIPv4Net != null) |
| 118 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 119 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 120 | if (matchDstIPv4Net != null) |
| 121 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 122 | Byte matchIpProto = flowEntryObj.getMatchIpProto(); |
| 123 | if (matchIpProto != null) |
| 124 | match.enableIpProto(matchIpProto); |
| 125 | Byte matchIpToS = flowEntryObj.getMatchIpToS(); |
| 126 | if (matchIpToS != null) |
| 127 | match.enableIpToS(matchIpToS); |
| 128 | Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort(); |
| 129 | if (matchSrcTcpUdpPort != null) |
| 130 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 131 | Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort(); |
| 132 | if (matchDstTcpUdpPort != null) |
| 133 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 134 | flowEntry.setFlowEntryMatch(match); |
| 135 | |
| 136 | // |
| 137 | // Extract the actions |
| 138 | // |
| 139 | ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>(); |
| 140 | Short actionOutputPort = flowEntryObj.getActionOutput(); |
| 141 | if (actionOutputPort != null) { |
| 142 | FlowEntryAction action = new FlowEntryAction(); |
| 143 | action.setActionOutput(new Port(actionOutputPort)); |
| 144 | actions.add(action); |
| 145 | } |
| 146 | flowEntry.setFlowEntryActions(actions); |
| 147 | |
| 148 | String userState = flowEntryObj.getUserState(); |
| 149 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
| 150 | String switchState = flowEntryObj.getSwitchState(); |
| 151 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 152 | // |
| 153 | // TODO: Take care of the FlowEntryMatch, FlowEntryAction set, |
| 154 | // and FlowEntryErrorState. |
| 155 | // |
| 156 | this.dataPath().flowEntries().add(flowEntry); |
| 157 | } |
| 158 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Get the flow path Flow ID. |
| 162 | * |
| 163 | * @return the flow path Flow ID. |
| 164 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 165 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 166 | public FlowId flowId() { return flowId; } |
| 167 | |
| 168 | /** |
| 169 | * Set the flow path Flow ID. |
| 170 | * |
| 171 | * @param flowId the flow path Flow ID to set. |
| 172 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 173 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 174 | public void setFlowId(FlowId flowId) { |
| 175 | this.flowId = flowId; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Get the Caller ID of the flow path installer. |
| 180 | * |
| 181 | * @return the Caller ID of the flow path installer. |
| 182 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 183 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 184 | public CallerId installerId() { return installerId; } |
| 185 | |
| 186 | /** |
| 187 | * Set the Caller ID of the flow path installer. |
| 188 | * |
| 189 | * @param installerId the Caller ID of the flow path installer. |
| 190 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 191 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 192 | public void setInstallerId(CallerId installerId) { |
| 193 | this.installerId = installerId; |
| 194 | } |
| 195 | |
| 196 | /** |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 197 | * Get the flow path flags. |
| 198 | * |
| 199 | * @return the flow path flags. |
| 200 | */ |
| 201 | @JsonProperty("flowPathFlags") |
| 202 | public FlowPathFlags flowPathFlags() { return flowPathFlags; } |
| 203 | |
| 204 | /** |
| 205 | * Set the flow path flags. |
| 206 | * |
| 207 | * @param flowPathFlags the flow path flags to set. |
| 208 | */ |
| 209 | @JsonProperty("flowPathFlags") |
| 210 | public void setFlowPathFlags(FlowPathFlags flowPathFlags) { |
| 211 | this.flowPathFlags = flowPathFlags; |
| 212 | } |
| 213 | |
| 214 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 215 | * Get the flow path's data path. |
| 216 | * |
| 217 | * @return the flow path's data path. |
| 218 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 219 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 220 | public DataPath dataPath() { return dataPath; } |
| 221 | |
| 222 | /** |
| 223 | * Set the flow path's data path. |
| 224 | * |
| 225 | * @param dataPath the flow path's data path to set. |
| 226 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 227 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 228 | public void setDataPath(DataPath dataPath) { |
| 229 | this.dataPath = dataPath; |
| 230 | } |
| 231 | |
| 232 | /** |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 233 | * Get the flow path's match conditions common for all Flow Entries. |
| 234 | * |
| 235 | * @return the flow path's match conditions common for all Flow Entries. |
| 236 | */ |
| 237 | @JsonProperty("flowEntryMatch") |
| 238 | public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; } |
| 239 | |
| 240 | /** |
| 241 | * Set the flow path's match conditions common for all Flow Entries. |
| 242 | * |
| 243 | * @param flowEntryMatch the flow path's match conditions common for all |
| 244 | * Flow Entries. |
| 245 | */ |
| 246 | @JsonProperty("flowEntryMatch") |
| 247 | public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) { |
| 248 | this.flowEntryMatch = flowEntryMatch; |
| 249 | } |
| 250 | |
| 251 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 252 | * Convert the flow path to a string. |
| 253 | * |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 254 | * The string has the following form: |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 255 | * [flowId=XXX installerId=XXX flowPathFlags=XXX dataPath=XXX] |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 256 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 257 | * @return the flow path as a string. |
| 258 | */ |
| 259 | @Override |
| 260 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 261 | String ret = "[flowId=" + this.flowId.toString(); |
| 262 | ret += " installerId=" + this.installerId.toString(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame^] | 263 | ret += " flowPathFlags=" + this.flowPathFlags.toString(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 264 | if (dataPath != null) |
| 265 | ret += " dataPath=" + this.dataPath.toString(); |
| 266 | if (flowEntryMatch != null) |
| 267 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 268 | ret += "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 269 | return ret; |
| 270 | } |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * CompareTo method to order flowPath by Id |
| 274 | */ |
| 275 | @Override |
| 276 | public int compareTo(FlowPath f) { |
| 277 | return (int) (this.flowId.value() - f.flowId.value()); |
| 278 | } |
| 279 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 280 | } |