blob: f699e4038c8d69ce0447b09259393585eca86935 [file] [log] [blame]
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -07001/*
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 */
16package org.onosproject.segmentrouting.cli;
17
18
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070021import org.onosproject.cli.AbstractShellCommand;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080022import org.onosproject.net.ConnectPoint;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070023import org.onosproject.segmentrouting.SegmentRoutingService;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080024import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
25import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
26import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
27import org.onosproject.segmentrouting.pwaas.L2Tunnel;
28import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070029import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080030import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy;
31
32import static org.onosproject.segmentrouting.pwaas.PwaasUtil.*;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070033
34
35/**
36 * Command to add a pseuwodire.
37 */
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -070038@Command(scope = "onos", name = "sr-pw-add",
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070039 description = "Add a pseudowire to the network configuration, if it already exists update it.")
40public 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 Milkey86ad7bb2018-09-27 12:32:28 -070093 protected void doExecute() {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070094
95 SegmentRoutingService srService =
96 AbstractShellCommand.get(SegmentRoutingService.class);
97
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080098 L2Tunnel tun;
99 L2TunnelPolicy policy;
100
101 try {
102 tun = new DefaultL2Tunnel(parseMode(mode), parseVlan(sDTag), parsePwId(pwId), parsePWLabel(pwLabel));
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -0700103 } 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 Pantelopouloscd339592018-02-23 14:18:00 -0800106 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 Pantelopoulos5bf13662018-04-10 19:34:47 -0700115 } 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 Pantelopouloscd339592018-02-23 14:18:00 -0800118 return;
119 }
120
121 L2TunnelDescription pw = new DefaultL2TunnelDescription(tun, policy);
122 L2TunnelHandler.Result res = srService.addPseudowire(pw);
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -0700123 log.info("Deploying pseudowire {} via the command line.", pw);
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700124 switch (res) {
Andreas Pantelopoulosffe69742018-03-20 13:58:49 -0700125 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 Pantelopoulos27532cd2017-10-23 12:18:25 -0700140 break;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -0800141 case SUCCESS:
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700142 break;
143 default:
Andreas Pantelopoulos20474e02017-12-20 18:04:27 -0800144 break;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700145 }
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700146 }
147}