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