use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method revokeIpRuleForRouter.
/**
* Revokes IP flow rules for the router IP address from given device.
*
* @param targetSw target switch from which the ipPrefix need to be removed
* @param ipPrefix the IP address of the destination router
* @return true if all rules are removed successfully, false otherwise
*/
private boolean revokeIpRuleForRouter(DeviceId targetSw, IpPrefix ipPrefix) {
TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix);
TrafficSelector selector = sbuilder.build();
TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build();
ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder().fromApp(srManager.appId).makePermanent().withSelector(selector).withTreatment(dummyTreatment).withPriority(getPriorityFromPrefix(ipPrefix)).withFlag(ForwardingObjective.Flag.SPECIFIC);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("IP rule for router {} revoked from {}", ipPrefix, targetSw), (objective, error) -> log.warn("Failed to revoke IP rule for router {} from {}: {}", ipPrefix, targetSw, error));
srManager.flowObjectiveService.forward(targetSw, fwdBuilder.remove(context));
return true;
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method revokeBridging.
/**
* Revoke a bridging rule on given deviceId that matches given mac, given vlan and
* output to given port.
*
* @param deviceId device ID
* @param port port
* @param mac mac address
* @param vlanId VLAN ID
* @return future that carries the flow objective if succeeded, null if otherwise
*/
CompletableFuture<Objective> revokeBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) {
ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, true);
if (fob == null) {
log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId);
return CompletableFuture.completedFuture(null);
}
CompletableFuture<Objective> future = new CompletableFuture<>();
ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
log.debug("Brigding rule for {}/{} revoked", mac, vlanId);
future.complete(objective);
}, (objective, error) -> {
log.warn("Failed to revoke bridging rule for {}/{}: {}", mac, vlanId, error);
future.complete(null);
});
srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
return future;
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method populateRoute.
/**
* Populates IP rules for a route that has direct connection to the switch.
* This method should not be invoked directly without going through DefaultRoutingHandler.
*
* @param deviceId device ID of the device that next hop attaches to
* @param prefix IP prefix of the route
* @param hostMac MAC address of the next hop
* @param hostVlanId Vlan ID of the nexthop
* @param outPort port where the next hop attaches to
* @param directHost host is of type direct or indirect
* @return future that carries the flow objective if succeeded, null if otherwise
*/
CompletableFuture<Objective> populateRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, boolean directHost) {
log.debug("Populate direct routing entry for route {} at {}:{}", prefix, deviceId, outPort);
ForwardingObjective.Builder fwdBuilder;
try {
fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, hostVlanId, outPort, null, null, directHost, false);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting direct populateRoute");
return CompletableFuture.completedFuture(null);
}
if (fwdBuilder == null) {
log.warn("Aborting host routing table entry due " + "to error for dev:{} route:{}", deviceId, prefix);
return CompletableFuture.completedFuture(null);
}
int nextId = fwdBuilder.add().nextId();
CompletableFuture<Objective> future = new CompletableFuture<>();
ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
log.debug("Direct routing rule for route {} populated. nextId={}", prefix, nextId);
future.complete(objective);
}, (objective, error) -> {
log.warn("Failed to populate direct routing rule for route {}: {}", prefix, error);
future.complete(null);
});
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
rulePopulationCounter.incrementAndGet();
return future;
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method processDoubleTaggedFilter.
/**
* Creates or removes filtering objectives for a double-tagged host on a port.
*
* @param deviceId device identifier
* @param portNum port identifier for port to be filtered
* @param outerVlan outer VLAN ID
* @param innerVlan inner VLAN ID
* @param install true to install the filtering objective, false to remove
*/
void processDoubleTaggedFilter(DeviceId deviceId, PortNumber portNum, VlanId outerVlan, VlanId innerVlan, boolean install) {
// We should trigger the removal of double tagged rules only when removing
// the filtering objective and no other hosts are connected to the same device port.
boolean cleanupDoubleTaggedRules = !anyDoubleTaggedHost(deviceId, portNum) && !install;
FilteringObjective.Builder fob = buildDoubleTaggedFilteringObj(deviceId, portNum, outerVlan, innerVlan, cleanupDoubleTaggedRules);
if (fob == null) {
// error encountered during build
return;
}
log.debug("{} double-tagged filtering objectives for dev/port: {}/{}", install ? "Installing" : "Removing", deviceId, portNum);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Filter for {}/{} {}", deviceId, portNum, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}", install ? "install" : "remove", deviceId, portNum, error));
if (install) {
srManager.flowObjectiveService.filter(deviceId, fob.add(context));
} else {
srManager.flowObjectiveService.filter(deviceId, fob.remove(context));
}
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class McastHandler method removePortFromDevice.
/**
* Removes a port from given multicast group on given device.
* This involves the update of L3 multicast group and multicast routing
* table entry.
*
* @param deviceId device ID
* @param port port to be added
* @param mcastIp multicast group
* @param assignedVlan assigned VLAN ID
* @return true if this is the last sink on this device
*/
private boolean removePortFromDevice(DeviceId deviceId, PortNumber port, IpAddress mcastIp, VlanId assignedVlan) {
// TODO trace
log.info("Removing {} on {}/{} and vlan {}", mcastIp, deviceId, port, assignedVlan);
McastStoreKey mcastStoreKey = new McastStoreKey(mcastIp, deviceId, assignedVlan);
// This device is not serving this multicast group
if (!mcastNextObjStore.containsKey(mcastStoreKey)) {
return true;
}
NextObjective nextObj = mcastNextObjStore.get(mcastStoreKey).value();
Set<PortNumber> existingPorts = mcastUtils.getPorts(nextObj.next());
// This port does not serve this multicast group
if (!existingPorts.contains(port)) {
if (!existingPorts.isEmpty()) {
log.debug("{} is not serving {} on port {}. Abort.", deviceId, mcastIp, port);
return false;
}
return true;
}
// Copy and modify the ImmutableSet
existingPorts = Sets.newHashSet(existingPorts);
existingPorts.remove(port);
NextObjective newNextObj;
ObjectiveContext context;
ForwardingObjective fwdObj;
if (existingPorts.isEmpty()) {
context = new DefaultObjectiveContext((objective) -> log.debug("Successfully remove {} on {}/{}, vlan {}", mcastIp, deviceId, port.toLong(), assignedVlan), (objective, error) -> log.warn("Failed to remove {} on {}/{}, vlan {}: {}", mcastIp, deviceId, port.toLong(), assignedVlan, error));
fwdObj = mcastUtils.fwdObjBuilder(mcastIp, assignedVlan, nextObj.id()).remove(context);
if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
log.debug("skip forward flowobjective removal for device: {}", deviceId);
} else {
srManager.flowObjectiveService.forward(deviceId, fwdObj);
}
mcastNextObjStore.remove(mcastStoreKey);
} else {
// Here we store the next objective with the remaining port
newNextObj = mcastUtils.nextObjBuilder(mcastIp, assignedVlan, existingPorts, nextObj.id()).removeFromExisting();
mcastNextObjStore.put(mcastStoreKey, newNextObj);
// Let's modify the next objective removing the bucket
newNextObj = mcastUtils.nextObjBuilder(mcastIp, assignedVlan, ImmutableSet.of(port), nextObj.id()).removeFromExisting();
if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
log.debug("skip next flowobjective update for device: {}", deviceId);
} else {
// no need to update the flow here since we have updated the next objective + group
// the existing flow will keep pointing to the updated nextobj
srManager.flowObjectiveService.next(deviceId, newNextObj);
}
}
return existingPorts.isEmpty();
}
Aggregations