Showing
6 changed files
with
157 additions
and
15 deletions
... | @@ -6,7 +6,7 @@ import java.util.Collections; | ... | @@ -6,7 +6,7 @@ import java.util.Collections; |
6 | import java.util.Objects; | 6 | import java.util.Objects; |
7 | import java.util.Set; | 7 | import java.util.Set; |
8 | 8 | ||
9 | -import org.onlab.packet.IpAddress; | 9 | +import org.onlab.packet.IpPrefix; |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * Default port implementation. | 12 | * Default port implementation. |
... | @@ -18,7 +18,7 @@ public class DefaultPort implements Port { | ... | @@ -18,7 +18,7 @@ public class DefaultPort implements Port { |
18 | private final boolean isEnabled; | 18 | private final boolean isEnabled; |
19 | 19 | ||
20 | // Attributes | 20 | // Attributes |
21 | - private final Set<IpAddress> ipAddresses; | 21 | + private final Set<IpPrefix> ipAddresses; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Creates a network element attributed to the specified provider. | 24 | * Creates a network element attributed to the specified provider. |
... | @@ -41,7 +41,7 @@ public class DefaultPort implements Port { | ... | @@ -41,7 +41,7 @@ public class DefaultPort implements Port { |
41 | * @param ipAddresses set of IP addresses assigned to the port | 41 | * @param ipAddresses set of IP addresses assigned to the port |
42 | */ | 42 | */ |
43 | public DefaultPort(Element element, PortNumber number, | 43 | public DefaultPort(Element element, PortNumber number, |
44 | - boolean isEnabled, Set<IpAddress> ipAddresses) { | 44 | + boolean isEnabled, Set<IpPrefix> ipAddresses) { |
45 | this.element = element; | 45 | this.element = element; |
46 | this.number = number; | 46 | this.number = number; |
47 | this.isEnabled = isEnabled; | 47 | this.isEnabled = isEnabled; |
... | @@ -90,7 +90,7 @@ public class DefaultPort implements Port { | ... | @@ -90,7 +90,7 @@ public class DefaultPort implements Port { |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | - public Set<IpAddress> ipAddresses() { | 93 | + public Set<IpPrefix> ipAddresses() { |
94 | return ipAddresses; | 94 | return ipAddresses; |
95 | } | 95 | } |
96 | 96 | ... | ... |
... | @@ -2,7 +2,7 @@ package org.onlab.onos.net; | ... | @@ -2,7 +2,7 @@ package org.onlab.onos.net; |
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.Set; |
4 | 4 | ||
5 | -import org.onlab.packet.IpAddress; | 5 | +import org.onlab.packet.IpPrefix; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Abstraction of a network port. | 8 | * Abstraction of a network port. |
... | @@ -39,5 +39,5 @@ public interface Port { | ... | @@ -39,5 +39,5 @@ public interface Port { |
39 | * @return the set of IP addresses configured on the port. The set is empty | 39 | * @return the set of IP addresses configured on the port. The set is empty |
40 | * if no addresses are configured. | 40 | * if no addresses are configured. |
41 | */ | 41 | */ |
42 | - Set<IpAddress> ipAddresses(); | 42 | + Set<IpPrefix> ipAddresses(); |
43 | } | 43 | } | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | +import java.util.Set; | ||
4 | + | ||
3 | import org.onlab.onos.net.ConnectPoint; | 5 | import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.Host; | 7 | import org.onlab.onos.net.Host; |
... | @@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix; | ... | @@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix; |
8 | import org.onlab.packet.MacAddress; | 10 | import org.onlab.packet.MacAddress; |
9 | import org.onlab.packet.VlanId; | 11 | import org.onlab.packet.VlanId; |
10 | 12 | ||
11 | -import java.util.Set; | ||
12 | - | ||
13 | /** | 13 | /** |
14 | * Service for interacting with the inventory of end-station hosts. | 14 | * Service for interacting with the inventory of end-station hosts. |
15 | */ | 15 | */ |
... | @@ -82,6 +82,22 @@ public interface HostService { | ... | @@ -82,6 +82,22 @@ public interface HostService { |
82 | Set<Host> getConnectedHosts(DeviceId deviceId); | 82 | Set<Host> getConnectedHosts(DeviceId deviceId); |
83 | 83 | ||
84 | /** | 84 | /** |
85 | + * Requests the host service to monitor hosts with the given IP address and | ||
86 | + * notify listeners of changes. | ||
87 | + * | ||
88 | + * @param ip IP address of the host to monitor | ||
89 | + */ | ||
90 | + void monitorIp(IpPrefix ip); | ||
91 | + | ||
92 | + /** | ||
93 | + * Stops the host service from monitoring an IP address. | ||
94 | + * | ||
95 | + * @param ip IP address to stop monitoring | ||
96 | + */ | ||
97 | + // TODO clients can cancel other client's requests | ||
98 | + void stopMonitoringIp(IpPrefix ip); | ||
99 | + | ||
100 | + /** | ||
85 | * Adds the specified host listener. | 101 | * Adds the specified host listener. |
86 | * | 102 | * |
87 | * @param listener host listener | 103 | * @param listener host listener | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | +import java.util.Set; | ||
4 | + | ||
3 | import org.onlab.onos.net.ConnectPoint; | 5 | import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.Host; | 7 | import org.onlab.onos.net.Host; |
... | @@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix; | ... | @@ -8,8 +10,6 @@ import org.onlab.packet.IpPrefix; |
8 | import org.onlab.packet.MacAddress; | 10 | import org.onlab.packet.MacAddress; |
9 | import org.onlab.packet.VlanId; | 11 | import org.onlab.packet.VlanId; |
10 | 12 | ||
11 | -import java.util.Set; | ||
12 | - | ||
13 | /** | 13 | /** |
14 | * Test adapter for host service. | 14 | * Test adapter for host service. |
15 | */ | 15 | */ |
... | @@ -55,6 +55,14 @@ public class HostServiceAdapter implements HostService { | ... | @@ -55,6 +55,14 @@ public class HostServiceAdapter implements HostService { |
55 | } | 55 | } |
56 | 56 | ||
57 | @Override | 57 | @Override |
58 | + public void monitorIp(IpPrefix ip) { | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public void stopMonitoringIp(IpPrefix ip) { | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
58 | public void addListener(HostListener listener) { | 66 | public void addListener(HostListener listener) { |
59 | } | 67 | } |
60 | 68 | ... | ... |
1 | package org.onlab.onos.net.trivial.host.impl; | 1 | package org.onlab.onos.net.trivial.host.impl; |
2 | 2 | ||
3 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
4 | +import static org.slf4j.LoggerFactory.getLogger; | ||
5 | + | ||
6 | +import java.util.Set; | ||
7 | + | ||
3 | import org.apache.felix.scr.annotations.Activate; | 8 | import org.apache.felix.scr.annotations.Activate; |
4 | import org.apache.felix.scr.annotations.Component; | 9 | import org.apache.felix.scr.annotations.Component; |
5 | import org.apache.felix.scr.annotations.Deactivate; | 10 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -28,11 +33,6 @@ import org.onlab.packet.MacAddress; | ... | @@ -28,11 +33,6 @@ import org.onlab.packet.MacAddress; |
28 | import org.onlab.packet.VlanId; | 33 | import org.onlab.packet.VlanId; |
29 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
30 | 35 | ||
31 | -import java.util.Set; | ||
32 | - | ||
33 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
34 | -import static org.slf4j.LoggerFactory.getLogger; | ||
35 | - | ||
36 | /** | 36 | /** |
37 | * Provides basic implementation of the host SB & NB APIs. | 37 | * Provides basic implementation of the host SB & NB APIs. |
38 | */ | 38 | */ |
... | @@ -118,6 +118,16 @@ public class SimpleHostManager | ... | @@ -118,6 +118,16 @@ public class SimpleHostManager |
118 | } | 118 | } |
119 | 119 | ||
120 | @Override | 120 | @Override |
121 | + public void monitorIp(IpPrefix ip) { | ||
122 | + // TODO pass through to SimpleHostMonitor | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public void stopMonitoringIp(IpPrefix ip) { | ||
127 | + // TODO pass through to SimpleHostMonitor | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
121 | public void addListener(HostListener listener) { | 131 | public void addListener(HostListener listener) { |
122 | listenerRegistry.addListener(listener); | 132 | listenerRegistry.addListener(listener); |
123 | } | 133 | } | ... | ... |
1 | +package org.onlab.onos.net.trivial.host.impl; | ||
2 | + | ||
3 | +import java.util.HashSet; | ||
4 | +import java.util.Set; | ||
5 | +import java.util.concurrent.TimeUnit; | ||
6 | + | ||
7 | +import org.jboss.netty.util.Timeout; | ||
8 | +import org.jboss.netty.util.TimerTask; | ||
9 | +import org.onlab.onos.net.Device; | ||
10 | +import org.onlab.onos.net.Host; | ||
11 | +import org.onlab.onos.net.Port; | ||
12 | +import org.onlab.onos.net.device.DeviceService; | ||
13 | +import org.onlab.onos.net.host.HostProvider; | ||
14 | +import org.onlab.onos.net.host.HostService; | ||
15 | +import org.onlab.onos.net.packet.PacketProvider; | ||
16 | +import org.onlab.onos.net.topology.TopologyService; | ||
17 | +import org.onlab.packet.IpPrefix; | ||
18 | +import org.onlab.util.Timer; | ||
19 | + | ||
20 | +public class SimpleHostMonitor implements TimerTask { | ||
21 | + | ||
22 | + private final HostService hostService; | ||
23 | + private final TopologyService topologyService; | ||
24 | + private final DeviceService deviceService; | ||
25 | + private final HostProvider hostProvider; | ||
26 | + private final PacketProvider packetProvider; | ||
27 | + | ||
28 | + private final Set<IpPrefix> monitoredAddresses; | ||
29 | + | ||
30 | + private final long probeRate; | ||
31 | + | ||
32 | + private Timeout timeout; | ||
33 | + | ||
34 | + public SimpleHostMonitor(HostService hostService, TopologyService topologyService, | ||
35 | + DeviceService deviceService, | ||
36 | + HostProvider hostProvider, PacketProvider packetProvider) { | ||
37 | + this.hostService = hostService; | ||
38 | + this.topologyService = topologyService; | ||
39 | + this.deviceService = deviceService; | ||
40 | + this.hostProvider = hostProvider; | ||
41 | + this.packetProvider = packetProvider; | ||
42 | + | ||
43 | + monitoredAddresses = new HashSet<>(); | ||
44 | + | ||
45 | + probeRate = 30000; // milliseconds | ||
46 | + | ||
47 | + timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); | ||
48 | + } | ||
49 | + | ||
50 | + public void addMonitoringFor(IpPrefix ip) { | ||
51 | + monitoredAddresses.add(ip); | ||
52 | + } | ||
53 | + | ||
54 | + public void stopMonitoring(IpPrefix ip) { | ||
55 | + monitoredAddresses.remove(ip); | ||
56 | + } | ||
57 | + | ||
58 | + public void shutdown() { | ||
59 | + timeout.cancel(); | ||
60 | + } | ||
61 | + | ||
62 | + @Override | ||
63 | + public void run(Timeout timeout) throws Exception { | ||
64 | + for (IpPrefix ip : monitoredAddresses) { | ||
65 | + Set<Host> hosts = hostService.getHostsByIp(ip); | ||
66 | + | ||
67 | + if (hosts.isEmpty()) { | ||
68 | + sendArpRequest(ip); | ||
69 | + } else { | ||
70 | + for (Host host : hosts) { | ||
71 | + hostProvider.triggerProbe(host); | ||
72 | + } | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
76 | + timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Sends an ARP request for the given IP address. | ||
81 | + * | ||
82 | + * @param targetIp IP address to ARP for | ||
83 | + */ | ||
84 | + private void sendArpRequest(IpPrefix targetIp) { | ||
85 | + // emit ARP packet out appropriate ports | ||
86 | + | ||
87 | + // if ip in one of the configured (external) subnets | ||
88 | + // sent out that port | ||
89 | + // else (ip isn't in any configured subnet) | ||
90 | + // send out all non-external edge ports | ||
91 | + | ||
92 | + for (Device device : deviceService.getDevices()) { | ||
93 | + for (Port port : deviceService.getPorts(device.id())) { | ||
94 | + for (IpPrefix ip : port.ipAddresses()) { | ||
95 | + if (ip.contains(targetIp)) { | ||
96 | + sendProbe(port, targetIp); | ||
97 | + continue; | ||
98 | + } | ||
99 | + } | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + private void sendProbe(Port port, IpPrefix targetIp) { | ||
106 | + | ||
107 | + } | ||
108 | +} |
-
Please register or login to post a comment