blob: bd42704f3721abe34f55f1ff7a8bba3834b06bde [file] [log] [blame]
Andrea Campanellacbbb7952019-11-25 06:38:41 +00001/*
2 * Copyright 2016-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
17package org.opencord.olt.cli;
18
19import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Option;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.onlab.packet.VlanId;
24import org.onosproject.cli.AbstractShellCommand;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070025import org.onosproject.net.ConnectPoint;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000026import org.opencord.olt.AccessDeviceService;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000027
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070028import static com.google.common.base.Strings.isNullOrEmpty;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000029
30/**
31 * Adds a subscriber uni tag.
32 */
33@Service
34@Command(scope = "onos", name = "volt-add-subscriber-unitag",
35 description = "Adds a uni tag to an access device")
36public class UniTagAddCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "portName", description = "Port name",
39 required = true, multiValued = false)
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070040 private String portName = null;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000041
42 @Option(name = "--cTag", description = "Inner vlan id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070043 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000044 private String strCtag = null;
45
46 @Option(name = "--sTag", description = "Outer vlan id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070047 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000048 private String strStag = null;
49
50 @Option(name = "--tpId", description = "Technology profile id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070051 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000052 private String strTpId = null;
53
54 @Override
55 protected void doExecute() {
56
57 AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class);
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070058 ConnectPoint cp = service.findSubscriberConnectPoint(portName);
59 if (cp == null) {
60 log.warn("ConnectPoint not found for {}", portName);
61 print("ConnectPoint not found for %s", portName);
62 return;
63 }
64 if (isNullOrEmpty(strCtag) || isNullOrEmpty(strStag) || isNullOrEmpty(strTpId)) {
65 print("Values for c-tag (%s), s-tag (%s) and technology profile Id (%s) " +
66 "are required", strCtag, strStag, strTpId);
67 return;
68 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +000069
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070070 VlanId cTag = VlanId.vlanId(strCtag);
71 VlanId sTag = VlanId.vlanId(strStag);
72 Integer tpId = Integer.valueOf(strTpId);
73 service.provisionSubscriber(cp, cTag, sTag, tpId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000074 }
75}