blob: 762b9f37aabe3046c8c076dea810f39e7ca25f71 [file] [log] [blame]
Charles Chanc7b3c452018-06-19 20:31:57 -07001/*
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 */
16package org.onosproject.segmentrouting.cli;
17
18import com.google.common.collect.Sets;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkeyb52acf32018-10-05 10:17:34 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chanc7b3c452018-06-19 20:31:57 -070023import org.onlab.packet.VlanId;
24import org.onosproject.cli.AbstractShellCommand;
Ray Milkeyb52acf32018-10-05 10:17:34 -070025import org.onosproject.cli.PlaceholderCompleter;
26import org.onosproject.cli.net.DeviceIdCompleter;
27import org.onosproject.cli.net.PortNumberCompleter;
Charles Chanc7b3c452018-06-19 20:31:57 -070028import org.onosproject.net.DeviceId;
29import org.onosproject.net.PortNumber;
30import org.onosproject.segmentrouting.xconnect.api.XconnectService;
31
32import java.util.Set;
33
34/**
35 * Creates Xconnect.
36 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070037@Service
Charles Chanc7b3c452018-06-19 20:31:57 -070038@Command(scope = "onos", name = "sr-xconnect-add", description = "Create Xconnect")
39public class XconnectAddCommand extends AbstractShellCommand {
40 @Argument(index = 0, name = "deviceId",
41 description = "Device ID",
42 required = true, multiValued = false)
Ray Milkeyb52acf32018-10-05 10:17:34 -070043 @Completion(DeviceIdCompleter.class)
Charles Chanc7b3c452018-06-19 20:31:57 -070044 private String deviceIdStr;
45
46 @Argument(index = 1, name = "vlanId",
47 description = "VLAN ID",
48 required = true, multiValued = false)
Ray Milkeyb52acf32018-10-05 10:17:34 -070049 @Completion(PlaceholderCompleter.class)
Charles Chanc7b3c452018-06-19 20:31:57 -070050 private String vlanIdStr;
51
52 @Argument(index = 2, name = "port1",
53 description = "Port 1",
54 required = true, multiValued = false)
Ray Milkeyb52acf32018-10-05 10:17:34 -070055 @Completion(PortNumberCompleter.class)
Charles Chanc7b3c452018-06-19 20:31:57 -070056 private String port1Str;
57
58 @Argument(index = 3, name = "port2",
59 description = "Port 2",
60 required = true, multiValued = false)
Ray Milkeyb52acf32018-10-05 10:17:34 -070061 @Completion(PortNumberCompleter.class)
Charles Chanc7b3c452018-06-19 20:31:57 -070062 private String port2Str;
63
64
65 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070066 protected void doExecute() {
Charles Chanc7b3c452018-06-19 20:31:57 -070067 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}