blob: 0ca0d133944161ba31e1e051e6d95ccbe7fd3d59 [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
3import java.util.ArrayList;
4
5import net.floodlightcontroller.util.SwitchPort;
6import net.floodlightcontroller.util.FlowEntry;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
8import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009
10/**
11 * The class representing the Data Path.
12 */
13public class DataPath {
14 private SwitchPort srcPort; // The source port
15 private SwitchPort dstPort; // The destination port
16 private ArrayList<FlowEntry> flowEntries; // The Flow Entries
17
18 /**
19 * Default constructor.
20 */
21 public DataPath() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080022 srcPort = new SwitchPort();
23 dstPort = new SwitchPort();
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080024 flowEntries = new ArrayList<FlowEntry>();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080025 }
26
27 /**
28 * Get the data path source port.
29 *
30 * @return the data path source port.
31 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080032 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080033 public SwitchPort srcPort() { return srcPort; }
34
35 /**
36 * Set the data path source port.
37 *
38 * @param srcPort the data path source port to set.
39 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080040 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080041 public void setSrcPort(SwitchPort srcPort) {
42 this.srcPort = srcPort;
43 }
44
45 /**
46 * Get the data path destination port.
47 *
48 * @return the data path destination port.
49 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080050 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080051 public SwitchPort dstPort() { return dstPort; }
52
53 /**
54 * Set the data path destination port.
55 *
56 * @param dstPort the data path destination port to set.
57 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080058 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080059 public void setDstPort(SwitchPort dstPort) {
60 this.dstPort = dstPort;
61 }
62
63 /**
64 * Get the data path flow entries.
65 *
66 * @return the data path flow entries.
67 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080068 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080069 public ArrayList<FlowEntry> flowEntries() { return flowEntries; }
70
71 /**
72 * Set the data path flow entries.
73 *
74 * @param flowEntries the data path flow entries to set.
75 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080076 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080077 public void setFlowEntries(ArrayList<FlowEntry> flowEntries) {
78 this.flowEntries = flowEntries;
79 }
80
81 /**
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -070082 * Get a string with the summary of the shortest-path data path
83 * computation.
84 *
85 * NOTE: This method assumes the DataPath was created by
86 * using FlowManager::getShortestPath() so the inPort and outPort
87 * of the Flow Entries are set.
88 * NOTE: This method is a temporary solution and will be removed
89 * in the future.
90 *
91 * @return a string with the summary of the shortest-path
92 * data path computation if valid, otherwise the string "X".
93 * If the shortest-path was valid, The string has the following form:
94 * inPort/dpid/outPort;inPort/dpid/outPort;...
95 */
96 public String dataPathSummary() {
97 String resultStr = new String();
98 if (this.flowEntries != null) {
99 for (FlowEntry flowEntry : this.flowEntries) {
100 // The data path summary string
101 resultStr = resultStr +
102 flowEntry.inPort().toString() + "/"
103 + flowEntry.dpid().toString() + "/" +
104 flowEntry.outPort().toString() + ";";
105 }
106 }
107 if (resultStr.isEmpty())
108 resultStr = "X"; // Invalid shortest-path
109 return resultStr;
110 }
111
112 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800113 * Convert the data path to a string.
114 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800115 * The string has the following form:
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800116 * [src=01:01:01:01:01:01:01:01/1111 flowEntry=<entry1> flowEntry=<entry2> flowEntry=<entry3> dst=02:02:02:02:02:02:02:02/2222]
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800117 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800118 * @return the data path as a string.
119 */
120 @Override
121 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800122 String ret = "[src=" + this.srcPort.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800123
124 for (FlowEntry fe : flowEntries) {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800125 ret += " flowEntry=" + fe.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800126 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800127 ret += " dst=" + this.dstPort.toString() + "]";
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800128
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800129 return ret;
130 }
131}