use of org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint in project trellis-control by opennetworkinglab.
the class XconnectAddCommand method doExecute.
@Override
protected void doExecute() {
DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
VlanId vlanId = VlanId.vlanId(vlanIdStr);
XconnectEndpoint ep1 = XconnectEndpoint.fromString(ep1Str);
XconnectEndpoint ep2 = XconnectEndpoint.fromString(ep2Str);
Set<XconnectEndpoint> endpoints = Sets.newHashSet(ep1, ep2);
XconnectService xconnectService = get(XconnectService.class);
xconnectService.addOrUpdateXconnect(deviceId, vlanId, endpoints);
}
use of org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint 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.segmentrouting.xconnect.api.XconnectEndpoint in project trellis-control by opennetworkinglab.
the class XconnectManager method populateXConnect.
/**
* Populates XConnect groups and flows for given key.
*
* @param key XConnect key
* @param endpoints a set of endpoints to be cross-connected
*/
private void populateXConnect(XconnectKey key, Set<XconnectEndpoint> endpoints) {
if (!srService.shouldProgram(key.deviceId())) {
log.debug("Abort populating XConnect {}: {}", key, ERROR_NOT_LEADER);
return;
}
int nextId = populateNext(key, endpoints);
if (nextId == -1) {
log.warn("Fail to populateXConnect {}: {}", key, ERROR_NEXT_ID);
return;
}
populateFilter(key, endpoints);
populateFwd(key, nextId);
populateAcl(key);
}
use of org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint 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);
}
use of org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint 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");
}
Aggregations