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
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpPeer.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpPeer.java
similarity index 94%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpPeer.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpPeer.java
index 5d89075..47a3520 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpPeer.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpPeer.java
@@ -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 @@
@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);
}
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpSpeaker.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpSpeaker.java
similarity index 96%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpSpeaker.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpSpeaker.java
index 6e89b1f..c19ceb6 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/BgpSpeaker.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/BgpSpeaker.java
@@ -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 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 @@
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));
}
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/Interface.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/Interface.java
similarity index 98%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/Interface.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/Interface.java
index 2179653..7f7547d 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/Interface.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/Interface.java
@@ -13,19 +13,18 @@
* 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 java.util.Objects;
-import java.util.Set;
-
+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
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/InterfaceAddress.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/InterfaceAddress.java
similarity index 95%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/InterfaceAddress.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/InterfaceAddress.java
index 7b14735..5fa4d64 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/InterfaceAddress.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/InterfaceAddress.java
@@ -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;
-
-import org.onlab.packet.IpAddress;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
+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;
/**
* Represents an address of a {@link BgpSpeaker} configured on an
@@ -48,7 +48,7 @@
@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);
}
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/InterfaceService.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/RoutingConfigurationService.java
similarity index 71%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/InterfaceService.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/RoutingConfigurationService.java
index 7b821d3..385e99d 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/InterfaceService.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/RoutingConfigurationService.java
@@ -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 @@
* @return the matching interface
*/
Interface getMatchingInterface(IpAddress ipAddress);
+
}
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/package-info.java b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/package-info.java
similarity index 93%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/package-info.java
rename to apps/routing-api/src/main/java/org/onosproject/routingapi/config/package-info.java
index 7689a2e..7e464da 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/package-info.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routingapi/config/package-info.java
@@ -17,4 +17,4 @@
/**
* SDN-IP configuration services.
*/
-package org.onosproject.sdnip.config;
+package org.onosproject.routingapi.config;
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/Configuration.java b/apps/routing/src/main/java/org/onosproject/routing/config/Configuration.java
similarity index 93%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/Configuration.java
rename to apps/routing/src/main/java/org/onosproject/routing/config/Configuration.java
index 3d917cd..9ae69f8 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/Configuration.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/config/Configuration.java
@@ -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.
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/HostToInterfaceAdaptor.java b/apps/routing/src/main/java/org/onosproject/routing/config/HostToInterfaceAdaptor.java
similarity index 89%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/HostToInterfaceAdaptor.java
rename to apps/routing/src/main/java/org/onosproject/routing/config/HostToInterfaceAdaptor.java
index e6275a6..98b7914 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/HostToInterfaceAdaptor.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/config/HostToInterfaceAdaptor.java
@@ -13,25 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.sdnip;
+package org.onosproject.routing.config;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Set;
-
+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 @@
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 @@
return interfaces;
}
- @Override
public Interface getInterface(ConnectPoint connectPoint) {
checkNotNull(connectPoint);
@@ -65,7 +63,6 @@
return null;
}
- @Override
public Interface getMatchingInterface(IpAddress ipAddress) {
checkNotNull(ipAddress);
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationReader.java b/apps/routing/src/main/java/org/onosproject/routing/config/RoutingConfigurationImpl.java
similarity index 63%
rename from apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationReader.java
rename to apps/routing/src/main/java/org/onosproject/routing/config/RoutingConfigurationImpl.java
index b36f421..6ca0155 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationReader.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/config/RoutingConfigurationImpl.java
@@ -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 @@
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 @@
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);
+ }
+
}
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/HostToInterfaceAdaptorTest.java b/apps/routing/src/test/java/org/onosproject/routing/config/HostToInterfaceAdaptorTest.java
similarity index 98%
rename from apps/sdnip/src/test/java/org/onosproject/sdnip/HostToInterfaceAdaptorTest.java
rename to apps/routing/src/test/java/org/onosproject/routing/config/HostToInterfaceAdaptorTest.java
index 096e63c..7dd6411 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/HostToInterfaceAdaptorTest.java
+++ b/apps/routing/src/test/java/org/onosproject/routing/config/HostToInterfaceAdaptorTest.java
@@ -13,20 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.sdnip;
+package org.onosproject.routing.config;
-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;
-
+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.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.
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index 85574b8..b1c9961 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -37,9 +37,9 @@
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 @@
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 @@
* @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 @@
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 @@
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);
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
index 93b442d..baad757 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
@@ -28,11 +28,11 @@
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 @@
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 @@
* @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 @@
List<InterfaceAddress> interfaceAddresses =
bgpSpeaker.interfaceAddresses();
- Interface peerInterface = interfaceService.getInterface(
+ Interface peerInterface = configService.getInterface(
bgpPeer.connectPoint());
if (peerInterface == null) {
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java
index 2f24e15..cf6280d 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java
@@ -29,10 +29,9 @@
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 @@
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 @@
@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 @@
protected NetworkConfigService networkConfigService;
private IntentSynchronizer intentSynchronizer;
- private SdnIpConfigurationReader config;
private PeerConnectivityManager peerConnectivity;
private LeadershipEventListener leadershipEventListener =
@@ -87,22 +85,16 @@
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);
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationService.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationService.java
deleted file mode 100644
index 3b86a22..0000000
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/config/SdnIpConfigurationService.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2014 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * 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;
-
-/**
- * Provides information about the BGP elements configured in the network.
- */
-public interface SdnIpConfigurationService {
-
- /**
- * 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();
-
-}
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
index 857f49a..ffe839f 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
@@ -44,10 +44,10 @@
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 @@
*/
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 @@
@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 @@
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 @@
*/
private void setUpInterfaceService() {
- interfaceService = createMock(InterfaceService.class);
-
Set<Interface> interfaces = Sets.newHashSet();
Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
@@ -190,17 +190,16 @@
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 @@
// 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 @@
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);
}
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
index ed703b9..b3678c4 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
@@ -40,11 +40,11 @@
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 @@
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 @@
@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 @@
"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 @@
"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 @@
"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 @@
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 @@
*/
private List<PointToPointIntent> setUpIntentList() {
- intentList = new ArrayList<PointToPointIntent>();
+ intentList = new ArrayList<>();
setUpBgpIntents();
setUpIcmpIntents();
@@ -538,23 +534,21 @@
*/
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 @@
*/
@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 @@
*/
@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 @@
*/
@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 @@
"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);
diff --git a/core/api/src/main/java/org/onosproject/net/NetTools.java b/core/api/src/main/java/org/onosproject/net/NetTools.java
new file mode 100644
index 0000000..fc56188
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/NetTools.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net;
+
+/**
+ * Networking domain tools.
+ */
+public final class NetTools {
+
+ private NetTools() {
+ }
+
+ /**
+ * 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.
+ *
+ * @param dpid the DPID string to convert
+ * @return the URI string for this device
+ */
+ public static String dpidToUri(String dpid) {
+ return "of:" + dpid.replace(":", "");
+ }
+}