Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
| 5 | import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 6 | import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.util.CallerId; |
| 8 | import net.floodlightcontroller.util.DataPath; |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 9 | import net.floodlightcontroller.util.FlowEntryMatch; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 10 | import net.floodlightcontroller.util.FlowId; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 11 | |
| 12 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * The class representing the Flow Path. |
| 16 | */ |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 17 | public class FlowPath implements Comparable<FlowPath> { |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 18 | private FlowId flowId; // The Flow ID |
| 19 | private CallerId installerId; // The Caller ID of the path installer |
| 20 | private DataPath dataPath; // The data path |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 21 | private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all |
| 22 | // Flow Entries |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Default constructor. |
| 26 | */ |
| 27 | public FlowPath() { |
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())); |
| 38 | this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch())); |
| 39 | this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort())); |
| 40 | this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch())); |
| 41 | this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort())); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 42 | // |
| 43 | // Extract the match conditions that are common for all Flow Entries |
| 44 | // |
| 45 | { |
| 46 | FlowEntryMatch match = new FlowEntryMatch(); |
| 47 | Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
| 48 | if (matchEthernetFrameType != null) |
| 49 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 50 | String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
| 51 | if (matchSrcIPv4Net != null) |
| 52 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 53 | String matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
| 54 | if (matchDstIPv4Net != null) |
| 55 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 56 | String matchSrcMac = flowObj.getMatchSrcMac(); |
| 57 | if (matchSrcMac != null) |
| 58 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 59 | String matchDstMac = flowObj.getMatchDstMac(); |
| 60 | if (matchDstMac != null) |
| 61 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 62 | this.setFlowEntryMatch(match); |
| 63 | } |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 64 | |
| 65 | // |
| 66 | // Extract all Flow Entries |
| 67 | // |
| 68 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 69 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 70 | FlowEntry flowEntry = new FlowEntry(); |
| 71 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId())); |
| 72 | flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid())); |
| 73 | |
| 74 | // |
| 75 | // Extract the match conditions |
| 76 | // |
| 77 | FlowEntryMatch match = new FlowEntryMatch(); |
| 78 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 79 | if (matchInPort != null) |
| 80 | match.enableInPort(new Port(matchInPort)); |
| 81 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 82 | if (matchEthernetFrameType != null) |
| 83 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 84 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 85 | if (matchSrcIPv4Net != null) |
| 86 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 87 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 88 | if (matchDstIPv4Net != null) |
| 89 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 90 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 91 | if (matchSrcMac != null) |
| 92 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 93 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 94 | if (matchDstMac != null) |
| 95 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 96 | flowEntry.setFlowEntryMatch(match); |
| 97 | |
| 98 | // |
| 99 | // Extract the actions |
| 100 | // |
| 101 | ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>(); |
| 102 | Short actionOutputPort = flowEntryObj.getActionOutput(); |
| 103 | if (actionOutputPort != null) { |
| 104 | FlowEntryAction action = new FlowEntryAction(); |
| 105 | action.setActionOutput(new Port(actionOutputPort)); |
| 106 | actions.add(action); |
| 107 | } |
| 108 | flowEntry.setFlowEntryActions(actions); |
| 109 | |
| 110 | String userState = flowEntryObj.getUserState(); |
| 111 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
| 112 | String switchState = flowEntryObj.getSwitchState(); |
| 113 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 114 | // |
| 115 | // TODO: Take care of the FlowEntryMatch, FlowEntryAction set, |
| 116 | // and FlowEntryErrorState. |
| 117 | // |
| 118 | this.dataPath().flowEntries().add(flowEntry); |
| 119 | } |
| 120 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Get the flow path Flow ID. |
| 124 | * |
| 125 | * @return the flow path Flow ID. |
| 126 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 127 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 128 | public FlowId flowId() { return flowId; } |
| 129 | |
| 130 | /** |
| 131 | * Set the flow path Flow ID. |
| 132 | * |
| 133 | * @param flowId the flow path Flow ID to set. |
| 134 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 135 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 136 | public void setFlowId(FlowId flowId) { |
| 137 | this.flowId = flowId; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Get the Caller ID of the flow path installer. |
| 142 | * |
| 143 | * @return the Caller ID of the flow path installer. |
| 144 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 145 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 146 | public CallerId installerId() { return installerId; } |
| 147 | |
| 148 | /** |
| 149 | * Set the Caller ID of the flow path installer. |
| 150 | * |
| 151 | * @param installerId the Caller ID of the flow path installer. |
| 152 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 153 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 154 | public void setInstallerId(CallerId installerId) { |
| 155 | this.installerId = installerId; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Get the flow path's data path. |
| 160 | * |
| 161 | * @return the flow path's data path. |
| 162 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 163 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 164 | public DataPath dataPath() { return dataPath; } |
| 165 | |
| 166 | /** |
| 167 | * Set the flow path's data path. |
| 168 | * |
| 169 | * @param dataPath the flow path's data path to set. |
| 170 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 171 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 172 | public void setDataPath(DataPath dataPath) { |
| 173 | this.dataPath = dataPath; |
| 174 | } |
| 175 | |
| 176 | /** |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 177 | * Get the flow path's match conditions common for all Flow Entries. |
| 178 | * |
| 179 | * @return the flow path's match conditions common for all Flow Entries. |
| 180 | */ |
| 181 | @JsonProperty("flowEntryMatch") |
| 182 | public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; } |
| 183 | |
| 184 | /** |
| 185 | * Set the flow path's match conditions common for all Flow Entries. |
| 186 | * |
| 187 | * @param flowEntryMatch the flow path's match conditions common for all |
| 188 | * Flow Entries. |
| 189 | */ |
| 190 | @JsonProperty("flowEntryMatch") |
| 191 | public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) { |
| 192 | this.flowEntryMatch = flowEntryMatch; |
| 193 | } |
| 194 | |
| 195 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 196 | * Convert the flow path to a string. |
| 197 | * |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 198 | * The string has the following form: |
| 199 | * [flowId=XXX installerId=XXX dataPath=XXX] |
| 200 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 201 | * @return the flow path as a string. |
| 202 | */ |
| 203 | @Override |
| 204 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 205 | String ret = "[flowId=" + this.flowId.toString(); |
| 206 | ret += " installerId=" + this.installerId.toString(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 207 | if (dataPath != null) |
| 208 | ret += " dataPath=" + this.dataPath.toString(); |
| 209 | if (flowEntryMatch != null) |
| 210 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 211 | ret += "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 212 | return ret; |
| 213 | } |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * CompareTo method to order flowPath by Id |
| 217 | */ |
| 218 | @Override |
| 219 | public int compareTo(FlowPath f) { |
| 220 | return (int) (this.flowId.value() - f.flowId.value()); |
| 221 | } |
| 222 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 223 | } |