Speeding up stuff.
HostDescription now passes up just a single IpAddress.
Showing
13 changed files
with
242 additions
and
185 deletions
... | @@ -22,8 +22,10 @@ public class SummaryCommand extends AbstractShellCommand { | ... | @@ -22,8 +22,10 @@ public class SummaryCommand extends AbstractShellCommand { |
22 | protected void execute() { | 22 | protected void execute() { |
23 | TopologyService topologyService = get(TopologyService.class); | 23 | TopologyService topologyService = get(TopologyService.class); |
24 | Topology topology = topologyService.currentTopology(); | 24 | Topology topology = topologyService.currentTopology(); |
25 | - print("version=%s, nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d", | 25 | + print("node=%s, version=%s", |
26 | - get(CoreService.class).version().toString(), | 26 | + get(ClusterService.class).getLocalNode().ip(), |
27 | + get(CoreService.class).version().toString()); | ||
28 | + print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d", | ||
27 | get(ClusterService.class).getNodes().size(), | 29 | get(ClusterService.class).getNodes().size(), |
28 | get(DeviceService.class).getDeviceCount(), | 30 | get(DeviceService.class).getDeviceCount(), |
29 | get(LinkService.class).getLinkCount(), | 31 | get(LinkService.class).getLinkCount(), | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | -import com.google.common.collect.ImmutableSet; | ||
4 | import org.onlab.onos.net.AbstractDescription; | 3 | import org.onlab.onos.net.AbstractDescription; |
5 | import org.onlab.onos.net.HostLocation; | 4 | import org.onlab.onos.net.HostLocation; |
6 | import org.onlab.onos.net.SparseAnnotations; | 5 | import org.onlab.onos.net.SparseAnnotations; |
... | @@ -8,9 +7,6 @@ import org.onlab.packet.IpPrefix; | ... | @@ -8,9 +7,6 @@ import org.onlab.packet.IpPrefix; |
8 | import org.onlab.packet.MacAddress; | 7 | import org.onlab.packet.MacAddress; |
9 | import org.onlab.packet.VlanId; | 8 | import org.onlab.packet.VlanId; |
10 | 9 | ||
11 | -import java.util.HashSet; | ||
12 | -import java.util.Set; | ||
13 | - | ||
14 | import static com.google.common.base.MoreObjects.toStringHelper; | 10 | import static com.google.common.base.MoreObjects.toStringHelper; |
15 | 11 | ||
16 | /** | 12 | /** |
... | @@ -22,7 +18,7 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -22,7 +18,7 @@ public class DefaultHostDescription extends AbstractDescription |
22 | private final MacAddress mac; | 18 | private final MacAddress mac; |
23 | private final VlanId vlan; | 19 | private final VlanId vlan; |
24 | private final HostLocation location; | 20 | private final HostLocation location; |
25 | - private final Set<IpPrefix> ips; | 21 | + private final IpPrefix ip; |
26 | 22 | ||
27 | /** | 23 | /** |
28 | * Creates a host description using the supplied information. | 24 | * Creates a host description using the supplied information. |
... | @@ -35,7 +31,7 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -35,7 +31,7 @@ public class DefaultHostDescription extends AbstractDescription |
35 | public DefaultHostDescription(MacAddress mac, VlanId vlan, | 31 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
36 | HostLocation location, | 32 | HostLocation location, |
37 | SparseAnnotations... annotations) { | 33 | SparseAnnotations... annotations) { |
38 | - this(mac, vlan, location, new HashSet<IpPrefix>(), annotations); | 34 | + this(mac, vlan, location, null, annotations); |
39 | } | 35 | } |
40 | 36 | ||
41 | /** | 37 | /** |
... | @@ -44,17 +40,17 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -44,17 +40,17 @@ public class DefaultHostDescription extends AbstractDescription |
44 | * @param mac host MAC address | 40 | * @param mac host MAC address |
45 | * @param vlan host VLAN identifier | 41 | * @param vlan host VLAN identifier |
46 | * @param location host location | 42 | * @param location host location |
47 | - * @param ips of host IP addresses | 43 | + * @param ip host IP address |
48 | * @param annotations optional key/value annotations map | 44 | * @param annotations optional key/value annotations map |
49 | */ | 45 | */ |
50 | public DefaultHostDescription(MacAddress mac, VlanId vlan, | 46 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
51 | - HostLocation location, Set<IpPrefix> ips, | 47 | + HostLocation location, IpPrefix ip, |
52 | SparseAnnotations... annotations) { | 48 | SparseAnnotations... annotations) { |
53 | super(annotations); | 49 | super(annotations); |
54 | this.mac = mac; | 50 | this.mac = mac; |
55 | this.vlan = vlan; | 51 | this.vlan = vlan; |
56 | this.location = location; | 52 | this.location = location; |
57 | - this.ips = new HashSet<>(ips); | 53 | + this.ip = ip; |
58 | } | 54 | } |
59 | 55 | ||
60 | @Override | 56 | @Override |
... | @@ -73,8 +69,8 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -73,8 +69,8 @@ public class DefaultHostDescription extends AbstractDescription |
73 | } | 69 | } |
74 | 70 | ||
75 | @Override | 71 | @Override |
76 | - public Set<IpPrefix> ipAddresses() { | 72 | + public IpPrefix ipAddress() { |
77 | - return ImmutableSet.copyOf(ips); | 73 | + return ip; |
78 | } | 74 | } |
79 | 75 | ||
80 | @Override | 76 | @Override |
... | @@ -83,7 +79,7 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -83,7 +79,7 @@ public class DefaultHostDescription extends AbstractDescription |
83 | .add("mac", mac) | 79 | .add("mac", mac) |
84 | .add("vlan", vlan) | 80 | .add("vlan", vlan) |
85 | .add("location", location) | 81 | .add("location", location) |
86 | - .add("ipAddresses", ips) | 82 | + .add("ipAddress", ip) |
87 | .toString(); | 83 | .toString(); |
88 | } | 84 | } |
89 | 85 | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | -import java.util.Set; | ||
4 | - | ||
5 | import org.onlab.onos.net.Description; | 3 | import org.onlab.onos.net.Description; |
6 | import org.onlab.onos.net.HostLocation; | 4 | import org.onlab.onos.net.HostLocation; |
7 | import org.onlab.packet.IpPrefix; | 5 | import org.onlab.packet.IpPrefix; |
... | @@ -35,10 +33,10 @@ public interface HostDescription extends Description { | ... | @@ -35,10 +33,10 @@ public interface HostDescription extends Description { |
35 | HostLocation location(); | 33 | HostLocation location(); |
36 | 34 | ||
37 | /** | 35 | /** |
38 | - * Returns zero or more IP address(es) associated with this host's MAC. | 36 | + * Returns the IP address associated with this host's MAC. |
39 | * | 37 | * |
40 | - * @return a set of IP addresses. | 38 | + * @return host IP address |
41 | */ | 39 | */ |
42 | - Set<IpPrefix> ipAddresses(); | 40 | + IpPrefix ipAddress(); |
43 | 41 | ||
44 | } | 42 | } | ... | ... |
... | @@ -45,15 +45,18 @@ public class AbstractEventAccumulatorTest { | ... | @@ -45,15 +45,18 @@ public class AbstractEventAccumulatorTest { |
45 | public void timeTrigger() { | 45 | public void timeTrigger() { |
46 | TestAccumulator accumulator = new TestAccumulator(); | 46 | TestAccumulator accumulator = new TestAccumulator(); |
47 | accumulator.add(new TestEvent(FOO, "a")); | 47 | accumulator.add(new TestEvent(FOO, "a")); |
48 | - delay(40); | 48 | + delay(30); |
49 | assertTrue("should not have fired yet", accumulator.batch.isEmpty()); | 49 | assertTrue("should not have fired yet", accumulator.batch.isEmpty()); |
50 | accumulator.add(new TestEvent(FOO, "b")); | 50 | accumulator.add(new TestEvent(FOO, "b")); |
51 | - delay(40); | 51 | + delay(30); |
52 | assertTrue("should not have fired yet", accumulator.batch.isEmpty()); | 52 | assertTrue("should not have fired yet", accumulator.batch.isEmpty()); |
53 | accumulator.add(new TestEvent(FOO, "c")); | 53 | accumulator.add(new TestEvent(FOO, "c")); |
54 | - delay(40); | 54 | + delay(30); |
55 | + assertTrue("should not have fired yet", accumulator.batch.isEmpty()); | ||
56 | + accumulator.add(new TestEvent(FOO, "d")); | ||
57 | + delay(30); | ||
55 | assertFalse("should have fired", accumulator.batch.isEmpty()); | 58 | assertFalse("should have fired", accumulator.batch.isEmpty()); |
56 | - assertEquals("incorrect batch", "abc", accumulator.batch); | 59 | + assertEquals("incorrect batch", "abcd", accumulator.batch); |
57 | } | 60 | } |
58 | 61 | ||
59 | @Test | 62 | @Test | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | -import static org.junit.Assert.assertEquals; | ||
4 | -import static org.junit.Assert.assertTrue; | ||
5 | - | ||
6 | -import java.util.Set; | ||
7 | - | ||
8 | import org.junit.Test; | 3 | import org.junit.Test; |
9 | import org.onlab.onos.net.DeviceId; | 4 | import org.onlab.onos.net.DeviceId; |
10 | import org.onlab.onos.net.HostLocation; | 5 | import org.onlab.onos.net.HostLocation; |
... | @@ -13,7 +8,8 @@ import org.onlab.packet.IpPrefix; | ... | @@ -13,7 +8,8 @@ import org.onlab.packet.IpPrefix; |
13 | import org.onlab.packet.MacAddress; | 8 | import org.onlab.packet.MacAddress; |
14 | import org.onlab.packet.VlanId; | 9 | import org.onlab.packet.VlanId; |
15 | 10 | ||
16 | -import com.google.common.collect.Sets; | 11 | +import static org.junit.Assert.assertEquals; |
12 | +import static org.junit.Assert.assertTrue; | ||
17 | 13 | ||
18 | /** | 14 | /** |
19 | * Test for the default host description. | 15 | * Test for the default host description. |
... | @@ -22,24 +18,22 @@ public class DefualtHostDecriptionTest { | ... | @@ -22,24 +18,22 @@ public class DefualtHostDecriptionTest { |
22 | 18 | ||
23 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); | 19 | private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); |
24 | private static final VlanId VLAN = VlanId.vlanId((short) 10); | 20 | private static final VlanId VLAN = VlanId.vlanId((short) 10); |
21 | + private static final IpPrefix IP = IpPrefix.valueOf("10.0.0.1"); | ||
22 | + | ||
25 | private static final HostLocation LOC = new HostLocation( | 23 | private static final HostLocation LOC = new HostLocation( |
26 | DeviceId.deviceId("of:foo"), | 24 | DeviceId.deviceId("of:foo"), |
27 | PortNumber.portNumber(100), | 25 | PortNumber.portNumber(100), |
28 | 123L | 26 | 123L |
29 | ); | 27 | ); |
30 | - private static final Set<IpPrefix> IPS = Sets.newHashSet( | ||
31 | - IpPrefix.valueOf("10.0.0.1"), | ||
32 | - IpPrefix.valueOf("10.0.0.2") | ||
33 | - ); | ||
34 | 28 | ||
35 | @Test | 29 | @Test |
36 | public void basics() { | 30 | public void basics() { |
37 | HostDescription host = | 31 | HostDescription host = |
38 | - new DefaultHostDescription(MAC, VLAN, LOC, IPS); | 32 | + new DefaultHostDescription(MAC, VLAN, LOC, IP); |
39 | assertEquals("incorrect mac", MAC, host.hwAddress()); | 33 | assertEquals("incorrect mac", MAC, host.hwAddress()); |
40 | assertEquals("incorrect vlan", VLAN, host.vlan()); | 34 | assertEquals("incorrect vlan", VLAN, host.vlan()); |
41 | assertEquals("incorrect location", LOC, host.location()); | 35 | assertEquals("incorrect location", LOC, host.location()); |
42 | - assertTrue("incorrect ip's", IPS.equals(host.ipAddresses())); | 36 | + assertEquals("incorrect ip's", IP, host.ipAddress()); |
43 | assertTrue("incorrect toString", host.toString().contains("vlan=10")); | 37 | assertTrue("incorrect toString", host.toString().contains("vlan=10")); |
44 | } | 38 | } |
45 | 39 | ... | ... |
... | @@ -168,7 +168,6 @@ public class HostManager | ... | @@ -168,7 +168,6 @@ public class HostManager |
168 | checkNotNull(hostId, HOST_ID_NULL); | 168 | checkNotNull(hostId, HOST_ID_NULL); |
169 | HostEvent event = store.removeHost(hostId); | 169 | HostEvent event = store.removeHost(hostId); |
170 | if (event != null) { | 170 | if (event != null) { |
171 | - log.info("Host {} administratively removed", hostId); | ||
172 | post(event); | 171 | post(event); |
173 | } | 172 | } |
174 | } | 173 | } |
... | @@ -214,7 +213,6 @@ public class HostManager | ... | @@ -214,7 +213,6 @@ public class HostManager |
214 | HostEvent event = store.createOrUpdateHost(provider().id(), hostId, | 213 | HostEvent event = store.createOrUpdateHost(provider().id(), hostId, |
215 | hostDescription); | 214 | hostDescription); |
216 | if (event != null) { | 215 | if (event != null) { |
217 | - log.debug("Host {} detected", hostId); | ||
218 | post(event); | 216 | post(event); |
219 | } | 217 | } |
220 | } | 218 | } |
... | @@ -225,7 +223,6 @@ public class HostManager | ... | @@ -225,7 +223,6 @@ public class HostManager |
225 | checkValidity(); | 223 | checkValidity(); |
226 | HostEvent event = store.removeHost(hostId); | 224 | HostEvent event = store.removeHost(hostId); |
227 | if (event != null) { | 225 | if (event != null) { |
228 | - log.debug("Host {} vanished", hostId); | ||
229 | post(event); | 226 | post(event); |
230 | } | 227 | } |
231 | } | 228 | } | ... | ... |
... | @@ -58,8 +58,6 @@ public class HostManagerTest { | ... | @@ -58,8 +58,6 @@ public class HostManagerTest { |
58 | 58 | ||
59 | private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1"); | 59 | private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1"); |
60 | private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2"); | 60 | private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2"); |
61 | - private static final Set<IpPrefix> IPSET1 = Sets.newHashSet(IP1); | ||
62 | - private static final Set<IpPrefix> IPSET2 = Sets.newHashSet(IP2); | ||
63 | 61 | ||
64 | private static final DeviceId DID1 = DeviceId.deviceId("of:001"); | 62 | private static final DeviceId DID1 = DeviceId.deviceId("of:001"); |
65 | private static final DeviceId DID2 = DeviceId.deviceId("of:002"); | 63 | private static final DeviceId DID2 = DeviceId.deviceId("of:002"); |
... | @@ -109,8 +107,8 @@ public class HostManagerTest { | ... | @@ -109,8 +107,8 @@ public class HostManagerTest { |
109 | } | 107 | } |
110 | 108 | ||
111 | private void detect(HostId hid, MacAddress mac, VlanId vlan, | 109 | private void detect(HostId hid, MacAddress mac, VlanId vlan, |
112 | - HostLocation loc, Set<IpPrefix> ips) { | 110 | + HostLocation loc, IpPrefix ip) { |
113 | - HostDescription descr = new DefaultHostDescription(mac, vlan, loc, ips); | 111 | + HostDescription descr = new DefaultHostDescription(mac, vlan, loc, ip); |
114 | providerService.hostDetected(hid, descr); | 112 | providerService.hostDetected(hid, descr); |
115 | assertNotNull("host should be found", mgr.getHost(hid)); | 113 | assertNotNull("host should be found", mgr.getHost(hid)); |
116 | } | 114 | } |
... | @@ -130,26 +128,26 @@ public class HostManagerTest { | ... | @@ -130,26 +128,26 @@ public class HostManagerTest { |
130 | assertNull("host shouldn't be found", mgr.getHost(HID1)); | 128 | assertNull("host shouldn't be found", mgr.getHost(HID1)); |
131 | 129 | ||
132 | // host addition | 130 | // host addition |
133 | - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); | 131 | + detect(HID1, MAC1, VLAN1, LOC1, IP1); |
134 | assertEquals("exactly one should be found", 1, mgr.getHostCount()); | 132 | assertEquals("exactly one should be found", 1, mgr.getHostCount()); |
135 | - detect(HID2, MAC2, VLAN2, LOC2, IPSET1); | 133 | + detect(HID2, MAC2, VLAN2, LOC2, IP1); |
136 | assertEquals("two hosts should be found", 2, mgr.getHostCount()); | 134 | assertEquals("two hosts should be found", 2, mgr.getHostCount()); |
137 | validateEvents(HOST_ADDED, HOST_ADDED); | 135 | validateEvents(HOST_ADDED, HOST_ADDED); |
138 | 136 | ||
139 | // host motion | 137 | // host motion |
140 | - detect(HID1, MAC1, VLAN1, LOC2, IPSET1); | 138 | + detect(HID1, MAC1, VLAN1, LOC2, IP1); |
141 | validateEvents(HOST_MOVED); | 139 | validateEvents(HOST_MOVED); |
142 | assertEquals("only two hosts should be found", 2, mgr.getHostCount()); | 140 | assertEquals("only two hosts should be found", 2, mgr.getHostCount()); |
143 | 141 | ||
144 | // host update | 142 | // host update |
145 | - detect(HID1, MAC1, VLAN1, LOC2, IPSET2); | 143 | + detect(HID1, MAC1, VLAN1, LOC2, IP2); |
146 | validateEvents(HOST_UPDATED); | 144 | validateEvents(HOST_UPDATED); |
147 | assertEquals("only two hosts should be found", 2, mgr.getHostCount()); | 145 | assertEquals("only two hosts should be found", 2, mgr.getHostCount()); |
148 | } | 146 | } |
149 | 147 | ||
150 | @Test | 148 | @Test |
151 | public void hostVanished() { | 149 | public void hostVanished() { |
152 | - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); | 150 | + detect(HID1, MAC1, VLAN1, LOC1, IP1); |
153 | providerService.hostVanished(HID1); | 151 | providerService.hostVanished(HID1); |
154 | validateEvents(HOST_ADDED, HOST_REMOVED); | 152 | validateEvents(HOST_ADDED, HOST_REMOVED); |
155 | 153 | ||
... | @@ -157,7 +155,7 @@ public class HostManagerTest { | ... | @@ -157,7 +155,7 @@ public class HostManagerTest { |
157 | } | 155 | } |
158 | 156 | ||
159 | private void validateHosts( | 157 | private void validateHosts( |
160 | - String msg, Iterable<Host> hosts, HostId ... ids) { | 158 | + String msg, Iterable<Host> hosts, HostId... ids) { |
161 | Set<HostId> hids = Sets.newHashSet(ids); | 159 | Set<HostId> hids = Sets.newHashSet(ids); |
162 | for (Host h : hosts) { | 160 | for (Host h : hosts) { |
163 | assertTrue(msg, hids.remove(h.id())); | 161 | assertTrue(msg, hids.remove(h.id())); |
... | @@ -167,8 +165,8 @@ public class HostManagerTest { | ... | @@ -167,8 +165,8 @@ public class HostManagerTest { |
167 | 165 | ||
168 | @Test | 166 | @Test |
169 | public void getHosts() { | 167 | public void getHosts() { |
170 | - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); | 168 | + detect(HID1, MAC1, VLAN1, LOC1, IP1); |
171 | - detect(HID2, MAC2, VLAN1, LOC2, IPSET2); | 169 | + detect(HID2, MAC2, VLAN1, LOC2, IP2); |
172 | 170 | ||
173 | validateHosts("host not properly stored", mgr.getHosts(), HID1, HID2); | 171 | validateHosts("host not properly stored", mgr.getHosts(), HID1, HID2); |
174 | validateHosts("can't get hosts by VLAN", mgr.getHostsByVlan(VLAN1), HID1, HID2); | 172 | validateHosts("can't get hosts by VLAN", mgr.getHostsByVlan(VLAN1), HID1, HID2); | ... | ... |
1 | package org.onlab.onos.store.host.impl; | 1 | package org.onlab.onos.store.host.impl; |
2 | 2 | ||
3 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; | 3 | +import com.google.common.collect.HashMultimap; |
4 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; | 4 | +import com.google.common.collect.ImmutableSet; |
5 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; | 5 | +import com.google.common.collect.Multimap; |
6 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; | 6 | +import com.google.common.collect.Sets; |
7 | -import static org.slf4j.LoggerFactory.getLogger; | ||
8 | - | ||
9 | -import java.util.Collections; | ||
10 | -import java.util.HashSet; | ||
11 | -import java.util.Map; | ||
12 | -import java.util.Set; | ||
13 | -import java.util.concurrent.ConcurrentHashMap; | ||
14 | - | ||
15 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
16 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
17 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
18 | import org.apache.felix.scr.annotations.Service; | 10 | import org.apache.felix.scr.annotations.Service; |
11 | +import org.onlab.onos.net.Annotations; | ||
19 | import org.onlab.onos.net.ConnectPoint; | 12 | import org.onlab.onos.net.ConnectPoint; |
20 | import org.onlab.onos.net.DefaultHost; | 13 | import org.onlab.onos.net.DefaultHost; |
21 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
22 | import org.onlab.onos.net.Host; | 15 | import org.onlab.onos.net.Host; |
23 | import org.onlab.onos.net.HostId; | 16 | import org.onlab.onos.net.HostId; |
17 | +import org.onlab.onos.net.HostLocation; | ||
24 | import org.onlab.onos.net.host.HostDescription; | 18 | import org.onlab.onos.net.host.HostDescription; |
25 | import org.onlab.onos.net.host.HostEvent; | 19 | import org.onlab.onos.net.host.HostEvent; |
26 | import org.onlab.onos.net.host.HostStore; | 20 | import org.onlab.onos.net.host.HostStore; |
... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; | ... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; |
33 | import org.onlab.packet.VlanId; | 27 | import org.onlab.packet.VlanId; |
34 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
35 | 29 | ||
36 | -import com.google.common.collect.HashMultimap; | 30 | +import java.util.HashSet; |
37 | -import com.google.common.collect.ImmutableSet; | 31 | +import java.util.Map; |
38 | -import com.google.common.collect.Multimap; | 32 | +import java.util.Set; |
39 | -import com.google.common.collect.Sets; | 33 | +import java.util.concurrent.ConcurrentHashMap; |
34 | + | ||
35 | +import static org.onlab.onos.net.host.HostEvent.Type.*; | ||
36 | +import static org.slf4j.LoggerFactory.getLogger; | ||
40 | 37 | ||
41 | /** | 38 | /** |
42 | * Manages inventory of end-station hosts using trivial in-memory | 39 | * Manages inventory of end-station hosts using trivial in-memory |
... | @@ -46,13 +43,13 @@ import com.google.common.collect.Sets; | ... | @@ -46,13 +43,13 @@ import com.google.common.collect.Sets; |
46 | @Component(immediate = true) | 43 | @Component(immediate = true) |
47 | @Service | 44 | @Service |
48 | public class DistributedHostStore | 45 | public class DistributedHostStore |
49 | -extends AbstractStore<HostEvent, HostStoreDelegate> | 46 | + extends AbstractStore<HostEvent, HostStoreDelegate> |
50 | -implements HostStore { | 47 | + implements HostStore { |
51 | 48 | ||
52 | private final Logger log = getLogger(getClass()); | 49 | private final Logger log = getLogger(getClass()); |
53 | 50 | ||
54 | // Host inventory | 51 | // Host inventory |
55 | - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); | 52 | + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16); |
56 | 53 | ||
57 | // Hosts tracked by their location | 54 | // Hosts tracked by their location |
58 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); | 55 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); |
... | @@ -73,7 +70,7 @@ implements HostStore { | ... | @@ -73,7 +70,7 @@ implements HostStore { |
73 | @Override | 70 | @Override |
74 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, | 71 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, |
75 | HostDescription hostDescription) { | 72 | HostDescription hostDescription) { |
76 | - Host host = hosts.get(hostId); | 73 | + StoredHost host = hosts.get(hostId); |
77 | if (host == null) { | 74 | if (host == null) { |
78 | return createHost(providerId, hostId, hostDescription); | 75 | return createHost(providerId, hostId, hostDescription); |
79 | } | 76 | } |
... | @@ -83,11 +80,11 @@ implements HostStore { | ... | @@ -83,11 +80,11 @@ implements HostStore { |
83 | // creates a new host and sends HOST_ADDED | 80 | // creates a new host and sends HOST_ADDED |
84 | private HostEvent createHost(ProviderId providerId, HostId hostId, | 81 | private HostEvent createHost(ProviderId providerId, HostId hostId, |
85 | HostDescription descr) { | 82 | HostDescription descr) { |
86 | - DefaultHost newhost = new DefaultHost(providerId, hostId, | 83 | + StoredHost newhost = new StoredHost(providerId, hostId, |
87 | descr.hwAddress(), | 84 | descr.hwAddress(), |
88 | descr.vlan(), | 85 | descr.vlan(), |
89 | descr.location(), | 86 | descr.location(), |
90 | - descr.ipAddresses()); | 87 | + ImmutableSet.of(descr.ipAddress())); |
91 | synchronized (this) { | 88 | synchronized (this) { |
92 | hosts.put(hostId, newhost); | 89 | hosts.put(hostId, newhost); |
93 | locations.put(descr.location(), newhost); | 90 | locations.put(descr.location(), newhost); |
... | @@ -96,28 +93,24 @@ implements HostStore { | ... | @@ -96,28 +93,24 @@ implements HostStore { |
96 | } | 93 | } |
97 | 94 | ||
98 | // checks for type of update to host, sends appropriate event | 95 | // checks for type of update to host, sends appropriate event |
99 | - private HostEvent updateHost(ProviderId providerId, Host host, | 96 | + private HostEvent updateHost(ProviderId providerId, StoredHost host, |
100 | HostDescription descr) { | 97 | HostDescription descr) { |
101 | - DefaultHost updated; | ||
102 | HostEvent event; | 98 | HostEvent event; |
103 | if (!host.location().equals(descr.location())) { | 99 | if (!host.location().equals(descr.location())) { |
104 | - updated = new DefaultHost(providerId, host.id(), | 100 | + host.setLocation(descr.location()); |
105 | - host.mac(), | 101 | + return new HostEvent(HOST_MOVED, host); |
106 | - host.vlan(), | 102 | + } |
107 | - descr.location(), | ||
108 | - host.ipAddresses()); | ||
109 | - event = new HostEvent(HOST_MOVED, updated); | ||
110 | 103 | ||
111 | - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { | 104 | + if (host.ipAddresses().contains(descr.ipAddress())) { |
112 | - updated = new DefaultHost(providerId, host.id(), | ||
113 | - host.mac(), | ||
114 | - host.vlan(), | ||
115 | - descr.location(), | ||
116 | - descr.ipAddresses()); | ||
117 | - event = new HostEvent(HOST_UPDATED, updated); | ||
118 | - } else { | ||
119 | return null; | 105 | return null; |
120 | } | 106 | } |
107 | + | ||
108 | + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses()); | ||
109 | + addresses.add(descr.ipAddress()); | ||
110 | + StoredHost updated = new StoredHost(providerId, host.id(), | ||
111 | + host.mac(), host.vlan(), | ||
112 | + descr.location(), addresses); | ||
113 | + event = new HostEvent(HOST_UPDATED, updated); | ||
121 | synchronized (this) { | 114 | synchronized (this) { |
122 | hosts.put(host.id(), updated); | 115 | hosts.put(host.id(), updated); |
123 | locations.remove(host.location(), host); | 116 | locations.remove(host.location(), host); |
... | @@ -145,7 +138,7 @@ implements HostStore { | ... | @@ -145,7 +138,7 @@ implements HostStore { |
145 | 138 | ||
146 | @Override | 139 | @Override |
147 | public Iterable<Host> getHosts() { | 140 | public Iterable<Host> getHosts() { |
148 | - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); | 141 | + return ImmutableSet.<Host>copyOf(hosts.values()); |
149 | } | 142 | } |
150 | 143 | ||
151 | @Override | 144 | @Override |
... | @@ -275,4 +268,35 @@ implements HostStore { | ... | @@ -275,4 +268,35 @@ implements HostStore { |
275 | return addresses; | 268 | return addresses; |
276 | } | 269 | } |
277 | 270 | ||
271 | + // Auxiliary extension to allow location to mutate. | ||
272 | + private class StoredHost extends DefaultHost { | ||
273 | + private HostLocation location; | ||
274 | + | ||
275 | + /** | ||
276 | + * Creates an end-station host using the supplied information. | ||
277 | + * | ||
278 | + * @param providerId provider identity | ||
279 | + * @param id host identifier | ||
280 | + * @param mac host MAC address | ||
281 | + * @param vlan host VLAN identifier | ||
282 | + * @param location host location | ||
283 | + * @param ips host IP addresses | ||
284 | + * @param annotations optional key/value annotations | ||
285 | + */ | ||
286 | + public StoredHost(ProviderId providerId, HostId id, | ||
287 | + MacAddress mac, VlanId vlan, HostLocation location, | ||
288 | + Set<IpPrefix> ips, Annotations... annotations) { | ||
289 | + super(providerId, id, mac, vlan, location, ips, annotations); | ||
290 | + this.location = location; | ||
291 | + } | ||
292 | + | ||
293 | + void setLocation(HostLocation location) { | ||
294 | + this.location = location; | ||
295 | + } | ||
296 | + | ||
297 | + @Override | ||
298 | + public HostLocation location() { | ||
299 | + return location; | ||
300 | + } | ||
301 | + } | ||
278 | } | 302 | } | ... | ... |
1 | package org.onlab.onos.store.host.impl; | 1 | package org.onlab.onos.store.host.impl; |
2 | 2 | ||
3 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; | 3 | +import com.google.common.collect.HashMultimap; |
4 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; | 4 | +import com.google.common.collect.ImmutableSet; |
5 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; | 5 | +import com.google.common.collect.Multimap; |
6 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; | 6 | +import com.google.common.collect.Sets; |
7 | -import static org.slf4j.LoggerFactory.getLogger; | ||
8 | - | ||
9 | -import java.util.Collections; | ||
10 | -import java.util.HashSet; | ||
11 | -import java.util.Map; | ||
12 | -import java.util.Set; | ||
13 | -import java.util.concurrent.ConcurrentHashMap; | ||
14 | - | ||
15 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
16 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
17 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
18 | import org.apache.felix.scr.annotations.Service; | 10 | import org.apache.felix.scr.annotations.Service; |
11 | +import org.onlab.onos.net.Annotations; | ||
19 | import org.onlab.onos.net.ConnectPoint; | 12 | import org.onlab.onos.net.ConnectPoint; |
20 | import org.onlab.onos.net.DefaultHost; | 13 | import org.onlab.onos.net.DefaultHost; |
21 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
22 | import org.onlab.onos.net.Host; | 15 | import org.onlab.onos.net.Host; |
23 | import org.onlab.onos.net.HostId; | 16 | import org.onlab.onos.net.HostId; |
17 | +import org.onlab.onos.net.HostLocation; | ||
24 | import org.onlab.onos.net.host.HostDescription; | 18 | import org.onlab.onos.net.host.HostDescription; |
25 | import org.onlab.onos.net.host.HostEvent; | 19 | import org.onlab.onos.net.host.HostEvent; |
26 | import org.onlab.onos.net.host.HostStore; | 20 | import org.onlab.onos.net.host.HostStore; |
... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; | ... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; |
33 | import org.onlab.packet.VlanId; | 27 | import org.onlab.packet.VlanId; |
34 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
35 | 29 | ||
36 | -import com.google.common.collect.HashMultimap; | 30 | +import java.util.HashSet; |
37 | -import com.google.common.collect.ImmutableSet; | 31 | +import java.util.Map; |
38 | -import com.google.common.collect.Multimap; | 32 | +import java.util.Set; |
39 | -import com.google.common.collect.Sets; | 33 | +import java.util.concurrent.ConcurrentHashMap; |
34 | + | ||
35 | +import static org.onlab.onos.net.host.HostEvent.Type.*; | ||
36 | +import static org.slf4j.LoggerFactory.getLogger; | ||
40 | 37 | ||
41 | /** | 38 | /** |
42 | * TEMPORARY: Manages inventory of end-station hosts using distributed | 39 | * TEMPORARY: Manages inventory of end-station hosts using distributed |
... | @@ -46,13 +43,13 @@ import com.google.common.collect.Sets; | ... | @@ -46,13 +43,13 @@ import com.google.common.collect.Sets; |
46 | @Component(immediate = true) | 43 | @Component(immediate = true) |
47 | @Service | 44 | @Service |
48 | public class DistributedHostStore | 45 | public class DistributedHostStore |
49 | -extends AbstractStore<HostEvent, HostStoreDelegate> | 46 | + extends AbstractStore<HostEvent, HostStoreDelegate> |
50 | -implements HostStore { | 47 | + implements HostStore { |
51 | 48 | ||
52 | private final Logger log = getLogger(getClass()); | 49 | private final Logger log = getLogger(getClass()); |
53 | 50 | ||
54 | // Host inventory | 51 | // Host inventory |
55 | - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); | 52 | + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16); |
56 | 53 | ||
57 | // Hosts tracked by their location | 54 | // Hosts tracked by their location |
58 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); | 55 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); |
... | @@ -73,7 +70,7 @@ implements HostStore { | ... | @@ -73,7 +70,7 @@ implements HostStore { |
73 | @Override | 70 | @Override |
74 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, | 71 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, |
75 | HostDescription hostDescription) { | 72 | HostDescription hostDescription) { |
76 | - Host host = hosts.get(hostId); | 73 | + StoredHost host = hosts.get(hostId); |
77 | if (host == null) { | 74 | if (host == null) { |
78 | return createHost(providerId, hostId, hostDescription); | 75 | return createHost(providerId, hostId, hostDescription); |
79 | } | 76 | } |
... | @@ -83,11 +80,11 @@ implements HostStore { | ... | @@ -83,11 +80,11 @@ implements HostStore { |
83 | // creates a new host and sends HOST_ADDED | 80 | // creates a new host and sends HOST_ADDED |
84 | private HostEvent createHost(ProviderId providerId, HostId hostId, | 81 | private HostEvent createHost(ProviderId providerId, HostId hostId, |
85 | HostDescription descr) { | 82 | HostDescription descr) { |
86 | - DefaultHost newhost = new DefaultHost(providerId, hostId, | 83 | + StoredHost newhost = new StoredHost(providerId, hostId, |
87 | descr.hwAddress(), | 84 | descr.hwAddress(), |
88 | descr.vlan(), | 85 | descr.vlan(), |
89 | descr.location(), | 86 | descr.location(), |
90 | - descr.ipAddresses()); | 87 | + ImmutableSet.of(descr.ipAddress())); |
91 | synchronized (this) { | 88 | synchronized (this) { |
92 | hosts.put(hostId, newhost); | 89 | hosts.put(hostId, newhost); |
93 | locations.put(descr.location(), newhost); | 90 | locations.put(descr.location(), newhost); |
... | @@ -96,28 +93,24 @@ implements HostStore { | ... | @@ -96,28 +93,24 @@ implements HostStore { |
96 | } | 93 | } |
97 | 94 | ||
98 | // checks for type of update to host, sends appropriate event | 95 | // checks for type of update to host, sends appropriate event |
99 | - private HostEvent updateHost(ProviderId providerId, Host host, | 96 | + private HostEvent updateHost(ProviderId providerId, StoredHost host, |
100 | HostDescription descr) { | 97 | HostDescription descr) { |
101 | - DefaultHost updated; | ||
102 | HostEvent event; | 98 | HostEvent event; |
103 | if (!host.location().equals(descr.location())) { | 99 | if (!host.location().equals(descr.location())) { |
104 | - updated = new DefaultHost(providerId, host.id(), | 100 | + host.setLocation(descr.location()); |
105 | - host.mac(), | 101 | + return new HostEvent(HOST_MOVED, host); |
106 | - host.vlan(), | 102 | + } |
107 | - descr.location(), | ||
108 | - host.ipAddresses()); | ||
109 | - event = new HostEvent(HOST_MOVED, updated); | ||
110 | 103 | ||
111 | - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { | 104 | + if (host.ipAddresses().contains(descr.ipAddress())) { |
112 | - updated = new DefaultHost(providerId, host.id(), | ||
113 | - host.mac(), | ||
114 | - host.vlan(), | ||
115 | - descr.location(), | ||
116 | - descr.ipAddresses()); | ||
117 | - event = new HostEvent(HOST_UPDATED, updated); | ||
118 | - } else { | ||
119 | return null; | 105 | return null; |
120 | } | 106 | } |
107 | + | ||
108 | + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses()); | ||
109 | + addresses.add(descr.ipAddress()); | ||
110 | + StoredHost updated = new StoredHost(providerId, host.id(), | ||
111 | + host.mac(), host.vlan(), | ||
112 | + descr.location(), addresses); | ||
113 | + event = new HostEvent(HOST_UPDATED, updated); | ||
121 | synchronized (this) { | 114 | synchronized (this) { |
122 | hosts.put(host.id(), updated); | 115 | hosts.put(host.id(), updated); |
123 | locations.remove(host.location(), host); | 116 | locations.remove(host.location(), host); |
... | @@ -145,7 +138,7 @@ implements HostStore { | ... | @@ -145,7 +138,7 @@ implements HostStore { |
145 | 138 | ||
146 | @Override | 139 | @Override |
147 | public Iterable<Host> getHosts() { | 140 | public Iterable<Host> getHosts() { |
148 | - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); | 141 | + return ImmutableSet.<Host>copyOf(hosts.values()); |
149 | } | 142 | } |
150 | 143 | ||
151 | @Override | 144 | @Override |
... | @@ -275,4 +268,35 @@ implements HostStore { | ... | @@ -275,4 +268,35 @@ implements HostStore { |
275 | return addresses; | 268 | return addresses; |
276 | } | 269 | } |
277 | 270 | ||
271 | + // Auxiliary extension to allow location to mutate. | ||
272 | + private class StoredHost extends DefaultHost { | ||
273 | + private HostLocation location; | ||
274 | + | ||
275 | + /** | ||
276 | + * Creates an end-station host using the supplied information. | ||
277 | + * | ||
278 | + * @param providerId provider identity | ||
279 | + * @param id host identifier | ||
280 | + * @param mac host MAC address | ||
281 | + * @param vlan host VLAN identifier | ||
282 | + * @param location host location | ||
283 | + * @param ips host IP addresses | ||
284 | + * @param annotations optional key/value annotations | ||
285 | + */ | ||
286 | + public StoredHost(ProviderId providerId, HostId id, | ||
287 | + MacAddress mac, VlanId vlan, HostLocation location, | ||
288 | + Set<IpPrefix> ips, Annotations... annotations) { | ||
289 | + super(providerId, id, mac, vlan, location, ips, annotations); | ||
290 | + this.location = location; | ||
291 | + } | ||
292 | + | ||
293 | + void setLocation(HostLocation location) { | ||
294 | + this.location = location; | ||
295 | + } | ||
296 | + | ||
297 | + @Override | ||
298 | + public HostLocation location() { | ||
299 | + return location; | ||
300 | + } | ||
301 | + } | ||
278 | } | 302 | } | ... | ... |
1 | package org.onlab.onos.store.trivial.impl; | 1 | package org.onlab.onos.store.trivial.impl; |
2 | 2 | ||
3 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; | 3 | +import com.google.common.collect.HashMultimap; |
4 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; | 4 | +import com.google.common.collect.ImmutableSet; |
5 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; | 5 | +import com.google.common.collect.Multimap; |
6 | -import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; | 6 | +import com.google.common.collect.Sets; |
7 | -import static org.slf4j.LoggerFactory.getLogger; | ||
8 | - | ||
9 | -import java.util.Collections; | ||
10 | -import java.util.HashSet; | ||
11 | -import java.util.Map; | ||
12 | -import java.util.Set; | ||
13 | -import java.util.concurrent.ConcurrentHashMap; | ||
14 | - | ||
15 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
16 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
17 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
18 | import org.apache.felix.scr.annotations.Service; | 10 | import org.apache.felix.scr.annotations.Service; |
11 | +import org.onlab.onos.net.Annotations; | ||
19 | import org.onlab.onos.net.ConnectPoint; | 12 | import org.onlab.onos.net.ConnectPoint; |
20 | import org.onlab.onos.net.DefaultHost; | 13 | import org.onlab.onos.net.DefaultHost; |
21 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
22 | import org.onlab.onos.net.Host; | 15 | import org.onlab.onos.net.Host; |
23 | import org.onlab.onos.net.HostId; | 16 | import org.onlab.onos.net.HostId; |
17 | +import org.onlab.onos.net.HostLocation; | ||
24 | import org.onlab.onos.net.host.HostDescription; | 18 | import org.onlab.onos.net.host.HostDescription; |
25 | import org.onlab.onos.net.host.HostEvent; | 19 | import org.onlab.onos.net.host.HostEvent; |
26 | import org.onlab.onos.net.host.HostStore; | 20 | import org.onlab.onos.net.host.HostStore; |
... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; | ... | @@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; |
33 | import org.onlab.packet.VlanId; | 27 | import org.onlab.packet.VlanId; |
34 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
35 | 29 | ||
36 | -import com.google.common.collect.HashMultimap; | 30 | +import java.util.HashSet; |
37 | -import com.google.common.collect.ImmutableSet; | 31 | +import java.util.Map; |
38 | -import com.google.common.collect.Multimap; | 32 | +import java.util.Set; |
39 | -import com.google.common.collect.Sets; | 33 | +import java.util.concurrent.ConcurrentHashMap; |
34 | + | ||
35 | +import static org.onlab.onos.net.host.HostEvent.Type.*; | ||
36 | +import static org.slf4j.LoggerFactory.getLogger; | ||
40 | 37 | ||
41 | /** | 38 | /** |
42 | * Manages inventory of end-station hosts using trivial in-memory | 39 | * Manages inventory of end-station hosts using trivial in-memory |
... | @@ -51,7 +48,7 @@ public class SimpleHostStore | ... | @@ -51,7 +48,7 @@ public class SimpleHostStore |
51 | private final Logger log = getLogger(getClass()); | 48 | private final Logger log = getLogger(getClass()); |
52 | 49 | ||
53 | // Host inventory | 50 | // Host inventory |
54 | - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); | 51 | + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16); |
55 | 52 | ||
56 | // Hosts tracked by their location | 53 | // Hosts tracked by their location |
57 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); | 54 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); |
... | @@ -72,7 +69,7 @@ public class SimpleHostStore | ... | @@ -72,7 +69,7 @@ public class SimpleHostStore |
72 | @Override | 69 | @Override |
73 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, | 70 | public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, |
74 | HostDescription hostDescription) { | 71 | HostDescription hostDescription) { |
75 | - Host host = hosts.get(hostId); | 72 | + StoredHost host = hosts.get(hostId); |
76 | if (host == null) { | 73 | if (host == null) { |
77 | return createHost(providerId, hostId, hostDescription); | 74 | return createHost(providerId, hostId, hostDescription); |
78 | } | 75 | } |
... | @@ -82,11 +79,11 @@ public class SimpleHostStore | ... | @@ -82,11 +79,11 @@ public class SimpleHostStore |
82 | // creates a new host and sends HOST_ADDED | 79 | // creates a new host and sends HOST_ADDED |
83 | private HostEvent createHost(ProviderId providerId, HostId hostId, | 80 | private HostEvent createHost(ProviderId providerId, HostId hostId, |
84 | HostDescription descr) { | 81 | HostDescription descr) { |
85 | - DefaultHost newhost = new DefaultHost(providerId, hostId, | 82 | + StoredHost newhost = new StoredHost(providerId, hostId, |
86 | descr.hwAddress(), | 83 | descr.hwAddress(), |
87 | descr.vlan(), | 84 | descr.vlan(), |
88 | descr.location(), | 85 | descr.location(), |
89 | - descr.ipAddresses()); | 86 | + ImmutableSet.of(descr.ipAddress())); |
90 | synchronized (this) { | 87 | synchronized (this) { |
91 | hosts.put(hostId, newhost); | 88 | hosts.put(hostId, newhost); |
92 | locations.put(descr.location(), newhost); | 89 | locations.put(descr.location(), newhost); |
... | @@ -95,28 +92,24 @@ public class SimpleHostStore | ... | @@ -95,28 +92,24 @@ public class SimpleHostStore |
95 | } | 92 | } |
96 | 93 | ||
97 | // checks for type of update to host, sends appropriate event | 94 | // checks for type of update to host, sends appropriate event |
98 | - private HostEvent updateHost(ProviderId providerId, Host host, | 95 | + private HostEvent updateHost(ProviderId providerId, StoredHost host, |
99 | HostDescription descr) { | 96 | HostDescription descr) { |
100 | - DefaultHost updated; | ||
101 | HostEvent event; | 97 | HostEvent event; |
102 | if (!host.location().equals(descr.location())) { | 98 | if (!host.location().equals(descr.location())) { |
103 | - updated = new DefaultHost(providerId, host.id(), | 99 | + host.setLocation(descr.location()); |
104 | - host.mac(), | 100 | + return new HostEvent(HOST_MOVED, host); |
105 | - host.vlan(), | 101 | + } |
106 | - descr.location(), | ||
107 | - host.ipAddresses()); | ||
108 | - event = new HostEvent(HOST_MOVED, updated); | ||
109 | 102 | ||
110 | - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { | 103 | + if (host.ipAddresses().contains(descr.ipAddress())) { |
111 | - updated = new DefaultHost(providerId, host.id(), | ||
112 | - host.mac(), | ||
113 | - host.vlan(), | ||
114 | - descr.location(), | ||
115 | - descr.ipAddresses()); | ||
116 | - event = new HostEvent(HOST_UPDATED, updated); | ||
117 | - } else { | ||
118 | return null; | 104 | return null; |
119 | } | 105 | } |
106 | + | ||
107 | + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses()); | ||
108 | + addresses.add(descr.ipAddress()); | ||
109 | + StoredHost updated = new StoredHost(providerId, host.id(), | ||
110 | + host.mac(), host.vlan(), | ||
111 | + descr.location(), addresses); | ||
112 | + event = new HostEvent(HOST_UPDATED, updated); | ||
120 | synchronized (this) { | 113 | synchronized (this) { |
121 | hosts.put(host.id(), updated); | 114 | hosts.put(host.id(), updated); |
122 | locations.remove(host.location(), host); | 115 | locations.remove(host.location(), host); |
... | @@ -144,7 +137,7 @@ public class SimpleHostStore | ... | @@ -144,7 +137,7 @@ public class SimpleHostStore |
144 | 137 | ||
145 | @Override | 138 | @Override |
146 | public Iterable<Host> getHosts() { | 139 | public Iterable<Host> getHosts() { |
147 | - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); | 140 | + return ImmutableSet.<Host>copyOf(hosts.values()); |
148 | } | 141 | } |
149 | 142 | ||
150 | @Override | 143 | @Override |
... | @@ -274,4 +267,35 @@ public class SimpleHostStore | ... | @@ -274,4 +267,35 @@ public class SimpleHostStore |
274 | return addresses; | 267 | return addresses; |
275 | } | 268 | } |
276 | 269 | ||
270 | + // Auxiliary extension to allow location to mutate. | ||
271 | + private class StoredHost extends DefaultHost { | ||
272 | + private HostLocation location; | ||
273 | + | ||
274 | + /** | ||
275 | + * Creates an end-station host using the supplied information. | ||
276 | + * | ||
277 | + * @param providerId provider identity | ||
278 | + * @param id host identifier | ||
279 | + * @param mac host MAC address | ||
280 | + * @param vlan host VLAN identifier | ||
281 | + * @param location host location | ||
282 | + * @param ips host IP addresses | ||
283 | + * @param annotations optional key/value annotations | ||
284 | + */ | ||
285 | + public StoredHost(ProviderId providerId, HostId id, | ||
286 | + MacAddress mac, VlanId vlan, HostLocation location, | ||
287 | + Set<IpPrefix> ips, Annotations... annotations) { | ||
288 | + super(providerId, id, mac, vlan, location, ips, annotations); | ||
289 | + this.location = location; | ||
290 | + } | ||
291 | + | ||
292 | + void setLocation(HostLocation location) { | ||
293 | + this.location = location; | ||
294 | + } | ||
295 | + | ||
296 | + @Override | ||
297 | + public HostLocation location() { | ||
298 | + return location; | ||
299 | + } | ||
300 | + } | ||
277 | } | 301 | } | ... | ... |
... | @@ -493,7 +493,7 @@ | ... | @@ -493,7 +493,7 @@ |
493 | <group> | 493 | <group> |
494 | <title>Core Subsystems</title> | 494 | <title>Core Subsystems</title> |
495 | <packages> | 495 | <packages> |
496 | - org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.store.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*:org.onlab.onos.net.intent.impl | 496 | + org.onlab.onos.impl:org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.store.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*:org.onlab.onos.net.intent.impl:org.onlab.onos.net.proxyarp.impl |
497 | </packages> | 497 | </packages> |
498 | </group> | 498 | </group> |
499 | <group> | 499 | <group> |
... | @@ -518,7 +518,7 @@ | ... | @@ -518,7 +518,7 @@ |
518 | <group> | 518 | <group> |
519 | <title>Sample Applications</title> | 519 | <title>Sample Applications</title> |
520 | <packages> | 520 | <packages> |
521 | - org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.foo | 521 | + org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo |
522 | </packages> | 522 | </packages> |
523 | </group> | 523 | </group> |
524 | </groups> | 524 | </groups> | ... | ... |
providers/openflow/host/src/main/java/org/onlab/onos/provider/of/host/impl/OpenFlowHostProvider.java
1 | package org.onlab.onos.provider.of.host.impl; | 1 | package org.onlab.onos.provider.of.host.impl; |
2 | 2 | ||
3 | -import static com.google.common.collect.Sets.newHashSet; | ||
4 | -import static org.onlab.onos.net.DeviceId.deviceId; | ||
5 | -import static org.onlab.onos.net.PortNumber.portNumber; | ||
6 | -import static org.slf4j.LoggerFactory.getLogger; | ||
7 | - | ||
8 | -import java.util.Set; | ||
9 | - | ||
10 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
11 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
12 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -36,6 +29,10 @@ import org.onlab.packet.IpPrefix; | ... | @@ -36,6 +29,10 @@ import org.onlab.packet.IpPrefix; |
36 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
37 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
38 | 31 | ||
32 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
33 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
34 | +import static org.slf4j.LoggerFactory.getLogger; | ||
35 | + | ||
39 | /** | 36 | /** |
40 | * Provider which uses an OpenFlow controller to detect network | 37 | * Provider which uses an OpenFlow controller to detect network |
41 | * end-station hosts. | 38 | * end-station hosts. |
... | @@ -58,6 +55,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -58,6 +55,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
58 | 55 | ||
59 | private final InternalHostProvider listener = new InternalHostProvider(); | 56 | private final InternalHostProvider listener = new InternalHostProvider(); |
60 | 57 | ||
58 | + private boolean ipLearn = true; | ||
59 | + | ||
61 | /** | 60 | /** |
62 | * Creates an OpenFlow host provider. | 61 | * Creates an OpenFlow host provider. |
63 | */ | 62 | */ |
... | @@ -69,7 +68,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -69,7 +68,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
69 | public void activate() { | 68 | public void activate() { |
70 | providerService = providerRegistry.register(this); | 69 | providerService = providerRegistry.register(this); |
71 | controller.addPacketListener(10, listener); | 70 | controller.addPacketListener(10, listener); |
72 | - | ||
73 | log.info("Started"); | 71 | log.info("Started"); |
74 | } | 72 | } |
75 | 73 | ||
... | @@ -78,7 +76,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -78,7 +76,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
78 | providerRegistry.unregister(this); | 76 | providerRegistry.unregister(this); |
79 | controller.removePacketListener(listener); | 77 | controller.removePacketListener(listener); |
80 | providerService = null; | 78 | providerService = null; |
81 | - | ||
82 | log.info("Stopped"); | 79 | log.info("Stopped"); |
83 | } | 80 | } |
84 | 81 | ||
... | @@ -106,22 +103,22 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid | ... | @@ -106,22 +103,22 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid |
106 | HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), | 103 | HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), |
107 | portNumber(pktCtx.inPort()), | 104 | portNumber(pktCtx.inPort()), |
108 | System.currentTimeMillis()); | 105 | System.currentTimeMillis()); |
106 | + | ||
109 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); | 107 | HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); |
108 | + | ||
110 | // Potentially a new or moved host | 109 | // Potentially a new or moved host |
111 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { | 110 | if (eth.getEtherType() == Ethernet.TYPE_ARP) { |
112 | - | ||
113 | - | ||
114 | ARP arp = (ARP) eth.getPayload(); | 111 | ARP arp = (ARP) eth.getPayload(); |
115 | - Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress())); | 112 | + IpPrefix ip = IpPrefix.valueOf(arp.getSenderProtocolAddress()); |
116 | HostDescription hdescr = | 113 | HostDescription hdescr = |
117 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); | 114 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); |
118 | providerService.hostDetected(hid, hdescr); | 115 | providerService.hostDetected(hid, hdescr); |
119 | 116 | ||
120 | - } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { | 117 | + } else if (ipLearn && eth.getEtherType() == Ethernet.TYPE_IPV4) { |
121 | - IPv4 ip = (IPv4) eth.getPayload(); | 118 | + IPv4 pip = (IPv4) eth.getPayload(); |
122 | - Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(ip.getSourceAddress())); | 119 | + IpPrefix ip = IpPrefix.valueOf(pip.getSourceAddress()); |
123 | HostDescription hdescr = | 120 | HostDescription hdescr = |
124 | - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); | 121 | + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip); |
125 | providerService.hostDetected(hid, hdescr); | 122 | providerService.hostDetected(hid, hdescr); |
126 | 123 | ||
127 | } | 124 | } | ... | ... |
-
Please register or login to post a comment