@Override public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) { int submitCount = 0, withdrawCount = 0; // // NOTE: Semantically, we MUST withdraw existing intents before // submitting new intents. // synchronized (this) { MultiPointToSinglePointIntent intent; // // Prepare the Intent batch operations for the intents to withdraw // for (FibUpdate withdraw : withdraws) { checkArgument( withdraw.type() == FibUpdate.Type.DELETE, "FibUpdate with wrong type in withdraws list"); IpPrefix prefix = withdraw.entry().prefix(); intent = routeIntents.remove(prefix); if (intent == null) { log.trace("SDN-IP No intent in routeIntents to delete " + "for prefix: {}", prefix); continue; } intentSynchronizer.withdraw(intent); withdrawCount++; } // // Prepare the Intent batch operations for the intents to submit // for (FibUpdate update : updates) { checkArgument( update.type() == FibUpdate.Type.UPDATE, "FibUpdate with wrong type in updates list"); IpPrefix prefix = update.entry().prefix(); intent = generateRouteIntent(prefix, update.entry().nextHopIp(), update.entry().nextHopMac()); if (intent == null) { // This preserves the old semantics - if an intent can't be // generated, we don't do anything with that prefix. But // perhaps we should withdraw the old intent anyway? continue; } routeIntents.put(prefix, intent); intentSynchronizer.submit(intent); submitCount++; } log.debug( "SDN-IP submitted {}/{}, withdrew = {}/{}", submitCount, updates.size(), withdrawCount, withdraws.size()); } }
/** * Tests whether peer connectivity manager can set up correct BGP and ICMP intents according to * specific configuration. * * <p>Two tricky cases included in the configuration are: 2 peers on a same switch port, peer on * the same switch with BGPd. */ @Test public void testConnectionSetup() { reset(intentSynchronizer); // Setup the expected intents for (Intent intent : intentList) { intentSynchronizer.submit(eqExceptId(intent)); } replay(intentSynchronizer); // Running the interface to be tested. peerConnectivityManager.start(); verify(intentSynchronizer); }