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.net.intent; |
| 17 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 18 | import java.util.List; |
| 19 | import java.util.Optional; |
| 20 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 21 | import com.google.common.annotations.Beta; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 22 | import org.onlab.packet.MplsLabel; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.Path; |
| 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 27 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Abstraction of explicit MPLS label-switched path. |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 33 | * |
| 34 | * @deprecated in Goldeneye Release, in favour of encapsulation |
| 35 | * constraint {@link org.onosproject.net.intent.constraint.EncapsulationConstraint} |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 36 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 37 | @Beta |
Michele Santuari | 6096acd | 2016-02-09 17:00:37 +0100 | [diff] [blame] | 38 | @Deprecated |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 39 | public final class MplsPathIntent extends PathIntent { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 40 | |
Ray Milkey | bd4f011 | 2015-03-02 17:07:09 -0800 | [diff] [blame] | 41 | private final Optional<MplsLabel> ingressLabel; |
| 42 | private final Optional<MplsLabel> egressLabel; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Creates a new point-to-point intent with the supplied ingress/egress |
| 46 | * ports and using the specified explicit path. |
| 47 | * |
| 48 | * @param appId application identifier |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 49 | * @param key intent key |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 50 | * @param selector traffic selector |
| 51 | * @param treatment treatment |
| 52 | * @param path traversed links |
| 53 | * @param ingressLabel MPLS egress label |
| 54 | * @param egressLabel MPLS ingress label |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 55 | * @param constraints optional list of constraints |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 56 | * @param priority priority to use for flows generated by this intent |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 57 | * @throws NullPointerException {@code path} is null |
| 58 | */ |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 59 | private MplsPathIntent(ApplicationId appId, Key key, TrafficSelector selector, |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 60 | TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 61 | Optional<MplsLabel> egressLabel, List<Constraint> constraints, |
| 62 | int priority) { |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 63 | super(appId, key, selector, treatment, path, constraints, |
Ray Milkey | 50a9b72 | 2015-03-12 10:38:55 -0700 | [diff] [blame] | 64 | priority); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 65 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 66 | this.ingressLabel = checkNotNull(ingressLabel); |
| 67 | this.egressLabel = checkNotNull(egressLabel); |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 71 | * Returns a new host to host intent builder. |
| 72 | * |
| 73 | * @return host to host intent builder |
| 74 | */ |
| 75 | public static Builder builder() { |
| 76 | return new Builder(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Builder of a host to host intent. |
| 81 | */ |
| 82 | public static final class Builder extends PathIntent.Builder { |
| 83 | private Optional<MplsLabel> ingressLabel = Optional.empty(); |
| 84 | private Optional<MplsLabel> egressLabel = Optional.empty(); |
| 85 | |
| 86 | private Builder() { |
| 87 | // Hide constructor |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Builder appId(ApplicationId appId) { |
| 92 | return (Builder) super.appId(appId); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Builder key(Key key) { |
| 97 | return (Builder) super.key(key); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public Builder selector(TrafficSelector selector) { |
| 102 | return (Builder) super.selector(selector); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public Builder treatment(TrafficTreatment treatment) { |
| 107 | return (Builder) super.treatment(treatment); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public Builder constraints(List<Constraint> constraints) { |
| 112 | return (Builder) super.constraints(constraints); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public Builder priority(int priority) { |
| 117 | return (Builder) super.priority(priority); |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public Builder path(Path path) { |
| 122 | return (Builder) super.path(path); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Sets the ingress label of the intent that will be built. |
| 127 | * |
| 128 | * @param ingressLabel ingress label |
| 129 | * @return this builder |
| 130 | */ |
| 131 | public Builder ingressLabel(Optional<MplsLabel> ingressLabel) { |
| 132 | this.ingressLabel = ingressLabel; |
| 133 | return this; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Sets the ingress label of the intent that will be built. |
| 138 | * |
| 139 | * @param egressLabel ingress label |
| 140 | * @return this builder |
| 141 | */ |
| 142 | public Builder egressLabel(Optional<MplsLabel> egressLabel) { |
| 143 | this.egressLabel = egressLabel; |
| 144 | return this; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Builds a host to host intent from the accumulated parameters. |
| 150 | * |
| 151 | * @return point to point intent |
| 152 | */ |
| 153 | public MplsPathIntent build() { |
| 154 | |
| 155 | return new MplsPathIntent( |
| 156 | appId, |
ilhem fajjari | b0a0684 | 2015-11-02 18:59:02 +0100 | [diff] [blame] | 157 | key, |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 158 | selector, |
| 159 | treatment, |
| 160 | path, |
| 161 | ingressLabel, |
| 162 | egressLabel, |
| 163 | constraints, |
| 164 | priority |
| 165 | ); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /** |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 171 | * Returns the MPLS label which the ingress traffic should tagged. |
| 172 | * |
| 173 | * @return ingress MPLS label |
| 174 | */ |
| 175 | public Optional<MplsLabel> ingressLabel() { |
| 176 | return ingressLabel; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns the MPLS label which the egress traffic should tagged. |
| 181 | * |
| 182 | * @return egress MPLS label |
| 183 | */ |
| 184 | public Optional<MplsLabel> egressLabel() { |
| 185 | return egressLabel; |
| 186 | } |
| 187 | |
| 188 | } |