Jonathan Hart

Moved routing/bgp config into common routing bundle.

This allows the configuration to be used from multiple applications.

 * The class that reads the configuration file is now a service so that
   config can be consumed by components in other bundles.
 * Name of config reader classes has been generalized to RoutingConfigService
 * All config has been added to RoutingConfigService, instead of having
   two service interfaces like we did previously

Change-Id: Iaec9daf0f5b72abe2d6709fb75188d6d81947478
Showing 16 changed files with 218 additions and 210 deletions
......@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
package org.onosproject.routingapi.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import java.util.Objects;
......@@ -42,7 +43,7 @@ public class BgpPeer {
@JsonProperty("attachmentPort") long port,
@JsonProperty("ipAddress") String ipAddress) {
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(SdnIpConfigurationReader.dpidToUri(dpid)),
DeviceId.deviceId(NetTools.dpidToUri(dpid)),
PortNumber.portNumber(port));
this.ipAddress = IpAddress.valueOf(ipAddress);
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
package org.onosproject.routingapi.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -21,6 +21,7 @@ import com.google.common.base.MoreObjects;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import java.util.List;
......@@ -63,7 +64,7 @@ public class BgpSpeaker {
this.name = name;
this.macAddress = MacAddress.valueOf(macAddress);
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(SdnIpConfigurationReader.dpidToUri(attachmentDpid)),
DeviceId.deviceId(NetTools.dpidToUri(attachmentDpid)),
PortNumber.portNumber(attachmentPort));
}
......
......@@ -13,19 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
import java.util.Objects;
import java.util.Set;
package org.onosproject.routingapi.config;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import java.util.Objects;
import java.util.Set;
/**
* An Interface is a set of addresses that are logically mapped to a switch
......
......@@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
import java.util.Objects;
package org.onosproject.routingapi.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import java.util.Objects;
/**
* Represents an address of a {@link BgpSpeaker} configured on an
......@@ -48,7 +48,7 @@ public class InterfaceAddress {
@JsonProperty("interfacePort") int port,
@JsonProperty("ipAddress") String ipAddress) {
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(SdnIpConfigurationReader.dpidToUri(dpid)),
DeviceId.deviceId(NetTools.dpidToUri(dpid)),
PortNumber.portNumber(port));
this.ipAddress = IpAddress.valueOf(ipAddress);
}
......
......@@ -13,18 +13,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip;
import java.util.Set;
package org.onosproject.routingapi.config;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.sdnip.config.Interface;
import java.util.Map;
import java.util.Set;
/**
* Provides information about the interfaces in the network.
* Provides information about the routing configuration.
*/
public interface InterfaceService {
public interface RoutingConfigurationService {
/**
* Gets the list of BGP speakers inside the SDN network.
*
* @return the map of BGP speaker names to BGP speaker objects
*/
public Map<String, BgpSpeaker> getBgpSpeakers();
/**
* Gets the list of configured BGP peers.
*
* @return the map from peer IP address to BgpPeer object
*/
public Map<IpAddress, BgpPeer> getBgpPeers();
/**
* Retrieves the entire set of interfaces in the network.
*
......@@ -49,4 +64,5 @@ public interface InterfaceService {
* @return the matching interface
*/
Interface getMatchingInterface(IpAddress ipAddress);
}
......
......@@ -17,4 +17,4 @@
/**
* SDN-IP configuration services.
*/
package org.onosproject.sdnip.config;
package org.onosproject.routingapi.config;
......
......@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
package org.onosproject.routing.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.BgpSpeaker;
import java.util.Collections;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Contains the configuration data for SDN-IP that has been read from a
* JSON-formatted configuration file.
......
......@@ -13,25 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
package org.onosproject.routing.config;
import com.google.common.collect.Sets;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.routingapi.config.Interface;
import com.google.common.collect.Sets;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Provides InterfaceService using PortAddresses data from the HostService.
* Adapts PortAddresses data from the HostService into Interface data used by
* the routing module.
*/
public class HostToInterfaceAdaptor implements InterfaceService {
public class HostToInterfaceAdaptor {
private final HostService hostService;
......@@ -39,7 +39,6 @@ public class HostToInterfaceAdaptor implements InterfaceService {
this.hostService = checkNotNull(hostService);
}
@Override
public Set<Interface> getInterfaces() {
Set<PortAddresses> addresses = hostService.getAddressBindings();
Set<Interface> interfaces = Sets.newHashSetWithExpectedSize(addresses.size());
......@@ -49,7 +48,6 @@ public class HostToInterfaceAdaptor implements InterfaceService {
return interfaces;
}
@Override
public Interface getInterface(ConnectPoint connectPoint) {
checkNotNull(connectPoint);
......@@ -65,7 +63,6 @@ public class HostToInterfaceAdaptor implements InterfaceService {
return null;
}
@Override
public Interface getMatchingInterface(IpAddress ipAddress) {
checkNotNull(ipAddress);
......
......@@ -13,26 +13,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
package org.onosproject.routing.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.HostService;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.BgpSpeaker;
import org.onosproject.routingapi.config.Interface;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.onlab.packet.IpAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Implementation of SdnIpConfigurationService which reads SDN-IP configuration
* from a file.
* Implementation of RoutingConfigurationService which reads routing
* configuration from a file.
*/
public class SdnIpConfigurationReader implements SdnIpConfigurationService {
@Component(immediate = true)
@Service
public class RoutingConfigurationImpl implements RoutingConfigurationService {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -40,9 +53,21 @@ public class SdnIpConfigurationReader implements SdnIpConfigurationService {
private static final String DEFAULT_CONFIG_FILE = "sdnip.json";
private String configFileName = DEFAULT_CONFIG_FILE;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
private HostToInterfaceAdaptor hostAdaptor;
@Activate
public void activate() {
readConfiguration();
hostAdaptor = new HostToInterfaceAdaptor(hostService);
log.info("Routing configuration service started");
}
/**
* Reads SDN-IP related information contained in the configuration file.
*
......@@ -87,14 +112,19 @@ public class SdnIpConfigurationReader implements SdnIpConfigurationService {
return Collections.unmodifiableMap(bgpPeers);
}
/**
* Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider
* device URIs.
*
* @param dpid the DPID string to convert
* @return the URI string for this device
*/
static String dpidToUri(String dpid) {
return "of:" + dpid.replace(":", "");
@Override
public Set<Interface> getInterfaces() {
return hostAdaptor.getInterfaces();
}
@Override
public Interface getInterface(ConnectPoint connectPoint) {
return hostAdaptor.getInterface(connectPoint);
}
@Override
public Interface getMatchingInterface(IpAddress ipAddress) {
return hostAdaptor.getMatchingInterface(ipAddress);
}
}
......
......@@ -13,20 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
package org.onosproject.routing.config;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
......@@ -39,10 +29,19 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.routingapi.config.Interface;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for the HostToInterfaceAdaptor class.
......
......@@ -37,9 +37,9 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.routingapi.FibListener;
import org.onosproject.routingapi.FibUpdate;
import org.onosproject.sdnip.config.BgpPeer;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.sdnip.config.SdnIpConfigurationService;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.Interface;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -79,8 +79,7 @@ public class IntentSynchronizer implements FibListener {
private volatile boolean isElectedLeader = false;
private volatile boolean isActivatedLeader = false;
private final SdnIpConfigurationService configService;
private final InterfaceService interfaceService;
private final RoutingConfigurationService configService;
/**
* Class constructor.
......@@ -88,18 +87,15 @@ public class IntentSynchronizer implements FibListener {
* @param appId the Application ID
* @param intentService the intent service
* @param configService the SDN-IP configuration service
* @param interfaceService the interface service
*/
IntentSynchronizer(ApplicationId appId, IntentService intentService,
SdnIpConfigurationService configService,
InterfaceService interfaceService) {
RoutingConfigurationService configService) {
this.appId = appId;
this.intentService = intentService;
peerIntents = new ConcurrentHashMap<>();
routeIntents = new ConcurrentHashMap<>();
this.configService = configService;
this.interfaceService = interfaceService;
bgpIntentsSynchronizerExecutor = Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder()
......@@ -289,12 +285,12 @@ public class IntentSynchronizer implements FibListener {
BgpPeer peer =
configService.getBgpPeers().get(nextHopIpAddress);
egressInterface =
interfaceService.getInterface(peer.connectPoint());
configService.getInterface(peer.connectPoint());
} else {
// Route to non-peer
log.debug("Route to non-peer {}", nextHopIpAddress);
egressInterface =
interfaceService.getMatchingInterface(nextHopIpAddress);
configService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}",
nextHopIpAddress);
......@@ -310,7 +306,7 @@ public class IntentSynchronizer implements FibListener {
log.debug("Generating intent for prefix {}, next hop mac {}",
prefix, nextHopMacAddress);
for (Interface intf : interfaceService.getInterfaces()) {
for (Interface intf : configService.getInterfaces()) {
if (!intf.connectPoint().equals(egressInterface.connectPoint())) {
ConnectPoint srcPort = intf.connectPoint();
ingressPorts.add(srcPort);
......
......@@ -28,11 +28,11 @@ import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.sdnip.config.BgpPeer;
import org.onosproject.sdnip.config.BgpSpeaker;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.sdnip.config.InterfaceAddress;
import org.onosproject.sdnip.config.SdnIpConfigurationService;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.BgpSpeaker;
import org.onosproject.routingapi.config.Interface;
import org.onosproject.routingapi.config.InterfaceAddress;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -51,8 +51,7 @@ public class PeerConnectivityManager {
private static final short BGP_PORT = 179;
private final IntentSynchronizer intentSynchronizer;
private final SdnIpConfigurationService configService;
private final InterfaceService interfaceService;
private final RoutingConfigurationService configService;
private final ApplicationId appId;
......@@ -62,23 +61,20 @@ public class PeerConnectivityManager {
* @param appId the application ID
* @param intentSynchronizer the intent synchronizer
* @param configService the SDN-IP config service
* @param interfaceService the interface service
*/
public PeerConnectivityManager(ApplicationId appId,
IntentSynchronizer intentSynchronizer,
SdnIpConfigurationService configService,
InterfaceService interfaceService) {
RoutingConfigurationService configService) {
this.appId = appId;
this.intentSynchronizer = intentSynchronizer;
this.configService = configService;
this.interfaceService = interfaceService;
}
/**
* Starts the peer connectivity manager.
*/
public void start() {
if (interfaceService.getInterfaces().isEmpty()) {
if (configService.getInterfaces().isEmpty()) {
log.warn("No interfaces found in configuration file");
}
......@@ -142,7 +138,7 @@ public class PeerConnectivityManager {
List<InterfaceAddress> interfaceAddresses =
bgpSpeaker.interfaceAddresses();
Interface peerInterface = interfaceService.getInterface(
Interface peerInterface = configService.getInterface(
bgpPeer.connectPoint());
if (peerInterface == null) {
......
......@@ -29,10 +29,9 @@ import org.onosproject.cluster.LeadershipService;
import org.onosproject.config.NetworkConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.IntentService;
import org.onosproject.routingapi.RoutingService;
import org.onosproject.sdnip.config.SdnIpConfigurationReader;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -54,9 +53,6 @@ public class SdnIp implements SdnIpService {
protected IntentService intentService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -65,6 +61,9 @@ public class SdnIp implements SdnIpService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingService routingService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingConfigurationService config;
//
// NOTE: Unused reference - needed to guarantee that the
// NetworkConfigReader component is activated and the network configuration
......@@ -74,7 +73,6 @@ public class SdnIp implements SdnIpService {
protected NetworkConfigService networkConfigService;
private IntentSynchronizer intentSynchronizer;
private SdnIpConfigurationReader config;
private PeerConnectivityManager peerConnectivity;
private LeadershipEventListener leadershipEventListener =
......@@ -87,22 +85,16 @@ public class SdnIp implements SdnIpService {
log.info("SDN-IP started");
appId = coreService.registerApplication(SDN_IP_APP);
config = new SdnIpConfigurationReader();
config.readConfiguration();
localControllerNode = clusterService.getLocalNode();
InterfaceService interfaceService =
new HostToInterfaceAdaptor(hostService);
intentSynchronizer = new IntentSynchronizer(appId, intentService,
config, interfaceService);
config);
intentSynchronizer.start();
peerConnectivity = new PeerConnectivityManager(appId,
intentSynchronizer,
config,
interfaceService);
config);
peerConnectivity.start();
routingService.start(intentSynchronizer);
......
......@@ -44,10 +44,10 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.routingapi.FibEntry;
import org.onosproject.routingapi.FibUpdate;
import org.onosproject.routingapi.RouteEntry;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.Interface;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import org.onosproject.sdnip.IntentSynchronizer.IntentKey;
import org.onosproject.sdnip.config.BgpPeer;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.sdnip.config.SdnIpConfigurationService;
import java.util.Collections;
import java.util.HashMap;
......@@ -70,8 +70,7 @@ import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId;
*/
public class IntentSyncTest extends AbstractIntentTest {
private SdnIpConfigurationService sdnIpConfigService;
private InterfaceService interfaceService;
private RoutingConfigurationService routingConfig;
private IntentService intentService;
private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
......@@ -107,13 +106,19 @@ public class IntentSyncTest extends AbstractIntentTest {
@Before
public void setUp() throws Exception {
super.setUp();
setUpInterfaceService();
routingConfig = createMock(RoutingConfigurationService.class);
// These will set expectations on routingConfig
setUpInterfaceService();
setUpBgpPeers();
replay(routingConfig);
intentService = createMock(IntentService.class);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
sdnIpConfigService, interfaceService);
routingConfig);
}
/**
......@@ -140,10 +145,7 @@ public class IntentSyncTest extends AbstractIntentTest {
peers.put(IpAddress.valueOf(peer1Sw4Eth1),
new BgpPeer("00:00:00:00:00:00:00:04", 1, peer1Sw4Eth1));
sdnIpConfigService = createMock(SdnIpConfigurationService.class);
expect(sdnIpConfigService.getBgpPeers()).andReturn(peers).anyTimes();
replay(sdnIpConfigService);
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
}
/**
......@@ -151,8 +153,6 @@ public class IntentSyncTest extends AbstractIntentTest {
*/
private void setUpInterfaceService() {
interfaceService = createMock(InterfaceService.class);
Set<Interface> interfaces = Sets.newHashSet();
Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
......@@ -190,17 +190,16 @@ public class IntentSyncTest extends AbstractIntentTest {
MacAddress.valueOf("00:00:00:00:00:04"),
VlanId.vlanId((short) 1));
expect(interfaceService.getInterface(SW4_ETH1)).andReturn(sw4Eth1).anyTimes();
expect(routingConfig.getInterface(SW4_ETH1)).andReturn(
sw4Eth1).anyTimes();
interfaces.add(sw4Eth1);
expect(interfaceService.getInterface(SW1_ETH1)).andReturn(
expect(routingConfig.getInterface(SW1_ETH1)).andReturn(
sw1Eth1).anyTimes();
expect(interfaceService.getInterface(SW2_ETH1)).andReturn(
expect(routingConfig.getInterface(SW2_ETH1)).andReturn(
sw2Eth1).anyTimes();
expect(interfaceService.getInterface(SW3_ETH1)).andReturn(
sw3Eth1).anyTimes();
expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
replay(interfaceService);
expect(routingConfig.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
expect(routingConfig.getInterfaces()).andReturn(interfaces).anyTimes();
}
/**
......@@ -517,7 +516,7 @@ public class IntentSyncTest extends AbstractIntentTest {
// Set up expectation
reset(intentService);
Set<Intent> intents = new HashSet<Intent>();
Set<Intent> intents = new HashSet<>();
intents.add(intent1);
expect(intentService.getIntentState(intent1.key()))
.andReturn(IntentState.INSTALLED).anyTimes();
......@@ -584,9 +583,9 @@ public class IntentSyncTest extends AbstractIntentTest {
DefaultTrafficTreatment.builder();
treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
Set<ConnectPoint> ingressPoints = new HashSet<ConnectPoint>();
for (Interface intf : interfaceService.getInterfaces()) {
if (!intf.equals(interfaceService.getInterface(egressPoint))) {
Set<ConnectPoint> ingressPoints = new HashSet<>();
for (Interface intf : routingConfig.getInterfaces()) {
if (!intf.equals(routingConfig.getInterface(egressPoint))) {
ConnectPoint srcPort = intf.connectPoint();
ingressPoints.add(srcPort);
}
......
......@@ -40,11 +40,11 @@ import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.sdnip.config.BgpPeer;
import org.onosproject.sdnip.config.BgpSpeaker;
import org.onosproject.sdnip.config.Interface;
import org.onosproject.sdnip.config.InterfaceAddress;
import org.onosproject.sdnip.config.SdnIpConfigurationService;
import org.onosproject.routingapi.config.BgpPeer;
import org.onosproject.routingapi.config.BgpSpeaker;
import org.onosproject.routingapi.config.Interface;
import org.onosproject.routingapi.config.InterfaceAddress;
import org.onosproject.routingapi.config.RoutingConfigurationService;
import java.util.ArrayList;
import java.util.Collections;
......@@ -75,8 +75,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
private PeerConnectivityManager peerConnectivityManager;
private IntentSynchronizer intentSynchronizer;
private SdnIpConfigurationService configInfoService;
private InterfaceService interfaceService;
private RoutingConfigurationService routingConfig;
private IntentService intentService;
private Map<String, BgpSpeaker> bgpSpeakers;
......@@ -114,6 +113,9 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
@Before
public void setUp() throws Exception {
super.setUp();
routingConfig = createMock(RoutingConfigurationService.class);
// These will set expectations on routingConfig
bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
interfaces = Collections.unmodifiableMap(setUpInterfaces());
peers = Collections.unmodifiableMap(setUpPeers());
......@@ -135,8 +137,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
"bgpSpeaker1",
"00:00:00:00:00:00:00:01", 100,
"00:00:00:00:00:01");
List<InterfaceAddress> interfaceAddresses1 =
new LinkedList<InterfaceAddress>();
List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>();
interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
interfaceAddresses1.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
......@@ -147,8 +148,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
"bgpSpeaker2",
"00:00:00:00:00:00:00:01", 100,
"00:00:00:00:00:02");
List<InterfaceAddress> interfaceAddresses2 =
new LinkedList<InterfaceAddress>();
List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>();
interfaceAddresses2.add(new InterfaceAddress(dpid1, 1, "192.168.10.102"));
interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.102"));
bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
......@@ -158,8 +158,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
"bgpSpeaker3",
"00:00:00:00:00:00:00:02", 100,
"00:00:00:00:00:03");
List<InterfaceAddress> interfaceAddresses3 =
new LinkedList<InterfaceAddress>();
List<InterfaceAddress> interfaceAddresses3 = new LinkedList<>();
interfaceAddresses3.add(new InterfaceAddress(dpid1, 1, "192.168.10.103"));
interfaceAddresses3.add(new InterfaceAddress(dpid2, 1, "192.168.20.103"));
bgpSpeaker3.setInterfaceAddresses(interfaceAddresses3);
......@@ -198,22 +197,19 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
VlanId.NONE);
configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
interfaceService = createMock(InterfaceService.class);
expect(interfaceService.getInterface(s1Eth1))
expect(routingConfig.getInterface(s1Eth1))
.andReturn(intfsw1eth1).anyTimes();
expect(interfaceService.getInterface(s2Eth1))
expect(routingConfig.getInterface(s2Eth1))
.andReturn(intfsw2eth1).anyTimes();
// Non-existent interface used during one of the tests
expect(interfaceService.getInterface(new ConnectPoint(
expect(routingConfig.getInterface(new ConnectPoint(
DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
PortNumber.portNumber(1))))
.andReturn(null).anyTimes();
expect(interfaceService.getInterfaces()).andReturn(
expect(routingConfig.getInterfaces()).andReturn(
Sets.newHashSet(configuredInterfaces.values())).anyTimes();
replay(interfaceService);
return configuredInterfaces;
}
......@@ -250,7 +246,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
private List<PointToPointIntent> setUpIntentList() {
intentList = new ArrayList<PointToPointIntent>();
intentList = new ArrayList<>();
setUpBgpIntents();
setUpIcmpIntents();
......@@ -538,23 +534,21 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
private void initPeerConnectivity() throws TestUtilsException {
configInfoService = createMock(SdnIpConfigurationService.class);
expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(configInfoService);
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(routingConfig);
intentService = createMock(IntentService.class);
replay(intentService);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
configInfoService,
interfaceService);
routingConfig);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
peerConnectivityManager =
new PeerConnectivityManager(APPID, intentSynchronizer,
configInfoService, interfaceService);
routingConfig);
}
/**
......@@ -587,19 +581,17 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
@Test
public void testNullInterfaces() {
reset(interfaceService);
expect(interfaceService.getInterfaces()).andReturn(
reset(routingConfig);
expect(routingConfig.getInterfaces()).andReturn(
Sets.<Interface>newHashSet()).anyTimes();
expect(interfaceService.getInterface(s2Eth1))
expect(routingConfig.getInterface(s2Eth1))
.andReturn(null).anyTimes();
expect(interfaceService.getInterface(s1Eth1))
expect(routingConfig.getInterface(s1Eth1))
.andReturn(null).anyTimes();
replay(interfaceService);
reset(configInfoService);
expect(configInfoService.getBgpPeers()).andReturn(peers).anyTimes();
expect(configInfoService.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(configInfoService);
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(routingConfig);
reset(intentService);
replay(intentService);
......@@ -612,17 +604,13 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
@Test
public void testNullBgpPeers() {
reset(interfaceService);
expect(interfaceService.getInterfaces()).andReturn(
reset(routingConfig);
expect(routingConfig.getInterfaces()).andReturn(
Sets.newHashSet(interfaces.values())).anyTimes();
replay(interfaceService);
reset(configInfoService);
expect(configInfoService.getBgpPeers()).andReturn(
new HashMap<IpAddress, BgpPeer>()).anyTimes();
expect(configInfoService.getBgpSpeakers()).andReturn(
bgpSpeakers).anyTimes();
replay(configInfoService);
expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes();
expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(routingConfig);
reset(intentService);
replay(intentService);
......@@ -635,17 +623,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
@Test
public void testNullBgpSpeakers() {
reset(interfaceService);
expect(interfaceService.getInterfaces()).andReturn(
reset(routingConfig);
expect(routingConfig.getInterfaces()).andReturn(
Sets.newHashSet(interfaces.values())).anyTimes();
replay(interfaceService);
reset(configInfoService);
expect(configInfoService.getBgpPeers()).andReturn(
peers).anyTimes();
expect(configInfoService.getBgpSpeakers()).andReturn(
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
expect(routingConfig.getBgpSpeakers()).andReturn(
Collections.emptyMap()).anyTimes();
replay(configInfoService);
replay(routingConfig);
reset(intentService);
replay(intentService);
......@@ -676,8 +661,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
"bgpSpeaker100",
"00:00:00:00:00:00:01:00", 100,
"00:00:00:00:01:00");
List<InterfaceAddress> interfaceAddresses100 =
new LinkedList<InterfaceAddress>();
List<InterfaceAddress> interfaceAddresses100 = new LinkedList<>();
interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
......
/*
* Copyright 2014 Open Networking Laboratory
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,29 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip.config;
import java.util.Map;
import org.onlab.packet.IpAddress;
package org.onosproject.net;
/**
* Provides information about the BGP elements configured in the network.
* Networking domain tools.
*/
public interface SdnIpConfigurationService {
public final class NetTools {
/**
* Gets the list of BGP speakers inside the SDN network.
*
* @return the map of BGP speaker names to BGP speaker objects
*/
public Map<String, BgpSpeaker> getBgpSpeakers();
private NetTools() {
}
/**
* Gets the list of configured BGP peers.
* Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider
* device URIs. The is helpful for converting DPIDs coming from configuration
* or REST to URIs that the core understands.
*
* @return the map from peer IP address to BgpPeer object
* @param dpid the DPID string to convert
* @return the URI string for this device
*/
public Map<IpAddress, BgpPeer> getBgpPeers();
public static String dpidToUri(String dpid) {
return "of:" + dpid.replace(":", "");
}
}
......