Move some functions from segment routing manager to interface service/manager
Change-Id: I7185cf70f7e5d723a63ac35296b8916558560c35
diff --git a/app/BUCK b/app/BUCK
index 41ae39c..7deda13 100644
--- a/app/BUCK
+++ b/app/BUCK
@@ -14,6 +14,7 @@
TEST_DEPS = [
'//lib:TEST_ADAPTERS',
+ '//core/net:onos-core-net',
'//incubator/api:onos-incubator-api-tests',
'//apps/route-service/api:onos-apps-route-service-api-tests',
]
diff --git a/app/pom.xml b/app/pom.xml
index 67ae9d4..5770071 100644
--- a/app/pom.xml
+++ b/app/pom.xml
@@ -63,6 +63,12 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
+ <artifactId>onos-core-net</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
<artifactId>onos-incubator-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
diff --git a/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java b/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
index e14fdc2..b798cec 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/HostHandler.java
@@ -239,7 +239,7 @@
VlanId oldAssignedVlan = srManager.getInternalVlanId(prevLocation);
VlanId newAssignedVlan = srManager.getInternalVlanId(newLocation);
// Host is tagged and the new location has the host vlan in vlan-tagged
- return srManager.getTaggedVlanId(newLocation).contains(hostVlanId) ||
+ return srManager.interfaceService.getTaggedVlanId(newLocation).contains(hostVlanId) ||
(oldAssignedVlan != null && newAssignedVlan != null &&
// Host is untagged and the new location has the same assigned vlan
oldAssignedVlan.equals(newAssignedVlan));
@@ -401,7 +401,7 @@
*/
private boolean isHostInVlanOfPort(Host host, DeviceId deviceId, ConnectPoint cp) {
VlanId internalVlan = srManager.getInternalVlanId(cp);
- Set<VlanId> taggedVlan = srManager.getTaggedVlanId(cp);
+ Set<VlanId> taggedVlan = srManager.interfaceService.getTaggedVlanId(cp);
return taggedVlan.contains(host.vlan()) ||
(internalVlan != null && host.locations().stream()
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index 730d2d0..9063015 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -179,9 +179,9 @@
private ForwardingObjective.Builder bridgingFwdObjBuilder(
DeviceId deviceId, MacAddress mac, VlanId hostVlanId, PortNumber outport, boolean revoke) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, outport);
- VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint);
- Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint);
- VlanId nativeVlan = srManager.getNativeVlanId(connectPoint);
+ VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
+ Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
+ VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Create host selector
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
@@ -390,9 +390,9 @@
deviceMac = config.getDeviceMac(deviceId);
ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort);
- VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint);
- Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint);
- VlanId nativeVlan = srManager.getNativeVlanId(connectPoint);
+ VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
+ Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
+ VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Create route selector
TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix);
@@ -948,14 +948,14 @@
*/
boolean processSinglePortFilters(DeviceId deviceId, PortNumber portnum, boolean install) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum);
- VlanId untaggedVlan = srManager.getUntaggedVlanId(connectPoint);
- Set<VlanId> taggedVlans = srManager.getTaggedVlanId(connectPoint);
- VlanId nativeVlan = srManager.getNativeVlanId(connectPoint);
+ VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
+ Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
+ VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Do not configure filter for edge ports where double-tagged hosts are connected.
if (taggedVlans.size() != 0) {
// Filter for tagged vlans
- if (!srManager.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId ->
+ if (!srManager.interfaceService.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId ->
processSinglePortFiltersInternal(deviceId, portnum, false, taggedVlanId, install))) {
return false;
}
@@ -1516,9 +1516,9 @@
return enabledPorts.stream().noneMatch(cp ->
// Given vlanId is included in the vlan-tagged configuration
- srManager.getTaggedVlanId(cp).contains(vlanId) ||
+ srManager.interfaceService.getTaggedVlanId(cp).contains(vlanId) ||
// Given vlanId is INTERNAL_VLAN and the interface is not configured
- (srManager.getTaggedVlanId(cp).isEmpty() && srManager.getInternalVlanId(cp) == null &&
+ (srManager.interfaceService.getTaggedVlanId(cp).isEmpty() && srManager.getInternalVlanId(cp) == null &&
vlanId.equals(INTERNAL_VLAN)) ||
// interface is configured and either vlan-untagged or vlan-native matches given vlanId
(srManager.getInternalVlanId(cp) != null && srManager.getInternalVlanId(cp).equals(vlanId))
diff --git a/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 388d213..6f381a2 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -834,58 +834,6 @@
return tunnelHandler.getTunnel(tunnelId);
}
- // TODO Consider moving these to InterfaceService
- /**
- * Returns untagged VLAN configured on given connect point.
- * <p>
- * Only returns the first match if there are multiple untagged VLAN configured
- * on the connect point.
- *
- * @param connectPoint connect point
- * @return untagged VLAN or null if not configured
- */
- VlanId getUntaggedVlanId(ConnectPoint connectPoint) {
- return interfaceService.getInterfacesByPort(connectPoint).stream()
- .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE))
- .map(Interface::vlanUntagged)
- .findFirst().orElse(null);
- }
-
- /**
- * Returns tagged VLAN configured on given connect point.
- * <p>
- * Returns all matches if there are multiple tagged VLAN configured
- * on the connect point.
- *
- * @param connectPoint connect point
- * @return tagged VLAN or empty set if not configured
- */
- Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) {
- Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
- return interfaces.stream()
- .map(Interface::vlanTagged)
- .flatMap(Set::stream)
- .collect(Collectors.toSet());
- }
-
- /**
- * Returns native VLAN configured on given connect point.
- * <p>
- * Only returns the first match if there are multiple native VLAN configured
- * on the connect point.
- *
- * @param connectPoint connect point
- * @return native VLAN or null if not configured
- */
- VlanId getNativeVlanId(ConnectPoint connectPoint) {
- Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint);
- return interfaces.stream()
- .filter(intf -> !intf.vlanNative().equals(VlanId.NONE))
- .map(Interface::vlanNative)
- .findFirst()
- .orElse(null);
- }
-
/**
* Returns internal VLAN for untagged hosts on given connect point.
* <p>
@@ -896,8 +844,8 @@
* @return internal VLAN or null if both vlan-untagged and vlan-native are undefined
*/
public VlanId getInternalVlanId(ConnectPoint connectPoint) {
- VlanId untaggedVlanId = getUntaggedVlanId(connectPoint);
- VlanId nativeVlanId = getNativeVlanId(connectPoint);
+ VlanId untaggedVlanId = interfaceService.getUntaggedVlanId(connectPoint);
+ VlanId nativeVlanId = interfaceService.getNativeVlanId(connectPoint);
return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
}
@@ -1395,9 +1343,9 @@
// group editing necessary for port up/down. Here we only process edge ports
// that are already configured.
ConnectPoint cp = new ConnectPoint(device.id(), port.number());
- VlanId untaggedVlan = getUntaggedVlanId(cp);
- VlanId nativeVlan = getNativeVlanId(cp);
- Set<VlanId> taggedVlans = getTaggedVlanId(cp);
+ VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp);
+ VlanId nativeVlan = interfaceService.getNativeVlanId(cp);
+ Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp);
if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
log.debug("Not handling port updated event for non-edge port (unconfigured) "
diff --git a/app/src/test/java/org/onosproject/segmentrouting/MockInterfaceService.java b/app/src/test/java/org/onosproject/segmentrouting/MockInterfaceService.java
index f8d04ca..17422d2 100644
--- a/app/src/test/java/org/onosproject/segmentrouting/MockInterfaceService.java
+++ b/app/src/test/java/org/onosproject/segmentrouting/MockInterfaceService.java
@@ -19,7 +19,7 @@
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.intf.Interface;
-import org.onosproject.net.intf.InterfaceServiceAdapter;
+import org.onosproject.net.intf.impl.InterfaceManager;
import java.util.Set;
import java.util.stream.Collectors;
@@ -27,7 +27,7 @@
/**
* Mock Interface Service.
*/
-public class MockInterfaceService extends InterfaceServiceAdapter {
+public class MockInterfaceService extends InterfaceManager {
private Set<Interface> interfaces;
MockInterfaceService(Set<Interface> interfaces) {