mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 19:01:06 +02:00
clean up the SingleSwitchFibInstaller, added the predeactivate hook and modified unit test CORD-663
Change-Id: I8bf9dd4c7a6e9c42833a6f631bfceb85b7f3ddef
This commit is contained in:
parent
259847d20b
commit
a2e61a5eb0
@ -32,6 +32,7 @@ import org.onlab.packet.IpPrefix;
|
|||||||
import org.onlab.packet.MacAddress;
|
import org.onlab.packet.MacAddress;
|
||||||
import org.onlab.packet.VlanId;
|
import org.onlab.packet.VlanId;
|
||||||
import org.onlab.util.Tools;
|
import org.onlab.util.Tools;
|
||||||
|
import org.onosproject.app.ApplicationService;
|
||||||
import org.onosproject.cfg.ComponentConfigService;
|
import org.onosproject.cfg.ComponentConfigService;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
@ -88,6 +89,7 @@ import java.util.stream.Collectors;
|
|||||||
public class SingleSwitchFibInstaller {
|
public class SingleSwitchFibInstaller {
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private static final String APP_NAME = "org.onosproject.vrouter";
|
||||||
|
|
||||||
private static final int PRIORITY_OFFSET = 100;
|
private static final int PRIORITY_OFFSET = 100;
|
||||||
private static final int PRIORITY_MULTIPLIER = 5;
|
private static final int PRIORITY_MULTIPLIER = 5;
|
||||||
@ -118,6 +120,9 @@ public class SingleSwitchFibInstaller {
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected DeviceService deviceService;
|
protected DeviceService deviceService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected ApplicationService applicationService;
|
||||||
|
|
||||||
@Property(name = "routeToNextHop", boolValue = false,
|
@Property(name = "routeToNextHop", boolValue = false,
|
||||||
label = "Install a /32 route to each next hop")
|
label = "Install a /32 route to each next hop")
|
||||||
private boolean routeToNextHop = false;
|
private boolean routeToNextHop = false;
|
||||||
@ -133,6 +138,7 @@ public class SingleSwitchFibInstaller {
|
|||||||
|
|
||||||
private ApplicationId coreAppId;
|
private ApplicationId coreAppId;
|
||||||
private ApplicationId routerAppId;
|
private ApplicationId routerAppId;
|
||||||
|
private ApplicationId vrouterAppId;
|
||||||
|
|
||||||
// Reference count for how many times a next hop is used by a route
|
// Reference count for how many times a next hop is used by a route
|
||||||
private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create();
|
private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create();
|
||||||
@ -163,6 +169,7 @@ public class SingleSwitchFibInstaller {
|
|||||||
|
|
||||||
coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME);
|
coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME);
|
||||||
routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
|
routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
|
||||||
|
vrouterAppId = coreService.registerApplication(APP_NAME);
|
||||||
|
|
||||||
networkConfigRegistry.registerConfigFactory(mcastConfigFactory);
|
networkConfigRegistry.registerConfigFactory(mcastConfigFactory);
|
||||||
|
|
||||||
@ -173,6 +180,10 @@ public class SingleSwitchFibInstaller {
|
|||||||
|
|
||||||
updateConfig();
|
updateConfig();
|
||||||
|
|
||||||
|
applicationService.registerDeactivateHook(vrouterAppId, () -> {
|
||||||
|
this.cleanUp();
|
||||||
|
});
|
||||||
|
|
||||||
log.info("Started");
|
log.info("Started");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +213,17 @@ public class SingleSwitchFibInstaller {
|
|||||||
log.info("routeToNextHop set to {}", routeToNextHop);
|
log.info("routeToNextHop set to {}", routeToNextHop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//remove filtering objectives and routes before deactivate.
|
||||||
|
private void cleanUp() {
|
||||||
|
//clean up the routes.
|
||||||
|
for (Map.Entry<IpPrefix, IpAddress> routes: prefixToNextHop.entrySet()) {
|
||||||
|
deleteRoute(new ResolvedRoute(routes.getKey(), null, null));
|
||||||
|
}
|
||||||
|
//clean up the filtering objective for interfaces.
|
||||||
|
Set<Interface> intfs = getInterfaces();
|
||||||
|
processIntfFilters(false, intfs);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateConfig() {
|
private void updateConfig() {
|
||||||
RouterConfig routerConfig =
|
RouterConfig routerConfig =
|
||||||
networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS);
|
networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS);
|
||||||
@ -226,7 +248,12 @@ public class SingleSwitchFibInstaller {
|
|||||||
|
|
||||||
private void updateDevice() {
|
private void updateDevice() {
|
||||||
if (deviceId != null && deviceService.isAvailable(deviceId)) {
|
if (deviceId != null && deviceService.isAvailable(deviceId)) {
|
||||||
|
Set<Interface> intfs = getInterfaces();
|
||||||
|
processIntfFilters(true, intfs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<Interface> getInterfaces() {
|
||||||
Set<Interface> intfs;
|
Set<Interface> intfs;
|
||||||
if (interfaces.isEmpty()) {
|
if (interfaces.isEmpty()) {
|
||||||
intfs = interfaceService.getInterfaces();
|
intfs = interfaceService.getInterfaces();
|
||||||
@ -237,9 +264,7 @@ public class SingleSwitchFibInstaller {
|
|||||||
.filter(intf -> interfaces.contains(intf.name()))
|
.filter(intf -> interfaces.contains(intf.name()))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
return intfs;
|
||||||
processIntfFilters(true, intfs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRoute(ResolvedRoute route) {
|
private void updateRoute(ResolvedRoute route) {
|
||||||
|
@ -26,6 +26,7 @@ import org.onlab.packet.IpPrefix;
|
|||||||
import org.onlab.packet.MacAddress;
|
import org.onlab.packet.MacAddress;
|
||||||
import org.onlab.packet.VlanId;
|
import org.onlab.packet.VlanId;
|
||||||
import org.onosproject.TestApplicationId;
|
import org.onosproject.TestApplicationId;
|
||||||
|
import org.onosproject.app.ApplicationService;
|
||||||
import org.onosproject.cfg.ComponentConfigService;
|
import org.onosproject.cfg.ComponentConfigService;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
@ -102,12 +103,12 @@ public class SingleSwitchFibInstallerTest {
|
|||||||
private static final InterfaceIpAddress INTF2 =
|
private static final InterfaceIpAddress INTF2 =
|
||||||
InterfaceIpAddress.valueOf("192.168.20.2/24");
|
InterfaceIpAddress.valueOf("192.168.20.2/24");
|
||||||
|
|
||||||
|
|
||||||
private final Set<Interface> interfaces = Sets.newHashSet();
|
private final Set<Interface> interfaces = Sets.newHashSet();
|
||||||
private InterfaceService interfaceService;
|
private InterfaceService interfaceService;
|
||||||
private NetworkConfigService networkConfigService;
|
private NetworkConfigService networkConfigService;
|
||||||
private NetworkConfigRegistry networkConfigRegistry;
|
private NetworkConfigRegistry networkConfigRegistry;
|
||||||
private FlowObjectiveService flowObjectiveService;
|
private FlowObjectiveService flowObjectiveService;
|
||||||
|
private ApplicationService applicationService;
|
||||||
private DeviceService deviceService;
|
private DeviceService deviceService;
|
||||||
private static final ApplicationId APPID = TestApplicationId.create("foo");
|
private static final ApplicationId APPID = TestApplicationId.create("foo");
|
||||||
|
|
||||||
@ -132,6 +133,8 @@ public class SingleSwitchFibInstallerTest {
|
|||||||
networkConfigService = createMock(NetworkConfigService.class);
|
networkConfigService = createMock(NetworkConfigService.class);
|
||||||
networkConfigRegistry = createMock(NetworkConfigRegistry.class);
|
networkConfigRegistry = createMock(NetworkConfigRegistry.class);
|
||||||
flowObjectiveService = createMock(FlowObjectiveService.class);
|
flowObjectiveService = createMock(FlowObjectiveService.class);
|
||||||
|
applicationService = createNiceMock(ApplicationService.class);
|
||||||
|
replay(applicationService);
|
||||||
deviceService = new TestDeviceService();
|
deviceService = new TestDeviceService();
|
||||||
CoreService coreService = createNiceMock(CoreService.class);
|
CoreService coreService = createNiceMock(CoreService.class);
|
||||||
expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
|
expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
|
||||||
@ -141,6 +144,7 @@ public class SingleSwitchFibInstallerTest {
|
|||||||
sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
|
sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
|
||||||
sSfibInstaller.interfaceService = interfaceService;
|
sSfibInstaller.interfaceService = interfaceService;
|
||||||
sSfibInstaller.flowObjectiveService = flowObjectiveService;
|
sSfibInstaller.flowObjectiveService = flowObjectiveService;
|
||||||
|
sSfibInstaller.applicationService = applicationService;
|
||||||
sSfibInstaller.coreService = coreService;
|
sSfibInstaller.coreService = coreService;
|
||||||
sSfibInstaller.routeService = new TestRouteService();
|
sSfibInstaller.routeService = new TestRouteService();
|
||||||
sSfibInstaller.deviceService = deviceService;
|
sSfibInstaller.deviceService = deviceService;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user