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