Refactor DefaultRoutingHandler to avoid hitting 2000 lines limit
Change-Id: I426e7fc70dcc063bd5742f86ba1141adf6d1d94e
diff --git a/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java b/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
index c813410..0d25c10 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.segmentrouting;
-import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
@@ -62,7 +61,6 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Stream;
-import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.Executors.newScheduledThreadPool;
import static org.onlab.util.Tools.groupedThreads;
@@ -432,10 +430,8 @@
* seen link
*/
// TODO This method should be refactored into three separated methods
- public void populateRoutingRulesForLinkStatusChange(Link linkDown,
- Link linkUp,
- DeviceId switchDown,
- boolean seenBefore) {
+ public void populateRoutingRulesForLinkStatusChange(Link linkDown, Link linkUp,
+ DeviceId switchDown, boolean seenBefore) {
if (Stream.of(linkDown, linkUp, switchDown).filter(Objects::nonNull)
.count() != 1) {
log.warn("Only one event can be handled for link status change .. aborting");
@@ -946,7 +942,6 @@
}
}
-
// To save on ECMP groups
// avoid MPLS rules in non-edge-devices to non-edge-devices
// avoid MPLS transit rules in edge-devices
@@ -1264,7 +1259,6 @@
void purgeEcmpGraph(DeviceId deviceId) {
statusLock.lock();
try {
-
if (populationStatus == Status.STARTED) {
log.warn("Previous rule population is not finished. Cannot"
+ " proceeed with purgeEcmpGraph for {}", deviceId);
@@ -1812,54 +1806,6 @@
return ImmutableSet.of(); //no next-hops found
}
- /**
- * Represents two devices that are paired by configuration. An EdgePair for
- * (dev1, dev2) is the same as as EdgePair for (dev2, dev1)
- */
- protected final class EdgePair {
- DeviceId dev1;
- DeviceId dev2;
-
- EdgePair(DeviceId dev1, DeviceId dev2) {
- this.dev1 = dev1;
- this.dev2 = dev2;
- }
-
- boolean includes(DeviceId dev) {
- return dev1.equals(dev) || dev2.equals(dev);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof EdgePair)) {
- return false;
- }
- EdgePair that = (EdgePair) o;
- return ((this.dev1.equals(that.dev1) && this.dev2.equals(that.dev2)) ||
- (this.dev1.equals(that.dev2) && this.dev2.equals(that.dev1)));
- }
-
- @Override
- public int hashCode() {
- if (dev1.toString().compareTo(dev2.toString()) <= 0) {
- return Objects.hash(dev1, dev2);
- } else {
- return Objects.hash(dev2, dev1);
- }
- }
-
- @Override
- public String toString() {
- return toStringHelper(this)
- .add("Dev1", dev1)
- .add("Dev2", dev2)
- .toString();
- }
- }
-
//////////////////////////////////////
// Filtering rule creation
//////////////////////////////////////
@@ -1885,49 +1831,6 @@
}
/**
- * Utility class used to temporarily store information about the ports on a
- * device processed for filtering objectives.
- */
- public final class PortFilterInfo {
- int disabledPorts = 0, errorPorts = 0, filteredPorts = 0;
-
- public PortFilterInfo(int disabledPorts, int errorPorts,
- int filteredPorts) {
- this.disabledPorts = disabledPorts;
- this.filteredPorts = filteredPorts;
- this.errorPorts = errorPorts;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(disabledPorts, filteredPorts, errorPorts);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if ((obj == null) || (!(obj instanceof PortFilterInfo))) {
- return false;
- }
- PortFilterInfo other = (PortFilterInfo) obj;
- return ((disabledPorts == other.disabledPorts) &&
- (filteredPorts == other.filteredPorts) &&
- (errorPorts == other.errorPorts));
- }
-
- @Override
- public String toString() {
- MoreObjects.ToStringHelper helper = toStringHelper(this)
- .add("disabledPorts", disabledPorts)
- .add("errorPorts", errorPorts)
- .add("filteredPorts", filteredPorts);
- return helper.toString();
- }
- }
-
- /**
* RetryFilters populates filtering objectives for a device and keeps retrying
* till the number of ports filtered are constant for a predefined number
* of attempts.
@@ -1963,5 +1866,4 @@
prevRun = (thisRun == null) ? prevRun : thisRun;
}
}
-
}
diff --git a/app/src/main/java/org/onosproject/segmentrouting/EdgePair.java b/app/src/main/java/org/onosproject/segmentrouting/EdgePair.java
new file mode 100644
index 0000000..571e87f
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/EdgePair.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.segmentrouting;
+
+import org.onosproject.net.DeviceId;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Represents two devices that are paired by configuration. An EdgePair for
+ * (dev1, dev2) is the same as as EdgePair for (dev2, dev1)
+ */
+public final class EdgePair {
+ DeviceId dev1;
+ DeviceId dev2;
+
+ EdgePair(DeviceId dev1, DeviceId dev2) {
+ this.dev1 = dev1;
+ this.dev2 = dev2;
+ }
+
+ boolean includes(DeviceId dev) {
+ return dev1.equals(dev) || dev2.equals(dev);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof EdgePair)) {
+ return false;
+ }
+ EdgePair that = (EdgePair) o;
+ return ((this.dev1.equals(that.dev1) && this.dev2.equals(that.dev2)) ||
+ (this.dev1.equals(that.dev2) && this.dev2.equals(that.dev1)));
+ }
+
+ @Override
+ public int hashCode() {
+ if (dev1.toString().compareTo(dev2.toString()) <= 0) {
+ return Objects.hash(dev1, dev2);
+ } else {
+ return Objects.hash(dev2, dev1);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("Dev1", dev1)
+ .add("Dev2", dev2)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/onosproject/segmentrouting/PortFilterInfo.java b/app/src/main/java/org/onosproject/segmentrouting/PortFilterInfo.java
new file mode 100644
index 0000000..75c12d6
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/PortFilterInfo.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.segmentrouting;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Utility class used to temporarily store information about the ports on a
+ * device processed for filtering objectives.
+ */
+public final class PortFilterInfo {
+ int disabledPorts = 0, errorPorts = 0, filteredPorts = 0;
+
+ public PortFilterInfo(int disabledPorts, int errorPorts,
+ int filteredPorts) {
+ this.disabledPorts = disabledPorts;
+ this.filteredPorts = filteredPorts;
+ this.errorPorts = errorPorts;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(disabledPorts, filteredPorts, errorPorts);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || (!(obj instanceof PortFilterInfo))) {
+ return false;
+ }
+ PortFilterInfo other = (PortFilterInfo) obj;
+ return ((disabledPorts == other.disabledPorts) &&
+ (filteredPorts == other.filteredPorts) &&
+ (errorPorts == other.errorPorts));
+ }
+
+ @Override
+ public String toString() {
+ MoreObjects.ToStringHelper helper = toStringHelper(this)
+ .add("disabledPorts", disabledPorts)
+ .add("errorPorts", errorPorts)
+ .add("filteredPorts", filteredPorts);
+ return helper.toString();
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index 77103f1..d00a258 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -34,7 +34,6 @@
import org.onosproject.net.flowobjective.ObjectiveError;
import org.onosproject.net.intf.Interface;
import org.onosproject.net.packet.PacketPriority;
-import org.onosproject.segmentrouting.DefaultRoutingHandler.PortFilterInfo;
import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
import org.onosproject.segmentrouting.config.DeviceConfiguration;
import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
@@ -933,8 +932,7 @@
}
log.debug("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}",
deviceId, disabledPorts, errorPorts, filteredPorts);
- return srManager.defaultRoutingHandler.new PortFilterInfo(disabledPorts,
- errorPorts, filteredPorts);
+ return new PortFilterInfo(disabledPorts, errorPorts, filteredPorts);
}
/**