Refactor DefaultRoutingHandler to avoid hitting 2000 lines limit
Change-Id: I426e7fc70dcc063bd5742f86ba1141adf6d1d94e
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
index 5179ded..2d494c3 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java
+++ b/apps/segmentrouting/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;
@@ -60,7 +59,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;
@@ -435,10 +433,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");
@@ -939,7 +935,6 @@
}
}
-
// To save on ECMP groups
// avoid MPLS rules in non-edge-devices to non-edge-devices
// avoid MPLS transit rules in edge-devices
@@ -1182,7 +1177,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);
@@ -1770,54 +1764,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
//////////////////////////////////////
@@ -1843,49 +1789,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.
@@ -1921,5 +1824,4 @@
prevRun = (thisRun == null) ? prevRun : thisRun;
}
}
-
}
diff --git a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/EdgePair.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/EdgePair.java
new file mode 100644
index 0000000..571e87f
--- /dev/null
+++ b/apps/segmentrouting/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/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/PortFilterInfo.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/PortFilterInfo.java
new file mode 100644
index 0000000..75c12d6
--- /dev/null
+++ b/apps/segmentrouting/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/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index ef9e279..ea730aa 100644
--- a/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/apps/segmentrouting/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -47,7 +47,6 @@
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.net.flowobjective.ObjectiveError;
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;
@@ -922,8 +921,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);
}
/**