Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | 0964a2c | 2023-01-05 14:26:05 -0500 | [diff] [blame^] | 2 | * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 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.bng.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.Completion; |
| 22 | import org.apache.karaf.shell.api.action.Option; |
| 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.net.behaviour.BngProgrammable; |
| 26 | import org.opencord.bng.BngAttachment; |
| 27 | import org.opencord.bng.BngService; |
| 28 | import org.opencord.bng.PppoeBngAttachment; |
| 29 | |
| 30 | @Service |
| 31 | @Command(scope = "bng", name = "attachment-enable", |
| 32 | description = "Enable/Disable an attachment") |
| 33 | public class EnableAttachment extends AbstractShellCommand { |
| 34 | |
| 35 | @Argument(index = 0, name = "attachmentKey", description = "Attachment Key", required = true) |
| 36 | @Completion(AttachmentKeyCompleter.class) |
| 37 | String attachmentKey = null; |
| 38 | |
| 39 | @Option(name = "-d", aliases = "--disable", description = "Disable the specified attachment", |
| 40 | required = false, multiValued = false) |
| 41 | boolean disable = false; |
| 42 | |
| 43 | @Override |
| 44 | protected void doExecute() throws Exception { |
| 45 | BngService bngService = AbstractShellCommand.get(BngService.class); |
| 46 | |
| 47 | BngAttachment attachment = bngService.getAttachment(attachmentKey); |
| 48 | |
| 49 | if (attachment == null) { |
| 50 | print("Attachment " + attachmentKey.toString() + "not found!"); |
| 51 | return; |
| 52 | } |
| 53 | if (attachment.lineActive() == !disable) { |
| 54 | print("Attachment is already " + (disable ? "disabled" : "enabled")); |
| 55 | return; |
| 56 | } |
| 57 | if (!attachment.type().equals(BngProgrammable.Attachment.AttachmentType.PPPoE)) { |
| 58 | print((disable ? "Disable" : "Enable") + " supported only for PPPoE attachment"); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | BngAttachment newAttachment = PppoeBngAttachment.builder() |
| 63 | .withPppoeSessionId(attachment.pppoeSessionId()) |
| 64 | .withApplicationId(attachment.appId()) |
| 65 | .withMacAddress(attachment.macAddress()) |
| 66 | .withCTag(attachment.cTag()) |
| 67 | .withSTag(attachment.sTag()) |
| 68 | .withIpAddress(attachment.ipAddress()) |
| 69 | .withOltConnectPoint(attachment.oltConnectPoint()) |
| 70 | .withOnuSerial(attachment.onuSerial()) |
| 71 | .lineActivated(!disable) |
| 72 | .build(); |
| 73 | print(disable ? "Disabling" : "Enabling" + " attachment: " + newAttachment.toString()); |
| 74 | bngService.setupAttachment(attachmentKey, newAttachment); |
| 75 | } |
| 76 | } |