CORD-180 Changed the way how learnt hosts are suppressed in gerrit 9195
Change-Id: I086ba82147ef716c076cb6140b03da2886515c32
diff --git a/src/main/java/org/onosproject/segmentrouting/HostHandler.java b/src/main/java/org/onosproject/segmentrouting/HostHandler.java
index 132bff5..d5c93fd 100644
--- a/src/main/java/org/onosproject/segmentrouting/HostHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/HostHandler.java
@@ -38,7 +38,6 @@
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostService;
-import org.onosproject.provider.netcfghost.NetworkConfigHostProvider;
import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -351,16 +350,12 @@
* @return true if segment routing accepts the host
*/
private boolean accepted(Host host) {
- // Always accept configured hosts
- if (host.providerId().equals(NetworkConfigHostProvider.PROVIDER_ID)) {
- return true;
- }
-
SegmentRoutingAppConfig appConfig = srManager.cfgService
.getConfig(srManager.appId, SegmentRoutingAppConfig.class);
- boolean accepted = appConfig != null &&
- appConfig.hostLearning() &&
- !appConfig.suppressHost().contains(host.location());
+
+ boolean accepted = appConfig == null ||
+ (!appConfig.suppressHostByProvider().contains(host.providerId().id()) &&
+ !appConfig.suppressHostByPort().contains(host.location()));
if (!accepted) {
log.info("Ignore suppressed host {}", host.id());
}
diff --git a/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfig.java b/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfig.java
index 9bbcaa6..0eb2c8e 100644
--- a/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfig.java
+++ b/src/main/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfig.java
@@ -37,15 +37,17 @@
private static final String VROUTER_MACS = "vRouterMacs";
private static final String VROUTER_ID = "vRouterId";
private static final String SUPPRESS_SUBNET = "suppressSubnet";
- private static final String SUPPRESS_HOST = "suppressHost";
- private static final String HOST_LEARNING = "hostLearning";
+ private static final String SUPPRESS_HOST_BY_PORT = "suppressHostByPort";
+ // TODO We might want to move SUPPRESS_HOST_BY_PROVIDER to Component Config
+ private static final String SUPPRESS_HOST_BY_PROVIDER = "suppressHostByProvider";
@Override
public boolean isValid() {
return hasOnlyFields(VROUTER_MACS, VROUTER_ID, SUPPRESS_SUBNET,
- SUPPRESS_HOST, HOST_LEARNING) &&
+ SUPPRESS_HOST_BY_PORT, SUPPRESS_HOST_BY_PROVIDER) &&
vRouterMacs() != null && vRouterId() != null &&
- suppressSubnet() != null && suppressHost() != null;
+ suppressSubnet() != null && suppressHostByPort() != null &&
+ suppressHostByProvider() != null;
}
/**
@@ -181,18 +183,18 @@
}
/**
- * Gets names of ports to which SegmentRouting does not push host rules.
+ * Gets connect points to which SegmentRouting does not push host rules.
*
- * @return Set of port names, empty if not specified, or null
+ * @return Set of connect points, empty if not specified, or null
* if not valid
*/
- public Set<ConnectPoint> suppressHost() {
- if (!object.has(SUPPRESS_HOST)) {
+ public Set<ConnectPoint> suppressHostByPort() {
+ if (!object.has(SUPPRESS_HOST_BY_PORT)) {
return ImmutableSet.of();
}
ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
- ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST);
+ ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST_BY_PORT);
for (JsonNode jsonNode : arrayNode) {
String portName = jsonNode.asText(null);
if (portName == null) {
@@ -208,42 +210,61 @@
}
/**
- * Sets names of ports to which SegmentRouting does not push host rules.
+ * Sets connect points to which SegmentRouting does not push host rules.
*
- * @param suppressHost names of ports to which SegmentRouting does not push
+ * @param connectPoints connect points to which SegmentRouting does not push
* host rules
* @return this {@link SegmentRoutingAppConfig}
*/
- public SegmentRoutingAppConfig setSuppressHost(Set<ConnectPoint> suppressHost) {
- if (suppressHost == null) {
- object.remove(SUPPRESS_HOST);
+ public SegmentRoutingAppConfig setSuppressHostByPort(Set<ConnectPoint> connectPoints) {
+ if (connectPoints == null) {
+ object.remove(SUPPRESS_HOST_BY_PORT);
} else {
ArrayNode arrayNode = mapper.createArrayNode();
- suppressHost.forEach(connectPoint -> {
+ connectPoints.forEach(connectPoint -> {
arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port());
});
- object.set(SUPPRESS_HOST, arrayNode);
+ object.set(SUPPRESS_HOST_BY_PORT, arrayNode);
}
return this;
}
/**
- * Gets whether host learning is enabled or not.
+ * Gets provider names from which SegmentRouting does not learn host info.
*
- * @return true if enabled. false if disabled or not configured
+ * @return array of provider names that need to be ignored
*/
- public boolean hostLearning() {
- return object.has(HOST_LEARNING) && object.path(HOST_LEARNING).asBoolean();
+ public Set<String> suppressHostByProvider() {
+ if (!object.has(SUPPRESS_HOST_BY_PROVIDER)) {
+ return ImmutableSet.of();
+ }
+
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+ ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST_BY_PROVIDER);
+ for (JsonNode jsonNode : arrayNode) {
+ String providerName = jsonNode.asText(null);
+ if (providerName == null) {
+ return null;
+ }
+ builder.add(providerName);
+ }
+ return builder.build();
}
/**
- * Sets whether host learning is enabled or not.
+ * Sets provider names from which SegmentRouting does not learn host info.
*
- * @param enabled true if enabled
+ * @param providers set of provider names
* @return this {@link SegmentRoutingAppConfig}
*/
- public SegmentRoutingAppConfig setHostLearning(boolean enabled) {
- object.put(HOST_LEARNING, enabled);
+ public SegmentRoutingAppConfig setSuppressHostByProvider(Set<String> providers) {
+ if (providers == null) {
+ object.remove(SUPPRESS_HOST_BY_PROVIDER);
+ } else {
+ ArrayNode arrayNode = mapper.createArrayNode();
+ providers.forEach(arrayNode::add);
+ object.set(SUPPRESS_HOST_BY_PROVIDER, arrayNode);
+ }
return this;
}
@@ -253,8 +274,8 @@
.add("vRouterMacs", vRouterMacs())
.add("vRouterId", vRouterId())
.add("suppressSubnet", suppressSubnet())
- .add("suppressHost", suppressHost())
- .add("hostLearning", hostLearning())
+ .add("suppressHostByPort", suppressHostByPort())
+ .add("suppressHostByProvider", suppressHostByProvider())
.toString();
}
}