Luca Prete
Committed by Gerrit Code Review

Moving vpls app from onos-app-samples to onos repo

Change-Id: I27f8bcac00350b072a6dc33debc8adc589033490
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
67 <module>vrouter</module> 67 <module>vrouter</module>
68 <module>openstackrouting</module> 68 <module>openstackrouting</module>
69 <module>cordmcast</module> 69 <module>cordmcast</module>
70 + <module>vpls</module>
70 </modules> 71 </modules>
71 72
72 <properties> 73 <properties>
......
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
22 + <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle>
23 + </feature>
24 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014-2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-apps</artifactId>
25 + <version>1.5.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-app-vpls</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>Application to create L2 broadcast network using VLAN</description>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.vpls</onos.app.name>
36 + </properties>
37 +
38 + <dependencies>
39 + <dependency>
40 + <groupId>org.onosproject</groupId>
41 + <artifactId>onos-incubator-api</artifactId>
42 + </dependency>
43 + <dependency>
44 + <groupId>org.onosproject</groupId>
45 + <artifactId>onos-app-routing-api</artifactId>
46 + <version>${project.version}</version>
47 + </dependency>
48 + <dependency>
49 + <groupId>org.onosproject</groupId>
50 + <artifactId>onos-api</artifactId>
51 + <version>${project.version}</version>
52 + <scope>test</scope>
53 + <classifier>tests</classifier>
54 + </dependency>
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
57 + <artifactId>onos-app-sdnip</artifactId>
58 + <version>${project.version}</version>
59 + </dependency>
60 + <dependency>
61 + <groupId>org.easymock</groupId>
62 + <artifactId>easymock</artifactId>
63 + <scope>test</scope>
64 + </dependency>
65 + <dependency>
66 + <groupId>org.onosproject</groupId>
67 + <artifactId>onlab-junit</artifactId>
68 + <scope>test</scope>
69 + </dependency>
70 + </dependencies>
71 +</project>
1 +package org.onosproject.vpls;
2 +
3 +import com.google.common.collect.SetMultimap;
4 +import javafx.util.Pair;
5 +import org.onlab.packet.MacAddress;
6 +import org.onlab.packet.VlanId;
7 +import org.onosproject.core.ApplicationId;
8 +import org.onosproject.net.ConnectPoint;
9 +import org.onosproject.net.flow.DefaultTrafficSelector;
10 +import org.onosproject.net.flow.DefaultTrafficTreatment;
11 +import org.onosproject.net.flow.TrafficSelector;
12 +import org.onosproject.net.flow.TrafficTreatment;
13 +import org.onosproject.net.intent.Intent;
14 +import org.onosproject.net.intent.IntentService;
15 +import org.onosproject.net.intent.Key;
16 +import org.onosproject.net.intent.MultiPointToSinglePointIntent;
17 +import org.onosproject.net.intent.SinglePointToMultiPointIntent;
18 +import org.onosproject.routing.IntentSynchronizationService;
19 +import org.slf4j.Logger;
20 +import org.slf4j.LoggerFactory;
21 +
22 +import java.util.ArrayList;
23 +import java.util.Collection;
24 +import java.util.HashSet;
25 +import java.util.List;
26 +import java.util.Set;
27 +import java.util.stream.Collectors;
28 +
29 +/**
30 + * Synchronizes intents between the in-memory intent store and the
31 + * IntentService.
32 + */
33 +public class IntentInstaller {
34 + private static final Logger log = LoggerFactory.getLogger(
35 + IntentInstaller.class);
36 +
37 + private static final int PRIORITY_OFFSET = 1000;
38 +
39 + private static final String PREFIX_BROADCAST = "brc";
40 + private static final String PREFIX_UNICAST = "uni";
41 +
42 + private final ApplicationId appId;
43 + private final IntentSynchronizationService intentSynchronizer;
44 + private final IntentService intentService;
45 +
46 + /**
47 + * Class constructor.
48 + *
49 + * @param appId the Application ID
50 + * @param intentService the intent service
51 + * @param intentSynchronizer the intent synchronizer service
52 + */
53 + public IntentInstaller(ApplicationId appId, IntentService intentService,
54 + IntentSynchronizationService intentSynchronizer) {
55 + this.appId = appId;
56 + this.intentService = intentService;
57 + this.intentSynchronizer = intentSynchronizer;
58 + }
59 +
60 + /**
61 + * Formats the requests for creating and submit intents.
62 + * Single Points to Multi Point intents are created for all the conigured
63 + * Connect Points. Multi Point to Single Point intents are created for
64 + * Connect Points configured that have hosts attached.
65 + *
66 + * @param confHostPresentCPoint A map of Connect Points with the eventual
67 + * MAC address of the host attached, by VLAN
68 + */
69 + protected void installIntents(SetMultimap<VlanId,
70 + Pair<ConnectPoint,
71 + MacAddress>> confHostPresentCPoint) {
72 + List<Intent> intents = new ArrayList<>();
73 +
74 + confHostPresentCPoint.asMap().keySet()
75 + .forEach(vlanId -> {
76 + List<Pair<ConnectPoint, MacAddress>> cPoints =
77 + confHostPresentCPoint.get(vlanId).stream().collect(Collectors.toList());
78 +
79 + if (cPoints != null && !cPoints.isEmpty()) {
80 + for (int i = 0; i < cPoints.size(); i++) {
81 + ConnectPoint src = cPoints.get(i).getKey();
82 + Set<ConnectPoint> dsts = new HashSet<>();
83 + MacAddress mac = cPoints.get(i).getValue();
84 + for (int j = 0; j < cPoints.size(); j++) {
85 + ConnectPoint dst = cPoints.get(j).getKey();
86 + if (!dst.equals(src)) {
87 + dsts.add(dst);
88 + }
89 + }
90 + Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId);
91 + if (intentService.getIntent(brcKey) == null) {
92 + SinglePointToMultiPointIntent brcIntent =
93 + buildBrcIntent(brcKey, src, dsts, vlanId);
94 + intents.add(brcIntent);
95 + }
96 + if (mac != null && countMacInCPoints(cPoints) > 1) {
97 + Key uniKey = buildKey(PREFIX_UNICAST, src, vlanId);
98 + if (intentService.getIntent(uniKey) == null) {
99 + MultiPointToSinglePointIntent uniIntent =
100 + buildUniIntent(uniKey,
101 + dsts,
102 + src,
103 + vlanId,
104 + mac);
105 + intents.add(uniIntent);
106 + }
107 + }
108 + }
109 + }
110 + });
111 + submitIntents(intents);
112 + }
113 +
114 + /**
115 + * Requests to install the intents passed as argument to the Intent Service.
116 + *
117 + * @param intents intents to be submitted
118 + */
119 + private void submitIntents(Collection<Intent> intents) {
120 + log.debug("Submitting intents to the IntentSynchronizer");
121 +
122 + for (Intent intent : intents) {
123 + intentSynchronizer.submit(intent);
124 + }
125 + }
126 +
127 + /**
128 + * Builds a Single Point to Multi Point intent.
129 + *
130 + * @param src The source Connect Point
131 + * @param dsts The destination Connect Points
132 + * @return Single Point to Multi Point intent generated.
133 + */
134 + private SinglePointToMultiPointIntent buildBrcIntent(Key key,
135 + ConnectPoint src,
136 + Set<ConnectPoint> dsts,
137 + VlanId vlanId) {
138 + log.debug("Building p2mp intent from {}", src);
139 +
140 + SinglePointToMultiPointIntent intent;
141 +
142 + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
143 +
144 + TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
145 + .matchEthDst(MacAddress.BROADCAST)
146 + .matchVlanId(vlanId);
147 +
148 + TrafficSelector selector = builder.build();
149 +
150 + intent = SinglePointToMultiPointIntent.builder()
151 + .appId(appId)
152 + .key(key)
153 + .selector(selector)
154 + .treatment(treatment)
155 + .ingressPoint(src)
156 + .egressPoints(dsts)
157 + .priority(PRIORITY_OFFSET)
158 + .build();
159 + return intent;
160 + }
161 +
162 + /**
163 + * Builds a Multi Point to Single Point intent.
164 + *
165 + * @param srcs The source Connect Points
166 + * @param dst The destination Connect Point
167 + * @return Multi Point to Single Point intent generated.
168 + */
169 + private MultiPointToSinglePointIntent buildUniIntent(Key key,
170 + Set<ConnectPoint> srcs,
171 + ConnectPoint dst,
172 + VlanId vlanId,
173 + MacAddress mac) {
174 + log.debug("Building mp2p intent to {}", dst);
175 +
176 + MultiPointToSinglePointIntent intent;
177 +
178 + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
179 +
180 + TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
181 + .matchEthDst(mac)
182 + .matchVlanId(vlanId);
183 +
184 + TrafficSelector selector = builder.build();
185 +
186 + intent = MultiPointToSinglePointIntent.builder()
187 + .appId(appId)
188 + .key(key)
189 + .selector(selector)
190 + .treatment(treatment)
191 + .ingressPoints(srcs)
192 + .egressPoint(dst)
193 + .priority(PRIORITY_OFFSET)
194 + .build();
195 + return intent;
196 + }
197 +
198 + /**
199 + * Builds an intent Key for either for a Single Point to Multi Point or
200 + * Multi Point to Single Point intent, based on a prefix that defines
201 + * the type of intent, the single connection point representing the source
202 + * or the destination and the vlan id representing the network.
203 + *
204 + * @param cPoint the source or destination connect point
205 + * @param vlanId the network vlan id
206 + * @param prefix prefix string
207 + * @return
208 + */
209 + private Key buildKey(String prefix, ConnectPoint cPoint, VlanId vlanId) {
210 + String keyString = new StringBuilder()
211 + .append(prefix)
212 + .append("-")
213 + .append(cPoint.deviceId())
214 + .append("-")
215 + .append(cPoint.port())
216 + .append("-")
217 + .append(vlanId)
218 + .toString();
219 +
220 + return Key.of(keyString, appId);
221 + }
222 +
223 + /**
224 + * Counts the number of mac addresses associated to a specific list of
225 + * ConnectPoint.
226 + *
227 + * @param cPoints List of ConnectPoints, eventually binded to the MAC of the
228 + * host attached
229 + * @return number of mac addresses found.
230 + */
231 + private int countMacInCPoints(List<Pair<ConnectPoint, MacAddress>> cPoints) {
232 + int macFound = 0;
233 + for (Pair<ConnectPoint, MacAddress> p : cPoints) {
234 + if (p.getValue() != null) {
235 + macFound++;
236 + }
237 + }
238 + return macFound;
239 + }
240 +
241 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.vpls;
17 +
18 +import com.google.common.collect.HashMultimap;
19 +import com.google.common.collect.SetMultimap;
20 +import javafx.util.Pair;
21 +import org.apache.felix.scr.annotations.Activate;
22 +import org.apache.felix.scr.annotations.Component;
23 +import org.apache.felix.scr.annotations.Deactivate;
24 +import org.apache.felix.scr.annotations.Reference;
25 +import org.apache.felix.scr.annotations.ReferenceCardinality;
26 +import org.onlab.packet.MacAddress;
27 +import org.onlab.packet.VlanId;
28 +import org.onosproject.app.ApplicationService;
29 +import org.onosproject.core.ApplicationId;
30 +import org.onosproject.core.CoreService;
31 +import org.onosproject.incubator.net.intf.InterfaceService;
32 +import org.onosproject.net.ConnectPoint;
33 +import org.onosproject.net.Host;
34 +import org.onosproject.net.host.HostEvent;
35 +import org.onosproject.net.host.HostListener;
36 +import org.onosproject.net.host.HostService;
37 +import org.onosproject.net.intent.IntentService;
38 +import org.onosproject.routing.IntentSynchronizationAdminService;
39 +import org.onosproject.routing.IntentSynchronizationService;
40 +import org.slf4j.Logger;
41 +
42 +import java.util.Map;
43 +import java.util.Set;
44 +
45 +import static org.slf4j.LoggerFactory.getLogger;
46 +
47 +/**
48 + * Application to create L2 broadcast overlay networks using VLAN.
49 + */
50 +@Component(immediate = true)
51 +public class Vpls {
52 + private static final String VPLS_APP = "org.onosproject.vpls";
53 + private final Logger log = getLogger(getClass());
54 +
55 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 + protected ApplicationService applicationService;
57 +
58 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 + protected CoreService coreService;
60 +
61 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 + protected HostService hostService;
63 +
64 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 + protected IntentService intentService;
66 +
67 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 + protected InterfaceService interfaceService;
69 +
70 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 + protected IntentSynchronizationService intentSynchronizer;
72 +
73 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 + protected IntentSynchronizationAdminService intentSynchronizerAdmin;
75 +
76 + private final HostListener hostListener = new InternalHostListener();
77 +
78 + private IntentInstaller intentInstaller;
79 +
80 + private ApplicationId appId;
81 +
82 + @Activate
83 + public void activate() {
84 + appId = coreService.registerApplication(VPLS_APP);
85 +
86 + intentInstaller = new IntentInstaller(appId,
87 + intentService,
88 + intentSynchronizer);
89 +
90 + applicationService.registerDeactivateHook(appId,
91 + intentSynchronizerAdmin::removeIntents);
92 +
93 + hostService.addListener(hostListener);
94 +
95 + setupConnectivity();
96 +
97 + log.info("Started");
98 + }
99 +
100 + @Deactivate
101 + public void deactivate() {
102 + log.info("Stopped");
103 + }
104 +
105 + protected void setupConnectivity() {
106 + /*
107 + * Parse Configuration and get Connect Point by VlanId.
108 + */
109 + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan = getConfigCPoints();
110 +
111 + /*
112 + * Check that configured Connect Points have hosts attached and
113 + * associate their Mac Address to the Connect Points configured.
114 + */
115 + SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> confHostPresentCPoint =
116 + pairAvailableHosts(confCPointsByVlan);
117 +
118 + /*
119 + * Create and submit intents between the Connect Points.
120 + * Intents for broadcast between all the configured Connect Points.
121 + * Intents for unicast between all the configured Connect Points with
122 + * hosts attached.
123 + */
124 + intentInstaller.installIntents(confHostPresentCPoint);
125 + }
126 +
127 + /**
128 + * Computes the list of configured interfaces with a VLAN Id.
129 + *
130 + * @return the interfaces grouped by vlan id
131 + */
132 + protected SetMultimap<VlanId, ConnectPoint> getConfigCPoints() {
133 + log.debug("Checking interface configuration");
134 +
135 + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan =
136 + HashMultimap.create();
137 +
138 + interfaceService.getInterfaces()
139 + .forEach(intf -> confCPointsByVlan.put(intf.vlan(),
140 + intf.connectPoint()));
141 + return confCPointsByVlan;
142 + }
143 +
144 + /**
145 + * Checks if for any ConnectPoint configured there's an host present
146 + * and in case it associate them together.
147 + *
148 + * @param confCPointsByVlan the configured ConnectPoints grouped by vlan id
149 + * @return the configured ConnectPoints with eventual hosts associated.
150 + */
151 + protected SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> pairAvailableHosts(
152 + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan) {
153 + log.debug("Binding connected hosts mac addresses");
154 +
155 + SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> confHostPresentCPoint =
156 + HashMultimap.create();
157 +
158 + confCPointsByVlan.entries()
159 + .forEach(e -> bindMacAddr(e, confHostPresentCPoint));
160 +
161 + return confHostPresentCPoint;
162 + }
163 +
164 + private void bindMacAddr(Map.Entry<VlanId, ConnectPoint> e,
165 + SetMultimap<VlanId, Pair<ConnectPoint,
166 + MacAddress>> confHostPresentCPoint) {
167 + VlanId vlanId = e.getKey();
168 + ConnectPoint cp = e.getValue();
169 + Set<Host> connectedHosts = hostService.getConnectedHosts(cp);
170 + if (!connectedHosts.isEmpty()) {
171 + connectedHosts.forEach(host -> {
172 + if (host.vlan().equals(vlanId)) {
173 + confHostPresentCPoint.put(vlanId, new Pair<>(cp, host.mac()));
174 + } else {
175 + confHostPresentCPoint.put(vlanId, new Pair<>(cp, null));
176 + }
177 + });
178 + } else {
179 + confHostPresentCPoint.put(vlanId, new Pair<>(cp, null));
180 + }
181 + }
182 +
183 + /**
184 + * Listener for host events.
185 + */
186 + class InternalHostListener implements HostListener {
187 + @Override
188 + public void event(HostEvent event) {
189 + log.debug("Received HostEvent {}", event);
190 + switch (event.type()) {
191 + case HOST_ADDED:
192 + case HOST_UPDATED:
193 + case HOST_REMOVED:
194 + setupConnectivity();
195 + break;
196 + default:
197 + break;
198 + }
199 + }
200 + }
201 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Application to create L2 broadcast network using VLAN.
19 + */
20 +package org.onosproject.vpls;
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.vpls;
17 +
18 +import com.google.common.collect.Sets;
19 +import org.junit.Before;
20 +import org.junit.BeforeClass;
21 +import org.junit.Test;
22 +import org.onlab.packet.Ip4Address;
23 +import org.onlab.packet.MacAddress;
24 +import org.onlab.packet.VlanId;
25 +import org.onosproject.TestApplicationId;
26 +import org.onosproject.app.ApplicationService;
27 +import org.onosproject.core.ApplicationId;
28 +import org.onosproject.core.CoreService;
29 +import org.onosproject.core.IdGenerator;
30 +import org.onosproject.incubator.net.intf.Interface;
31 +import org.onosproject.incubator.net.intf.InterfaceService;
32 +import org.onosproject.net.ConnectPoint;
33 +import org.onosproject.net.DefaultHost;
34 +import org.onosproject.net.DeviceId;
35 +import org.onosproject.net.Host;
36 +import org.onosproject.net.HostId;
37 +import org.onosproject.net.HostLocation;
38 +import org.onosproject.net.PortNumber;
39 +import org.onosproject.net.flow.DefaultTrafficSelector;
40 +import org.onosproject.net.flow.DefaultTrafficTreatment;
41 +import org.onosproject.net.flow.TrafficSelector;
42 +import org.onosproject.net.flow.TrafficTreatment;
43 +import org.onosproject.net.host.HostEvent;
44 +import org.onosproject.net.host.HostListener;
45 +import org.onosproject.net.host.HostService;
46 +import org.onosproject.net.host.HostServiceAdapter;
47 +import org.onosproject.net.intent.Intent;
48 +import org.onosproject.net.intent.IntentService;
49 +import org.onosproject.net.intent.IntentServiceAdapter;
50 +import org.onosproject.net.intent.IntentUtils;
51 +import org.onosproject.net.intent.Key;
52 +import org.onosproject.net.intent.MultiPointToSinglePointIntent;
53 +import org.onosproject.net.intent.SinglePointToMultiPointIntent;
54 +import org.onosproject.net.provider.ProviderId;
55 +import org.onosproject.routing.IntentSynchronizationAdminService;
56 +import org.onosproject.routing.IntentSynchronizationService;
57 +
58 +import java.util.ArrayList;
59 +import java.util.Collections;
60 +import java.util.HashSet;
61 +import java.util.List;
62 +import java.util.Set;
63 +import java.util.concurrent.atomic.AtomicLong;
64 +import java.util.stream.Collectors;
65 +
66 +import static java.lang.String.format;
67 +import static org.easymock.EasyMock.createMock;
68 +import static org.easymock.EasyMock.expect;
69 +import static org.easymock.EasyMock.replay;
70 +import static org.junit.Assert.assertEquals;
71 +import static org.junit.Assert.assertTrue;
72 +
73 +/**
74 + * Tests for the {@link Vpls} class.
75 + */
76 +public class VplsTest {
77 +
78 + private static final int NUM_DEVICES = 7;
79 +
80 + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01");
81 + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02");
82 + private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03");
83 + private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04");
84 + private static final MacAddress MAC5 = MacAddress.valueOf("00:00:00:00:00:05");
85 + private static final MacAddress MAC6 = MacAddress.valueOf("00:00:00:00:00:06");
86 + private static final MacAddress MAC7 = MacAddress.valueOf("00:00:00:00:00:07");
87 +
88 + private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1");
89 + private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2");
90 +
91 + private static final PortNumber P1 = PortNumber.portNumber(1);
92 +
93 + private static final VlanId VLAN1 = VlanId.vlanId((short) 1);
94 + private static final VlanId VLAN2 = VlanId.vlanId((short) 2);
95 +
96 + private static final int PRIORITY_OFFSET = 1000;
97 + private static final String PREFIX_BROADCAST = "brc";
98 + private static final String PREFIX_UNICAST = "uni";
99 +
100 + private static final DeviceId DID1 = getDeviceId(1);
101 + private static final DeviceId DID2 = getDeviceId(2);
102 + private static final DeviceId DID3 = getDeviceId(3);
103 + private static final DeviceId DID4 = getDeviceId(4);
104 + private static final DeviceId DID5 = getDeviceId(5);
105 + private static final DeviceId DID6 = getDeviceId(6);
106 +
107 + private static final ConnectPoint C1 = new ConnectPoint(DID1, P1);
108 + private static final ConnectPoint C2 = new ConnectPoint(DID2, P1);
109 + private static final ConnectPoint C3 = new ConnectPoint(DID3, P1);
110 + private static final ConnectPoint C4 = new ConnectPoint(DID4, P1);
111 + private static final ConnectPoint C5 = new ConnectPoint(DID5, P1);
112 + private static final ConnectPoint C6 = new ConnectPoint(DID6, P1);
113 +
114 + private static final HostId HID1 = HostId.hostId(MAC1, VLAN1);
115 + private static final HostId HID2 = HostId.hostId(MAC2, VLAN1);
116 + private static final HostId HID3 = HostId.hostId(MAC3, VLAN1);
117 + private static final HostId HID4 = HostId.hostId(MAC4, VLAN2);
118 + private static final HostId HID5 = HostId.hostId(MAC5, VLAN2);
119 + private static final HostId HID6 = HostId.hostId(MAC6, VLAN2);
120 + private static final HostId HID7 = HostId.hostId(MAC7, VlanId.NONE);
121 +
122 + private ApplicationService applicationService;
123 + private CoreService coreService;
124 + private HostListener hostListener;
125 + private Set<Host> hostsAvailable;
126 + private HostService hostService;
127 + private IntentService intentService;
128 + private InterfaceService interfaceService;
129 + private Vpls vpls;
130 +
131 + private static final String APP_NAME = "org.onosproject.vpls";
132 + private static final ApplicationId APPID = TestApplicationId.create(APP_NAME);
133 +
134 + private static final ProviderId PID = new ProviderId("of", "foo");
135 +
136 + @BeforeClass
137 + public static void setUpClass() {
138 + IdGenerator idGenerator = new TestIdGenerator();
139 + Intent.bindIdGenerator(idGenerator);
140 + }
141 +
142 + @Before
143 + public void setUp() throws Exception {
144 + applicationService = createMock(ApplicationService.class);
145 +
146 + coreService = createMock(CoreService.class);
147 + expect(coreService.registerApplication(APP_NAME))
148 + .andReturn(APPID);
149 + replay(coreService);
150 +
151 + hostsAvailable = Sets.newHashSet();
152 + hostService = new TestHostService(hostsAvailable);
153 +
154 + intentService = new TestIntentService();
155 +
156 + TestIntentSynchronizer intentSynchronizer =
157 + new TestIntentSynchronizer(intentService);
158 +
159 + interfaceService = createMock(InterfaceService.class);
160 + addIntfConfig();
161 +
162 + vpls = new Vpls();
163 + vpls.applicationService = applicationService;
164 + vpls.coreService = coreService;
165 + vpls.hostService = hostService;
166 + vpls.intentService = intentService;
167 + vpls.interfaceService = interfaceService;
168 + vpls.intentSynchronizer = intentSynchronizer;
169 + vpls.intentSynchronizerAdmin = intentSynchronizer;
170 + }
171 +
172 + /**
173 + * Creates the interface configuration. On devices 1, 2 and 3 is configured
174 + * an interface on port 1 with vlan 1. On devices 4, 5 and 6 is configured
175 + * an interface on port 1 with vlan 2. On device 5 no interfaces are
176 + * configured.
177 + */
178 + private void addIntfConfig() {
179 + Set<Interface> interfaces = Sets.newHashSet();
180 + Set<Interface> vlanOneSet = new HashSet<>();
181 + Set<Interface> vlanTwoSet = new HashSet<>();
182 +
183 + for (int i = 1; i <= NUM_DEVICES - 1; i++) {
184 + ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
185 +
186 + Interface intf =
187 + new Interface(cp, Collections.emptySet(), null, VlanId.NONE);
188 +
189 + if (i <= 3) {
190 + intf = new Interface(cp, Collections.emptySet(), null, VLAN1);
191 + interfaces.add(intf);
192 + vlanOneSet.add(intf);
193 + } else if (i > 3 && i <= 6) {
194 + intf = new Interface(cp, Collections.emptySet(), null, VLAN2);
195 + interfaces.add(intf);
196 + vlanTwoSet.add(intf);
197 + }
198 + expect(interfaceService.getInterfacesByPort(cp))
199 + .andReturn(Sets.newHashSet(intf)).anyTimes();
200 + }
201 + expect(interfaceService.getInterfacesByVlan(VLAN1))
202 + .andReturn(vlanOneSet).anyTimes();
203 + expect(interfaceService.getInterfacesByVlan(VLAN2))
204 + .andReturn(vlanTwoSet).anyTimes();
205 + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
206 +
207 + replay(interfaceService);
208 + }
209 +
210 + /**
211 + * Checks the case in which six ports are configured with VLANs but no
212 + * hosts are registered by the HostService. The first three ports have an
213 + * interface configured on VLAN1, the other three on VLAN2. The number of
214 + * intents expected is six: three for VLAN1, three for VLAN2. three sp2mp
215 + * intents, three mp2sp intents.
216 + */
217 + @Test
218 + public void testActivateNoHosts() {
219 + vpls.activate();
220 +
221 + List<Intent> expectedIntents = new ArrayList<>();
222 + expectedIntents.addAll(generateVlanOneBrc());
223 + expectedIntents.addAll(generateVlanTwoBrc());
224 +
225 + checkIntents(expectedIntents);
226 + }
227 +
228 + /**
229 + * Checks the case in which six ports are configured with VLANs and four
230 + * hosts are registered by the HostService. The first three ports have an
231 + * interface configured on VLAN1, the other three on VLAN2. The number of
232 + * intents expected is twelve: six for VLAN1, six for VLAN2. six sp2mp
233 + * intents, six mp2sp intents. For VLAN1 IPs are added to demonstrate it
234 + * doesn't influence the number of intents created.
235 + */
236 + @Test
237 + public void testFourInterfacesConfiguredHostsPresent() {
238 + Host h1 = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(1),
239 + Collections.singleton(IP1));
240 + Host h2 = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(2),
241 + Collections.singleton(IP2));
242 + Host h3 = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(3),
243 + Collections.EMPTY_SET);
244 + Host h4 = new DefaultHost(PID, HID4, MAC4, VLAN2, getLocation(4),
245 + Collections.EMPTY_SET);
246 + Host h5 = new DefaultHost(PID, HID5, MAC5, VLAN2, getLocation(5),
247 + Collections.EMPTY_SET);
248 + Host h6 = new DefaultHost(PID, HID6, MAC6, VLAN2, getLocation(6),
249 + Collections.EMPTY_SET);
250 + hostsAvailable.addAll(Sets.newHashSet(h1, h2, h3, h4, h5, h6));
251 +
252 + vpls.activate();
253 +
254 + List<Intent> expectedIntents = new ArrayList<>();
255 + expectedIntents.addAll(generateVlanOneBrc());
256 + expectedIntents.addAll(generateVlanOneUni());
257 + expectedIntents.addAll(generateVlanTwoBrc());
258 + expectedIntents.addAll(generateVlanTwoUni());
259 +
260 + checkIntents(expectedIntents);
261 + }
262 +
263 + /**
264 + * Checks the case in which six ports are configured with VLANs and
265 + * initially no hosts are registered by the HostService. The first three
266 + * ports have an interface configured on VLAN1, the other three have an
267 + * interface configured on VLAN2. When the module starts up, three hosts -
268 + * on device one, two and three - port 1 (both on VLAN1), are registered by
269 + * the HostService and events are sent to the application. sp2mp intents
270 + * are created for all interfaces configured and mp2sp intents are created
271 + * only for the hosts attached.
272 + * The number of intents expected is nine: six for VLAN1, three for VLAN2.
273 + * Six sp2mp intents, three mp2sp intents. IPs are added on the first two
274 + * hosts only to demonstrate it doesn't influence the number of intents
275 + * created.
276 + * An additional host is added on device seven, port one to demonstrate
277 + * that, even if it's on the same VLAN of other interfaces configured in
278 + * the system, it doesn't let the application generate intents, since it's
279 + * not connected to the interface configured.
280 + */
281 + @Test
282 + public void testFourInterfacesThreeHostEventsSameVlan() {
283 + vpls.activate();
284 +
285 + Host h1 = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(1),
286 + Collections.singleton(IP1));
287 + Host h2 = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(2),
288 + Collections.singleton(IP2));
289 + Host h3 = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(3),
290 + Collections.EMPTY_SET);
291 + Host h7 = new DefaultHost(PID, HID7, MAC7, VLAN1, getLocation(7),
292 + Collections.EMPTY_SET);
293 + hostsAvailable.addAll(Sets.newHashSet(h1, h2, h3, h7));
294 +
295 + hostsAvailable.forEach(host ->
296 + hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host)));
297 +
298 + List<Intent> expectedIntents = new ArrayList<>();
299 + expectedIntents.addAll(generateVlanOneBrc());
300 + expectedIntents.addAll(generateVlanOneUni());
301 + expectedIntents.addAll(generateVlanTwoBrc());
302 +
303 + checkIntents(expectedIntents);
304 + }
305 +
306 + /**
307 + * Checks the case in which six ports are configured with VLANs and
308 + * initially no hosts are registered by the HostService. The first three
309 + * ports have an interface configured on VLAN1, the other three have an
310 + * interface configured on VLAN2. When the module starts up, two hosts -
311 + * on device one and four - port 1 (VLAN 1 and VLAN 2), are registered by
312 + * the HostService and events are sent to the application. sp2mp intents
313 + * are created for all interfaces configured and no mp2sp intents are created
314 + * at all, since the minimum number of hosts needed on the same vlan to
315 + * create mp2sp intents is 2.
316 + * The number of intents expected is six: three for VLAN1, three for VLAN2.
317 + * six sp2mp intents, zero mp2sp intents. IPs are added on the first host
318 + * only to demonstrate it doesn't influence the number of intents created.
319 + */
320 + @Test
321 + public void testFourInterfacesTwoHostEventsDifferentVlan() {
322 + vpls.activate();
323 +
324 + Host h1 = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(1),
325 + Collections.singleton(IP1));
326 + Host h4 = new DefaultHost(PID, HID4, MAC4, VLAN2, getLocation(4),
327 + Collections.EMPTY_SET);
328 + hostsAvailable.addAll(Sets.newHashSet(h1, h4));
329 +
330 + hostsAvailable.forEach(host -> {
331 + hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host));
332 + });
333 +
334 + List<Intent> expectedIntents = new ArrayList<>();
335 + expectedIntents.addAll(generateVlanOneBrc());
336 + expectedIntents.addAll(generateVlanTwoBrc());
337 +
338 + checkIntents(expectedIntents);
339 + }
340 +
341 + /**
342 + * Checks both that the number of intents in submitted in the intent
343 + * framework it's equal to the number of intents expected and that all
344 + * intents are equivalent.
345 + *
346 + * @param intents the list of intents expected
347 + */
348 + private void checkIntents(List<Intent> intents) {
349 + assertEquals(intents.size(), intentService.getIntentCount());
350 +
351 + for (Intent intentOne : intents) {
352 + boolean found = false;
353 + for (Intent intentTwo : intentService.getIntents()) {
354 + if (intentOne.key().equals(intentTwo.key())) {
355 + found = true;
356 + assertTrue(format("Comparing %s and %s", intentOne, intentTwo),
357 + IntentUtils.intentsAreEqual(intentOne, intentTwo));
358 + break;
359 + }
360 + }
361 + assertTrue(found);
362 + }
363 + }
364 +
365 + /**
366 + * Generates the list of the expected sp2mp intents for VLAN 1.
367 + *
368 + * @return the list of expected sp2mp intents for VLAN 1
369 + */
370 + private List<SinglePointToMultiPointIntent> generateVlanOneBrc() {
371 + Key key = null;
372 +
373 + List<SinglePointToMultiPointIntent> intents = new ArrayList<>();
374 +
375 + // Building sp2mp intent for H1 - VLAN1
376 + key = Key.of((PREFIX_BROADCAST + "-" + DID1 + "-" + P1 + "-" + VLAN1),
377 + APPID);
378 + intents.add(buildBrcIntent(key, C1, Sets.newHashSet(C2, C3), VLAN1));
379 +
380 + // Building sp2mp intent for H2 - VLAN1
381 + key = Key.of((PREFIX_BROADCAST + "-" + DID2 + "-" + P1 + "-" + VLAN1),
382 + APPID);
383 + intents.add(buildBrcIntent(key, C2, Sets.newHashSet(C1, C3), VLAN1));
384 +
385 + // Building sp2mp intent for H3 - VLAN1
386 + key = Key.of((PREFIX_BROADCAST + "-" + DID3 + "-" + P1 + "-" + VLAN1),
387 + APPID);
388 + intents.add(buildBrcIntent(key, C3, Sets.newHashSet(C1, C2), VLAN1));
389 +
390 + return intents;
391 + }
392 +
393 + /**
394 + * Generates the list of the expected mp2sp intents for VLAN 1.
395 + *
396 + * @return the list of expected mp2sp intents for VLAN 1
397 + */
398 + private List<MultiPointToSinglePointIntent> generateVlanOneUni() {
399 + Key key = null;
400 +
401 + List<MultiPointToSinglePointIntent> intents = new ArrayList<>();
402 +
403 + // Building mp2sp intent for H1 - VLAN1
404 + key = Key.of((PREFIX_UNICAST + "-" + DID1 + "-" + P1 + "-" + VLAN1),
405 + APPID);
406 + intents.add(buildUniIntent(key, Sets.newHashSet(C2, C3), C1, VLAN1, MAC1));
407 +
408 + // Building mp2sp intent for H2 - VLAN1
409 + key = Key.of((PREFIX_UNICAST + "-" + DID2 + "-" + P1 + "-" + VLAN1),
410 + APPID);
411 + intents.add(buildUniIntent(key, Sets.newHashSet(C1, C3), C2, VLAN1, MAC2));
412 +
413 + // Building mp2sp intent for H3 - VLAN1
414 + key = Key.of((PREFIX_UNICAST + "-" + DID3 + "-" + P1 + "-" + VLAN1),
415 + APPID);
416 + intents.add(buildUniIntent(key, Sets.newHashSet(C1, C2), C3, VLAN1, MAC3));
417 +
418 + return intents;
419 + }
420 +
421 + /**
422 + * Generates the list of the expected sp2mp intents for VLAN 2.
423 + *
424 + * @return the list of expected sp2mp intents for VLAN 2
425 + */
426 + private List<SinglePointToMultiPointIntent> generateVlanTwoBrc() {
427 + Key key = null;
428 +
429 + List<SinglePointToMultiPointIntent> intents = new ArrayList<>();
430 +
431 + // Building sp2mp intent for H4 - VLAN2
432 + key = Key.of((PREFIX_BROADCAST + "-" + DID4 + "-" + P1 + "-" + VLAN2),
433 + APPID);
434 + intents.add(buildBrcIntent(key, C4, Sets.newHashSet(C5, C6), VLAN2));
435 +
436 + // Building sp2mp intent for H5 - VLAN2
437 + key = Key.of((PREFIX_BROADCAST + "-" + DID5 + "-" + P1 + "-" + VLAN2),
438 + APPID);
439 + intents.add(buildBrcIntent(key, C5, Sets.newHashSet(C4, C6), VLAN2));
440 +
441 + // Building sp2mp intent for H6 - VLAN2
442 + key = Key.of((PREFIX_BROADCAST + "-" + DID6 + "-" + P1 + "-" + VLAN2),
443 + APPID);
444 + intents.add(buildBrcIntent(key, C6, Sets.newHashSet(C4, C5), VLAN2));
445 +
446 + return intents;
447 + }
448 +
449 + /**
450 + * Generates the list of the expected mp2sp intents for VLAN 2.
451 + *
452 + * @return the list of expected mp2sp intents for VLAN 2
453 + */
454 + private List<MultiPointToSinglePointIntent> generateVlanTwoUni() {
455 + Key key = null;
456 +
457 + List<MultiPointToSinglePointIntent> intents = new ArrayList<>();
458 +
459 + // Building mp2sp intent for H4 - VLAN2
460 + key = Key.of((PREFIX_UNICAST + "-" + DID4 + "-" + P1 + "-" + VLAN2),
461 + APPID);
462 + intents.add(buildUniIntent(key, Sets.newHashSet(C5, C6), C4, VLAN2, MAC4));
463 +
464 + // Building mp2sp intent for H5 - VLAN2
465 + key = Key.of((PREFIX_UNICAST + "-" + DID5 + "-" + P1 + "-" + VLAN2),
466 + APPID);
467 + intents.add(buildUniIntent(key, Sets.newHashSet(C4, C6), C5, VLAN2, MAC5));
468 +
469 + // Building mp2sp intent for H6 - VLAN2
470 + key = Key.of((PREFIX_UNICAST + "-" + DID6 + "-" + P1 + "-" + VLAN2),
471 + APPID);
472 + intents.add(buildUniIntent(key, Sets.newHashSet(C4, C5), C6, VLAN2, MAC6));
473 +
474 + return intents;
475 + }
476 +
477 + /**
478 + * Builds a Single Point to Multi Point intent.
479 + *
480 + * @param key The intent key
481 + * @param src The source Connect Point
482 + * @param dsts The destination Connect Points
483 + * @return Single Point to Multi Point intent generated.
484 + */
485 + private SinglePointToMultiPointIntent buildBrcIntent(Key key,
486 + ConnectPoint src,
487 + Set<ConnectPoint> dsts,
488 + VlanId vlanId) {
489 + SinglePointToMultiPointIntent intent;
490 +
491 + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
492 +
493 + TrafficSelector selector = DefaultTrafficSelector.builder()
494 + .matchEthDst(MacAddress.BROADCAST)
495 + .matchVlanId(vlanId)
496 + .build();
497 +
498 + intent = SinglePointToMultiPointIntent.builder()
499 + .appId(APPID)
500 + .key(key)
501 + .selector(selector)
502 + .treatment(treatment)
503 + .ingressPoint(src)
504 + .egressPoints(dsts)
505 + .priority(PRIORITY_OFFSET)
506 + .build();
507 + return intent;
508 + }
509 +
510 + /**
511 + * Builds a Multi Point to Single Point intent.
512 + *
513 + * @param key The intent key
514 + * @param srcs The source Connect Points
515 + * @param dst The destination Connect Point
516 + * @return Multi Point to Single Point intent generated.
517 + */
518 + private MultiPointToSinglePointIntent buildUniIntent(Key key,
519 + Set<ConnectPoint> srcs,
520 + ConnectPoint dst,
521 + VlanId vlanId,
522 + MacAddress mac) {
523 + MultiPointToSinglePointIntent intent;
524 +
525 + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
526 +
527 + TrafficSelector.Builder builder = DefaultTrafficSelector.builder()
528 + .matchEthDst(mac)
529 + .matchVlanId(vlanId);
530 +
531 + TrafficSelector selector = builder.build();
532 +
533 + intent = MultiPointToSinglePointIntent.builder()
534 + .appId(APPID)
535 + .key(key)
536 + .selector(selector)
537 + .treatment(treatment)
538 + .ingressPoints(srcs)
539 + .egressPoint(dst)
540 + .priority(PRIORITY_OFFSET)
541 + .build();
542 + return intent;
543 + }
544 +
545 + /**
546 + * Returns the device ID of the ith device.
547 + *
548 + * @param i device to get the ID of
549 + * @return the device ID
550 + */
551 + private static DeviceId getDeviceId(int i) {
552 + return DeviceId.deviceId("" + i);
553 + }
554 +
555 + private static HostLocation getLocation(int i) {
556 + return new HostLocation(new ConnectPoint(getDeviceId(i), P1), 123L);
557 + }
558 +
559 + /**
560 + * Represents a fake IntentService class that easily allows to store and
561 + * retrieve intents without implementing the IntentService logic.
562 + */
563 + private class TestIntentService extends IntentServiceAdapter {
564 +
565 + private Set<Intent> intents;
566 +
567 + public TestIntentService() {
568 + intents = Sets.newHashSet();
569 + }
570 +
571 + @Override
572 + public void submit(Intent intent) {
573 + intents.add(intent);
574 + }
575 +
576 + @Override
577 + public long getIntentCount() {
578 + return intents.size();
579 + }
580 +
581 + @Override
582 + public Iterable<Intent> getIntents() {
583 + return intents;
584 + }
585 +
586 + @Override
587 + public Intent getIntent(Key intentKey) {
588 + for (Intent intent : intents) {
589 + if (intent.key().equals(intentKey)) {
590 + return intent;
591 + }
592 + }
593 + return null;
594 + }
595 + }
596 +
597 + /**
598 + * Represents a fake HostService class which allows to add hosts manually
599 + * in each test, when needed.
600 + */
601 + private class TestHostService extends HostServiceAdapter {
602 +
603 + private Set<Host> hosts;
604 +
605 + public TestHostService(Set<Host> hosts) {
606 + this.hosts = hosts;
607 + }
608 +
609 + @Override
610 + public void addListener(HostListener listener) {
611 + VplsTest.this.hostListener = listener;
612 + }
613 +
614 + @Override
615 + public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
616 + return hosts.stream()
617 + .filter(h -> h.location().elementId().equals(connectPoint.elementId())
618 + && h.location().port().equals(connectPoint.port()))
619 + .collect(Collectors.toSet());
620 + }
621 +
622 + }
623 +
624 + private static class TestIdGenerator implements IdGenerator {
625 +
626 + private final AtomicLong id = new AtomicLong(0);
627 +
628 + @Override
629 + public long getNewId() {
630 + return id.getAndIncrement();
631 + }
632 +
633 + }
634 +
635 + /**
636 + * Test IntentSynchronizer that passes all intents straight through to the
637 + * intent service.
638 + */
639 + private class TestIntentSynchronizer implements IntentSynchronizationService,
640 + IntentSynchronizationAdminService {
641 +
642 + private final IntentService intentService;
643 +
644 + /**
645 + * Creates a new test intent synchronizer.
646 + *
647 + * @param intentService intent service
648 + */
649 + public TestIntentSynchronizer(IntentService intentService) {
650 + this.intentService = intentService;
651 + }
652 +
653 + @Override
654 + public void submit(Intent intent) {
655 + intentService.submit(intent);
656 + }
657 +
658 + @Override
659 + public void withdraw(Intent intent) {
660 + intentService.withdraw(intent);
661 + }
662 +
663 + @Override
664 + public void modifyPrimary(boolean isPrimary) {
665 +
666 + }
667 +
668 + @Override
669 + public void removeIntents() {
670 +
671 + }
672 + }
673 +
674 +}