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