Committed by
Gerrit Code Review
Add support for reconfiguring interfaces in SDN-IP.
Change-Id: I2ea85d85432e661c3cbdca5e5a8b16678a242369
Showing
9 changed files
with
372 additions
and
84 deletions
| ... | @@ -58,6 +58,14 @@ | ... | @@ -58,6 +58,14 @@ |
| 58 | 58 | ||
| 59 | <dependency> | 59 | <dependency> |
| 60 | <groupId>org.onosproject</groupId> | 60 | <groupId>org.onosproject</groupId> |
| 61 | + <artifactId>onos-incubator-api</artifactId> | ||
| 62 | + <version>${project.version}</version> | ||
| 63 | + <scope>test</scope> | ||
| 64 | + <classifier>tests</classifier> | ||
| 65 | + </dependency> | ||
| 66 | + | ||
| 67 | + <dependency> | ||
| 68 | + <groupId>org.onosproject</groupId> | ||
| 61 | <artifactId>onos-app-routing</artifactId> | 69 | <artifactId>onos-app-routing</artifactId> |
| 62 | <version>${project.version}</version> | 70 | <version>${project.version}</version> |
| 63 | </dependency> | 71 | </dependency> | ... | ... |
| ... | @@ -23,6 +23,8 @@ import org.onlab.packet.IpPrefix; | ... | @@ -23,6 +23,8 @@ import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.TpPort; | 23 | import org.onlab.packet.TpPort; |
| 24 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.incubator.net.intf.Interface; | 25 | import org.onosproject.incubator.net.intf.Interface; |
| 26 | +import org.onosproject.incubator.net.intf.InterfaceEvent; | ||
| 27 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 26 | import org.onosproject.incubator.net.intf.InterfaceService; | 28 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 27 | import org.onosproject.net.ConnectPoint; | 29 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.config.NetworkConfigEvent; | 30 | import org.onosproject.net.config.NetworkConfigEvent; |
| ... | @@ -44,9 +46,11 @@ import org.slf4j.LoggerFactory; | ... | @@ -44,9 +46,11 @@ import org.slf4j.LoggerFactory; |
| 44 | 46 | ||
| 45 | import java.util.ArrayList; | 47 | import java.util.ArrayList; |
| 46 | import java.util.Collection; | 48 | import java.util.Collection; |
| 49 | +import java.util.Collections; | ||
| 47 | import java.util.HashMap; | 50 | import java.util.HashMap; |
| 48 | import java.util.List; | 51 | import java.util.List; |
| 49 | import java.util.Map; | 52 | import java.util.Map; |
| 53 | +import java.util.Set; | ||
| 50 | 54 | ||
| 51 | import static com.google.common.base.Preconditions.checkNotNull; | 55 | import static com.google.common.base.Preconditions.checkNotNull; |
| 52 | 56 | ||
| ... | @@ -77,14 +81,17 @@ public class PeerConnectivityManager { | ... | @@ -77,14 +81,17 @@ public class PeerConnectivityManager { |
| 77 | private final InternalNetworkConfigListener configListener | 81 | private final InternalNetworkConfigListener configListener |
| 78 | = new InternalNetworkConfigListener(); | 82 | = new InternalNetworkConfigListener(); |
| 79 | 83 | ||
| 84 | + private final InternalInterfaceListener interfaceListener | ||
| 85 | + = new InternalInterfaceListener(); | ||
| 86 | + | ||
| 80 | /** | 87 | /** |
| 81 | * Creates a new PeerConnectivityManager. | 88 | * Creates a new PeerConnectivityManager. |
| 82 | * | 89 | * |
| 83 | * @param appId the application ID | 90 | * @param appId the application ID |
| 84 | * @param intentSynchronizer the intent synchronizer | 91 | * @param intentSynchronizer the intent synchronizer |
| 85 | - * @param configService the SDN-IP config service | 92 | + * @param configService the network config service |
| 86 | - * @param interfaceService the interface service | ||
| 87 | * @param routerAppId application ID | 93 | * @param routerAppId application ID |
| 94 | + * @param interfaceService the interface service | ||
| 88 | */ | 95 | */ |
| 89 | public PeerConnectivityManager(ApplicationId appId, | 96 | public PeerConnectivityManager(ApplicationId appId, |
| 90 | IntentSynchronizationService intentSynchronizer, | 97 | IntentSynchronizationService intentSynchronizer, |
| ... | @@ -105,6 +112,7 @@ public class PeerConnectivityManager { | ... | @@ -105,6 +112,7 @@ public class PeerConnectivityManager { |
| 105 | */ | 112 | */ |
| 106 | public void start() { | 113 | public void start() { |
| 107 | configService.addListener(configListener); | 114 | configService.addListener(configListener); |
| 115 | + interfaceService.addListener(interfaceListener); | ||
| 108 | setUpConnectivity(); | 116 | setUpConnectivity(); |
| 109 | } | 117 | } |
| 110 | 118 | ||
| ... | @@ -113,6 +121,7 @@ public class PeerConnectivityManager { | ... | @@ -113,6 +121,7 @@ public class PeerConnectivityManager { |
| 113 | */ | 121 | */ |
| 114 | public void stop() { | 122 | public void stop() { |
| 115 | configService.removeListener(configListener); | 123 | configService.removeListener(configListener); |
| 124 | + interfaceService.removeListener(interfaceListener); | ||
| 116 | } | 125 | } |
| 117 | 126 | ||
| 118 | /** | 127 | /** |
| ... | @@ -122,14 +131,18 @@ public class PeerConnectivityManager { | ... | @@ -122,14 +131,18 @@ public class PeerConnectivityManager { |
| 122 | private void setUpConnectivity() { | 131 | private void setUpConnectivity() { |
| 123 | BgpConfig config = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS); | 132 | BgpConfig config = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS); |
| 124 | 133 | ||
| 134 | + Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers; | ||
| 135 | + | ||
| 125 | if (config == null) { | 136 | if (config == null) { |
| 126 | - log.warn("No BgpConfig found"); | 137 | + log.warn("No BGP config available"); |
| 127 | - return; | 138 | + bgpSpeakers = Collections.emptySet(); |
| 139 | + } else { | ||
| 140 | + bgpSpeakers = config.bgpSpeakers(); | ||
| 128 | } | 141 | } |
| 129 | 142 | ||
| 130 | Map<Key, PointToPointIntent> existingIntents = new HashMap<>(peerIntents); | 143 | Map<Key, PointToPointIntent> existingIntents = new HashMap<>(peerIntents); |
| 131 | 144 | ||
| 132 | - for (BgpConfig.BgpSpeakerConfig bgpSpeaker : config.bgpSpeakers()) { | 145 | + for (BgpConfig.BgpSpeakerConfig bgpSpeaker : bgpSpeakers) { |
| 133 | log.debug("Start to set up BGP paths for BGP speaker: {}", | 146 | log.debug("Start to set up BGP paths for BGP speaker: {}", |
| 134 | bgpSpeaker); | 147 | bgpSpeaker); |
| 135 | 148 | ||
| ... | @@ -409,4 +422,19 @@ public class PeerConnectivityManager { | ... | @@ -409,4 +422,19 @@ public class PeerConnectivityManager { |
| 409 | } | 422 | } |
| 410 | } | 423 | } |
| 411 | 424 | ||
| 425 | + private class InternalInterfaceListener implements InterfaceListener { | ||
| 426 | + @Override | ||
| 427 | + public void event(InterfaceEvent event) { | ||
| 428 | + switch (event.type()) { | ||
| 429 | + case INTERFACE_ADDED: | ||
| 430 | + case INTERFACE_UPDATED: | ||
| 431 | + case INTERFACE_REMOVED: | ||
| 432 | + setUpConnectivity(); | ||
| 433 | + break; | ||
| 434 | + default: | ||
| 435 | + break; | ||
| 436 | + } | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + | ||
| 412 | } | 440 | } | ... | ... |
| ... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
| 17 | package org.onosproject.sdnip; | 17 | package org.onosproject.sdnip; |
| 18 | 18 | ||
| 19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.common.collect.Sets; | ||
| 20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -30,6 +31,8 @@ import org.onlab.packet.VlanId; | ... | @@ -30,6 +31,8 @@ import org.onlab.packet.VlanId; |
| 30 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; | 32 | import org.onosproject.core.CoreService; |
| 32 | import org.onosproject.incubator.net.intf.Interface; | 33 | import org.onosproject.incubator.net.intf.Interface; |
| 34 | +import org.onosproject.incubator.net.intf.InterfaceEvent; | ||
| 35 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 33 | import org.onosproject.incubator.net.intf.InterfaceService; | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 34 | import org.onosproject.net.ConnectPoint; | 37 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; | 38 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| ... | @@ -75,6 +78,7 @@ public class SdnIpFib { | ... | @@ -75,6 +78,7 @@ public class SdnIpFib { |
| 75 | protected RoutingService routingService; | 78 | protected RoutingService routingService; |
| 76 | 79 | ||
| 77 | private final InternalFibListener fibListener = new InternalFibListener(); | 80 | private final InternalFibListener fibListener = new InternalFibListener(); |
| 81 | + private final InternalInterfaceListener interfaceListener = new InternalInterfaceListener(); | ||
| 78 | 82 | ||
| 79 | private static final int PRIORITY_OFFSET = 100; | 83 | private static final int PRIORITY_OFFSET = 100; |
| 80 | private static final int PRIORITY_MULTIPLIER = 5; | 84 | private static final int PRIORITY_MULTIPLIER = 5; |
| ... | @@ -90,12 +94,15 @@ public class SdnIpFib { | ... | @@ -90,12 +94,15 @@ public class SdnIpFib { |
| 90 | public void activate() { | 94 | public void activate() { |
| 91 | appId = coreService.getAppId(SdnIp.SDN_IP_APP); | 95 | appId = coreService.getAppId(SdnIp.SDN_IP_APP); |
| 92 | 96 | ||
| 97 | + interfaceService.addListener(interfaceListener); | ||
| 98 | + | ||
| 93 | routingService.addFibListener(fibListener); | 99 | routingService.addFibListener(fibListener); |
| 94 | routingService.start(); | 100 | routingService.start(); |
| 95 | } | 101 | } |
| 96 | 102 | ||
| 97 | @Deactivate | 103 | @Deactivate |
| 98 | public void deactivate() { | 104 | public void deactivate() { |
| 105 | + interfaceService.removeListener(interfaceListener); | ||
| 99 | // TODO remove listener | 106 | // TODO remove listener |
| 100 | routingService.stop(); | 107 | routingService.stop(); |
| 101 | } | 108 | } |
| ... | @@ -240,6 +247,51 @@ public class SdnIpFib { | ... | @@ -240,6 +247,51 @@ public class SdnIpFib { |
| 240 | .build(); | 247 | .build(); |
| 241 | } | 248 | } |
| 242 | 249 | ||
| 250 | + private void updateInterface(Interface intf) { | ||
| 251 | + synchronized (this) { | ||
| 252 | + for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { | ||
| 253 | + MultiPointToSinglePointIntent intent = entry.getValue(); | ||
| 254 | + Set<ConnectPoint> ingress = Sets.newHashSet(intent.ingressPoints()); | ||
| 255 | + ingress.add(intf.connectPoint()); | ||
| 256 | + | ||
| 257 | + MultiPointToSinglePointIntent newIntent = | ||
| 258 | + MultiPointToSinglePointIntent.builder(intent) | ||
| 259 | + .ingressPoints(ingress) | ||
| 260 | + .build(); | ||
| 261 | + | ||
| 262 | + routeIntents.put(entry.getKey(), newIntent); | ||
| 263 | + intentSynchronizer.submit(newIntent); | ||
| 264 | + } | ||
| 265 | + } | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + private void removeInterface(Interface intf) { | ||
| 269 | + synchronized (this) { | ||
| 270 | + for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { | ||
| 271 | + MultiPointToSinglePointIntent intent = entry.getValue(); | ||
| 272 | + if (intent.egressPoint().equals(intf.connectPoint())) { | ||
| 273 | + // This intent just lost its head. Remove it and let | ||
| 274 | + // higher layer routing reroute. | ||
| 275 | + intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); | ||
| 276 | + } else { | ||
| 277 | + if (intent.ingressPoints().contains(intf.connectPoint())) { | ||
| 278 | + | ||
| 279 | + Set<ConnectPoint> ingress = Sets.newHashSet(intent.ingressPoints()); | ||
| 280 | + ingress.remove(intf.connectPoint()); | ||
| 281 | + | ||
| 282 | + MultiPointToSinglePointIntent newIntent = | ||
| 283 | + MultiPointToSinglePointIntent.builder(intent) | ||
| 284 | + .ingressPoints(ingress) | ||
| 285 | + .build(); | ||
| 286 | + | ||
| 287 | + routeIntents.put(entry.getKey(), newIntent); | ||
| 288 | + intentSynchronizer.submit(newIntent); | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + } | ||
| 294 | + | ||
| 243 | private class InternalFibListener implements FibListener { | 295 | private class InternalFibListener implements FibListener { |
| 244 | @Override | 296 | @Override |
| 245 | public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { | 297 | public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { |
| ... | @@ -247,4 +299,23 @@ public class SdnIpFib { | ... | @@ -247,4 +299,23 @@ public class SdnIpFib { |
| 247 | } | 299 | } |
| 248 | } | 300 | } |
| 249 | 301 | ||
| 302 | + private class InternalInterfaceListener implements InterfaceListener { | ||
| 303 | + | ||
| 304 | + @Override | ||
| 305 | + public void event(InterfaceEvent event) { | ||
| 306 | + switch (event.type()) { | ||
| 307 | + case INTERFACE_ADDED: | ||
| 308 | + updateInterface(event.subject()); | ||
| 309 | + break; | ||
| 310 | + case INTERFACE_UPDATED: | ||
| 311 | + break; | ||
| 312 | + case INTERFACE_REMOVED: | ||
| 313 | + removeInterface(event.subject()); | ||
| 314 | + break; | ||
| 315 | + default: | ||
| 316 | + break; | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + } | ||
| 320 | + | ||
| 250 | } | 321 | } | ... | ... |
| ... | @@ -17,7 +17,6 @@ package org.onosproject.sdnip; | ... | @@ -17,7 +17,6 @@ package org.onosproject.sdnip; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.Sets; | 18 | import com.google.common.collect.Sets; |
| 19 | import org.junit.Before; | 19 | import org.junit.Before; |
| 20 | -import org.junit.Ignore; | ||
| 21 | import org.junit.Test; | 20 | import org.junit.Test; |
| 22 | import org.onlab.junit.TestUtils.TestUtilsException; | 21 | import org.onlab.junit.TestUtils.TestUtilsException; |
| 23 | import org.onlab.packet.Ethernet; | 22 | import org.onlab.packet.Ethernet; |
| ... | @@ -30,6 +29,7 @@ import org.onlab.packet.VlanId; | ... | @@ -30,6 +29,7 @@ import org.onlab.packet.VlanId; |
| 30 | import org.onosproject.TestApplicationId; | 29 | import org.onosproject.TestApplicationId; |
| 31 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.incubator.net.intf.Interface; | 31 | import org.onosproject.incubator.net.intf.Interface; |
| 32 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 33 | import org.onosproject.incubator.net.intf.InterfaceService; | 33 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 34 | import org.onosproject.net.ConnectPoint; | 34 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
| ... | @@ -48,14 +48,10 @@ import org.onosproject.net.intent.PointToPointIntent; | ... | @@ -48,14 +48,10 @@ import org.onosproject.net.intent.PointToPointIntent; |
| 48 | import org.onosproject.routing.IntentSynchronizationService; | 48 | import org.onosproject.routing.IntentSynchronizationService; |
| 49 | import org.onosproject.routing.config.BgpConfig; | 49 | import org.onosproject.routing.config.BgpConfig; |
| 50 | import org.onosproject.routing.config.BgpPeer; | 50 | import org.onosproject.routing.config.BgpPeer; |
| 51 | -import org.onosproject.routing.config.BgpSpeaker; | ||
| 52 | -import org.onosproject.routing.config.InterfaceAddress; | ||
| 53 | -import org.onosproject.routing.config.RoutingConfigurationService; | ||
| 54 | 51 | ||
| 55 | import java.util.ArrayList; | 52 | import java.util.ArrayList; |
| 56 | import java.util.Collections; | 53 | import java.util.Collections; |
| 57 | import java.util.HashMap; | 54 | import java.util.HashMap; |
| 58 | -import java.util.LinkedList; | ||
| 59 | import java.util.List; | 55 | import java.util.List; |
| 60 | import java.util.Map; | 56 | import java.util.Map; |
| 61 | import java.util.Optional; | 57 | import java.util.Optional; |
| ... | @@ -81,7 +77,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -81,7 +77,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 81 | 77 | ||
| 82 | private PeerConnectivityManager peerConnectivityManager; | 78 | private PeerConnectivityManager peerConnectivityManager; |
| 83 | private IntentSynchronizationService intentSynchronizer; | 79 | private IntentSynchronizationService intentSynchronizer; |
| 84 | - private RoutingConfigurationService routingConfig; | ||
| 85 | private InterfaceService interfaceService; | 80 | private InterfaceService interfaceService; |
| 86 | private NetworkConfigService networkConfigService; | 81 | private NetworkConfigService networkConfigService; |
| 87 | 82 | ||
| ... | @@ -104,8 +99,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -104,8 +99,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 104 | // Interfaces connected to BGP speakers | 99 | // Interfaces connected to BGP speakers |
| 105 | private final ConnectPoint s1Eth100 = | 100 | private final ConnectPoint s1Eth100 = |
| 106 | new ConnectPoint(deviceId1, PortNumber.portNumber(100)); | 101 | new ConnectPoint(deviceId1, PortNumber.portNumber(100)); |
| 107 | - private final ConnectPoint s2Eth100 = | ||
| 108 | - new ConnectPoint(deviceId2, PortNumber.portNumber(100)); | ||
| 109 | 102 | ||
| 110 | // Interfaces connected to BGP peers | 103 | // Interfaces connected to BGP peers |
| 111 | private final ConnectPoint s1Eth1 = | 104 | private final ConnectPoint s1Eth1 = |
| ... | @@ -119,8 +112,10 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -119,8 +112,10 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 119 | @Before | 112 | @Before |
| 120 | public void setUp() throws Exception { | 113 | public void setUp() throws Exception { |
| 121 | super.setUp(); | 114 | super.setUp(); |
| 122 | - routingConfig = createMock(RoutingConfigurationService.class); | 115 | + |
| 123 | interfaceService = createMock(InterfaceService.class); | 116 | interfaceService = createMock(InterfaceService.class); |
| 117 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 118 | + expectLastCall().anyTimes(); | ||
| 124 | networkConfigService = createMock(NetworkConfigService.class); | 119 | networkConfigService = createMock(NetworkConfigService.class); |
| 125 | networkConfigService.addListener(anyObject(NetworkConfigListener.class)); | 120 | networkConfigService.addListener(anyObject(NetworkConfigListener.class)); |
| 126 | expectLastCall().anyTimes(); | 121 | expectLastCall().anyTimes(); |
| ... | @@ -172,7 +167,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -172,7 +167,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 172 | InterfaceIpAddress ia1 = | 167 | InterfaceIpAddress ia1 = |
| 173 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), | 168 | new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), |
| 174 | IpPrefix.valueOf("192.168.10.0/24")); | 169 | IpPrefix.valueOf("192.168.10.0/24")); |
| 175 | - Interface intfsw1eth1 = new Interface(s1Eth1, | 170 | + Interface intfsw1eth1 = new Interface(interfaceSw1Eth1, s1Eth1, |
| 176 | Collections.singletonList(ia1), | 171 | Collections.singletonList(ia1), |
| 177 | MacAddress.valueOf("00:00:00:00:00:01"), | 172 | MacAddress.valueOf("00:00:00:00:00:01"), |
| 178 | VlanId.NONE); | 173 | VlanId.NONE); |
| ... | @@ -182,7 +177,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -182,7 +177,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 182 | InterfaceIpAddress ia2 = | 177 | InterfaceIpAddress ia2 = |
| 183 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), | 178 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
| 184 | IpPrefix.valueOf("192.168.20.0/24")); | 179 | IpPrefix.valueOf("192.168.20.0/24")); |
| 185 | - Interface intfsw2eth1 = new Interface(s2Eth1, | 180 | + Interface intfsw2eth1 = new Interface(interfaceSw2Eth1, s2Eth1, |
| 186 | Collections.singletonList(ia2), | 181 | Collections.singletonList(ia2), |
| 187 | MacAddress.valueOf("00:00:00:00:00:02"), | 182 | MacAddress.valueOf("00:00:00:00:00:02"), |
| 188 | VlanId.NONE); | 183 | VlanId.NONE); |
| ... | @@ -192,7 +187,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -192,7 +187,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 192 | InterfaceIpAddress ia3 = | 187 | InterfaceIpAddress ia3 = |
| 193 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), | 188 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
| 194 | IpPrefix.valueOf("192.168.30.0/24")); | 189 | IpPrefix.valueOf("192.168.30.0/24")); |
| 195 | - Interface intfsw2eth1intf2 = new Interface(s2Eth1, | 190 | + Interface intfsw2eth1intf2 = new Interface(interfaceSw2Eth1intf2, s2Eth1, |
| 196 | Collections.singletonList(ia3), | 191 | Collections.singletonList(ia3), |
| 197 | MacAddress.valueOf("00:00:00:00:00:03"), | 192 | MacAddress.valueOf("00:00:00:00:00:03"), |
| 198 | VlanId.NONE); | 193 | VlanId.NONE); |
| ... | @@ -430,13 +425,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -430,13 +425,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 430 | * @throws TestUtilsException if exceptions when using TestUtils | 425 | * @throws TestUtilsException if exceptions when using TestUtils |
| 431 | */ | 426 | */ |
| 432 | private void initPeerConnectivity() throws TestUtilsException { | 427 | private void initPeerConnectivity() throws TestUtilsException { |
| 433 | - expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | ||
| 434 | expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); | 428 | expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
| 435 | replay(bgpConfig); | 429 | replay(bgpConfig); |
| 436 | expect(networkConfigService.getConfig(APPID, BgpConfig.class)) | 430 | expect(networkConfigService.getConfig(APPID, BgpConfig.class)) |
| 437 | .andReturn(bgpConfig).anyTimes(); | 431 | .andReturn(bgpConfig).anyTimes(); |
| 438 | replay(networkConfigService); | 432 | replay(networkConfigService); |
| 439 | - replay(routingConfig); | ||
| 440 | replay(interfaceService); | 433 | replay(interfaceService); |
| 441 | 434 | ||
| 442 | intentSynchronizer = createMock(IntentSynchronizationService.class); | 435 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
| ... | @@ -478,6 +471,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -478,6 +471,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 478 | @Test | 471 | @Test |
| 479 | public void testNullInterfaces() { | 472 | public void testNullInterfaces() { |
| 480 | reset(interfaceService); | 473 | reset(interfaceService); |
| 474 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 475 | + expectLastCall().anyTimes(); | ||
| 481 | 476 | ||
| 482 | expect(interfaceService.getInterfaces()).andReturn( | 477 | expect(interfaceService.getInterfaces()).andReturn( |
| 483 | Sets.newHashSet()).anyTimes(); | 478 | Sets.newHashSet()).anyTimes(); |
| ... | @@ -511,13 +506,9 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -511,13 +506,9 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 511 | */ | 506 | */ |
| 512 | @Test | 507 | @Test |
| 513 | public void testNullBgpSpeakers() { | 508 | public void testNullBgpSpeakers() { |
| 514 | - reset(routingConfig); | ||
| 515 | reset(bgpConfig); | 509 | reset(bgpConfig); |
| 516 | - | ||
| 517 | expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes(); | 510 | expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes(); |
| 518 | replay(bgpConfig); | 511 | replay(bgpConfig); |
| 519 | - expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | ||
| 520 | - replay(routingConfig); | ||
| 521 | 512 | ||
| 522 | reset(intentSynchronizer); | 513 | reset(intentSynchronizer); |
| 523 | replay(intentSynchronizer); | 514 | replay(intentSynchronizer); |
| ... | @@ -537,21 +528,4 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -537,21 +528,4 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 537 | testConnectionSetup(); | 528 | testConnectionSetup(); |
| 538 | } | 529 | } |
| 539 | 530 | ||
| 540 | - /** | ||
| 541 | - * Tests a corner case, when there is no Interface configured for one BGP | ||
| 542 | - * speaker. | ||
| 543 | - */ | ||
| 544 | - @Ignore | ||
| 545 | - @Test | ||
| 546 | - public void testNoSpeakerInterface() { | ||
| 547 | - BgpSpeaker bgpSpeaker100 = new BgpSpeaker( | ||
| 548 | - "bgpSpeaker100", | ||
| 549 | - "00:00:00:00:00:00:01:00", 100, | ||
| 550 | - "00:00:00:00:01:00"); | ||
| 551 | - List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>(); | ||
| 552 | - interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201")); | ||
| 553 | - interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201")); | ||
| 554 | - bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100); | ||
| 555 | - testConnectionSetup(); | ||
| 556 | - } | ||
| 557 | } | 531 | } | ... | ... |
| ... | @@ -31,7 +31,10 @@ import org.onosproject.TestApplicationId; | ... | @@ -31,7 +31,10 @@ import org.onosproject.TestApplicationId; |
| 31 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreServiceAdapter; | 32 | import org.onosproject.core.CoreServiceAdapter; |
| 33 | import org.onosproject.incubator.net.intf.Interface; | 33 | import org.onosproject.incubator.net.intf.Interface; |
| 34 | +import org.onosproject.incubator.net.intf.InterfaceEvent; | ||
| 35 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 34 | import org.onosproject.incubator.net.intf.InterfaceService; | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 37 | +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
| 35 | import org.onosproject.net.ConnectPoint; | 38 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DeviceId; | 39 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.PortNumber; | 40 | import org.onosproject.net.PortNumber; |
| ... | @@ -48,18 +51,16 @@ import org.onosproject.routing.FibListener; | ... | @@ -48,18 +51,16 @@ import org.onosproject.routing.FibListener; |
| 48 | import org.onosproject.routing.FibUpdate; | 51 | import org.onosproject.routing.FibUpdate; |
| 49 | import org.onosproject.routing.IntentSynchronizationService; | 52 | import org.onosproject.routing.IntentSynchronizationService; |
| 50 | import org.onosproject.routing.RoutingServiceAdapter; | 53 | import org.onosproject.routing.RoutingServiceAdapter; |
| 51 | -import org.onosproject.routing.config.BgpPeer; | ||
| 52 | -import org.onosproject.routing.config.RoutingConfigurationService; | ||
| 53 | 54 | ||
| 54 | import java.util.Collections; | 55 | import java.util.Collections; |
| 55 | -import java.util.HashMap; | ||
| 56 | import java.util.HashSet; | 56 | import java.util.HashSet; |
| 57 | import java.util.List; | 57 | import java.util.List; |
| 58 | -import java.util.Map; | ||
| 59 | import java.util.Set; | 58 | import java.util.Set; |
| 60 | 59 | ||
| 60 | +import static org.easymock.EasyMock.anyObject; | ||
| 61 | import static org.easymock.EasyMock.createMock; | 61 | import static org.easymock.EasyMock.createMock; |
| 62 | import static org.easymock.EasyMock.expect; | 62 | import static org.easymock.EasyMock.expect; |
| 63 | +import static org.easymock.EasyMock.expectLastCall; | ||
| 63 | import static org.easymock.EasyMock.replay; | 64 | import static org.easymock.EasyMock.replay; |
| 64 | import static org.easymock.EasyMock.reset; | 65 | import static org.easymock.EasyMock.reset; |
| 65 | import static org.easymock.EasyMock.verify; | 66 | import static org.easymock.EasyMock.verify; |
| ... | @@ -70,7 +71,6 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ... | @@ -70,7 +71,6 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
| 70 | */ | 71 | */ |
| 71 | public class SdnIpFibTest extends AbstractIntentTest { | 72 | public class SdnIpFibTest extends AbstractIntentTest { |
| 72 | 73 | ||
| 73 | - private RoutingConfigurationService routingConfig; | ||
| 74 | private InterfaceService interfaceService; | 74 | private InterfaceService interfaceService; |
| 75 | 75 | ||
| 76 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | 76 | private static final ConnectPoint SW1_ETH1 = new ConnectPoint( |
| ... | @@ -89,6 +89,10 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -89,6 +89,10 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 89 | DeviceId.deviceId("of:0000000000000004"), | 89 | DeviceId.deviceId("of:0000000000000004"), |
| 90 | PortNumber.portNumber(1)); | 90 | PortNumber.portNumber(1)); |
| 91 | 91 | ||
| 92 | + private static final ConnectPoint SW5_ETH1 = new ConnectPoint( | ||
| 93 | + DeviceId.deviceId("of:0000000000000005"), | ||
| 94 | + PortNumber.portNumber(1)); | ||
| 95 | + | ||
| 92 | private SdnIpFib sdnipFib; | 96 | private SdnIpFib sdnipFib; |
| 93 | private IntentSynchronizationService intentSynchronizer; | 97 | private IntentSynchronizationService intentSynchronizer; |
| 94 | private final Set<Interface> interfaces = Sets.newHashSet(); | 98 | private final Set<Interface> interfaces = Sets.newHashSet(); |
| ... | @@ -96,19 +100,19 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -96,19 +100,19 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 96 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | 100 | private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); |
| 97 | 101 | ||
| 98 | private FibListener fibListener; | 102 | private FibListener fibListener; |
| 103 | + private InterfaceListener interfaceListener; | ||
| 99 | 104 | ||
| 100 | @Before | 105 | @Before |
| 101 | public void setUp() throws Exception { | 106 | public void setUp() throws Exception { |
| 102 | super.setUp(); | 107 | super.setUp(); |
| 103 | 108 | ||
| 104 | - routingConfig = createMock(RoutingConfigurationService.class); | ||
| 105 | interfaceService = createMock(InterfaceService.class); | 109 | interfaceService = createMock(InterfaceService.class); |
| 110 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 111 | + expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
| 106 | 112 | ||
| 107 | // These will set expectations on routingConfig and interfaceService | 113 | // These will set expectations on routingConfig and interfaceService |
| 108 | setUpInterfaceService(); | 114 | setUpInterfaceService(); |
| 109 | - setUpBgpPeers(); | ||
| 110 | 115 | ||
| 111 | - replay(routingConfig); | ||
| 112 | replay(interfaceService); | 116 | replay(interfaceService); |
| 113 | 117 | ||
| 114 | intentSynchronizer = createMock(IntentSynchronizationService.class); | 118 | intentSynchronizer = createMock(IntentSynchronizationService.class); |
| ... | @@ -123,33 +127,6 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -123,33 +127,6 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 123 | } | 127 | } |
| 124 | 128 | ||
| 125 | /** | 129 | /** |
| 126 | - * Sets up BGP peers in external networks. | ||
| 127 | - */ | ||
| 128 | - private void setUpBgpPeers() { | ||
| 129 | - | ||
| 130 | - Map<IpAddress, BgpPeer> peers = new HashMap<>(); | ||
| 131 | - | ||
| 132 | - String peerSw1Eth1 = "192.168.10.1"; | ||
| 133 | - peers.put(IpAddress.valueOf(peerSw1Eth1), | ||
| 134 | - new BgpPeer("00:00:00:00:00:00:00:01", 1, peerSw1Eth1)); | ||
| 135 | - | ||
| 136 | - // Two BGP peers are connected to switch 2 port 1. | ||
| 137 | - String peer1Sw2Eth1 = "192.168.20.1"; | ||
| 138 | - peers.put(IpAddress.valueOf(peer1Sw2Eth1), | ||
| 139 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer1Sw2Eth1)); | ||
| 140 | - | ||
| 141 | - String peer2Sw2Eth1 = "192.168.20.2"; | ||
| 142 | - peers.put(IpAddress.valueOf(peer2Sw2Eth1), | ||
| 143 | - new BgpPeer("00:00:00:00:00:00:00:02", 1, peer2Sw2Eth1)); | ||
| 144 | - | ||
| 145 | - String peer1Sw4Eth1 = "192.168.40.1"; | ||
| 146 | - peers.put(IpAddress.valueOf(peer1Sw4Eth1), | ||
| 147 | - new BgpPeer("00:00:00:00:00:00:00:04", 1, peer1Sw4Eth1)); | ||
| 148 | - | ||
| 149 | - expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - /** | ||
| 153 | * Sets up InterfaceService. | 130 | * Sets up InterfaceService. |
| 154 | */ | 131 | */ |
| 155 | private void setUpInterfaceService() { | 132 | private void setUpInterfaceService() { |
| ... | @@ -157,7 +134,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -157,7 +134,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 157 | interfaceIpAddresses1.add(new InterfaceIpAddress( | 134 | interfaceIpAddresses1.add(new InterfaceIpAddress( |
| 158 | IpAddress.valueOf("192.168.10.101"), | 135 | IpAddress.valueOf("192.168.10.101"), |
| 159 | IpPrefix.valueOf("192.168.10.0/24"))); | 136 | IpPrefix.valueOf("192.168.10.0/24"))); |
| 160 | - Interface sw1Eth1 = new Interface(SW1_ETH1, | 137 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, |
| 161 | interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | 138 | interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), |
| 162 | VlanId.NONE); | 139 | VlanId.NONE); |
| 163 | interfaces.add(sw1Eth1); | 140 | interfaces.add(sw1Eth1); |
| ... | @@ -166,7 +143,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -166,7 +143,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 166 | interfaceIpAddresses2.add( | 143 | interfaceIpAddresses2.add( |
| 167 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), | 144 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
| 168 | IpPrefix.valueOf("192.168.20.0/24"))); | 145 | IpPrefix.valueOf("192.168.20.0/24"))); |
| 169 | - Interface sw2Eth1 = new Interface(SW2_ETH1, | 146 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, |
| 170 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | 147 | interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), |
| 171 | VlanId.NONE); | 148 | VlanId.NONE); |
| 172 | interfaces.add(sw2Eth1); | 149 | interfaces.add(sw2Eth1); |
| ... | @@ -175,7 +152,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -175,7 +152,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 175 | interfaceIpAddresses3.add( | 152 | interfaceIpAddresses3.add( |
| 176 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), | 153 | new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), |
| 177 | IpPrefix.valueOf("192.168.30.0/24"))); | 154 | IpPrefix.valueOf("192.168.30.0/24"))); |
| 178 | - Interface sw3Eth1 = new Interface(SW3_ETH1, | 155 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, |
| 179 | interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), | 156 | interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"), |
| 180 | VlanId.NONE); | 157 | VlanId.NONE); |
| 181 | interfaces.add(sw3Eth1); | 158 | interfaces.add(sw3Eth1); |
| ... | @@ -183,7 +160,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -183,7 +160,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 183 | InterfaceIpAddress interfaceIpAddress4 = | 160 | InterfaceIpAddress interfaceIpAddress4 = |
| 184 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), | 161 | new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), |
| 185 | IpPrefix.valueOf("192.168.40.0/24")); | 162 | IpPrefix.valueOf("192.168.40.0/24")); |
| 186 | - Interface sw4Eth1 = new Interface(SW4_ETH1, | 163 | + Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1, |
| 187 | Lists.newArrayList(interfaceIpAddress4), | 164 | Lists.newArrayList(interfaceIpAddress4), |
| 188 | MacAddress.valueOf("00:00:00:00:00:04"), | 165 | MacAddress.valueOf("00:00:00:00:00:04"), |
| 189 | VlanId.vlanId((short) 1)); | 166 | VlanId.vlanId((short) 1)); |
| ... | @@ -428,6 +405,100 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -428,6 +405,100 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 428 | verify(intentSynchronizer); | 405 | verify(intentSynchronizer); |
| 429 | } | 406 | } |
| 430 | 407 | ||
| 408 | + @Test | ||
| 409 | + public void testAddInterface() { | ||
| 410 | + testFibAdd(); | ||
| 411 | + | ||
| 412 | + IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 413 | + | ||
| 414 | + // Construct the existing MultiPointToSinglePoint intent | ||
| 415 | + TrafficSelector.Builder selectorBuilder = | ||
| 416 | + DefaultTrafficSelector.builder(); | ||
| 417 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix); | ||
| 418 | + | ||
| 419 | + TrafficTreatment.Builder treatmentBuilder = | ||
| 420 | + DefaultTrafficTreatment.builder(); | ||
| 421 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | ||
| 422 | + | ||
| 423 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 424 | + ingressPoints.add(SW2_ETH1); | ||
| 425 | + ingressPoints.add(SW3_ETH1); | ||
| 426 | + ingressPoints.add(SW4_ETH1); | ||
| 427 | + ingressPoints.add(SW5_ETH1); | ||
| 428 | + | ||
| 429 | + MultiPointToSinglePointIntent addedIntent = | ||
| 430 | + MultiPointToSinglePointIntent.builder() | ||
| 431 | + .appId(APPID) | ||
| 432 | + .key(Key.of(prefix.toString(), APPID)) | ||
| 433 | + .selector(selectorBuilder.build()) | ||
| 434 | + .treatment(treatmentBuilder.build()) | ||
| 435 | + .ingressPoints(ingressPoints) | ||
| 436 | + .egressPoint(SW1_ETH1) | ||
| 437 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
| 438 | + .build(); | ||
| 439 | + | ||
| 440 | + reset(intentSynchronizer); | ||
| 441 | + | ||
| 442 | + intentSynchronizer.submit(eqExceptId(addedIntent)); | ||
| 443 | + expectLastCall().once(); | ||
| 444 | + | ||
| 445 | + replay(intentSynchronizer); | ||
| 446 | + | ||
| 447 | + Interface intf = new Interface("newintf", SW5_ETH1, | ||
| 448 | + Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")), | ||
| 449 | + MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE); | ||
| 450 | + InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); | ||
| 451 | + interfaceListener.event(intfEvent); | ||
| 452 | + | ||
| 453 | + verify(intentSynchronizer); | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + @Test | ||
| 457 | + public void testRemoveInterface() { | ||
| 458 | + testFibAdd(); | ||
| 459 | + | ||
| 460 | + IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 461 | + | ||
| 462 | + // Construct the existing MultiPointToSinglePoint intent | ||
| 463 | + TrafficSelector.Builder selectorBuilder = | ||
| 464 | + DefaultTrafficSelector.builder(); | ||
| 465 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(prefix); | ||
| 466 | + | ||
| 467 | + TrafficTreatment.Builder treatmentBuilder = | ||
| 468 | + DefaultTrafficTreatment.builder(); | ||
| 469 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | ||
| 470 | + | ||
| 471 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 472 | + ingressPoints.add(SW2_ETH1); | ||
| 473 | + ingressPoints.add(SW3_ETH1); | ||
| 474 | + | ||
| 475 | + MultiPointToSinglePointIntent addedIntent = | ||
| 476 | + MultiPointToSinglePointIntent.builder() | ||
| 477 | + .appId(APPID) | ||
| 478 | + .key(Key.of(prefix.toString(), APPID)) | ||
| 479 | + .selector(selectorBuilder.build()) | ||
| 480 | + .treatment(treatmentBuilder.build()) | ||
| 481 | + .ingressPoints(ingressPoints) | ||
| 482 | + .egressPoint(SW1_ETH1) | ||
| 483 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
| 484 | + .build(); | ||
| 485 | + | ||
| 486 | + reset(intentSynchronizer); | ||
| 487 | + | ||
| 488 | + intentSynchronizer.submit(eqExceptId(addedIntent)); | ||
| 489 | + expectLastCall().once(); | ||
| 490 | + | ||
| 491 | + replay(intentSynchronizer); | ||
| 492 | + | ||
| 493 | + Interface intf = new Interface("newintf", SW4_ETH1, | ||
| 494 | + Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")), | ||
| 495 | + MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE); | ||
| 496 | + InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); | ||
| 497 | + interfaceListener.event(intfEvent); | ||
| 498 | + | ||
| 499 | + verify(intentSynchronizer); | ||
| 500 | + } | ||
| 501 | + | ||
| 431 | private class TestCoreService extends CoreServiceAdapter { | 502 | private class TestCoreService extends CoreServiceAdapter { |
| 432 | @Override | 503 | @Override |
| 433 | public ApplicationId getAppId(String name) { | 504 | public ApplicationId getAppId(String name) { |
| ... | @@ -442,4 +513,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -442,4 +513,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
| 442 | SdnIpFibTest.this.fibListener = fibListener; | 513 | SdnIpFibTest.this.fibListener = fibListener; |
| 443 | } | 514 | } |
| 444 | } | 515 | } |
| 516 | + | ||
| 517 | + private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
| 518 | + | ||
| 519 | + @Override | ||
| 520 | + public void addListener(InterfaceListener listener) { | ||
| 521 | + SdnIpFibTest.this.interfaceListener = listener; | ||
| 522 | + } | ||
| 523 | + } | ||
| 445 | } | 524 | } | ... | ... |
| ... | @@ -96,6 +96,26 @@ public abstract class ConnectivityIntent extends Intent { | ... | @@ -96,6 +96,26 @@ public abstract class ConnectivityIntent extends Intent { |
| 96 | protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | 96 | protected TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
| 97 | protected List<Constraint> constraints = ImmutableList.of(); | 97 | protected List<Constraint> constraints = ImmutableList.of(); |
| 98 | 98 | ||
| 99 | + /** | ||
| 100 | + * Creates a new empty builder. | ||
| 101 | + */ | ||
| 102 | + protected Builder() { | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * Creates a new builder pre-populated with the information in the given | ||
| 107 | + * intent. | ||
| 108 | + * | ||
| 109 | + * @param intent initial intent | ||
| 110 | + */ | ||
| 111 | + protected Builder(ConnectivityIntent intent) { | ||
| 112 | + super(intent); | ||
| 113 | + | ||
| 114 | + this.selector(intent.selector()) | ||
| 115 | + .treatment(intent.treatment()) | ||
| 116 | + .constraints(intent.constraints()); | ||
| 117 | + } | ||
| 118 | + | ||
| 99 | @Override | 119 | @Override |
| 100 | public Builder appId(ApplicationId appId) { | 120 | public Builder appId(ApplicationId appId) { |
| 101 | return (Builder) super.appId(appId); | 121 | return (Builder) super.appId(appId); |
| ... | @@ -111,7 +131,6 @@ public abstract class ConnectivityIntent extends Intent { | ... | @@ -111,7 +131,6 @@ public abstract class ConnectivityIntent extends Intent { |
| 111 | return (Builder) super.priority(priority); | 131 | return (Builder) super.priority(priority); |
| 112 | } | 132 | } |
| 113 | 133 | ||
| 114 | - | ||
| 115 | /** | 134 | /** |
| 116 | * Sets the traffic selector for the intent that will be built. | 135 | * Sets the traffic selector for the intent that will be built. |
| 117 | * | 136 | * |
| ... | @@ -146,7 +165,6 @@ public abstract class ConnectivityIntent extends Intent { | ... | @@ -146,7 +165,6 @@ public abstract class ConnectivityIntent extends Intent { |
| 146 | } | 165 | } |
| 147 | } | 166 | } |
| 148 | 167 | ||
| 149 | - | ||
| 150 | /** | 168 | /** |
| 151 | * Returns the match specifying the type of traffic. | 169 | * Returns the match specifying the type of traffic. |
| 152 | * | 170 | * | ... | ... |
| ... | @@ -15,14 +15,14 @@ | ... | @@ -15,14 +15,14 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
| 17 | 17 | ||
| 18 | -import java.util.Collection; | ||
| 19 | -import java.util.Objects; | ||
| 20 | - | ||
| 21 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
| 22 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.core.IdGenerator; | 20 | import org.onosproject.core.IdGenerator; |
| 24 | import org.onosproject.net.NetworkResource; | 21 | import org.onosproject.net.NetworkResource; |
| 25 | 22 | ||
| 23 | +import java.util.Collection; | ||
| 24 | +import java.util.Objects; | ||
| 25 | + | ||
| 26 | import static com.google.common.base.Preconditions.checkArgument; | 26 | import static com.google.common.base.Preconditions.checkArgument; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | import static com.google.common.base.Preconditions.checkState; | 28 | import static com.google.common.base.Preconditions.checkState; |
| ... | @@ -91,6 +91,24 @@ public abstract class Intent { | ... | @@ -91,6 +91,24 @@ public abstract class Intent { |
| 91 | protected int priority = Intent.DEFAULT_INTENT_PRIORITY; | 91 | protected int priority = Intent.DEFAULT_INTENT_PRIORITY; |
| 92 | 92 | ||
| 93 | /** | 93 | /** |
| 94 | + * Creates a new empty builder. | ||
| 95 | + */ | ||
| 96 | + protected Builder() { | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * Creates a new builder pre-populated with the information in the given | ||
| 101 | + * intent. | ||
| 102 | + * | ||
| 103 | + * @param intent initial intent | ||
| 104 | + */ | ||
| 105 | + protected Builder(Intent intent) { | ||
| 106 | + this.appId(intent.appId()) | ||
| 107 | + .key(intent.key()) | ||
| 108 | + .priority(intent.priority()); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 94 | * Sets the application id for the intent that will be built. | 112 | * Sets the application id for the intent that will be built. |
| 95 | * | 113 | * |
| 96 | * @param appId application id to use for built intent | 114 | * @param appId application id to use for built intent | ... | ... |
| ... | @@ -100,6 +100,17 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -100,6 +100,17 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /** | 102 | /** |
| 103 | + * Creates a new builder pre-populated with the information in the given | ||
| 104 | + * intent. | ||
| 105 | + * | ||
| 106 | + * @param intent initial intent | ||
| 107 | + * @return intent builder | ||
| 108 | + */ | ||
| 109 | + public static Builder builder(MultiPointToSinglePointIntent intent) { | ||
| 110 | + return new Builder(intent); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 103 | * Builder of a multi point to single point intent. | 114 | * Builder of a multi point to single point intent. |
| 104 | */ | 115 | */ |
| 105 | public static final class Builder extends ConnectivityIntent.Builder { | 116 | public static final class Builder extends ConnectivityIntent.Builder { |
| ... | @@ -110,6 +121,19 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { | ... | @@ -110,6 +121,19 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { |
| 110 | // Hide constructor | 121 | // Hide constructor |
| 111 | } | 122 | } |
| 112 | 123 | ||
| 124 | + /** | ||
| 125 | + * Creates a new builder pre-populated with information from the given | ||
| 126 | + * intent. | ||
| 127 | + * | ||
| 128 | + * @param intent initial intent | ||
| 129 | + */ | ||
| 130 | + protected Builder(MultiPointToSinglePointIntent intent) { | ||
| 131 | + super(intent); | ||
| 132 | + | ||
| 133 | + this.ingressPoints(intent.ingressPoints()) | ||
| 134 | + .egressPoint(intent.egressPoint()); | ||
| 135 | + } | ||
| 136 | + | ||
| 113 | @Override | 137 | @Override |
| 114 | public Builder appId(ApplicationId appId) { | 138 | public Builder appId(ApplicationId appId) { |
| 115 | return (Builder) super.appId(appId); | 139 | return (Builder) super.appId(appId); | ... | ... |
incubator/api/src/test/java/org/onosproject/incubator/net/intf/InterfaceServiceAdapter.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | +package org.onosproject.incubator.net.intf; | ||
| 18 | + | ||
| 19 | +import org.onlab.packet.IpAddress; | ||
| 20 | +import org.onlab.packet.VlanId; | ||
| 21 | +import org.onosproject.net.ConnectPoint; | ||
| 22 | + | ||
| 23 | +import java.util.Set; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Interface service adapter class for tests. | ||
| 27 | + */ | ||
| 28 | +public class InterfaceServiceAdapter implements InterfaceService { | ||
| 29 | + @Override | ||
| 30 | + public Set<Interface> getInterfaces() { | ||
| 31 | + return null; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Interface getInterfaceByName(ConnectPoint connectPoint, String name) { | ||
| 36 | + return null; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public Set<Interface> getInterfacesByPort(ConnectPoint port) { | ||
| 41 | + return null; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + public Set<Interface> getInterfacesByIp(IpAddress ip) { | ||
| 46 | + return null; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public Set<Interface> getInterfacesByVlan(VlanId vlan) { | ||
| 51 | + return null; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public Interface getMatchingInterface(IpAddress ip) { | ||
| 56 | + return null; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void addListener(InterfaceListener listener) { | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void removeListener(InterfaceListener listener) { | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | +} |
-
Please register or login to post a comment