blob: d595d5c2cb595f071392625e2d5a973f9c1bc94e [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070022import org.onosproject.cli.AbstractShellCommand;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080023import org.onosproject.net.ConnectPoint;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070024import org.onosproject.segmentrouting.SegmentRoutingService;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080025import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
26import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
27import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
28import org.onosproject.segmentrouting.pwaas.L2Tunnel;
29import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070030import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -080031import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy;
32
33import static org.onosproject.segmentrouting.pwaas.PwaasUtil.*;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070034
35
36/**
37 * Command to add a pseuwodire.
38 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070039@Service
Andreas Pantelopoulosff691b72018-03-12 16:30:20 -070040@Command(scope = "onos", name = "sr-pw-add",
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070041 description = "Add a pseudowire to the network configuration, if it already exists update it.")
42public 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 Milkey86ad7bb2018-09-27 12:32:28 -070095 protected void doExecute() {
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -070096
97 SegmentRoutingService srService =
98 AbstractShellCommand.get(SegmentRoutingService.class);
99
Andreas Pantelopouloscd339592018-02-23 14:18:00 -0800100 L2Tunnel tun;
101 L2TunnelPolicy policy;
102
103 try {
104 tun = new DefaultL2Tunnel(parseMode(mode), parseVlan(sDTag), parsePwId(pwId), parsePWLabel(pwLabel));
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -0700105 } 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 Pantelopouloscd339592018-02-23 14:18:00 -0800108 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 Pantelopoulos5bf13662018-04-10 19:34:47 -0700117 } 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 Pantelopouloscd339592018-02-23 14:18:00 -0800120 return;
121 }
122
123 L2TunnelDescription pw = new DefaultL2TunnelDescription(tun, policy);
124 L2TunnelHandler.Result res = srService.addPseudowire(pw);
Andreas Pantelopoulos5bf13662018-04-10 19:34:47 -0700125 log.info("Deploying pseudowire {} via the command line.", pw);
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700126 switch (res) {
Andreas Pantelopoulosffe69742018-03-20 13:58:49 -0700127 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 Pantelopoulos27532cd2017-10-23 12:18:25 -0700142 break;
Andreas Pantelopouloscd339592018-02-23 14:18:00 -0800143 case SUCCESS:
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700144 break;
145 default:
Andreas Pantelopoulos20474e02017-12-20 18:04:27 -0800146 break;
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700147 }
Andreas Pantelopoulos27532cd2017-10-23 12:18:25 -0700148 }
149}