jcc | d869723 | 2015-05-05 14:42:23 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014-2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.cli.net; |
| 17 | |
| 18 | import java.util.Optional; |
| 19 | |
| 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.DefaultApplicationId; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.provider.ProviderId; |
| 29 | import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint; |
| 30 | import org.onosproject.net.tunnel.IpTunnelEndPoint; |
| 31 | import org.onosproject.net.tunnel.OpticalLogicId; |
| 32 | import org.onosproject.net.tunnel.OpticalTunnelEndPoint; |
| 33 | import org.onosproject.net.tunnel.TunnelEndPoint; |
| 34 | import org.onosproject.net.tunnel.TunnelService; |
| 35 | |
| 36 | /** |
| 37 | * Returns all tunnels between specific source tunnel end point and specific |
| 38 | * destination tunnel end point. Supports for IP address and optical as tunnel |
| 39 | * end point now. It's used by consumers. |
| 40 | */ |
| 41 | @Command(scope = "onos", name = "return-tunnels", |
| 42 | description = "Returns all tunnels between specific source tunnel end point and specific " |
| 43 | + " destination tunnel end point. Supports for IP address and optical as tunnel end point now." |
| 44 | + " It's used by consumers.") |
| 45 | public class ReturnTunnelCommand extends AbstractShellCommand { |
| 46 | @Argument(index = 0, name = "consumerId", description = "consumer id means application id.", |
| 47 | required = true, multiValued = false) |
| 48 | String consumerId = null; |
| 49 | @Argument(index = 1, name = "src", description = "Source tunnel point." |
| 50 | + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now." |
| 51 | + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber." |
| 52 | + " Otherwise src means IP address.", required = true, multiValued = false) |
| 53 | String src = null; |
| 54 | @Argument(index = 2, name = "dst", description = "Destination tunnel point." |
| 55 | + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now." |
| 56 | + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber." |
| 57 | + " Otherwise dst means IP address.", required = true, multiValued = false) |
| 58 | String dst = null; |
| 59 | |
| 60 | @Argument(index = 3, name = "type", description = "The type of tunnels," |
| 61 | + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false) |
| 62 | String type = null; |
| 63 | |
| 64 | @Override |
| 65 | protected void execute() { |
| 66 | TunnelService service = get(TunnelService.class); |
| 67 | ApplicationId appId = new DefaultApplicationId(1, consumerId); |
| 68 | ProviderId producerName = new ProviderId("default", |
| 69 | "org.onosproject.provider.tunnel.default"); |
| 70 | TunnelEndPoint srcPoint = null; |
| 71 | TunnelEndPoint dstPoint = null; |
| 72 | if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type) |
| 73 | || "GRE".equals(type)) { |
| 74 | srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src)); |
| 75 | dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst)); |
| 76 | } else if ("ODUK".equals(type) || "OCH".equals(type)) { |
| 77 | String[] srcArray = src.split("-"); |
| 78 | String[] dstArray = dst.split("-"); |
| 79 | srcPoint = new DefaultOpticalTunnelEndPoint( |
| 80 | producerName, |
| 81 | Optional.of(DeviceId |
| 82 | .deviceId(srcArray[0])), |
| 83 | Optional.of(PortNumber |
| 84 | .portNumber(srcArray[1])), |
| 85 | null, |
| 86 | OpticalTunnelEndPoint.Type.LAMBDA, |
| 87 | OpticalLogicId |
| 88 | .logicId(0), |
| 89 | true); |
| 90 | dstPoint = new DefaultOpticalTunnelEndPoint( |
| 91 | producerName, |
| 92 | Optional.of(DeviceId |
| 93 | .deviceId(dstArray[0])), |
| 94 | Optional.of(PortNumber |
| 95 | .portNumber(dstArray[1])), |
| 96 | null, |
| 97 | OpticalTunnelEndPoint.Type.LAMBDA, |
| 98 | OpticalLogicId |
| 99 | .logicId(0), |
| 100 | true); |
| 101 | } else { |
| 102 | print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH."); |
| 103 | return; |
| 104 | } |
| 105 | service.returnTunnel(appId, srcPoint, dstPoint); |
| 106 | } |
| 107 | |
| 108 | } |