Search in sources :

Example 16 with Tunnel

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

the class DistributedTunnelStore method queryTunnel.

@Override
public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
    Collection<Tunnel> result = new HashSet<Tunnel>();
    TunnelKey key = TunnelKey.tunnelKey(src, dst);
    Set<TunnelId> tunnelIds = srcAndDstKeyMap.get(key);
    if (tunnelIds == null) {
        return Collections.emptySet();
    }
    for (TunnelId id : tunnelIds) {
        result.add(tunnelIdAsKeyStore.get(id));
    }
    return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
}
Also used : Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) HashSet(java.util.HashSet)

Example 17 with Tunnel

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

the class TunnelBorrowCommand method doExecute.

@Override
protected void doExecute() {
    Collection<Tunnel> tunnelSet = null;
    Tunnel.Type trueType = null;
    TunnelService service = get(TunnelService.class);
    ApplicationId appId = new DefaultApplicationId(1, consumerId);
    ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
    if (!isNull(src) && !isNull(dst) && !isNull(type)) {
        TunnelEndPoint srcPoint = null;
        TunnelEndPoint dstPoint = null;
        if ("MPLS".equals(type)) {
            trueType = Tunnel.Type.MPLS;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("VXLAN".equals(type)) {
            trueType = Tunnel.Type.VXLAN;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("GRE".equals(type)) {
            trueType = Tunnel.Type.GRE;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("VLAN".equals(type)) {
            trueType = Tunnel.Type.VLAN;
            String[] srcArray = src.split("-");
            String[] dstArray = dst.split("-");
            srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, null, OpticalLogicId.logicId(0), true);
            dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, null, OpticalLogicId.logicId(0), true);
        } else if ("ODUK".equals(type)) {
            trueType = Tunnel.Type.ODUK;
            String[] srcArray = src.split("-");
            String[] dstArray = dst.split("-");
            srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
            dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
        } else if ("OCH".equals(type)) {
            trueType = Tunnel.Type.OCH;
            String[] srcArray = src.split("-");
            String[] dstArray = dst.split("-");
            srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
            dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
        } else {
            print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
            return;
        }
        tunnelSet = service.borrowTunnel(appId, srcPoint, dstPoint, trueType);
    }
    if (!isNull(tunnelId)) {
        TunnelId id = TunnelId.valueOf(tunnelId);
        Tunnel tunnel = service.borrowTunnel(appId, id);
        tunnelSet = new HashSet<Tunnel>();
        tunnelSet.add(tunnel);
    }
    if (!isNull(tunnelName)) {
        TunnelName name = TunnelName.tunnelName(tunnelName);
        tunnelSet = service.borrowTunnel(appId, name);
    }
    for (Tunnel tunnel : tunnelSet) {
        print(FMT, tunnel.src(), tunnel.dst(), tunnel.type(), tunnel.state(), tunnel.providerId(), tunnel.tunnelName(), tunnel.groupId());
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) OpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) TunnelEndPoint(org.onosproject.incubator.net.tunnel.TunnelEndPoint) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) IpTunnelEndPoint(org.onosproject.incubator.net.tunnel.IpTunnelEndPoint) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) TunnelName(org.onosproject.incubator.net.tunnel.TunnelName) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) TunnelService(org.onosproject.incubator.net.tunnel.TunnelService) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId)

Example 18 with Tunnel

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

the class TunnelCreateCommand method doExecute.

@Override
protected void doExecute() {
    TunnelProvider service = get(TunnelProvider.class);
    ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
    TunnelEndPoint srcPoint = null;
    TunnelEndPoint dstPoint = null;
    Tunnel.Type trueType = null;
    if ("MPLS".equals(type)) {
        trueType = Tunnel.Type.MPLS;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("VLAN".equals(type)) {
        trueType = Tunnel.Type.VLAN;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, null, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, null, OpticalLogicId.logicId(0), true);
    } else if ("VXLAN".equals(type)) {
        trueType = Tunnel.Type.VXLAN;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("GRE".equals(type)) {
        trueType = Tunnel.Type.GRE;
        srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
        dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
    } else if ("ODUK".equals(type)) {
        trueType = Tunnel.Type.ODUK;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
    } else if ("OCH".equals(type)) {
        trueType = Tunnel.Type.OCH;
        String[] srcArray = src.split("/");
        String[] dstArray = dst.split("/");
        srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
        dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.TIMESLOT, OpticalLogicId.logicId(0), true);
    } else {
        print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
        return;
    }
    SparseAnnotations annotations = DefaultAnnotations.builder().set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth).build();
    TunnelDescription tunnel = new DefaultTunnelDescription(null, srcPoint, dstPoint, trueType, new GroupId(Integer.parseInt(groupId)), producerName, TunnelName.tunnelName(tunnelName), null, annotations);
    TunnelId tunnelId = service.tunnelAdded(tunnel);
    if (tunnelId == null) {
        error("Create tunnel failed.");
        return;
    }
    print(FMT, tunnelId.id());
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) TunnelProvider(org.onosproject.incubator.net.tunnel.TunnelProvider) OpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) TunnelEndPoint(org.onosproject.incubator.net.tunnel.TunnelEndPoint) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) IpTunnelEndPoint(org.onosproject.incubator.net.tunnel.IpTunnelEndPoint) TunnelDescription(org.onosproject.incubator.net.tunnel.TunnelDescription) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) GroupId(org.onosproject.core.GroupId) SparseAnnotations(org.onosproject.net.SparseAnnotations) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)

Example 19 with Tunnel

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

the class TunnelRemoveCommand method doExecute.

@Override
protected void doExecute() {
    TunnelDescription tunnel = null;
    TunnelProvider service = get(TunnelProvider.class);
    ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
    if (!isNull(src) && !isNull(dst) && !isNull(type)) {
        TunnelEndPoint srcPoint = null;
        TunnelEndPoint dstPoint = null;
        Tunnel.Type trueType = null;
        if ("MPLS".equals(type)) {
            trueType = Tunnel.Type.MPLS;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("VLAN".equals(type)) {
            trueType = Tunnel.Type.VLAN;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("VXLAN".equals(type)) {
            trueType = Tunnel.Type.VXLAN;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("GRE".equals(type)) {
            trueType = Tunnel.Type.GRE;
            srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
            dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
        } else if ("ODUK".equals(type)) {
            trueType = Tunnel.Type.ODUK;
            String[] srcArray = src.split("/");
            String[] dstArray = dst.split("/");
            srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
            dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
        } else if ("OCH".equals(type)) {
            trueType = Tunnel.Type.OCH;
            String[] srcArray = src.split("/");
            String[] dstArray = dst.split("/");
            srcPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(srcArray[0])), Optional.of(PortNumber.portNumber(srcArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
            dstPoint = new DefaultOpticalTunnelEndPoint(producerName, Optional.of(DeviceId.deviceId(dstArray[0])), Optional.of(PortNumber.portNumber(dstArray[1])), null, OpticalTunnelEndPoint.Type.LAMBDA, OpticalLogicId.logicId(0), true);
        } else {
            print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
            return;
        }
        tunnel = new DefaultTunnelDescription(null, srcPoint, dstPoint, trueType, null, producerName, null, null);
        service.tunnelRemoved(tunnel);
        return;
    }
    if (!isNull(tunnelId)) {
        TunnelId id = TunnelId.valueOf(tunnelId);
        tunnel = new DefaultTunnelDescription(id, null, null, null, null, producerName, null, null);
        service.tunnelRemoved(tunnel);
        return;
    }
    if (!isNull(type)) {
        Tunnel.Type trueType = null;
        Collection<Tunnel> tunnelSet = null;
        TunnelService tunnelService = get(TunnelService.class);
        if ("MPLS".equals(type)) {
            trueType = Tunnel.Type.MPLS;
        } else if ("VLAN".equals(type)) {
            trueType = Tunnel.Type.VLAN;
        } else if ("VXLAN".equals(type)) {
            trueType = Tunnel.Type.VXLAN;
        } else if ("GRE".equals(type)) {
            trueType = Tunnel.Type.GRE;
        } else if ("ODUK".equals(type)) {
            trueType = Tunnel.Type.ODUK;
        } else if ("OCH".equals(type)) {
            trueType = Tunnel.Type.OCH;
        } else {
            print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
            return;
        }
        tunnelSet = tunnelService.queryTunnel(trueType);
        if (tunnelSet != null) {
            for (Tunnel tunnelTemp : tunnelSet) {
                tunnel = new DefaultTunnelDescription(tunnelTemp.tunnelId(), null, null, null, null, producerName, null, null);
                service.tunnelRemoved(tunnel);
            }
        }
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) TunnelProvider(org.onosproject.incubator.net.tunnel.TunnelProvider) OpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) TunnelEndPoint(org.onosproject.incubator.net.tunnel.TunnelEndPoint) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) IpTunnelEndPoint(org.onosproject.incubator.net.tunnel.IpTunnelEndPoint) TunnelDescription(org.onosproject.incubator.net.tunnel.TunnelDescription) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) TunnelService(org.onosproject.incubator.net.tunnel.TunnelService) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultOpticalTunnelEndPoint(org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint) DefaultTunnelDescription(org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)

Example 20 with Tunnel

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

the class TunnelManager method removeTunnel.

@Override
public void removeTunnel(TunnelId tunnelId) {
    checkNotNull(tunnelId, TUNNNEL_ID_NULL);
    Tunnel tunnel = store.queryTunnel(tunnelId);
    if (tunnel != null) {
        store.deleteTunnel(tunnelId);
        if (tunnel.providerId() != null) {
            TunnelProvider provider = getProvider(tunnel.providerId());
            if (provider != null) {
                provider.releaseTunnel(tunnel);
            }
        } else {
            Set<ProviderId> ids = getProviders();
            for (ProviderId providerId : ids) {
                TunnelProvider provider = getProvider(providerId);
                provider.releaseTunnel(tunnel);
            }
        }
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) TunnelProvider(org.onosproject.incubator.net.tunnel.TunnelProvider) Tunnel(org.onosproject.incubator.net.tunnel.Tunnel) DefaultTunnel(org.onosproject.incubator.net.tunnel.DefaultTunnel)

Aggregations

Tunnel (org.onosproject.incubator.net.tunnel.Tunnel)23 DefaultTunnel (org.onosproject.incubator.net.tunnel.DefaultTunnel)18 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)15 ProviderId (org.onosproject.net.provider.ProviderId)12 TunnelProvider (org.onosproject.incubator.net.tunnel.TunnelProvider)9 HashSet (java.util.HashSet)5 DefaultOpticalTunnelEndPoint (org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint)5 IpTunnelEndPoint (org.onosproject.incubator.net.tunnel.IpTunnelEndPoint)5 OpticalTunnelEndPoint (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint)5 TunnelEndPoint (org.onosproject.incubator.net.tunnel.TunnelEndPoint)5 TunnelEvent (org.onosproject.incubator.net.tunnel.TunnelEvent)4 TunnelService (org.onosproject.incubator.net.tunnel.TunnelService)4 TunnelSubscription (org.onosproject.incubator.net.tunnel.TunnelSubscription)4 ArrayList (java.util.ArrayList)2 ApplicationId (org.onosproject.core.ApplicationId)2 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)2 DefaultTunnelDescription (org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)2 TunnelDescription (org.onosproject.incubator.net.tunnel.TunnelDescription)2 TunnelName (org.onosproject.incubator.net.tunnel.TunnelName)2 SparseAnnotations (org.onosproject.net.SparseAnnotations)2