Bundle restructuring
Change-Id: I5a9efa7f4d03bd78dd17297731c5addea5cf0442
Showing
67 changed files
with
818 additions
and
25 deletions
... | @@ -40,13 +40,14 @@ | ... | @@ -40,13 +40,14 @@ |
40 | Currently required for DistributedDeviceManagerTest. --> | 40 | Currently required for DistributedDeviceManagerTest. --> |
41 | <dependency> | 41 | <dependency> |
42 | <groupId>org.onlab.onos</groupId> | 42 | <groupId>org.onlab.onos</groupId> |
43 | - <artifactId>onos-core-store</artifactId> | 43 | + <artifactId>onos-core-hz</artifactId> |
44 | <version>${project.version}</version> | 44 | <version>${project.version}</version> |
45 | <scope>test</scope> | 45 | <scope>test</scope> |
46 | </dependency> | 46 | </dependency> |
47 | <dependency> | 47 | <dependency> |
48 | <groupId>org.onlab.onos</groupId> | 48 | <groupId>org.onlab.onos</groupId> |
49 | - <artifactId>onos-core-store</artifactId> | 49 | + <!-- FIXME: should be somewhere else --> |
50 | + <artifactId>onos-core-hz</artifactId> | ||
50 | <version>${project.version}</version> | 51 | <version>${project.version}</version> |
51 | <classifier>tests</classifier> | 52 | <classifier>tests</classifier> |
52 | <scope>test</scope> | 53 | <scope>test</scope> | ... | ... |
core/store/dist/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onlab.onos</groupId> | ||
9 | + <artifactId>onos-core-store</artifactId> | ||
10 | + <version>1.0.0-SNAPSHOT</version> | ||
11 | + <relativePath>../pom.xml</relativePath> | ||
12 | + </parent> | ||
13 | + | ||
14 | + <artifactId>onos-core-dist</artifactId> | ||
15 | + <packaging>bundle</packaging> | ||
16 | + | ||
17 | + <description>ONOS Gossip based distributed store subsystems</description> | ||
18 | + | ||
19 | + <dependencies> | ||
20 | + <dependency> | ||
21 | + <groupId>org.onlab.onos</groupId> | ||
22 | + <artifactId>onos-api</artifactId> | ||
23 | + </dependency> | ||
24 | + <dependency> | ||
25 | + <groupId>org.onlab.onos</groupId> | ||
26 | + <artifactId>onos-core-serializers</artifactId> | ||
27 | + <version>${project.version}</version> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
30 | + <groupId>org.apache.felix</groupId> | ||
31 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
32 | + </dependency> | ||
33 | + <dependency> | ||
34 | + <groupId>de.javakaffee</groupId> | ||
35 | + <artifactId>kryo-serializers</artifactId> | ||
36 | + </dependency> | ||
37 | + </dependencies> | ||
38 | + | ||
39 | + <build> | ||
40 | + <plugins> | ||
41 | + <plugin> | ||
42 | + <groupId>org.apache.felix</groupId> | ||
43 | + <artifactId>maven-scr-plugin</artifactId> | ||
44 | + </plugin> | ||
45 | + </plugins> | ||
46 | + </build> | ||
47 | + | ||
48 | +</project> |
core/store/hz/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onlab.onos</groupId> | ||
9 | + <artifactId>onos-core-store</artifactId> | ||
10 | + <version>1.0.0-SNAPSHOT</version> | ||
11 | + <relativePath>../pom.xml</relativePath> | ||
12 | + </parent> | ||
13 | + | ||
14 | + <artifactId>onos-core-hz</artifactId> | ||
15 | + <packaging>bundle</packaging> | ||
16 | + | ||
17 | + <description>ONOS Hazelcast based distributed store subsystems</description> | ||
18 | + | ||
19 | + <dependencies> | ||
20 | + <dependency> | ||
21 | + <groupId>org.onlab.onos</groupId> | ||
22 | + <artifactId>onos-api</artifactId> | ||
23 | + </dependency> | ||
24 | + <dependency> | ||
25 | + <groupId>org.onlab.onos</groupId> | ||
26 | + <artifactId>onos-core-serializers</artifactId> | ||
27 | + <version>${project.version}</version> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
30 | + <groupId>org.apache.felix</groupId> | ||
31 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
32 | + </dependency> | ||
33 | + <dependency> | ||
34 | + <groupId>com.hazelcast</groupId> | ||
35 | + <artifactId>hazelcast</artifactId> | ||
36 | + </dependency> | ||
37 | + <dependency> | ||
38 | + <groupId>de.javakaffee</groupId> | ||
39 | + <artifactId>kryo-serializers</artifactId> | ||
40 | + </dependency> | ||
41 | + </dependencies> | ||
42 | + | ||
43 | + <build> | ||
44 | + <plugins> | ||
45 | + <plugin> | ||
46 | + <groupId>org.apache.felix</groupId> | ||
47 | + <artifactId>maven-scr-plugin</artifactId> | ||
48 | + </plugin> | ||
49 | + </plugins> | ||
50 | + </build> | ||
51 | + | ||
52 | +</project> |
1 | +package org.onlab.onos.store.flow.impl; | ||
2 | + | ||
3 | +import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED; | ||
4 | +import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; | ||
5 | +import static org.slf4j.LoggerFactory.getLogger; | ||
6 | + | ||
7 | +import java.util.Collection; | ||
8 | +import java.util.Collections; | ||
9 | + | ||
10 | +import org.apache.felix.scr.annotations.Activate; | ||
11 | +import org.apache.felix.scr.annotations.Component; | ||
12 | +import org.apache.felix.scr.annotations.Deactivate; | ||
13 | +import org.apache.felix.scr.annotations.Service; | ||
14 | +import org.onlab.onos.ApplicationId; | ||
15 | +import org.onlab.onos.net.DeviceId; | ||
16 | +import org.onlab.onos.net.flow.DefaultFlowRule; | ||
17 | +import org.onlab.onos.net.flow.FlowRule; | ||
18 | +import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
19 | +import org.onlab.onos.net.flow.FlowRuleEvent; | ||
20 | +import org.onlab.onos.net.flow.FlowRuleEvent.Type; | ||
21 | +import org.onlab.onos.net.flow.FlowRuleStore; | ||
22 | +import org.onlab.onos.net.flow.FlowRuleStoreDelegate; | ||
23 | +import org.onlab.onos.store.AbstractStore; | ||
24 | +import org.slf4j.Logger; | ||
25 | + | ||
26 | +import com.google.common.collect.ArrayListMultimap; | ||
27 | +import com.google.common.collect.ImmutableSet; | ||
28 | +import com.google.common.collect.Multimap; | ||
29 | + | ||
30 | +/** | ||
31 | + * Manages inventory of flow rules using trivial in-memory implementation. | ||
32 | + */ | ||
33 | +//FIXME: I LIE I AM NOT DISTRIBUTED | ||
34 | +@Component(immediate = true) | ||
35 | +@Service | ||
36 | +public class DistributedFlowRuleStore | ||
37 | +extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate> | ||
38 | +implements FlowRuleStore { | ||
39 | + | ||
40 | + private final Logger log = getLogger(getClass()); | ||
41 | + | ||
42 | + // store entries as a pile of rules, no info about device tables | ||
43 | + private final Multimap<DeviceId, FlowRule> flowEntries = | ||
44 | + ArrayListMultimap.<DeviceId, FlowRule>create(); | ||
45 | + | ||
46 | + private final Multimap<ApplicationId, FlowRule> flowEntriesById = | ||
47 | + ArrayListMultimap.<ApplicationId, FlowRule>create(); | ||
48 | + | ||
49 | + @Activate | ||
50 | + public void activate() { | ||
51 | + log.info("Started"); | ||
52 | + } | ||
53 | + | ||
54 | + @Deactivate | ||
55 | + public void deactivate() { | ||
56 | + log.info("Stopped"); | ||
57 | + } | ||
58 | + | ||
59 | + | ||
60 | + @Override | ||
61 | + public synchronized FlowRule getFlowRule(FlowRule rule) { | ||
62 | + for (FlowRule f : flowEntries.get(rule.deviceId())) { | ||
63 | + if (f.equals(rule)) { | ||
64 | + return f; | ||
65 | + } | ||
66 | + } | ||
67 | + return null; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) { | ||
72 | + Collection<FlowRule> rules = flowEntries.get(deviceId); | ||
73 | + if (rules == null) { | ||
74 | + return Collections.emptyList(); | ||
75 | + } | ||
76 | + return ImmutableSet.copyOf(rules); | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) { | ||
81 | + Collection<FlowRule> rules = flowEntriesById.get(appId); | ||
82 | + if (rules == null) { | ||
83 | + return Collections.emptyList(); | ||
84 | + } | ||
85 | + return ImmutableSet.copyOf(rules); | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public synchronized void storeFlowRule(FlowRule rule) { | ||
90 | + FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD); | ||
91 | + DeviceId did = f.deviceId(); | ||
92 | + if (!flowEntries.containsEntry(did, f)) { | ||
93 | + flowEntries.put(did, f); | ||
94 | + flowEntriesById.put(rule.appId(), f); | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public synchronized void deleteFlowRule(FlowRule rule) { | ||
100 | + FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE); | ||
101 | + DeviceId did = f.deviceId(); | ||
102 | + | ||
103 | + /* | ||
104 | + * find the rule and mark it for deletion. | ||
105 | + * Ultimately a flow removed will come remove it. | ||
106 | + */ | ||
107 | + | ||
108 | + if (flowEntries.containsEntry(did, f)) { | ||
109 | + //synchronized (flowEntries) { | ||
110 | + flowEntries.remove(did, f); | ||
111 | + flowEntries.put(did, f); | ||
112 | + flowEntriesById.remove(rule.appId(), rule); | ||
113 | + //} | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + @Override | ||
118 | + public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) { | ||
119 | + DeviceId did = rule.deviceId(); | ||
120 | + | ||
121 | + // check if this new rule is an update to an existing entry | ||
122 | + if (flowEntries.containsEntry(did, rule)) { | ||
123 | + //synchronized (flowEntries) { | ||
124 | + // Multimaps support duplicates so we have to remove our rule | ||
125 | + // and replace it with the current version. | ||
126 | + flowEntries.remove(did, rule); | ||
127 | + flowEntries.put(did, rule); | ||
128 | + //} | ||
129 | + return new FlowRuleEvent(Type.RULE_UPDATED, rule); | ||
130 | + } | ||
131 | + | ||
132 | + flowEntries.put(did, rule); | ||
133 | + return new FlowRuleEvent(RULE_ADDED, rule); | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) { | ||
138 | + //synchronized (this) { | ||
139 | + if (flowEntries.remove(rule.deviceId(), rule)) { | ||
140 | + return new FlowRuleEvent(RULE_REMOVED, rule); | ||
141 | + } else { | ||
142 | + return null; | ||
143 | + } | ||
144 | + //} | ||
145 | + } | ||
146 | + | ||
147 | + | ||
148 | + | ||
149 | + | ||
150 | + | ||
151 | + | ||
152 | + | ||
153 | +} |
1 | +package org.onlab.onos.store.host.impl; | ||
2 | + | ||
3 | +import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; | ||
4 | +import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; | ||
5 | +import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; | ||
6 | +import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; | ||
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; | ||
16 | +import org.apache.felix.scr.annotations.Component; | ||
17 | +import org.apache.felix.scr.annotations.Deactivate; | ||
18 | +import org.apache.felix.scr.annotations.Service; | ||
19 | +import org.onlab.onos.net.ConnectPoint; | ||
20 | +import org.onlab.onos.net.DefaultHost; | ||
21 | +import org.onlab.onos.net.DeviceId; | ||
22 | +import org.onlab.onos.net.Host; | ||
23 | +import org.onlab.onos.net.HostId; | ||
24 | +import org.onlab.onos.net.host.HostDescription; | ||
25 | +import org.onlab.onos.net.host.HostEvent; | ||
26 | +import org.onlab.onos.net.host.HostStore; | ||
27 | +import org.onlab.onos.net.host.HostStoreDelegate; | ||
28 | +import org.onlab.onos.net.host.PortAddresses; | ||
29 | +import org.onlab.onos.net.provider.ProviderId; | ||
30 | +import org.onlab.onos.store.AbstractStore; | ||
31 | +import org.onlab.packet.IpPrefix; | ||
32 | +import org.onlab.packet.MacAddress; | ||
33 | +import org.onlab.packet.VlanId; | ||
34 | +import org.slf4j.Logger; | ||
35 | + | ||
36 | +import com.google.common.collect.HashMultimap; | ||
37 | +import com.google.common.collect.ImmutableSet; | ||
38 | +import com.google.common.collect.Multimap; | ||
39 | +import com.google.common.collect.Sets; | ||
40 | + | ||
41 | +/** | ||
42 | + * Manages inventory of end-station hosts using trivial in-memory | ||
43 | + * implementation. | ||
44 | + */ | ||
45 | +//FIXME: I LIE I AM NOT DISTRIBUTED | ||
46 | +@Component(immediate = true) | ||
47 | +@Service | ||
48 | +public class DistributedHostStore | ||
49 | +extends AbstractStore<HostEvent, HostStoreDelegate> | ||
50 | +implements HostStore { | ||
51 | + | ||
52 | + private final Logger log = getLogger(getClass()); | ||
53 | + | ||
54 | + // Host inventory | ||
55 | + private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); | ||
56 | + | ||
57 | + // Hosts tracked by their location | ||
58 | + private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); | ||
59 | + | ||
60 | + private final Map<ConnectPoint, PortAddresses> portAddresses = | ||
61 | + new ConcurrentHashMap<>(); | ||
62 | + | ||
63 | + @Activate | ||
64 | + public void activate() { | ||
65 | + log.info("Started"); | ||
66 | + } | ||
67 | + | ||
68 | + @Deactivate | ||
69 | + public void deactivate() { | ||
70 | + log.info("Stopped"); | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, | ||
75 | + HostDescription hostDescription) { | ||
76 | + Host host = hosts.get(hostId); | ||
77 | + if (host == null) { | ||
78 | + return createHost(providerId, hostId, hostDescription); | ||
79 | + } | ||
80 | + return updateHost(providerId, host, hostDescription); | ||
81 | + } | ||
82 | + | ||
83 | + // creates a new host and sends HOST_ADDED | ||
84 | + private HostEvent createHost(ProviderId providerId, HostId hostId, | ||
85 | + HostDescription descr) { | ||
86 | + DefaultHost newhost = new DefaultHost(providerId, hostId, | ||
87 | + descr.hwAddress(), | ||
88 | + descr.vlan(), | ||
89 | + descr.location(), | ||
90 | + descr.ipAddresses()); | ||
91 | + synchronized (this) { | ||
92 | + hosts.put(hostId, newhost); | ||
93 | + locations.put(descr.location(), newhost); | ||
94 | + } | ||
95 | + return new HostEvent(HOST_ADDED, newhost); | ||
96 | + } | ||
97 | + | ||
98 | + // checks for type of update to host, sends appropriate event | ||
99 | + private HostEvent updateHost(ProviderId providerId, Host host, | ||
100 | + HostDescription descr) { | ||
101 | + DefaultHost updated; | ||
102 | + HostEvent event; | ||
103 | + if (!host.location().equals(descr.location())) { | ||
104 | + updated = new DefaultHost(providerId, host.id(), | ||
105 | + host.mac(), | ||
106 | + host.vlan(), | ||
107 | + descr.location(), | ||
108 | + host.ipAddresses()); | ||
109 | + event = new HostEvent(HOST_MOVED, updated); | ||
110 | + | ||
111 | + } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { | ||
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; | ||
120 | + } | ||
121 | + synchronized (this) { | ||
122 | + hosts.put(host.id(), updated); | ||
123 | + locations.remove(host.location(), host); | ||
124 | + locations.put(updated.location(), updated); | ||
125 | + } | ||
126 | + return event; | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public HostEvent removeHost(HostId hostId) { | ||
131 | + synchronized (this) { | ||
132 | + Host host = hosts.remove(hostId); | ||
133 | + if (host != null) { | ||
134 | + locations.remove((host.location()), host); | ||
135 | + return new HostEvent(HOST_REMOVED, host); | ||
136 | + } | ||
137 | + return null; | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + @Override | ||
142 | + public int getHostCount() { | ||
143 | + return hosts.size(); | ||
144 | + } | ||
145 | + | ||
146 | + @Override | ||
147 | + public Iterable<Host> getHosts() { | ||
148 | + return Collections.unmodifiableSet(new HashSet<>(hosts.values())); | ||
149 | + } | ||
150 | + | ||
151 | + @Override | ||
152 | + public Host getHost(HostId hostId) { | ||
153 | + return hosts.get(hostId); | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public Set<Host> getHosts(VlanId vlanId) { | ||
158 | + Set<Host> vlanset = new HashSet<>(); | ||
159 | + for (Host h : hosts.values()) { | ||
160 | + if (h.vlan().equals(vlanId)) { | ||
161 | + vlanset.add(h); | ||
162 | + } | ||
163 | + } | ||
164 | + return vlanset; | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public Set<Host> getHosts(MacAddress mac) { | ||
169 | + Set<Host> macset = new HashSet<>(); | ||
170 | + for (Host h : hosts.values()) { | ||
171 | + if (h.mac().equals(mac)) { | ||
172 | + macset.add(h); | ||
173 | + } | ||
174 | + } | ||
175 | + return macset; | ||
176 | + } | ||
177 | + | ||
178 | + @Override | ||
179 | + public Set<Host> getHosts(IpPrefix ip) { | ||
180 | + Set<Host> ipset = new HashSet<>(); | ||
181 | + for (Host h : hosts.values()) { | ||
182 | + if (h.ipAddresses().contains(ip)) { | ||
183 | + ipset.add(h); | ||
184 | + } | ||
185 | + } | ||
186 | + return ipset; | ||
187 | + } | ||
188 | + | ||
189 | + @Override | ||
190 | + public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | ||
191 | + return ImmutableSet.copyOf(locations.get(connectPoint)); | ||
192 | + } | ||
193 | + | ||
194 | + @Override | ||
195 | + public Set<Host> getConnectedHosts(DeviceId deviceId) { | ||
196 | + Set<Host> hostset = new HashSet<>(); | ||
197 | + for (ConnectPoint p : locations.keySet()) { | ||
198 | + if (p.deviceId().equals(deviceId)) { | ||
199 | + hostset.addAll(locations.get(p)); | ||
200 | + } | ||
201 | + } | ||
202 | + return hostset; | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public void updateAddressBindings(PortAddresses addresses) { | ||
207 | + synchronized (portAddresses) { | ||
208 | + PortAddresses existing = portAddresses.get(addresses.connectPoint()); | ||
209 | + if (existing == null) { | ||
210 | + portAddresses.put(addresses.connectPoint(), addresses); | ||
211 | + } else { | ||
212 | + Set<IpPrefix> union = Sets.union(existing.ips(), addresses.ips()) | ||
213 | + .immutableCopy(); | ||
214 | + | ||
215 | + MacAddress newMac = (addresses.mac() == null) ? existing.mac() | ||
216 | + : addresses.mac(); | ||
217 | + | ||
218 | + PortAddresses newAddresses = | ||
219 | + new PortAddresses(addresses.connectPoint(), union, newMac); | ||
220 | + | ||
221 | + portAddresses.put(newAddresses.connectPoint(), newAddresses); | ||
222 | + } | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | + @Override | ||
227 | + public void removeAddressBindings(PortAddresses addresses) { | ||
228 | + synchronized (portAddresses) { | ||
229 | + PortAddresses existing = portAddresses.get(addresses.connectPoint()); | ||
230 | + if (existing != null) { | ||
231 | + Set<IpPrefix> difference = | ||
232 | + Sets.difference(existing.ips(), addresses.ips()).immutableCopy(); | ||
233 | + | ||
234 | + // If they removed the existing mac, set the new mac to null. | ||
235 | + // Otherwise, keep the existing mac. | ||
236 | + MacAddress newMac = existing.mac(); | ||
237 | + if (addresses.mac() != null && addresses.mac().equals(existing.mac())) { | ||
238 | + newMac = null; | ||
239 | + } | ||
240 | + | ||
241 | + PortAddresses newAddresses = | ||
242 | + new PortAddresses(addresses.connectPoint(), difference, newMac); | ||
243 | + | ||
244 | + portAddresses.put(newAddresses.connectPoint(), newAddresses); | ||
245 | + } | ||
246 | + } | ||
247 | + } | ||
248 | + | ||
249 | + @Override | ||
250 | + public void clearAddressBindings(ConnectPoint connectPoint) { | ||
251 | + synchronized (portAddresses) { | ||
252 | + portAddresses.remove(connectPoint); | ||
253 | + } | ||
254 | + } | ||
255 | + | ||
256 | + @Override | ||
257 | + public Set<PortAddresses> getAddressBindings() { | ||
258 | + synchronized (portAddresses) { | ||
259 | + return new HashSet<>(portAddresses.values()); | ||
260 | + } | ||
261 | + } | ||
262 | + | ||
263 | + @Override | ||
264 | + public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) { | ||
265 | + PortAddresses addresses; | ||
266 | + | ||
267 | + synchronized (portAddresses) { | ||
268 | + addresses = portAddresses.get(connectPoint); | ||
269 | + } | ||
270 | + | ||
271 | + if (addresses == null) { | ||
272 | + addresses = new PortAddresses(connectPoint, null, null); | ||
273 | + } | ||
274 | + | ||
275 | + return addresses; | ||
276 | + } | ||
277 | + | ||
278 | +} |
... | @@ -35,7 +35,6 @@ import org.onlab.onos.store.serializers.DeviceIdSerializer; | ... | @@ -35,7 +35,6 @@ import org.onlab.onos.store.serializers.DeviceIdSerializer; |
35 | import org.onlab.onos.store.serializers.IpPrefixSerializer; | 35 | import org.onlab.onos.store.serializers.IpPrefixSerializer; |
36 | import org.onlab.onos.store.serializers.LinkKeySerializer; | 36 | import org.onlab.onos.store.serializers.LinkKeySerializer; |
37 | import org.onlab.onos.store.serializers.NodeIdSerializer; | 37 | import org.onlab.onos.store.serializers.NodeIdSerializer; |
38 | -import org.onlab.onos.store.serializers.OnosTimestampSerializer; | ||
39 | import org.onlab.onos.store.serializers.PortNumberSerializer; | 38 | import org.onlab.onos.store.serializers.PortNumberSerializer; |
40 | import org.onlab.onos.store.serializers.ProviderIdSerializer; | 39 | import org.onlab.onos.store.serializers.ProviderIdSerializer; |
41 | import org.onlab.packet.IpPrefix; | 40 | import org.onlab.packet.IpPrefix; |
... | @@ -102,7 +101,6 @@ public class StoreManager implements StoreService { | ... | @@ -102,7 +101,6 @@ public class StoreManager implements StoreService { |
102 | .register(DeviceId.class, new DeviceIdSerializer()) | 101 | .register(DeviceId.class, new DeviceIdSerializer()) |
103 | .register(PortNumber.class, new PortNumberSerializer()) | 102 | .register(PortNumber.class, new PortNumberSerializer()) |
104 | .register(DefaultPort.class, new DefaultPortSerializer()) | 103 | .register(DefaultPort.class, new DefaultPortSerializer()) |
105 | - .register(OnosTimestamp.class, new OnosTimestampSerializer()) | ||
106 | .register(LinkKey.class, new LinkKeySerializer()) | 104 | .register(LinkKey.class, new LinkKeySerializer()) |
107 | .register(ConnectPoint.class, new ConnectPointSerializer()) | 105 | .register(ConnectPoint.class, new ConnectPointSerializer()) |
108 | .register(DefaultLink.class, new DefaultLinkSerializer()) | 106 | .register(DefaultLink.class, new DefaultLinkSerializer()) | ... | ... |
This diff is collapsed. Click to expand it.
1 | +package org.onlab.onos.store.topology.impl; | ||
2 | + | ||
3 | +import org.onlab.graph.AdjacencyListsGraph; | ||
4 | +import org.onlab.onos.net.topology.TopologyEdge; | ||
5 | +import org.onlab.onos.net.topology.TopologyGraph; | ||
6 | +import org.onlab.onos.net.topology.TopologyVertex; | ||
7 | + | ||
8 | +import java.util.Set; | ||
9 | + | ||
10 | +/** | ||
11 | + * Default implementation of an immutable topology graph based on a generic | ||
12 | + * implementation of adjacency lists graph. | ||
13 | + */ | ||
14 | +public class DefaultTopologyGraph | ||
15 | + extends AdjacencyListsGraph<TopologyVertex, TopologyEdge> | ||
16 | + implements TopologyGraph { | ||
17 | + | ||
18 | + /** | ||
19 | + * Creates a topology graph comprising of the specified vertexes and edges. | ||
20 | + * | ||
21 | + * @param vertexes set of graph vertexes | ||
22 | + * @param edges set of graph edges | ||
23 | + */ | ||
24 | + public DefaultTopologyGraph(Set<TopologyVertex> vertexes, Set<TopologyEdge> edges) { | ||
25 | + super(vertexes, edges); | ||
26 | + } | ||
27 | + | ||
28 | +} |
core/store/hz/src/main/java/org/onlab/onos/store/topology/impl/DistributedTopologyStore.java
0 → 100644
1 | +package org.onlab.onos.store.topology.impl; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | +import java.util.Set; | ||
7 | + | ||
8 | +import org.apache.felix.scr.annotations.Activate; | ||
9 | +import org.apache.felix.scr.annotations.Component; | ||
10 | +import org.apache.felix.scr.annotations.Deactivate; | ||
11 | +import org.apache.felix.scr.annotations.Service; | ||
12 | +import org.onlab.onos.event.Event; | ||
13 | +import org.onlab.onos.net.ConnectPoint; | ||
14 | +import org.onlab.onos.net.DeviceId; | ||
15 | +import org.onlab.onos.net.Link; | ||
16 | +import org.onlab.onos.net.Path; | ||
17 | +import org.onlab.onos.net.provider.ProviderId; | ||
18 | +import org.onlab.onos.net.topology.ClusterId; | ||
19 | +import org.onlab.onos.net.topology.GraphDescription; | ||
20 | +import org.onlab.onos.net.topology.LinkWeight; | ||
21 | +import org.onlab.onos.net.topology.Topology; | ||
22 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
23 | +import org.onlab.onos.net.topology.TopologyEvent; | ||
24 | +import org.onlab.onos.net.topology.TopologyGraph; | ||
25 | +import org.onlab.onos.net.topology.TopologyStore; | ||
26 | +import org.onlab.onos.net.topology.TopologyStoreDelegate; | ||
27 | +import org.onlab.onos.store.AbstractStore; | ||
28 | +import org.slf4j.Logger; | ||
29 | + | ||
30 | +/** | ||
31 | + * Manages inventory of topology snapshots using trivial in-memory | ||
32 | + * structures implementation. | ||
33 | + */ | ||
34 | +//FIXME: I LIE I AM NOT DISTRIBUTED | ||
35 | +@Component(immediate = true) | ||
36 | +@Service | ||
37 | +public class DistributedTopologyStore | ||
38 | +extends AbstractStore<TopologyEvent, TopologyStoreDelegate> | ||
39 | +implements TopologyStore { | ||
40 | + | ||
41 | + private final Logger log = getLogger(getClass()); | ||
42 | + | ||
43 | + private volatile DefaultTopology current; | ||
44 | + | ||
45 | + @Activate | ||
46 | + public void activate() { | ||
47 | + log.info("Started"); | ||
48 | + } | ||
49 | + | ||
50 | + @Deactivate | ||
51 | + public void deactivate() { | ||
52 | + log.info("Stopped"); | ||
53 | + } | ||
54 | + @Override | ||
55 | + public Topology currentTopology() { | ||
56 | + return current; | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public boolean isLatest(Topology topology) { | ||
61 | + // Topology is current only if it is the same as our current topology | ||
62 | + return topology == current; | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public TopologyGraph getGraph(Topology topology) { | ||
67 | + return defaultTopology(topology).getGraph(); | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public Set<TopologyCluster> getClusters(Topology topology) { | ||
72 | + return defaultTopology(topology).getClusters(); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public TopologyCluster getCluster(Topology topology, ClusterId clusterId) { | ||
77 | + return defaultTopology(topology).getCluster(clusterId); | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) { | ||
82 | + return defaultTopology(topology).getClusterDevices(cluster); | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) { | ||
87 | + return defaultTopology(topology).getClusterLinks(cluster); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) { | ||
92 | + return defaultTopology(topology).getPaths(src, dst); | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, | ||
97 | + LinkWeight weight) { | ||
98 | + return defaultTopology(topology).getPaths(src, dst, weight); | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
102 | + public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { | ||
103 | + return defaultTopology(topology).isInfrastructure(connectPoint); | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) { | ||
108 | + return defaultTopology(topology).isBroadcastPoint(connectPoint); | ||
109 | + } | ||
110 | + | ||
111 | + @Override | ||
112 | + public TopologyEvent updateTopology(ProviderId providerId, | ||
113 | + GraphDescription graphDescription, | ||
114 | + List<Event> reasons) { | ||
115 | + // First off, make sure that what we're given is indeed newer than | ||
116 | + // what we already have. | ||
117 | + if (current != null && graphDescription.timestamp() < current.time()) { | ||
118 | + return null; | ||
119 | + } | ||
120 | + | ||
121 | + // Have the default topology construct self from the description data. | ||
122 | + DefaultTopology newTopology = | ||
123 | + new DefaultTopology(providerId, graphDescription); | ||
124 | + | ||
125 | + // Promote the new topology to current and return a ready-to-send event. | ||
126 | + synchronized (this) { | ||
127 | + current = newTopology; | ||
128 | + return new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, current); | ||
129 | + } | ||
130 | + } | ||
131 | + | ||
132 | + // Validates the specified topology and returns it as a default | ||
133 | + private DefaultTopology defaultTopology(Topology topology) { | ||
134 | + if (topology instanceof DefaultTopology) { | ||
135 | + return (DefaultTopology) topology; | ||
136 | + } | ||
137 | + throw new IllegalArgumentException("Topology class " + topology.getClass() + | ||
138 | + " not supported"); | ||
139 | + } | ||
140 | + | ||
141 | +} |
1 | +package org.onlab.onos.store.topology.impl; | ||
2 | + | ||
3 | +import org.onlab.onos.net.DeviceId; | ||
4 | + | ||
5 | +import java.util.Objects; | ||
6 | + | ||
7 | +/** | ||
8 | + * Key for filing pre-computed paths between source and destination devices. | ||
9 | + */ | ||
10 | +class PathKey { | ||
11 | + private final DeviceId src; | ||
12 | + private final DeviceId dst; | ||
13 | + | ||
14 | + /** | ||
15 | + * Creates a path key from the given source/dest pair. | ||
16 | + * @param src source device | ||
17 | + * @param dst destination device | ||
18 | + */ | ||
19 | + PathKey(DeviceId src, DeviceId dst) { | ||
20 | + this.src = src; | ||
21 | + this.dst = dst; | ||
22 | + } | ||
23 | + | ||
24 | + @Override | ||
25 | + public int hashCode() { | ||
26 | + return Objects.hash(src, dst); | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public boolean equals(Object obj) { | ||
31 | + if (this == obj) { | ||
32 | + return true; | ||
33 | + } | ||
34 | + if (obj instanceof PathKey) { | ||
35 | + final PathKey other = (PathKey) obj; | ||
36 | + return Objects.equals(this.src, other.src) && Objects.equals(this.dst, other.dst); | ||
37 | + } | ||
38 | + return false; | ||
39 | + } | ||
40 | +} |
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
3 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
5 | <modelVersion>4.0.0</modelVersion> | 3 | <modelVersion>4.0.0</modelVersion> |
6 | 4 | ||
7 | <parent> | 5 | <parent> |
... | @@ -12,34 +10,41 @@ | ... | @@ -12,34 +10,41 @@ |
12 | </parent> | 10 | </parent> |
13 | 11 | ||
14 | <artifactId>onos-core-store</artifactId> | 12 | <artifactId>onos-core-store</artifactId> |
15 | - <packaging>bundle</packaging> | 13 | + <packaging>pom</packaging> |
16 | 14 | ||
17 | - <description>ONOS distributed store subsystems</description> | 15 | + <description>ONOS Core Store subsystem</description> |
16 | + | ||
17 | + <modules> | ||
18 | + <module>trivial</module> | ||
19 | + <module>dist</module> | ||
20 | + <module>hz</module> | ||
21 | + <module>serializers</module> | ||
22 | + </modules> | ||
18 | 23 | ||
19 | <dependencies> | 24 | <dependencies> |
20 | <dependency> | 25 | <dependency> |
26 | + <groupId>com.google.guava</groupId> | ||
27 | + <artifactId>guava</artifactId> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
21 | <groupId>org.onlab.onos</groupId> | 30 | <groupId>org.onlab.onos</groupId> |
22 | - <artifactId>onos-api</artifactId> | 31 | + <artifactId>onlab-misc</artifactId> |
23 | </dependency> | 32 | </dependency> |
24 | <dependency> | 33 | <dependency> |
25 | - <groupId>org.apache.felix</groupId> | 34 | + <groupId>org.onlab.onos</groupId> |
26 | - <artifactId>org.apache.felix.scr.annotations</artifactId> | 35 | + <artifactId>onlab-junit</artifactId> |
27 | </dependency> | 36 | </dependency> |
28 | <dependency> | 37 | <dependency> |
29 | <groupId>com.hazelcast</groupId> | 38 | <groupId>com.hazelcast</groupId> |
30 | <artifactId>hazelcast</artifactId> | 39 | <artifactId>hazelcast</artifactId> |
31 | </dependency> | 40 | </dependency> |
32 | - <dependency> | ||
33 | - <groupId>de.javakaffee</groupId> | ||
34 | - <artifactId>kryo-serializers</artifactId> | ||
35 | - </dependency> | ||
36 | </dependencies> | 41 | </dependencies> |
37 | 42 | ||
38 | <build> | 43 | <build> |
39 | <plugins> | 44 | <plugins> |
40 | <plugin> | 45 | <plugin> |
41 | <groupId>org.apache.felix</groupId> | 46 | <groupId>org.apache.felix</groupId> |
42 | - <artifactId>maven-scr-plugin</artifactId> | 47 | + <artifactId>maven-bundle-plugin</artifactId> |
43 | </plugin> | 48 | </plugin> |
44 | </plugins> | 49 | </plugins> |
45 | </build> | 50 | </build> | ... | ... |
core/store/serializers/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onlab.onos</groupId> | ||
9 | + <artifactId>onos-core-store</artifactId> | ||
10 | + <version>1.0.0-SNAPSHOT</version> | ||
11 | + <relativePath>../pom.xml</relativePath> | ||
12 | + </parent> | ||
13 | + | ||
14 | + <artifactId>onos-core-serializers</artifactId> | ||
15 | + <packaging>bundle</packaging> | ||
16 | + | ||
17 | + <description>Serializers for ONOS classes</description> | ||
18 | + | ||
19 | + <dependencies> | ||
20 | + <dependency> | ||
21 | + <groupId>org.onlab.onos</groupId> | ||
22 | + <artifactId>onos-api</artifactId> | ||
23 | + </dependency> | ||
24 | + <dependency> | ||
25 | + <groupId>org.apache.felix</groupId> | ||
26 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
27 | + </dependency> | ||
28 | + <dependency> | ||
29 | + <groupId>de.javakaffee</groupId> | ||
30 | + <artifactId>kryo-serializers</artifactId> | ||
31 | + </dependency> | ||
32 | + </dependencies> | ||
33 | + | ||
34 | + <build> | ||
35 | + <plugins> | ||
36 | + <plugin> | ||
37 | + <groupId>org.apache.felix</groupId> | ||
38 | + <artifactId>maven-scr-plugin</artifactId> | ||
39 | + </plugin> | ||
40 | + </plugins> | ||
41 | + </build> | ||
42 | + | ||
43 | +</project> |
... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
6 | 6 | ||
7 | <parent> | 7 | <parent> |
8 | <groupId>org.onlab.onos</groupId> | 8 | <groupId>org.onlab.onos</groupId> |
9 | - <artifactId>onos-core</artifactId> | 9 | + <artifactId>onos-core-store</artifactId> |
10 | <version>1.0.0-SNAPSHOT</version> | 10 | <version>1.0.0-SNAPSHOT</version> |
11 | <relativePath>../pom.xml</relativePath> | 11 | <relativePath>../pom.xml</relativePath> |
12 | </parent> | 12 | </parent> | ... | ... |
1 | -<project> | 1 | +<?xml version="1.0" encoding="UTF-8"?> |
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4_0_0.xsd"> | ||
2 | <modelVersion>4.0.0</modelVersion> | 5 | <modelVersion>4.0.0</modelVersion> |
3 | <groupId>org.onlab.tools</groupId> | 6 | <groupId>org.onlab.tools</groupId> |
4 | <artifactId>onos-build-conf</artifactId> | 7 | <artifactId>onos-build-conf</artifactId> | ... | ... |
... | @@ -2,4 +2,4 @@ | ... | @@ -2,4 +2,4 @@ |
2 | * Mechanism to transfer messages over network using IO loop and | 2 | * Mechanism to transfer messages over network using IO loop and |
3 | * message stream, backed by NIO byte buffers. | 3 | * message stream, backed by NIO byte buffers. |
4 | */ | 4 | */ |
5 | -package org.onlab.nio; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
5 | +package org.onlab.nio; | ... | ... |
-
Please register or login to post a comment