blob: 01c30017c36d731efc97ca02759e10e7b2a4b3cd [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 Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chanc7b3c452018-06-19 20:31:57 -070022import org.onlab.packet.VlanId;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.segmentrouting.xconnect.api.XconnectService;
27
28import java.util.Set;
29
30/**
31 * Creates Xconnect.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
Charles Chanc7b3c452018-06-19 20:31:57 -070034@Command(scope = "onos", name = "sr-xconnect-add", description = "Create Xconnect")
35public class XconnectAddCommand extends AbstractShellCommand {
36 @Argument(index = 0, name = "deviceId",
37 description = "Device ID",
38 required = true, multiValued = false)
39 private String deviceIdStr;
40
41 @Argument(index = 1, name = "vlanId",
42 description = "VLAN ID",
43 required = true, multiValued = false)
44 private String vlanIdStr;
45
46 @Argument(index = 2, name = "port1",
47 description = "Port 1",
48 required = true, multiValued = false)
49 private String port1Str;
50
51 @Argument(index = 3, name = "port2",
52 description = "Port 2",
53 required = true, multiValued = false)
54 private String port2Str;
55
56
57 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070058 protected void doExecute() {
Charles Chanc7b3c452018-06-19 20:31:57 -070059 DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
60 VlanId vlanId = VlanId.vlanId(vlanIdStr);
61 PortNumber port1 = PortNumber.portNumber(port1Str);
62 PortNumber port2 = PortNumber.portNumber(port2Str);
63 Set<PortNumber> ports = Sets.newHashSet(port1, port2);
64
65 XconnectService xconnectService = get(XconnectService.class);
66 xconnectService.addOrUpdateXconnect(deviceId, vlanId, ports);
67 }
68}