Bri Prebilic Cole

GUI -- Refactored IntentView java backend for details.

Change-Id: Id0fb2c1cdb61e801576980030493ff98d555089c
......@@ -20,7 +20,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.intent.ConnectivityIntent;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
......@@ -89,133 +92,142 @@ public class IntentViewMessageHandler extends AbstractTabularViewMessageHandler
APP_ID, KEY, TYPE, PRIORITY, RESOURCES, DETAILS
};
private String formatDetails(Intent intent) {
StringBuilder details = new StringBuilder("");
private StringBuilder details = new StringBuilder();
if (intent instanceof ConnectivityIntent) {
ConnectivityIntent ci = (ConnectivityIntent) intent;
if (!ci.selector().criteria().isEmpty()) {
details.append("selector=")
.append(ci.selector().criteria().toString());
private void appendMultiPointsDetails(Set<ConnectPoint> points) {
for (ConnectPoint point : points) {
details.append(point.elementId())
.append('/')
.append(point.port())
.append(' ');
}
if (!ci.treatment().allInstructions().isEmpty()) {
details.append("treatment=")
.append(ci.treatment().allInstructions().toString());
}
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
details.append("constraints=")
.append(ci.constraints().toString());
private void buildConnectivityDetails(ConnectivityIntent intent) {
Set<Criterion> criteria = intent.selector().criteria();
List<Instruction> instructions = intent.treatment().allInstructions();
List<Constraint> constraints = intent.constraints();
if (!criteria.isEmpty()) {
details.append("selector=").append(criteria);
}
if (!instructions.isEmpty()) {
details.append("treatment=").append(instructions);
}
if (constraints != null && !constraints.isEmpty()) {
details.append("constraints=").append(constraints);
}
}
if (intent instanceof HostToHostIntent) {
HostToHostIntent pi = (HostToHostIntent) intent;
private void buildHostToHostDetails(HostToHostIntent intent) {
details.append(" host1=")
.append(pi.one().toString())
.append(intent.one())
.append(", host2=")
.append(pi.two().toString());
.append(intent.two());
}
} else if (intent instanceof PointToPointIntent) {
PointToPointIntent pi = (PointToPointIntent) intent;
ConnectPoint ingress = pi.ingressPoint();
ConnectPoint egress = pi.egressPoint();
private void buildPointToPointDetails(PointToPointIntent intent) {
ConnectPoint ingress = intent.ingressPoint();
ConnectPoint egress = intent.egressPoint();
details.append(" ingress=")
.append(ingress.elementId().toString())
.append(ingress.elementId())
.append('/')
.append(ingress.port().toString())
.append(ingress.port())
.append(", egress=")
.append(egress.elementId().toString())
.append(egress.elementId())
.append('/')
.append(egress.port().toString())
.append(egress.port())
.append(' ');
}
} else if (intent instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent pi
= (MultiPointToSinglePointIntent) intent;
Set<ConnectPoint> ingresses = pi.ingressPoints();
ConnectPoint egress = pi.egressPoint();
private void buildMPToSPDetails(MultiPointToSinglePointIntent intent) {
ConnectPoint egress = intent.egressPoint();
details.append(" ingress=");
for (ConnectPoint ingress : ingresses) {
details.append(ingress.elementId().toString())
.append('/')
.append(ingress.port().toString())
.append(' ');
}
appendMultiPointsDetails(intent.ingressPoints());
details.append(", egress=")
.append(egress.elementId().toString())
.append(egress.elementId())
.append('/')
.append(egress.port().toString())
.append(egress.port())
.append(' ');
}
} else if (intent instanceof SinglePointToMultiPointIntent) {
SinglePointToMultiPointIntent pi
= (SinglePointToMultiPointIntent) intent;
ConnectPoint ingress = pi.ingressPoint();
Set<ConnectPoint> egresses = pi.egressPoints();
private void buildSPToMPDetails(SinglePointToMultiPointIntent intent) {
ConnectPoint ingress = intent.ingressPoint();
details.append(" ingress=")
.append(ingress.elementId().toString())
.append(ingress.elementId())
.append('/')
.append(ingress.port().toString())
.append(ingress.port())
.append(", egress=");
for (ConnectPoint egress : egresses) {
details.append(egress.elementId().toString())
.append('/')
.append(egress.port().toString())
.append(' ');
appendMultiPointsDetails(intent.egressPoints());
}
} else if (intent instanceof PathIntent) {
PathIntent pi = (PathIntent) intent;
private void buildPathDetails(PathIntent intent) {
details.append(" path=")
.append(pi.path().links().toString())
.append(intent.path().links())
.append(", cost=")
.append(pi.path().cost());
} else if (intent instanceof LinkCollectionIntent) {
LinkCollectionIntent li = (LinkCollectionIntent) intent;
Set<ConnectPoint> egresses = li.egressPoints();
.append(intent.path().cost());
}
private void buildLinkConnectionDetails(LinkCollectionIntent intent) {
details.append(" links=")
.append(li.links().toString())
.append(intent.links())
.append(", egress=");
for (ConnectPoint egress : egresses) {
details.append(egress.elementId().toString())
.append('/')
.append(egress.port().toString())
.append(' ');
appendMultiPointsDetails(intent.egressPoints());
}
private String formatDetails(Intent intent) {
if (intent instanceof ConnectivityIntent) {
buildConnectivityDetails((ConnectivityIntent) intent);
}
if (details.toString().equals("")) {
details.append("No details for this intent");
if (intent instanceof HostToHostIntent) {
buildHostToHostDetails((HostToHostIntent) intent);
} else if (intent instanceof PointToPointIntent) {
buildPointToPointDetails((PointToPointIntent) intent);
} else if (intent instanceof MultiPointToSinglePointIntent) {
buildMPToSPDetails((MultiPointToSinglePointIntent) intent);
} else if (intent instanceof SinglePointToMultiPointIntent) {
buildSPToMPDetails((SinglePointToMultiPointIntent) intent);
} else if (intent instanceof PathIntent) {
buildPathDetails((PathIntent) intent);
} else if (intent instanceof LinkCollectionIntent) {
buildLinkConnectionDetails((LinkCollectionIntent) intent);
}
if (details.length() == 0) {
details.append("(No details for this intent)");
} else {
details.insert(0, "Details: ");
}
return details.toString();
}
private String formatResources(Intent i) {
if (!i.resources().isEmpty()) {
return "Resources: " + i.resources();
}
return "No resources for this intent.";
private String formatResources(Intent intent) {
return (intent.resources().isEmpty() ?
"(No resources for this intent)" :
"Resources: " + intent.resources());
}
public IntentTableRow(Intent i) {
ApplicationId appid = i.appId();
public IntentTableRow(Intent intent) {
ApplicationId appid = intent.appId();
add(APP_ID, String.valueOf(appid.id()) + " : " + appid.name());
add(KEY, i.key().toString());
add(TYPE, i.getClass().getSimpleName());
add(PRIORITY, Integer.toString(i.priority()));
add(RESOURCES, formatResources(i));
add(DETAILS, formatDetails(i));
add(KEY, intent.key().toString());
add(TYPE, intent.getClass().getSimpleName());
add(PRIORITY, Integer.toString(intent.priority()));
add(RESOURCES, formatResources(intent));
add(DETAILS, formatDetails(intent));
}
@Override
......