alshabib | 0ccde6d | 2015-05-30 18:22:36 -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 | 0ccde6d | 2015-05-30 18:22:36 -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 | d61b77b | 2016-02-01 23:30:53 -0800 | [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; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 22 | import com.google.common.collect.Lists; |
| 23 | import org.apache.commons.lang3.tuple.ImmutablePair; |
| 24 | import org.apache.commons.lang3.tuple.Pair; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 25 | import org.onlab.osgi.ServiceDirectory; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 26 | import org.onlab.packet.EthType; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 27 | import org.onlab.packet.IPv4; |
| 28 | import org.onlab.packet.VlanId; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 29 | import org.onlab.util.KryoNamespace; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.PortNumber; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 34 | import org.onosproject.net.behaviour.NextGroup; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 35 | import org.onosproject.net.behaviour.Pipeliner; |
| 36 | import org.onosproject.net.behaviour.PipelinerContext; |
| 37 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 38 | import org.onosproject.net.flow.DefaultFlowRule; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 39 | import org.onosproject.net.flow.DefaultTrafficSelector; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 40 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 41 | import org.onosproject.net.flow.FlowRule; |
| 42 | import org.onosproject.net.flow.FlowRuleOperations; |
| 43 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 44 | import org.onosproject.net.flow.FlowRuleService; |
| 45 | import org.onosproject.net.flow.TrafficSelector; |
| 46 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.Criteria; |
| 48 | import org.onosproject.net.flow.criteria.Criterion; |
| 49 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flow.criteria.IPCriterion; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 52 | import org.onosproject.net.flow.criteria.PortCriterion; |
Amit Ghosh | cbaf867 | 2016-12-23 21:36:19 +0000 | [diff] [blame] | 53 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
alshabib | 2f74f2c | 2016-01-14 13:29:35 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flow.instructions.Instructions; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 57 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 58 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 59 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 60 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 61 | import org.onosproject.net.flowobjective.NextObjective; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 62 | import org.onosproject.net.flowobjective.Objective; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 63 | import org.onosproject.net.flowobjective.ObjectiveError; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 64 | import org.onosproject.net.group.DefaultGroupBucket; |
| 65 | import org.onosproject.net.group.DefaultGroupDescription; |
| 66 | import org.onosproject.net.group.DefaultGroupKey; |
| 67 | import org.onosproject.net.group.Group; |
| 68 | import org.onosproject.net.group.GroupBucket; |
| 69 | import org.onosproject.net.group.GroupBuckets; |
| 70 | import org.onosproject.net.group.GroupDescription; |
| 71 | import org.onosproject.net.group.GroupEvent; |
| 72 | import org.onosproject.net.group.GroupKey; |
| 73 | import org.onosproject.net.group.GroupListener; |
| 74 | import org.onosproject.net.group.GroupService; |
| 75 | import org.onosproject.store.serializers.KryoNamespaces; |
alshabib | 5ccbe3f | 2016-03-02 22:36:02 -0800 | [diff] [blame] | 76 | import org.onosproject.store.service.StorageService; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 77 | import org.slf4j.Logger; |
| 78 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 79 | import java.util.Collection; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 80 | import java.util.Collections; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 81 | import java.util.List; |
| 82 | import java.util.Optional; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 83 | import java.util.concurrent.TimeUnit; |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 84 | import java.util.stream.Collectors; |
| 85 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 86 | import static org.slf4j.LoggerFactory.getLogger; |
| 87 | |
| 88 | /** |
Jonathan Hart | 64da69d | 2015-07-15 15:10:28 -0700 | [diff] [blame] | 89 | * Pipeliner for OLT device. |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 90 | */ |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 91 | |
Jonathan Hart | b92cc51 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 92 | public class OltPipeline extends AbstractHandlerBehaviour implements Pipeliner { |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 93 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 94 | private static final Integer QQ_TABLE = 1; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 95 | private static final short MCAST_VLAN = 4000; |
alshabib | 5ccbe3f | 2016-03-02 22:36:02 -0800 | [diff] [blame] | 96 | private static final String OLTCOOKIES = "olt-cookies-must-be-unique"; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 97 | private final Logger log = getLogger(getClass()); |
| 98 | |
| 99 | private ServiceDirectory serviceDirectory; |
| 100 | private FlowRuleService flowRuleService; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 101 | private GroupService groupService; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 102 | private CoreService coreService; |
alshabib | 5ccbe3f | 2016-03-02 22:36:02 -0800 | [diff] [blame] | 103 | private StorageService storageService; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 104 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 105 | private DeviceId deviceId; |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 106 | private ApplicationId appId; |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 107 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 108 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 109 | protected FlowObjectiveStore flowObjectiveStore; |
| 110 | |
| 111 | private Cache<GroupKey, NextObjective> pendingGroups; |
| 112 | |
| 113 | protected static KryoNamespace appKryo = new KryoNamespace.Builder() |
| 114 | .register(KryoNamespaces.API) |
| 115 | .register(GroupKey.class) |
| 116 | .register(DefaultGroupKey.class) |
| 117 | .register(OLTPipelineGroup.class) |
Charles Chan | eefdedf | 2016-05-23 16:45:45 -0700 | [diff] [blame] | 118 | .build("OltPipeline"); |
alshabib | 2cc73cb | 2015-06-30 20:26:56 -0700 | [diff] [blame] | 119 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 120 | @Override |
| 121 | public void init(DeviceId deviceId, PipelinerContext context) { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 122 | log.debug("Initiate OLT pipeline"); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 123 | this.serviceDirectory = context.directory(); |
| 124 | this.deviceId = deviceId; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 125 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 126 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 127 | coreService = serviceDirectory.get(CoreService.class); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 128 | groupService = serviceDirectory.get(GroupService.class); |
| 129 | flowObjectiveStore = context.store(); |
alshabib | 5ccbe3f | 2016-03-02 22:36:02 -0800 | [diff] [blame] | 130 | storageService = serviceDirectory.get(StorageService.class); |
| 131 | |
Jonathan Hart | dfc3b86 | 2015-07-01 14:49:56 -0700 | [diff] [blame] | 132 | appId = coreService.registerApplication( |
| 133 | "org.onosproject.driver.OLTPipeline"); |
| 134 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 135 | |
| 136 | pendingGroups = CacheBuilder.newBuilder() |
| 137 | .expireAfterWrite(20, TimeUnit.SECONDS) |
| 138 | .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> { |
| 139 | if (notification.getCause() == RemovalCause.EXPIRED) { |
| 140 | fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED); |
| 141 | } |
| 142 | }).build(); |
| 143 | |
| 144 | groupService.addListener(new InnerGroupListener()); |
| 145 | |
alshabib | b32cefe | 2015-06-08 18:15:05 -0700 | [diff] [blame] | 146 | } |
| 147 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 148 | @Override |
| 149 | public void filter(FilteringObjective filter) { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 150 | Instructions.OutputInstruction output; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 151 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 152 | if (filter.meta() != null && !filter.meta().immediate().isEmpty()) { |
| 153 | output = (Instructions.OutputInstruction) filter.meta().immediate().stream() |
| 154 | .filter(t -> t.type().equals(Instruction.Type.OUTPUT)) |
| 155 | .limit(1) |
| 156 | .findFirst().get(); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 157 | |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 158 | if (output == null || !output.port().equals(PortNumber.CONTROLLER)) { |
| 159 | log.error("OLT can only filter packet to controller"); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 160 | fail(filter, ObjectiveError.UNSUPPORTED); |
| 161 | return; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 162 | } |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 163 | } else { |
| 164 | fail(filter, ObjectiveError.BADPARAMS); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 168 | if (filter.key().type() != Criterion.Type.IN_PORT) { |
| 169 | fail(filter, ObjectiveError.BADPARAMS); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | EthTypeCriterion ethType = (EthTypeCriterion) |
| 174 | filterForCriterion(filter.conditions(), Criterion.Type.ETH_TYPE); |
| 175 | |
| 176 | if (ethType == null) { |
| 177 | fail(filter, ObjectiveError.BADPARAMS); |
| 178 | return; |
| 179 | } |
| 180 | |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 181 | if (ethType.ethType().equals(EthType.EtherType.EAPOL.ethType())) { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 182 | provisionEapol(filter, ethType, output); |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 183 | } else if (ethType.ethType().equals(EthType.EtherType.IPV4.ethType())) { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 184 | IPProtocolCriterion ipProto = (IPProtocolCriterion) |
| 185 | filterForCriterion(filter.conditions(), Criterion.Type.IP_PROTO); |
| 186 | if (ipProto.protocol() == IPv4.PROTOCOL_IGMP) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 187 | provisionIgmp(filter, ethType, ipProto, output); |
Amit Ghosh | cbaf867 | 2016-12-23 21:36:19 +0000 | [diff] [blame] | 188 | } else if (ipProto.protocol() == IPv4.PROTOCOL_UDP) { |
| 189 | UdpPortCriterion udpSrcPort = (UdpPortCriterion) |
| 190 | filterForCriterion(filter.conditions(), Criterion.Type.UDP_SRC); |
| 191 | |
| 192 | UdpPortCriterion udpDstPort = (UdpPortCriterion) |
| 193 | filterForCriterion(filter.conditions(), Criterion.Type.UDP_DST); |
| 194 | |
| 195 | if (udpSrcPort.udpPort().toInt() != 68 || udpDstPort.udpPort().toInt() != 67) { |
| 196 | log.error("OLT can only filte DHCP, wrong UDP Src or Dst Port"); |
| 197 | fail(filter, ObjectiveError.UNSUPPORTED); |
| 198 | } |
| 199 | provisionDhcp(filter, ethType, ipProto, udpSrcPort, udpDstPort, output); |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 200 | } else { |
Amit Ghosh | cbaf867 | 2016-12-23 21:36:19 +0000 | [diff] [blame] | 201 | log.error("OLT can only filter igmp and DHCP"); |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 202 | fail(filter, ObjectiveError.UNSUPPORTED); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 203 | } |
| 204 | } else { |
Amit Ghosh | cbaf867 | 2016-12-23 21:36:19 +0000 | [diff] [blame] | 205 | log.error("OLT can only filter eapol igmp"); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 206 | fail(filter, ObjectiveError.UNSUPPORTED); |
| 207 | } |
| 208 | |
| 209 | } |
| 210 | |
| 211 | |
| 212 | @Override |
| 213 | public void forward(ForwardingObjective fwd) { |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 214 | |
| 215 | if (checkForMulticast(fwd)) { |
| 216 | processMulticastRule(fwd); |
| 217 | return; |
| 218 | } |
| 219 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 220 | TrafficTreatment treatment = fwd.treatment(); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 221 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 222 | List<Instruction> instructions = treatment.allInstructions(); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 223 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 224 | Optional<Instruction> vlanIntruction = instructions.stream() |
| 225 | .filter(i -> i.type() == Instruction.Type.L2MODIFICATION) |
| 226 | .filter(i -> ((L2ModificationInstruction) i).subtype() == |
| 227 | L2ModificationInstruction.L2SubType.VLAN_PUSH || |
| 228 | ((L2ModificationInstruction) i).subtype() == |
| 229 | L2ModificationInstruction.L2SubType.VLAN_POP) |
| 230 | .findAny(); |
| 231 | |
| 232 | if (!vlanIntruction.isPresent()) { |
| 233 | fail(fwd, ObjectiveError.BADPARAMS); |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | L2ModificationInstruction vlanIns = |
| 238 | (L2ModificationInstruction) vlanIntruction.get(); |
| 239 | |
| 240 | if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) { |
| 241 | installUpstreamRules(fwd); |
| 242 | } else if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP) { |
| 243 | installDownstreamRules(fwd); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 244 | } else { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 245 | log.error("Unknown OLT operation: {}", fwd); |
| 246 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 247 | return; |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 250 | pass(fwd); |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 251 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 254 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 255 | @Override |
| 256 | public void next(NextObjective nextObjective) { |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 257 | if (nextObjective.type() != NextObjective.Type.BROADCAST) { |
| 258 | log.error("OLT only supports broadcast groups."); |
| 259 | fail(nextObjective, ObjectiveError.BADPARAMS); |
| 260 | } |
| 261 | |
| 262 | if (nextObjective.next().size() != 1) { |
| 263 | log.error("OLT only supports singleton broadcast groups."); |
| 264 | fail(nextObjective, ObjectiveError.BADPARAMS); |
| 265 | } |
| 266 | |
| 267 | TrafficTreatment treatment = nextObjective.next().stream().findFirst().get(); |
| 268 | |
| 269 | |
| 270 | GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(treatment); |
| 271 | GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id())); |
| 272 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 273 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 274 | pendingGroups.put(key, nextObjective); |
| 275 | |
| 276 | switch (nextObjective.op()) { |
| 277 | case ADD: |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 278 | GroupDescription groupDesc = |
| 279 | new DefaultGroupDescription(deviceId, |
| 280 | GroupDescription.Type.ALL, |
| 281 | new GroupBuckets(Collections.singletonList(bucket)), |
| 282 | key, |
| 283 | null, |
| 284 | nextObjective.appId()); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 285 | groupService.addGroup(groupDesc); |
| 286 | break; |
| 287 | case REMOVE: |
| 288 | groupService.removeGroup(deviceId, key, nextObjective.appId()); |
| 289 | break; |
| 290 | case ADD_TO_EXISTING: |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 291 | groupService.addBucketsToGroup(deviceId, key, |
| 292 | new GroupBuckets(Collections.singletonList(bucket)), |
| 293 | key, nextObjective.appId()); |
| 294 | break; |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 295 | case REMOVE_FROM_EXISTING: |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 296 | groupService.removeBucketsFromGroup(deviceId, key, |
alshabib | 56efe43 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 297 | new GroupBuckets(Collections.singletonList(bucket)), |
| 298 | key, nextObjective.appId()); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 299 | break; |
| 300 | default: |
| 301 | log.warn("Unknown next objective operation: {}", nextObjective.op()); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | } |
| 306 | |
| 307 | private void processMulticastRule(ForwardingObjective fwd) { |
| 308 | if (fwd.nextId() == null) { |
| 309 | log.error("Multicast objective does not have a next id"); |
| 310 | fail(fwd, ObjectiveError.BADPARAMS); |
| 311 | } |
| 312 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 313 | GroupKey key = getGroupForNextObjective(fwd.nextId()); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 314 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 315 | if (key == null) { |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 316 | log.error("Group for forwarding objective missing: {}", fwd); |
| 317 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 318 | } |
| 319 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 320 | Group group = groupService.getGroup(deviceId, key); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 321 | TrafficTreatment treatment = |
| 322 | buildTreatment(Instructions.createGroup(group.id())); |
| 323 | |
| 324 | FlowRule rule = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 325 | .fromApp(fwd.appId()) |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 326 | .forDevice(deviceId) |
| 327 | .forTable(0) |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 328 | .makePermanent() |
| 329 | .withPriority(fwd.priority()) |
| 330 | .withSelector(fwd.selector()) |
| 331 | .withTreatment(treatment) |
| 332 | .build(); |
| 333 | |
| 334 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
| 335 | switch (fwd.op()) { |
| 336 | |
| 337 | case ADD: |
| 338 | builder.add(rule); |
| 339 | break; |
| 340 | case REMOVE: |
| 341 | builder.remove(rule); |
| 342 | break; |
| 343 | case ADD_TO_EXISTING: |
| 344 | case REMOVE_FROM_EXISTING: |
| 345 | break; |
| 346 | default: |
| 347 | log.warn("Unknown forwarding operation: {}", fwd.op()); |
| 348 | } |
| 349 | |
| 350 | applyFlowRules(builder, fwd); |
| 351 | |
| 352 | } |
| 353 | |
| 354 | private boolean checkForMulticast(ForwardingObjective fwd) { |
| 355 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 356 | IPCriterion ip = (IPCriterion) filterForCriterion(fwd.selector().criteria(), |
alshabib | 56efe43 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 357 | Criterion.Type.IPV4_DST); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 358 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 359 | if (ip == null) { |
| 360 | return false; |
| 361 | } |
| 362 | |
Charles Chan | aedabfd | 2016-02-26 09:31:48 -0800 | [diff] [blame] | 363 | return ip.ip().isMulticast(); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 364 | |
| 365 | } |
| 366 | |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 367 | private GroupKey getGroupForNextObjective(Integer nextId) { |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 368 | NextGroup next = flowObjectiveStore.getNextGroup(nextId); |
alshabib | 1aa5814 | 2016-02-17 15:37:56 -0800 | [diff] [blame] | 369 | return appKryo.deserialize(next.data()); |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 370 | |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 373 | private void installDownstreamRules(ForwardingObjective fwd) { |
| 374 | List<Pair<Instruction, Instruction>> vlanOps = |
| 375 | vlanOps(fwd, |
| 376 | L2ModificationInstruction.L2SubType.VLAN_POP); |
| 377 | |
| 378 | if (vlanOps == null) { |
| 379 | return; |
| 380 | } |
| 381 | |
alshabib | b3c1434 | 2016-03-04 17:05:01 -0800 | [diff] [blame] | 382 | Instructions.OutputInstruction output = (Instructions.OutputInstruction) fetchOutput(fwd, "downstream"); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 383 | |
| 384 | if (output == null) { |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | Pair<Instruction, Instruction> popAndRewrite = vlanOps.remove(0); |
| 389 | |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 390 | TrafficSelector selector = fwd.selector(); |
| 391 | |
| 392 | Criterion outerVlan = selector.getCriterion(Criterion.Type.VLAN_VID); |
| 393 | Criterion innerVlan = selector.getCriterion(Criterion.Type.INNER_VLAN_VID); |
| 394 | Criterion inport = selector.getCriterion(Criterion.Type.IN_PORT); |
alshabib | b3c1434 | 2016-03-04 17:05:01 -0800 | [diff] [blame] | 395 | Criterion bullshit = Criteria.matchMetadata(output.port().toLong()); |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 396 | |
| 397 | if (outerVlan == null || innerVlan == null || inport == null) { |
| 398 | log.error("Forwarding objective is underspecified: {}", fwd); |
| 399 | fail(fwd, ObjectiveError.BADPARAMS); |
| 400 | return; |
| 401 | } |
| 402 | |
alshabib | 2f74f2c | 2016-01-14 13:29:35 -0800 | [diff] [blame] | 403 | Criterion innerVid = Criteria.matchVlanId(((VlanIdCriterion) innerVlan).vlanId()); |
| 404 | |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 405 | FlowRule.Builder outer = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 406 | .fromApp(fwd.appId()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 407 | .forDevice(deviceId) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 408 | .makePermanent() |
| 409 | .withPriority(fwd.priority()) |
alshabib | b3c1434 | 2016-03-04 17:05:01 -0800 | [diff] [blame] | 410 | .withSelector(buildSelector(inport, outerVlan, bullshit)) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 411 | .withTreatment(buildTreatment(popAndRewrite.getLeft(), |
| 412 | Instructions.transition(QQ_TABLE))); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 413 | |
alshabib | fa0dc66 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 414 | FlowRule.Builder inner = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 415 | .fromApp(fwd.appId()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 416 | .forDevice(deviceId) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 417 | .forTable(QQ_TABLE) |
| 418 | .makePermanent() |
| 419 | .withPriority(fwd.priority()) |
alshabib | 2f74f2c | 2016-01-14 13:29:35 -0800 | [diff] [blame] | 420 | .withSelector(buildSelector(inport, innerVid)) |
alshabib | e507584 | 2016-02-04 13:28:33 -0800 | [diff] [blame] | 421 | .withTreatment(buildTreatment(popAndRewrite.getLeft(), |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 422 | output)); |
| 423 | |
| 424 | applyRules(fwd, inner, outer); |
| 425 | |
| 426 | } |
| 427 | |
| 428 | private void installUpstreamRules(ForwardingObjective fwd) { |
| 429 | List<Pair<Instruction, Instruction>> vlanOps = |
| 430 | vlanOps(fwd, |
| 431 | L2ModificationInstruction.L2SubType.VLAN_PUSH); |
| 432 | |
| 433 | if (vlanOps == null) { |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | Instruction output = fetchOutput(fwd, "upstream"); |
| 438 | |
| 439 | if (output == null) { |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | Pair<Instruction, Instruction> innerPair = vlanOps.remove(0); |
| 444 | |
| 445 | Pair<Instruction, Instruction> outerPair = vlanOps.remove(0); |
| 446 | |
| 447 | FlowRule.Builder inner = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 448 | .fromApp(fwd.appId()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 449 | .forDevice(deviceId) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 450 | .makePermanent() |
| 451 | .withPriority(fwd.priority()) |
| 452 | .withSelector(fwd.selector()) |
| 453 | .withTreatment(buildTreatment(innerPair.getRight(), |
| 454 | Instructions.transition(QQ_TABLE))); |
| 455 | |
| 456 | PortCriterion inPort = (PortCriterion) |
| 457 | fwd.selector().getCriterion(Criterion.Type.IN_PORT); |
| 458 | |
| 459 | VlanId cVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) |
| 460 | innerPair.getRight()).vlanId(); |
| 461 | |
| 462 | FlowRule.Builder outer = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 463 | .fromApp(fwd.appId()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 464 | .forDevice(deviceId) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 465 | .forTable(QQ_TABLE) |
| 466 | .makePermanent() |
| 467 | .withPriority(fwd.priority()) |
| 468 | .withSelector(buildSelector(inPort, |
| 469 | Criteria.matchVlanId(cVlanId))) |
| 470 | .withTreatment(buildTreatment(outerPair.getLeft(), |
| 471 | outerPair.getRight(), |
| 472 | output)); |
| 473 | |
| 474 | applyRules(fwd, inner, outer); |
| 475 | |
| 476 | } |
| 477 | |
| 478 | private Instruction fetchOutput(ForwardingObjective fwd, String direction) { |
| 479 | Instruction output = fwd.treatment().allInstructions().stream() |
| 480 | .filter(i -> i.type() == Instruction.Type.OUTPUT) |
| 481 | .findFirst().orElse(null); |
| 482 | |
| 483 | if (output == null) { |
| 484 | log.error("OLT {} rule has no output", direction); |
| 485 | fail(fwd, ObjectiveError.BADPARAMS); |
| 486 | return null; |
| 487 | } |
| 488 | return output; |
| 489 | } |
| 490 | |
| 491 | private List<Pair<Instruction, Instruction>> vlanOps(ForwardingObjective fwd, |
| 492 | L2ModificationInstruction.L2SubType type) { |
| 493 | |
| 494 | List<Pair<Instruction, Instruction>> vlanOps = findVlanOps( |
| 495 | fwd.treatment().allInstructions(), type); |
| 496 | |
| 497 | if (vlanOps == null) { |
| 498 | String direction = type == L2ModificationInstruction.L2SubType.VLAN_POP |
| 499 | ? "downstream" : "upstream"; |
| 500 | log.error("Missing vlan operations in {} forwarding: {}", direction, fwd); |
| 501 | fail(fwd, ObjectiveError.BADPARAMS); |
| 502 | return null; |
| 503 | } |
| 504 | return vlanOps; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | private List<Pair<Instruction, Instruction>> findVlanOps(List<Instruction> instructions, |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 509 | L2ModificationInstruction.L2SubType type) { |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 510 | |
| 511 | List<Instruction> vlanPushs = findL2Instructions( |
| 512 | type, |
| 513 | instructions); |
| 514 | List<Instruction> vlanSets = findL2Instructions( |
| 515 | L2ModificationInstruction.L2SubType.VLAN_ID, |
| 516 | instructions); |
| 517 | |
| 518 | if (vlanPushs.size() != vlanSets.size()) { |
| 519 | return null; |
| 520 | } |
| 521 | |
| 522 | List<Pair<Instruction, Instruction>> pairs = Lists.newArrayList(); |
| 523 | |
| 524 | for (int i = 0; i < vlanPushs.size(); i++) { |
| 525 | pairs.add(new ImmutablePair<>(vlanPushs.get(i), vlanSets.get(i))); |
| 526 | } |
| 527 | return pairs; |
| 528 | } |
| 529 | |
| 530 | private List<Instruction> findL2Instructions(L2ModificationInstruction.L2SubType subType, |
| 531 | List<Instruction> actions) { |
| 532 | return actions.stream() |
| 533 | .filter(i -> i.type() == Instruction.Type.L2MODIFICATION) |
| 534 | .filter(i -> ((L2ModificationInstruction) i).subtype() == subType) |
| 535 | .collect(Collectors.toList()); |
| 536 | } |
| 537 | |
| 538 | private void provisionEapol(FilteringObjective filter, |
| 539 | EthTypeCriterion ethType, |
| 540 | Instructions.OutputInstruction output) { |
| 541 | |
| 542 | TrafficSelector selector = buildSelector(filter.key(), ethType); |
| 543 | TrafficTreatment treatment = buildTreatment(output); |
| 544 | buildAndApplyRule(filter, selector, treatment); |
| 545 | |
| 546 | } |
| 547 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 548 | private void provisionIgmp(FilteringObjective filter, EthTypeCriterion ethType, |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 549 | IPProtocolCriterion ipProto, |
| 550 | Instructions.OutputInstruction output) { |
| 551 | TrafficSelector selector = buildSelector(filter.key(), ethType, ipProto); |
| 552 | TrafficTreatment treatment = buildTreatment(output); |
| 553 | buildAndApplyRule(filter, selector, treatment); |
| 554 | } |
| 555 | |
Amit Ghosh | cbaf867 | 2016-12-23 21:36:19 +0000 | [diff] [blame] | 556 | private void provisionDhcp(FilteringObjective filter, EthTypeCriterion ethType, |
| 557 | IPProtocolCriterion ipProto, |
| 558 | UdpPortCriterion udpSrcPort, |
| 559 | UdpPortCriterion udpDstPort, |
| 560 | Instructions.OutputInstruction output) { |
| 561 | TrafficSelector selector = buildSelector(filter.key(), ethType, ipProto, udpSrcPort, udpDstPort); |
| 562 | TrafficTreatment treatment = buildTreatment(output); |
| 563 | buildAndApplyRule(filter, selector, treatment); |
| 564 | } |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 565 | private void buildAndApplyRule(FilteringObjective filter, TrafficSelector selector, |
| 566 | TrafficTreatment treatment) { |
| 567 | FlowRule rule = DefaultFlowRule.builder() |
alshabib | 8336447 | 2016-03-25 09:59:55 -0700 | [diff] [blame] | 568 | .fromApp(filter.appId()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 569 | .forDevice(deviceId) |
| 570 | .forTable(0) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 571 | .makePermanent() |
| 572 | .withSelector(selector) |
| 573 | .withTreatment(treatment) |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 574 | .withPriority(filter.priority()) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 575 | .build(); |
| 576 | |
| 577 | FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder(); |
| 578 | |
| 579 | switch (filter.type()) { |
| 580 | case PERMIT: |
| 581 | opsBuilder.add(rule); |
| 582 | break; |
| 583 | case DENY: |
| 584 | opsBuilder.remove(rule); |
| 585 | break; |
| 586 | default: |
| 587 | log.warn("Unknown filter type : {}", filter.type()); |
| 588 | fail(filter, ObjectiveError.UNSUPPORTED); |
| 589 | } |
| 590 | |
| 591 | applyFlowRules(opsBuilder, filter); |
| 592 | } |
| 593 | |
| 594 | private void applyRules(ForwardingObjective fwd, |
| 595 | FlowRule.Builder inner, FlowRule.Builder outer) { |
| 596 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
| 597 | switch (fwd.op()) { |
| 598 | case ADD: |
| 599 | builder.add(inner.build()).add(outer.build()); |
| 600 | break; |
| 601 | case REMOVE: |
alshabib | b05be2d | 2016-04-11 12:52:36 -0700 | [diff] [blame] | 602 | builder.remove(inner.build()).remove(outer.build()); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 603 | break; |
| 604 | case ADD_TO_EXISTING: |
| 605 | break; |
| 606 | case REMOVE_FROM_EXISTING: |
| 607 | break; |
| 608 | default: |
| 609 | log.warn("Unknown forwarding operation: {}", fwd.op()); |
| 610 | } |
| 611 | |
| 612 | applyFlowRules(builder, fwd); |
| 613 | } |
| 614 | |
| 615 | private void applyFlowRules(FlowRuleOperations.Builder builder, |
| 616 | Objective objective) { |
| 617 | flowRuleService.apply(builder.build(new FlowRuleOperationsContext() { |
| 618 | @Override |
| 619 | public void onSuccess(FlowRuleOperations ops) { |
| 620 | pass(objective); |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public void onError(FlowRuleOperations ops) { |
| 625 | fail(objective, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 626 | } |
| 627 | })); |
| 628 | } |
| 629 | |
| 630 | private Criterion filterForCriterion(Collection<Criterion> criteria, Criterion.Type type) { |
| 631 | return criteria.stream() |
alshabib | bb42423 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 632 | .filter(c -> c.type().equals(type)) |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 633 | .limit(1) |
| 634 | .findFirst().orElse(null); |
| 635 | } |
| 636 | |
| 637 | private TrafficSelector buildSelector(Criterion... criteria) { |
| 638 | |
| 639 | |
| 640 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 641 | |
| 642 | for (Criterion c : criteria) { |
| 643 | sBuilder.add(c); |
| 644 | } |
| 645 | |
| 646 | return sBuilder.build(); |
| 647 | } |
| 648 | |
| 649 | private TrafficTreatment buildTreatment(Instruction... instructions) { |
| 650 | |
| 651 | |
| 652 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 653 | |
| 654 | for (Instruction i : instructions) { |
| 655 | tBuilder.add(i); |
| 656 | } |
| 657 | |
| 658 | return tBuilder.build(); |
| 659 | } |
| 660 | |
| 661 | |
| 662 | private void fail(Objective obj, ObjectiveError error) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 663 | obj.context().ifPresent(context -> context.onError(obj, error)); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | private void pass(Objective obj) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 667 | obj.context().ifPresent(context -> context.onSuccess(obj)); |
alshabib | fd430b6 | 2015-12-16 18:56:38 -0800 | [diff] [blame] | 668 | } |
| 669 | |
alshabib | 2cc73cb | 2015-06-30 20:26:56 -0700 | [diff] [blame] | 670 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 671 | private class InnerGroupListener implements GroupListener { |
alshabib | 2cc73cb | 2015-06-30 20:26:56 -0700 | [diff] [blame] | 672 | @Override |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 673 | public void event(GroupEvent event) { |
ke han | f508667 | 2016-08-12 11:09:17 +0800 | [diff] [blame] | 674 | if (event.type() == GroupEvent.Type.GROUP_ADDED || |
| 675 | event.type() == GroupEvent.Type.GROUP_UPDATED) { |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 676 | GroupKey key = event.subject().appCookie(); |
alshabib | 2cc73cb | 2015-06-30 20:26:56 -0700 | [diff] [blame] | 677 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 678 | NextObjective obj = pendingGroups.getIfPresent(key); |
| 679 | if (obj != null) { |
| 680 | flowObjectiveStore.putNextGroup(obj.id(), new OLTPipelineGroup(key)); |
| 681 | pass(obj); |
| 682 | pendingGroups.invalidate(key); |
| 683 | } |
| 684 | } |
alshabib | 2cc73cb | 2015-06-30 20:26:56 -0700 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
alshabib | d61b77b | 2016-02-01 23:30:53 -0800 | [diff] [blame] | 688 | private static class OLTPipelineGroup implements NextGroup { |
| 689 | |
| 690 | private final GroupKey key; |
| 691 | |
| 692 | public OLTPipelineGroup(GroupKey key) { |
| 693 | this.key = key; |
| 694 | } |
| 695 | |
| 696 | public GroupKey key() { |
| 697 | return key; |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public byte[] data() { |
| 702 | return appKryo.serialize(key); |
| 703 | } |
| 704 | |
| 705 | } |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 706 | |
| 707 | @Override |
| 708 | public List<String> getNextMappings(NextGroup nextGroup) { |
| 709 | // TODO Implementation deferred to vendor |
| 710 | return null; |
| 711 | } |
alshabib | 0ccde6d | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 712 | } |