blob: d05418ad402ba20ac40e9cc2605423015fdda398 [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;
Gamze Abakaea4b06a2020-05-06 14:06:44 +000022import org.apache.karaf.shell.api.action.lifecycle.Service;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000023import 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 -070028
29import static com.google.common.base.Strings.isNullOrEmpty;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000030
31/**
32 * Removes a uni tag from a subscriber (portname).
33 */
34@Service
35@Command(scope = "onos", name = "volt-remove-subscriber-unitag",
36 description = "Removes a uni tag from an access device")
37public class UniTagRemoveCommand extends AbstractShellCommand {
38
39 @Argument(index = 0, name = "portName", description = "Port name",
40 required = true, multiValued = false)
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070041 private String portName = null;
Andrea Campanellacbbb7952019-11-25 06:38:41 +000042
43 @Option(name = "--cTag", description = "Inner vlan id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070044 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000045 private String strCtag = null;
46
47 @Option(name = "--sTag", description = "Outer vlan id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070048 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000049 private String strStag = null;
50
51 @Option(name = "--tpId", description = "Technology profile id",
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070052 required = true, multiValued = false)
Andrea Campanellacbbb7952019-11-25 06:38:41 +000053 private String strTpId = null;
54
55 @Override
56 protected void doExecute() {
57
58 AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class);
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070059 ConnectPoint cp = service.findSubscriberConnectPoint(portName);
60 if (cp == null) {
61 log.warn("ConnectPoint not found for {}", portName);
62 print("ConnectPoint not found for %s", portName);
63 return;
64 }
65 if (isNullOrEmpty(strCtag) || isNullOrEmpty(strStag) || isNullOrEmpty(strTpId)) {
66 print("Values for c-tag (%s), s-tag (%s) and technology profile Id (%s) " +
67 "are required", strCtag, strStag, strTpId);
68 return;
69 }
Andrea Campanellacbbb7952019-11-25 06:38:41 +000070
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070071 VlanId cTag = VlanId.vlanId(strCtag);
72 VlanId sTag = VlanId.vlanId(strStag);
73 Integer tpId = Integer.valueOf(strTpId);
74 service.removeSubscriber(cp, cTag, sTag, tpId);
Andrea Campanellacbbb7952019-11-25 06:38:41 +000075 }
76}