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 | |
| 3 | import java.util.ArrayList; |
| 4 | |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 5 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * The class representing the Data Path. |
| 9 | */ |
| 10 | public class DataPath { |
| 11 | private SwitchPort srcPort; // The source port |
| 12 | private SwitchPort dstPort; // The destination port |
| 13 | private ArrayList<FlowEntry> flowEntries; // The Flow Entries |
| 14 | |
| 15 | /** |
| 16 | * Default constructor. |
| 17 | */ |
| 18 | public DataPath() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 19 | srcPort = new SwitchPort(); |
| 20 | dstPort = new SwitchPort(); |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 21 | flowEntries = new ArrayList<FlowEntry>(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Get the data path source port. |
| 26 | * |
| 27 | * @return the data path source port. |
| 28 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 29 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 30 | public SwitchPort srcPort() { return srcPort; } |
| 31 | |
| 32 | /** |
| 33 | * Set the data path source port. |
| 34 | * |
| 35 | * @param srcPort the data path source port to set. |
| 36 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 37 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 38 | public void setSrcPort(SwitchPort srcPort) { |
| 39 | this.srcPort = srcPort; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the data path destination port. |
| 44 | * |
| 45 | * @return the data path destination port. |
| 46 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 47 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 48 | public SwitchPort dstPort() { return dstPort; } |
| 49 | |
| 50 | /** |
| 51 | * Set the data path destination port. |
| 52 | * |
| 53 | * @param dstPort the data path destination port to set. |
| 54 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 55 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 56 | public void setDstPort(SwitchPort dstPort) { |
| 57 | this.dstPort = dstPort; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the data path flow entries. |
| 62 | * |
| 63 | * @return the data path flow entries. |
| 64 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 65 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 66 | public ArrayList<FlowEntry> flowEntries() { return flowEntries; } |
| 67 | |
| 68 | /** |
| 69 | * Set the data path flow entries. |
| 70 | * |
| 71 | * @param flowEntries the data path flow entries to set. |
| 72 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 73 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 74 | public void setFlowEntries(ArrayList<FlowEntry> flowEntries) { |
| 75 | this.flowEntries = flowEntries; |
| 76 | } |
| 77 | |
| 78 | /** |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 79 | * Get a string with the summary of the shortest-path data path |
| 80 | * computation. |
| 81 | * |
| 82 | * NOTE: This method assumes the DataPath was created by |
| 83 | * using FlowManager::getShortestPath() so the inPort and outPort |
| 84 | * of the Flow Entries are set. |
| 85 | * NOTE: This method is a temporary solution and will be removed |
| 86 | * in the future. |
| 87 | * |
| 88 | * @return a string with the summary of the shortest-path |
| 89 | * data path computation if valid, otherwise the string "X". |
| 90 | * If the shortest-path was valid, The string has the following form: |
| 91 | * inPort/dpid/outPort;inPort/dpid/outPort;... |
| 92 | */ |
| 93 | public String dataPathSummary() { |
| 94 | String resultStr = new String(); |
| 95 | if (this.flowEntries != null) { |
| 96 | for (FlowEntry flowEntry : this.flowEntries) { |
| 97 | // The data path summary string |
| 98 | resultStr = resultStr + |
| 99 | flowEntry.inPort().toString() + "/" |
| 100 | + flowEntry.dpid().toString() + "/" + |
| 101 | flowEntry.outPort().toString() + ";"; |
| 102 | } |
| 103 | } |
| 104 | if (resultStr.isEmpty()) |
| 105 | resultStr = "X"; // Invalid shortest-path |
| 106 | return resultStr; |
| 107 | } |
| 108 | |
| 109 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 110 | * Convert the data path to a string. |
| 111 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 112 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 113 | * [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 Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 114 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 115 | * @return the data path as a string. |
| 116 | */ |
| 117 | @Override |
| 118 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 119 | String ret = "[src=" + this.srcPort.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 120 | |
| 121 | for (FlowEntry fe : flowEntries) { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 122 | ret += " flowEntry=" + fe.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 123 | } |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 124 | ret += " dst=" + this.dstPort.toString() + "]"; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 125 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 126 | return ret; |
| 127 | } |
| 128 | } |