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; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.util.FlowEntryMatch; |
| 9 | import net.onrc.onos.ofcontroller.util.FlowId; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 10 | |
| 11 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * The class representing the Flow Path. |
| 15 | */ |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 16 | public class FlowPath implements Comparable<FlowPath> { |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 17 | 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 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 | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 27 | dataPath = new DataPath(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 28 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 29 | |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 30 | /** |
| 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 Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 41 | // |
| 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 Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 63 | |
| 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Get the flow path Flow ID. |
| 123 | * |
| 124 | * @return the flow path Flow ID. |
| 125 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 126 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 127 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 134 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 135 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 144 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 145 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 152 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 153 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 162 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 163 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 170 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 171 | public void setDataPath(DataPath dataPath) { |
| 172 | this.dataPath = dataPath; |
| 173 | } |
| 174 | |
| 175 | /** |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 176 | * 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 195 | * Convert the flow path to a string. |
| 196 | * |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 197 | * The string has the following form: |
| 198 | * [flowId=XXX installerId=XXX dataPath=XXX] |
| 199 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 200 | * @return the flow path as a string. |
| 201 | */ |
| 202 | @Override |
| 203 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 204 | String ret = "[flowId=" + this.flowId.toString(); |
| 205 | ret += " installerId=" + this.installerId.toString(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 206 | if (dataPath != null) |
| 207 | ret += " dataPath=" + this.dataPath.toString(); |
| 208 | if (flowEntryMatch != null) |
| 209 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 210 | ret += "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 211 | return ret; |
| 212 | } |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 213 | |
| 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 222 | } |