Andreas Papazois | c2c4501 | 2016-01-20 14:26:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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.onosproject.sdxl3.cli; |
| 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.apache.karaf.shell.commands.Option; |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.sdxl3.SdxL3PeerService; |
| 26 | |
| 27 | /** |
| 28 | * Command to set details for an existing BGP peer. |
| 29 | */ |
| 30 | @Command(scope = "onos", name = "peer-add-details", |
| 31 | description = "Adds the details of an external BGP peer") |
| 32 | public class AddPeerDetailsCommand extends AbstractShellCommand { |
| 33 | |
| 34 | @Argument(index = 0, name = "ip", description = "BGP peer IP", |
| 35 | required = true, multiValued = false) |
| 36 | private String ip = null; |
| 37 | |
| 38 | @Argument(index = 1, name = "port", |
| 39 | description = "Connect point of the BGP peer", |
| 40 | required = true, multiValued = false) |
| 41 | private String connectPoint = null; |
| 42 | |
| 43 | @Argument(index = 2, name = "intfName", |
| 44 | description = "Name of configured interface for the BGP peer", |
| 45 | required = true, multiValued = false) |
| 46 | private String interfaceName = null; |
| 47 | |
| 48 | @Option(name = "-n", aliases = "--name", description = "BGP peer name", |
| 49 | required = false, multiValued = false) |
| 50 | private String peerName = null; |
| 51 | |
| 52 | private static final String DETAILS_ADD_SUCCESS = |
| 53 | "Details successfully added to peer."; |
| 54 | private static final String DETAILS_ADD_FAIL = |
| 55 | "Details could not be added to peer: "; |
| 56 | |
| 57 | private IpAddress peerAddress = null; |
| 58 | private ConnectPoint port = null; |
| 59 | |
| 60 | @Override |
| 61 | protected void execute() { |
| 62 | peerAddress = IpAddress.valueOf(ip); |
| 63 | port = ConnectPoint.deviceConnectPoint(connectPoint); |
| 64 | |
| 65 | SdxL3PeerService peerService = get(SdxL3PeerService.class); |
| 66 | try { |
| 67 | peerService.addPeerDetails(peerName, peerAddress, port, interfaceName); |
| 68 | print(DETAILS_ADD_SUCCESS); |
| 69 | } catch (Exception e) { |
| 70 | print(DETAILS_ADD_FAIL + e.getMessage()); |
| 71 | } |
| 72 | } |
| 73 | } |