Charles Chan
Committed by Charles Chan

Segment Routing refactoring

- Change name: McastEventHandler -> McastHandler
- Separate HostHandler from SRManager
- Move storekeys to a dedicated package
- Replace SRObjevtiveContext and BridgeTableObjectiveContext with DefaultObjectiveContext

Change-Id: Iab25529487004759105e5ba60c1d2a3852ac45e6
Showing 13 changed files with 84 additions and 105 deletions
......@@ -48,7 +48,7 @@ import org.onosproject.net.flowobjective.NextObjective;
import org.onosproject.net.mcast.McastEvent;
import org.onosproject.net.mcast.McastRouteInfo;
import org.onosproject.net.topology.TopologyService;
import org.onosproject.segmentrouting.grouphandler.McastNextObjectiveStoreKey;
import org.onosproject.segmentrouting.storekey.McastNextObjectiveStoreKey;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
......@@ -63,10 +63,10 @@ import java.util.Optional;
import java.util.Set;
/**
* Multicast event handler.
* Handles multicast-related events.
*/
public class McastEventHandler {
private static final Logger log = LoggerFactory.getLogger(McastEventHandler.class);
public class McastHandler {
private static final Logger log = LoggerFactory.getLogger(McastHandler.class);
private final SegmentRoutingManager srManager;
private final ApplicationId coreAppId;
private StorageService storageService;
......@@ -79,7 +79,7 @@ public class McastEventHandler {
*
* @param srManager Segment Routing manager
*/
public McastEventHandler(SegmentRoutingManager srManager) {
public McastHandler(SegmentRoutingManager srManager) {
coreAppId = srManager.coreService.getAppId(CoreService.CORE_APP_NAME);
this.srManager = srManager;
......
......@@ -23,7 +23,9 @@ import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flowobjective.DefaultFilteringObjective;
import org.onosproject.net.flowobjective.DefaultObjectiveContext;
import org.onosproject.net.flowobjective.FilteringObjective;
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
import org.slf4j.Logger;
......@@ -117,9 +119,11 @@ public class NetworkConfigEventHandler {
return;
}
getVRouterFlowObjBuilders(pendingAdd).forEach(foBuilder -> {
srManager.flowObjectiveService.
filter(deviceId, foBuilder.add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FILTER)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("vRouterMac filter for {} populated", pendingAdd),
(objective, error) ->
log.warn("Failed to populate vRouterMac filter for {}: {}", pendingAdd, error));
srManager.flowObjectiveService.filter(deviceId, foBuilder.add(context));
});
}
......@@ -128,9 +132,11 @@ public class NetworkConfigEventHandler {
return;
}
getVRouterFlowObjBuilders(pendingRemove).forEach(foBuilder -> {
srManager.flowObjectiveService.
filter(deviceId, foBuilder.remove(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FILTER)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("vRouterMac filter for {} revoked", pendingRemove),
(objective, error) ->
log.warn("Failed to revoke vRouterMac filter for {}: {}", pendingRemove, error));
srManager.flowObjectiveService.filter(deviceId, foBuilder.remove(context));
});
}
......
......@@ -24,6 +24,8 @@ import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flowobjective.DefaultObjectiveContext;
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
import org.onosproject.segmentrouting.config.DeviceConfiguration;
import org.onosproject.segmentrouting.grouphandler.NeighborSet;
......@@ -112,9 +114,11 @@ public class RoutingRulePopulator {
log.warn(e.getMessage() + " Aborting populateIpRuleForHost.");
return;
}
srManager.flowObjectiveService.
forward(deviceId, fwdBuilder.add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP rule for host {} populated", hostIp),
(objective, error) ->
log.warn("Failed to populate IP rule for host {}: {}", hostIp, error));
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
rulePopulationCounter.incrementAndGet();
}
......@@ -138,9 +142,11 @@ public class RoutingRulePopulator {
log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
return;
}
srManager.flowObjectiveService.
forward(deviceId, fwdBuilder.remove(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP rule for host {} revoked", hostIp),
(objective, error) ->
log.warn("Failed to revoke IP rule for host {}: {}", hostIp, error));
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
}
private ForwardingObjective.Builder getForwardingObjectiveBuilder(
......@@ -285,11 +291,11 @@ public class RoutingRulePopulator {
+ "for router IP/subnet {} in switch {}",
ipPrefix,
deviceId);
srManager.flowObjectiveService.
forward(deviceId,
fwdBuilder.
add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP rule for router {} populated", ipPrefix),
(objective, error) ->
log.warn("Failed to populate IP rule for router {}: {}", ipPrefix, error));
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
rulePopulationCounter.incrementAndGet();
return true;
......@@ -387,11 +393,11 @@ public class RoutingRulePopulator {
.makePermanent()).withSelector(selector)
.withPriority(SegmentRoutingService.DEFAULT_PRIORITY))
.withFlag(ForwardingObjective.Flag.SPECIFIC);
srManager.flowObjectiveService.
forward(deviceId,
fwdObjBuilder.
add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("MPLS rule for SID {} populated", segmentId),
(objective, error) ->
log.warn("Failed to populate MPLS rule for SID {}: {}", segmentId, error));
srManager.flowObjectiveService.forward(deviceId, fwdObjBuilder.add(context));
rulePopulationCounter.incrementAndGet();
}
......@@ -471,9 +477,9 @@ public class RoutingRulePopulator {
}
for (Port port : srManager.deviceService.getPorts(deviceId)) {
ConnectPoint cp = new ConnectPoint(deviceId, port.number());
ConnectPoint connectPoint = new ConnectPoint(deviceId, port.number());
// TODO: Handles dynamic port events when we are ready for dynamic config
if (!srManager.deviceConfiguration.suppressSubnet().contains(cp) &&
if (!srManager.deviceConfiguration.suppressSubnet().contains(connectPoint) &&
port.isEnabled()) {
Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number());
VlanId assignedVlan = (portSubnet == null)
......@@ -492,9 +498,11 @@ public class RoutingRulePopulator {
fob.withMeta(tt);
}
fob.permit().fromApp(srManager.appId);
srManager.flowObjectiveService.
filter(deviceId, fob.add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FILTER)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("Filter for {} populated", connectPoint),
(objective, error) ->
log.warn("Failed to populate filter for {}: {}", connectPoint, error));
srManager.flowObjectiveService.filter(deviceId, fob.add(context));
}
}
}
......@@ -537,11 +545,11 @@ public class RoutingRulePopulator {
.withPriority(SegmentRoutingService.HIGHEST_PRIORITY)
.makePermanent()
.fromApp(srManager.appId);
log.debug("Installing forwarding objective to punt port IP addresses");
srManager.flowObjectiveService.
forward(deviceId,
puntIp.add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP punt rule for {} populated", ipaddr),
(objective, error) ->
log.warn("Failed to populate IP punt rule for {}: {}", ipaddr, error));
srManager.flowObjectiveService.forward(deviceId, puntIp.add(context));
}
}
......@@ -585,14 +593,11 @@ public class RoutingRulePopulator {
.withPriority(SegmentRoutingService.FLOOD_PRIORITY)
.fromApp(srManager.appId)
.makePermanent();
srManager.flowObjectiveService.forward(
deviceId,
fob.add(new SRObjectiveContext(
deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)
)
);
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("Subnet broadcast rule for {} populated", subnet),
(objective, error) ->
log.warn("Failed to populate subnet broadcast rule for {}: {}", subnet, error));
srManager.flowObjectiveService.forward(deviceId, fob.add(context));
});
}
......@@ -618,11 +623,12 @@ public class RoutingRulePopulator {
.addCondition(Criteria.matchVlanId(vlanId))
.addCondition(Criteria.matchEthDst(MacAddress.NONE))
.withPriority(SegmentRoutingService.XCONNECT_PRIORITY);
fob.permit().fromApp(srManager.appId);
srManager.flowObjectiveService
.filter(deviceId, fob.add(new SRObjectiveContext(deviceId,
SRObjectiveContext.ObjectiveType.FILTER)));
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("XConnect filter for {} populated", connectPoint),
(objective, error) ->
log.warn("Failed to populate xconnect filter for {}: {}", connectPoint, error));
srManager.flowObjectiveService.filter(deviceId, fob.add(context));
});
});
}
......@@ -666,14 +672,11 @@ public class RoutingRulePopulator {
.withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
.fromApp(srManager.appId)
.makePermanent();
srManager.flowObjectiveService.forward(
deviceId,
fob.add(new SRObjectiveContext(
deviceId,
SRObjectiveContext.ObjectiveType.FORWARDING)
)
);
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("XConnect rule for {} populated", xConnects),
(objective, error) ->
log.warn("Failed to populate xconnect rule for {}: {}", xConnects, error));
srManager.flowObjectiveService.forward(deviceId, fob.add(context));
});
}
......
......@@ -53,6 +53,10 @@ import org.onosproject.net.link.LinkService;
import org.onosproject.segmentrouting.SegmentRoutingManager;
import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
import org.onosproject.segmentrouting.config.DeviceProperties;
import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey;
import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
import org.onosproject.segmentrouting.storekey.SubnetNextObjectiveStoreKey;
import org.onosproject.segmentrouting.storekey.XConnectNextObjectiveStoreKey;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.slf4j.Logger;
......
/*
* Copyright 2015-present Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.segmentrouting.grouphandler;
package org.onosproject.segmentrouting.storekey;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
......
/*
* Copyright 2015-present Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -14,11 +14,12 @@
* limitations under the License.
*/
package org.onosproject.segmentrouting.grouphandler;
package org.onosproject.segmentrouting.storekey;
import java.util.Objects;
import org.onosproject.net.DeviceId;
import org.onosproject.segmentrouting.grouphandler.NeighborSet;
/**
* Key of Neighborset next objective store.
......
/*
* Copyright 2015-present Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.segmentrouting.grouphandler;
package org.onosproject.segmentrouting.storekey;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......
/*
* Copyright 2015-present Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.segmentrouting;
package org.onosproject.segmentrouting.storekey;
import java.util.Objects;
......
/*
* Copyright 2015-present Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.segmentrouting.grouphandler;
package org.onosproject.segmentrouting.storekey;
import org.onlab.packet.IpPrefix;
import org.onosproject.net.DeviceId;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.segmentrouting.grouphandler;
package org.onosproject.segmentrouting.storekey;
import org.onlab.packet.VlanId;
import org.onosproject.net.DeviceId;
......
......@@ -13,43 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.segmentrouting;
import org.onosproject.net.DeviceId;
import org.onosproject.net.flowobjective.Objective;
import org.onosproject.net.flowobjective.ObjectiveContext;
import org.onosproject.net.flowobjective.ObjectiveError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Segment Routing Flow Objective Context.
* Key data structure of various stores used by Segment Routing.
*/
public class SRObjectiveContext implements ObjectiveContext {
enum ObjectiveType {
FILTER,
FORWARDING
}
private final DeviceId deviceId;
private final ObjectiveType type;
private static final Logger log = LoggerFactory
.getLogger(SegmentRoutingManager.class);
SRObjectiveContext(DeviceId deviceId, ObjectiveType type) {
this.deviceId = deviceId;
this.type = type;
}
@Override
public void onSuccess(Objective objective) {
log.debug("{} objective operation successful in device {}",
type.name(), deviceId);
}
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("{} objective {} operation failed with error: {} in device {}",
type.name(), objective, error, deviceId);
}
}
package org.onosproject.segmentrouting.storekey;
\ No newline at end of file
......