blob: 09698a46e5050f970dd70c0c8cc4a6efdd6ac174 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 Jampani117aaae2014-10-23 10:04:05 -070016package org.onlab.onos.net.flow;
17
18import java.util.Collections;
19import java.util.List;
20
Brian O'Connor427a1762014-11-19 18:40:32 -080021import com.google.common.base.Function;
22import com.google.common.collect.FluentIterable;
23
24
Madan Jampani117aaae2014-10-23 10:04:05 -070025
26import com.google.common.collect.Lists;
27
28public class FlowRuleBatchRequest {
29
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070030 private final int batchId;
Brian O'Connor427a1762014-11-19 18:40:32 -080031 private final List<FlowRuleBatchEntry> toAdd;
32 private final List<FlowRuleBatchEntry> toRemove;
Madan Jampani117aaae2014-10-23 10:04:05 -070033
Brian O'Connor427a1762014-11-19 18:40:32 -080034 public FlowRuleBatchRequest(int batchId, List<FlowRuleBatchEntry> toAdd,
35 List<FlowRuleBatchEntry> toRemove) {
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070036 this.batchId = batchId;
Madan Jampani117aaae2014-10-23 10:04:05 -070037 this.toAdd = Collections.unmodifiableList(toAdd);
38 this.toRemove = Collections.unmodifiableList(toRemove);
39 }
40
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080041 public List<FlowRule> toAdd() {
Brian O'Connor427a1762014-11-19 18:40:32 -080042 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 Jampani117aaae2014-10-23 10:04:05 -070050 }
51
Yuta HIGUCHI2fcb40c2014-11-03 14:39:10 -080052 public List<FlowRule> toRemove() {
Brian O'Connor427a1762014-11-19 18:40:32 -080053 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 Jampani117aaae2014-10-23 10:04:05 -070061 }
62
63 public FlowRuleBatchOperation asBatchOperation() {
64 List<FlowRuleBatchEntry> entries = Lists.newArrayList();
Brian O'Connor427a1762014-11-19 18:40:32 -080065 entries.addAll(toAdd);
66 entries.addAll(toRemove);
Madan Jampani117aaae2014-10-23 10:04:05 -070067 return new FlowRuleBatchOperation(entries);
68 }
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070069
70 public int batchId() {
71 return batchId;
72 }
Madan Jampani117aaae2014-10-23 10:04:05 -070073}