Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.ImmutableList; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 21 | import org.onlab.packet.EthType; |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 24 | import org.onlab.packet.MplsLabel; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 26 | import org.onosproject.core.GroupId; |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 27 | import org.onosproject.net.IndexedLambda; |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 28 | import org.onosproject.net.PortNumber; |
| 29 | import org.onosproject.net.flow.instructions.Instruction; |
| 30 | import org.onosproject.net.flow.instructions.Instructions; |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 31 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 32 | import java.util.Collections; |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 33 | import java.util.List; |
| 34 | import java.util.Objects; |
Yuta HIGUCHI | 2809bf3 | 2014-10-20 22:44:12 -0700 | [diff] [blame] | 35 | |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 36 | import static com.google.common.base.Preconditions.checkNotNull; |
| 37 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Default traffic treatment implementation. |
| 40 | */ |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 41 | public final class DefaultTrafficTreatment implements TrafficTreatment { |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 42 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 43 | private final List<Instruction> immediate; |
| 44 | private final List<Instruction> deferred; |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 45 | private final List<Instruction> all; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 46 | private final Instructions.TableTypeTransition table; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 47 | private final Instructions.MetadataInstruction meta; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 48 | |
| 49 | private final boolean hasClear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 50 | |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 51 | private static final DefaultTrafficTreatment EMPTY |
| 52 | = new DefaultTrafficTreatment(Collections.emptyList()); |
| 53 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Creates a new traffic treatment from the specified list of instructions. |
| 56 | * |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 57 | * @param immediate immediate instructions |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 58 | */ |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 59 | private DefaultTrafficTreatment(List<Instruction> immediate) { |
| 60 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 61 | this.deferred = ImmutableList.of(); |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 62 | this.all = this.immediate; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 63 | this.hasClear = false; |
| 64 | this.table = null; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 65 | this.meta = null; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Creates a new traffic treatment from the specified list of instructions. |
| 70 | * |
| 71 | * @param deferred deferred instructions |
| 72 | * @param immediate immediate instructions |
| 73 | * @param table table transition instruction |
| 74 | * @param clear instruction to clear the deferred actions list |
| 75 | */ |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 76 | private DefaultTrafficTreatment(List<Instruction> deferred, |
| 77 | List<Instruction> immediate, |
| 78 | Instructions.TableTypeTransition table, |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 79 | boolean clear, |
| 80 | Instructions.MetadataInstruction meta) { |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 81 | this.immediate = ImmutableList.copyOf(checkNotNull(immediate)); |
| 82 | this.deferred = ImmutableList.copyOf(checkNotNull(deferred)); |
Sho SHIMIZU | d4fa7fd | 2015-06-30 18:56:05 -0700 | [diff] [blame] | 83 | this.all = new ImmutableList.Builder<Instruction>() |
| 84 | .addAll(immediate) |
| 85 | .addAll(deferred) |
| 86 | .build(); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 87 | this.table = table; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 88 | this.meta = meta; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 89 | this.hasClear = clear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 93 | public List<Instruction> deferred() { |
| 94 | return deferred; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public List<Instruction> immediate() { |
| 99 | return immediate; |
| 100 | } |
| 101 | |
| 102 | @Override |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 103 | public List<Instruction> allInstructions() { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 104 | return all; |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 108 | public Instructions.TableTypeTransition tableTransition() { |
| 109 | return table; |
| 110 | } |
| 111 | |
| 112 | @Override |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 113 | public boolean clearedDeferred() { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 114 | return hasClear; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 117 | @Override |
| 118 | public Instructions.MetadataInstruction writeMetadata() { |
| 119 | return meta; |
| 120 | } |
| 121 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 122 | /** |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 123 | * Returns a new traffic treatment builder. |
| 124 | * |
| 125 | * @return traffic treatment builder |
| 126 | */ |
| 127 | public static TrafficTreatment.Builder builder() { |
| 128 | return new Builder(); |
| 129 | } |
| 130 | |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 131 | /** |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 132 | * Returns an empty traffic treatment. |
| 133 | * |
| 134 | * @return empty traffic treatment |
| 135 | */ |
| 136 | public static TrafficTreatment emptyTreatment() { |
| 137 | return EMPTY; |
| 138 | } |
| 139 | |
| 140 | /** |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 141 | * Returns a new traffic treatment builder primed to produce entities |
| 142 | * patterned after the supplied treatment. |
| 143 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 144 | * @param treatment base treatment |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 145 | * @return traffic treatment builder |
| 146 | */ |
| 147 | public static TrafficTreatment.Builder builder(TrafficTreatment treatment) { |
| 148 | return new Builder(treatment); |
| 149 | } |
| 150 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 151 | //FIXME: Order of instructions may affect hashcode |
| 152 | @Override |
| 153 | public int hashCode() { |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 154 | return Objects.hash(immediate, deferred, table, meta); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public boolean equals(Object obj) { |
| 159 | if (this == obj) { |
| 160 | return true; |
| 161 | } |
| 162 | if (obj instanceof DefaultTrafficTreatment) { |
| 163 | DefaultTrafficTreatment that = (DefaultTrafficTreatment) obj; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 164 | return Objects.equals(immediate, that.immediate) && |
| 165 | Objects.equals(deferred, that.deferred) && |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 166 | Objects.equals(table, that.table) && |
| 167 | Objects.equals(meta, that.meta); |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 168 | |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
Jonathan Hart | d87aeca | 2014-10-21 10:42:52 -0700 | [diff] [blame] | 173 | @Override |
| 174 | public String toString() { |
| 175 | return MoreObjects.toStringHelper(getClass()) |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 176 | .add("immediate", immediate) |
| 177 | .add("deferred", deferred) |
| 178 | .add("transition", table == null ? "None" : table.toString()) |
| 179 | .add("cleared", hasClear) |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 180 | .add("metadata", meta) |
Jonathan Hart | d87aeca | 2014-10-21 10:42:52 -0700 | [diff] [blame] | 181 | .toString(); |
| 182 | } |
| 183 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 184 | /** |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 185 | * Builds a list of treatments following the following order. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 186 | * Modifications -> Group -> Output (including drop) |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 187 | */ |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 188 | public static final class Builder implements TrafficTreatment.Builder { |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 189 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 190 | boolean clear = false; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 191 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 192 | Instructions.TableTypeTransition table; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 193 | |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 194 | Instructions.MetadataInstruction meta; |
| 195 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 196 | List<Instruction> deferred = Lists.newLinkedList(); |
| 197 | |
| 198 | List<Instruction> immediate = Lists.newLinkedList(); |
| 199 | |
| 200 | List<Instruction> current = immediate; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 201 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 202 | // Creates a new builder |
| 203 | private Builder() { |
| 204 | } |
| 205 | |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 206 | // Creates a new builder based off an existing treatment |
| 207 | private Builder(TrafficTreatment treatment) { |
Jonathan Hart | 4a0ba56 | 2015-03-23 17:23:33 -0700 | [diff] [blame] | 208 | deferred(); |
| 209 | treatment.deferred().forEach(i -> add(i)); |
| 210 | |
| 211 | immediate(); |
| 212 | treatment.immediate().forEach(i -> add(i)); |
| 213 | |
| 214 | clear = treatment.clearedDeferred(); |
Jonathan Hart | 6e88c68 | 2014-10-21 17:05:25 -0700 | [diff] [blame] | 215 | } |
| 216 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 217 | @Override |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 218 | public Builder add(Instruction instruction) { |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 219 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 220 | switch (instruction.type()) { |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 221 | case DROP: |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 222 | case OUTPUT: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 223 | case GROUP: |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 224 | case L0MODIFICATION: |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 225 | case L2MODIFICATION: |
| 226 | case L3MODIFICATION: |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 227 | current.add(instruction); |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 228 | break; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 229 | case TABLE: |
| 230 | table = (Instructions.TableTypeTransition) instruction; |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 231 | break; |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 232 | case METADATA: |
| 233 | meta = (Instructions.MetadataInstruction) instruction; |
| 234 | break; |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 235 | default: |
tom | 1679e18 | 2014-10-09 13:50:45 -0700 | [diff] [blame] | 236 | throw new IllegalArgumentException("Unknown instruction type: " + |
| 237 | instruction.type()); |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 238 | } |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 239 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 240 | return this; |
| 241 | } |
| 242 | |
| 243 | @Override |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 244 | public Builder drop() { |
| 245 | return add(Instructions.createDrop()); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public Builder punt() { |
| 250 | return add(Instructions.createOutput(PortNumber.CONTROLLER)); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public Builder setOutput(PortNumber number) { |
| 255 | return add(Instructions.createOutput(number)); |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public Builder setEthSrc(MacAddress addr) { |
| 260 | return add(Instructions.modL2Src(addr)); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public Builder setEthDst(MacAddress addr) { |
| 265 | return add(Instructions.modL2Dst(addr)); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public Builder setVlanId(VlanId id) { |
| 270 | return add(Instructions.modVlanId(id)); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public Builder setVlanPcp(Byte pcp) { |
| 275 | return add(Instructions.modVlanPcp(pcp)); |
| 276 | } |
| 277 | |
| 278 | @Override |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 279 | public Builder setIpSrc(IpAddress addr) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 280 | return add(Instructions.modL3Src(addr)); |
| 281 | } |
| 282 | |
| 283 | @Override |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 284 | public Builder setIpDst(IpAddress addr) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 285 | return add(Instructions.modL3Dst(addr)); |
| 286 | } |
| 287 | |
| 288 | @Override |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 289 | public Builder decNwTtl() { |
| 290 | return add(Instructions.decNwTtl()); |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public Builder copyTtlIn() { |
| 295 | return add(Instructions.copyTtlIn()); |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public Builder copyTtlOut() { |
| 300 | return add(Instructions.copyTtlOut()); |
| 301 | } |
| 302 | |
| 303 | @Override |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 304 | public Builder pushMpls() { |
| 305 | return add(Instructions.pushMpls()); |
| 306 | } |
| 307 | |
| 308 | @Override |
| 309 | public Builder popMpls() { |
| 310 | return add(Instructions.popMpls()); |
| 311 | } |
| 312 | |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 313 | @Override |
alshabib | 0ad4398 | 2015-05-07 13:43:13 -0700 | [diff] [blame] | 314 | public Builder popMpls(int etherType) { |
alshabib | 7b808c5 | 2015-06-26 14:22:24 -0700 | [diff] [blame] | 315 | return add(Instructions.popMpls(new EthType(etherType))); |
| 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public Builder popMpls(EthType etherType) { |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 320 | return add(Instructions.popMpls(etherType)); |
| 321 | } |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 322 | |
| 323 | @Override |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 324 | public Builder setMpls(MplsLabel mplsLabel) { |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 325 | return add(Instructions.modMplsLabel(mplsLabel)); |
| 326 | } |
| 327 | |
| 328 | @Override |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 329 | public Builder decMplsTtl() { |
| 330 | return add(Instructions.decMplsTtl()); |
| 331 | } |
| 332 | |
Sho SHIMIZU | 9553bb8 | 2015-06-30 16:02:45 -0700 | [diff] [blame] | 333 | @Deprecated |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 334 | @Override |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 335 | public Builder setLambda(short lambda) { |
Ray Milkey | 85571eb | 2015-06-25 09:45:46 -0700 | [diff] [blame] | 336 | return add(Instructions.modL0Lambda(new IndexedLambda(lambda))); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | @Override |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 340 | public Builder group(GroupId groupId) { |
| 341 | return add(Instructions.createGroup(groupId)); |
| 342 | } |
| 343 | |
| 344 | @Override |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 345 | public Builder popVlan() { |
| 346 | return add(Instructions.popVlan()); |
| 347 | } |
| 348 | |
| 349 | @Override |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 350 | public Builder pushVlan() { |
| 351 | return add(Instructions.pushVlan()); |
| 352 | } |
| 353 | |
| 354 | @Override |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 355 | public Builder transition(FlowRule.Type type) { |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 356 | return add(Instructions.transition(type.ordinal())); |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public Builder transition(Integer tableId) { |
| 361 | return add(Instructions.transition(tableId)); |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public Builder immediate() { |
| 366 | current = immediate; |
| 367 | return this; |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public Builder deferred() { |
| 372 | current = deferred; |
| 373 | return this; |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public Builder wipeDeferred() { |
| 378 | clear = true; |
| 379 | return this; |
| 380 | } |
| 381 | |
| 382 | @Override |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 383 | public Builder writeMetadata(long metadata, long metadataMask) { |
| 384 | return add(Instructions.writeMetadata(metadata, metadataMask)); |
| 385 | } |
| 386 | |
| 387 | @Override |
Hyunsun Moon | a08c5d0 | 2015-07-14 17:53:00 -0700 | [diff] [blame] | 388 | public Builder setTunnelId(long tunnelId) { |
| 389 | return add(Instructions.modTunnelId(tunnelId)); |
| 390 | } |
| 391 | |
| 392 | @Override |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 393 | public TrafficTreatment build() { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 394 | //Don't add DROP instruction by default when instruction |
| 395 | //set is empty. This will be handled in DefaultSingleTablePipeline |
| 396 | //driver. |
| 397 | |
| 398 | //if (deferred.size() == 0 && immediate.size() == 0 |
| 399 | // && table == null && !clear) { |
| 400 | // drop(); |
| 401 | //} |
Saurav Das | 86af8f1 | 2015-05-25 23:55:33 -0700 | [diff] [blame] | 402 | return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta); |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | } |
| 406 | |
| 407 | } |