blob: e1249a93184c233407900833f7a919f001531082 [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());
140 Group group = groupService.getGroup(deviceId, soGroup.key());
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700141
142 if (group == null) {
143 log.warn("The group left!");
144 fail(fwd, ObjectiveError.GROUPMISSING);
145 return Collections.emptySet();
146 }
147 treatmentBuilder.group(group.id());
148 log.debug("Adding OUTGROUP action");
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700149 } else {
150 log.warn("processSpecific: No associated next objective object");
151 fail(fwd, ObjectiveError.GROUPMISSING);
152 return Collections.emptySet();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700153 }
154 }
155
156 TrafficSelector filteredSelector = filteredSelectorBuilder.build();
157 TrafficTreatment treatment = treatmentBuilder.transition(aclTableId)
158 .build();
159
160 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
161 .fromApp(fwd.appId()).withPriority(fwd.priority())
162 .forDevice(deviceId).withSelector(filteredSelector)
163 .withTreatment(treatment);
164
165 if (fwd.permanent()) {
166 ruleBuilder.makePermanent();
167 } else {
168 ruleBuilder.makeTemporary(fwd.timeout());
169 }
170
171 ruleBuilder.forTable(forTableId);
172 return Collections.singletonList(ruleBuilder.build());
173
174 }
175
176 @Override
177 //Dell switches need ETH_DST based match condition in all IP table entries.
178 //So while processing the ETH_DST based filtering objective, store
179 //the device MAC to be used locally to use it while pushing the IP rules.
Charles Chan68aa62d2015-11-09 16:37:23 -0800180 protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion,
181 VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700182 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800183 VlanId assignedVlan,
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700184 ApplicationId applicationId) {
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700185 // Store device termination Mac to be used in IP flow entries
Charles Chan68aa62d2015-11-09 16:37:23 -0800186 deviceTMac = ethCriterion.mac();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700187
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700188 log.debug("For now not adding any TMAC rules "
189 + "into Dell switches as it is ignoring");
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700190
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700191 return Collections.emptyList();
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700192 }
193
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700194 @Override
Charles Chan68aa62d2015-11-09 16:37:23 -0800195 protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700196 FilteringObjective filt,
Charles Chan68aa62d2015-11-09 16:37:23 -0800197 VlanId assignedVlan,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700198 ApplicationId applicationId) {
199 log.debug("For now not adding any VLAN rules "
200 + "into Dell switches as it is ignoring");
201
202 return Collections.emptyList();
203 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700204}