blob: 9979cc101a3c46f06628a19a82dc7676479e3bc6 [file] [log] [blame]
Michele Santuari9a8d16d2016-03-24 10:37:58 -07001/*
2 * Copyright 2014-2016 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 */
16
17package org.onosproject.drivers.corsa;
18
Michele Santuarid2c8b152016-03-30 17:57:56 -070019import com.google.common.collect.ImmutableSet;
Michele Santuari9a8d16d2016-03-24 10:37:58 -070020import org.onlab.packet.Ethernet;
21import org.onlab.packet.IPv4;
22import org.onlab.packet.VlanId;
23import org.onosproject.net.flow.DefaultFlowRule;
24import org.onosproject.net.flow.DefaultTrafficSelector;
25import org.onosproject.net.flow.DefaultTrafficTreatment;
26import org.onosproject.net.flow.FlowRule;
27import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.net.flow.TrafficTreatment;
29import org.onosproject.net.flow.criteria.Criterion;
30import org.onosproject.net.flow.criteria.IPCriterion;
31import org.onosproject.net.flow.criteria.IPProtocolCriterion;
Michele Santuarid2c8b152016-03-30 17:57:56 -070032import org.onosproject.net.flow.instructions.Instructions;
33import org.onosproject.net.flow.instructions.L2ModificationInstruction;
Michele Santuari9a8d16d2016-03-24 10:37:58 -070034import org.onosproject.net.flowobjective.ForwardingObjective;
35import org.onosproject.net.flowobjective.ObjectiveError;
36import org.slf4j.Logger;
37
38import java.util.Collection;
39import java.util.Collections;
40
41import static org.onosproject.net.flow.FlowRule.Builder;
Michele Santuarid2c8b152016-03-30 17:57:56 -070042import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_DST;
43import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_SRC;
44import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID;
45import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP;
Michele Santuari9a8d16d2016-03-24 10:37:58 -070046import static org.slf4j.LoggerFactory.getLogger;
47
48public class CorsaPipelineV39 extends CorsaPipelineV3 {
49
50 private final Logger log = getLogger(getClass());
51
52 private static final Short NATIVE_VLAN = 4095;
53
54 @Override
55 public void initializePipeline() {
56
57 processMeterTable(true); //Meter Table
58 processPortBasedProtoTable(true);
59 processVlanCheckTable(true); //Table 1
60 processVlanMacXlateTable(true); //Table 2
61 processVlanCircuitTable(true); //Table 3
62 processL3IFMacDATable(true); //Table 5
63 processEtherTable(true); //Table 6
64 //TODO: to be implemented for intents
Michele Santuarid2c8b152016-03-30 17:57:56 -070065 processFibTable(true); //Table 7
Michele Santuari9a8d16d2016-03-24 10:37:58 -070066 //processLocalTable(true); //Table 9
67 }
68
69 @Override
70 protected void processVlanCheckTable(boolean install) {
Michele Santuarid2c8b152016-03-30 17:57:56 -070071 //current device pipeline reports errors, but it is a bug
Michele Santuari9a8d16d2016-03-24 10:37:58 -070072 processTableMissGoTo(true, VLAN_CHECK_TABLE, VLAN_MAC_XLATE_TABLE, "Provisioned vlan tagged");
73 //Tag untagged packets
74 processUntaggedPackets(install);
75
76 }
77
78 private void processUntaggedPackets(boolean install) {
79
80 deviceService.getPorts(deviceId).forEach(port -> {
81 if (!port.number().isLogical()) {
82
83 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
84 .pushVlan().setVlanId(VlanId.vlanId(NATIVE_VLAN))
85 .transition(VLAN_MAC_XLATE_TABLE);
86
87 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
88 .matchVlanId(VlanId.NONE)
89 .matchInPort(port.number());
90
91 Builder rule = DefaultFlowRule.builder()
92 .forDevice(deviceId)
93 .withTreatment(treatment.build())
94 .withSelector(selector.build())
95 .withPriority(CONTROLLER_PRIORITY)
96 .fromApp(appId)
97 .makePermanent()
98 .forTable(VLAN_CHECK_TABLE);
99
100 processFlowRule(install, rule.build(), "Provisioned vlan untagged packet table");
101 }
102 });
103 }
104
105 @Override
106 protected void processVlanCircuitTable(boolean install) {
107 //Default action
108 processTableMissDrop(install, VLAN_CIRCUIT_TABLE, "Provisioned vlan circuit table drop");
109 //FIXME: it should be done only per port based when intent is installed
110 //Manage untagged packets
111 processRouterPacket(install);
112 }
113
114 private void processRouterPacket(boolean install) {
115
116 deviceService.getPorts(deviceId).forEach(port -> {
117 if (!port.number().isLogical()) {
118 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
119 .matchVlanId(VlanId.vlanId(NATIVE_VLAN))
120 .matchInPort(port.number());
121
122 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
123 .setVlanPcp((byte) 0)
124 .setQueue(0)
125 .meter(defaultMeterId)
126 .transition(L3_IF_MAC_DA_TABLE);
127
128 FlowRule rule = DefaultFlowRule.builder()
129 .forDevice(deviceId)
130 .withSelector(selector.build())
131 .withTreatment(treatment.build())
132 .withPriority(CONTROLLER_PRIORITY)
133 .fromApp(appId)
134 .makePermanent()
135 .forTable(VLAN_CIRCUIT_TABLE).build();
136 processFlowRule(install, rule, "Provisioned vlan circuit table");
137 }
138 });
139 }
140
141 @Override
142 protected void processL3IFMacDATable(boolean install) {
143 int table = L3_IF_MAC_DA_TABLE;
144
145 //Default action
146 processTableMissDrop(install, table, "Provisioned l3 table drop");
147
148 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
149
150 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
151 .transition(ETHER_TABLE);
152
153 FlowRule rule = DefaultFlowRule.builder()
154 .forDevice(deviceId)
155 .withSelector(selector.build())
156 .withTreatment(treatment.build())
157 .withPriority(1)
158 .fromApp(appId)
159 .makePermanent()
160 .forTable(table).build();
161 processFlowRule(install, rule, "Provisioned l3 table");
162 }
163
164 protected void processEtherTable(boolean install) {
165
166 //Default action
167 processTableMissDrop(install, ETHER_TABLE, "Provisioned ether type table drop");
168
169 //IP to FIB_TABLE
170 TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
171 .matchEthType(Ethernet.TYPE_IPV4);
172
173 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().transition(FIB_TABLE);
174
175 FlowRule rule = DefaultFlowRule.builder()
176 .forDevice(deviceId)
177 .withSelector(selector.build())
178 .withTreatment(treatment.build())
179 .withPriority(CONTROLLER_PRIORITY)
180 .fromApp(appId)
181 .makePermanent()
182 .forTable(ETHER_TABLE).build();
183 processFlowRule(install, rule, "Provisioned ether type table ip");
184 }
185
186 @Override
187 protected Collection<FlowRule> processArpTraffic(ForwardingObjective fwd, Builder rule) {
188 rule.forTable(PORT_BASED_PROTO_TABLE);
189 rule.withPriority(255);
190 return Collections.singletonList(rule.build());
191 }
192
193 @Override
194 protected Collection<FlowRule> processLinkDiscovery(ForwardingObjective fwd, Builder rule) {
195 rule.forTable(PORT_BASED_PROTO_TABLE);
196 rule.withPriority(255);
197 return Collections.singletonList(rule.build());
198 }
199
200 @Override
201 protected Collection<FlowRule> processIpTraffic(ForwardingObjective fwd, Builder rule) {
202 IPCriterion ipSrc = (IPCriterion) fwd.selector()
203 .getCriterion(Criterion.Type.IPV4_SRC);
204 if (ipSrc != null) {
205 log.warn("Driver does not currently handle matching Src IP");
206 fail(fwd, ObjectiveError.UNSUPPORTED);
Michele Santuarid2c8b152016-03-30 17:57:56 -0700207 return ImmutableSet.of();
Michele Santuari9a8d16d2016-03-24 10:37:58 -0700208 }
209 IPCriterion ipDst = (IPCriterion) fwd.selector()
210 .getCriterion(Criterion.Type.IPV4_DST);
211 if (ipDst != null) {
212 log.error("Driver handles Dst IP matching as specific forwarding "
213 + "objective, not versatile");
214 fail(fwd, ObjectiveError.UNSUPPORTED);
Michele Santuarid2c8b152016-03-30 17:57:56 -0700215 return ImmutableSet.of();
Michele Santuari9a8d16d2016-03-24 10:37:58 -0700216 }
217 IPProtocolCriterion ipProto = (IPProtocolCriterion) fwd.selector()
218 .getCriterion(Criterion.Type.IP_PROTO);
219 if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) {
220 log.warn("Driver automatically punts all packets reaching the "
221 + "LOCAL table to the controller");
222 pass(fwd);
Michele Santuarid2c8b152016-03-30 17:57:56 -0700223 return ImmutableSet.of();
Michele Santuari9a8d16d2016-03-24 10:37:58 -0700224 }
Michele Santuarid2c8b152016-03-30 17:57:56 -0700225 return ImmutableSet.of();
226 }
227
228 @Override
229 protected TrafficTreatment processNextTreatment(TrafficTreatment treatment) {
230 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
231 tb.add(Instructions.popVlan());
232 treatment.immediate().stream()
233 .filter(i -> {
234 switch (i.type()) {
235 case L2MODIFICATION:
236 L2ModificationInstruction l2i = (L2ModificationInstruction) i;
237 if (l2i.subtype() == VLAN_ID ||
238 l2i.subtype() == VLAN_POP ||
239 l2i.subtype() == VLAN_POP ||
240 l2i.subtype() == ETH_DST ||
241 l2i.subtype() == ETH_SRC) {
242 return true;
243 }
244 case OUTPUT:
245 return true;
246 default:
247 return false;
248 }
249 }).forEach(i -> tb.add(i));
250 return tb.build();
Michele Santuari9a8d16d2016-03-24 10:37:58 -0700251 }
252}