mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 12:16:13 +02:00
Refactor DefaultRoutingHandler to avoid hitting 2000 lines limit
Change-Id: I426e7fc70dcc063bd5742f86ba1141adf6d1d94e
This commit is contained in:
parent
275af2c8ff
commit
5adc628bd3
@ -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.Lock;
|
||||
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 @@ public class DefaultRoutingHandler {
|
||||
* 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 @@ public class DefaultRoutingHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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 @@ public class DefaultRoutingHandler {
|
||||
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 @@ public class DefaultRoutingHandler {
|
||||
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
|
||||
//////////////////////////////////////
|
||||
@ -1884,49 +1830,6 @@ public class DefaultRoutingHandler {
|
||||
RETRY_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -1963,5 +1866,4 @@ public class DefaultRoutingHandler {
|
||||
prevRun = (thisRun == null) ? prevRun : thisRun;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,6 @@ import org.onosproject.net.flowobjective.ObjectiveContext;
|
||||
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 @@ public class RoutingRulePopulator {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user