tom

Added display of hosts in the topology viewer and fixed a glitch in the host provider.

...@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; ...@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
5 import com.fasterxml.jackson.databind.node.ObjectNode; 5 import com.fasterxml.jackson.databind.node.ObjectNode;
6 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
7 import org.onlab.onos.net.ElementId; 7 import org.onlab.onos.net.ElementId;
8 +import org.onlab.onos.net.Host;
8 import org.onlab.onos.net.Link; 9 import org.onlab.onos.net.Link;
9 import org.onlab.onos.net.Path; 10 import org.onlab.onos.net.Path;
10 import org.onlab.onos.net.device.DeviceService; 11 import org.onlab.onos.net.device.DeviceService;
...@@ -26,6 +27,7 @@ import java.util.Map; ...@@ -26,6 +27,7 @@ import java.util.Map;
26 import java.util.Set; 27 import java.util.Set;
27 28
28 import static org.onlab.onos.net.DeviceId.deviceId; 29 import static org.onlab.onos.net.DeviceId.deviceId;
30 +import static org.onlab.onos.net.PortNumber.portNumber;
29 31
30 /** 32 /**
31 * Topology viewer resource. 33 * Topology viewer resource.
...@@ -67,13 +69,10 @@ public class TopologyResource extends BaseResource { ...@@ -67,13 +69,10 @@ public class TopologyResource extends BaseResource {
67 69
68 // Merge the exterior and interior vertexes and inject host links as 70 // Merge the exterior and interior vertexes and inject host links as
69 // the exterior edges. 71 // the exterior edges.
70 -// Iterator<Host> hosts = hostService.getHosts(); 72 + for (Host host : hostService.getHosts()) {
71 -// while (hosts.hasNext()) { 73 + vertexesNode.add(json(mapper, host.id(), 3, true));
72 -// Host host = hosts.next(); 74 + edgesNode.add(json(mapper, 1, host.location(), new ConnectPoint(host.id(), portNumber(-1))));
73 -// vertexesNode.add(json(mapper, host.id().ip().toString(), 3, true)); 75 + }
74 -// edgesNode.add(json(mapper, 1, host.ip().toString(),
75 -// host.location().elementId().uri()));
76 -// }
77 76
78 // Now put the vertexes and edges into a root node and ship them off 77 // Now put the vertexes and edges into a root node and ship them off
79 ObjectNode rootNode = mapper.createObjectNode(); 78 ObjectNode rootNode = mapper.createObjectNode();
......
...@@ -46,7 +46,8 @@ public class DefaultTopologyProvider extends AbstractProvider ...@@ -46,7 +46,8 @@ public class DefaultTopologyProvider extends AbstractProvider
46 private static final int MAX_BATCH_MS = 200; 46 private static final int MAX_BATCH_MS = 200;
47 private static final int MAX_THREADS = 8; 47 private static final int MAX_THREADS = 8;
48 48
49 - // FIXME: Replace with a system-wide timer instance 49 + // FIXME: Replace with a system-wide timer instance;
50 + // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt
50 private static final Timer TIMER = new Timer(); 51 private static final Timer TIMER = new Timer();
51 52
52 private final Logger log = getLogger(getClass()); 53 private final Logger log = getLogger(getClass());
......
1 package org.onlab.onos.provider.of.host.impl; 1 package org.onlab.onos.provider.of.host.impl;
2 2
3 -import java.util.Set;
4 -
5 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
6 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
7 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
8 import org.apache.felix.scr.annotations.Reference; 6 import org.apache.felix.scr.annotations.Reference;
9 import org.apache.felix.scr.annotations.ReferenceCardinality; 7 import org.apache.felix.scr.annotations.ReferenceCardinality;
10 -import org.onlab.onos.net.DeviceId; 8 +import org.onlab.onos.net.ConnectPoint;
11 import org.onlab.onos.net.Host; 9 import org.onlab.onos.net.Host;
12 import org.onlab.onos.net.HostId; 10 import org.onlab.onos.net.HostId;
13 import org.onlab.onos.net.HostLocation; 11 import org.onlab.onos.net.HostLocation;
14 -import org.onlab.onos.net.PortNumber;
15 import org.onlab.onos.net.host.DefaultHostDescription; 12 import org.onlab.onos.net.host.DefaultHostDescription;
16 import org.onlab.onos.net.host.HostDescription; 13 import org.onlab.onos.net.host.HostDescription;
17 import org.onlab.onos.net.host.HostProvider; 14 import org.onlab.onos.net.host.HostProvider;
...@@ -19,6 +16,8 @@ import org.onlab.onos.net.host.HostProviderRegistry; ...@@ -19,6 +16,8 @@ import org.onlab.onos.net.host.HostProviderRegistry;
19 import org.onlab.onos.net.host.HostProviderService; 16 import org.onlab.onos.net.host.HostProviderService;
20 import org.onlab.onos.net.provider.AbstractProvider; 17 import org.onlab.onos.net.provider.AbstractProvider;
21 import org.onlab.onos.net.provider.ProviderId; 18 import org.onlab.onos.net.provider.ProviderId;
19 +import org.onlab.onos.net.topology.Topology;
20 +import org.onlab.onos.net.topology.TopologyService;
22 import org.onlab.onos.of.controller.Dpid; 21 import org.onlab.onos.of.controller.Dpid;
23 import org.onlab.onos.of.controller.OpenFlowController; 22 import org.onlab.onos.of.controller.OpenFlowController;
24 import org.onlab.onos.of.controller.OpenFlowPacketContext; 23 import org.onlab.onos.of.controller.OpenFlowPacketContext;
...@@ -29,8 +28,11 @@ import org.onlab.packet.IPAddress; ...@@ -29,8 +28,11 @@ import org.onlab.packet.IPAddress;
29 import org.onlab.packet.VLANID; 28 import org.onlab.packet.VLANID;
30 import org.slf4j.Logger; 29 import org.slf4j.Logger;
31 30
32 -import com.google.common.collect.Sets; 31 +import java.util.Set;
33 32
33 +import static com.google.common.collect.Sets.newHashSet;
34 +import static org.onlab.onos.net.DeviceId.deviceId;
35 +import static org.onlab.onos.net.PortNumber.portNumber;
34 import static org.slf4j.LoggerFactory.getLogger; 36 import static org.slf4j.LoggerFactory.getLogger;
35 37
36 /** 38 /**
...@@ -48,6 +50,9 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -48,6 +50,9 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 protected OpenFlowController controller; 51 protected OpenFlowController controller;
50 52
53 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 + protected TopologyService topologyService;
55 +
51 private HostProviderService providerService; 56 private HostProviderService providerService;
52 57
53 private final InternalHostProvider listener = new InternalHostProvider(); 58 private final InternalHostProvider listener = new InternalHostProvider();
...@@ -87,25 +92,32 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -87,25 +92,32 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
87 public void handlePacket(OpenFlowPacketContext pktCtx) { 92 public void handlePacket(OpenFlowPacketContext pktCtx) {
88 Ethernet eth = pktCtx.parsed(); 93 Ethernet eth = pktCtx.parsed();
89 94
90 - // potentially a new or moved host 95 + // Potentially a new or moved host
91 if (eth.getEtherType() == Ethernet.TYPE_ARP) { 96 if (eth.getEtherType() == Ethernet.TYPE_ARP) {
92 VLANID vlan = VLANID.vlanId(eth.getVlanID()); 97 VLANID vlan = VLANID.vlanId(eth.getVlanID());
93 - HostId hid = HostId.hostId( 98 + ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())),
94 - eth.getSourceMAC(), vlan); 99 + portNumber(pktCtx.inPort()));
95 - HostLocation hloc = new HostLocation( 100 +
96 - DeviceId.deviceId(Dpid.uri(pktCtx.dpid())), 101 + // If this is not an edge port, bail out.
97 - PortNumber.portNumber(pktCtx.inPort()), 102 + Topology topology = topologyService.currentTopology();
103 + if (topologyService.isInfrastructure(topology, heardOn)) {
104 + return;
105 + }
106 +
107 + HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())),
108 + portNumber(pktCtx.inPort()),
98 System.currentTimeMillis()); 109 System.currentTimeMillis());
110 +
111 + HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);
99 ARP arp = (ARP) eth.getPayload(); 112 ARP arp = (ARP) eth.getPayload();
100 - Set<IPAddress> ips = Sets.newHashSet(IPAddress.valueOf(arp.getSenderProtocolAddress())); 113 + Set<IPAddress> ips = newHashSet(IPAddress.valueOf(arp.getSenderProtocolAddress()));
101 - HostDescription hdescr = new DefaultHostDescription( 114 + HostDescription hdescr =
102 - eth.getSourceMAC(), 115 + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips);
103 - vlan,
104 - hloc,
105 - ips);
106 providerService.hostDetected(hid, hdescr); 116 providerService.hostDetected(hid, hdescr);
107 117
108 } 118 }
119 +
120 + // TODO: Use DHCP packets as well later...
109 } 121 }
110 122
111 } 123 }
......