aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/sdnip
diff options
context:
space:
mode:
authorAshlee Young <ashlee@wildernessvoice.com>2015-11-03 14:08:10 -0800
committerAshlee Young <ashlee@wildernessvoice.com>2015-11-03 14:08:10 -0800
commit643ee33289bd2cb9e6afbfb09b4ed72d467ba1c2 (patch)
treec2c376a44a359544fe3d4c45eb0cc0e2ec4a7080 /framework/src/onos/apps/sdnip
parent46eeb79b54345bdafb6055b8ee4bad4ce8b01274 (diff)
This updates ONOS src tree to commit id
03fa5e571cabbd001ddb1598847e1150b11c7333 Change-Id: I13b554026d6f902933e35887d29bd5fdb669c0bd Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/apps/sdnip')
-rw-r--r--framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java58
-rw-r--r--framework/src/onos/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java5
2 files changed, 53 insertions, 10 deletions
diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
index b2ce0f8a..a27baaf9 100644
--- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
+++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
@@ -15,8 +15,6 @@
*/
package org.onosproject.sdnip;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IPv6;
@@ -27,6 +25,8 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -43,7 +43,9 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -69,9 +71,10 @@ public class PeerConnectivityManager {
private final ApplicationId appId;
private final ApplicationId routerAppId;
- // Just putting something random here for now. Figure out exactly what
- // indexes we need when we start making use of them.
- private final Multimap<BgpConfig.BgpSpeakerConfig, PointToPointIntent> peerIntents;
+ private final Map<Key, PointToPointIntent> peerIntents;
+
+ private final InternalNetworkConfigListener configListener
+ = new InternalNetworkConfigListener();
/**
* Creates a new PeerConnectivityManager.
@@ -93,13 +96,14 @@ public class PeerConnectivityManager {
this.routerAppId = routerAppId;
this.interfaceService = interfaceService;
- peerIntents = HashMultimap.create();
+ peerIntents = new HashMap<>();
}
/**
* Starts the peer connectivity manager.
*/
public void start() {
+ configService.addListener(configListener);
setUpConnectivity();
}
@@ -107,6 +111,7 @@ public class PeerConnectivityManager {
* Stops the peer connectivity manager.
*/
public void stop() {
+ configService.removeListener(configListener);
}
/**
@@ -121,16 +126,27 @@ public class PeerConnectivityManager {
return;
}
+ Map<Key, PointToPointIntent> existingIntents = new HashMap<>(peerIntents);
+
for (BgpConfig.BgpSpeakerConfig bgpSpeaker : config.bgpSpeakers()) {
log.debug("Start to set up BGP paths for BGP speaker: {}",
bgpSpeaker);
buildSpeakerIntents(bgpSpeaker).forEach(i -> {
- peerIntents.put(bgpSpeaker, i);
- intentSynchronizer.submit(i);
+ PointToPointIntent intent = existingIntents.remove(i.key());
+ if (intent == null || !IntentUtils.equals(i, intent)) {
+ peerIntents.put(i.key(), i);
+ intentSynchronizer.submit(i);
+ }
});
-
}
+
+ // Remove any remaining intents that we used to have that we don't need
+ // anymore
+ existingIntents.values().forEach(i -> {
+ peerIntents.remove(i.key());
+ intentSynchronizer.withdraw(i);
+ });
}
private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) {
@@ -356,7 +372,7 @@ public class PeerConnectivityManager {
* @param srcIp source IP address
* @param dstIp destination IP address
* @param suffix suffix string
- * @return
+ * @return intent key
*/
private Key buildKey(IpAddress srcIp, IpAddress dstIp, String suffix) {
String keyString = new StringBuilder()
@@ -370,4 +386,26 @@ public class PeerConnectivityManager {
return Key.of(keyString, appId);
}
+ private class InternalNetworkConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ switch (event.type()) {
+ case CONFIG_REGISTERED:
+ break;
+ case CONFIG_UNREGISTERED:
+ break;
+ case CONFIG_ADDED:
+ case CONFIG_UPDATED:
+ case CONFIG_REMOVED:
+ if (event.configClass() == RoutingService.CONFIG_CLASS) {
+ setUpConnectivity();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
}
diff --git a/framework/src/onos/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java b/framework/src/onos/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
index c4b2daad..0dcc969d 100644
--- a/framework/src/onos/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
+++ b/framework/src/onos/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
@@ -34,6 +34,7 @@ import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -60,8 +61,10 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
@@ -119,6 +122,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
routingConfig = createMock(RoutingConfigurationService.class);
interfaceService = createMock(InterfaceService.class);
networkConfigService = createMock(NetworkConfigService.class);
+ networkConfigService.addListener(anyObject(NetworkConfigListener.class));
+ expectLastCall().anyTimes();
bgpConfig = createMock(BgpConfig.class);
// These will set expectations on routingConfig and interfaceService