Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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.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.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onosproject.cli.AbstractShellCommand; |
| 28 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 29 | import org.onosproject.cli.net.PortNumberCompleter; |
| 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
| 32 | import org.onosproject.net.ConnectPoint; |
| 33 | import org.opencord.bng.BngAttachment; |
Daniele Moro | ad7057d | 2020-01-15 10:54:37 -0800 | [diff] [blame^] | 34 | import org.opencord.bng.impl.BngManager; |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 35 | import org.opencord.bng.BngService; |
Daniele Moro | ad7057d | 2020-01-15 10:54:37 -0800 | [diff] [blame^] | 36 | import org.opencord.bng.impl.BngUtils; |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 37 | import org.opencord.bng.PppoeBngAttachment; |
| 38 | |
| 39 | @Service |
| 40 | @Command(scope = "bng", name = "attachment-add", |
| 41 | description = "Add an attachment on the BNG in disabled state") |
| 42 | public class AddAttachment extends AbstractShellCommand { |
| 43 | |
| 44 | @Argument(index = 0, name = "macAddress", description = "Mac Address of the attachment", required = true) |
| 45 | String macAddressString = null; |
| 46 | |
| 47 | @Argument(index = 1, name = "ipAddress", description = "IP Address of the attachment", required = true) |
| 48 | String ipAddressString = null; |
| 49 | |
| 50 | @Argument(index = 2, name = "cTag", description = "VLAN C-TAG of the attachment", required = true) |
| 51 | short cTag = 0; |
| 52 | |
| 53 | @Argument(index = 3, name = "sTag", description = "VLAN S-TAG of the attachment", required = true) |
| 54 | short sTag = 0; |
| 55 | |
| 56 | @Argument(index = 4, name = "pppoeSessionId", |
| 57 | description = "PPPoE session ID of the attachment", required = true) |
| 58 | short pppoeSessionId = 0; |
| 59 | |
| 60 | @Argument(index = 5, name = "oltDeviceID", |
| 61 | description = "OLT device ID the attachment is connected to", required = true) |
| 62 | @Completion(DeviceIdCompleter.class) |
| 63 | String oltDeviceId = null; |
| 64 | |
| 65 | @Argument(index = 6, name = "portNumber", |
| 66 | description = "Port number on the OLT device", required = true) |
| 67 | @Completion(PortNumberCompleter.class) |
| 68 | String oltPortNumber = null; |
| 69 | |
| 70 | @Argument(index = 7, name = "onuSerial", |
| 71 | description = "Serial number for the ONU of the attachment", required = true) |
| 72 | @Completion(OnuSerialCompleter.class) |
| 73 | String onuSerial = null; |
| 74 | |
| 75 | @Option(name = "-d", aliases = "--disable", description = "Disable the specified attachment", |
| 76 | required = false, multiValued = false) |
| 77 | boolean disable = false; |
| 78 | |
| 79 | |
| 80 | @Override |
| 81 | protected void doExecute() throws Exception { |
| 82 | CoreService coreService = get(CoreService.class); |
| 83 | |
| 84 | ApplicationId appId = coreService.getAppId(BngManager.BNG_APP); |
| 85 | ConnectPoint uniCp = ConnectPoint.fromString(oltDeviceId + "/" + oltPortNumber); |
| 86 | MacAddress macAddress = MacAddress.valueOf(macAddressString); |
| 87 | IpAddress ipAddress = IpAddress.valueOf(ipAddressString); |
| 88 | |
| 89 | String attachmentKey = "CLI" + "/" + |
| 90 | BngUtils.calculateBngAttachmentKey(onuSerial, VlanId.vlanId(cTag), |
| 91 | VlanId.vlanId(sTag), uniCp, ipAddress, |
| 92 | macAddress); |
| 93 | |
| 94 | BngAttachment newAttachment = PppoeBngAttachment.builder() |
| 95 | .withPppoeSessionId(pppoeSessionId) |
| 96 | .withApplicationId(appId) |
| 97 | .withMacAddress(macAddress) |
| 98 | .withCTag(VlanId.vlanId(cTag)) |
| 99 | .withSTag(VlanId.vlanId(sTag)) |
| 100 | .withIpAddress(ipAddress) |
| 101 | .withOltConnectPoint(uniCp) |
| 102 | .withOnuSerial(onuSerial) |
| 103 | .lineActivated(!disable) |
| 104 | .build(); |
| 105 | BngService bngService = get(BngService.class); |
| 106 | bngService.setupAttachment(attachmentKey, newAttachment); |
| 107 | } |
| 108 | } |