Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 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 Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
| 17 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.apache.karaf.shell.commands.Option; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 21 | import org.onlab.packet.MplsLabel; |
| 22 | import org.onosproject.net.ConnectPoint; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | import org.onosproject.net.intent.Constraint; |
| 26 | import org.onosproject.net.intent.IntentService; |
| 27 | import org.onosproject.net.intent.MplsIntent; |
| 28 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 29 | import java.util.List; |
| 30 | import java.util.Optional; |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 31 | |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 32 | /** |
| 33 | * Installs MPLS intents. |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 34 | * |
| 35 | * @deprecated in Goldeneye Release, in favour of encapsulation |
| 36 | * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint} |
Charles M.C. Chan | 6f5bdc6 | 2015-04-22 01:21:09 +0800 | [diff] [blame] | 37 | */ |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 38 | @Deprecated |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 39 | @Command(scope = "onos", name = "add-mpls-intent", description = "Installs mpls connectivity intent") |
| 40 | public 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 Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 70 | ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 71 | Optional<MplsLabel> ingressLabel = Optional.empty(); |
| 72 | if (!ingressLabelString.isEmpty()) { |
| 73 | ingressLabel = Optional |
| 74 | .ofNullable(MplsLabel.mplsLabel(parseInt(ingressLabelString))); |
| 75 | } |
| 76 | |
Jonathan Hart | c3af35a | 2015-04-30 22:20:29 -0700 | [diff] [blame] | 77 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 78 | Optional<MplsLabel> egressLabel = Optional.empty(); |
Charles Chan | 4b003c5 | 2015-08-23 23:04:27 +0800 | [diff] [blame] | 79 | if (!egressLabelString.isEmpty()) { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 80 | 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 Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 89 | 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 Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 100 | service.submit(intent); |
| 101 | } |
| 102 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 103 | protected Integer parseInt(String value) { |
| 104 | try { |
| 105 | return Integer.parseInt(value); |
| 106 | } catch (NumberFormatException nfe) { |
| 107 | return null; |
| 108 | } |
| 109 | } |
| 110 | } |