Praseed Balakrishnan

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

...@@ -148,9 +148,9 @@ public class PeerConnectivityManager { ...@@ -148,9 +148,9 @@ public class PeerConnectivityManager {
148 .matchEthType(Ethernet.TYPE_IPV4) 148 .matchEthType(Ethernet.TYPE_IPV4)
149 .matchIPProtocol(IPv4.PROTOCOL_TCP) 149 .matchIPProtocol(IPv4.PROTOCOL_TCP)
150 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), 150 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(),
151 - IpAddress.MAX_INET_MASK)) 151 + IpPrefix.MAX_INET_MASK_LENGTH))
152 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 152 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
153 - IpAddress.MAX_INET_MASK)) 153 + IpPrefix.MAX_INET_MASK_LENGTH))
154 .matchTcpDst((short) BgpConstants.BGP_PORT) 154 .matchTcpDst((short) BgpConstants.BGP_PORT)
155 .build(); 155 .build();
156 156
...@@ -171,9 +171,9 @@ public class PeerConnectivityManager { ...@@ -171,9 +171,9 @@ public class PeerConnectivityManager {
171 .matchEthType(Ethernet.TYPE_IPV4) 171 .matchEthType(Ethernet.TYPE_IPV4)
172 .matchIPProtocol(IPv4.PROTOCOL_TCP) 172 .matchIPProtocol(IPv4.PROTOCOL_TCP)
173 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), 173 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(),
174 - IpAddress.MAX_INET_MASK)) 174 + IpPrefix.MAX_INET_MASK_LENGTH))
175 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 175 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
176 - IpAddress.MAX_INET_MASK)) 176 + IpPrefix.MAX_INET_MASK_LENGTH))
177 .matchTcpSrc((short) BgpConstants.BGP_PORT) 177 .matchTcpSrc((short) BgpConstants.BGP_PORT)
178 .build(); 178 .build();
179 179
...@@ -191,9 +191,9 @@ public class PeerConnectivityManager { ...@@ -191,9 +191,9 @@ public class PeerConnectivityManager {
191 .matchEthType(Ethernet.TYPE_IPV4) 191 .matchEthType(Ethernet.TYPE_IPV4)
192 .matchIPProtocol(IPv4.PROTOCOL_TCP) 192 .matchIPProtocol(IPv4.PROTOCOL_TCP)
193 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 193 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
194 - IpAddress.MAX_INET_MASK)) 194 + IpPrefix.MAX_INET_MASK_LENGTH))
195 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), 195 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(),
196 - IpAddress.MAX_INET_MASK)) 196 + IpPrefix.MAX_INET_MASK_LENGTH))
197 .matchTcpDst((short) BgpConstants.BGP_PORT) 197 .matchTcpDst((short) BgpConstants.BGP_PORT)
198 .build(); 198 .build();
199 199
...@@ -211,9 +211,9 @@ public class PeerConnectivityManager { ...@@ -211,9 +211,9 @@ public class PeerConnectivityManager {
211 .matchEthType(Ethernet.TYPE_IPV4) 211 .matchEthType(Ethernet.TYPE_IPV4)
212 .matchIPProtocol(IPv4.PROTOCOL_TCP) 212 .matchIPProtocol(IPv4.PROTOCOL_TCP)
213 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 213 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
214 - IpAddress.MAX_INET_MASK)) 214 + IpPrefix.MAX_INET_MASK_LENGTH))
215 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), 215 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(),
216 - IpAddress.MAX_INET_MASK)) 216 + IpPrefix.MAX_INET_MASK_LENGTH))
217 .matchTcpSrc((short) BgpConstants.BGP_PORT) 217 .matchTcpSrc((short) BgpConstants.BGP_PORT)
218 .build(); 218 .build();
219 219
...@@ -281,9 +281,9 @@ public class PeerConnectivityManager { ...@@ -281,9 +281,9 @@ public class PeerConnectivityManager {
281 .matchEthType(Ethernet.TYPE_IPV4) 281 .matchEthType(Ethernet.TYPE_IPV4)
282 .matchIPProtocol(IPv4.PROTOCOL_ICMP) 282 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
283 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(), 283 .matchIPSrc(IpPrefix.valueOf(bgpdAddress.toInt(),
284 - IpAddress.MAX_INET_MASK)) 284 + IpPrefix.MAX_INET_MASK_LENGTH))
285 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 285 .matchIPDst(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
286 - IpAddress.MAX_INET_MASK)) 286 + IpPrefix.MAX_INET_MASK_LENGTH))
287 .build(); 287 .build();
288 288
289 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 289 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
...@@ -301,9 +301,9 @@ public class PeerConnectivityManager { ...@@ -301,9 +301,9 @@ public class PeerConnectivityManager {
301 .matchEthType(Ethernet.TYPE_IPV4) 301 .matchEthType(Ethernet.TYPE_IPV4)
302 .matchIPProtocol(IPv4.PROTOCOL_ICMP) 302 .matchIPProtocol(IPv4.PROTOCOL_ICMP)
303 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(), 303 .matchIPSrc(IpPrefix.valueOf(bgpdPeerAddress.toInt(),
304 - IpAddress.MAX_INET_MASK)) 304 + IpPrefix.MAX_INET_MASK_LENGTH))
305 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(), 305 .matchIPDst(IpPrefix.valueOf(bgpdAddress.toInt(),
306 - IpAddress.MAX_INET_MASK)) 306 + IpPrefix.MAX_INET_MASK_LENGTH))
307 .build(); 307 .build();
308 308
309 PointToPointIntent reversedIntent = 309 PointToPointIntent reversedIntent =
......
...@@ -75,7 +75,7 @@ public class RouteEntry { ...@@ -75,7 +75,7 @@ public class RouteEntry {
75 StringBuilder result = new StringBuilder(ip4Prefix.prefixLength()); 75 StringBuilder result = new StringBuilder(ip4Prefix.prefixLength());
76 long value = ip4Prefix.toInt(); 76 long value = ip4Prefix.toInt();
77 for (int i = 0; i < ip4Prefix.prefixLength(); i++) { 77 for (int i = 0; i < ip4Prefix.prefixLength(); i++) {
78 - long mask = 1 << (IpAddress.MAX_INET_MASK - 1 - i); 78 + long mask = 1 << (IpPrefix.MAX_INET_MASK_LENGTH - 1 - i);
79 result.append(((value & mask) == 0) ? "0" : "1"); 79 result.append(((value & mask) == 0) ? "0" : "1");
80 } 80 }
81 return result.toString(); 81 return result.toString();
......
...@@ -190,12 +190,12 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler { ...@@ -190,12 +190,12 @@ class TestBgpPeerChannelHandler extends SimpleChannelHandler {
190 190
191 IpAddress address = prefix.toIpAddress(); 191 IpAddress address = prefix.toIpAddress();
192 long value = address.toInt() & 0xffffffffL; 192 long value = address.toInt() & 0xffffffffL;
193 - for (int i = 0; i < IpAddress.INET_LEN; i++) { 193 + for (int i = 0; i < IpAddress.INET_BYTE_LENGTH; i++) {
194 if (prefixBytelen-- == 0) { 194 if (prefixBytelen-- == 0) {
195 break; 195 break;
196 } 196 }
197 long nextByte = 197 long nextByte =
198 - (value >> ((IpAddress.INET_LEN - i - 1) * 8)) & 0xff; 198 + (value >> ((IpAddress.INET_BYTE_LENGTH - i - 1) * 8)) & 0xff;
199 message.writeByte((int) nextByte); 199 message.writeByte((int) nextByte);
200 } 200 }
201 } 201 }
......
...@@ -269,10 +269,6 @@ implements MastershipService, MastershipAdminService { ...@@ -269,10 +269,6 @@ implements MastershipService, MastershipAdminService {
269 269
270 @Override 270 @Override
271 public void notify(MastershipEvent event) { 271 public void notify(MastershipEvent event) {
272 - if (clusterService.getLocalNode().id().equals(event.roleInfo().master())) {
273 - log.info("ignoring locally-generated event {}", event);
274 - // return;
275 - }
276 log.info("dispatching mastership event {}", event); 272 log.info("dispatching mastership event {}", event);
277 eventDispatcher.post(event); 273 eventDispatcher.post(event);
278 } 274 }
......
...@@ -432,7 +432,6 @@ public class DeviceManager ...@@ -432,7 +432,6 @@ public class DeviceManager
432 if (!isReachable(device)) { 432 if (!isReachable(device)) {
433 log.warn("Device {} has disconnected after this event", did); 433 log.warn("Device {} has disconnected after this event", did);
434 mastershipService.relinquishMastership(did); 434 mastershipService.relinquishMastership(did);
435 - applyRole(did, MastershipRole.STANDBY);
436 return; 435 return;
437 } 436 }
438 //flag the device as online. Is there a better way to do this? 437 //flag the device as online. Is there a better way to do this?
...@@ -448,6 +447,7 @@ public class DeviceManager ...@@ -448,6 +447,7 @@ public class DeviceManager
448 if (!isReachable(getDevice(did))) { 447 if (!isReachable(getDevice(did))) {
449 log.warn("Device {} has disconnected after this event", did); 448 log.warn("Device {} has disconnected after this event", did);
450 mastershipService.relinquishMastership(did); 449 mastershipService.relinquishMastership(did);
450 + return;
451 } 451 }
452 applyRole(did, MastershipRole.STANDBY); 452 applyRole(did, MastershipRole.STANDBY);
453 } 453 }
...@@ -455,19 +455,21 @@ public class DeviceManager ...@@ -455,19 +455,21 @@ public class DeviceManager
455 455
456 // checks for duplicate event, returning true if one is found. 456 // checks for duplicate event, returning true if one is found.
457 private boolean checkDuplicate(RoleInfo roleInfo, int term) { 457 private boolean checkDuplicate(RoleInfo roleInfo, int term) {
458 - synchronized (eventCache) { 458 + // turning off duplicate check
459 - if (eventCache.get(term).contains(roleInfo)) { 459 + return false;
460 - log.info("duplicate event detected; ignoring"); 460 +// synchronized (eventCache) {
461 - return true; 461 +// if (eventCache.get(term).contains(roleInfo)) {
462 - } else { 462 +// log.info("duplicate event detected; ignoring");
463 - eventCache.put(term, roleInfo); 463 +// return true;
464 - // purge by-term oldest entries to keep the cache size under limit 464 +// } else {
465 - if (eventCache.size() > cacheSize) { 465 +// eventCache.put(term, roleInfo);
466 - eventCache.removeAll(term - cacheSize); 466 +// // purge by-term oldest entries to keep the cache size under limit
467 - } 467 +// if (eventCache.size() > cacheSize) {
468 - return false; 468 +// eventCache.removeAll(term - cacheSize);
469 - } 469 +// }
470 - } 470 +// return false;
471 +// }
472 +// }
471 } 473 }
472 474
473 } 475 }
......
...@@ -46,7 +46,6 @@ import org.onlab.onos.net.provider.ProviderId; ...@@ -46,7 +46,6 @@ import org.onlab.onos.net.provider.ProviderId;
46 import org.onlab.packet.ARP; 46 import org.onlab.packet.ARP;
47 import org.onlab.packet.Ethernet; 47 import org.onlab.packet.Ethernet;
48 import org.onlab.packet.IpAddress; 48 import org.onlab.packet.IpAddress;
49 -import org.onlab.packet.IpPrefix;
50 import org.onlab.packet.MacAddress; 49 import org.onlab.packet.MacAddress;
51 import org.onlab.util.Timer; 50 import org.onlab.util.Timer;
52 51
...@@ -212,7 +211,7 @@ public class HostMonitor implements TimerTask { ...@@ -212,7 +211,7 @@ public class HostMonitor implements TimerTask {
212 arp.setHardwareType(ARP.HW_TYPE_ETHERNET) 211 arp.setHardwareType(ARP.HW_TYPE_ETHERNET)
213 .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) 212 .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
214 .setProtocolType(ARP.PROTO_TYPE_IP) 213 .setProtocolType(ARP.PROTO_TYPE_IP)
215 - .setProtocolAddressLength((byte) IpPrefix.INET_LEN) 214 + .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH)
216 .setOpCode(ARP.OP_REQUEST); 215 .setOpCode(ARP.OP_REQUEST);
217 216
218 arp.setSenderHardwareAddress(sourceMac.getAddress()) 217 arp.setSenderHardwareAddress(sourceMac.getAddress())
......
...@@ -56,7 +56,6 @@ import org.onlab.onos.net.proxyarp.ProxyArpService; ...@@ -56,7 +56,6 @@ import org.onlab.onos.net.proxyarp.ProxyArpService;
56 import org.onlab.packet.ARP; 56 import org.onlab.packet.ARP;
57 import org.onlab.packet.Ethernet; 57 import org.onlab.packet.Ethernet;
58 import org.onlab.packet.IpAddress; 58 import org.onlab.packet.IpAddress;
59 -import org.onlab.packet.IpPrefix;
60 import org.onlab.packet.MacAddress; 59 import org.onlab.packet.MacAddress;
61 import org.onlab.packet.VlanId; 60 import org.onlab.packet.VlanId;
62 import org.slf4j.Logger; 61 import org.slf4j.Logger;
...@@ -368,7 +367,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -368,7 +367,7 @@ public class ProxyArpManager implements ProxyArpService {
368 arp.setProtocolType(ARP.PROTO_TYPE_IP); 367 arp.setProtocolType(ARP.PROTO_TYPE_IP);
369 arp.setHardwareType(ARP.HW_TYPE_ETHERNET); 368 arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
370 369
371 - arp.setProtocolAddressLength((byte) IpPrefix.INET_LEN); 370 + arp.setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH);
372 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); 371 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
373 arp.setSenderHardwareAddress(srcMac.getAddress()); 372 arp.setSenderHardwareAddress(srcMac.getAddress());
374 arp.setTargetHardwareAddress(request.getSourceMACAddress()); 373 arp.setTargetHardwareAddress(request.getSourceMACAddress());
......
...@@ -534,7 +534,7 @@ public class ProxyArpManagerTest { ...@@ -534,7 +534,7 @@ public class ProxyArpManagerTest {
534 arp.setProtocolType(ARP.PROTO_TYPE_IP); 534 arp.setProtocolType(ARP.PROTO_TYPE_IP);
535 arp.setHardwareType(ARP.HW_TYPE_ETHERNET); 535 arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
536 536
537 - arp.setProtocolAddressLength((byte) IpPrefix.INET_LEN); 537 + arp.setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH);
538 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); 538 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
539 arp.setSenderHardwareAddress(srcMac.getAddress()); 539 arp.setSenderHardwareAddress(srcMac.getAddress());
540 540
......
...@@ -358,6 +358,7 @@ implements MastershipStore { ...@@ -358,6 +358,7 @@ implements MastershipStore {
358 358
359 @Override 359 @Override
360 public void entryAdded(EntryEvent<DeviceId, RoleValue> event) { 360 public void entryAdded(EntryEvent<DeviceId, RoleValue> event) {
361 + entryUpdated(event);
361 } 362 }
362 363
363 @Override 364 @Override
...@@ -366,7 +367,6 @@ implements MastershipStore { ...@@ -366,7 +367,6 @@ implements MastershipStore {
366 367
367 @Override 368 @Override
368 public void entryUpdated(EntryEvent<DeviceId, RoleValue> event) { 369 public void entryUpdated(EntryEvent<DeviceId, RoleValue> event) {
369 - // this subsumes entryAdded event
370 notifyDelegate(new MastershipEvent( 370 notifyDelegate(new MastershipEvent(
371 MASTER_CHANGED, event.getKey(), event.getValue().roleInfo())); 371 MASTER_CHANGED, event.getKey(), event.getValue().roleInfo()));
372 } 372 }
......
...@@ -17,6 +17,7 @@ package org.onlab.onos.store.topology.impl; ...@@ -17,6 +17,7 @@ package org.onlab.onos.store.topology.impl;
17 17
18 import static org.slf4j.LoggerFactory.getLogger; 18 import static org.slf4j.LoggerFactory.getLogger;
19 19
20 +import java.util.Collections;
20 import java.util.List; 21 import java.util.List;
21 import java.util.Set; 22 import java.util.Set;
22 23
...@@ -26,11 +27,13 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -26,11 +27,13 @@ import org.apache.felix.scr.annotations.Deactivate;
26 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
27 import org.onlab.onos.event.Event; 28 import org.onlab.onos.event.Event;
28 import org.onlab.onos.net.ConnectPoint; 29 import org.onlab.onos.net.ConnectPoint;
30 +import org.onlab.onos.net.Device;
29 import org.onlab.onos.net.DeviceId; 31 import org.onlab.onos.net.DeviceId;
30 import org.onlab.onos.net.Link; 32 import org.onlab.onos.net.Link;
31 import org.onlab.onos.net.Path; 33 import org.onlab.onos.net.Path;
32 import org.onlab.onos.net.provider.ProviderId; 34 import org.onlab.onos.net.provider.ProviderId;
33 import org.onlab.onos.net.topology.ClusterId; 35 import org.onlab.onos.net.topology.ClusterId;
36 +import org.onlab.onos.net.topology.DefaultGraphDescription;
34 import org.onlab.onos.net.topology.GraphDescription; 37 import org.onlab.onos.net.topology.GraphDescription;
35 import org.onlab.onos.net.topology.LinkWeight; 38 import org.onlab.onos.net.topology.LinkWeight;
36 import org.onlab.onos.net.topology.Topology; 39 import org.onlab.onos.net.topology.Topology;
...@@ -55,7 +58,11 @@ implements TopologyStore { ...@@ -55,7 +58,11 @@ implements TopologyStore {
55 58
56 private final Logger log = getLogger(getClass()); 59 private final Logger log = getLogger(getClass());
57 60
58 - private volatile DefaultTopology current; 61 + private volatile DefaultTopology current =
62 + new DefaultTopology(ProviderId.NONE,
63 + new DefaultGraphDescription(0L,
64 + Collections.<Device>emptyList(),
65 + Collections.<Link>emptyList()));
59 66
60 @Activate 67 @Activate
61 public void activate() { 68 public void activate() {
......
...@@ -145,7 +145,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -145,7 +145,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
145 break; 145 break;
146 case PORT_ADDED: 146 case PORT_ADDED:
147 case PORT_UPDATED: 147 case PORT_UPDATED:
148 - if (event.port().isEnabled()) { 148 + if (port.isEnabled()) {
149 ld = discoverers.get(device.id()); 149 ld = discoverers.get(device.id());
150 if (ld == null) { 150 if (ld == null) {
151 return; 151 return;
...@@ -155,6 +155,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -155,6 +155,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
155 ld.addPort(port); 155 ld.addPort(port);
156 } 156 }
157 } else { 157 } else {
158 + log.debug("Port down {}", port);
158 ConnectPoint point = new ConnectPoint(device.id(), 159 ConnectPoint point = new ConnectPoint(device.id(),
159 port.number()); 160 port.number());
160 providerService.linksVanished(point); 161 providerService.linksVanished(point);
......
...@@ -68,6 +68,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -68,6 +68,7 @@ public class LinkDiscovery implements TimerTask {
68 // send 1 probe every probeRate milliseconds 68 // send 1 probe every probeRate milliseconds
69 private final long probeRate; 69 private final long probeRate;
70 private final Set<Long> slowPorts; 70 private final Set<Long> slowPorts;
71 + // ports, known to have incoming links
71 private final Set<Long> fastPorts; 72 private final Set<Long> fastPorts;
72 // number of unacknowledged probes per port 73 // number of unacknowledged probes per port
73 private final Map<Long, AtomicInteger> portProbeCount; 74 private final Map<Long, AtomicInteger> portProbeCount;
...@@ -125,6 +126,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -125,6 +126,7 @@ public class LinkDiscovery implements TimerTask {
125 log.info("Using BDDP to discover network"); 126 log.info("Using BDDP to discover network");
126 } 127 }
127 128
129 + this.isStopped = true;
128 start(); 130 start();
129 this.log.debug("Started discovery manager for switch {}", 131 this.log.debug("Started discovery manager for switch {}",
130 device.id()); 132 device.id());
...@@ -140,7 +142,10 @@ public class LinkDiscovery implements TimerTask { ...@@ -140,7 +142,10 @@ public class LinkDiscovery implements TimerTask {
140 public void addPort(final Port port) { 142 public void addPort(final Port port) {
141 this.log.debug("Sending init probe to port {}@{}", 143 this.log.debug("Sending init probe to port {}@{}",
142 port.number().toLong(), device.id()); 144 port.number().toLong(), device.id());
143 - sendProbes(port.number().toLong()); 145 + boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
146 + if (isMaster) {
147 + sendProbes(port.number().toLong());
148 + }
144 synchronized (this) { 149 synchronized (this) {
145 this.slowPorts.add(port.number().toLong()); 150 this.slowPorts.add(port.number().toLong());
146 } 151 }
...@@ -233,6 +238,13 @@ public class LinkDiscovery implements TimerTask { ...@@ -233,6 +238,13 @@ public class LinkDiscovery implements TimerTask {
233 */ 238 */
234 @Override 239 @Override
235 public void run(final Timeout t) { 240 public void run(final Timeout t) {
241 + boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER;
242 + if (!isMaster) {
243 + // reschedule timer
244 + timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS);
245 + return;
246 + }
247 +
236 this.log.trace("Sending probes from {}", device.id()); 248 this.log.trace("Sending probes from {}", device.id());
237 synchronized (this) { 249 synchronized (this) {
238 final Iterator<Long> fastIterator = this.fastPorts.iterator(); 250 final Iterator<Long> fastIterator = this.fastPorts.iterator();
...@@ -245,6 +257,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -245,6 +257,7 @@ public class LinkDiscovery implements TimerTask {
245 sendProbes(portNumber); 257 sendProbes(portNumber);
246 258
247 } else { 259 } else {
260 + // Link down, demote to slowPorts
248 // Update fast and slow ports 261 // Update fast and slow ports
249 fastIterator.remove(); 262 fastIterator.remove();
250 this.slowPorts.add(portNumber); 263 this.slowPorts.add(portNumber);
...@@ -274,8 +287,12 @@ public class LinkDiscovery implements TimerTask { ...@@ -274,8 +287,12 @@ public class LinkDiscovery implements TimerTask {
274 } 287 }
275 288
276 public void start() { 289 public void start() {
277 - timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); 290 + if (isStopped) {
278 - isStopped = false; 291 + timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
292 + isStopped = false;
293 + } else {
294 + log.warn("LinkDiscovery started multiple times?");
295 + }
279 } 296 }
280 297
281 /** 298 /**
...@@ -317,8 +334,8 @@ public class LinkDiscovery implements TimerTask { ...@@ -317,8 +334,8 @@ public class LinkDiscovery implements TimerTask {
317 } 334 }
318 335
319 private void sendProbes(Long portNumber) { 336 private void sendProbes(Long portNumber) {
320 - boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; 337 + // TODO: should have suppression port configuration, not by type
321 - if (isMaster && device.type() != Device.Type.ROADM) { 338 + if (device.type() != Device.Type.ROADM) {
322 log.debug("Sending probes out to {}@{}", portNumber, device.id()); 339 log.debug("Sending probes out to {}@{}", portNumber, device.id());
323 OutboundPacket pkt = this.createOutBoundLLDP(portNumber); 340 OutboundPacket pkt = this.createOutBoundLLDP(portNumber);
324 pktService.emit(pkt); 341 pktService.emit(pkt);
......
...@@ -171,7 +171,8 @@ public class FlowEntryBuilder { ...@@ -171,7 +171,8 @@ public class FlowEntryBuilder {
171 builder.setIpDst(IpPrefix.valueOf(di.getInt(), 171 builder.setIpDst(IpPrefix.valueOf(di.getInt(),
172 di.asCidrMaskLength())); 172 di.asCidrMaskLength()));
173 } else { 173 } else {
174 - builder.setIpDst(IpPrefix.valueOf(di.getInt())); 174 + builder.setIpDst(IpPrefix.valueOf(di.getInt(),
175 + IpPrefix.MAX_INET_MASK_LENGTH));
175 } 176 }
176 break; 177 break;
177 case SET_NW_SRC: 178 case SET_NW_SRC:
...@@ -181,7 +182,8 @@ public class FlowEntryBuilder { ...@@ -181,7 +182,8 @@ public class FlowEntryBuilder {
181 builder.setIpSrc(IpPrefix.valueOf(si.getInt(), 182 builder.setIpSrc(IpPrefix.valueOf(si.getInt(),
182 si.asCidrMaskLength())); 183 si.asCidrMaskLength()));
183 } else { 184 } else {
184 - builder.setIpSrc(IpPrefix.valueOf(si.getInt())); 185 + builder.setIpSrc(IpPrefix.valueOf(si.getInt(),
186 + IpPrefix.MAX_INET_MASK_LENGTH));
185 } 187 }
186 break; 188 break;
187 case EXPERIMENTER: 189 case EXPERIMENTER:
...@@ -256,7 +258,7 @@ public class FlowEntryBuilder { ...@@ -256,7 +258,7 @@ public class FlowEntryBuilder {
256 } else { 258 } else {
257 dip = IpPrefix.valueOf( 259 dip = IpPrefix.valueOf(
258 match.get(MatchField.IPV4_DST).getInt(), 260 match.get(MatchField.IPV4_DST).getInt(),
259 - IpPrefix.MAX_INET_MASK); 261 + IpPrefix.MAX_INET_MASK_LENGTH);
260 } 262 }
261 263
262 builder.matchIPDst(dip); 264 builder.matchIPDst(dip);
...@@ -272,7 +274,7 @@ public class FlowEntryBuilder { ...@@ -272,7 +274,7 @@ public class FlowEntryBuilder {
272 } else { 274 } else {
273 sip = IpPrefix.valueOf( 275 sip = IpPrefix.valueOf(
274 match.get(MatchField.IPV4_SRC).getInt(), 276 match.get(MatchField.IPV4_SRC).getInt(),
275 - IpPrefix.MAX_INET_MASK); 277 + IpPrefix.MAX_INET_MASK_LENGTH);
276 } 278 }
277 279
278 builder.matchIPSrc(sip); 280 builder.matchIPSrc(sip);
......
...@@ -8,7 +8,7 @@ export ONOS_ROOT=${ONOS_ROOT:-~/onos-next} ...@@ -8,7 +8,7 @@ export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
8 # Setup some environmental context for developers 8 # Setup some environmental context for developers
9 if [ -z "${JAVA_HOME}" ]; then 9 if [ -z "${JAVA_HOME}" ]; then
10 if [ -x /usr/libexec/java_home ]; then 10 if [ -x /usr/libexec/java_home ]; then
11 - export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) 11 + export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
12 elif [ -d /usr/lib/jvm/java-7-openjdk-amd64 ]; then 12 elif [ -d /usr/lib/jvm/java-7-openjdk-amd64 ]; then
13 export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64" 13 export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
14 fi 14 fi
......
...@@ -101,20 +101,6 @@ public final class Ip4Prefix { ...@@ -101,20 +101,6 @@ public final class Ip4Prefix {
101 return this.address.toString() + "/" + this.prefixLen; 101 return this.address.toString() + "/" + this.prefixLen;
102 } 102 }
103 103
104 - /**
105 - * Compares the value of two Ip4Prefix objects.
106 - * <p/>
107 - * Note the value of the IPv4 address is compared directly between the
108 - * objects, and must match exactly for the objects to be considered equal.
109 - * This may result in objects which represent the same IP prefix being
110 - * classified as unequal, because the unsignificant bits of the address
111 - * field don't match (the bits to the right of the prefix length).
112 - * <p/>
113 - * TODO Change this behavior so that objects that represent the same prefix
114 - * are classified as equal according to this equals method.
115 - *
116 - * @see Object#equals(Object)
117 - */
118 @Override 104 @Override
119 public boolean equals(Object other) { 105 public boolean equals(Object other) {
120 if (other == this) { 106 if (other == this) {
......
...@@ -101,20 +101,6 @@ public final class Ip6Prefix { ...@@ -101,20 +101,6 @@ public final class Ip6Prefix {
101 return this.address.toString() + "/" + this.prefixLen; 101 return this.address.toString() + "/" + this.prefixLen;
102 } 102 }
103 103
104 - /**
105 - * Compares the value of two Ip6Prefix objects.
106 - * <p/>
107 - * Note the value of the IPv6 address is compared directly between the
108 - * objects, and must match exactly for the objects to be considered equal.
109 - * This may result in objects which represent the same IP prefix being
110 - * classified as unequal, because the unsignificant bits of the address
111 - * field don't match (the bits to the right of the prefix length).
112 - * <p/>
113 - * TODO Change this behavior so that objects that represent the same prefix
114 - * are classified as equal according to this equals method.
115 - *
116 - * @see Object#equals(Object)
117 - */
118 @Override 104 @Override
119 public boolean equals(Object other) { 105 public boolean equals(Object other) {
120 if (other == this) { 106 if (other == this) {
......
...@@ -26,48 +26,37 @@ public final class IpPrefix { ...@@ -26,48 +26,37 @@ public final class IpPrefix {
26 26
27 // TODO a comparator for netmasks? E.g. for sorting by prefix match order. 27 // TODO a comparator for netmasks? E.g. for sorting by prefix match order.
28 28
29 - //IP Versions 29 + // IP Versions: IPv4 and IPv6
30 public enum Version { INET, INET6 }; 30 public enum Version { INET, INET6 };
31 31
32 - //lengths of address, in bytes 32 + // Maximum network mask length
33 - public static final int INET_LEN = 4; 33 + public static final int MAX_INET_MASK_LENGTH = IpAddress.INET_BIT_LENGTH;
34 - public static final int INET6_LEN = 16; 34 + public static final int MAX_INET6_MASK_LENGTH = IpAddress.INET6_BIT_LENGTH;
35 35
36 - //maximum CIDR value
37 - public static final int MAX_INET_MASK = 32;
38 //no mask (no network), e.g. a simple address 36 //no mask (no network), e.g. a simple address
39 - public static final int DEFAULT_MASK = 0; 37 + private static final int DEFAULT_MASK = 0;
40 38
41 /** 39 /**
42 * Default value indicating an unspecified address. 40 * Default value indicating an unspecified address.
43 */ 41 */
44 - static final byte[] ANY = new byte [] {0, 0, 0, 0}; 42 + private static final byte[] ANY = new byte[] {0, 0, 0, 0};
45 43
46 - protected Version version; 44 + private final Version version;
47 - 45 + private final byte[] octets;
48 - protected byte[] octets; 46 + private final int netmask;
49 - protected int netmask;
50 -
51 - private IpPrefix(Version ver, byte[] octets, int netmask) {
52 - this.version = ver;
53 - this.octets = Arrays.copyOf(octets, INET_LEN);
54 - this.netmask = netmask;
55 - }
56 -
57 - private IpPrefix(Version ver, byte[] octets) {
58 - this.version = ver;
59 - this.octets = Arrays.copyOf(octets, INET_LEN);
60 - this.netmask = DEFAULT_MASK;
61 - }
62 47
63 /** 48 /**
64 - * Converts a byte array into an IP address. 49 + * Constructor for given IP address version, prefix address octets,
50 + * and network mask length.
65 * 51 *
66 - * @param address a byte array 52 + * @param ver the IP address version
67 - * @return an IP address 53 + * @param octets the IP prefix address octets
54 + * @param netmask the network mask length
68 */ 55 */
69 - public static IpPrefix valueOf(byte [] address) { 56 + private IpPrefix(Version ver, byte[] octets, int netmask) {
70 - return new IpPrefix(Version.INET, address); 57 + this.version = ver;
58 + this.octets = Arrays.copyOf(octets, IpAddress.INET_BYTE_LENGTH);
59 + this.netmask = netmask;
71 } 60 }
72 61
73 /** 62 /**
...@@ -77,7 +66,7 @@ public final class IpPrefix { ...@@ -77,7 +66,7 @@ public final class IpPrefix {
77 * @param netmask the CIDR value subnet mask 66 * @param netmask the CIDR value subnet mask
78 * @return an IP address 67 * @return an IP address
79 */ 68 */
80 - public static IpPrefix valueOf(byte [] address, int netmask) { 69 + public static IpPrefix valueOf(byte[] address, int netmask) {
81 return new IpPrefix(Version.INET, address, netmask); 70 return new IpPrefix(Version.INET, address, netmask);
82 } 71 }
83 72
...@@ -87,10 +76,11 @@ public final class IpPrefix { ...@@ -87,10 +76,11 @@ public final class IpPrefix {
87 * @param address the integer to convert 76 * @param address the integer to convert
88 * @return a byte array 77 * @return a byte array
89 */ 78 */
90 - private static byte [] bytes(int address) { 79 + private static byte[] bytes(int address) {
91 - byte [] bytes = new byte [INET_LEN]; 80 + byte[] bytes = new byte [IpAddress.INET_BYTE_LENGTH];
92 - for (int i = 0; i < INET_LEN; i++) { 81 + for (int i = 0; i < IpAddress.INET_BYTE_LENGTH; i++) {
93 - bytes[i] = (byte) ((address >> (INET_LEN - (i + 1)) * 8) & 0xff); 82 + bytes[i] = (byte) ((address >> (IpAddress.INET_BYTE_LENGTH
83 + - (i + 1)) * 8) & 0xff);
94 } 84 }
95 85
96 return bytes; 86 return bytes;
...@@ -100,16 +90,6 @@ public final class IpPrefix { ...@@ -100,16 +90,6 @@ public final class IpPrefix {
100 * Converts an integer into an IPv4 address. 90 * Converts an integer into an IPv4 address.
101 * 91 *
102 * @param address an integer representing an IP value 92 * @param address an integer representing an IP value
103 - * @return an IP address
104 - */
105 - public static IpPrefix valueOf(int address) {
106 - return new IpPrefix(Version.INET, bytes(address));
107 - }
108 -
109 - /**
110 - * Converts an integer into an IPv4 address.
111 - *
112 - * @param address an integer representing an IP value
113 * @param netmask the CIDR value subnet mask 93 * @param netmask the CIDR value subnet mask
114 * @return an IP address 94 * @return an IP address
115 */ 95 */
...@@ -127,7 +107,7 @@ public final class IpPrefix { ...@@ -127,7 +107,7 @@ public final class IpPrefix {
127 */ 107 */
128 public static IpPrefix valueOf(String address) { 108 public static IpPrefix valueOf(String address) {
129 109
130 - final String [] parts = address.split("\\/"); 110 + final String[] parts = address.split("\\/");
131 if (parts.length > 2) { 111 if (parts.length > 2) {
132 throw new IllegalArgumentException("Malformed IP address string; " 112 throw new IllegalArgumentException("Malformed IP address string; "
133 + "Address must take form \"x.x.x.x\" or \"x.x.x.x/y\""); 113 + "Address must take form \"x.x.x.x\" or \"x.x.x.x/y\"");
...@@ -136,20 +116,20 @@ public final class IpPrefix { ...@@ -136,20 +116,20 @@ public final class IpPrefix {
136 int mask = DEFAULT_MASK; 116 int mask = DEFAULT_MASK;
137 if (parts.length == 2) { 117 if (parts.length == 2) {
138 mask = Integer.parseInt(parts[1]); 118 mask = Integer.parseInt(parts[1]);
139 - if (mask > MAX_INET_MASK) { 119 + if (mask > MAX_INET_MASK_LENGTH) {
140 throw new IllegalArgumentException( 120 throw new IllegalArgumentException(
141 "Value of subnet mask cannot exceed " 121 "Value of subnet mask cannot exceed "
142 - + MAX_INET_MASK); 122 + + MAX_INET_MASK_LENGTH);
143 } 123 }
144 } 124 }
145 125
146 - final String [] net = parts[0].split("\\."); 126 + final String[] net = parts[0].split("\\.");
147 - if (net.length != INET_LEN) { 127 + if (net.length != IpAddress.INET_BYTE_LENGTH) {
148 throw new IllegalArgumentException("Malformed IP address string; " 128 throw new IllegalArgumentException("Malformed IP address string; "
149 + "Address must have four decimal values separated by dots (.)"); 129 + "Address must have four decimal values separated by dots (.)");
150 } 130 }
151 - final byte [] bytes = new byte[INET_LEN]; 131 + final byte[] bytes = new byte[IpAddress.INET_BYTE_LENGTH];
152 - for (int i = 0; i < INET_LEN; i++) { 132 + for (int i = 0; i < IpAddress.INET_BYTE_LENGTH; i++) {
153 bytes[i] = (byte) Short.parseShort(net[i], 10); 133 bytes[i] = (byte) Short.parseShort(net[i], 10);
154 } 134 }
155 return new IpPrefix(Version.INET, bytes, mask); 135 return new IpPrefix(Version.INET, bytes, mask);
...@@ -170,7 +150,7 @@ public final class IpPrefix { ...@@ -170,7 +150,7 @@ public final class IpPrefix {
170 * @return a byte array 150 * @return a byte array
171 */ 151 */
172 public byte[] toOctets() { 152 public byte[] toOctets() {
173 - return Arrays.copyOf(this.octets, INET_LEN); 153 + return Arrays.copyOf(this.octets, IpAddress.INET_BYTE_LENGTH);
174 } 154 }
175 155
176 /** 156 /**
...@@ -202,18 +182,17 @@ public final class IpPrefix { ...@@ -202,18 +182,17 @@ public final class IpPrefix {
202 * @return an integer bitmask 182 * @return an integer bitmask
203 */ 183 */
204 private int mask() { 184 private int mask() {
205 - int shift = MAX_INET_MASK - this.netmask; 185 + int shift = MAX_INET_MASK_LENGTH - this.netmask;
206 return ((Integer.MAX_VALUE >>> (shift - 1)) << shift); 186 return ((Integer.MAX_VALUE >>> (shift - 1)) << shift);
207 } 187 }
208 188
209 /** 189 /**
210 - * Returns the subnet mask in IpAddress form. The netmask value for 190 + * Returns the subnet mask in IpAddress form.
211 - * the returned IpAddress is 0, as the address itself is a mask.
212 * 191 *
213 - * @return the subnet mask 192 + * @return the subnet mask as an IpAddress
214 */ 193 */
215 - public IpPrefix netmask() { 194 + public IpAddress netmask() {
216 - return new IpPrefix(Version.INET, bytes(mask())); 195 + return IpAddress.valueOf(mask());
217 } 196 }
218 197
219 /** 198 /**
...@@ -228,9 +207,9 @@ public final class IpPrefix { ...@@ -228,9 +207,9 @@ public final class IpPrefix {
228 return new IpPrefix(version, ANY, DEFAULT_MASK); 207 return new IpPrefix(version, ANY, DEFAULT_MASK);
229 } 208 }
230 209
231 - byte [] net = new byte [4]; 210 + byte[] net = new byte [4];
232 - byte [] mask = bytes(mask()); 211 + byte[] mask = bytes(mask());
233 - for (int i = 0; i < INET_LEN; i++) { 212 + for (int i = 0; i < IpAddress.INET_BYTE_LENGTH; i++) {
234 net[i] = (byte) (octets[i] & mask[i]); 213 net[i] = (byte) (octets[i] & mask[i]);
235 } 214 }
236 return new IpPrefix(version, net, netmask); 215 return new IpPrefix(version, net, netmask);
...@@ -249,9 +228,9 @@ public final class IpPrefix { ...@@ -249,9 +228,9 @@ public final class IpPrefix {
249 new IpPrefix(version, octets, netmask); 228 new IpPrefix(version, octets, netmask);
250 } 229 }
251 230
252 - byte [] host = new byte [INET_LEN]; 231 + byte[] host = new byte [IpAddress.INET_BYTE_LENGTH];
253 - byte [] mask = bytes(mask()); 232 + byte[] mask = bytes(mask());
254 - for (int i = 0; i < INET_LEN; i++) { 233 + for (int i = 0; i < IpAddress.INET_BYTE_LENGTH; i++) {
255 host[i] = (byte) (octets[i] & ~mask[i]); 234 host[i] = (byte) (octets[i] & ~mask[i]);
256 } 235 }
257 return new IpPrefix(version, host, netmask); 236 return new IpPrefix(version, host, netmask);
...@@ -283,7 +262,7 @@ public final class IpPrefix { ...@@ -283,7 +262,7 @@ public final class IpPrefix {
283 public boolean contains(IpPrefix other) { 262 public boolean contains(IpPrefix other) {
284 if (this.netmask <= other.netmask) { 263 if (this.netmask <= other.netmask) {
285 // Special case where they're both /32 addresses 264 // Special case where they're both /32 addresses
286 - if (this.netmask == MAX_INET_MASK) { 265 + if (this.netmask == MAX_INET_MASK_LENGTH) {
287 return Arrays.equals(octets, other.octets); 266 return Arrays.equals(octets, other.octets);
288 } 267 }
289 268
...@@ -302,7 +281,7 @@ public final class IpPrefix { ...@@ -302,7 +281,7 @@ public final class IpPrefix {
302 IpPrefix meMasked = network(); 281 IpPrefix meMasked = network();
303 282
304 IpPrefix otherMasked = 283 IpPrefix otherMasked =
305 - IpPrefix.valueOf(address.octets, netmask).network(); 284 + IpPrefix.valueOf(address.toOctets(), netmask).network();
306 285
307 return Arrays.equals(meMasked.octets, otherMasked.octets); 286 return Arrays.equals(meMasked.octets, otherMasked.octets);
308 } 287 }
...@@ -364,5 +343,4 @@ public final class IpPrefix { ...@@ -364,5 +343,4 @@ public final class IpPrefix {
364 } 343 }
365 return builder.toString(); 344 return builder.toString();
366 } 345 }
367 -
368 } 346 }
......
...@@ -32,15 +32,15 @@ public class IpPrefixTest { ...@@ -32,15 +32,15 @@ public class IpPrefixTest {
32 private static final byte [] BYTES2 = new byte [] {0xa, 0x0, 0x0, 0xb}; 32 private static final byte [] BYTES2 = new byte [] {0xa, 0x0, 0x0, 0xb};
33 private static final int INTVAL1 = 167772170; 33 private static final int INTVAL1 = 167772170;
34 private static final int INTVAL2 = 167772171; 34 private static final int INTVAL2 = 167772171;
35 - private static final String STRVAL = "10.0.0.12"; 35 + private static final String STRVAL = "10.0.0.12/16";
36 - private static final int MASK = 16; 36 + private static final int MASK_LENGTH = 16;
37 37
38 @Test 38 @Test
39 public void testEquality() { 39 public void testEquality() {
40 - IpPrefix ip1 = IpPrefix.valueOf(BYTES1); 40 + IpPrefix ip1 = IpPrefix.valueOf(BYTES1, IpPrefix.MAX_INET_MASK_LENGTH);
41 - IpPrefix ip2 = IpPrefix.valueOf(INTVAL1); 41 + IpPrefix ip2 = IpPrefix.valueOf(INTVAL1, IpPrefix.MAX_INET_MASK_LENGTH);
42 - IpPrefix ip3 = IpPrefix.valueOf(BYTES2); 42 + IpPrefix ip3 = IpPrefix.valueOf(BYTES2, IpPrefix.MAX_INET_MASK_LENGTH);
43 - IpPrefix ip4 = IpPrefix.valueOf(INTVAL2); 43 + IpPrefix ip4 = IpPrefix.valueOf(INTVAL2, IpPrefix.MAX_INET_MASK_LENGTH);
44 IpPrefix ip5 = IpPrefix.valueOf(STRVAL); 44 IpPrefix ip5 = IpPrefix.valueOf(STRVAL);
45 45
46 new EqualsTester().addEqualityGroup(ip1, ip2) 46 new EqualsTester().addEqualityGroup(ip1, ip2)
...@@ -49,21 +49,21 @@ public class IpPrefixTest { ...@@ -49,21 +49,21 @@ public class IpPrefixTest {
49 .testEquals(); 49 .testEquals();
50 50
51 // string conversions 51 // string conversions
52 - IpPrefix ip6 = IpPrefix.valueOf(BYTES1, MASK); 52 + IpPrefix ip6 = IpPrefix.valueOf(BYTES1, MASK_LENGTH);
53 IpPrefix ip7 = IpPrefix.valueOf("10.0.0.10/16"); 53 IpPrefix ip7 = IpPrefix.valueOf("10.0.0.10/16");
54 - IpPrefix ip8 = IpPrefix.valueOf(new byte [] {0xa, 0x0, 0x0, 0xc}); 54 + IpPrefix ip8 = IpPrefix.valueOf(new byte [] {0xa, 0x0, 0x0, 0xc}, 16);
55 assertEquals("incorrect address conversion", ip6, ip7); 55 assertEquals("incorrect address conversion", ip6, ip7);
56 assertEquals("incorrect address conversion", ip5, ip8); 56 assertEquals("incorrect address conversion", ip5, ip8);
57 } 57 }
58 58
59 @Test 59 @Test
60 public void basics() { 60 public void basics() {
61 - IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK); 61 + IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK_LENGTH);
62 final byte [] bytes = new byte [] {0xa, 0x0, 0x0, 0xa}; 62 final byte [] bytes = new byte [] {0xa, 0x0, 0x0, 0xa};
63 63
64 //check fields 64 //check fields
65 assertEquals("incorrect IP Version", Version.INET, ip1.version()); 65 assertEquals("incorrect IP Version", Version.INET, ip1.version());
66 - assertEquals("incorrect netmask", 16, ip1.netmask); 66 + assertEquals("incorrect netmask", 16, ip1.prefixLength());
67 assertTrue("faulty toOctets()", Arrays.equals(bytes, ip1.toOctets())); 67 assertTrue("faulty toOctets()", Arrays.equals(bytes, ip1.toOctets()));
68 assertEquals("faulty toInt()", INTVAL1, ip1.toInt()); 68 assertEquals("faulty toInt()", INTVAL1, ip1.toInt());
69 assertEquals("faulty toString()", "10.0.0.10/16", ip1.toString()); 69 assertEquals("faulty toString()", "10.0.0.10/16", ip1.toString());
...@@ -72,7 +72,7 @@ public class IpPrefixTest { ...@@ -72,7 +72,7 @@ public class IpPrefixTest {
72 @Test 72 @Test
73 public void netmasks() { 73 public void netmasks() {
74 // masked 74 // masked
75 - IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK); 75 + IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK_LENGTH);
76 76
77 IpPrefix host = IpPrefix.valueOf("0.0.0.10/16"); 77 IpPrefix host = IpPrefix.valueOf("0.0.0.10/16");
78 IpPrefix network = IpPrefix.valueOf("10.0.0.0/16"); 78 IpPrefix network = IpPrefix.valueOf("10.0.0.0/16");
...@@ -80,14 +80,6 @@ public class IpPrefixTest { ...@@ -80,14 +80,6 @@ public class IpPrefixTest {
80 assertEquals("incorrect network address", network, ip1.network()); 80 assertEquals("incorrect network address", network, ip1.network());
81 assertEquals("incorrect netmask", "255.255.0.0", ip1.netmask().toString()); 81 assertEquals("incorrect netmask", "255.255.0.0", ip1.netmask().toString());
82 82
83 - //unmasked
84 - IpPrefix ip2 = IpPrefix.valueOf(BYTES1);
85 - IpPrefix umhost = IpPrefix.valueOf("10.0.0.10/0");
86 - IpPrefix umnet = IpPrefix.valueOf("0.0.0.0/0");
87 - assertEquals("incorrect host address", umhost, ip2.host());
88 - assertEquals("incorrect host address", umnet, ip2.network());
89 - assertTrue("incorrect netmask",
90 - Arrays.equals(IpPrefix.ANY, ip2.netmask().toOctets()));
91 } 83 }
92 84
93 @Test 85 @Test
......
...@@ -20,6 +20,7 @@ import java.net.UnknownHostException; ...@@ -20,6 +20,7 @@ import java.net.UnknownHostException;
20 import java.util.concurrent.ConcurrentHashMap; 20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentMap; 21 import java.util.concurrent.ConcurrentMap;
22 import java.util.concurrent.TimeUnit; 22 import java.util.concurrent.TimeUnit;
23 +import java.util.concurrent.TimeoutException;
23 import java.util.concurrent.atomic.AtomicLong; 24 import java.util.concurrent.atomic.AtomicLong;
24 25
25 import io.netty.bootstrap.Bootstrap; 26 import io.netty.bootstrap.Bootstrap;
...@@ -27,6 +28,7 @@ import io.netty.bootstrap.ServerBootstrap; ...@@ -27,6 +28,7 @@ import io.netty.bootstrap.ServerBootstrap;
27 import io.netty.buffer.PooledByteBufAllocator; 28 import io.netty.buffer.PooledByteBufAllocator;
28 import io.netty.channel.Channel; 29 import io.netty.channel.Channel;
29 import io.netty.channel.ChannelFuture; 30 import io.netty.channel.ChannelFuture;
31 +import io.netty.channel.ChannelFutureListener;
30 import io.netty.channel.ChannelHandler; 32 import io.netty.channel.ChannelHandler;
31 import io.netty.channel.ChannelHandlerContext; 33 import io.netty.channel.ChannelHandlerContext;
32 import io.netty.channel.ChannelInitializer; 34 import io.netty.channel.ChannelInitializer;
...@@ -49,6 +51,8 @@ import org.slf4j.LoggerFactory; ...@@ -49,6 +51,8 @@ import org.slf4j.LoggerFactory;
49 51
50 import com.google.common.cache.Cache; 52 import com.google.common.cache.Cache;
51 import com.google.common.cache.CacheBuilder; 53 import com.google.common.cache.CacheBuilder;
54 +import com.google.common.cache.RemovalListener;
55 +import com.google.common.cache.RemovalNotification;
52 import com.google.common.util.concurrent.ListenableFuture; 56 import com.google.common.util.concurrent.ListenableFuture;
53 import com.google.common.util.concurrent.SettableFuture; 57 import com.google.common.util.concurrent.SettableFuture;
54 58
...@@ -64,8 +68,13 @@ public class NettyMessagingService implements MessagingService { ...@@ -64,8 +68,13 @@ public class NettyMessagingService implements MessagingService {
64 private final AtomicLong messageIdGenerator = new AtomicLong(0); 68 private final AtomicLong messageIdGenerator = new AtomicLong(0);
65 private final Cache<Long, SettableFuture<byte[]>> responseFutures = CacheBuilder.newBuilder() 69 private final Cache<Long, SettableFuture<byte[]>> responseFutures = CacheBuilder.newBuilder()
66 .maximumSize(100000) 70 .maximumSize(100000)
67 - // TODO: Once the entry expires, notify blocking threads (if any). 71 + .expireAfterWrite(10, TimeUnit.SECONDS)
68 - .expireAfterWrite(10, TimeUnit.MINUTES) 72 + .removalListener(new RemovalListener<Long, SettableFuture<byte[]>>() {
73 + @Override
74 + public void onRemoval(RemovalNotification<Long, SettableFuture<byte[]>> entry) {
75 + entry.getValue().setException(new TimeoutException("Timedout waiting for reply"));
76 + }
77 + })
69 .build(); 78 .build();
70 private final GenericKeyedObjectPool<Endpoint, Channel> channels 79 private final GenericKeyedObjectPool<Endpoint, Channel> channels
71 = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory()); 80 = new GenericKeyedObjectPool<Endpoint, Channel>(new OnosCommunicationChannelFactory());
...@@ -153,9 +162,12 @@ public class NettyMessagingService implements MessagingService { ...@@ -153,9 +162,12 @@ public class NettyMessagingService implements MessagingService {
153 } finally { 162 } finally {
154 channels.returnObject(ep, channel); 163 channels.returnObject(ep, channel);
155 } 164 }
165 + } catch (IOException e) {
166 + throw e;
156 } catch (Exception e) { 167 } catch (Exception e) {
157 - throw new IOException("Failed to send message to " + ep.toString(), e); 168 + throw new IOException(e);
158 } 169 }
170 +
159 } 171 }
160 172
161 @Override 173 @Override
...@@ -172,7 +184,7 @@ public class NettyMessagingService implements MessagingService { ...@@ -172,7 +184,7 @@ public class NettyMessagingService implements MessagingService {
172 .build(); 184 .build();
173 try { 185 try {
174 sendAsync(ep, message); 186 sendAsync(ep, message);
175 - } catch (IOException e) { 187 + } catch (Exception e) {
176 responseFutures.invalidate(messageId); 188 responseFutures.invalidate(messageId);
177 throw e; 189 throw e;
178 } 190 }
...@@ -277,7 +289,7 @@ public class NettyMessagingService implements MessagingService { ...@@ -277,7 +289,7 @@ public class NettyMessagingService implements MessagingService {
277 289
278 @Override 290 @Override
279 public void run() { 291 public void run() {
280 - channel.writeAndFlush(message, channel.voidPromise()); 292 + channel.writeAndFlush(message).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
281 } 293 }
282 } 294 }
283 295
......