blob: 27743495b8228fc4bd6bd8c77c11cc67cf6dce8c [file] [log] [blame]
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -07003 *
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
Yuta HIGUCHI6a1ee2d2016-07-24 00:21:26 -070018import static org.slf4j.LoggerFactory.getLogger;
19
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070020import java.util.Collection;
21import java.util.Collections;
22import java.util.List;
23
24import org.onlab.packet.Ethernet;
25import org.onlab.packet.MacAddress;
Charles Chan68aa62d2015-11-09 16:37:23 -080026import org.onlab.packet.VlanId;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070027import org.onosproject.core.ApplicationId;
28import org.onosproject.net.behaviour.NextGroup;
29import org.onosproject.net.flow.DefaultFlowRule;
30import org.onosproject.net.flow.DefaultTrafficSelector;
31import org.onosproject.net.flow.DefaultTrafficTreatment;
32import org.onosproject.net.flow.FlowRule;
33import org.onosproject.net.flow.TrafficSelector;
34import org.onosproject.net.flow.TrafficTreatment;
35import org.onosproject.net.flow.criteria.Criterion;
36import org.onosproject.net.flow.criteria.EthCriterion;
37import org.onosproject.net.flow.criteria.EthTypeCriterion;
38import org.onosproject.net.flow.criteria.IPCriterion;
Charles Chan188ebf52015-12-23 00:15:11 -080039import org.onosproject.net.flow.criteria.MplsBosCriterion;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070040import org.onosproject.net.flow.criteria.MplsCriterion;
Charles Chan68aa62d2015-11-09 16:37:23 -080041import org.onosproject.net.flow.criteria.VlanIdCriterion;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070042import org.onosproject.net.flow.instructions.Instruction;
43import org.onosproject.net.flowobjective.FilteringObjective;
44import org.onosproject.net.flowobjective.ForwardingObjective;
45import org.onosproject.net.flowobjective.ObjectiveError;
46import org.onosproject.net.group.Group;
Yuta HIGUCHI6a1ee2d2016-07-24 00:21:26 -070047import org.slf4j.Logger;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070048
49/**
50 * Spring-open driver implementation for Dell hardware switches.
51 */
52public class SpringOpenTTPDell extends SpringOpenTTP {
53
54 /* Table IDs to be used for Dell Open Segment Routers*/
55 private static final int DELL_TABLE_VLAN = 17;
56 private static final int DELL_TABLE_TMAC = 18;
57 private static final int DELL_TABLE_IPV4_UNICAST = 30;
58 private static final int DELL_TABLE_MPLS = 25;
59 private static final int DELL_TABLE_ACL = 40;
60
Yuta HIGUCHI6a1ee2d2016-07-24 00:21:26 -070061 private final Logger log = getLogger(getClass());
62
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070063 //TODO: Store this info in the distributed store.
64 private MacAddress deviceTMac = null;
65
66 public SpringOpenTTPDell() {
67 super();
68 vlanTableId = DELL_TABLE_VLAN;
69 tmacTableId = DELL_TABLE_TMAC;
70 ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST;
71 mplsTableId = DELL_TABLE_MPLS;
72 aclTableId = DELL_TABLE_ACL;
73 }
74
75 @Override
76 protected void setTableMissEntries() {
77 // No need to set table-miss-entries in Dell switches
78 return;
79 }
80
81 @Override
82 //Dell switches need ETH_DST based match condition in all IP table entries.
83 //So this method overrides the default spring-open behavior and adds
84 //ETH_DST match condition while pushing IP table flow rules
85 protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
86 log.debug("Processing specific");
87 TrafficSelector selector = fwd.selector();
88 EthTypeCriterion ethType = (EthTypeCriterion) selector
89 .getCriterion(Criterion.Type.ETH_TYPE);
90 if ((ethType == null) ||
alshabibcaf1ca22015-06-25 15:18:16 -070091 (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
92 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070093 log.debug("processSpecific: Unsupported "
94 + "forwarding objective criteraia");
95 fail(fwd, ObjectiveError.UNSUPPORTED);
96 return Collections.emptySet();
97 }
98
99 TrafficSelector.Builder filteredSelectorBuilder =
100 DefaultTrafficSelector.builder();
101 int forTableId = -1;
alshabibcaf1ca22015-06-25 15:18:16 -0700102 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700103 if (deviceTMac == null) {
104 log.debug("processSpecific: ETH_DST filtering "
105 + "objective is not set which is required "
106 + "before sending a IPv4 forwarding objective");
107 //TODO: Map the error to more appropriate error code.
108 fail(fwd, ObjectiveError.DEVICEMISSING);
109 return Collections.emptySet();
110 }
111 filteredSelectorBuilder = filteredSelectorBuilder
112 .matchEthType(Ethernet.TYPE_IPV4)
113 .matchEthDst(deviceTMac)
114 .matchIPDst(((IPCriterion) selector
115 .getCriterion(Criterion.Type.IPV4_DST))
116 .ip());
117 forTableId = ipv4UnicastTableId;
118 log.debug("processing IPv4 specific forwarding objective");
119 } else {
120 filteredSelectorBuilder = filteredSelectorBuilder
121 .matchEthType(Ethernet.MPLS_UNICAST)
122 .matchMplsLabel(((MplsCriterion)
123 selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
Charles Chan188ebf52015-12-23 00:15:11 -0800124 if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
125 filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion)
126 selector.getCriterion(Criterion.Type.MPLS_BOS)).mplsBos());
127 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700128 forTableId = mplsTableId;
129 log.debug("processing MPLS specific forwarding objective");
130 }
131
132 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
133 .builder();
134 if (fwd.treatment() != null) {
135 for (Instruction i : fwd.treatment().allInstructions()) {
136 treatmentBuilder.add(i);
137 }
138 }
139
140 if (fwd.nextId() != null) {
141 NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
142
143 if (next != null) {
Charles Chane3ba6952016-05-02 11:02:36 -0700144 SpringOpenGroup soGroup = appKryo.deserialize(next.data());
Saurav Das77621792016-05-03 16:36:57 -0700145 if (soGroup.dummy()) {
146 log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} "
147 + "in dev: {}", soGroup.treatment().allInstructions().size(),
148 fwd.id(), fwd.nextId(), deviceId);
149 for (Instruction ins : soGroup.treatment().allInstructions()) {
150 treatmentBuilder.add(ins);
151 }
152 } else {
153 Group group = groupService.getGroup(deviceId, soGroup.key());
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700154
Saurav Das77621792016-05-03 16:36:57 -0700155 if (group == null) {
156 log.warn("The group left!");
157 fail(fwd, ObjectiveError.GROUPMISSING);
158 return Collections.emptySet();
159 }
160 treatmentBuilder.group(group.id());
161 log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} "
162 + "for next:{} in dev: {}", group.id(), fwd.id(),
163 fwd.nextId(), deviceId);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700164 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700165 } else {
166 log.warn("processSpecific: No associated next objective object");
167 fail(fwd, ObjectiveError.GROUPMISSING);
168 return Collections.emptySet();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700169 }
170 }
171
172 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
173 TrafficTreatment treatment = treatmentBuilder.transition(aclTableId)
174 .build();
175
176 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
177 .fromApp(fwd.appId()).withPriority(fwd.priority())
178 .forDevice(deviceId).withSelector(filteredSelector)
179 .withTreatment(treatment);
180
181 if (fwd.permanent()) {
182 ruleBuilder.makePermanent();
183 } else {
184 ruleBuilder.makeTemporary(fwd.timeout());
185 }
186
187 ruleBuilder.forTable(forTableId);
188 return Collections.singletonList(ruleBuilder.build());
189
190 }
191
192 @Override
193 //Dell switches need ETH_DST based match condition in all IP table entries.
194 //So while processing the ETH_DST based filtering objective, store
195 //the device MAC to be used locally to use it while pushing the IP rules.
Charles Chan68aa62d2015-11-09 16:37:23 -0800196 protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion,
197 VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700198 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800199 VlanId assignedVlan,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700200 ApplicationId applicationId) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700201 // Store device termination Mac to be used in IP flow entries
Charles Chan68aa62d2015-11-09 16:37:23 -0800202 deviceTMac = ethCriterion.mac();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700203
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700204 log.debug("For now not adding any TMAC rules "
205 + "into Dell switches as it is ignoring");
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700206
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700207 return Collections.emptyList();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700208 }
209
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700210 @Override
Charles Chan68aa62d2015-11-09 16:37:23 -0800211 protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700212 FilteringObjective filt,
Konstantinos Kanonakisa477e342016-06-03 13:27:27 -0500213 VlanId assignedVlan, VlanId modifiedVlan, VlanId pushedVlan,
214 boolean popVlan, boolean pushVlan,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700215 ApplicationId applicationId) {
216 log.debug("For now not adding any VLAN rules "
217 + "into Dell switches as it is ignoring");
218
219 return Collections.emptyList();
220 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700221}