alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 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 | package org.onosproject.driver.pipeline; |
| 17 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 18 | import com.google.common.cache.Cache; |
| 19 | import com.google.common.cache.CacheBuilder; |
| 20 | import com.google.common.cache.RemovalCause; |
| 21 | import com.google.common.cache.RemovalNotification; |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 22 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 23 | import org.onlab.osgi.ServiceDirectory; |
| 24 | import org.onlab.packet.Ethernet; |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 25 | import org.onlab.packet.IPv4; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onlab.packet.VlanId; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 28 | import org.onlab.util.KryoNamespace; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 29 | import org.onosproject.core.ApplicationId; |
| 30 | import org.onosproject.core.CoreService; |
| 31 | import org.onosproject.net.DeviceId; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.NextGroup; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 33 | import org.onosproject.net.behaviour.Pipeliner; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 34 | import org.onosproject.net.behaviour.PipelinerContext; |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 35 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flow.DefaultFlowRule; |
| 37 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 39 | import org.onosproject.net.flow.FlowRule; |
| 40 | import org.onosproject.net.flow.FlowRuleOperations; |
| 41 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 42 | import org.onosproject.net.flow.FlowRuleService; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.Criteria; |
| 46 | import org.onosproject.net.flow.criteria.Criterion; |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 48 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 49 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 50 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 51 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 52 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 53 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 54 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 55 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 56 | import org.onosproject.net.flowobjective.NextObjective; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 57 | import org.onosproject.net.flowobjective.Objective; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 58 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 59 | import org.onosproject.net.group.DefaultGroupBucket; |
| 60 | import org.onosproject.net.group.DefaultGroupDescription; |
| 61 | import org.onosproject.net.group.DefaultGroupKey; |
| 62 | import org.onosproject.net.group.Group; |
| 63 | import org.onosproject.net.group.GroupBucket; |
| 64 | import org.onosproject.net.group.GroupBuckets; |
| 65 | import org.onosproject.net.group.GroupDescription; |
| 66 | import org.onosproject.net.group.GroupEvent; |
| 67 | import org.onosproject.net.group.GroupKey; |
| 68 | import org.onosproject.net.group.GroupListener; |
| 69 | import org.onosproject.net.group.GroupService; |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 70 | import org.onosproject.net.meter.MeterService; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 71 | import org.slf4j.Logger; |
| 72 | |
| 73 | import java.util.Collection; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 74 | import java.util.Collections; |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 75 | import java.util.List; |
Sho SHIMIZU | 4590604 | 2016-01-13 23:05:54 -0800 | [diff] [blame] | 76 | import java.util.Objects; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 77 | import java.util.Set; |
| 78 | import java.util.concurrent.Executors; |
| 79 | import java.util.concurrent.ScheduledExecutorService; |
| 80 | import java.util.concurrent.TimeUnit; |
| 81 | import java.util.stream.Collectors; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 82 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 83 | import static org.onlab.util.Tools.groupedThreads; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 84 | import static org.slf4j.LoggerFactory.getLogger; |
| 85 | |
| 86 | /** |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 87 | * OpenvSwitch emulation of the Corsa pipeline handler. |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 88 | */ |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 89 | public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeliner { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 90 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 91 | protected static final int MAC_TABLE = 0; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 92 | protected static final int VLAN_MPLS_TABLE = 1; |
| 93 | protected static final int VLAN_TABLE = 2; |
| 94 | //protected static final int MPLS_TABLE = 3; |
| 95 | protected static final int ETHER_TABLE = 4; |
| 96 | protected static final int COS_MAP_TABLE = 5; |
| 97 | protected static final int FIB_TABLE = 6; |
| 98 | protected static final int LOCAL_TABLE = 9; |
| 99 | |
| 100 | |
Saurav Das | d8b9700 | 2015-05-14 23:42:49 -0700 | [diff] [blame] | 101 | protected static final int CONTROLLER_PRIORITY = 255; |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 102 | protected static final int DROP_PRIORITY = 0; |
| 103 | protected static final int HIGHEST_PRIORITY = 0xffff; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 104 | |
| 105 | private final Logger log = getLogger(getClass()); |
| 106 | |
| 107 | private ServiceDirectory serviceDirectory; |
Saurav Das | d8b9700 | 2015-05-14 23:42:49 -0700 | [diff] [blame] | 108 | protected FlowRuleService flowRuleService; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 109 | private CoreService coreService; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 110 | private GroupService groupService; |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 111 | protected MeterService meterService; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 112 | private FlowObjectiveStore flowObjectiveStore; |
Saurav Das | d8b9700 | 2015-05-14 23:42:49 -0700 | [diff] [blame] | 113 | protected DeviceId deviceId; |
| 114 | protected ApplicationId appId; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 115 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 116 | private KryoNamespace appKryo = new KryoNamespace.Builder() |
| 117 | .register(GroupKey.class) |
| 118 | .register(DefaultGroupKey.class) |
| 119 | .register(CorsaGroup.class) |
| 120 | .register(byte[].class) |
| 121 | .build(); |
| 122 | |
| 123 | private Cache<GroupKey, NextObjective> pendingGroups; |
| 124 | |
| 125 | private ScheduledExecutorService groupChecker = |
| 126 | Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner", |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 127 | "ovs-corsa-%d", |
| 128 | log)); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 129 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 130 | @Override |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 131 | public void init(DeviceId deviceId, PipelinerContext context) { |
| 132 | this.serviceDirectory = context.directory(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 133 | this.deviceId = deviceId; |
| 134 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 135 | pendingGroups = CacheBuilder.newBuilder() |
| 136 | .expireAfterWrite(20, TimeUnit.SECONDS) |
| 137 | .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> { |
| 138 | if (notification.getCause() == RemovalCause.EXPIRED) { |
| 139 | fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED); |
| 140 | } |
| 141 | }).build(); |
| 142 | |
| 143 | groupChecker.scheduleAtFixedRate(new GroupChecker(), 0, 500, TimeUnit.MILLISECONDS); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 144 | |
| 145 | coreService = serviceDirectory.get(CoreService.class); |
| 146 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 147 | groupService = serviceDirectory.get(GroupService.class); |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 148 | meterService = serviceDirectory.get(MeterService.class); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 149 | flowObjectiveStore = context.store(); |
| 150 | |
| 151 | groupService.addListener(new InnerGroupListener()); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 152 | |
| 153 | appId = coreService.registerApplication( |
| 154 | "org.onosproject.driver.OVSCorsaPipeline"); |
| 155 | |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 156 | initializePipeline(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 160 | public void filter(FilteringObjective filteringObjective) { |
| 161 | if (filteringObjective.type() == FilteringObjective.Type.PERMIT) { |
| 162 | processFilter(filteringObjective, |
| 163 | filteringObjective.op() == Objective.Operation.ADD, |
| 164 | filteringObjective.appId()); |
| 165 | } else { |
| 166 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 167 | } |
| 168 | } |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 169 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 170 | @Override |
| 171 | public void forward(ForwardingObjective fwd) { |
| 172 | Collection<FlowRule> rules; |
| 173 | FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder(); |
| 174 | |
| 175 | rules = processForward(fwd); |
| 176 | switch (fwd.op()) { |
| 177 | case ADD: |
| 178 | rules.stream() |
Sho SHIMIZU | 4590604 | 2016-01-13 23:05:54 -0800 | [diff] [blame] | 179 | .filter(Objects::nonNull) |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 180 | .forEach(flowBuilder::add); |
| 181 | break; |
| 182 | case REMOVE: |
| 183 | rules.stream() |
Sho SHIMIZU | 4590604 | 2016-01-13 23:05:54 -0800 | [diff] [blame] | 184 | .filter(Objects::nonNull) |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 185 | .forEach(flowBuilder::remove); |
| 186 | break; |
| 187 | default: |
| 188 | fail(fwd, ObjectiveError.UNKNOWN); |
| 189 | log.warn("Unknown forwarding type {}", fwd.op()); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() { |
| 194 | @Override |
| 195 | public void onSuccess(FlowRuleOperations ops) { |
| 196 | pass(fwd); |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void onError(FlowRuleOperations ops) { |
| 201 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 202 | } |
| 203 | })); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 204 | |
| 205 | } |
| 206 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public void next(NextObjective nextObjective) { |
| 209 | switch (nextObjective.type()) { |
| 210 | case SIMPLE: |
| 211 | Collection<TrafficTreatment> treatments = nextObjective.next(); |
| 212 | if (treatments.size() == 1) { |
| 213 | TrafficTreatment treatment = treatments.iterator().next(); |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 214 | treatment = processNextTreatment(treatment); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 215 | GroupBucket bucket = |
| 216 | DefaultGroupBucket.createIndirectGroupBucket(treatment); |
| 217 | final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id())); |
| 218 | GroupDescription groupDescription |
| 219 | = new DefaultGroupDescription(deviceId, |
| 220 | GroupDescription.Type.INDIRECT, |
| 221 | new GroupBuckets(Collections |
| 222 | .singletonList(bucket)), |
| 223 | key, |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 224 | null, // let group service determine group id |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 225 | nextObjective.appId()); |
| 226 | groupService.addGroup(groupDescription); |
| 227 | pendingGroups.put(key, nextObjective); |
| 228 | } |
| 229 | break; |
| 230 | case HASHED: |
| 231 | case BROADCAST: |
| 232 | case FAILOVER: |
| 233 | fail(nextObjective, ObjectiveError.UNSUPPORTED); |
| 234 | log.warn("Unsupported next objective type {}", nextObjective.type()); |
| 235 | break; |
| 236 | default: |
| 237 | fail(nextObjective, ObjectiveError.UNKNOWN); |
| 238 | log.warn("Unknown next objective type {}", nextObjective.type()); |
| 239 | } |
| 240 | |
| 241 | } |
| 242 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 243 | /* Hook for altering the NextObjective treatment */ |
| 244 | protected TrafficTreatment processNextTreatment(TrafficTreatment treatment) { |
| 245 | return treatment; /* Keep treatment as is for OVSCorsaPipeline */ |
| 246 | } |
| 247 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 248 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 249 | switch (fwd.flag()) { |
| 250 | case SPECIFIC: |
| 251 | return processSpecific(fwd); |
| 252 | case VERSATILE: |
| 253 | return processVersatile(fwd); |
| 254 | default: |
| 255 | fail(fwd, ObjectiveError.UNKNOWN); |
| 256 | log.warn("Unknown forwarding flag {}", fwd.flag()); |
| 257 | } |
| 258 | return Collections.emptySet(); |
| 259 | } |
| 260 | |
| 261 | private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 262 | log.debug("Processing versatile forwarding objective"); |
| 263 | TrafficSelector selector = fwd.selector(); |
| 264 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 265 | EthTypeCriterion ethType = |
| 266 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 267 | if (ethType == null) { |
| 268 | log.error("Versatile forwarding objective must include ethType"); |
| 269 | fail(fwd, ObjectiveError.UNKNOWN); |
| 270 | return Collections.emptySet(); |
| 271 | } |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 272 | if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) { |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 273 | log.warn("Driver automatically handles ARP packets by punting to controller " |
| 274 | + " from ETHER table"); |
| 275 | pass(fwd); |
| 276 | return Collections.emptySet(); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 277 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP || |
| 278 | ethType.ethType().toShort() == Ethernet.TYPE_BSN) { |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 279 | log.warn("Driver currently does not currently handle LLDP packets"); |
| 280 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 281 | return Collections.emptySet(); |
alshabib | caf1ca2 | 2015-06-25 15:18:16 -0700 | [diff] [blame] | 282 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 283 | IPCriterion ipSrc = (IPCriterion) selector |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 284 | .getCriterion(Criterion.Type.IPV4_SRC); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 285 | IPCriterion ipDst = (IPCriterion) selector |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 286 | .getCriterion(Criterion.Type.IPV4_DST); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 287 | IPProtocolCriterion ipProto = (IPProtocolCriterion) selector |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 288 | .getCriterion(Criterion.Type.IP_PROTO); |
| 289 | if (ipSrc != null) { |
Saurav Das | bd7f742 | 2015-04-23 16:31:47 -0700 | [diff] [blame] | 290 | log.warn("Driver does not currently handle matching Src IP"); |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 291 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 292 | return Collections.emptySet(); |
| 293 | } |
| 294 | if (ipDst != null) { |
| 295 | log.error("Driver handles Dst IP matching as specific forwarding " |
| 296 | + "objective, not versatile"); |
| 297 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 298 | return Collections.emptySet(); |
| 299 | } |
| 300 | if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) { |
| 301 | log.warn("Driver automatically punts all packets reaching the " |
| 302 | + "LOCAL table to the controller"); |
| 303 | pass(fwd); |
| 304 | return Collections.emptySet(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | log.warn("Driver does not support given versatile forwarding objective"); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 309 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 310 | return Collections.emptySet(); |
| 311 | } |
| 312 | |
| 313 | private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { |
Saurav Das | 3d03826 | 2015-04-23 12:36:58 -0700 | [diff] [blame] | 314 | log.debug("Processing specific forwarding objective"); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 315 | TrafficSelector selector = fwd.selector(); |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 316 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 317 | EthTypeCriterion ethType = |
| 318 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 319 | if (ethType != null) { |
| 320 | short et = ethType.ethType().toShort(); |
| 321 | if (et == Ethernet.TYPE_IPV4) { |
| 322 | return processSpecificRoute(fwd); |
| 323 | } else if (et == Ethernet.TYPE_VLAN) { |
| 324 | /* The ForwardingObjective must specify VLAN ethtype in order to use the Transit Circuit */ |
| 325 | return processSpecificSwitch(fwd); |
| 326 | } |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 329 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 330 | return Collections.emptySet(); |
| 331 | } |
| 332 | |
| 333 | private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 334 | TrafficSelector filteredSelector = |
| 335 | DefaultTrafficSelector.builder() |
| 336 | .matchEthType(Ethernet.TYPE_IPV4) |
| 337 | .matchIPDst( |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 338 | ((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip()) |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 339 | .build(); |
| 340 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 341 | TrafficTreatment.Builder tb = processSpecificRoutingTreatment(); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 342 | |
sangho | dde53d1 | 2015-04-30 10:34:41 -0700 | [diff] [blame] | 343 | if (fwd.nextId() != null) { |
| 344 | NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId()); |
| 345 | GroupKey key = appKryo.deserialize(next.data()); |
| 346 | Group group = groupService.getGroup(deviceId, key); |
| 347 | if (group == null) { |
| 348 | log.warn("The group left!"); |
| 349 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 350 | return Collections.emptySet(); |
| 351 | } |
| 352 | tb.group(group.id()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 353 | } |
| 354 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 355 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 356 | .fromApp(fwd.appId()) |
| 357 | .withPriority(fwd.priority()) |
| 358 | .forDevice(deviceId) |
| 359 | .withSelector(filteredSelector) |
sangho | dde53d1 | 2015-04-30 10:34:41 -0700 | [diff] [blame] | 360 | .withTreatment(tb.build()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 361 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 362 | ruleBuilder = processSpecificRoutingRule(ruleBuilder); |
| 363 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 364 | if (fwd.permanent()) { |
| 365 | ruleBuilder.makePermanent(); |
| 366 | } else { |
| 367 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 368 | } |
| 369 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 370 | return Collections.singletonList(ruleBuilder.build()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 373 | /* Hook for modifying Route traffic treatment */ |
| 374 | protected TrafficTreatment.Builder processSpecificRoutingTreatment() { |
| 375 | return DefaultTrafficTreatment.builder(); |
| 376 | } |
| 377 | |
| 378 | /* Hook for modifying Route flow rule */ |
| 379 | protected FlowRule.Builder processSpecificRoutingRule(FlowRule.Builder rb) { |
| 380 | return rb.forTable(FIB_TABLE); |
| 381 | } |
| 382 | |
| 383 | protected Collection<FlowRule> processSpecificSwitch(ForwardingObjective fwd) { |
| 384 | /* Not supported by until CorsaPipelineV3 */ |
| 385 | log.warn("Vlan switching not supported in ovs-corsa driver"); |
| 386 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 387 | return Collections.emptySet(); |
| 388 | } |
| 389 | |
| 390 | protected void processFilter(FilteringObjective filt, boolean install, |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 391 | ApplicationId applicationId) { |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 392 | // This driver only processes filtering criteria defined with switch |
| 393 | // ports as the key |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 394 | PortCriterion p; |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 395 | if (!filt.key().equals(Criteria.dummy()) && |
| 396 | filt.key().type() == Criterion.Type.IN_PORT) { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 397 | p = (PortCriterion) filt.key(); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 398 | } else { |
| 399 | log.warn("No key defined in filtering objective from app: {}. Not" |
| 400 | + "processing filtering objective", applicationId); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 401 | fail(filt, ObjectiveError.UNKNOWN); |
| 402 | return; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 403 | } |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 404 | // convert filtering conditions for switch-intfs into flowrules |
| 405 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 406 | for (Criterion c : filt.conditions()) { |
| 407 | if (c.type() == Criterion.Type.ETH_DST) { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 408 | EthCriterion e = (EthCriterion) c; |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 409 | log.debug("adding rule for MAC: {}", e.mac()); |
| 410 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 411 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 412 | selector.matchEthDst(e.mac()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 413 | treatment.transition(VLAN_MPLS_TABLE); |
| 414 | FlowRule rule = DefaultFlowRule.builder() |
| 415 | .forDevice(deviceId) |
| 416 | .withSelector(selector.build()) |
| 417 | .withTreatment(treatment.build()) |
| 418 | .withPriority(CONTROLLER_PRIORITY) |
| 419 | .fromApp(applicationId) |
| 420 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 421 | .forTable(MAC_TABLE).build(); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 422 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 423 | } else if (c.type() == Criterion.Type.VLAN_VID) { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 424 | VlanIdCriterion v = (VlanIdCriterion) c; |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 425 | log.debug("adding rule for VLAN: {}", v.vlanId()); |
| 426 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 427 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 428 | selector.matchVlanId(v.vlanId()); |
| 429 | selector.matchInPort(p.port()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 430 | treatment.transition(ETHER_TABLE); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 431 | treatment.deferred().popVlan(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 432 | FlowRule rule = DefaultFlowRule.builder() |
| 433 | .forDevice(deviceId) |
| 434 | .withSelector(selector.build()) |
| 435 | .withTreatment(treatment.build()) |
| 436 | .withPriority(CONTROLLER_PRIORITY) |
| 437 | .fromApp(applicationId) |
| 438 | .makePermanent() |
| 439 | .forTable(VLAN_TABLE).build(); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 440 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 441 | } else if (c.type() == Criterion.Type.IPV4_DST) { |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 442 | IPCriterion ip = (IPCriterion) c; |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 443 | log.debug("adding rule for IP: {}", ip.ip()); |
| 444 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 445 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 446 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 447 | selector.matchIPDst(ip.ip()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 448 | treatment.transition(LOCAL_TABLE); |
| 449 | FlowRule rule = DefaultFlowRule.builder() |
| 450 | .forDevice(deviceId) |
| 451 | .withSelector(selector.build()) |
| 452 | .withTreatment(treatment.build()) |
| 453 | .withPriority(HIGHEST_PRIORITY) |
| 454 | .fromApp(applicationId) |
| 455 | .makePermanent() |
| 456 | .forTable(FIB_TABLE).build(); |
| 457 | |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 458 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 459 | } else { |
| 460 | log.warn("Driver does not currently process filtering condition" |
| 461 | + " of type: {}", c.type()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 462 | fail(filt, ObjectiveError.UNSUPPORTED); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | // apply filtering flow rules |
| 466 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 467 | @Override |
| 468 | public void onSuccess(FlowRuleOperations ops) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 469 | pass(filt); |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 470 | log.info("Applied filtering rules"); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | @Override |
| 474 | public void onError(FlowRuleOperations ops) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 475 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 476 | log.info("Failed to apply filtering rules"); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 477 | } |
| 478 | })); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 481 | protected void pass(Objective obj) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 482 | obj.context().ifPresent(context -> context.onSuccess(obj)); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 485 | protected void fail(Objective obj, ObjectiveError error) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 486 | obj.context().ifPresent(context -> context.onError(obj, error)); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Jonathan Gravel | 8c9f7bc | 2015-12-03 15:46:20 -0500 | [diff] [blame] | 489 | protected void initializePipeline() { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 490 | processMacTable(true); |
| 491 | processVlanMplsTable(true); |
| 492 | processVlanTable(true); |
| 493 | processEtherTable(true); |
| 494 | processCosTable(true); |
| 495 | processFibTable(true); |
| 496 | processLocalTable(true); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 499 | private void processMacTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 500 | TrafficSelector.Builder selector; |
| 501 | TrafficTreatment.Builder treatment; |
| 502 | |
| 503 | // Bcast rule |
| 504 | selector = DefaultTrafficSelector.builder(); |
| 505 | treatment = DefaultTrafficTreatment.builder(); |
| 506 | |
| 507 | selector.matchEthDst(MacAddress.BROADCAST); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 508 | treatment.transition(VLAN_MPLS_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 509 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 510 | FlowRule rule = DefaultFlowRule.builder() |
| 511 | .forDevice(deviceId) |
| 512 | .withSelector(selector.build()) |
| 513 | .withTreatment(treatment.build()) |
| 514 | .withPriority(CONTROLLER_PRIORITY) |
| 515 | .fromApp(appId) |
| 516 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 517 | .forTable(MAC_TABLE).build(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 518 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 519 | |
| 520 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 521 | |
| 522 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 523 | |
| 524 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 525 | //Drop rule |
| 526 | selector = DefaultTrafficSelector.builder(); |
| 527 | treatment = DefaultTrafficTreatment.builder(); |
| 528 | |
| 529 | treatment.drop(); |
| 530 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 531 | rule = DefaultFlowRule.builder() |
| 532 | .forDevice(deviceId) |
| 533 | .withSelector(selector.build()) |
| 534 | .withTreatment(treatment.build()) |
| 535 | .withPriority(DROP_PRIORITY) |
| 536 | .fromApp(appId) |
| 537 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 538 | .forTable(MAC_TABLE).build(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 539 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 540 | |
| 541 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 542 | |
| 543 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 544 | @Override |
| 545 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 546 | log.info("Provisioned mac table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | @Override |
| 550 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 551 | log.info("Failed to provision mac table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 552 | } |
| 553 | })); |
| 554 | |
| 555 | } |
| 556 | |
Saurav Das | d8b9700 | 2015-05-14 23:42:49 -0700 | [diff] [blame] | 557 | protected void processVlanMplsTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 558 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 559 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 560 | .builder(); |
| 561 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 562 | FlowRule rule; |
| 563 | |
| 564 | selector.matchVlanId(VlanId.ANY); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 565 | treatment.transition(VLAN_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 566 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 567 | rule = DefaultFlowRule.builder() |
| 568 | .forDevice(deviceId) |
| 569 | .withSelector(selector.build()) |
| 570 | .withTreatment(treatment.build()) |
| 571 | .withPriority(CONTROLLER_PRIORITY) |
| 572 | .fromApp(appId) |
| 573 | .makePermanent() |
| 574 | .forTable(VLAN_MPLS_TABLE).build(); |
| 575 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 576 | |
| 577 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 578 | |
| 579 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 580 | @Override |
| 581 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 582 | log.info("Provisioned vlan/mpls table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public void onError(FlowRuleOperations ops) { |
| 587 | log.info( |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 588 | "Failed to provision vlan/mpls table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 589 | } |
| 590 | })); |
| 591 | |
| 592 | } |
| 593 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 594 | private void processVlanTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 595 | TrafficSelector.Builder selector; |
| 596 | TrafficTreatment.Builder treatment; |
| 597 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 598 | FlowRule rule; |
| 599 | |
| 600 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 601 | //Drop rule |
| 602 | selector = DefaultTrafficSelector.builder(); |
| 603 | treatment = DefaultTrafficTreatment.builder(); |
| 604 | |
| 605 | treatment.drop(); |
| 606 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 607 | rule = DefaultFlowRule.builder() |
| 608 | .forDevice(deviceId) |
| 609 | .withSelector(selector.build()) |
| 610 | .withTreatment(treatment.build()) |
| 611 | .withPriority(DROP_PRIORITY) |
| 612 | .fromApp(appId) |
| 613 | .makePermanent() |
| 614 | .forTable(VLAN_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 615 | |
| 616 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 617 | |
| 618 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 619 | @Override |
| 620 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 621 | log.info("Provisioned vlan table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 626 | log.info("Failed to provision vlan table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 627 | } |
| 628 | })); |
| 629 | } |
| 630 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 631 | private void processEtherTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 632 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 633 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 634 | .builder(); |
| 635 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 636 | FlowRule rule; |
| 637 | |
| 638 | selector.matchEthType(Ethernet.TYPE_ARP); |
| 639 | treatment.punt(); |
| 640 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 641 | rule = DefaultFlowRule.builder() |
| 642 | .forDevice(deviceId) |
| 643 | .withSelector(selector.build()) |
| 644 | .withTreatment(treatment.build()) |
| 645 | .withPriority(CONTROLLER_PRIORITY) |
| 646 | .fromApp(appId) |
| 647 | .makePermanent() |
| 648 | .forTable(ETHER_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 649 | |
| 650 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 651 | |
| 652 | selector = DefaultTrafficSelector.builder(); |
| 653 | treatment = DefaultTrafficTreatment.builder(); |
| 654 | |
| 655 | selector.matchEthType(Ethernet.TYPE_IPV4); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 656 | treatment.transition(COS_MAP_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 657 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 658 | rule = DefaultFlowRule.builder() |
| 659 | .forDevice(deviceId) |
| 660 | .withPriority(CONTROLLER_PRIORITY) |
| 661 | .withSelector(selector.build()) |
| 662 | .withTreatment(treatment.build()) |
| 663 | .fromApp(appId) |
| 664 | .makePermanent() |
| 665 | .forTable(ETHER_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 666 | |
| 667 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 668 | |
| 669 | //Drop rule |
| 670 | selector = DefaultTrafficSelector.builder(); |
| 671 | treatment = DefaultTrafficTreatment.builder(); |
| 672 | |
| 673 | treatment.drop(); |
| 674 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 675 | rule = DefaultFlowRule.builder() |
| 676 | .forDevice(deviceId) |
| 677 | .withSelector(selector.build()) |
| 678 | .withTreatment(treatment.build()) |
| 679 | .withPriority(DROP_PRIORITY) |
| 680 | .fromApp(appId) |
| 681 | .makePermanent() |
| 682 | .forTable(ETHER_TABLE).build(); |
| 683 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 684 | |
| 685 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 686 | |
| 687 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 688 | @Override |
| 689 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 690 | log.info("Provisioned ether table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | @Override |
| 694 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 695 | log.info("Failed to provision ether table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 696 | } |
| 697 | })); |
| 698 | |
| 699 | } |
| 700 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 701 | private void processCosTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 702 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 703 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 704 | .builder(); |
| 705 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 706 | FlowRule rule; |
| 707 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 708 | treatment.transition(FIB_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 709 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 710 | rule = DefaultFlowRule.builder() |
| 711 | .forDevice(deviceId) |
| 712 | .withSelector(selector.build()) |
| 713 | .withTreatment(treatment.build()) |
| 714 | .withPriority(DROP_PRIORITY) |
| 715 | .fromApp(appId) |
| 716 | .makePermanent() |
| 717 | .forTable(COS_MAP_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 718 | |
| 719 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 720 | |
| 721 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 722 | @Override |
| 723 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 724 | log.info("Provisioned cos table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | @Override |
| 728 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 729 | log.info("Failed to provision cos table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 730 | } |
| 731 | })); |
| 732 | |
| 733 | } |
| 734 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 735 | private void processFibTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 736 | TrafficSelector.Builder selector; |
| 737 | TrafficTreatment.Builder treatment; |
| 738 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 739 | FlowRule rule; |
| 740 | |
| 741 | //Drop rule |
| 742 | selector = DefaultTrafficSelector.builder(); |
| 743 | treatment = DefaultTrafficTreatment.builder(); |
| 744 | |
| 745 | treatment.drop(); |
| 746 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 747 | rule = DefaultFlowRule.builder() |
| 748 | .forDevice(deviceId) |
| 749 | .withSelector(selector.build()) |
| 750 | .withTreatment(treatment.build()) |
| 751 | .withPriority(DROP_PRIORITY) |
| 752 | .fromApp(appId) |
| 753 | .makePermanent() |
| 754 | .forTable(FIB_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 755 | |
| 756 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 757 | |
| 758 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 759 | @Override |
| 760 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 761 | log.info("Provisioned FIB table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | @Override |
| 765 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 766 | log.info("Failed to provision FIB table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 767 | } |
| 768 | })); |
| 769 | } |
| 770 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 771 | private void processLocalTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 772 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 773 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 774 | .builder(); |
| 775 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 776 | FlowRule rule; |
| 777 | |
| 778 | treatment.punt(); |
| 779 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 780 | rule = DefaultFlowRule.builder() |
| 781 | .forDevice(deviceId) |
| 782 | .withSelector(selector.build()) |
| 783 | .withTreatment(treatment.build()) |
| 784 | .withPriority(CONTROLLER_PRIORITY) |
| 785 | .fromApp(appId) |
| 786 | .makePermanent() |
| 787 | .forTable(LOCAL_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 788 | |
| 789 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 790 | |
| 791 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 792 | @Override |
| 793 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 794 | log.info("Provisioned Local table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | @Override |
| 798 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 799 | log.info("Failed to provision Local table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 800 | } |
| 801 | })); |
| 802 | } |
| 803 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 804 | private class InnerGroupListener implements GroupListener { |
| 805 | @Override |
| 806 | public void event(GroupEvent event) { |
| 807 | if (event.type() == GroupEvent.Type.GROUP_ADDED) { |
| 808 | GroupKey key = event.subject().appCookie(); |
| 809 | |
| 810 | NextObjective obj = pendingGroups.getIfPresent(key); |
| 811 | if (obj != null) { |
| 812 | flowObjectiveStore.putNextGroup(obj.id(), new CorsaGroup(key)); |
| 813 | pass(obj); |
| 814 | pendingGroups.invalidate(key); |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | |
| 821 | private class GroupChecker implements Runnable { |
| 822 | |
| 823 | @Override |
| 824 | public void run() { |
| 825 | Set<GroupKey> keys = pendingGroups.asMap().keySet().stream() |
| 826 | .filter(key -> groupService.getGroup(deviceId, key) != null) |
| 827 | .collect(Collectors.toSet()); |
| 828 | |
| 829 | keys.stream().forEach(key -> { |
| 830 | NextObjective obj = pendingGroups.getIfPresent(key); |
| 831 | if (obj == null) { |
| 832 | return; |
| 833 | } |
| 834 | pass(obj); |
| 835 | pendingGroups.invalidate(key); |
Saurav Das | bd7f742 | 2015-04-23 16:31:47 -0700 | [diff] [blame] | 836 | log.info("Heard back from group service for group {}. " |
| 837 | + "Applying pending forwarding objectives", obj.id()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 838 | flowObjectiveStore.putNextGroup(obj.id(), new CorsaGroup(key)); |
| 839 | }); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | private class CorsaGroup implements NextGroup { |
| 844 | |
| 845 | private final GroupKey key; |
| 846 | |
| 847 | public CorsaGroup(GroupKey key) { |
| 848 | this.key = key; |
| 849 | } |
| 850 | |
Saurav Das | e3274c8 | 2015-05-24 17:21:56 -0700 | [diff] [blame] | 851 | @SuppressWarnings("unused") |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 852 | public GroupKey key() { |
| 853 | return key; |
| 854 | } |
| 855 | |
| 856 | @Override |
| 857 | public byte[] data() { |
| 858 | return appKryo.serialize(key); |
| 859 | } |
| 860 | |
| 861 | } |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 862 | |
| 863 | @Override |
| 864 | public List<String> getNextMappings(NextGroup nextGroup) { |
| 865 | // TODO Implementation deferred to vendor |
| 866 | return null; |
| 867 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 868 | } |