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; |
| 9 | import net.floodlightcontroller.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 |
| 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 | } |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 27 | |
| 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())); |
| 39 | |
| 40 | // |
| 41 | // Extract all Flow Entries |
| 42 | // |
| 43 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 44 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 45 | FlowEntry flowEntry = new FlowEntry(); |
| 46 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId())); |
| 47 | flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid())); |
| 48 | |
| 49 | // |
| 50 | // Extract the match conditions |
| 51 | // |
| 52 | FlowEntryMatch match = new FlowEntryMatch(); |
| 53 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 54 | if (matchInPort != null) |
| 55 | match.enableInPort(new Port(matchInPort)); |
| 56 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 57 | if (matchEthernetFrameType != null) |
| 58 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 59 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 60 | if (matchSrcIPv4Net != null) |
| 61 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 62 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 63 | if (matchDstIPv4Net != null) |
| 64 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 65 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 66 | if (matchSrcMac != null) |
| 67 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 68 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 69 | if (matchDstMac != null) |
| 70 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 71 | flowEntry.setFlowEntryMatch(match); |
| 72 | |
| 73 | // |
| 74 | // Extract the actions |
| 75 | // |
| 76 | ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>(); |
| 77 | Short actionOutputPort = flowEntryObj.getActionOutput(); |
| 78 | if (actionOutputPort != null) { |
| 79 | FlowEntryAction action = new FlowEntryAction(); |
| 80 | action.setActionOutput(new Port(actionOutputPort)); |
| 81 | actions.add(action); |
| 82 | } |
| 83 | flowEntry.setFlowEntryActions(actions); |
| 84 | |
| 85 | String userState = flowEntryObj.getUserState(); |
| 86 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
| 87 | String switchState = flowEntryObj.getSwitchState(); |
| 88 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 89 | // |
| 90 | // TODO: Take care of the FlowEntryMatch, FlowEntryAction set, |
| 91 | // and FlowEntryErrorState. |
| 92 | // |
| 93 | this.dataPath().flowEntries().add(flowEntry); |
| 94 | } |
| 95 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Get the flow path Flow ID. |
| 99 | * |
| 100 | * @return the flow path Flow ID. |
| 101 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 102 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 103 | public FlowId flowId() { return flowId; } |
| 104 | |
| 105 | /** |
| 106 | * Set the flow path Flow ID. |
| 107 | * |
| 108 | * @param flowId the flow path Flow ID to set. |
| 109 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 110 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 111 | public void setFlowId(FlowId flowId) { |
| 112 | this.flowId = flowId; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get the Caller ID of the flow path installer. |
| 117 | * |
| 118 | * @return the Caller ID of the flow path installer. |
| 119 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 120 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 121 | public CallerId installerId() { return installerId; } |
| 122 | |
| 123 | /** |
| 124 | * Set the Caller ID of the flow path installer. |
| 125 | * |
| 126 | * @param installerId the Caller ID of the flow path installer. |
| 127 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 128 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 129 | public void setInstallerId(CallerId installerId) { |
| 130 | this.installerId = installerId; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Get the flow path's data path. |
| 135 | * |
| 136 | * @return the flow path's data path. |
| 137 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 138 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 139 | public DataPath dataPath() { return dataPath; } |
| 140 | |
| 141 | /** |
| 142 | * Set the flow path's data path. |
| 143 | * |
| 144 | * @param dataPath the flow path's data path to set. |
| 145 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 146 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 147 | public void setDataPath(DataPath dataPath) { |
| 148 | this.dataPath = dataPath; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Convert the flow path to a string. |
| 153 | * |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 154 | * The string has the following form: |
| 155 | * [flowId=XXX installerId=XXX dataPath=XXX] |
| 156 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 157 | * @return the flow path as a string. |
| 158 | */ |
| 159 | @Override |
| 160 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 161 | String ret = "[flowId=" + this.flowId.toString(); |
| 162 | ret += " installerId=" + this.installerId.toString(); |
| 163 | ret += " dataPath=" + this.dataPath.toString(); |
| 164 | ret += "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 165 | return ret; |
| 166 | } |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * CompareTo method to order flowPath by Id |
| 170 | */ |
| 171 | @Override |
| 172 | public int compareTo(FlowPath f) { |
| 173 | return (int) (this.flowId.value() - f.flowId.value()); |
| 174 | } |
| 175 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 176 | } |