blob: 911062c9453f46a79ccbcb12f97aa4e14df2800f [file] [log] [blame]
Kyuhwi Choi70537882016-06-24 17:24:12 +09001/*
2 * Copyright 2016-present 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 */
16
17package org.onosproject.scalablegateway.cli;
18
19import com.google.common.collect.Lists;
20import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
22import org.onlab.packet.Ip4Address;
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.net.DeviceId;
25import org.onosproject.scalablegateway.api.GatewayNode;
26import org.onosproject.scalablegateway.api.ScalableGatewayService;
27
28import java.util.Collections;
29import java.util.List;
30
31/**
32 * Adds gateway node information for scalablegateway node managements.
33 */
34
35@Command(scope = "onos", name = "gateway-add",
36 description = "Adds gateway node information for scalablegateway node managements")
37public class ScalableGatewayAddCommand extends AbstractShellCommand {
38
39 private static final String SUCCESS = "Process of adding gateway node is succeed";
40 private static final String FAIL = "Process of adding gateway node is failed";
41
42 @Argument(index = 0, name = "DeviceId", description = "GatewayNode device id",
43 required = true, multiValued = false)
44 String deviceId = null;
45
46 @Argument(index = 1, name = "dataPlaneIp",
47 description = "GatewayNode datePlane interface ip address",
48 required = true, multiValued = false)
49 String ipAddress = null;
50
51 @Argument(index = 2, name = "extInterfaceNames",
52 description = "GatewayNode Interface name to outgoing external network",
53 required = true, multiValued = true)
54 String interfaceName = null;
55
56 @Override
57 protected void execute() {
58 ScalableGatewayService service = get(ScalableGatewayService.class);
59
60 GatewayNode gatewayNode = GatewayNode.builder()
61 .gatewayDeviceId(DeviceId.deviceId(deviceId))
62 .dataIpAddress(Ip4Address.valueOf(ipAddress))
63 .gatewayExternalInterfaceNames(splitNameList(interfaceName))
64 .build();
65 if (service.addGatewayNode(gatewayNode)) {
66 print(SUCCESS);
67 } else {
68 print(FAIL);
69 }
70 }
71
72 private List<String> splitNameList(String interfaceName) {
73 List<String> list = Lists.newArrayList();
74 return Collections.addAll(list, interfaceName.split(",")) ? list : null;
75 }
76}