blob: 6e99b3569678745eea3d1e0ac1b1178dc40a9281 [file] [log] [blame]
alshabibfaa1e362015-04-02 15:01:54 -07001/*
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 */
16package org.onosproject.driver.pipeline;
17
18import com.google.common.util.concurrent.SettableFuture;
19import org.onlab.osgi.ServiceDirectory;
20import org.onosproject.core.DefaultGroupId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.behaviour.Pipeliner;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070023import org.onosproject.net.behaviour.PipelinerContext;
alshabib77b88482015-04-07 15:47:50 -070024import org.onosproject.net.driver.DriverData;
alshabibfaa1e362015-04-02 15:01:54 -070025import org.onosproject.net.flow.DefaultFlowRule;
26import org.onosproject.net.flow.FlowRule;
27import org.onosproject.net.flow.FlowRuleOperations;
28import org.onosproject.net.flow.FlowRuleOperationsContext;
29import org.onosproject.net.flow.FlowRuleService;
30import org.onosproject.net.flow.TrafficSelector;
31import org.onosproject.net.flowobjective.FilteringObjective;
32import org.onosproject.net.flowobjective.ForwardingObjective;
alshabib77b88482015-04-07 15:47:50 -070033import org.onosproject.net.flowobjective.NextObjective;
alshabibfaa1e362015-04-02 15:01:54 -070034import org.slf4j.Logger;
35
36import java.util.Collection;
37import java.util.concurrent.Future;
38
39import static org.slf4j.LoggerFactory.getLogger;
40
41/**
42 * Simple single table pipeline abstraction.
43 */
44public class DefaultSingleTablePipeline implements Pipeliner {
45
46 private final Logger log = getLogger(getClass());
47
48 private ServiceDirectory serviceDirectory;
49 private FlowRuleService flowRuleService;
50 private DeviceId deviceId;
51
52 @Override
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070053 public void init(DeviceId deviceId, PipelinerContext context) {
54 this.serviceDirectory = context.directory();
alshabibfaa1e362015-04-02 15:01:54 -070055 this.deviceId = deviceId;
56
57 flowRuleService = serviceDirectory.get(FlowRuleService.class);
58
59 }
60
61 @Override
62 public Future<Boolean> filter(Collection<FilteringObjective> filters) {
63 throw new UnsupportedOperationException("Single table does not filter.");
64 }
65
66 @Override
67 public Future<Boolean> forward(Collection<ForwardingObjective> forwardings) {
68 FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
69 forwardings.forEach(fwd -> {
70 if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) {
71 throw new UnsupportedOperationException(
72 "Only VERSATILE is supported.");
73 }
74
75 TrafficSelector selector = fwd.selector();
76
77 FlowRule rule = new DefaultFlowRule(deviceId, selector,
78 fwd.treatment(),
79 fwd.priority(), fwd.appId(),
80 new DefaultGroupId(fwd.id()),
81 fwd.timeout(), fwd.permanent());
82
83 switch (fwd.op()) {
84
85 case ADD:
86 flowBuilder.add(rule);
87 break;
88 case REMOVE:
89 flowBuilder.remove(rule);
90 break;
91 default:
92 log.warn("Unknown operation {}", fwd.op());
93 }
94
95 });
96
97 SettableFuture<Boolean> future = SettableFuture.create();
98
99 flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
100 @Override
101 public void onSuccess(FlowRuleOperations ops) {
102 future.set(true);
103 }
104
105 @Override
106 public void onError(FlowRuleOperations ops) {
107 future.set(false);
108 }
109 }));
110 return future;
111 }
alshabib77b88482015-04-07 15:47:50 -0700112
113 @Override
114 public Future<Boolean> next(Collection<NextObjective> nextObjectives) {
115 throw new UnsupportedOperationException("Single table does not next hop.");
116 }
117
118 @Override
119 public void setData(DriverData data) {
120
121 }
alshabibfaa1e362015-04-02 15:01:54 -0700122}