blob: f02552bba4972c886b64291e88f0cd1b185fbff0 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
3import java.util.ArrayList;
4
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005
6import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007
8/**
9 * The class representing the Data Path.
10 */
11public class DataPath {
12 private SwitchPort srcPort; // The source port
13 private SwitchPort dstPort; // The destination port
14 private ArrayList<FlowEntry> flowEntries; // The Flow Entries
15
16 /**
17 * Default constructor.
18 */
19 public DataPath() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080020 srcPort = new SwitchPort();
21 dstPort = new SwitchPort();
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080022 flowEntries = new ArrayList<FlowEntry>();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080023 }
24
25 /**
26 * Get the data path source port.
27 *
28 * @return the data path source port.
29 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080030 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080031 public SwitchPort srcPort() { return srcPort; }
32
33 /**
34 * Set the data path source port.
35 *
36 * @param srcPort the data path source port to set.
37 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080038 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080039 public void setSrcPort(SwitchPort srcPort) {
40 this.srcPort = srcPort;
41 }
42
43 /**
44 * Get the data path destination port.
45 *
46 * @return the data path destination port.
47 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080048 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080049 public SwitchPort dstPort() { return dstPort; }
50
51 /**
52 * Set the data path destination port.
53 *
54 * @param dstPort the data path destination port to set.
55 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080056 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080057 public void setDstPort(SwitchPort dstPort) {
58 this.dstPort = dstPort;
59 }
60
61 /**
62 * Get the data path flow entries.
63 *
64 * @return the data path flow entries.
65 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080066 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080067 public ArrayList<FlowEntry> flowEntries() { return flowEntries; }
68
69 /**
70 * Set the data path flow entries.
71 *
72 * @param flowEntries the data path flow entries to set.
73 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080074 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080075 public void setFlowEntries(ArrayList<FlowEntry> flowEntries) {
76 this.flowEntries = flowEntries;
77 }
78
79 /**
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -070080 * Get a string with the summary of the shortest-path data path
81 * computation.
82 *
83 * NOTE: This method assumes the DataPath was created by
84 * using FlowManager::getShortestPath() so the inPort and outPort
85 * of the Flow Entries are set.
86 * NOTE: This method is a temporary solution and will be removed
87 * in the future.
88 *
89 * @return a string with the summary of the shortest-path
90 * data path computation if valid, otherwise the string "X".
91 * If the shortest-path was valid, The string has the following form:
92 * inPort/dpid/outPort;inPort/dpid/outPort;...
93 */
94 public String dataPathSummary() {
95 String resultStr = new String();
96 if (this.flowEntries != null) {
97 for (FlowEntry flowEntry : this.flowEntries) {
98 // The data path summary string
99 resultStr = resultStr +
100 flowEntry.inPort().toString() + "/"
101 + flowEntry.dpid().toString() + "/" +
102 flowEntry.outPort().toString() + ";";
103 }
104 }
105 if (resultStr.isEmpty())
106 resultStr = "X"; // Invalid shortest-path
107 return resultStr;
108 }
109
110 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800111 * Convert the data path to a string.
112 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800113 * The string has the following form:
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800114 * [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 -0800115 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800116 * @return the data path as a string.
117 */
118 @Override
119 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800120 String ret = "[src=" + this.srcPort.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800121
122 for (FlowEntry fe : flowEntries) {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800123 ret += " flowEntry=" + fe.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800124 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800125 ret += " dst=" + this.dstPort.toString() + "]";
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800126
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800127 return ret;
128 }
129}