use of org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler in project trellis-control by opennetworkinglab.
the class DefaultRoutingHandler method fixHashGroupsForRoute.
/**
* Edits hash groups in the src-switch (targetSw) of a route-path by
* calling the groupHandler to either add or remove buckets in an existing
* hash group.
*
* @param route a single list representing a route-path where the first element
* is the src-switch (targetSw) of the route-path and the
* second element is the dst-switch
* @param revoke true if buckets in the hash-groups need to be removed;
* false if buckets in the hash-groups need to be added
* @return true if the hash group editing is successful
*/
private boolean fixHashGroupsForRoute(ArrayList<DeviceId> route, boolean revoke) {
DeviceId targetSw = route.get(0);
if (route.size() < 2) {
log.warn("Cannot fixHashGroupsForRoute - no dstSw in route {}", route);
return false;
}
DeviceId destSw = route.get(1);
if (!seenBeforeRoutes.containsEntry(destSw, targetSw)) {
log.warn("Cannot fixHashGroupsForRoute {} -> {} has not been programmed before", targetSw, destSw);
return false;
}
log.debug("* processing fixHashGroupsForRoute: Target {} -> Dest {}", targetSw, destSw);
// figure out the new next hops at the targetSw towards the destSw
Set<DeviceId> nextHops = getNextHops(targetSw, destSw);
// call group handler to change hash group at targetSw
DefaultGroupHandler grpHandler = srManager.getGroupHandler(targetSw);
if (grpHandler == null) {
log.warn("Cannot find grouphandler for dev:{} .. aborting" + " {} hash group buckets for route:{} ", targetSw, (revoke) ? "revoke" : "repopulate", route);
return false;
}
log.debug("{} hash-groups buckets For Route {} -> {} to new next-hops {}", (revoke) ? "revoke" : "repopulating", targetSw, destSw, nextHops);
return (revoke) ? grpHandler.fixHashGroups(targetSw, nextHops, destSw, true) : grpHandler.fixHashGroups(targetSw, nextHops, destSw, false);
}
use of org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method getMplsForwardingObjective.
/**
* Returns a Forwarding Objective builder for the MPLS rule that references
* the desired Next Objective. Creates a DestinationSet that allows the
* groupHandler to create or find the required next objective.
*
* @param targetSw the target sw
* @param nextHops the set of next hops
* @param phpRequired true if penultimate-hop-popping is required
* @param isBos true if matched label is bottom-of-stack
* @param meta metadata for creating next objective
* @param routerIp the router ip representing the destination switch
* @param destSw the destination sw
* @return the mpls forwarding objective builder
*/
private ForwardingObjective.Builder getMplsForwardingObjective(DeviceId targetSw, Set<DeviceId> nextHops, boolean phpRequired, boolean isBos, TrafficSelector meta, IpAddress routerIp, int segmentId, DeviceId destSw) {
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.SPECIFIC);
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
DestinationSet ds = null;
DestinationSet.DestinationSetType dstType = null;
boolean simple = false;
if (phpRequired) {
// php case - pop should always be flow-action
log.debug("getMplsForwardingObjective: php required");
tbuilder.deferred().copyTtlIn();
if (isBos) {
if (routerIp.isIp4()) {
tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType());
} else {
tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType());
}
tbuilder.decNwTtl();
// standard case -> BoS == True; pop results in IP packet and forwarding
// is via an ECMP group
ds = DestinationSet.createTypePopBos(destSw);
} else {
tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()).decMplsTtl();
// double-label case -> BoS == False, pop results in MPLS packet
// depending on configuration we can ECMP this packet or choose one output
ds = DestinationSet.createTypePopNotBos(destSw);
if (!srManager.getMplsEcmp()) {
simple = true;
}
}
} else {
// swap with self case - SR CONTINUE
log.debug("getMplsForwardingObjective: swap with self");
tbuilder.deferred().decMplsTtl();
// swap results in MPLS packet with same BoS bit regardless of bit value
// depending on configuration we can ECMP this packet or choose one output
// differentiate here between swap with not bos or swap with bos
ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) : DestinationSet.createTypeSwapNotBos(segmentId, destSw);
if (!srManager.getMplsEcmp()) {
simple = true;
}
}
fwdBuilder.withTreatment(tbuilder.build());
log.debug("Trying to get a nextObjId for mpls rule on device:{} to ds:{}", targetSw, ds);
DefaultGroupHandler gh = srManager.getGroupHandler(targetSw);
if (gh == null) {
log.warn("getNextObjectiveId query - groupHandler for device {} " + "not found", targetSw);
return null;
}
Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>();
dstNextHops.put(destSw, nextHops);
int nextId = gh.getNextObjectiveId(ds, dstNextHops, meta, simple);
if (nextId <= 0) {
log.warn("No next objective in {} for ds: {}", targetSw, ds);
return null;
} else {
log.debug("nextObjId found:{} for mpls rule on device:{} to ds:{}", nextId, targetSw, ds);
}
fwdBuilder.nextStep(nextId);
return fwdBuilder;
}
use of org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method processDeviceAddedInternal.
private void processDeviceAddedInternal(DeviceId deviceId) {
// Irrespective of whether the local is leading the programming or not for this device,
// we need to create a SR-group-handler instance. This is because in a
// multi-instance setup, any instance can initiate forwarding/next-objectives
// for any switch (even if this instance is a SLAVE or not even connected
// to the switch). To handle this, a default-group-handler instance is necessary
// per switch.
log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
if (groupHandlerMap.get(deviceId) == null) {
DefaultGroupHandler groupHandler;
try {
groupHandler = DefaultGroupHandler.createGroupHandler(deviceId, appId, deviceConfiguration, linkService, flowObjectiveService, this);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting processDeviceAdded.");
return;
}
log.debug("updating groupHandlerMap with new grpHdlr for device: {}", deviceId);
groupHandlerMap.put(deviceId, groupHandler);
}
if (shouldProgram(deviceId)) {
defaultRoutingHandler.populatePortAddressingRules(deviceId);
DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
groupHandler.createGroupsFromVlanConfig();
routingRulePopulator.populateSubnetBroadcastRule(deviceId);
}
appCfgHandler.init(deviceId);
}
use of org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method updatePortVlanTreatment.
private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean pushVlan) {
DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
if (grpHandler == null) {
log.warn("Failed to retrieve group handler for device {}", deviceId);
return;
}
// Update filtering objective for a single port
routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false);
routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true);
if (getVlanNextObjectiveId(deviceId, vlanId) != -1) {
// Update L2IG bucket of the port
grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan);
} else {
log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
}
}
use of org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method updateVlanConfigInternal.
private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean pushVlan, boolean install) {
DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
if (grpHandler == null) {
log.warn("Failed to retrieve group handler for device {}", deviceId);
return;
}
// Update filtering objective for a single port
routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install);
// Update filtering objective for multicast ingress port
mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install);
int nextId = getVlanNextObjectiveId(deviceId, vlanId);
if (nextId != -1 && !install) {
// Remove L2 Bridging rule and L3 Unicast rule to the host
ScheduledFuture<?> future = hostEventExecutor.schedule(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install), 0, TimeUnit.SECONDS);
// only if there is no port configured on that VLAN ID
if (!getVlanPortMap(deviceId).containsKey(vlanId)) {
// Remove broadcast forwarding rule for the VLAN
routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
// Remove L2FG for VLAN
grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan);
} else {
// Remove a single port from L2FG
grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
}
// Before moving forward we have to be sure that processIntfVlanUpdatedEvent completed;
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
log.warn("Exception caught when executing updateVlanConfigInternal future");
}
// Remove L2IG of the port
grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan);
} else if (install) {
// Create L2IG of the port
grpHandler.createPortNextObjective(deviceId, portNum, vlanId, pushVlan);
// Create L2 Bridging rule and L3 Unicast rule to the host
hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install));
if (nextId != -1) {
// Add a single port to L2FG
grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
} else {
// Create L2FG for VLAN
grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum));
routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
}
} else {
log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
}
}
Aggregations