tom

Merge remote-tracking branch 'origin/master'

...@@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger;
8 */ 8 */
9 public final class ApplicationId { 9 public final class ApplicationId {
10 10
11 - private static AtomicInteger idDispenser; 11 + private static final AtomicInteger ID_DISPENCER = new AtomicInteger(1);
12 private final Integer id; 12 private final Integer id;
13 13
14 // Ban public construction 14 // Ban public construction
...@@ -50,10 +50,7 @@ public final class ApplicationId { ...@@ -50,10 +50,7 @@ public final class ApplicationId {
50 * @return app id 50 * @return app id
51 */ 51 */
52 public static ApplicationId getAppId() { 52 public static ApplicationId getAppId() {
53 - if (ApplicationId.idDispenser == null) { 53 + return new ApplicationId(ApplicationId.ID_DISPENCER.getAndIncrement());
54 - ApplicationId.idDispenser = new AtomicInteger(1);
55 - }
56 - return new ApplicationId(ApplicationId.idDispenser.getAndIncrement());
57 } 54 }
58 55
59 } 56 }
......
...@@ -26,6 +26,9 @@ public final class FlowId { ...@@ -26,6 +26,9 @@ public final class FlowId {
26 if (this == obj) { 26 if (this == obj) {
27 return true; 27 return true;
28 } 28 }
29 + if (obj == null) {
30 + return false;
31 + }
29 if (obj.getClass() == this.getClass()) { 32 if (obj.getClass() == this.getClass()) {
30 FlowId that = (FlowId) obj; 33 FlowId that = (FlowId) obj;
31 return Objects.equal(this.flowid, that.flowid); 34 return Objects.equal(this.flowid, that.flowid);
......
...@@ -39,7 +39,7 @@ public class DeviceEventTest extends AbstractEventTest { ...@@ -39,7 +39,7 @@ public class DeviceEventTest extends AbstractEventTest {
39 Device device = createDevice(); 39 Device device = createDevice();
40 Port port = new DefaultPort(device, PortNumber.portNumber(123), true); 40 Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
41 long before = System.currentTimeMillis(); 41 long before = System.currentTimeMillis();
42 - DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device); 42 + DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, port);
43 long after = System.currentTimeMillis(); 43 long after = System.currentTimeMillis();
44 validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, before, after); 44 validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, before, after);
45 } 45 }
......
...@@ -94,14 +94,14 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -94,14 +94,14 @@ public class ProxyArpManager implements ProxyArpService {
94 94
95 @Override 95 @Override
96 public boolean known(IpPrefix addr) { 96 public boolean known(IpPrefix addr) {
97 - checkNotNull(MAC_ADDR_NULL, addr); 97 + checkNotNull(addr, MAC_ADDR_NULL);
98 Set<Host> hosts = hostService.getHostsByIp(addr); 98 Set<Host> hosts = hostService.getHostsByIp(addr);
99 return !hosts.isEmpty(); 99 return !hosts.isEmpty();
100 } 100 }
101 101
102 @Override 102 @Override
103 public void reply(Ethernet eth) { 103 public void reply(Ethernet eth) {
104 - checkNotNull(REQUEST_NULL, eth); 104 + checkNotNull(eth, REQUEST_NULL);
105 checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP, 105 checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP,
106 REQUEST_NOT_ARP); 106 REQUEST_NOT_ARP);
107 ARP arp = (ARP) eth.getPayload(); 107 ARP arp = (ARP) eth.getPayload();
...@@ -137,7 +137,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -137,7 +137,7 @@ public class ProxyArpManager implements ProxyArpService {
137 137
138 @Override 138 @Override
139 public void forward(Ethernet eth) { 139 public void forward(Ethernet eth) {
140 - checkNotNull(REQUEST_NULL, eth); 140 + checkNotNull(eth, REQUEST_NULL);
141 checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP, 141 checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP,
142 REQUEST_NOT_ARP); 142 REQUEST_NOT_ARP);
143 ARP arp = (ARP) eth.getPayload(); 143 ARP arp = (ARP) eth.getPayload();
...@@ -206,12 +206,12 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -206,12 +206,12 @@ public class ProxyArpManager implements ProxyArpService {
206 for (Link l : links) { 206 for (Link l : links) {
207 // for each link, mark the concerned ports as internal 207 // for each link, mark the concerned ports as internal
208 // and the remaining ports are therefore external. 208 // and the remaining ports are therefore external.
209 - if (l.src().deviceId().equals(d) 209 + if (l.src().deviceId().equals(d.id())
210 && ports.contains(l.src().port())) { 210 && ports.contains(l.src().port())) {
211 ports.remove(l.src().port()); 211 ports.remove(l.src().port());
212 internalPorts.put(d, l.src().port()); 212 internalPorts.put(d, l.src().port());
213 } 213 }
214 - if (l.dst().deviceId().equals(d) 214 + if (l.dst().deviceId().equals(d.id())
215 && ports.contains(l.dst().port())) { 215 && ports.contains(l.dst().port())) {
216 ports.remove(l.dst().port()); 216 ports.remove(l.dst().port());
217 internalPorts.put(d, l.dst().port()); 217 internalPorts.put(d, l.dst().port());
......
...@@ -34,7 +34,8 @@ import com.google.common.collect.ImmutableMap; ...@@ -34,7 +34,8 @@ import com.google.common.collect.ImmutableMap;
34 import com.google.common.collect.ImmutableSet; 34 import com.google.common.collect.ImmutableSet;
35 import com.google.common.testing.EqualsTester; 35 import com.google.common.testing.EqualsTester;
36 36
37 -public class KryoSerializerTests { 37 +public class KryoSerializerTest {
38 +
38 private static final ProviderId PID = new ProviderId("of", "foo"); 39 private static final ProviderId PID = new ProviderId("of", "foo");
39 private static final ProviderId PIDA = new ProviderId("of", "foo", true); 40 private static final ProviderId PIDA = new ProviderId("of", "foo", true);
40 private static final DeviceId DID1 = deviceId("of:foo"); 41 private static final DeviceId DID1 = deviceId("of:foo");
...@@ -92,7 +93,7 @@ public class KryoSerializerTests { ...@@ -92,7 +93,7 @@ public class KryoSerializerTests {
92 93
93 94
94 @Test 95 @Test
95 - public final void test() { 96 + public final void testSerialization() {
96 testSerialized(new ConnectPoint(DID1, P1)); 97 testSerialized(new ConnectPoint(DID1, P1));
97 testSerialized(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT)); 98 testSerialized(new DefaultLink(PID, CP1, CP2, Link.Type.DIRECT));
98 testSerialized(new DefaultPort(DEV1, P1, true)); 99 testSerialized(new DefaultPort(DEV1, P1, true));
...@@ -119,6 +120,7 @@ public class KryoSerializerTests { ...@@ -119,6 +120,7 @@ public class KryoSerializerTests {
119 } 120 }
120 } 121 }
121 122
123 + @Test
122 public final void testAnnotations() { 124 public final void testAnnotations() {
123 // Annotations does not have equals defined, manually test equality 125 // Annotations does not have equals defined, manually test equality
124 final byte[] a1Bytes = kryos.serialize(A1); 126 final byte[] a1Bytes = kryos.serialize(A1);
...@@ -132,9 +134,9 @@ public class KryoSerializerTests { ...@@ -132,9 +134,9 @@ public class KryoSerializerTests {
132 134
133 // code clone 135 // code clone
134 public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { 136 public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
135 - DefaultAnnotations expected = DefaultAnnotations.builder().build(); 137 + SparseAnnotations expected = DefaultAnnotations.builder().build();
136 for (SparseAnnotations a : annotations) { 138 for (SparseAnnotations a : annotations) {
137 - expected = DefaultAnnotations.merge(expected, a); 139 + expected = DefaultAnnotations.union(expected, a);
138 } 140 }
139 assertEquals(expected.keys(), actual.keys()); 141 assertEquals(expected.keys(), actual.keys());
140 for (String key : expected.keys()) { 142 for (String key : expected.keys()) {
......
...@@ -8,7 +8,7 @@ import org.jboss.netty.util.HashedWheelTimer; ...@@ -8,7 +8,7 @@ import org.jboss.netty.util.HashedWheelTimer;
8 */ 8 */
9 public final class Timer { 9 public final class Timer {
10 10
11 - private static HashedWheelTimer timer; 11 + private static volatile HashedWheelTimer timer;
12 12
13 // Ban public construction 13 // Ban public construction
14 private Timer() { 14 private Timer() {
...@@ -21,10 +21,16 @@ public final class Timer { ...@@ -21,10 +21,16 @@ public final class Timer {
21 */ 21 */
22 public static HashedWheelTimer getTimer() { 22 public static HashedWheelTimer getTimer() {
23 if (Timer.timer == null) { 23 if (Timer.timer == null) {
24 + initTimer();
25 + }
26 + return Timer.timer;
27 + }
28 +
29 + private static synchronized void initTimer() {
30 + if (Timer.timer == null) {
24 Timer.timer = new HashedWheelTimer(); 31 Timer.timer = new HashedWheelTimer();
25 Timer.timer.start(); 32 Timer.timer.start();
26 } 33 }
27 - return Timer.timer;
28 } 34 }
29 35
30 } 36 }
......