blob: 2b71ff789631dad8c90c6bcf0c60be6ba3edc332 [file] [log] [blame]
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -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
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;
45import org.onosproject.net.group.GroupKey;
46
47/**
48 * Spring-open driver implementation for Dell hardware switches.
49 */
50public class SpringOpenTTPDell extends SpringOpenTTP {
51
52 /* Table IDs to be used for Dell Open Segment Routers*/
53 private static final int DELL_TABLE_VLAN = 17;
54 private static final int DELL_TABLE_TMAC = 18;
55 private static final int DELL_TABLE_IPV4_UNICAST = 30;
56 private static final int DELL_TABLE_MPLS = 25;
57 private static final int DELL_TABLE_ACL = 40;
58
59 //TODO: Store this info in the distributed store.
60 private MacAddress deviceTMac = null;
61
62 public SpringOpenTTPDell() {
63 super();
64 vlanTableId = DELL_TABLE_VLAN;
65 tmacTableId = DELL_TABLE_TMAC;
66 ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST;
67 mplsTableId = DELL_TABLE_MPLS;
68 aclTableId = DELL_TABLE_ACL;
69 }
70
71 @Override
72 protected void setTableMissEntries() {
73 // No need to set table-miss-entries in Dell switches
74 return;
75 }
76
77 @Override
78 //Dell switches need ETH_DST based match condition in all IP table entries.
79 //So this method overrides the default spring-open behavior and adds
80 //ETH_DST match condition while pushing IP table flow rules
81 protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
82 log.debug("Processing specific");
83 TrafficSelector selector = fwd.selector();
84 EthTypeCriterion ethType = (EthTypeCriterion) selector
85 .getCriterion(Criterion.Type.ETH_TYPE);
86 if ((ethType == null) ||
alshabibcaf1ca22015-06-25 15:18:16 -070087 (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
88 (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070089 log.debug("processSpecific: Unsupported "
90 + "forwarding objective criteraia");
91 fail(fwd, ObjectiveError.UNSUPPORTED);
92 return Collections.emptySet();
93 }
94
95 TrafficSelector.Builder filteredSelectorBuilder =
96 DefaultTrafficSelector.builder();
97 int forTableId = -1;
alshabibcaf1ca22015-06-25 15:18:16 -070098 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070099 if (deviceTMac == null) {
100 log.debug("processSpecific: ETH_DST filtering "
101 + "objective is not set which is required "
102 + "before sending a IPv4 forwarding objective");
103 //TODO: Map the error to more appropriate error code.
104 fail(fwd, ObjectiveError.DEVICEMISSING);
105 return Collections.emptySet();
106 }
107 filteredSelectorBuilder = filteredSelectorBuilder
108 .matchEthType(Ethernet.TYPE_IPV4)
109 .matchEthDst(deviceTMac)
110 .matchIPDst(((IPCriterion) selector
111 .getCriterion(Criterion.Type.IPV4_DST))
112 .ip());
113 forTableId = ipv4UnicastTableId;
114 log.debug("processing IPv4 specific forwarding objective");
115 } else {
116 filteredSelectorBuilder = filteredSelectorBuilder
117 .matchEthType(Ethernet.MPLS_UNICAST)
118 .matchMplsLabel(((MplsCriterion)
119 selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
Charles Chan188ebf52015-12-23 00:15:11 -0800120 if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
121 filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion)
122 selector.getCriterion(Criterion.Type.MPLS_BOS)).mplsBos());
123 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700124 forTableId = mplsTableId;
125 log.debug("processing MPLS specific forwarding objective");
126 }
127
128 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
129 .builder();
130 if (fwd.treatment() != null) {
131 for (Instruction i : fwd.treatment().allInstructions()) {
132 treatmentBuilder.add(i);
133 }
134 }
135
136 if (fwd.nextId() != null) {
137 NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
138
139 if (next != null) {
140 GroupKey key = appKryo.deserialize(next.data());
141
142 Group group = groupService.getGroup(deviceId, key);
143
144 if (group == null) {
145 log.warn("The group left!");
146 fail(fwd, ObjectiveError.GROUPMISSING);
147 return Collections.emptySet();
148 }
149 treatmentBuilder.group(group.id());
150 log.debug("Adding OUTGROUP action");
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700151 } else {
152 log.warn("processSpecific: No associated next objective object");
153 fail(fwd, ObjectiveError.GROUPMISSING);
154 return Collections.emptySet();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700155 }
156 }
157
158 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
159 TrafficTreatment treatment = treatmentBuilder.transition(aclTableId)
160 .build();
161
162 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
163 .fromApp(fwd.appId()).withPriority(fwd.priority())
164 .forDevice(deviceId).withSelector(filteredSelector)
165 .withTreatment(treatment);
166
167 if (fwd.permanent()) {
168 ruleBuilder.makePermanent();
169 } else {
170 ruleBuilder.makeTemporary(fwd.timeout());
171 }
172
173 ruleBuilder.forTable(forTableId);
174 return Collections.singletonList(ruleBuilder.build());
175
176 }
177
178 @Override
179 //Dell switches need ETH_DST based match condition in all IP table entries.
180 //So while processing the ETH_DST based filtering objective, store
181 //the device MAC to be used locally to use it while pushing the IP rules.
Charles Chan68aa62d2015-11-09 16:37:23 -0800182 protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion,
183 VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700184 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800185 VlanId assignedVlan,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700186 ApplicationId applicationId) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700187 // Store device termination Mac to be used in IP flow entries
Charles Chan68aa62d2015-11-09 16:37:23 -0800188 deviceTMac = ethCriterion.mac();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700189
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700190 log.debug("For now not adding any TMAC rules "
191 + "into Dell switches as it is ignoring");
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700192
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700193 return Collections.emptyList();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700194 }
195
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700196 @Override
Charles Chan68aa62d2015-11-09 16:37:23 -0800197 protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700198 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800199 VlanId assignedVlan,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700200 ApplicationId applicationId) {
201 log.debug("For now not adding any VLAN rules "
202 + "into Dell switches as it is ignoring");
203
204 return Collections.emptyList();
205 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700206}