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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Collections; |
| 19 | import java.util.List; |
| 20 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 21 | import com.google.common.base.Function; |
| 22 | import com.google.common.collect.FluentIterable; |
| 23 | |
| 24 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 25 | |
| 26 | import com.google.common.collect.Lists; |
| 27 | |
| 28 | public class FlowRuleBatchRequest { |
| 29 | |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 30 | private final int batchId; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 31 | private final List<FlowRuleBatchEntry> toAdd; |
| 32 | private final List<FlowRuleBatchEntry> toRemove; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 33 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 34 | public FlowRuleBatchRequest(int batchId, List<FlowRuleBatchEntry> toAdd, |
| 35 | List<FlowRuleBatchEntry> toRemove) { |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 36 | this.batchId = batchId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 37 | this.toAdd = Collections.unmodifiableList(toAdd); |
| 38 | this.toRemove = Collections.unmodifiableList(toRemove); |
| 39 | } |
| 40 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 41 | public List<FlowRule> toAdd() { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 42 | return FluentIterable.from(toAdd).transform( |
| 43 | new Function<FlowRuleBatchEntry, FlowRule>() { |
| 44 | |
| 45 | @Override |
| 46 | public FlowRule apply(FlowRuleBatchEntry input) { |
| 47 | return input.getTarget(); |
| 48 | } |
| 49 | }).toList(); |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 52 | public List<FlowRule> toRemove() { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 53 | return FluentIterable.from(toRemove).transform( |
| 54 | new Function<FlowRuleBatchEntry, FlowRule>() { |
| 55 | |
| 56 | @Override |
| 57 | public FlowRule apply(FlowRuleBatchEntry input) { |
| 58 | return input.getTarget(); |
| 59 | } |
| 60 | }).toList(); |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public FlowRuleBatchOperation asBatchOperation() { |
| 64 | List<FlowRuleBatchEntry> entries = Lists.newArrayList(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 65 | entries.addAll(toAdd); |
| 66 | entries.addAll(toRemove); |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 67 | return new FlowRuleBatchOperation(entries); |
| 68 | } |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 69 | |
| 70 | public int batchId() { |
| 71 | return batchId; |
| 72 | } |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 73 | } |