Search in sources :

Example 1 with TunnelSubscription

use of org.onosproject.incubator.net.tunnel.TunnelSubscription in project onos by opennetworkinglab.

the class DistributedTunnelStore method borrowTunnel.

@Override
public Collection<Tunnel> borrowTunnel(ApplicationId appId, TunnelName tunnelName, Annotations... annotations) {
    Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
    if (orderSet == null) {
        orderSet = new HashSet<TunnelSubscription>();
    }
    TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName, annotations);
    boolean isExist = orderSet.contains(order);
    Set<TunnelId> idSet = tunnelNameAsKeyMap.get(tunnelName);
    if (idSet == null || idSet.isEmpty()) {
        return Collections.emptySet();
    }
    Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
    for (TunnelId tunnelId : idSet) {
        Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
        if (Tunnel.State.ACTIVE.equals(result.state())) {
            tunnelSet.add(result);
        }
    }
    if (!tunnelSet.isEmpty() && !isExist) {
        orderSet.add(order);
        orderRelationship.put(appId, orderSet);
    }
    return tunnelSet;
}
Also used : Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) TunnelSubscription(org.onosproject.incubator.net.tunnel.TunnelSubscription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) HashSet(java.util.HashSet)

Example 2 with TunnelSubscription

use of org.onosproject.incubator.net.tunnel.TunnelSubscription in project onos by opennetworkinglab.

the class TunnelQuerySubscriptionCommand method doExecute.

@Override
protected void doExecute() {
    TunnelService service = get(TunnelService.class);
    ApplicationId applicationId = new DefaultApplicationId(1, consumerId);
    Collection<TunnelSubscription> tunnelSet = service.queryTunnelSubscription(applicationId);
    for (TunnelSubscription order : tunnelSet) {
        print(FMT, order.consumerId(), order.src(), order.dst(), order.type(), order.tunnelId());
    }
}
Also used : TunnelService(org.onosproject.incubator.net.tunnel.TunnelService) TunnelSubscription(org.onosproject.incubator.net.tunnel.TunnelSubscription) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Example 3 with TunnelSubscription

use of org.onosproject.incubator.net.tunnel.TunnelSubscription in project onos by opennetworkinglab.

the class DistributedTunnelStore method borrowTunnel.

@Override
public Collection<Tunnel> borrowTunnel(ApplicationId appId, TunnelEndPoint src, TunnelEndPoint dst, Type type, Annotations... annotations) {
    Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
    if (orderSet == null) {
        orderSet = new HashSet<TunnelSubscription>();
    }
    TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
    boolean isExist = orderSet.contains(order);
    if (!isExist) {
        orderSet.add(order);
    }
    orderRelationship.put(appId, orderSet);
    TunnelKey key = TunnelKey.tunnelKey(src, dst);
    Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
    if (idSet == null || idSet.isEmpty()) {
        return Collections.emptySet();
    }
    Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
    for (TunnelId tunnelId : idSet) {
        Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
        if (type.equals(result.type()) && Tunnel.State.ACTIVE.equals(result.state())) {
            tunnelSet.add(result);
        }
    }
    return tunnelSet;
}
Also used : Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) TunnelSubscription(org.onosproject.incubator.net.tunnel.TunnelSubscription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) HashSet(java.util.HashSet)

Example 4 with TunnelSubscription

use of org.onosproject.incubator.net.tunnel.TunnelSubscription in project onos by opennetworkinglab.

the class DistributedTunnelStore method activate.

@Activate
public void activate() {
    KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(MultiValuedTimestamp.class);
    tunnelIdAsKeyStore = storageService.<TunnelId, Tunnel>eventuallyConsistentMapBuilder().withName("all_tunnel").withSerializer(serializer).withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
    orderRelationship = storageService.<ApplicationId, Set<TunnelSubscription>>eventuallyConsistentMapBuilder().withName("type_tunnel").withSerializer(serializer).withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
    idGenerator = coreService.getIdGenerator(tunnelOpTopic);
    tunnelIdAsKeyStore.addListener(tunnelUpdateListener);
    log.info("Started");
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) KryoNamespace(org.onlab.util.KryoNamespace) TunnelSubscription(org.onosproject.incubator.net.tunnel.TunnelSubscription) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with TunnelSubscription

use of org.onosproject.incubator.net.tunnel.TunnelSubscription in project onos by opennetworkinglab.

the class DistributedTunnelStore method borrowTunnel.

@Override
public Tunnel borrowTunnel(ApplicationId appId, TunnelId tunnelId, Annotations... annotations) {
    Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
    if (orderSet == null) {
        orderSet = new HashSet<TunnelSubscription>();
    }
    TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null, annotations);
    Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
    if (result == null || Tunnel.State.INACTIVE.equals(result.state())) {
        return null;
    }
    orderSet.add(order);
    orderRelationship.put(appId, orderSet);
    return result;
}
Also used : Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) TunnelSubscription(org.onosproject.incubator.net.tunnel.TunnelSubscription)

Aggregations

TunnelSubscription (org.onosproject.incubator.net.tunnel.TunnelSubscription)6 DefaultTunnel (org.onosproject.incubator.net.tunnel.DefaultTunnel)4 Tunnel (org.onosproject.incubator.net.tunnel.Tunnel)4 HashSet (java.util.HashSet)3 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)3 KryoNamespace (org.onlab.util.KryoNamespace)1 ApplicationId (org.onosproject.core.ApplicationId)1 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)1 TunnelService (org.onosproject.incubator.net.tunnel.TunnelService)1 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)1 Activate (org.osgi.service.component.annotations.Activate)1