use of org.onosproject.incubator.net.tunnel.TunnelId in project onos by opennetworkinglab.
the class TunnelQueryCommand method doExecute.
@Override
protected void doExecute() {
Tunnel.Type trueType = null;
TunnelService service = get(TunnelService.class);
ProviderId producerName = new ProviderId("default", "org.onosproject.provider.tunnel.default");
Collection<Tunnel> tunnelSet = null;
if (isNull(src) && isNull(dst) && isNull(type) && isNull(tunnelId)) {
tunnelSet = service.queryAllTunnels();
}
if (!isNull(src) && !isNull(dst) && !isNull(type)) {
TunnelEndPoint srcPoint = null;
TunnelEndPoint dstPoint = null;
if ("MPLS".equals(type) || "VXLAN".equals(type) || "GRE".equals(type)) {
srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
} else if ("VLAN".equals(type)) {
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)) {
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)) {
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.queryTunnel(srcPoint, dstPoint);
}
if (!isNull(type)) {
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 = service.queryTunnel(trueType);
}
if (!isNull(tunnelId)) {
TunnelId id = TunnelId.valueOf(tunnelId);
Tunnel tunnel = service.queryTunnel(id);
tunnelSet = new HashSet<Tunnel>();
tunnelSet.add(tunnel);
}
if (tunnelSet != null) {
for (Tunnel tunnel : tunnelSet) {
print(FMT, tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(), tunnel.type(), tunnel.state(), tunnel.providerId(), tunnel.tunnelName(), tunnel.groupId(), showPath(tunnel.path()), annotations(tunnel.annotations()));
}
}
}
use of org.onosproject.incubator.net.tunnel.TunnelId in project onos by opennetworkinglab.
the class TunnelManager method downTunnel.
@Override
public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
// TODO: producerId to check if really required to consider while deleting the tunnel.
checkNotNull(tunnelId, TUNNNEL_ID_NULL);
Tunnel tunnel = store.queryTunnel(tunnelId);
if (tunnel != null) {
TunnelId updtTunnelId = store.createOrUpdateTunnel(tunnel, State.INACTIVE);
if (updtTunnelId != null) {
Set<ProviderId> ids = getProviders();
for (ProviderId providerId : ids) {
TunnelProvider provider = getProvider(providerId);
provider.releaseTunnel(tunnel);
}
}
return true;
}
return false;
}
use of org.onosproject.incubator.net.tunnel.TunnelId in project onos by opennetworkinglab.
the class DistributedTunnelStore method deleteTunnel.
@Override
public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
TunnelKey key = TunnelKey.tunnelKey(src, dst);
Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
if (idSet == null) {
return;
}
Tunnel deletedTunnel = null;
TunnelEvent event = null;
List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
for (TunnelId id : idSet) {
deletedTunnel = tunnelIdAsKeyStore.get(id);
if (producerName == null || producerName.equals(deletedTunnel.providerId())) {
tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, deletedTunnel);
ls.add(event);
}
}
if (!ls.isEmpty()) {
notifyDelegate(ls);
}
}
use of org.onosproject.incubator.net.tunnel.TunnelId in project onos by opennetworkinglab.
the class DistributedTunnelStore method deleteTunnel.
@Override
public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
TunnelKey key = TunnelKey.tunnelKey(src, dst);
Set<TunnelId> idSet = srcAndDstKeyMap.get(key);
if (idSet == null) {
return;
}
Tunnel deletedTunnel = null;
TunnelEvent event = null;
List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
for (TunnelId id : idSet) {
deletedTunnel = tunnelIdAsKeyStore.get(id);
if (type.equals(deletedTunnel.type()) && (producerName == null || producerName.equals(deletedTunnel.providerId()))) {
tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED, deletedTunnel);
ls.add(event);
}
}
if (!ls.isEmpty()) {
notifyDelegate(ls);
}
}
use of org.onosproject.incubator.net.tunnel.TunnelId 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;
}
Aggregations