Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 21 | import java.util.Collection; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 22 | import java.util.Collections; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 23 | import java.util.Deque; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 24 | import java.util.List; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 25 | import java.util.Set; |
| 26 | import java.util.concurrent.ConcurrentHashMap; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 27 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 28 | import org.onlab.packet.Ethernet; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
| 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.net.Port; |
| 32 | import org.onosproject.net.PortNumber; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 33 | import org.onosproject.net.behaviour.NextGroup; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultFlowRule; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.FlowRule; |
| 38 | import org.onosproject.net.flow.FlowRuleOperations; |
| 39 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 40 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.Criteria; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.Criterion; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.EthCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 46 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 47 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 48 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 50 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.instructions.Instruction; |
| 52 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 53 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 54 | import org.onosproject.net.group.Group; |
| 55 | import org.onosproject.net.group.GroupKey; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 56 | import org.slf4j.Logger; |
| 57 | |
| 58 | |
| 59 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 60 | * Driver for software switch emulation of the OFDPA 2.0 pipeline. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 61 | * The software switch is the CPqD OF 1.3 switch. |
| 62 | */ |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 63 | public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 64 | |
| 65 | private final Logger log = getLogger(getClass()); |
| 66 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 67 | /* |
| 68 | * Cpqd emulation does not require the non-OF standard rules for |
| 69 | * matching untagged packets. |
| 70 | * |
| 71 | * (non-Javadoc) |
| 72 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter |
| 73 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 74 | @Override |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 75 | protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion, |
| 76 | VlanIdCriterion vidCriterion, |
| 77 | VlanId assignedVlan, |
| 78 | ApplicationId applicationId) { |
| 79 | List<FlowRule> rules = new ArrayList<FlowRule>(); |
| 80 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 81 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 82 | selector.matchVlanId(vidCriterion.vlanId()); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 83 | treatment.transition(TMAC_TABLE); |
| 84 | |
| 85 | VlanId storeVlan = null; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 86 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 87 | // untagged packets are assigned vlans |
| 88 | treatment.pushVlan().setVlanId(assignedVlan); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 89 | storeVlan = assignedVlan; |
| 90 | } else { |
| 91 | storeVlan = vidCriterion.vlanId(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 92 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 93 | |
| 94 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 95 | // rules for each port. |
| 96 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 97 | if (portCriterion.port() == PortNumber.ALL) { |
| 98 | for (Port port : deviceService.getPorts(deviceId)) { |
| 99 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 100 | portnums.add(port.number()); |
| 101 | } |
| 102 | } |
| 103 | } else { |
| 104 | portnums.add(portCriterion.port()); |
| 105 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 106 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 107 | for (PortNumber pnum : portnums) { |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 108 | // update storage |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 109 | ofdpa2GroupHandler.port2Vlan.put(pnum, storeVlan); |
| 110 | Set<PortNumber> vlanPorts = ofdpa2GroupHandler.vlan2Port.get(storeVlan); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 111 | if (vlanPorts == null) { |
| 112 | vlanPorts = Collections.newSetFromMap( |
| 113 | new ConcurrentHashMap<PortNumber, Boolean>()); |
| 114 | vlanPorts.add(pnum); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 115 | ofdpa2GroupHandler.vlan2Port.put(storeVlan, vlanPorts); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 116 | } else { |
| 117 | vlanPorts.add(pnum); |
| 118 | } |
| 119 | // create rest of flowrule |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 120 | selector.matchInPort(pnum); |
| 121 | FlowRule rule = DefaultFlowRule.builder() |
| 122 | .forDevice(deviceId) |
| 123 | .withSelector(selector.build()) |
| 124 | .withTreatment(treatment.build()) |
| 125 | .withPriority(DEFAULT_PRIORITY) |
| 126 | .fromApp(applicationId) |
| 127 | .makePermanent() |
| 128 | .forTable(VLAN_TABLE).build(); |
| 129 | rules.add(rule); |
| 130 | } |
| 131 | return rules; |
| 132 | } |
| 133 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 134 | /* |
| 135 | * Cpqd emulation does not handle vlan tags and mpls labels correctly. |
| 136 | * Workaround requires popping off the VLAN tags in the TMAC table. |
| 137 | * |
| 138 | * (non-Javadoc) |
| 139 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter |
| 140 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 141 | @Override |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 142 | protected List<FlowRule> processEthDstFilter(PortCriterion portCriterion, |
| 143 | EthCriterion ethCriterion, |
| 144 | VlanIdCriterion vidCriterion, |
| 145 | VlanId assignedVlan, |
| 146 | ApplicationId applicationId) { |
| 147 | //handling untagged packets via assigned VLAN |
| 148 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 149 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
| 150 | } |
| 151 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 152 | // rules for each port. |
| 153 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 154 | if (portCriterion.port() == PortNumber.ALL) { |
| 155 | for (Port port : deviceService.getPorts(deviceId)) { |
| 156 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 157 | portnums.add(port.number()); |
| 158 | } |
| 159 | } |
| 160 | } else { |
| 161 | portnums.add(portCriterion.port()); |
| 162 | } |
| 163 | |
| 164 | List<FlowRule> rules = new ArrayList<FlowRule>(); |
| 165 | for (PortNumber pnum : portnums) { |
| 166 | // for unicast IP packets |
| 167 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 168 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 169 | selector.matchInPort(pnum); |
| 170 | selector.matchVlanId(vidCriterion.vlanId()); |
| 171 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 172 | selector.matchEthDst(ethCriterion.mac()); |
| 173 | /* |
| 174 | * Note: CpqD switches do not handle MPLS-related operation properly |
| 175 | * for a packet with VLAN tag. We pop VLAN here as a workaround. |
| 176 | * Side effect: HostService learns redundant hosts with same MAC but |
| 177 | * different VLAN. No known side effect on the network reachability. |
| 178 | */ |
| 179 | treatment.popVlan(); |
| 180 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 181 | FlowRule rule = DefaultFlowRule.builder() |
| 182 | .forDevice(deviceId) |
| 183 | .withSelector(selector.build()) |
| 184 | .withTreatment(treatment.build()) |
| 185 | .withPriority(DEFAULT_PRIORITY) |
| 186 | .fromApp(applicationId) |
| 187 | .makePermanent() |
| 188 | .forTable(TMAC_TABLE).build(); |
| 189 | rules.add(rule); |
| 190 | //for MPLS packets |
| 191 | selector = DefaultTrafficSelector.builder(); |
| 192 | treatment = DefaultTrafficTreatment.builder(); |
| 193 | selector.matchInPort(pnum); |
| 194 | selector.matchVlanId(vidCriterion.vlanId()); |
| 195 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 196 | selector.matchEthDst(ethCriterion.mac()); |
| 197 | // workaround here again |
| 198 | treatment.popVlan(); |
| 199 | treatment.transition(MPLS_TABLE_0); |
| 200 | rule = DefaultFlowRule.builder() |
| 201 | .forDevice(deviceId) |
| 202 | .withSelector(selector.build()) |
| 203 | .withTreatment(treatment.build()) |
| 204 | .withPriority(DEFAULT_PRIORITY) |
| 205 | .fromApp(applicationId) |
| 206 | .makePermanent() |
| 207 | .forTable(TMAC_TABLE).build(); |
| 208 | rules.add(rule); |
| 209 | } |
| 210 | return rules; |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Cpqd emulation allows MPLS ecmp. |
| 215 | * |
| 216 | * (non-Javadoc) |
| 217 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific |
| 218 | */ |
| 219 | @Override |
| 220 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 221 | TrafficSelector selector = fwd.selector(); |
| 222 | EthTypeCriterion ethType = |
| 223 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 224 | if ((ethType == null) || |
| 225 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
| 226 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 227 | log.warn("processSpecific: Unsupported forwarding objective criteria" |
| 228 | + "ethType:{} in dev:{}", ethType, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 229 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 230 | return Collections.emptySet(); |
| 231 | } |
| 232 | |
| 233 | int forTableId = -1; |
| 234 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
| 235 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
| 236 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4) |
| 237 | .matchIPDst(((IPCriterion) |
| 238 | selector.getCriterion(Criterion.Type.IPV4_DST)).ip()); |
| 239 | forTableId = UNICAST_ROUTING_TABLE; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 240 | log.debug("processing IPv4 specific forwarding objective {} -> next:{}" |
| 241 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 242 | } else { |
| 243 | filteredSelector |
| 244 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 245 | .matchMplsLabel(((MplsCriterion) |
| 246 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 247 | MplsBosCriterion bos = (MplsBosCriterion) selector |
| 248 | .getCriterion(Criterion.Type.MPLS_BOS); |
| 249 | if (bos != null) { |
| 250 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 251 | } |
| 252 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 253 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 254 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 258 | if (fwd.treatment() != null) { |
| 259 | for (Instruction i : fwd.treatment().allInstructions()) { |
Charles Chan | 7d10b16 | 2015-12-07 18:54:45 -0800 | [diff] [blame] | 260 | /* |
| 261 | * NOTE: OF-DPA does not support immediate instruction in |
| 262 | * L3 unicast and MPLS table. |
| 263 | */ |
| 264 | tb.deferred().add(i); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 269 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 270 | if (next != null) { |
| 271 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 272 | // we only need the top level group's key to point the flow to it |
| 273 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 274 | if (group == null) { |
| 275 | log.warn("The group left!"); |
| 276 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 277 | return Collections.emptySet(); |
| 278 | } |
| 279 | tb.deferred().group(group.id()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 280 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 281 | } |
| 282 | tb.transition(ACL_TABLE); |
| 283 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 284 | .fromApp(fwd.appId()) |
| 285 | .withPriority(fwd.priority()) |
| 286 | .forDevice(deviceId) |
| 287 | .withSelector(filteredSelector.build()) |
| 288 | .withTreatment(tb.build()) |
| 289 | .forTable(forTableId); |
| 290 | |
| 291 | if (fwd.permanent()) { |
| 292 | ruleBuilder.makePermanent(); |
| 293 | } else { |
| 294 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 295 | } |
| 296 | |
| 297 | return Collections.singletonList(ruleBuilder.build()); |
| 298 | } |
| 299 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 300 | @Override |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 301 | protected void initializePipeline() { |
| 302 | processPortTable(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 303 | // vlan table processing not required, as default is to drop packets |
| 304 | // which can be accomplished without a table-miss-entry. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 305 | processTmacTable(); |
| 306 | processIpTable(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 307 | processMplsTable(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 308 | processBridgingTable(); |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 309 | processAclTable(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 312 | protected void processPortTable() { |
| 313 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 314 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 315 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 316 | treatment.transition(VLAN_TABLE); |
| 317 | FlowRule tmisse = DefaultFlowRule.builder() |
| 318 | .forDevice(deviceId) |
| 319 | .withSelector(selector.build()) |
| 320 | .withTreatment(treatment.build()) |
| 321 | .withPriority(LOWEST_PRIORITY) |
| 322 | .fromApp(driverId) |
| 323 | .makePermanent() |
| 324 | .forTable(PORT_TABLE).build(); |
| 325 | ops = ops.add(tmisse); |
| 326 | |
| 327 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 328 | @Override |
| 329 | public void onSuccess(FlowRuleOperations ops) { |
| 330 | log.info("Initialized port table"); |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void onError(FlowRuleOperations ops) { |
| 335 | log.info("Failed to initialize port table"); |
| 336 | } |
| 337 | })); |
| 338 | } |
| 339 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 340 | protected void processTmacTable() { |
| 341 | //table miss entry |
| 342 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 343 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 344 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 345 | selector = DefaultTrafficSelector.builder(); |
| 346 | treatment = DefaultTrafficTreatment.builder(); |
| 347 | treatment.transition(BRIDGING_TABLE); |
| 348 | FlowRule rule = DefaultFlowRule.builder() |
| 349 | .forDevice(deviceId) |
| 350 | .withSelector(selector.build()) |
| 351 | .withTreatment(treatment.build()) |
| 352 | .withPriority(LOWEST_PRIORITY) |
| 353 | .fromApp(driverId) |
| 354 | .makePermanent() |
| 355 | .forTable(TMAC_TABLE).build(); |
| 356 | ops = ops.add(rule); |
| 357 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 358 | @Override |
| 359 | public void onSuccess(FlowRuleOperations ops) { |
| 360 | log.info("Initialized tmac table"); |
| 361 | } |
| 362 | |
| 363 | @Override |
| 364 | public void onError(FlowRuleOperations ops) { |
| 365 | log.info("Failed to initialize tmac table"); |
| 366 | } |
| 367 | })); |
| 368 | } |
| 369 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 370 | protected void processIpTable() { |
| 371 | //table miss entry |
| 372 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 373 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 374 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 375 | selector = DefaultTrafficSelector.builder(); |
| 376 | treatment = DefaultTrafficTreatment.builder(); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 377 | treatment.deferred().setOutput(PortNumber.CONTROLLER); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 378 | treatment.transition(ACL_TABLE); |
| 379 | FlowRule rule = DefaultFlowRule.builder() |
| 380 | .forDevice(deviceId) |
| 381 | .withSelector(selector.build()) |
| 382 | .withTreatment(treatment.build()) |
| 383 | .withPriority(LOWEST_PRIORITY) |
| 384 | .fromApp(driverId) |
| 385 | .makePermanent() |
| 386 | .forTable(UNICAST_ROUTING_TABLE).build(); |
| 387 | ops = ops.add(rule); |
| 388 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 389 | @Override |
| 390 | public void onSuccess(FlowRuleOperations ops) { |
| 391 | log.info("Initialized IP table"); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void onError(FlowRuleOperations ops) { |
| 396 | log.info("Failed to initialize unicast IP table"); |
| 397 | } |
| 398 | })); |
| 399 | } |
| 400 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 401 | protected void processMplsTable() { |
| 402 | //table miss entry |
| 403 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 404 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 405 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 406 | selector = DefaultTrafficSelector.builder(); |
| 407 | treatment = DefaultTrafficTreatment.builder(); |
| 408 | treatment.transition(MPLS_TABLE_1); |
| 409 | FlowRule rule = DefaultFlowRule.builder() |
| 410 | .forDevice(deviceId) |
| 411 | .withSelector(selector.build()) |
| 412 | .withTreatment(treatment.build()) |
| 413 | .withPriority(LOWEST_PRIORITY) |
| 414 | .fromApp(driverId) |
| 415 | .makePermanent() |
| 416 | .forTable(MPLS_TABLE_0).build(); |
| 417 | ops = ops.add(rule); |
| 418 | |
| 419 | treatment.transition(ACL_TABLE); |
| 420 | rule = DefaultFlowRule.builder() |
| 421 | .forDevice(deviceId) |
| 422 | .withSelector(selector.build()) |
| 423 | .withTreatment(treatment.build()) |
| 424 | .withPriority(LOWEST_PRIORITY) |
| 425 | .fromApp(driverId) |
| 426 | .makePermanent() |
| 427 | .forTable(MPLS_TABLE_1).build(); |
| 428 | ops = ops.add(rule); |
| 429 | |
| 430 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 431 | @Override |
| 432 | public void onSuccess(FlowRuleOperations ops) { |
| 433 | log.info("Initialized MPLS tables"); |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void onError(FlowRuleOperations ops) { |
| 438 | log.info("Failed to initialize MPLS tables"); |
| 439 | } |
| 440 | })); |
| 441 | } |
| 442 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 443 | private void processBridgingTable() { |
| 444 | //table miss entry |
| 445 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 446 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 447 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 448 | selector = DefaultTrafficSelector.builder(); |
| 449 | treatment = DefaultTrafficTreatment.builder(); |
| 450 | treatment.transition(ACL_TABLE); |
| 451 | FlowRule rule = DefaultFlowRule.builder() |
| 452 | .forDevice(deviceId) |
| 453 | .withSelector(selector.build()) |
| 454 | .withTreatment(treatment.build()) |
| 455 | .withPriority(LOWEST_PRIORITY) |
| 456 | .fromApp(driverId) |
| 457 | .makePermanent() |
| 458 | .forTable(BRIDGING_TABLE).build(); |
| 459 | ops = ops.add(rule); |
| 460 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 461 | @Override |
| 462 | public void onSuccess(FlowRuleOperations ops) { |
| 463 | log.info("Initialized Bridging table"); |
| 464 | } |
| 465 | |
| 466 | @Override |
| 467 | public void onError(FlowRuleOperations ops) { |
| 468 | log.info("Failed to initialize Bridging table"); |
| 469 | } |
| 470 | })); |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 471 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 472 | |
Saurav Das | a07f203 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 473 | protected void processAclTable() { |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 474 | //table miss entry - catch all to executed action-set |
| 475 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 476 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 477 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 478 | selector = DefaultTrafficSelector.builder(); |
| 479 | treatment = DefaultTrafficTreatment.builder(); |
| 480 | FlowRule rule = DefaultFlowRule.builder() |
| 481 | .forDevice(deviceId) |
| 482 | .withSelector(selector.build()) |
| 483 | .withTreatment(treatment.build()) |
| 484 | .withPriority(LOWEST_PRIORITY) |
| 485 | .fromApp(driverId) |
| 486 | .makePermanent() |
| 487 | .forTable(ACL_TABLE).build(); |
| 488 | ops = ops.add(rule); |
| 489 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 490 | @Override |
| 491 | public void onSuccess(FlowRuleOperations ops) { |
| 492 | log.info("Initialized Acl table"); |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public void onError(FlowRuleOperations ops) { |
| 497 | log.info("Failed to initialize Acl table"); |
| 498 | } |
| 499 | })); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | } |