Bri Prebilic Cole

GUI -- Refactored IntentView java backend for details.

Change-Id: Id0fb2c1cdb61e801576980030493ff98d555089c
...@@ -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("");
94 96
95 - if (intent instanceof ConnectivityIntent) { 97 + private void appendMultiPointsDetails(Set<ConnectPoint> points) {
96 - ConnectivityIntent ci = (ConnectivityIntent) intent; 98 + for (ConnectPoint point : points) {
97 - if (!ci.selector().criteria().isEmpty()) { 99 + details.append(point.elementId())
98 - details.append("selector=") 100 + .append('/')
99 - .append(ci.selector().criteria().toString()); 101 + .append(point.port())
102 + .append(' ');
100 } 103 }
101 - if (!ci.treatment().allInstructions().isEmpty()) {
102 - details.append("treatment=")
103 - .append(ci.treatment().allInstructions().toString());
104 } 104 }
105 - if (ci.constraints() != null && !ci.constraints().isEmpty()) { 105 +
106 - details.append("constraints=") 106 + private void buildConnectivityDetails(ConnectivityIntent intent) {
107 - .append(ci.constraints().toString()); 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);
108 } 119 }
109 } 120 }
110 121
111 - if (intent instanceof HostToHostIntent) { 122 + private void buildHostToHostDetails(HostToHostIntent intent) {
112 - HostToHostIntent pi = (HostToHostIntent) intent;
113 details.append(" host1=") 123 details.append(" host1=")
114 - .append(pi.one().toString()) 124 + .append(intent.one())
115 .append(", host2=") 125 .append(", host2=")
116 - .append(pi.two().toString()); 126 + .append(intent.two());
127 + }
117 128
118 - } else if (intent instanceof PointToPointIntent) { 129 + private void buildPointToPointDetails(PointToPointIntent intent) {
119 - PointToPointIntent pi = (PointToPointIntent) intent; 130 + ConnectPoint ingress = intent.ingressPoint();
120 - ConnectPoint ingress = pi.ingressPoint(); 131 + ConnectPoint egress = intent.egressPoint();
121 - ConnectPoint egress = pi.egressPoint();
122 details.append(" ingress=") 132 details.append(" ingress=")
123 - .append(ingress.elementId().toString()) 133 + .append(ingress.elementId())
124 .append('/') 134 .append('/')
125 - .append(ingress.port().toString()) 135 + .append(ingress.port())
126 136
127 .append(", egress=") 137 .append(", egress=")
128 - .append(egress.elementId().toString()) 138 + .append(egress.elementId())
129 .append('/') 139 .append('/')
130 - .append(egress.port().toString()) 140 + .append(egress.port())
131 .append(' '); 141 .append(' ');
142 + }
132 143
133 - } else if (intent instanceof MultiPointToSinglePointIntent) { 144 + private void buildMPToSPDetails(MultiPointToSinglePointIntent intent) {
134 - MultiPointToSinglePointIntent pi 145 + ConnectPoint egress = intent.egressPoint();
135 - = (MultiPointToSinglePointIntent) intent;
136 - Set<ConnectPoint> ingresses = pi.ingressPoints();
137 - ConnectPoint egress = pi.egressPoint();
138 146
139 details.append(" ingress="); 147 details.append(" ingress=");
140 - for (ConnectPoint ingress : ingresses) { 148 + appendMultiPointsDetails(intent.ingressPoints());
141 - details.append(ingress.elementId().toString())
142 - .append('/')
143 - .append(ingress.port().toString())
144 - .append(' ');
145 - }
146 149
147 details.append(", egress=") 150 details.append(", egress=")
148 - .append(egress.elementId().toString()) 151 + .append(egress.elementId())
149 .append('/') 152 .append('/')
150 - .append(egress.port().toString()) 153 + .append(egress.port())
151 .append(' '); 154 .append(' ');
155 + }
152 156
153 - } else if (intent instanceof SinglePointToMultiPointIntent) { 157 + private void buildSPToMPDetails(SinglePointToMultiPointIntent intent) {
154 - SinglePointToMultiPointIntent pi 158 + ConnectPoint ingress = intent.ingressPoint();
155 - = (SinglePointToMultiPointIntent) intent;
156 - ConnectPoint ingress = pi.ingressPoint();
157 - Set<ConnectPoint> egresses = pi.egressPoints();
158 159
159 details.append(" ingress=") 160 details.append(" ingress=")
160 - .append(ingress.elementId().toString()) 161 + .append(ingress.elementId())
161 .append('/') 162 .append('/')
162 - .append(ingress.port().toString()) 163 + .append(ingress.port())
163 .append(", egress="); 164 .append(", egress=");
164 165
165 - for (ConnectPoint egress : egresses) { 166 + appendMultiPointsDetails(intent.egressPoints());
166 - details.append(egress.elementId().toString())
167 - .append('/')
168 - .append(egress.port().toString())
169 - .append(' ');
170 } 167 }
171 168
172 - } else if (intent instanceof PathIntent) { 169 + private void buildPathDetails(PathIntent intent) {
173 - PathIntent pi = (PathIntent) intent;
174 details.append(" path=") 170 details.append(" path=")
175 - .append(pi.path().links().toString()) 171 + .append(intent.path().links())
176 .append(", cost=") 172 .append(", cost=")
177 - .append(pi.path().cost()); 173 + .append(intent.path().cost());
178 - 174 + }
179 - } else if (intent instanceof LinkCollectionIntent) {
180 - LinkCollectionIntent li = (LinkCollectionIntent) intent;
181 - Set<ConnectPoint> egresses = li.egressPoints();
182 175
176 + private void buildLinkConnectionDetails(LinkCollectionIntent intent) {
183 details.append(" links=") 177 details.append(" links=")
184 - .append(li.links().toString()) 178 + .append(intent.links())
185 .append(", egress="); 179 .append(", egress=");
186 180
187 - for (ConnectPoint egress : egresses) { 181 + appendMultiPointsDetails(intent.egressPoints());
188 - details.append(egress.elementId().toString())
189 - .append('/')
190 - .append(egress.port().toString())
191 - .append(' ');
192 } 182 }
183 +
184 + private String formatDetails(Intent intent) {
185 + if (intent instanceof ConnectivityIntent) {
186 + buildConnectivityDetails((ConnectivityIntent) intent);
193 } 187 }
194 188
195 - if (details.toString().equals("")) { 189 + if (intent instanceof HostToHostIntent) {
196 - details.append("No details for this intent"); 190 + buildHostToHostDetails((HostToHostIntent) intent);
191 +
192 + } else if (intent instanceof PointToPointIntent) {
193 + buildPointToPointDetails((PointToPointIntent) intent);
194 +
195 + } else if (intent instanceof MultiPointToSinglePointIntent) {
196 + buildMPToSPDetails((MultiPointToSinglePointIntent) intent);
197 +
198 + } else if (intent instanceof SinglePointToMultiPointIntent) {
199 + buildSPToMPDetails((SinglePointToMultiPointIntent) intent);
200 +
201 + } else if (intent instanceof PathIntent) {
202 + buildPathDetails((PathIntent) intent);
203 +
204 + } else if (intent instanceof LinkCollectionIntent) {
205 + buildLinkConnectionDetails((LinkCollectionIntent) intent);
206 + }
207 +
208 + if (details.length() == 0) {
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
......