blob: b4bc117adf500a5242653982f2e0f3f0eb6a7be4 [file] [log] [blame]
jccd8697232015-05-05 14:42:23 +08001/*
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 */
16package org.onosproject.cli.net;
17
18import java.util.Collection;
19import java.util.Optional;
20
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
23import org.onlab.packet.IpAddress;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.PortNumber;
27import org.onosproject.net.provider.ProviderId;
28import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
29import org.onosproject.net.tunnel.IpTunnelEndPoint;
30import org.onosproject.net.tunnel.OpticalLogicId;
31import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
32import org.onosproject.net.tunnel.Tunnel;
33import org.onosproject.net.tunnel.TunnelEndPoint;
34import org.onosproject.net.tunnel.TunnelService;
35
36/**
37 * Supports for querying all tunnels by using IP address and optical as tunnel
38 * end point now. It's used by consumers.
39 */
40@Command(scope = "onos", name = "query-tunnels", description = "Supports for querying all tunnels by using IP address"
41 + " and optical as tunnel end point now."
42 + " It's used by consumers.")
43public class QueryTunnelCommand extends AbstractShellCommand {
44 @Argument(index = 0, name = "src", description = "Source tunnel point."
45 + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
46 + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
47 + " Otherwise src means IP address.", required = true, multiValued = false)
48 String src = null;
49 @Argument(index = 1, name = "dst", description = "Destination 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 dst means IP address.", required = true, multiValued = false)
53 String dst = null;
54
55 @Argument(index = 2, name = "type", description = "The type of tunnels,"
56 + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
57 String type = null;
58
59 private static final String FMT = "src=%s, dst=%s,"
60 + "type=%s, state=%s, producerName=%s, tunnelName=%s,"
61 + "groupId=%s";
62
63 @Override
64 protected void execute() {
65 TunnelService service = get(TunnelService.class);
66 ProviderId producerName = new ProviderId("default",
67 "org.onosproject.provider.tunnel.default");
68 TunnelEndPoint srcPoint = null;
69 TunnelEndPoint dstPoint = null;
70 if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type)
71 || "GRE".equals(type)) {
72 srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
73 dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
74 } else if ("ODUK".equals(type) || "OCH".equals(type)) {
75 String[] srcArray = src.split("-");
76 String[] dstArray = dst.split("-");
77 srcPoint = new DefaultOpticalTunnelEndPoint(
78 producerName,
79 Optional.of(DeviceId
80 .deviceId(srcArray[0])),
81 Optional.of(PortNumber
82 .portNumber(srcArray[1])),
83 null,
84 OpticalTunnelEndPoint.Type.LAMBDA,
85 OpticalLogicId
86 .logicId(0),
87 true);
88 dstPoint = new DefaultOpticalTunnelEndPoint(
89 producerName,
90 Optional.of(DeviceId
91 .deviceId(dstArray[0])),
92 Optional.of(PortNumber
93 .portNumber(dstArray[1])),
94 null,
95 OpticalTunnelEndPoint.Type.LAMBDA,
96 OpticalLogicId
97 .logicId(0),
98 true);
99 } else {
100 print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
101 return;
102 }
103 Collection<Tunnel> tunnelSet = service.queryTunnel(srcPoint, dstPoint);
104 for (Tunnel tunnel : tunnelSet) {
105 print(FMT, tunnel.src().toString(), tunnel.dst().toString(), tunnel.type(),
106 tunnel.state(), tunnel.providerId(), tunnel.tunnelName(),
107 tunnel.groupId());
108 }
109 }
110
111}