Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.opencord.olt.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
| 21 | import org.apache.karaf.shell.api.action.Option; |
Gamze Abaka | ea4b06a | 2020-05-06 14:06:44 +0000 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 25 | import org.onosproject.net.ConnectPoint; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 26 | import org.opencord.olt.AccessDeviceService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 27 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 28 | |
| 29 | import static com.google.common.base.Strings.isNullOrEmpty; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 30 | |
| 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") |
| 37 | public class UniTagRemoveCommand extends AbstractShellCommand { |
| 38 | |
| 39 | @Argument(index = 0, name = "portName", description = "Port name", |
| 40 | required = true, multiValued = false) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 41 | private String portName = null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 42 | |
| 43 | @Option(name = "--cTag", description = "Inner vlan id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 44 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 45 | private String strCtag = null; |
| 46 | |
| 47 | @Option(name = "--sTag", description = "Outer vlan id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 48 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 49 | private String strStag = null; |
| 50 | |
| 51 | @Option(name = "--tpId", description = "Technology profile id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 52 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 53 | private String strTpId = null; |
| 54 | |
| 55 | @Override |
| 56 | protected void doExecute() { |
| 57 | |
| 58 | AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 59 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 70 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 71 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 75 | } |
| 76 | } |