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; |
| 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 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 | import static com.google.common.base.Strings.isNullOrEmpty; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 29 | |
| 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") |
| 36 | public class UniTagAddCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "portName", description = "Port name", |
| 39 | required = true, multiValued = false) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 40 | private String portName = null; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 41 | |
| 42 | @Option(name = "--cTag", description = "Inner vlan id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 43 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 44 | private String strCtag = null; |
| 45 | |
| 46 | @Option(name = "--sTag", description = "Outer vlan id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 47 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 48 | private String strStag = null; |
| 49 | |
| 50 | @Option(name = "--tpId", description = "Technology profile id", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 51 | required = true, multiValued = false) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 52 | private String strTpId = null; |
| 53 | |
| 54 | @Override |
| 55 | protected void doExecute() { |
| 56 | |
| 57 | AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 58 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 69 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 70 | 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 Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 74 | } |
| 75 | } |