Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | package org.onosproject.segmentrouting.cli; |
| 17 | |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 24 | import org.onosproject.segmentrouting.SegmentRoutingService; |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 25 | import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel; |
| 26 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription; |
| 27 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy; |
| 28 | import org.onosproject.segmentrouting.pwaas.L2Tunnel; |
| 29 | import org.onosproject.segmentrouting.pwaas.L2TunnelDescription; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 30 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 31 | import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy; |
| 32 | |
| 33 | import static org.onosproject.segmentrouting.pwaas.PwaasUtil.*; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 34 | |
| 35 | |
| 36 | /** |
| 37 | * Command to add a pseuwodire. |
| 38 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 39 | @Service |
Andreas Pantelopoulos | ff691b7 | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 40 | @Command(scope = "onos", name = "sr-pw-add", |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 41 | description = "Add a pseudowire to the network configuration, if it already exists update it.") |
| 42 | public class PseudowireAddCommand extends AbstractShellCommand { |
| 43 | |
| 44 | @Argument(index = 0, name = "pwId", |
| 45 | description = "Pseudowire ID", |
| 46 | required = true, multiValued = false) |
| 47 | String pwId; |
| 48 | |
| 49 | @Argument(index = 1, name = "pwLabel", |
| 50 | description = "Pseudowire Label", |
| 51 | required = true, multiValued = false) |
| 52 | String pwLabel; |
| 53 | |
| 54 | @Argument(index = 2, name = "mode", |
| 55 | description = "Mode used for pseudowire", |
| 56 | required = true, multiValued = false) |
| 57 | String mode; |
| 58 | |
| 59 | @Argument(index = 3, name = "sDTag", |
| 60 | description = "Service delimiting tag", |
| 61 | required = true, multiValued = false) |
| 62 | String sDTag; |
| 63 | |
| 64 | @Argument(index = 4, name = "cP1", |
| 65 | description = "Connection Point 1", |
| 66 | required = true, multiValued = false) |
| 67 | String cP1; |
| 68 | |
| 69 | @Argument(index = 5, name = "cP1InnerVlan", |
| 70 | description = "Inner Vlan of Connection Point 1", |
| 71 | required = true, multiValued = false) |
| 72 | String cP1InnerVlan; |
| 73 | |
| 74 | @Argument(index = 6, name = "cP1OuterVlan", |
| 75 | description = "Outer Vlan of Connection Point 1", |
| 76 | required = true, multiValued = false) |
| 77 | String cP1OuterVlan; |
| 78 | |
| 79 | @Argument(index = 7, name = "cP2", |
| 80 | description = "Connection Point 2", |
| 81 | required = true, multiValued = false) |
| 82 | String cP2; |
| 83 | |
| 84 | @Argument(index = 8, name = "cP2InnerVlan", |
| 85 | description = "Inner Vlan of Connection Point 2", |
| 86 | required = true, multiValued = false) |
| 87 | String cP2InnerVlan; |
| 88 | |
| 89 | @Argument(index = 9, name = "cP2OuterVlan", |
| 90 | description = "Outer Vlan of Connection Point 2", |
| 91 | required = true, multiValued = false) |
| 92 | String cP2OuterVlan; |
| 93 | |
| 94 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 95 | protected void doExecute() { |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 96 | |
| 97 | SegmentRoutingService srService = |
| 98 | AbstractShellCommand.get(SegmentRoutingService.class); |
| 99 | |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 100 | L2Tunnel tun; |
| 101 | L2TunnelPolicy policy; |
| 102 | |
| 103 | try { |
| 104 | tun = new DefaultL2Tunnel(parseMode(mode), parseVlan(sDTag), parsePwId(pwId), parsePWLabel(pwLabel)); |
Andreas Pantelopoulos | 5bf1366 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 105 | } catch (IllegalArgumentException e) { |
| 106 | log.error("Exception while parsing L2Tunnel : \n\t %s", e.getMessage()); |
| 107 | print("Exception while parsing L2Tunnel : \n\t %s", e.getMessage()); |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 108 | return; |
| 109 | } |
| 110 | |
| 111 | try { |
| 112 | policy = new DefaultL2TunnelPolicy(parsePwId(pwId), |
| 113 | ConnectPoint.deviceConnectPoint(cP1), parseVlan(cP1InnerVlan), |
| 114 | parseVlan(cP1OuterVlan), ConnectPoint.deviceConnectPoint(cP2), |
| 115 | parseVlan(cP2InnerVlan), parseVlan(cP2OuterVlan)); |
| 116 | |
Andreas Pantelopoulos | 5bf1366 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 117 | } catch (IllegalArgumentException e) { |
| 118 | log.error("Exception while parsing L2TunnelPolicy : \n\t %s", e.getMessage()); |
| 119 | print("Exception while parsing L2TunnelPolicy : \n\t %s", e.getMessage()); |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 120 | return; |
| 121 | } |
| 122 | |
| 123 | L2TunnelDescription pw = new DefaultL2TunnelDescription(tun, policy); |
| 124 | L2TunnelHandler.Result res = srService.addPseudowire(pw); |
Andreas Pantelopoulos | 5bf1366 | 2018-04-10 19:34:47 -0700 | [diff] [blame] | 125 | log.info("Deploying pseudowire {} via the command line.", pw); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 126 | switch (res) { |
Andreas Pantelopoulos | ffe6974 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 127 | case WRONG_PARAMETERS: |
| 128 | print("Pseudowire could not be added , error in the parameters : \n\t%s", |
| 129 | res.getSpecificError()); |
| 130 | break; |
| 131 | case CONFIGURATION_ERROR: |
| 132 | print("Pseudowire could not be added, configuration error : \n\t%s", |
| 133 | res.getSpecificError()); |
| 134 | break; |
| 135 | case PATH_NOT_FOUND: |
| 136 | print("Pseudowire path not found : \n\t%s", |
| 137 | res.getSpecificError()); |
| 138 | break; |
| 139 | case INTERNAL_ERROR: |
| 140 | print("Pseudowire could not be added, internal error : \n\t%s", |
| 141 | res.getSpecificError()); |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 142 | break; |
Andreas Pantelopoulos | cd33959 | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 143 | case SUCCESS: |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 144 | break; |
| 145 | default: |
Andreas Pantelopoulos | 20474e0 | 2017-12-20 18:04:27 -0800 | [diff] [blame] | 146 | break; |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 147 | } |
Andreas Pantelopoulos | 27532cd | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 148 | } |
| 149 | } |