blob: e3afc0b6cc713877d21edd1fa33e05ce8a53e5dd [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
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070018import java.util.Collection;
19import java.util.Collections;
20import java.util.List;
21
22import org.onlab.packet.Ethernet;
23import org.onlab.packet.MacAddress;
Charles Chan68aa62d2015-11-09 16:37:23 -080024import org.onlab.packet.VlanId;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070025import org.onosproject.core.ApplicationId;
26import org.onosproject.net.behaviour.NextGroup;
27import org.onosproject.net.flow.DefaultFlowRule;
28import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.FlowRule;
31import org.onosproject.net.flow.TrafficSelector;
32import org.onosproject.net.flow.TrafficTreatment;
33import org.onosproject.net.flow.criteria.Criterion;
34import org.onosproject.net.flow.criteria.EthCriterion;
35import org.onosproject.net.flow.criteria.EthTypeCriterion;
36import org.onosproject.net.flow.criteria.IPCriterion;
Charles Chan188ebf52015-12-23 00:15:11 -080037import org.onosproject.net.flow.criteria.MplsBosCriterion;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070038import org.onosproject.net.flow.criteria.MplsCriterion;
Charles Chan68aa62d2015-11-09 16:37:23 -080039import org.onosproject.net.flow.criteria.VlanIdCriterion;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070040import org.onosproject.net.flow.instructions.Instruction;
41import org.onosproject.net.flowobjective.FilteringObjective;
42import org.onosproject.net.flowobjective.ForwardingObjective;
43import org.onosproject.net.flowobjective.ObjectiveError;
44import org.onosproject.net.group.Group;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070045
46/**
47 * Spring-open driver implementation for Dell hardware switches.
48 */
49public class SpringOpenTTPDell extends SpringOpenTTP {
50
51 /* Table IDs to be used for Dell Open Segment Routers*/
52 private static final int DELL_TABLE_VLAN = 17;
53 private static final int DELL_TABLE_TMAC = 18;
54 private static final int DELL_TABLE_IPV4_UNICAST = 30;
55 private static final int DELL_TABLE_MPLS = 25;
56 private static final int DELL_TABLE_ACL = 40;
57
58 //TODO: Store this info in the distributed store.
59 private MacAddress deviceTMac = null;
60
61 public SpringOpenTTPDell() {
62 super();
63 vlanTableId = DELL_TABLE_VLAN;
64 tmacTableId = DELL_TABLE_TMAC;
65 ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST;
66 mplsTableId = DELL_TABLE_MPLS;
67 aclTableId = DELL_TABLE_ACL;
68 }
69
70 @Override
71 protected void setTableMissEntries() {
72 // No need to set table-miss-entries in Dell switches
73 return;
74 }
75
76 @Override
77 //Dell switches need ETH_DST based match condition in all IP table entries.
78 //So this method overrides the default spring-open behavior and adds
79 //ETH_DST match condition while pushing IP table flow rules
80 protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
81 log.debug("Processing specific");
82 TrafficSelector selector = fwd.selector();
83 EthTypeCriterion ethType = (EthTypeCriterion) selector
84 .getCriterion(Criterion.Type.ETH_TYPE);
85 if ((ethType == null) ||
alshabibcaf1ca22015-06-25 15:18:16 -070086 (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
87 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070088 log.debug("processSpecific: Unsupported "
89 + "forwarding objective criteraia");
90 fail(fwd, ObjectiveError.UNSUPPORTED);
91 return Collections.emptySet();
92 }
93
94 TrafficSelector.Builder filteredSelectorBuilder =
95 DefaultTrafficSelector.builder();
96 int forTableId = -1;
alshabibcaf1ca22015-06-25 15:18:16 -070097 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070098 if (deviceTMac == null) {
99 log.debug("processSpecific: ETH_DST filtering "
100 + "objective is not set which is required "
101 + "before sending a IPv4 forwarding objective");
102 //TODO: Map the error to more appropriate error code.
103 fail(fwd, ObjectiveError.DEVICEMISSING);
104 return Collections.emptySet();
105 }
106 filteredSelectorBuilder = filteredSelectorBuilder
107 .matchEthType(Ethernet.TYPE_IPV4)
108 .matchEthDst(deviceTMac)
109 .matchIPDst(((IPCriterion) selector
110 .getCriterion(Criterion.Type.IPV4_DST))
111 .ip());
112 forTableId = ipv4UnicastTableId;
113 log.debug("processing IPv4 specific forwarding objective");
114 } else {
115 filteredSelectorBuilder = filteredSelectorBuilder
116 .matchEthType(Ethernet.MPLS_UNICAST)
117 .matchMplsLabel(((MplsCriterion)
118 selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
Charles Chan188ebf52015-12-23 00:15:11 -0800119 if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
120 filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion)
121 selector.getCriterion(Criterion.Type.MPLS_BOS)).mplsBos());
122 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700123 forTableId = mplsTableId;
124 log.debug("processing MPLS specific forwarding objective");
125 }
126
127 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
128 .builder();
129 if (fwd.treatment() != null) {
130 for (Instruction i : fwd.treatment().allInstructions()) {
131 treatmentBuilder.add(i);
132 }
133 }
134
135 if (fwd.nextId() != null) {
136 NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
137
138 if (next != null) {
Charles Chane3ba6952016-05-02 11:02:36 -0700139 SpringOpenGroup soGroup = appKryo.deserialize(next.data());
Saurav Das77621792016-05-03 16:36:57 -0700140 if (soGroup.dummy()) {
141 log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} "
142 + "in dev: {}", soGroup.treatment().allInstructions().size(),
143 fwd.id(), fwd.nextId(), deviceId);
144 for (Instruction ins : soGroup.treatment().allInstructions()) {
145 treatmentBuilder.add(ins);
146 }
147 } else {
148 Group group = groupService.getGroup(deviceId, soGroup.key());
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700149
Saurav Das77621792016-05-03 16:36:57 -0700150 if (group == null) {
151 log.warn("The group left!");
152 fail(fwd, ObjectiveError.GROUPMISSING);
153 return Collections.emptySet();
154 }
155 treatmentBuilder.group(group.id());
156 log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} "
157 + "for next:{} in dev: {}", group.id(), fwd.id(),
158 fwd.nextId(), deviceId);
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700159 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700160 } else {
161 log.warn("processSpecific: No associated next objective object");
162 fail(fwd, ObjectiveError.GROUPMISSING);
163 return Collections.emptySet();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700164 }
165 }
166
167 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
168 TrafficTreatment treatment = treatmentBuilder.transition(aclTableId)
169 .build();
170
171 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
172 .fromApp(fwd.appId()).withPriority(fwd.priority())
173 .forDevice(deviceId).withSelector(filteredSelector)
174 .withTreatment(treatment);
175
176 if (fwd.permanent()) {
177 ruleBuilder.makePermanent();
178 } else {
179 ruleBuilder.makeTemporary(fwd.timeout());
180 }
181
182 ruleBuilder.forTable(forTableId);
183 return Collections.singletonList(ruleBuilder.build());
184
185 }
186
187 @Override
188 //Dell switches need ETH_DST based match condition in all IP table entries.
189 //So while processing the ETH_DST based filtering objective, store
190 //the device MAC to be used locally to use it while pushing the IP rules.
Charles Chan68aa62d2015-11-09 16:37:23 -0800191 protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion,
192 VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700193 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800194 VlanId assignedVlan,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700195 ApplicationId applicationId) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700196 // Store device termination Mac to be used in IP flow entries
Charles Chan68aa62d2015-11-09 16:37:23 -0800197 deviceTMac = ethCriterion.mac();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700198
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700199 log.debug("For now not adding any TMAC rules "
200 + "into Dell switches as it is ignoring");
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700201
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700202 return Collections.emptyList();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700203 }
204
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700205 @Override
Charles Chan68aa62d2015-11-09 16:37:23 -0800206 protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700207 FilteringObjective filt,
Konstantinos Kanonakisa477e342016-06-03 13:27:27 -0500208 VlanId assignedVlan, VlanId modifiedVlan, VlanId pushedVlan,
209 boolean popVlan, boolean pushVlan,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700210 ApplicationId applicationId) {
211 log.debug("For now not adding any VLAN rules "
212 + "into Dell switches as it is ignoring");
213
214 return Collections.emptyList();
215 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700216}