use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method createGroupFromMacVlan.
/**
* Create simple next objective for an indirect host mac/vlan. The treatments can include
* all outgoing actions that need to happen on the packet.
*
* @param macAddr the mac address of the host
* @param vlanId the vlan of the host
* @param treatment the actions to apply on the packets (should include outport)
* @param meta optional data to pass to the driver
* @return next objective ID
*/
public int createGroupFromMacVlan(MacAddress macAddr, VlanId vlanId, TrafficTreatment treatment, TrafficSelector meta) {
int nextId = flowObjectiveService.allocateNextId();
MacVlanNextObjectiveStoreKey key = new MacVlanNextObjectiveStoreKey(deviceId, macAddr, vlanId);
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.SIMPLE).addTreatment(treatment).fromApp(appId).withMeta(meta);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("createGroupFromMacVlan installed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
log.warn("createGroupFromMacVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = nextObjBuilder.add(context);
flowObjectiveService.next(deviceId, nextObj);
log.debug("createGroupFromMacVlan: Submited next objective {} in device {} " + "for host {}/{}", nextId, deviceId, macAddr, vlanId);
macVlanNextObjStore.put(key, nextId);
return nextId;
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class XconnectManager method populateFilter.
/**
* Populates filtering objectives for given XConnect.
*
* @param key XConnect store key
* @param endpoints XConnect endpoints
*/
private void populateFilter(XconnectKey key, Set<XconnectEndpoint> endpoints) {
// FIXME Improve the logic
// If port load balancer is not involved, use filtered port. Otherwise, use unfiltered port.
// The purpose is to make sure existing XConnect logic can still work on a configured port.
boolean filtered = endpoints.stream().map(ep -> getNextTreatment(key.deviceId(), ep, false)).allMatch(t -> t.type().equals(NextTreatment.Type.TREATMENT));
endpoints.stream().map(ep -> getPhysicalPorts(key.deviceId(), ep)).flatMap(Set::stream).forEach(port -> {
FilteringObjective.Builder filtObjBuilder = filterObjBuilder(key, port, filtered);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("XConnect FilterObj for {} on port {} populated", key, port), (objective, error) -> log.warn("Failed to populate XConnect FilterObj for {} on port {}: {}", key, port, error));
flowObjectiveService.filter(key.deviceId(), filtObjBuilder.add(context));
});
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class XconnectManager method revokeAcl.
/**
* Revokes ACL forwarding objectives for given XConnect.
*
* @param key XConnect store key
*/
private void revokeAcl(XconnectKey key) {
ForwardingObjective.Builder aclObjBuilder = aclObjBuilder(key.vlanId());
ObjectiveContext aclContext = new DefaultObjectiveContext((objective) -> log.debug("XConnect AclObj for {} populated", key), (objective, error) -> log.warn("Failed to populate XConnect AclObj for {}: {}", key, error));
flowObjectiveService.forward(key.deviceId(), aclObjBuilder.remove(aclContext));
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class XconnectManager method revokeL2Multicast.
/**
* Removes access ports from VLAN L2 multicast group on given deviceId.
*
* @param deviceId Device ID
* @param vlanId VLAN ID
* @param accessPorts List of access ports to be added into L2 multicast group
*/
private void revokeL2Multicast(DeviceId deviceId, VlanId vlanId, List<PortNumber> accessPorts) {
// Ensure enough rights to program pair device
if (!srService.shouldProgram(deviceId)) {
log.debug("Abort revoke L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER);
return;
}
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
int vlanMulticastNextId = getMulticastGroupNextObjectiveId(key);
if (vlanMulticastNextId == -1) {
return;
}
NextObjective.Builder vlanMulticastNextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.BROADCAST).fromApp(srService.appId()).withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).build()).withId(vlanMulticastNextId);
accessPorts.forEach(p -> {
TrafficTreatment.Builder egressAction = DefaultTrafficTreatment.builder();
// Do vlan popup action based on interface configuration
if (interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, p)).stream().noneMatch(i -> i.vlanTagged().contains(vlanId))) {
egressAction.popVlan();
}
egressAction.setOutput(p);
vlanMulticastNextObjBuilder.addTreatment(egressAction.build());
removeMulticastGroupPort(key, p);
});
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("L2 multicast group installed/updated. " + "NextObject Id {} on {} for subnet {} ", vlanMulticastNextId, deviceId, vlanId), (objective, error) -> log.warn("L2 multicast group failed to install/update. " + " NextObject Id {} on {} for subnet {} : {}", vlanMulticastNextId, deviceId, vlanId, error));
flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.removeFromExisting(context));
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class XconnectManager method revokeNext.
/**
* Revokes next objectives for given XConnect.
*
* @param key XConnect store key
* @param endpoints XConnect endpoints
* @param nextId next objective id
* @param nextFuture completable future for this next objective operation
*/
private void revokeNext(XconnectKey key, Set<XconnectEndpoint> endpoints, int nextId, CompletableFuture<ObjectiveError> nextFuture) {
ObjectiveContext context = new ObjectiveContext() {
@Override
public void onSuccess(Objective objective) {
log.debug("Previous NextObj for {} removed", key);
if (nextFuture != null) {
nextFuture.complete(null);
}
}
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to remove previous NextObj for {}: {}", key, error);
if (nextFuture != null) {
nextFuture.complete(error);
}
srService.invalidateNextObj(objective.id());
}
};
NextObjective.Builder nextObjBuilder = nextObjBuilder(key, endpoints, nextId);
if (nextObjBuilder == null) {
log.warn("Fail to revokeNext {}: {}", key, ERROR_NEXT_OBJ_BUILDER);
return;
}
// Release the port load balancer if present
endpoints.stream().filter(endpoint -> endpoint.type() == XconnectEndpoint.Type.LOAD_BALANCER).forEach(endpoint -> {
String portLoadBalancerKey = String.valueOf(((XconnectLoadBalancerEndpoint) endpoint).key());
portLoadBalancerService.release(new PortLoadBalancerId(key.deviceId(), Integer.parseInt(portLoadBalancerKey)), appId);
});
flowObjectiveService.next(key.deviceId(), nextObjBuilder.remove(context));
xconnectNextObjStore.remove(key);
}
Aggregations