blob: f4c25c28a61557902eb6675ff9aaf3e689639ee9 [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pankaj Berde6a97eb82013-03-28 12:12:43 -07003import java.util.ArrayList;
4
5import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
6import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007import net.floodlightcontroller.util.CallerId;
8import net.floodlightcontroller.util.DataPath;
9import net.floodlightcontroller.util.FlowId;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010
11import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012
13/**
14 * The class representing the Flow Path.
15 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070016public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017 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 Radoslavovb6f53542013-03-01 16:02:14 -080025 dataPath = new DataPath();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080026 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070027
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 Radoslavov5363c2a2013-02-18 09:55:42 -080096
97 /**
98 * Get the flow path Flow ID.
99 *
100 * @return the flow path Flow ID.
101 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800102 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800103 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800110 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800111 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800120 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800121 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800128 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800129 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800138 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800139 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800146 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800147 public void setDataPath(DataPath dataPath) {
148 this.dataPath = dataPath;
149 }
150
151 /**
152 * Convert the flow path to a string.
153 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800154 * The string has the following form:
155 * [flowId=XXX installerId=XXX dataPath=XXX]
156 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800157 * @return the flow path as a string.
158 */
159 @Override
160 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800161 String ret = "[flowId=" + this.flowId.toString();
162 ret += " installerId=" + this.installerId.toString();
163 ret += " dataPath=" + this.dataPath.toString();
164 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800165 return ret;
166 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700167
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 Radoslavov5363c2a2013-02-18 09:55:42 -0800176}