use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class XconnectManager method populateL2Multicast.
/**
* Populate L2 multicast rule on given deviceId that matches given mac, given vlan and
* output to given port's L2 mulitcast group.
*
* @param deviceId Device ID
* @param pairPort Pair port number
* @param vlanId VLAN ID
* @param accessPorts List of access ports to be added into L2 multicast group
*/
private void populateL2Multicast(DeviceId deviceId, PortNumber pairPort, VlanId vlanId, List<PortNumber> accessPorts) {
// Ensure enough rights to program pair device
if (!srService.shouldProgram(deviceId)) {
log.debug("Abort populate L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER);
return;
}
boolean multicastGroupExists = true;
int vlanMulticastNextId;
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
// Step 1 : Populate single homed access ports into vlan's L2 multicast group
NextObjective.Builder vlanMulticastNextObjBuilder = DefaultNextObjective.builder().withType(NextObjective.Type.BROADCAST).fromApp(srService.appId()).withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).matchEthDst(MacAddress.IPV4_MULTICAST).build());
vlanMulticastNextId = getMulticastGroupNextObjectiveId(key);
if (vlanMulticastNextId == -1) {
// Vlan's L2 multicast group doesn't exist; create it, update store and add pair port as sub-group
multicastGroupExists = false;
vlanMulticastNextId = flowObjectiveService.allocateNextId();
addMulticastGroupNextObjectiveId(key, vlanMulticastNextId);
vlanMulticastNextObjBuilder.addTreatment(DefaultTrafficTreatment.builder().setOutput(pairPort).build());
}
vlanMulticastNextObjBuilder.withId(vlanMulticastNextId);
int nextId = 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());
addMulticastGroupPort(key, p);
});
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("L2 multicast group installed/updated. " + "NextObject Id {} on {} for subnet {} ", nextId, deviceId, vlanId), (objective, error) -> log.warn("L2 multicast group failed to install/update. " + " NextObject Id {} on {} for subnet {} : {}", nextId, deviceId, vlanId, error));
if (!multicastGroupExists) {
flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.add(context));
// Step 2 : Populate ACL rule; selector = vlan + pair-port, output = vlan L2 multicast group
TrafficSelector.Builder multicastSelector = DefaultTrafficSelector.builder();
multicastSelector.matchEthType(Ethernet.TYPE_VLAN);
multicastSelector.matchInPort(pairPort);
multicastSelector.matchVlanId(vlanId);
ForwardingObjective.Builder vlanMulticastForwardingObj = DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(vlanMulticastNextId).withSelector(multicastSelector.build()).withPriority(100).fromApp(srService.appId()).makePermanent();
context = new DefaultObjectiveContext((objective) -> log.debug("L2 multicasting versatile rule for device {}, port/vlan {}/{} populated", deviceId, pairPort, vlanId), (objective, error) -> log.warn("Failed to populate L2 multicasting versatile rule for device {}, " + "ports/vlan {}/{}: {}", deviceId, pairPort, vlanId, error));
flowObjectiveService.forward(deviceId, vlanMulticastForwardingObj.add(context));
} else {
// L2_MULTICAST & BROADCAST are similar structure in subgroups; so going with BROADCAST type.
vlanMulticastNextObjBuilder.withType(NextObjective.Type.BROADCAST);
flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.addToExisting(context));
}
}
use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class XconnectManager method cleanupL2MulticastRule.
/**
* Cleans up VLAN L2 multicast group on given deviceId. ACL rules for the group will also be deleted.
* Normally multicast group is not removed if it contains access ports; which can be forced
* by "force" flag
*
* @param deviceId Device ID
* @param pairPort Pair port number
* @param vlanId VLAN ID
* @param force Forceful removal
*/
private void cleanupL2MulticastRule(DeviceId deviceId, PortNumber pairPort, VlanId vlanId, boolean force) {
// Ensure enough rights to program pair device
if (!srService.shouldProgram(deviceId)) {
log.debug("Abort cleanup L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER);
return;
}
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
// Ensure L2 multicast group doesn't contain access ports
if (hasAccessPortInMulticastGroup(key, pairPort) && !force) {
return;
}
// Load L2 multicast group details
int vlanMulticastNextId = getMulticastGroupNextObjectiveId(key);
if (vlanMulticastNextId == -1) {
return;
}
// Step 1 : Clear ACL rule; selector = vlan + pair-port, output = vlan L2 multicast group
TrafficSelector.Builder l2MulticastSelector = DefaultTrafficSelector.builder();
l2MulticastSelector.matchEthType(Ethernet.TYPE_VLAN);
l2MulticastSelector.matchInPort(pairPort);
l2MulticastSelector.matchVlanId(vlanId);
ForwardingObjective.Builder vlanMulticastForwardingObj = DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(vlanMulticastNextId).withSelector(l2MulticastSelector.build()).withPriority(100).fromApp(srService.appId()).makePermanent();
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("L2 multicasting rule for device {}, port/vlan {}/{} deleted", deviceId, pairPort, vlanId), (objective, error) -> log.warn("Failed to delete L2 multicasting rule for device {}, " + "ports/vlan {}/{}: {}", deviceId, pairPort, vlanId, error));
flowObjectiveService.forward(deviceId, vlanMulticastForwardingObj.remove(context));
// Step 2 : Clear L2 multicast group associated with vlan
NextObjective.Builder l2MulticastGroupBuilder = DefaultNextObjective.builder().withId(vlanMulticastNextId).withType(NextObjective.Type.BROADCAST).fromApp(srService.appId()).withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).matchEthDst(MacAddress.IPV4_MULTICAST).build()).addTreatment(DefaultTrafficTreatment.builder().popVlan().setOutput(pairPort).build());
context = new DefaultObjectiveContext((objective) -> log.debug("L2 multicast group with NextObject Id {} deleted on {} for subnet {} ", vlanMulticastNextId, deviceId, vlanId), (objective, error) -> log.warn("L2 multicast group with NextObject Id {} failed to delete on {} for subnet {} : {}", vlanMulticastNextId, deviceId, vlanId, error));
flowObjectiveService.next(deviceId, l2MulticastGroupBuilder.remove(context));
// Finally clear store.
removeMulticastGroup(key);
}
use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class XconnectManager method revokeFwd.
/**
* Revokes bridging forwarding objectives for given XConnect.
*
* @param key XConnect store key
* @param nextId next objective id
* @param fwdFuture completable future for this forwarding objective operation
*/
private void revokeFwd(XconnectKey key, int nextId, CompletableFuture<ObjectiveError> fwdFuture) {
ForwardingObjective.Builder fwdObjBuilder = fwdObjBuilder(key, nextId);
ObjectiveContext context = new ObjectiveContext() {
@Override
public void onSuccess(Objective objective) {
log.debug("Previous FwdObj for {} removed", key);
if (fwdFuture != null) {
fwdFuture.complete(null);
}
}
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to remove previous FwdObj for {}: {}", key, error);
if (fwdFuture != null) {
fwdFuture.complete(error);
}
}
};
flowObjectiveService.forward(key.deviceId(), fwdObjBuilder.remove(context));
}
use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method processSinglePortFiltersInternal.
private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum, boolean pushVlan, VlanId vlanId, boolean install, boolean update) {
boolean doTMAC = true;
if (!pushVlan) {
// Skip the tagged vlans belonging to an interface without an IP address
Set<Interface> ifaces = srManager.interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, portnum)).stream().filter(intf -> intf.vlanTagged().contains(vlanId) && intf.ipAddressesList().isEmpty()).collect(Collectors.toSet());
if (!ifaces.isEmpty()) {
log.debug("processSinglePortFiltersInternal: skipping TMAC for vlan {} at {}/{} - no IP", vlanId, deviceId, portnum);
doTMAC = false;
}
}
FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId, doTMAC, update);
if (fob == null) {
// error encountered during build
return false;
}
log.debug("{} 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));
}
return true;
}
use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method processSinglePortFilters.
/**
* Creates or removes filtering objectives for a single port. Should only be
* called by the master for a switch.
*
* @param deviceId device identifier
* @param portnum port identifier for port to be filtered
* @param install true to install the filtering objective, false to remove
* @return true if no errors occurred during the build of the filtering objective
*/
boolean processSinglePortFilters(DeviceId deviceId, PortNumber portnum, boolean install) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum);
VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Do not configure filter for edge ports where double-tagged hosts are connected.
if (taggedVlans.size() != 0) {
// Filter for tagged vlans
if (!srManager.interfaceService.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId -> processSinglePortFiltersInternal(deviceId, portnum, false, taggedVlanId, install, false))) {
return false;
}
if (nativeVlan != null) {
// Filter for native vlan
if (!processSinglePortFiltersInternal(deviceId, portnum, true, nativeVlan, install, false)) {
return false;
}
}
} else if (untaggedVlan != null) {
// Filter for untagged vlan
if (!processSinglePortFiltersInternal(deviceId, portnum, true, untaggedVlan, install, false)) {
return false;
}
} else if (!hasIPConfiguration(connectPoint)) {
// Filter for unconfigured upstream port, using INTERNAL_VLAN
if (!processSinglePortFiltersInternal(deviceId, portnum, true, srManager.getDefaultInternalVlan(), install, false)) {
return false;
}
// Filter for receiveing pseudowire traffic
if (!processSinglePortFiltersInternal(deviceId, portnum, false, srManager.getPwTransportVlan(), install, false)) {
return false;
}
}
return true;
}
Aggregations