GUI -- Refactored IntentView java backend for details.
Change-Id: Id0fb2c1cdb61e801576980030493ff98d555089c
Showing
1 changed file
with
112 additions
and
100 deletions
... | @@ -20,7 +20,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; | ... | @@ -20,7 +20,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
21 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
22 | import org.onosproject.net.ConnectPoint; | 22 | import org.onosproject.net.ConnectPoint; |
23 | +import org.onosproject.net.flow.criteria.Criterion; | ||
24 | +import org.onosproject.net.flow.instructions.Instruction; | ||
23 | import org.onosproject.net.intent.ConnectivityIntent; | 25 | import org.onosproject.net.intent.ConnectivityIntent; |
26 | +import org.onosproject.net.intent.Constraint; | ||
24 | import org.onosproject.net.intent.HostToHostIntent; | 27 | import org.onosproject.net.intent.HostToHostIntent; |
25 | import org.onosproject.net.intent.Intent; | 28 | import org.onosproject.net.intent.Intent; |
26 | import org.onosproject.net.intent.IntentService; | 29 | import org.onosproject.net.intent.IntentService; |
... | @@ -89,133 +92,142 @@ public class IntentViewMessageHandler extends AbstractTabularViewMessageHandler | ... | @@ -89,133 +92,142 @@ public class IntentViewMessageHandler extends AbstractTabularViewMessageHandler |
89 | APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS | 92 | APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS |
90 | }; | 93 | }; |
91 | 94 | ||
92 | - private String formatDetails(Intent intent) { | 95 | + private StringBuilder details = new StringBuilder(); |
93 | - StringBuilder details = new StringBuilder(""); | 96 | + |
97 | + private void appendMultiPointsDetails(Set<ConnectPoint> points) { | ||
98 | + for (ConnectPoint point : points) { | ||
99 | + details.append(point.elementId()) | ||
100 | + .append('/') | ||
101 | + .append(point.port()) | ||
102 | + .append(' '); | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + private void buildConnectivityDetails(ConnectivityIntent intent) { | ||
107 | + Set<Criterion> criteria = intent.selector().criteria(); | ||
108 | + List<Instruction> instructions = intent.treatment().allInstructions(); | ||
109 | + List<Constraint> constraints = intent.constraints(); | ||
110 | + | ||
111 | + if (!criteria.isEmpty()) { | ||
112 | + details.append("selector=").append(criteria); | ||
113 | + } | ||
114 | + if (!instructions.isEmpty()) { | ||
115 | + details.append("treatment=").append(instructions); | ||
116 | + } | ||
117 | + if (constraints != null && !constraints.isEmpty()) { | ||
118 | + details.append("constraints=").append(constraints); | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + private void buildHostToHostDetails(HostToHostIntent intent) { | ||
123 | + details.append(" host1=") | ||
124 | + .append(intent.one()) | ||
125 | + .append(", host2=") | ||
126 | + .append(intent.two()); | ||
127 | + } | ||
128 | + | ||
129 | + private void buildPointToPointDetails(PointToPointIntent intent) { | ||
130 | + ConnectPoint ingress = intent.ingressPoint(); | ||
131 | + ConnectPoint egress = intent.egressPoint(); | ||
132 | + details.append(" ingress=") | ||
133 | + .append(ingress.elementId()) | ||
134 | + .append('/') | ||
135 | + .append(ingress.port()) | ||
136 | + | ||
137 | + .append(", egress=") | ||
138 | + .append(egress.elementId()) | ||
139 | + .append('/') | ||
140 | + .append(egress.port()) | ||
141 | + .append(' '); | ||
142 | + } | ||
143 | + | ||
144 | + private void buildMPToSPDetails(MultiPointToSinglePointIntent intent) { | ||
145 | + ConnectPoint egress = intent.egressPoint(); | ||
146 | + | ||
147 | + details.append(" ingress="); | ||
148 | + appendMultiPointsDetails(intent.ingressPoints()); | ||
149 | + | ||
150 | + details.append(", egress=") | ||
151 | + .append(egress.elementId()) | ||
152 | + .append('/') | ||
153 | + .append(egress.port()) | ||
154 | + .append(' '); | ||
155 | + } | ||
94 | 156 | ||
157 | + private void buildSPToMPDetails(SinglePointToMultiPointIntent intent) { | ||
158 | + ConnectPoint ingress = intent.ingressPoint(); | ||
159 | + | ||
160 | + details.append(" ingress=") | ||
161 | + .append(ingress.elementId()) | ||
162 | + .append('/') | ||
163 | + .append(ingress.port()) | ||
164 | + .append(", egress="); | ||
165 | + | ||
166 | + appendMultiPointsDetails(intent.egressPoints()); | ||
167 | + } | ||
168 | + | ||
169 | + private void buildPathDetails(PathIntent intent) { | ||
170 | + details.append(" path=") | ||
171 | + .append(intent.path().links()) | ||
172 | + .append(", cost=") | ||
173 | + .append(intent.path().cost()); | ||
174 | + } | ||
175 | + | ||
176 | + private void buildLinkConnectionDetails(LinkCollectionIntent intent) { | ||
177 | + details.append(" links=") | ||
178 | + .append(intent.links()) | ||
179 | + .append(", egress="); | ||
180 | + | ||
181 | + appendMultiPointsDetails(intent.egressPoints()); | ||
182 | + } | ||
183 | + | ||
184 | + private String formatDetails(Intent intent) { | ||
95 | if (intent instanceof ConnectivityIntent) { | 185 | if (intent instanceof ConnectivityIntent) { |
96 | - ConnectivityIntent ci = (ConnectivityIntent) intent; | 186 | + buildConnectivityDetails((ConnectivityIntent) intent); |
97 | - if (!ci.selector().criteria().isEmpty()) { | ||
98 | - details.append("selector=") | ||
99 | - .append(ci.selector().criteria().toString()); | ||
100 | - } | ||
101 | - if (!ci.treatment().allInstructions().isEmpty()) { | ||
102 | - details.append("treatment=") | ||
103 | - .append(ci.treatment().allInstructions().toString()); | ||
104 | - } | ||
105 | - if (ci.constraints() != null && !ci.constraints().isEmpty()) { | ||
106 | - details.append("constraints=") | ||
107 | - .append(ci.constraints().toString()); | ||
108 | - } | ||
109 | } | 187 | } |
110 | 188 | ||
111 | if (intent instanceof HostToHostIntent) { | 189 | if (intent instanceof HostToHostIntent) { |
112 | - HostToHostIntent pi = (HostToHostIntent) intent; | 190 | + buildHostToHostDetails((HostToHostIntent) intent); |
113 | - details.append(" host1=") | ||
114 | - .append(pi.one().toString()) | ||
115 | - .append(", host2=") | ||
116 | - .append(pi.two().toString()); | ||
117 | 191 | ||
118 | } else if (intent instanceof PointToPointIntent) { | 192 | } else if (intent instanceof PointToPointIntent) { |
119 | - PointToPointIntent pi = (PointToPointIntent) intent; | 193 | + buildPointToPointDetails((PointToPointIntent) intent); |
120 | - ConnectPoint ingress = pi.ingressPoint(); | ||
121 | - ConnectPoint egress = pi.egressPoint(); | ||
122 | - details.append(" ingress=") | ||
123 | - .append(ingress.elementId().toString()) | ||
124 | - .append('/') | ||
125 | - .append(ingress.port().toString()) | ||
126 | - | ||
127 | - .append(", egress=") | ||
128 | - .append(egress.elementId().toString()) | ||
129 | - .append('/') | ||
130 | - .append(egress.port().toString()) | ||
131 | - .append(' '); | ||
132 | 194 | ||
133 | } else if (intent instanceof MultiPointToSinglePointIntent) { | 195 | } else if (intent instanceof MultiPointToSinglePointIntent) { |
134 | - MultiPointToSinglePointIntent pi | 196 | + buildMPToSPDetails((MultiPointToSinglePointIntent) intent); |
135 | - = (MultiPointToSinglePointIntent) intent; | ||
136 | - Set<ConnectPoint> ingresses = pi.ingressPoints(); | ||
137 | - ConnectPoint egress = pi.egressPoint(); | ||
138 | - | ||
139 | - details.append(" ingress="); | ||
140 | - for (ConnectPoint ingress : ingresses) { | ||
141 | - details.append(ingress.elementId().toString()) | ||
142 | - .append('/') | ||
143 | - .append(ingress.port().toString()) | ||
144 | - .append(' '); | ||
145 | - } | ||
146 | - | ||
147 | - details.append(", egress=") | ||
148 | - .append(egress.elementId().toString()) | ||
149 | - .append('/') | ||
150 | - .append(egress.port().toString()) | ||
151 | - .append(' '); | ||
152 | 197 | ||
153 | } else if (intent instanceof SinglePointToMultiPointIntent) { | 198 | } else if (intent instanceof SinglePointToMultiPointIntent) { |
154 | - SinglePointToMultiPointIntent pi | 199 | + buildSPToMPDetails((SinglePointToMultiPointIntent) intent); |
155 | - = (SinglePointToMultiPointIntent) intent; | ||
156 | - ConnectPoint ingress = pi.ingressPoint(); | ||
157 | - Set<ConnectPoint> egresses = pi.egressPoints(); | ||
158 | - | ||
159 | - details.append(" ingress=") | ||
160 | - .append(ingress.elementId().toString()) | ||
161 | - .append('/') | ||
162 | - .append(ingress.port().toString()) | ||
163 | - .append(", egress="); | ||
164 | - | ||
165 | - for (ConnectPoint egress : egresses) { | ||
166 | - details.append(egress.elementId().toString()) | ||
167 | - .append('/') | ||
168 | - .append(egress.port().toString()) | ||
169 | - .append(' '); | ||
170 | - } | ||
171 | 200 | ||
172 | } else if (intent instanceof PathIntent) { | 201 | } else if (intent instanceof PathIntent) { |
173 | - PathIntent pi = (PathIntent) intent; | 202 | + buildPathDetails((PathIntent) intent); |
174 | - details.append(" path=") | ||
175 | - .append(pi.path().links().toString()) | ||
176 | - .append(", cost=") | ||
177 | - .append(pi.path().cost()); | ||
178 | 203 | ||
179 | } else if (intent instanceof LinkCollectionIntent) { | 204 | } else if (intent instanceof LinkCollectionIntent) { |
180 | - LinkCollectionIntent li = (LinkCollectionIntent) intent; | 205 | + buildLinkConnectionDetails((LinkCollectionIntent) intent); |
181 | - Set<ConnectPoint> egresses = li.egressPoints(); | ||
182 | - | ||
183 | - details.append(" links=") | ||
184 | - .append(li.links().toString()) | ||
185 | - .append(", egress="); | ||
186 | - | ||
187 | - for (ConnectPoint egress : egresses) { | ||
188 | - details.append(egress.elementId().toString()) | ||
189 | - .append('/') | ||
190 | - .append(egress.port().toString()) | ||
191 | - .append(' '); | ||
192 | - } | ||
193 | } | 206 | } |
194 | 207 | ||
195 | - if (details.toString().equals("")) { | 208 | + if (details.length() == 0) { |
196 | - details.append("No details for this intent"); | 209 | + details.append("(No details for this intent)"); |
197 | } else { | 210 | } else { |
198 | details.insert(0, "Details: "); | 211 | details.insert(0, "Details: "); |
199 | } | 212 | } |
200 | return details.toString(); | 213 | return details.toString(); |
201 | } | 214 | } |
202 | 215 | ||
203 | - private String formatResources(Intent i) { | 216 | + private String formatResources(Intent intent) { |
204 | - if (!i.resources().isEmpty()) { | 217 | + return (intent.resources().isEmpty() ? |
205 | - return "Resources: " + i.resources(); | 218 | + "(No resources for this intent)" : |
206 | - } | 219 | + "Resources: " + intent.resources()); |
207 | - return "No resources for this intent."; | ||
208 | } | 220 | } |
209 | 221 | ||
210 | - public IntentTableRow(Intent i) { | 222 | + public IntentTableRow(Intent intent) { |
211 | - ApplicationId appid = i.appId(); | 223 | + ApplicationId appid = intent.appId(); |
212 | 224 | ||
213 | add(APP_ID, String.valueOf(appid.id()) + " : " + appid.name()); | 225 | add(APP_ID, String.valueOf(appid.id()) + " : " + appid.name()); |
214 | - add(KEY, i.key().toString()); | 226 | + add(KEY, intent.key().toString()); |
215 | - add(TYPE, i.getClass().getSimpleName()); | 227 | + add(TYPE, intent.getClass().getSimpleName()); |
216 | - add(PRIORITY, Integer.toString(i.priority())); | 228 | + add(PRIORITY, Integer.toString(intent.priority())); |
217 | - add(RESOURCES, formatResources(i)); | 229 | + add(RESOURCES, formatResources(intent)); |
218 | - add(DETAILS, formatDetails(i)); | 230 | + add(DETAILS, formatDetails(intent)); |
219 | } | 231 | } |
220 | 232 | ||
221 | @Override | 233 | @Override | ... | ... |
-
Please register or login to post a comment