blob: 07b5ed00c0354fcb021d14b4ae454c9df3b4a45f [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 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 */
Michele Santuari4b6019e2014-12-19 11:31:45 +010016package org.onosproject.cli.net;
17
Michele Santuari4b6019e2014-12-19 11:31:45 +010018import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.apache.karaf.shell.commands.Option;
Michele Santuari4b6019e2014-12-19 11:31:45 +010021import org.onlab.packet.MplsLabel;
22import org.onosproject.net.ConnectPoint;
Michele Santuari4b6019e2014-12-19 11:31:45 +010023import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25import org.onosproject.net.intent.Constraint;
26import org.onosproject.net.intent.IntentService;
27import org.onosproject.net.intent.MplsIntent;
28
Jonathan Hartc3af35a2015-04-30 22:20:29 -070029import java.util.List;
30import java.util.Optional;
Ray Milkey50a9b722015-03-12 10:38:55 -070031
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080032/**
33 * Installs MPLS intents.
Michele Santuari6096acd2016-02-09 17:00:37 +010034 *
35 * @deprecated in Goldeneye Release, in favour of encapsulation
36 * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint}
Charles M.C. Chan6f5bdc62015-04-22 01:21:09 +080037 */
Michele Santuari6096acd2016-02-09 17:00:37 +010038@Deprecated
Michele Santuari4b6019e2014-12-19 11:31:45 +010039@Command(scope = "onos", name = "add-mpls-intent", description = "Installs mpls connectivity intent")
40public class AddMplsIntent extends ConnectivityIntentCommand {
41
42 @Argument(index = 0, name = "ingressDevice",
43 description = "Ingress Device/Port Description",
44 required = true,
45 multiValued = false)
46 private String ingressDeviceString = null;
47
48 @Option(name = "--ingressLabel",
49 description = "Ingress Mpls label",
50 required = false,
51 multiValued = false)
52 private String ingressLabelString = "";
53
54 @Argument(index = 1, name = "egressDevice",
55 description = "Egress Device/Port Description",
56 required = true,
57 multiValued = false)
58 private String egressDeviceString = null;
59
60 @Option(name = "--egressLabel",
61 description = "Egress Mpls label",
62 required = false,
63 multiValued = false)
64 private String egressLabelString = "";
65
66 @Override
67 protected void execute() {
68 IntentService service = get(IntentService.class);
69
Jonathan Hartc3af35a2015-04-30 22:20:29 -070070 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Michele Santuari4b6019e2014-12-19 11:31:45 +010071 Optional<MplsLabel> ingressLabel = Optional.empty();
72 if (!ingressLabelString.isEmpty()) {
73 ingressLabel = Optional
74 .ofNullable(MplsLabel.mplsLabel(parseInt(ingressLabelString)));
75 }
76
Jonathan Hartc3af35a2015-04-30 22:20:29 -070077 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Michele Santuari4b6019e2014-12-19 11:31:45 +010078 Optional<MplsLabel> egressLabel = Optional.empty();
Charles Chan4b003c52015-08-23 23:04:27 +080079 if (!egressLabelString.isEmpty()) {
Michele Santuari4b6019e2014-12-19 11:31:45 +010080 egressLabel = Optional
81 .ofNullable(MplsLabel.mplsLabel(parseInt(egressLabelString)));
82 }
83
84 TrafficSelector selector = buildTrafficSelector();
85 TrafficTreatment treatment = buildTrafficTreatment();
86
87 List<Constraint> constraints = buildConstraints();
88
Ray Milkeyebc5d222015-03-18 15:45:36 -070089 MplsIntent intent = MplsIntent.builder()
90 .appId(appId())
91 .selector(selector)
92 .treatment(treatment)
93 .ingressPoint(ingress)
94 .ingressLabel(ingressLabel)
95 .egressPoint(egress)
96 .egressLabel(egressLabel)
97 .constraints(constraints)
98 .priority(priority())
99 .build();
Michele Santuari4b6019e2014-12-19 11:31:45 +0100100 service.submit(intent);
101 }
102
Michele Santuari4b6019e2014-12-19 11:31:45 +0100103 protected Integer parseInt(String value) {
104 try {
105 return Integer.parseInt(value);
106 } catch (NumberFormatException nfe) {
107 return null;
108 }
109 }
110}