Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | |
| 5 | import net.floodlightcontroller.util.SwitchPort; |
| 6 | import net.floodlightcontroller.util.FlowEntry; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 7 | |
| 8 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * The class representing the Data Path. |
| 12 | */ |
| 13 | public 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 Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 22 | srcPort = new SwitchPort(); |
| 23 | dstPort = new SwitchPort(); |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 24 | flowEntries = new ArrayList<FlowEntry>(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Get the data path source port. |
| 29 | * |
| 30 | * @return the data path source port. |
| 31 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 32 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 33 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 40 | @JsonProperty("srcPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 41 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 50 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 51 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 58 | @JsonProperty("dstPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 59 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 68 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 69 | 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 76 | @JsonProperty("flowEntries") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 77 | public void setFlowEntries(ArrayList<FlowEntry> flowEntries) { |
| 78 | this.flowEntries = flowEntries; |
| 79 | } |
| 80 | |
| 81 | /** |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 82 | * 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 113 | * Convert the data path to a string. |
| 114 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 115 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 116 | * [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] | 117 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 118 | * @return the data path as a string. |
| 119 | */ |
| 120 | @Override |
| 121 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 122 | String ret = "[src=" + this.srcPort.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 123 | |
| 124 | for (FlowEntry fe : flowEntries) { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 125 | ret += " flowEntry=" + fe.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 126 | } |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 127 | ret += " dst=" + this.dstPort.toString() + "]"; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 128 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | } |