Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.segmentrouting.cli; |
| 17 | |
| 18 | import com.google.common.collect.Sets; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 25 | import org.onosproject.cli.PlaceholderCompleter; |
| 26 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 27 | import org.onosproject.cli.net.PortNumberCompleter; |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.segmentrouting.xconnect.api.XconnectService; |
| 31 | |
| 32 | import java.util.Set; |
| 33 | |
| 34 | /** |
| 35 | * Creates Xconnect. |
| 36 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 37 | @Service |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 38 | @Command(scope = "onos", name = "sr-xconnect-add", description = "Create Xconnect") |
| 39 | public class XconnectAddCommand extends AbstractShellCommand { |
| 40 | @Argument(index = 0, name = "deviceId", |
| 41 | description = "Device ID", |
| 42 | required = true, multiValued = false) |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 43 | @Completion(DeviceIdCompleter.class) |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 44 | private String deviceIdStr; |
| 45 | |
| 46 | @Argument(index = 1, name = "vlanId", |
| 47 | description = "VLAN ID", |
| 48 | required = true, multiValued = false) |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 49 | @Completion(PlaceholderCompleter.class) |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 50 | private String vlanIdStr; |
| 51 | |
| 52 | @Argument(index = 2, name = "port1", |
| 53 | description = "Port 1", |
| 54 | required = true, multiValued = false) |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 55 | @Completion(PortNumberCompleter.class) |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 56 | private String port1Str; |
| 57 | |
| 58 | @Argument(index = 3, name = "port2", |
| 59 | description = "Port 2", |
| 60 | required = true, multiValued = false) |
Ray Milkey | b52acf3 | 2018-10-05 10:17:34 -0700 | [diff] [blame^] | 61 | @Completion(PortNumberCompleter.class) |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 62 | private String port2Str; |
| 63 | |
| 64 | |
| 65 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 66 | protected void doExecute() { |
Charles Chan | c7b3c45 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 67 | DeviceId deviceId = DeviceId.deviceId(deviceIdStr); |
| 68 | VlanId vlanId = VlanId.vlanId(vlanIdStr); |
| 69 | PortNumber port1 = PortNumber.portNumber(port1Str); |
| 70 | PortNumber port2 = PortNumber.portNumber(port2Str); |
| 71 | Set<PortNumber> ports = Sets.newHashSet(port1, port2); |
| 72 | |
| 73 | XconnectService xconnectService = get(XconnectService.class); |
| 74 | xconnectService.addOrUpdateXconnect(deviceId, vlanId, ports); |
| 75 | } |
| 76 | } |