blob: 7c6597d24bd756fdc1808434074ddd065a997d37 [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 -08005import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08006
7/**
Pavlin Radoslavovd5b21db2013-07-29 17:09:53 -07008 * The data forwarding path state from a source to a destination.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009 */
10public 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 Radoslavovb6f53542013-03-01 16:02:14 -080019 srcPort = new SwitchPort();
20 dstPort = new SwitchPort();
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080021 flowEntries = new ArrayList<FlowEntry>();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080022 }
23
24 /**
25 * Get the data path source port.
26 *
27 * @return the data path source port.
28 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080029 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080030 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 Radoslavov2013cbb2013-02-26 10:15:18 -080037 @JsonProperty("srcPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080038 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 Radoslavov2013cbb2013-02-26 10:15:18 -080047 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080048 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 Radoslavov2013cbb2013-02-26 10:15:18 -080055 @JsonProperty("dstPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080056 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 Radoslavov2013cbb2013-02-26 10:15:18 -080065 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080066 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 Radoslavov2013cbb2013-02-26 10:15:18 -080073 @JsonProperty("flowEntries")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080074 public void setFlowEntries(ArrayList<FlowEntry> flowEntries) {
75 this.flowEntries = flowEntries;
76 }
77
78 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070079 * Apply Flow Path Flags to the pre-computed Data Path.
80 *
81 * @param flowPathFlags the Flow Path Flags to apply.
82 */
83 public void applyFlowPathFlags(FlowPathFlags flowPathFlags) {
84 if (flowPathFlags == null)
85 return; // Nothing to do
86
87 // Discard the first Flow Entry
88 if (flowPathFlags.isDiscardFirstHopEntry()) {
89 if (flowEntries.size() > 0)
90 flowEntries.remove(0);
91 }
92
93 // Keep only the first Flow Entry
94 if (flowPathFlags.isKeepOnlyFirstHopEntry()) {
95 if (flowEntries.size() > 1) {
96 FlowEntry flowEntry = flowEntries.get(0);
97 flowEntries.clear();
98 flowEntries.add(flowEntry);
99 }
100 }
101 }
102
103 /**
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700104 * Get a string with the summary of the shortest-path data path
105 * computation.
106 *
107 * NOTE: This method assumes the DataPath was created by
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700108 * using the TopologyManager shortest path computation, so the inPort
109 * and outPort of the Flow Entries are set.
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700110 * NOTE: This method is a temporary solution and will be removed
111 * in the future.
112 *
113 * @return a string with the summary of the shortest-path
114 * data path computation if valid, otherwise the string "X".
115 * If the shortest-path was valid, The string has the following form:
116 * inPort/dpid/outPort;inPort/dpid/outPort;...
117 */
118 public String dataPathSummary() {
Yuta HIGUCHI8e8900f2013-10-14 15:56:22 -0700119 StringBuilder resultStr = new StringBuilder(5+1+20+1+5+1);
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700120 if (this.flowEntries != null) {
121 for (FlowEntry flowEntry : this.flowEntries) {
122 // The data path summary string
Yuta HIGUCHI8e8900f2013-10-14 15:56:22 -0700123 resultStr.append(flowEntry.inPort().toString()).append('/')
124 .append(flowEntry.dpid().toString()).append('/')
125 .append(flowEntry.outPort().toString()).append(';');
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700126 }
127 }
Yuta HIGUCHI8e8900f2013-10-14 15:56:22 -0700128 if (resultStr.length() == 0)
129 resultStr.append("X"); // Invalid shortest-path
130 return resultStr.toString();
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700131 }
132
133 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800134 * Convert the data path to a string.
135 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800136 * The string has the following form:
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800137 * [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 -0800138 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800139 * @return the data path as a string.
140 */
141 @Override
142 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800143 String ret = "[src=" + this.srcPort.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800144
145 for (FlowEntry fe : flowEntries) {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800146 ret += " flowEntry=" + fe.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800147 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800148 ret += " dst=" + this.dstPort.toString() + "]";
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800149
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800150 return ret;
151 }
152}