Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.flow; |
| 17 | |
| 18 | import java.util.Collections; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; |
| 22 | |
| 23 | import com.google.common.collect.Lists; |
| 24 | |
| 25 | public class FlowRuleBatchRequest { |
| 26 | |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 27 | private final int batchId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 28 | private final List<FlowEntry> toAdd; |
| 29 | private final List<FlowEntry> toRemove; |
| 30 | |
Yuta HIGUCHI | 92891d1 | 2014-10-27 20:04:38 -0700 | [diff] [blame] | 31 | public FlowRuleBatchRequest(int batchId, List<? extends FlowEntry> toAdd, List<? extends FlowEntry> toRemove) { |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 32 | this.batchId = batchId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 33 | this.toAdd = Collections.unmodifiableList(toAdd); |
| 34 | this.toRemove = Collections.unmodifiableList(toRemove); |
| 35 | } |
| 36 | |
| 37 | public List<FlowEntry> toAdd() { |
| 38 | return toAdd; |
| 39 | } |
| 40 | |
| 41 | public List<FlowEntry> toRemove() { |
| 42 | return toRemove; |
| 43 | } |
| 44 | |
| 45 | public FlowRuleBatchOperation asBatchOperation() { |
| 46 | List<FlowRuleBatchEntry> entries = Lists.newArrayList(); |
| 47 | for (FlowEntry e : toAdd) { |
| 48 | entries.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, e)); |
| 49 | } |
| 50 | for (FlowEntry e : toRemove) { |
| 51 | entries.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, e)); |
| 52 | } |
| 53 | return new FlowRuleBatchOperation(entries); |
| 54 | } |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 55 | |
| 56 | public int batchId() { |
| 57 | return batchId; |
| 58 | } |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 59 | } |