use of org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey 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.segmentrouting.storekey.VlanNextObjectiveStoreKey in project trellis-control by opennetworkinglab.
the class XconnectManager method activate.
@Activate
void activate() {
appId = coreService.registerApplication(APP_NAME);
codecService.registerCodec(XconnectDesc.class, new XconnectCodec());
KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(XconnectManager.class).register(XconnectKey.class).register(XconnectEndpoint.class).register(XconnectPortEndpoint.class).register(XconnectLoadBalancerEndpoint.class).register(VlanNextObjectiveStoreKey.class);
xconnectStore = storageService.<XconnectKey, Set<XconnectEndpoint>>consistentMapBuilder().withName("onos-sr-xconnect").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer.build())).build();
xConnectExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-xconnect-event", "%d", log));
xconnectStore.addListener(xconnectListener, xConnectExecutor);
xconnectNextObjStore = storageService.<XconnectKey, Integer>consistentMapBuilder().withName("onos-sr-xconnect-next").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer.build())).build();
xconnectMulticastNextStore = storageService.<VlanNextObjectiveStoreKey, Integer>consistentMapBuilder().withName("onos-sr-xconnect-l2multicast-next").withSerializer(Serializer.using(serializer.build())).build();
xconnectMulticastPortsStore = storageService.<VlanNextObjectiveStoreKey, List<PortNumber>>consistentMapBuilder().withName("onos-sr-xconnect-l2multicast-ports").withSerializer(Serializer.using(serializer.build())).build();
deviceEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-xconnect-device-event", "%d", log));
deviceService.addListener(deviceListener);
hostEventExecutor = Executors.newSingleThreadExecutor(groupedThreads("sr-xconnect-host-event", "%d", log));
hostService.addListener(hostListener);
portLoadBalancerCache = CacheBuilder.newBuilder().expireAfterWrite(WAIT_TIME_MS, TimeUnit.MILLISECONDS).removalListener((RemovalNotification<PortLoadBalancerId, XconnectKey> notification) -> log.debug("PortLoadBalancer cache removal event. portLoadBalancerId={}, xConnectKey={}", notification.getKey(), notification.getValue())).build();
portLoadBalancerExecutor = newScheduledThreadPool(1, groupedThreads("portLoadBalancerCacheWorker", "-%d", log));
// Let's schedule the cleanup of the cache
portLoadBalancerExecutor.scheduleAtFixedRate(portLoadBalancerCache::cleanUp, 0, WAIT_TIME_MS, TimeUnit.MILLISECONDS);
portLoadBalancerService.addListener(portLoadBalancerListener);
log.info("Started");
}
use of org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method createBcastGroupFromVlan.
/**
* Creates a single broadcast group from a given vlan id and list of ports.
*
* @param vlanId vlan id
* @param ports list of ports in the subnet
*/
public void createBcastGroupFromVlan(VlanId vlanId, Collection<PortNumber> ports) {
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
if (vlanNextObjStore.containsKey(key)) {
log.debug("Broadcast group for device {} and subnet {} exists", deviceId, vlanId);
return;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
int nextId = flowObjectiveService.allocateNextId();
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
ports.forEach(port -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (toPopVlan(port, vlanId)) {
tBuilder.popVlan();
}
tBuilder.setOutput(port);
nextObjBuilder.addTreatment(tBuilder.build());
});
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("createBroadcastGroupFromVlan installed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
log.warn("createBroadcastGroupFromVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = nextObjBuilder.add(context);
flowObjectiveService.next(deviceId, nextObj);
log.debug("createBcastGroupFromVlan: Submitted next objective {} " + "for vlan: {} in device {}", nextId, vlanId, deviceId);
vlanNextObjStore.put(key, nextId);
}
use of org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method removeBcastGroupFromVlan.
/**
* Removes a single broadcast group from a given vlan id.
* The group should be empty.
* @param deviceId device Id to remove the group
* @param portNum port number related to the group
* @param vlanId vlan id of the broadcast group to remove
* @param popVlan true if the TrafficTreatment involves pop vlan tag action
*/
public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);
if (!vlanNextObjStore.containsKey(key)) {
log.debug("Broadcast group for device {} and subnet {} does not exist", deviceId, vlanId);
return;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
int nextId = vlanNextObjStore.get(key);
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).withMeta(metadata);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (popVlan) {
tBuilder.popVlan();
}
tBuilder.setOutput(portNum);
nextObjBuilder.addTreatment(tBuilder.build());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("removeBroadcastGroupFromVlan removed " + "NextObj {} on {}", nextId, deviceId), (objective, error) -> {
log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = nextObjBuilder.remove(context);
flowObjectiveService.next(deviceId, nextObj);
log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}", nextId, deviceId);
vlanNextObjStore.remove(key, nextId);
}
use of org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey 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));
}
}
Aggregations