blob: 22daeb5973a2913f65f8138348c31565bb300b9d [file] [log] [blame]
Charles Chan8d316332018-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 Milkeydb38bc82018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey5105ec32018-10-05 10:17:34 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkey52ca4e92018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chan8d316332018-06-19 20:31:57 -070023import org.onlab.packet.VlanId;
24import org.onosproject.cli.AbstractShellCommand;
Ray Milkey5105ec32018-10-05 10:17:34 -070025import org.onosproject.cli.PlaceholderCompleter;
26import org.onosproject.cli.net.DeviceIdCompleter;
27import org.onosproject.cli.net.PortNumberCompleter;
Charles Chan8d316332018-06-19 20:31:57 -070028import org.onosproject.net.DeviceId;
Charles Chan445659f2019-01-02 13:46:16 -080029import org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint;
30import org.onosproject.segmentrouting.xconnect.api.XconnectPortEndpoint;
Charles Chan8d316332018-06-19 20:31:57 -070031import org.onosproject.segmentrouting.xconnect.api.XconnectService;
32
33import java.util.Set;
34
35/**
36 * Creates Xconnect.
37 */
Ray Milkey52ca4e92018-09-28 10:58:28 -070038@Service
Charles Chan8d316332018-06-19 20:31:57 -070039@Command(scope = "onos", name = "sr-xconnect-add", description = "Create Xconnect")
40public class XconnectAddCommand extends AbstractShellCommand {
Charles Chan445659f2019-01-02 13:46:16 -080041 private static final String EP_DESC = "Can be a physical port number or a load balancer key. " +
42 "Use integer to specify physical port number. " +
43 "Use " + XconnectPortEndpoint.LB_KEYWORD + "key to specify load balancer key";
44
Charles Chan8d316332018-06-19 20:31:57 -070045 @Argument(index = 0, name = "deviceId",
46 description = "Device ID",
47 required = true, multiValued = false)
Ray Milkey5105ec32018-10-05 10:17:34 -070048 @Completion(DeviceIdCompleter.class)
Charles Chan8d316332018-06-19 20:31:57 -070049 private String deviceIdStr;
50
51 @Argument(index = 1, name = "vlanId",
52 description = "VLAN ID",
53 required = true, multiValued = false)
Ray Milkey5105ec32018-10-05 10:17:34 -070054 @Completion(PlaceholderCompleter.class)
Charles Chan8d316332018-06-19 20:31:57 -070055 private String vlanIdStr;
56
Charles Chan445659f2019-01-02 13:46:16 -080057 @Argument(index = 2, name = "ep1",
58 description = "First endpoint. " + EP_DESC,
Charles Chan8d316332018-06-19 20:31:57 -070059 required = true, multiValued = false)
Ray Milkey5105ec32018-10-05 10:17:34 -070060 @Completion(PortNumberCompleter.class)
Charles Chan445659f2019-01-02 13:46:16 -080061 private String ep1Str;
Charles Chan8d316332018-06-19 20:31:57 -070062
Charles Chan445659f2019-01-02 13:46:16 -080063 @Argument(index = 3, name = "ep2",
64 description = "Second endpoint. " + EP_DESC,
Charles Chan8d316332018-06-19 20:31:57 -070065 required = true, multiValued = false)
Ray Milkey5105ec32018-10-05 10:17:34 -070066 @Completion(PortNumberCompleter.class)
Charles Chan445659f2019-01-02 13:46:16 -080067 private String ep2Str;
Charles Chan8d316332018-06-19 20:31:57 -070068
Charles Chan48df9ad2018-10-30 18:08:59 -070069 private static final String L2LB_PATTERN = "^(\\d*|L2LB\\(\\d*\\))$";
Charles Chan8d316332018-06-19 20:31:57 -070070
71 @Override
Ray Milkeydb38bc82018-09-27 12:32:28 -070072 protected void doExecute() {
Charles Chan8d316332018-06-19 20:31:57 -070073 DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
74 VlanId vlanId = VlanId.vlanId(vlanIdStr);
Charles Chan48df9ad2018-10-30 18:08:59 -070075
Charles Chan445659f2019-01-02 13:46:16 -080076 XconnectEndpoint ep1 = XconnectEndpoint.fromString(ep1Str);
77 XconnectEndpoint ep2 = XconnectEndpoint.fromString(ep2Str);
78
79 Set<XconnectEndpoint> endpoints = Sets.newHashSet(ep1, ep2);
Charles Chan8d316332018-06-19 20:31:57 -070080
81 XconnectService xconnectService = get(XconnectService.class);
Charles Chan445659f2019-01-02 13:46:16 -080082 xconnectService.addOrUpdateXconnect(deviceId, vlanId, endpoints);
Charles Chan8d316332018-06-19 20:31:57 -070083 }
Charles Chan445659f2019-01-02 13:46:16 -080084
85
Charles Chan8d316332018-06-19 20:31:57 -070086}