ONOS-249 Added summary of flow rules for the selected device.
Change-Id: Ie2903e87e1284bc6fae49b81d9629ce913a1af99
Showing
1 changed file
with
25 additions
and
5 deletions
| ... | @@ -37,6 +37,8 @@ import org.onlab.onos.net.HostLocation; | ... | @@ -37,6 +37,8 @@ import org.onlab.onos.net.HostLocation; |
| 37 | import org.onlab.onos.net.Link; | 37 | import org.onlab.onos.net.Link; |
| 38 | import org.onlab.onos.net.device.DeviceEvent; | 38 | import org.onlab.onos.net.device.DeviceEvent; |
| 39 | import org.onlab.onos.net.device.DeviceService; | 39 | import org.onlab.onos.net.device.DeviceService; |
| 40 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 41 | +import org.onlab.onos.net.flow.FlowRuleService; | ||
| 40 | import org.onlab.onos.net.host.HostEvent; | 42 | import org.onlab.onos.net.host.HostEvent; |
| 41 | import org.onlab.onos.net.host.HostService; | 43 | import org.onlab.onos.net.host.HostService; |
| 42 | import org.onlab.onos.net.intent.Intent; | 44 | import org.onlab.onos.net.intent.Intent; |
| ... | @@ -106,6 +108,7 @@ public abstract class TopologyViewMessages { | ... | @@ -106,6 +108,7 @@ public abstract class TopologyViewMessages { |
| 106 | protected final HostService hostService; | 108 | protected final HostService hostService; |
| 107 | protected final MastershipService mastershipService; | 109 | protected final MastershipService mastershipService; |
| 108 | protected final IntentService intentService; | 110 | protected final IntentService intentService; |
| 111 | + protected final FlowRuleService flowService; | ||
| 109 | protected final StatisticService statService; | 112 | protected final StatisticService statService; |
| 110 | 113 | ||
| 111 | protected final ObjectMapper mapper = new ObjectMapper(); | 114 | protected final ObjectMapper mapper = new ObjectMapper(); |
| ... | @@ -126,6 +129,7 @@ public abstract class TopologyViewMessages { | ... | @@ -126,6 +129,7 @@ public abstract class TopologyViewMessages { |
| 126 | hostService = directory.get(HostService.class); | 129 | hostService = directory.get(HostService.class); |
| 127 | mastershipService = directory.get(MastershipService.class); | 130 | mastershipService = directory.get(MastershipService.class); |
| 128 | intentService = directory.get(IntentService.class); | 131 | intentService = directory.get(IntentService.class); |
| 132 | + flowService = directory.get(FlowRuleService.class); | ||
| 129 | statService = directory.get(StatisticService.class); | 133 | statService = directory.get(StatisticService.class); |
| 130 | } | 134 | } |
| 131 | 135 | ||
| ... | @@ -412,11 +416,13 @@ public abstract class TopologyViewMessages { | ... | @@ -412,11 +416,13 @@ public abstract class TopologyViewMessages { |
| 412 | protected ObjectNode deviceDetails(DeviceId deviceId, long sid) { | 416 | protected ObjectNode deviceDetails(DeviceId deviceId, long sid) { |
| 413 | Device device = deviceService.getDevice(deviceId); | 417 | Device device = deviceService.getDevice(deviceId); |
| 414 | Annotations annot = device.annotations(); | 418 | Annotations annot = device.annotations(); |
| 419 | + String name = annot.value("name"); | ||
| 415 | int portCount = deviceService.getPorts(deviceId).size(); | 420 | int portCount = deviceService.getPorts(deviceId).size(); |
| 421 | + int flowCount = getFlowCount(deviceId); | ||
| 416 | return envelope("showDetails", sid, | 422 | return envelope("showDetails", sid, |
| 417 | - json(deviceId.toString(), | 423 | + json(isNullOrEmpty(name) ? deviceId.toString() : name, |
| 418 | device.type().toString().toLowerCase(), | 424 | device.type().toString().toLowerCase(), |
| 419 | - new Prop("Name", annot.value("name")), | 425 | + new Prop("URI", deviceId.toString()), |
| 420 | new Prop("Vendor", device.manufacturer()), | 426 | new Prop("Vendor", device.manufacturer()), |
| 421 | new Prop("H/W Version", device.hwVersion()), | 427 | new Prop("H/W Version", device.hwVersion()), |
| 422 | new Prop("S/W Version", device.swVersion()), | 428 | new Prop("S/W Version", device.swVersion()), |
| ... | @@ -425,20 +431,34 @@ public abstract class TopologyViewMessages { | ... | @@ -425,20 +431,34 @@ public abstract class TopologyViewMessages { |
| 425 | new Prop("Latitude", annot.value("latitude")), | 431 | new Prop("Latitude", annot.value("latitude")), |
| 426 | new Prop("Longitude", annot.value("longitude")), | 432 | new Prop("Longitude", annot.value("longitude")), |
| 427 | new Prop("Ports", Integer.toString(portCount)), | 433 | new Prop("Ports", Integer.toString(portCount)), |
| 434 | + new Prop("Flows", Integer.toString(flowCount)), | ||
| 428 | new Separator(), | 435 | new Separator(), |
| 429 | new Prop("Master", master(deviceId)))); | 436 | new Prop("Master", master(deviceId)))); |
| 430 | } | 437 | } |
| 431 | 438 | ||
| 439 | + protected int getFlowCount(DeviceId deviceId) { | ||
| 440 | + int count = 0; | ||
| 441 | + Iterator<FlowEntry> it = flowService.getFlowEntries(deviceId).iterator(); | ||
| 442 | + while (it.hasNext()) { | ||
| 443 | + count++; | ||
| 444 | + it.next(); | ||
| 445 | + } | ||
| 446 | + return count; | ||
| 447 | + } | ||
| 448 | + | ||
| 432 | // Returns host details response. | 449 | // Returns host details response. |
| 433 | protected ObjectNode hostDetails(HostId hostId, long sid) { | 450 | protected ObjectNode hostDetails(HostId hostId, long sid) { |
| 434 | Host host = hostService.getHost(hostId); | 451 | Host host = hostService.getHost(hostId); |
| 435 | Annotations annot = host.annotations(); | 452 | Annotations annot = host.annotations(); |
| 436 | String type = annot.value("type"); | 453 | String type = annot.value("type"); |
| 454 | + String name = annot.value("name"); | ||
| 455 | + String vlan = host.vlan().toString(); | ||
| 437 | return envelope("showDetails", sid, | 456 | return envelope("showDetails", sid, |
| 438 | - json(hostId.toString(), isNullOrEmpty(type) ? "host" : type, | 457 | + json(isNullOrEmpty(name) ? hostId.toString() : name, |
| 439 | - new Prop("Name", annot.value("name")), | 458 | + isNullOrEmpty(type) ? "host" : type, |
| 440 | new Prop("MAC", host.mac().toString()), | 459 | new Prop("MAC", host.mac().toString()), |
| 441 | - new Prop("IP", host.ipAddresses().toString()), | 460 | + new Prop("IP", host.ipAddresses().toString().replaceAll("[\\[\\]]", "")), |
| 461 | + new Prop("VLAN", vlan.equals("-1") ? "none" : vlan), | ||
| 442 | new Separator(), | 462 | new Separator(), |
| 443 | new Prop("Latitude", annot.value("latitude")), | 463 | new Prop("Latitude", annot.value("latitude")), |
| 444 | new Prop("Longitude", annot.value("longitude")))); | 464 | new Prop("Longitude", annot.value("longitude")))); | ... | ... |
-
Please register or login to post a comment