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 | |
| 6 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 7 | |
| 8 | /** |
| 9 | * The class representing the Data Path. |
| 10 | */ |
| 11 | public 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 Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 20 | srcPort = new SwitchPort(); |
| 21 | dstPort = new SwitchPort(); |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 22 | flowEntries = new ArrayList<FlowEntry>(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Get the data path source port. |
| 27 | * |
| 28 | * @return the data path source port. |
| 29 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 30 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 31 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 38 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 39 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 48 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 49 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 56 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 57 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 66 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 67 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 74 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 75 | public void setFlowEntries(ArrayList<FlowEntry> flowEntries) { |
| 76 | this.flowEntries = flowEntries; |
| 77 | } |
| 78 | |
| 79 | /** |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 80 | * 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 111 | * Convert the data path to a string. |
| 112 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 113 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 114 | * [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] | 115 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 116 | * @return the data path as a string. |
| 117 | */ |
| 118 | @Override |
| 119 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 120 | String ret = "[src=" + this.srcPort.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 121 | |
| 122 | for (FlowEntry fe : flowEntries) { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 123 | ret += " flowEntry=" + fe.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 124 | } |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 125 | ret += " dst=" + this.dstPort.toString() + "]"; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 126 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 127 | return ret; |
| 128 | } |
| 129 | } |