Showing
3 changed files
with
55 additions
and
18 deletions
... | @@ -76,7 +76,7 @@ public class HostManager | ... | @@ -76,7 +76,7 @@ public class HostManager |
76 | eventDispatcher.addSink(HostEvent.class, listenerRegistry); | 76 | eventDispatcher.addSink(HostEvent.class, listenerRegistry); |
77 | 77 | ||
78 | monitor = new HostMonitor(deviceService, packetService, this); | 78 | monitor = new HostMonitor(deviceService, packetService, this); |
79 | - | 79 | + monitor.start(); |
80 | } | 80 | } |
81 | 81 | ||
82 | @Deactivate | 82 | @Deactivate | ... | ... |
... | @@ -2,7 +2,7 @@ package org.onlab.onos.net.host.impl; | ... | @@ -2,7 +2,7 @@ package org.onlab.onos.net.host.impl; |
2 | 2 | ||
3 | import java.nio.ByteBuffer; | 3 | import java.nio.ByteBuffer; |
4 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
5 | -import java.util.HashSet; | 5 | +import java.util.Collections; |
6 | import java.util.List; | 6 | import java.util.List; |
7 | import java.util.Set; | 7 | import java.util.Set; |
8 | import java.util.concurrent.ConcurrentHashMap; | 8 | import java.util.concurrent.ConcurrentHashMap; |
... | @@ -33,8 +33,6 @@ import org.onlab.packet.IpAddress; | ... | @@ -33,8 +33,6 @@ import org.onlab.packet.IpAddress; |
33 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
34 | import org.onlab.packet.MacAddress; | 34 | import org.onlab.packet.MacAddress; |
35 | import org.onlab.util.Timer; | 35 | import org.onlab.util.Timer; |
36 | -import org.slf4j.Logger; | ||
37 | -import org.slf4j.LoggerFactory; | ||
38 | 36 | ||
39 | /** | 37 | /** |
40 | * Monitors hosts on the dataplane to detect changes in host data. | 38 | * Monitors hosts on the dataplane to detect changes in host data. |
... | @@ -44,15 +42,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -44,15 +42,6 @@ import org.slf4j.LoggerFactory; |
44 | * probe for hosts that have not yet been detected (specified by IP address). | 42 | * probe for hosts that have not yet been detected (specified by IP address). |
45 | */ | 43 | */ |
46 | public class HostMonitor implements TimerTask { | 44 | public class HostMonitor implements TimerTask { |
47 | - private static final Logger log = LoggerFactory.getLogger(HostMonitor.class); | ||
48 | - | ||
49 | - private static final byte[] ZERO_MAC_ADDRESS = | ||
50 | - MacAddress.valueOf("00:00:00:00:00:00").getAddress(); | ||
51 | - | ||
52 | - // TODO put on Ethernet | ||
53 | - private static final byte[] BROADCAST_MAC = | ||
54 | - MacAddress.valueOf("ff:ff:ff:ff:ff:ff").getAddress(); | ||
55 | - | ||
56 | private DeviceService deviceService; | 45 | private DeviceService deviceService; |
57 | private PacketService packetService; | 46 | private PacketService packetService; |
58 | private HostManager hostManager; | 47 | private HostManager hostManager; |
... | @@ -64,8 +53,15 @@ public class HostMonitor implements TimerTask { | ... | @@ -64,8 +53,15 @@ public class HostMonitor implements TimerTask { |
64 | private static final long DEFAULT_PROBE_RATE = 30000; // milliseconds | 53 | private static final long DEFAULT_PROBE_RATE = 30000; // milliseconds |
65 | private long probeRate = DEFAULT_PROBE_RATE; | 54 | private long probeRate = DEFAULT_PROBE_RATE; |
66 | 55 | ||
67 | - private final Timeout timeout; | 56 | + private Timeout timeout; |
68 | 57 | ||
58 | + /** | ||
59 | + * Creates a new host monitor. | ||
60 | + * | ||
61 | + * @param deviceService device service used to find edge ports | ||
62 | + * @param packetService packet service used to send packets on the data plane | ||
63 | + * @param hostService host service used to look up host information | ||
64 | + */ | ||
69 | public HostMonitor(DeviceService deviceService, PacketService packetService, | 65 | public HostMonitor(DeviceService deviceService, PacketService packetService, |
70 | HostManager hostService) { | 66 | HostManager hostService) { |
71 | 67 | ||
... | @@ -73,24 +69,59 @@ public class HostMonitor implements TimerTask { | ... | @@ -73,24 +69,59 @@ public class HostMonitor implements TimerTask { |
73 | this.packetService = packetService; | 69 | this.packetService = packetService; |
74 | this.hostManager = hostService; | 70 | this.hostManager = hostService; |
75 | 71 | ||
76 | - monitoredAddresses = new HashSet<>(); | 72 | + monitoredAddresses = Collections.newSetFromMap( |
73 | + new ConcurrentHashMap<IpAddress, Boolean>()); | ||
77 | hostProviders = new ConcurrentHashMap<>(); | 74 | hostProviders = new ConcurrentHashMap<>(); |
78 | 75 | ||
79 | timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); | 76 | timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); |
80 | } | 77 | } |
81 | 78 | ||
79 | + /** | ||
80 | + * Adds an IP address to be monitored by the host monitor. The monitor will | ||
81 | + * periodically probe the host to detect changes. | ||
82 | + * | ||
83 | + * @param ip IP address of the host to monitor | ||
84 | + */ | ||
82 | void addMonitoringFor(IpAddress ip) { | 85 | void addMonitoringFor(IpAddress ip) { |
83 | monitoredAddresses.add(ip); | 86 | monitoredAddresses.add(ip); |
84 | } | 87 | } |
85 | 88 | ||
89 | + /** | ||
90 | + * Stops monitoring the given IP address. | ||
91 | + * | ||
92 | + * @param ip IP address to stop monitoring on | ||
93 | + */ | ||
86 | void stopMonitoring(IpAddress ip) { | 94 | void stopMonitoring(IpAddress ip) { |
87 | monitoredAddresses.remove(ip); | 95 | monitoredAddresses.remove(ip); |
88 | } | 96 | } |
89 | 97 | ||
98 | + /** | ||
99 | + * Starts the host monitor. Does nothing if the monitor is already running. | ||
100 | + */ | ||
101 | + void start() { | ||
102 | + synchronized (this) { | ||
103 | + if (timeout == null) { | ||
104 | + timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); | ||
105 | + } | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Stops the host monitor. | ||
111 | + */ | ||
90 | void shutdown() { | 112 | void shutdown() { |
113 | + synchronized (this) { | ||
91 | timeout.cancel(); | 114 | timeout.cancel(); |
115 | + timeout = null; | ||
116 | + } | ||
92 | } | 117 | } |
93 | 118 | ||
119 | + /** | ||
120 | + * Registers a host provider with the host monitor. The monitor can use the | ||
121 | + * provider to probe hosts. | ||
122 | + * | ||
123 | + * @param provider the host provider to register | ||
124 | + */ | ||
94 | void registerHostProvider(HostProvider provider) { | 125 | void registerHostProvider(HostProvider provider) { |
95 | hostProviders.put(provider.id(), provider); | 126 | hostProviders.put(provider.id(), provider); |
96 | } | 127 | } |
... | @@ -117,7 +148,7 @@ public class HostMonitor implements TimerTask { | ... | @@ -117,7 +148,7 @@ public class HostMonitor implements TimerTask { |
117 | } | 148 | } |
118 | } | 149 | } |
119 | 150 | ||
120 | - timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); | 151 | + this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); |
121 | } | 152 | } |
122 | 153 | ||
123 | /** | 154 | /** |
... | @@ -173,12 +204,12 @@ public class HostMonitor implements TimerTask { | ... | @@ -173,12 +204,12 @@ public class HostMonitor implements TimerTask { |
173 | 204 | ||
174 | arp.setSenderHardwareAddress(sourceMac.getAddress()) | 205 | arp.setSenderHardwareAddress(sourceMac.getAddress()) |
175 | .setSenderProtocolAddress(sourceIp.toOctets()) | 206 | .setSenderProtocolAddress(sourceIp.toOctets()) |
176 | - .setTargetHardwareAddress(ZERO_MAC_ADDRESS) | 207 | + .setTargetHardwareAddress(MacAddress.ZERO_MAC_ADDRESS) |
177 | .setTargetProtocolAddress(targetIp.toOctets()); | 208 | .setTargetProtocolAddress(targetIp.toOctets()); |
178 | 209 | ||
179 | Ethernet ethernet = new Ethernet(); | 210 | Ethernet ethernet = new Ethernet(); |
180 | ethernet.setEtherType(Ethernet.TYPE_ARP) | 211 | ethernet.setEtherType(Ethernet.TYPE_ARP) |
181 | - .setDestinationMACAddress(BROADCAST_MAC) | 212 | + .setDestinationMACAddress(MacAddress.BROADCAST_MAC) |
182 | .setSourceMACAddress(sourceMac.getAddress()) | 213 | .setSourceMACAddress(sourceMac.getAddress()) |
183 | .setPayload(arp); | 214 | .setPayload(arp); |
184 | 215 | ... | ... |
... | @@ -22,6 +22,12 @@ import java.util.Arrays; | ... | @@ -22,6 +22,12 @@ import java.util.Arrays; |
22 | * | 22 | * |
23 | */ | 23 | */ |
24 | public class MacAddress { | 24 | public class MacAddress { |
25 | + public static final byte[] ZERO_MAC_ADDRESS = | ||
26 | + MacAddress.valueOf("00:00:00:00:00:00").getAddress(); | ||
27 | + | ||
28 | + public static final byte[] BROADCAST_MAC = | ||
29 | + MacAddress.valueOf("ff:ff:ff:ff:ff:ff").getAddress(); | ||
30 | + | ||
25 | public static final int MAC_ADDRESS_LENGTH = 6; | 31 | public static final int MAC_ADDRESS_LENGTH = 6; |
26 | private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH]; | 32 | private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH]; |
27 | 33 | ... | ... |
-
Please register or login to post a comment