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