Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -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 | */ |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline.ofdpa; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 17 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 20 | import org.onlab.osgi.ServiceDirectory; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 21 | import org.onlab.packet.EthType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 22 | import org.onlab.packet.Ethernet; |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 23 | import org.onlab.packet.EthType.EtherType; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 25 | import org.onlab.packet.IpPrefix; |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 26 | import org.onlab.packet.MacAddress; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
| 28 | import org.onlab.util.KryoNamespace; |
| 29 | import org.onosproject.core.ApplicationId; |
| 30 | import org.onosproject.core.CoreService; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 31 | import org.onosproject.driver.extensions.Ofdpa3CopyField; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 32 | import org.onosproject.driver.extensions.Ofdpa3MplsType; |
| 33 | import org.onosproject.driver.extensions.Ofdpa3SetMplsType; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 34 | import org.onosproject.driver.extensions.OfdpaMatchActsetOutput; |
| 35 | import org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 36 | import org.onosproject.driver.extensions.OfdpaMatchVlanVid; |
| 37 | import org.onosproject.driver.extensions.OfdpaSetVlanVid; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 38 | import org.onosproject.net.DeviceId; |
| 39 | import org.onosproject.net.Port; |
| 40 | import org.onosproject.net.PortNumber; |
| 41 | import org.onosproject.net.behaviour.NextGroup; |
| 42 | import org.onosproject.net.behaviour.Pipeliner; |
| 43 | import org.onosproject.net.behaviour.PipelinerContext; |
| 44 | import org.onosproject.net.device.DeviceService; |
| 45 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 46 | import org.onosproject.net.flow.DefaultFlowRule; |
| 47 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 48 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 49 | import org.onosproject.net.flow.FlowRule; |
| 50 | import org.onosproject.net.flow.FlowRuleOperations; |
| 51 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 52 | import org.onosproject.net.flow.FlowRuleService; |
| 53 | import org.onosproject.net.flow.TrafficSelector; |
| 54 | import org.onosproject.net.flow.TrafficTreatment; |
| 55 | import org.onosproject.net.flow.criteria.Criteria; |
| 56 | import org.onosproject.net.flow.criteria.Criterion; |
| 57 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 58 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 59 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 60 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 61 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 62 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 63 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 64 | import org.onosproject.net.flow.criteria.PortCriterion; |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 65 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
| 66 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 67 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 68 | import org.onosproject.net.flow.instructions.Instruction; |
| 69 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 70 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 71 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 72 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 73 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 74 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 75 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 76 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 77 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 78 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 79 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 80 | import org.onosproject.net.flowobjective.NextObjective; |
| 81 | import org.onosproject.net.flowobjective.Objective; |
| 82 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 83 | import org.onosproject.net.group.DefaultGroupKey; |
| 84 | import org.onosproject.net.group.Group; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 85 | import org.onosproject.net.group.GroupKey; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 86 | import org.onosproject.net.group.GroupService; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 87 | import org.onosproject.store.serializers.KryoNamespaces; |
| 88 | import org.slf4j.Logger; |
| 89 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 90 | import java.util.ArrayDeque; |
| 91 | import java.util.ArrayList; |
| 92 | import java.util.Collection; |
| 93 | import java.util.Collections; |
| 94 | import java.util.Deque; |
| 95 | import java.util.List; |
| 96 | import java.util.Objects; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 97 | import java.util.Optional; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 98 | import java.util.concurrent.ScheduledExecutorService; |
| 99 | import java.util.concurrent.TimeUnit; |
| 100 | |
| 101 | import static java.util.concurrent.Executors.newScheduledThreadPool; |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 102 | import static org.onlab.packet.MacAddress.BROADCAST; |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 103 | import static org.onlab.packet.MacAddress.IPV4_MULTICAST; |
| 104 | import static org.onlab.packet.MacAddress.IPV6_MULTICAST; |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 105 | import static org.onlab.packet.MacAddress.NONE; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 106 | import static org.onlab.util.Tools.groupedThreads; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 107 | import static org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_PACKET_REG_1; |
| 108 | import static org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_VLAN_VID; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 109 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 110 | import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_TYPE; |
Pier Luigi | 075f101 | 2018-02-01 10:23:12 +0100 | [diff] [blame] | 111 | import static org.onosproject.net.group.GroupDescription.Type.SELECT; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 112 | import static org.slf4j.LoggerFactory.getLogger; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 113 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 114 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 115 | /** |
| 116 | * Driver for Broadcom's OF-DPA v2.0 TTP. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 117 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 118 | public class Ofdpa2Pipeline extends AbstractHandlerBehaviour implements Pipeliner { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 119 | protected static final int PORT_TABLE = 0; |
| 120 | protected static final int VLAN_TABLE = 10; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 121 | protected static final int VLAN_1_TABLE = 11; |
| 122 | protected static final int MPLS_L2_PORT_FLOW_TABLE = 13; |
| 123 | protected static final int MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE = 16; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 124 | protected static final int TMAC_TABLE = 20; |
| 125 | protected static final int UNICAST_ROUTING_TABLE = 30; |
| 126 | protected static final int MULTICAST_ROUTING_TABLE = 40; |
| 127 | protected static final int MPLS_TABLE_0 = 23; |
| 128 | protected static final int MPLS_TABLE_1 = 24; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 129 | protected static final int MPLS_L3_TYPE_TABLE = 27; |
| 130 | protected static final int MPLS_TYPE_TABLE = 29; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 131 | protected static final int BRIDGING_TABLE = 50; |
| 132 | protected static final int ACL_TABLE = 60; |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 133 | protected static final int EGRESS_VLAN_FLOW_TABLE = 210; |
| 134 | protected static final int EGRESS_DSCP_PCP_REMARK_FLOW_TABLE = 230; |
| 135 | protected static final int EGRESS_TPID_FLOW_TABLE = 235; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 136 | protected static final int MAC_LEARNING_TABLE = 254; |
| 137 | protected static final long OFPP_MAX = 0xffffff00L; |
| 138 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 139 | protected static final int HIGHEST_PRIORITY = 0xffff; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 140 | protected static final int DEFAULT_PRIORITY = 0x8000; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 141 | protected static final int LOWEST_PRIORITY = 0x0; |
| 142 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 143 | protected static final int MPLS_L2_PORT_PRIORITY = 2; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 144 | protected static final int MPLS_TUNNEL_ID_BASE = 0x10000; |
| 145 | protected static final int MPLS_TUNNEL_ID_MAX = 0x1FFFF; |
| 146 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 147 | protected static final int MPLS_UNI_PORT_MAX = 0x0000FFFF; |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 148 | protected static final int MPLS_NNI_PORT_BASE = 0x00020000; |
| 149 | protected static final int MPLS_NNI_PORT_MAX = 0x0002FFFF; |
| 150 | |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 151 | protected static final short ALLOW_VLAN_TRANSLATION = 1; |
| 152 | protected static final int COPY_FIELD_NBITS = 12; |
| 153 | protected static final int COPY_FIELD_OFFSET = 0; |
| 154 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 155 | private final Logger log = getLogger(getClass()); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 156 | protected ServiceDirectory serviceDirectory; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 157 | protected FlowRuleService flowRuleService; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 158 | protected CoreService coreService; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 159 | protected GroupService groupService; |
| 160 | protected FlowObjectiveStore flowObjectiveStore; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 161 | protected DeviceId deviceId; |
| 162 | protected ApplicationId driverId; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 163 | protected DeviceService deviceService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 164 | protected static KryoNamespace appKryo = new KryoNamespace.Builder() |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 165 | .register(KryoNamespaces.API) |
| 166 | .register(GroupKey.class) |
| 167 | .register(DefaultGroupKey.class) |
| 168 | .register(OfdpaNextGroup.class) |
| 169 | .register(ArrayDeque.class) |
| 170 | .build("Ofdpa2Pipeline"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 171 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 172 | protected Ofdpa2GroupHandler groupHandler; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 173 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 174 | // flows installations to be retried |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 175 | private ScheduledExecutorService executorService |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 176 | = newScheduledThreadPool(5, groupedThreads("OfdpaPipeliner", "retry-%d", log)); |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 177 | private static final int MAX_RETRY_ATTEMPTS = 10; |
| 178 | private static final int RETRY_MS = 1000; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 179 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 180 | @Override |
| 181 | public void init(DeviceId deviceId, PipelinerContext context) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 182 | this.deviceId = deviceId; |
| 183 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 184 | serviceDirectory = context.directory(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 185 | coreService = serviceDirectory.get(CoreService.class); |
| 186 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
| 187 | groupService = serviceDirectory.get(GroupService.class); |
| 188 | flowObjectiveStore = context.store(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 189 | deviceService = serviceDirectory.get(DeviceService.class); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 190 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 191 | initDriverId(); |
| 192 | initGroupHander(context); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 193 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 194 | initializePipeline(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 197 | protected void initDriverId() { |
| 198 | driverId = coreService.registerApplication( |
| 199 | "org.onosproject.driver.Ofdpa2Pipeline"); |
| 200 | } |
| 201 | |
| 202 | protected void initGroupHander(PipelinerContext context) { |
| 203 | groupHandler = new Ofdpa2GroupHandler(); |
| 204 | groupHandler.init(deviceId, context); |
| 205 | } |
| 206 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 207 | protected void initializePipeline() { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 208 | // OF-DPA does not require initializing the pipeline as it puts default |
| 209 | // rules automatically in the hardware. However emulation of OFDPA in |
| 210 | // software switches does require table-miss-entries. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 213 | /** |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 214 | * Determines whether this pipeline requires MPLS POP instruction. |
| 215 | * |
| 216 | * @return true to use MPLS POP instruction |
| 217 | */ |
| 218 | public boolean requireMplsPop() { |
| 219 | return true; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Determines whether this pipeline requires MPLS BOS match. |
| 224 | * |
| 225 | * @return true to use MPLS BOS match |
| 226 | */ |
| 227 | public boolean requireMplsBosMatch() { |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Determines whether this pipeline requires MPLS TTL decrement and copy. |
| 233 | * |
| 234 | * @return true to use MPLS TTL decrement and copy |
| 235 | */ |
| 236 | public boolean requireMplsTtlModification() { |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 241 | * Determines whether this pipeline requires OFDPA match and set VLAN extensions. |
| 242 | * |
| 243 | * @return true to use the extensions |
| 244 | */ |
| 245 | protected boolean requireVlanExtensions() { |
| 246 | return true; |
| 247 | } |
| 248 | |
Saurav Das | 86d13e8 | 2017-04-28 17:03:48 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Determines whether in-port should be matched on in TMAC table rules. |
| 251 | * |
| 252 | * @return true if match on in-port should be programmed |
| 253 | */ |
| 254 | protected boolean matchInPortTmacTable() { |
| 255 | return true; |
| 256 | } |
| 257 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Determines whether matching L4 destination port on IPv6 packets is supported in ACL table. |
| 260 | * |
| 261 | * @return true if matching L4 destination port on IPv6 packets is supported in ACL table. |
| 262 | */ |
| 263 | protected boolean supportIpv6L4Dst() { |
| 264 | return true; |
| 265 | } |
| 266 | |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Determines whether this driver should continue to retry flows that point |
| 269 | * to empty groups. See CORD-554. |
| 270 | * |
| 271 | * @return true if the driver should retry flows |
| 272 | */ |
| 273 | protected boolean shouldRetry() { |
| 274 | return true; |
| 275 | } |
| 276 | |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 277 | /** |
| 278 | * Determines whether this driver requires unicast flow to be installed before multicast flow |
| 279 | * in TMAC table. |
| 280 | * |
| 281 | * @return true if required |
| 282 | */ |
| 283 | protected boolean requireUnicastBeforeMulticast() { |
| 284 | return false; |
| 285 | } |
| 286 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 287 | ////////////////////////////////////// |
| 288 | // Flow Objectives |
| 289 | ////////////////////////////////////// |
| 290 | |
| 291 | @Override |
| 292 | public void filter(FilteringObjective filteringObjective) { |
| 293 | if (filteringObjective.type() == FilteringObjective.Type.PERMIT) { |
| 294 | processFilter(filteringObjective, |
| 295 | filteringObjective.op() == Objective.Operation.ADD, |
| 296 | filteringObjective.appId()); |
| 297 | } else { |
| 298 | // Note that packets that don't match the PERMIT filter are |
| 299 | // automatically denied. The DENY filter is used to deny packets |
| 300 | // that are otherwise permitted by the PERMIT filter. |
| 301 | // Use ACL table flow rules here for DENY filtering objectives |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 302 | log.warn("filter objective other than PERMIT currently not supported"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 303 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void forward(ForwardingObjective fwd) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 309 | Collection<FlowRule> rules = processForward(fwd); |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 310 | if (rules == null || rules.isEmpty()) { |
| 311 | // Assumes fail message has already been generated to the objective |
| 312 | // context. Returning here prevents spurious pass message to be |
| 313 | // generated by FlowRule service for empty flowOps. |
| 314 | return; |
| 315 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 316 | sendForward(fwd, rules); |
| 317 | } |
| 318 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 319 | private void sendForward(ForwardingObjective fwd, Collection<FlowRule> rules) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 320 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 321 | switch (fwd.op()) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 322 | case ADD: |
| 323 | rules.stream() |
| 324 | .filter(Objects::nonNull) |
| 325 | .forEach(flowOpsBuilder::add); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 326 | log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 327 | break; |
| 328 | case REMOVE: |
| 329 | rules.stream() |
| 330 | .filter(Objects::nonNull) |
| 331 | .forEach(flowOpsBuilder::remove); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 332 | log.debug("Deleting a flow rule to sw:{}", deviceId); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 333 | break; |
| 334 | default: |
| 335 | fail(fwd, ObjectiveError.UNKNOWN); |
| 336 | log.warn("Unknown forwarding type {}", fwd.op()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 339 | flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() { |
| 340 | @Override |
| 341 | public void onSuccess(FlowRuleOperations ops) { |
| 342 | pass(fwd); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void onError(FlowRuleOperations ops) { |
| 347 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 348 | } |
| 349 | })); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public void next(NextObjective nextObjective) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 354 | NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); |
| 355 | switch (nextObjective.op()) { |
| 356 | case ADD: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 357 | if (nextGroup != null) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 358 | log.warn("Cannot add next {} that already exists in device {}", |
| 359 | nextObjective.id(), deviceId); |
| 360 | return; |
| 361 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 362 | log.debug("Processing NextObjective id {} in dev {} - add group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 363 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 364 | groupHandler.addGroup(nextObjective); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 365 | break; |
| 366 | case ADD_TO_EXISTING: |
| 367 | if (nextGroup != null) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 368 | log.debug("Processing NextObjective id {} in dev {} - add bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 369 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 370 | groupHandler.addBucketToGroup(nextObjective, nextGroup); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 371 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 372 | // it is possible that group-chain has not been fully created yet |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 373 | log.debug("Waiting to add bucket to group for next-id:{} in dev:{}", |
| 374 | nextObjective.id(), deviceId); |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 375 | |
| 376 | // by design multiple pending bucket is allowed for the group |
| 377 | groupHandler.pendingBuckets.compute(nextObjective.id(), (nextId, pendBkts) -> { |
| 378 | if (pendBkts == null) { |
| 379 | pendBkts = Sets.newHashSet(); |
| 380 | } |
| 381 | pendBkts.add(nextObjective); |
| 382 | return pendBkts; |
| 383 | }); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 384 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 385 | break; |
| 386 | case REMOVE: |
| 387 | if (nextGroup == null) { |
| 388 | log.warn("Cannot remove next {} that does not exist in device {}", |
| 389 | nextObjective.id(), deviceId); |
| 390 | return; |
| 391 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 392 | log.debug("Processing NextObjective id {} in dev {} - remove group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 393 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 394 | groupHandler.removeGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 395 | break; |
| 396 | case REMOVE_FROM_EXISTING: |
| 397 | if (nextGroup == null) { |
| 398 | log.warn("Cannot remove from next {} that does not exist in device {}", |
| 399 | nextObjective.id(), deviceId); |
| 400 | return; |
| 401 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 402 | log.debug("Processing NextObjective id {} in dev {} - remove bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 403 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 404 | groupHandler.removeBucketFromGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 405 | break; |
Jonghwan Hyun | f810a7a | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 406 | case MODIFY: |
| 407 | if (nextGroup == null) { |
| 408 | log.warn("Cannot modify next {} that does not exist in device {}", |
| 409 | nextObjective.id(), deviceId); |
| 410 | return; |
| 411 | } |
| 412 | log.debug("Processing NextObjective id {} in dev {} - modify bucket", |
| 413 | nextObjective.id(), deviceId); |
| 414 | groupHandler.modifyBucketFromGroup(nextObjective, nextGroup); |
| 415 | break; |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 416 | case VERIFY: |
| 417 | if (nextGroup == null) { |
| 418 | log.warn("Cannot verify next {} that does not exist in device {}", |
| 419 | nextObjective.id(), deviceId); |
| 420 | return; |
| 421 | } |
| 422 | log.debug("Processing NextObjective id {} in dev {} - verify", |
| 423 | nextObjective.id(), deviceId); |
| 424 | groupHandler.verifyGroup(nextObjective, nextGroup); |
| 425 | break; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 426 | default: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 427 | log.warn("Unsupported operation {}", nextObjective.op()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | ////////////////////////////////////// |
| 432 | // Flow handling |
| 433 | ////////////////////////////////////// |
| 434 | |
| 435 | /** |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 436 | * As per OFDPA 2.0 TTP, filtering of VLAN ids and MAC addresses (for routing) |
| 437 | * configured on switch ports happen in different tables. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 438 | * |
| 439 | * @param filt the filtering objective |
| 440 | * @param install indicates whether to add or remove the objective |
| 441 | * @param applicationId the application that sent this objective |
| 442 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 443 | protected void processFilter(FilteringObjective filt, |
| 444 | boolean install, ApplicationId applicationId) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 445 | // This driver only processes filtering criteria defined with switch |
| 446 | // ports as the key |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 447 | PortCriterion portCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 448 | EthCriterion ethCriterion = null; |
| 449 | VlanIdCriterion vidCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 450 | if (!filt.key().equals(Criteria.dummy()) && |
| 451 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 452 | portCriterion = (PortCriterion) filt.key(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 453 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 454 | if (portCriterion == null) { |
| 455 | log.debug("No IN_PORT defined in filtering objective from app: {}", |
| 456 | applicationId); |
| 457 | } else { |
| 458 | log.debug("Received filtering objective for dev/port: {}/{}", deviceId, |
| 459 | portCriterion.port()); |
| 460 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 461 | // convert filtering conditions for switch-intfs into flowrules |
| 462 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 463 | for (Criterion criterion : filt.conditions()) { |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 464 | switch (criterion.type()) { |
| 465 | case ETH_DST: |
| 466 | case ETH_DST_MASKED: |
| 467 | ethCriterion = (EthCriterion) criterion; |
| 468 | break; |
| 469 | case VLAN_VID: |
| 470 | vidCriterion = (VlanIdCriterion) criterion; |
| 471 | break; |
| 472 | default: |
| 473 | log.warn("Unsupported filter {}", criterion); |
| 474 | fail(filt, ObjectiveError.UNSUPPORTED); |
| 475 | return; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 479 | VlanId assignedVlan = null; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 480 | if (vidCriterion != null) { |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 481 | // Use the VLAN in criterion if metadata is not present and the traffic is tagged |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 482 | if (!vidCriterion.vlanId().equals(VlanId.NONE)) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 483 | assignedVlan = vidCriterion.vlanId(); |
Pier | e5bff48 | 2018-03-07 11:42:50 +0100 | [diff] [blame] | 484 | } |
| 485 | // If the meta VLAN is present let's update the assigned vlan |
| 486 | if (filt.meta() != null) { |
| 487 | VlanId metaVlan = readVlanFromTreatment(filt.meta()); |
| 488 | if (metaVlan != null) { |
| 489 | assignedVlan = metaVlan; |
| 490 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 491 | } |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 492 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 493 | if (assignedVlan == null) { |
| 494 | log.error("Driver fails to extract VLAN information. " |
Frank Wang | d8ab096 | 2017-08-11 11:09:30 +0800 | [diff] [blame] | 495 | + "Not processing VLAN filters on device {}.", deviceId); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 496 | log.debug("VLAN ID in criterion={}, metadata={}", |
| 497 | readVlanFromTreatment(filt.meta()), vidCriterion.vlanId()); |
| 498 | fail(filt, ObjectiveError.BADPARAMS); |
| 499 | return; |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 503 | if (ethCriterion == null || ethCriterion.mac().equals(NONE)) { |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 504 | // NOTE: it is possible that a filtering objective only has vidCriterion |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 505 | log.warn("filtering objective missing dstMac, cannot program TMAC table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 506 | } else { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 507 | MacAddress unicastMac = readEthDstFromTreatment(filt.meta()); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 508 | List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 509 | vidCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 510 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 511 | log.trace("Starting a new flow rule stage for TMAC table flow"); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 512 | ops.newStage(); |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 513 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 514 | for (FlowRule flowRule : flowRules) { |
| 515 | log.trace("{} flow rules in TMAC table: {} for dev: {}", |
| 516 | (install) ? "adding" : "removing", flowRules, deviceId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 517 | if (install) { |
| 518 | ops = ops.add(flowRule); |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 519 | } else { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 520 | // NOTE: Only remove TMAC flow when there is no more enabled port within the |
| 521 | // same VLAN on this device if TMAC doesn't support matching on in_port. |
| 522 | if (matchInPortTmacTable() || (filt.meta() != null && filt.meta().clearedDeferred())) { |
| 523 | ops = ops.remove(flowRule); |
| 524 | } else { |
| 525 | log.debug("Abort TMAC flow removal on {}. Some other ports still share this TMAC flow"); |
| 526 | } |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 527 | } |
| 528 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 532 | if (vidCriterion == null) { |
| 533 | // NOTE: it is possible that a filtering objective only has ethCriterion |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 534 | log.info("filtering objective missing VLAN, cannot program VLAN Table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 535 | } else { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 536 | List<List<FlowRule>> allStages = processVlanIdFilter( |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 537 | portCriterion, vidCriterion, assignedVlan, applicationId); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 538 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 539 | log.trace("Starting a new flow rule stage for VLAN table flow"); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 540 | ops.newStage(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 541 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 542 | for (FlowRule flowRule : flowRules) { |
| 543 | log.trace("{} flow rules in VLAN table: {} for dev: {}", |
| 544 | (install) ? "adding" : "removing", flowRule, deviceId); |
| 545 | ops = install ? ops.add(flowRule) : ops.remove(flowRule); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 546 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 550 | // apply filtering flow rules |
| 551 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 552 | @Override |
| 553 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 554 | log.debug("Applied {} filtering rules in device {}", |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 555 | ops.stages().get(0).size(), deviceId); |
| 556 | pass(filt); |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public void onError(FlowRuleOperations ops) { |
| 561 | log.info("Failed to apply all filtering rules in dev {}", deviceId); |
| 562 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 563 | } |
| 564 | })); |
| 565 | |
| 566 | } |
| 567 | |
| 568 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 569 | * Internal implementation of processVlanIdFilter. |
| 570 | * <p> |
| 571 | * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12. |
| 572 | * Since it is non-OF spec, we need an extension treatment for that. |
| 573 | * The useVlanExtension must be set to false for OFDPA i12. |
| 574 | * </p> |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 575 | * <p> |
| 576 | * NOTE: Separate VLAN filtering rules and assignment rules |
| 577 | * into different stages in order to guarantee that filtering rules |
| 578 | * always go first, as required by OFDPA. |
| 579 | * </p> |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 580 | * |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 581 | * @param portCriterion port on device for which this filter is programmed |
| 582 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
| 583 | * @param assignedVlan assigned vlan-id for untagged packets |
| 584 | * @param applicationId for application programming this filter |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 585 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 586 | */ |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 587 | protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 588 | VlanIdCriterion vidCriterion, |
| 589 | VlanId assignedVlan, |
| 590 | ApplicationId applicationId) { |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 591 | List<FlowRule> filteringRules = new ArrayList<>(); |
| 592 | List<FlowRule> assignmentRules = new ArrayList<>(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 593 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 594 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 595 | TrafficSelector.Builder preSelector = null; |
| 596 | TrafficTreatment.Builder preTreatment = null; |
| 597 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 598 | treatment.transition(TMAC_TABLE); |
| 599 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 600 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 601 | // untagged packets are assigned vlans |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 602 | preSelector = DefaultTrafficSelector.builder(); |
| 603 | if (requireVlanExtensions()) { |
| 604 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.NONE); |
| 605 | selector.extension(ofdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 606 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 607 | treatment.extension(ofdpaSetVlanVid, deviceId); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 608 | |
| 609 | OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 610 | preSelector.extension(preOfdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 611 | } else { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 612 | selector.matchVlanId(VlanId.NONE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 613 | treatment.setVlanId(assignedVlan); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 614 | |
| 615 | preSelector.matchVlanId(assignedVlan); |
| 616 | } |
| 617 | preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE); |
| 618 | } else { |
| 619 | if (requireVlanExtensions()) { |
| 620 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 621 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 622 | } else { |
| 623 | selector.matchVlanId(vidCriterion.vlanId()); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 624 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 625 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 626 | if (!assignedVlan.equals(vidCriterion.vlanId())) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 627 | if (requireVlanExtensions()) { |
Charles Chan | c03782d | 2017-01-31 13:57:55 -0800 | [diff] [blame] | 628 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 629 | treatment.extension(ofdpaSetVlanVid, deviceId); |
| 630 | } else { |
| 631 | treatment.setVlanId(assignedVlan); |
| 632 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 633 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 634 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 635 | |
| 636 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 637 | // rules for each port. |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 638 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 639 | if (portCriterion != null) { |
| 640 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 641 | for (Port port : deviceService.getPorts(deviceId)) { |
| 642 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 643 | portnums.add(port.number()); |
| 644 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 645 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 646 | } else { |
| 647 | portnums.add(portCriterion.port()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 648 | } |
| 649 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 650 | log.warn("Filtering Objective missing Port Criterion . " + |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 651 | "VLAN Table cannot be programmed for {}", deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 652 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 653 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 654 | for (PortNumber pnum : portnums) { |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 655 | // create rest of flowrule |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 656 | selector.matchInPort(pnum); |
| 657 | FlowRule rule = DefaultFlowRule.builder() |
| 658 | .forDevice(deviceId) |
| 659 | .withSelector(selector.build()) |
| 660 | .withTreatment(treatment.build()) |
| 661 | .withPriority(DEFAULT_PRIORITY) |
| 662 | .fromApp(applicationId) |
| 663 | .makePermanent() |
| 664 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 665 | assignmentRules.add(rule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 666 | |
| 667 | if (preSelector != null) { |
| 668 | preSelector.matchInPort(pnum); |
| 669 | FlowRule preRule = DefaultFlowRule.builder() |
| 670 | .forDevice(deviceId) |
| 671 | .withSelector(preSelector.build()) |
| 672 | .withTreatment(preTreatment.build()) |
| 673 | .withPriority(DEFAULT_PRIORITY) |
| 674 | .fromApp(applicationId) |
| 675 | .makePermanent() |
| 676 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 677 | filteringRules.add(preRule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 678 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 679 | } |
Charles Chan | 2686dd7 | 2018-03-06 22:10:15 -0800 | [diff] [blame] | 680 | return ImmutableList.of(filteringRules, assignmentRules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Allows routed packets with correct destination MAC to be directed |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 685 | * to unicast routing table, multicast routing table or MPLS forwarding table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 686 | * |
| 687 | * @param portCriterion port on device for which this filter is programmed |
| 688 | * @param ethCriterion dstMac of device for which is filter is programmed |
| 689 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 690 | * @param assignedVlan assigned vlan-id for untagged packets |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 691 | * @param unicastMac some switches require a unicast TMAC flow to be programmed before multicast |
| 692 | * TMAC flow. This MAC address will be used for the unicast TMAC flow. |
| 693 | * This is unused if the filtering objective is a unicast. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 694 | * @param applicationId for application programming this filter |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 695 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 696 | |
| 697 | */ |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 698 | protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 699 | EthCriterion ethCriterion, |
| 700 | VlanIdCriterion vidCriterion, |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 701 | VlanId assignedVlan, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 702 | MacAddress unicastMac, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 703 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 704 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
Sivachidambaram Subramanian | c598d06 | 2017-05-16 22:42:06 +0530 | [diff] [blame] | 705 | if (portCriterion != null && PortNumber.ANY.equals(portCriterion.port())) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 706 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 707 | } |
| 708 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 709 | // Multicast MAC |
| 710 | if (ethCriterion.mask() != null) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 711 | return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 714 | //handling untagged packets via assigned VLAN |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 715 | if (vidCriterion != null && vidCriterion.vlanId() == VlanId.NONE) { |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 716 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 717 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 718 | List<FlowRule> rules = new ArrayList<>(); |
| 719 | OfdpaMatchVlanVid ofdpaMatchVlanVid = null; |
| 720 | if (vidCriterion != null && requireVlanExtensions()) { |
| 721 | ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 722 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 723 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 724 | // rules for each port. |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 725 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 726 | if (portCriterion != null) { |
| 727 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 728 | for (Port port : deviceService.getPorts(deviceId)) { |
| 729 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 730 | portnums.add(port.number()); |
| 731 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 732 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 733 | } else { |
| 734 | portnums.add(portCriterion.port()); |
| 735 | } |
| 736 | for (PortNumber pnum : portnums) { |
| 737 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 738 | vidCriterion, |
| 739 | ofdpaMatchVlanVid, |
| 740 | applicationId, |
| 741 | pnum)); |
| 742 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 743 | vidCriterion, |
| 744 | ofdpaMatchVlanVid, |
| 745 | applicationId, |
| 746 | pnum)); |
| 747 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 748 | vidCriterion, |
| 749 | ofdpaMatchVlanVid, |
| 750 | applicationId, |
| 751 | pnum)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 752 | } |
| 753 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 754 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 755 | vidCriterion, |
| 756 | ofdpaMatchVlanVid, |
| 757 | applicationId, |
| 758 | null)); |
| 759 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 760 | vidCriterion, |
| 761 | ofdpaMatchVlanVid, |
| 762 | applicationId, |
| 763 | null)); |
| 764 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 765 | vidCriterion, |
| 766 | ofdpaMatchVlanVid, |
| 767 | applicationId, |
| 768 | null)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 769 | } |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 770 | return ImmutableList.of(rules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 773 | /** |
| 774 | * Builds TMAC rules for IPv4 packets. |
| 775 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 776 | * @param ethCriterion dst mac matching |
| 777 | * @param vidCriterion vlan id assigned to the port |
| 778 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 779 | * @param applicationId application id |
| 780 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 781 | * @return TMAC rule for IPV4 packets |
| 782 | */ |
| 783 | private FlowRule buildTmacRuleForIpv4(EthCriterion ethCriterion, |
| 784 | VlanIdCriterion vidCriterion, |
| 785 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 786 | ApplicationId applicationId, |
| 787 | PortNumber pnum) { |
| 788 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 789 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 790 | if (pnum != null) { |
| 791 | if (matchInPortTmacTable()) { |
| 792 | selector.matchInPort(pnum); |
| 793 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 794 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 795 | "ignoring the IN_PORT criteria"); |
| 796 | } |
| 797 | } |
| 798 | if (vidCriterion != null) { |
| 799 | if (requireVlanExtensions()) { |
| 800 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 801 | } else { |
| 802 | selector.matchVlanId(vidCriterion.vlanId()); |
| 803 | } |
| 804 | } |
| 805 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 806 | selector.matchEthDst(ethCriterion.mac()); |
| 807 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 808 | return DefaultFlowRule.builder() |
| 809 | .forDevice(deviceId) |
| 810 | .withSelector(selector.build()) |
| 811 | .withTreatment(treatment.build()) |
| 812 | .withPriority(DEFAULT_PRIORITY) |
| 813 | .fromApp(applicationId) |
| 814 | .makePermanent() |
| 815 | .forTable(TMAC_TABLE).build(); |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Builds TMAC rule for MPLS packets. |
| 820 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 821 | * @param ethCriterion dst mac matching |
| 822 | * @param vidCriterion vlan id assigned to the port |
| 823 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 824 | * @param applicationId application id |
| 825 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 826 | * @return TMAC rule for MPLS packets |
| 827 | */ |
| 828 | private FlowRule buildTmacRuleForMpls(EthCriterion ethCriterion, |
| 829 | VlanIdCriterion vidCriterion, |
| 830 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 831 | ApplicationId applicationId, |
| 832 | PortNumber pnum) { |
| 833 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 834 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 835 | if (pnum != null) { |
| 836 | if (matchInPortTmacTable()) { |
| 837 | selector.matchInPort(pnum); |
| 838 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 839 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 840 | "ignoring the IN_PORT criteria"); |
| 841 | } |
| 842 | } |
| 843 | if (vidCriterion != null) { |
| 844 | if (requireVlanExtensions()) { |
| 845 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 846 | } else { |
| 847 | selector.matchVlanId(vidCriterion.vlanId()); |
| 848 | } |
| 849 | } |
| 850 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 851 | selector.matchEthDst(ethCriterion.mac()); |
| 852 | treatment.transition(MPLS_TABLE_0); |
| 853 | return DefaultFlowRule.builder() |
| 854 | .forDevice(deviceId) |
| 855 | .withSelector(selector.build()) |
| 856 | .withTreatment(treatment.build()) |
| 857 | .withPriority(DEFAULT_PRIORITY) |
| 858 | .fromApp(applicationId) |
| 859 | .makePermanent() |
| 860 | .forTable(TMAC_TABLE).build(); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Builds TMAC rules for IPv6 packets. |
| 865 | * |
Charles Chan | c550f2e | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 866 | * @param ethCriterion dst mac matching |
| 867 | * @param vidCriterion vlan id assigned to the port |
| 868 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 869 | * @param applicationId application id |
| 870 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 871 | * @return TMAC rule for IPV6 packets |
| 872 | */ |
| 873 | private FlowRule buildTmacRuleForIpv6(EthCriterion ethCriterion, |
| 874 | VlanIdCriterion vidCriterion, |
| 875 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 876 | ApplicationId applicationId, |
| 877 | PortNumber pnum) { |
| 878 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 879 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 880 | if (pnum != null) { |
| 881 | if (matchInPortTmacTable()) { |
| 882 | selector.matchInPort(pnum); |
| 883 | } else { |
Saurav Das | f14d9ef | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 884 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 885 | "ignoring the IN_PORT criteria"); |
| 886 | } |
| 887 | } |
| 888 | if (vidCriterion != null) { |
| 889 | if (requireVlanExtensions()) { |
| 890 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 891 | } else { |
| 892 | selector.matchVlanId(vidCriterion.vlanId()); |
| 893 | } |
| 894 | } |
| 895 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 896 | selector.matchEthDst(ethCriterion.mac()); |
| 897 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 898 | return DefaultFlowRule.builder() |
| 899 | .forDevice(deviceId) |
| 900 | .withSelector(selector.build()) |
| 901 | .withTreatment(treatment.build()) |
| 902 | .withPriority(DEFAULT_PRIORITY) |
| 903 | .fromApp(applicationId) |
| 904 | .makePermanent() |
| 905 | .forTable(TMAC_TABLE).build(); |
| 906 | } |
| 907 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 908 | protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 909 | ApplicationId applicationId) { |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 910 | ImmutableList.Builder<FlowRule> builder = ImmutableList.builder(); |
| 911 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 912 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 913 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 914 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 915 | selector.matchEthDst(ethCriterion.mac()); |
| 916 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 917 | FlowRule rule = DefaultFlowRule.builder() |
| 918 | .forDevice(deviceId) |
| 919 | .withSelector(selector.build()) |
| 920 | .withTreatment(treatment.build()) |
| 921 | .withPriority(DEFAULT_PRIORITY) |
| 922 | .fromApp(applicationId) |
| 923 | .makePermanent() |
| 924 | .forTable(TMAC_TABLE).build(); |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 925 | builder.add(rule); |
| 926 | |
| 927 | selector = DefaultTrafficSelector.builder(); |
| 928 | treatment = DefaultTrafficTreatment.builder(); |
| 929 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 930 | selector.matchEthDst(ethCriterion.mac()); |
| 931 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 932 | rule = DefaultFlowRule.builder() |
| 933 | .forDevice(deviceId) |
| 934 | .withSelector(selector.build()) |
| 935 | .withTreatment(treatment.build()) |
| 936 | .withPriority(DEFAULT_PRIORITY) |
| 937 | .fromApp(applicationId) |
| 938 | .makePermanent() |
| 939 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 940 | return ImmutableList.of(builder.add(rule).build()); |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 941 | } |
| 942 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 943 | List<List<FlowRule>> processMcastEthDstFilter(EthCriterion ethCriterion, |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 944 | VlanId assignedVlan, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 945 | MacAddress unicastMac, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 946 | ApplicationId applicationId) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 947 | ImmutableList.Builder<FlowRule> unicastFlows = ImmutableList.builder(); |
| 948 | ImmutableList.Builder<FlowRule> multicastFlows = ImmutableList.builder(); |
| 949 | TrafficSelector.Builder selector; |
| 950 | TrafficTreatment.Builder treatment; |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 951 | FlowRule rule; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 952 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 953 | if (IPV4_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 954 | if (requireUnicastBeforeMulticast()) { |
| 955 | selector = DefaultTrafficSelector.builder(); |
| 956 | treatment = DefaultTrafficTreatment.builder(); |
| 957 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 958 | selector.matchEthDst(unicastMac); |
| 959 | selector.matchVlanId(assignedVlan); |
| 960 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 961 | rule = DefaultFlowRule.builder() |
| 962 | .forDevice(deviceId) |
| 963 | .withSelector(selector.build()) |
| 964 | .withTreatment(treatment.build()) |
| 965 | .withPriority(DEFAULT_PRIORITY) |
| 966 | .fromApp(applicationId) |
| 967 | .makePermanent() |
| 968 | .forTable(TMAC_TABLE).build(); |
| 969 | unicastFlows.add(rule); |
| 970 | } |
| 971 | |
| 972 | selector = DefaultTrafficSelector.builder(); |
| 973 | treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 974 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 975 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
| 976 | selector.matchVlanId(assignedVlan); |
| 977 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 978 | rule = DefaultFlowRule.builder() |
| 979 | .forDevice(deviceId) |
| 980 | .withSelector(selector.build()) |
| 981 | .withTreatment(treatment.build()) |
| 982 | .withPriority(DEFAULT_PRIORITY) |
| 983 | .fromApp(applicationId) |
| 984 | .makePermanent() |
| 985 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 986 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | if (IPV6_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 990 | if (requireUnicastBeforeMulticast()) { |
| 991 | selector = DefaultTrafficSelector.builder(); |
| 992 | treatment = DefaultTrafficTreatment.builder(); |
| 993 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 994 | selector.matchEthDst(unicastMac); |
| 995 | selector.matchVlanId(assignedVlan); |
| 996 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 997 | rule = DefaultFlowRule.builder() |
| 998 | .forDevice(deviceId) |
| 999 | .withSelector(selector.build()) |
| 1000 | .withTreatment(treatment.build()) |
| 1001 | .withPriority(DEFAULT_PRIORITY) |
| 1002 | .fromApp(applicationId) |
| 1003 | .makePermanent() |
| 1004 | .forTable(TMAC_TABLE).build(); |
| 1005 | unicastFlows.add(rule); |
| 1006 | } |
| 1007 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1008 | selector = DefaultTrafficSelector.builder(); |
| 1009 | treatment = DefaultTrafficTreatment.builder(); |
| 1010 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 1011 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
| 1012 | selector.matchVlanId(assignedVlan); |
| 1013 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 1014 | rule = DefaultFlowRule.builder() |
| 1015 | .forDevice(deviceId) |
| 1016 | .withSelector(selector.build()) |
| 1017 | .withTreatment(treatment.build()) |
| 1018 | .withPriority(DEFAULT_PRIORITY) |
| 1019 | .fromApp(applicationId) |
| 1020 | .makePermanent() |
| 1021 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1022 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1023 | } |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1024 | return ImmutableList.of(unicastFlows.build(), multicastFlows.build()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1027 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 1028 | switch (fwd.flag()) { |
| 1029 | case SPECIFIC: |
| 1030 | return processSpecific(fwd); |
| 1031 | case VERSATILE: |
| 1032 | return processVersatile(fwd); |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1033 | case EGRESS: |
| 1034 | return processEgress(fwd); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1035 | default: |
| 1036 | fail(fwd, ObjectiveError.UNKNOWN); |
| 1037 | log.warn("Unknown forwarding flag {}", fwd.flag()); |
| 1038 | } |
| 1039 | return Collections.emptySet(); |
| 1040 | } |
| 1041 | |
| 1042 | /** |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1043 | * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the |
| 1044 | * egress tables. |
| 1045 | * @param fwd the forwarding objective of type 'egress' |
| 1046 | * @return a collection of flow rules to be sent to the switch. An empty |
| 1047 | * collection may be returned if there is a problem in processing |
| 1048 | * the flow rule |
| 1049 | */ |
| 1050 | protected Collection<FlowRule> processEgress(ForwardingObjective fwd) { |
| 1051 | log.debug("Processing egress forwarding objective:{} in dev:{}", |
| 1052 | fwd, deviceId); |
| 1053 | |
| 1054 | List<FlowRule> rules = new ArrayList<>(); |
| 1055 | |
| 1056 | // Build selector |
| 1057 | TrafficSelector.Builder sb = DefaultTrafficSelector.builder(); |
| 1058 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID); |
| 1059 | if (vlanIdCriterion == null) { |
| 1060 | log.error("Egress forwarding objective:{} must include vlanId", fwd.id()); |
| 1061 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1062 | return rules; |
| 1063 | } |
| 1064 | |
| 1065 | Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream() |
| 1066 | .filter(instruction -> instruction instanceof OutputInstruction).findFirst(); |
| 1067 | if (!outInstr.isPresent()) { |
| 1068 | log.error("Egress forwarding objective:{} must include output port", fwd.id()); |
| 1069 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1070 | return rules; |
| 1071 | } |
| 1072 | |
| 1073 | PortNumber portNumber = ((OutputInstruction) outInstr.get()).port(); |
| 1074 | |
| 1075 | sb.matchVlanId(vlanIdCriterion.vlanId()); |
| 1076 | OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber); |
| 1077 | sb.extension(actsetOutput, deviceId); |
| 1078 | |
| 1079 | sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId); |
| 1080 | |
| 1081 | // Build a flow rule for Egress VLAN Flow table |
| 1082 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 1083 | tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE); |
| 1084 | if (fwd.treatment() != null) { |
| 1085 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1086 | if (instr instanceof L2ModificationInstruction && |
| 1087 | ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) { |
| 1088 | tb.immediate().add(instr); |
| 1089 | } |
| 1090 | if (instr instanceof L2ModificationInstruction && |
| 1091 | ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) { |
| 1092 | tb.immediate().pushVlan(); |
| 1093 | EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType(); |
| 1094 | if (ethType.equals(EtherType.QINQ.ethType())) { |
| 1095 | // Build a flow rule for Egress TPID Flow table |
| 1096 | TrafficSelector tpidSelector = DefaultTrafficSelector.builder() |
| 1097 | .extension(actsetOutput, deviceId) |
| 1098 | .matchVlanId(VlanId.ANY).build(); |
| 1099 | |
| 1100 | TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder() |
| 1101 | .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, |
| 1102 | COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, |
| 1103 | OXM_ID_PACKET_REG_1), |
| 1104 | deviceId) |
| 1105 | .popVlan() |
| 1106 | .pushVlan(EtherType.QINQ.ethType()) |
| 1107 | .extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, |
| 1108 | COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, |
| 1109 | OXM_ID_VLAN_VID), |
| 1110 | deviceId) |
| 1111 | .build(); |
| 1112 | |
| 1113 | FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder() |
| 1114 | .fromApp(fwd.appId()) |
| 1115 | .withPriority(fwd.priority()) |
| 1116 | .forDevice(deviceId) |
| 1117 | .withSelector(tpidSelector) |
| 1118 | .withTreatment(tpidTreatment) |
| 1119 | .makePermanent() |
| 1120 | .forTable(EGRESS_TPID_FLOW_TABLE); |
| 1121 | rules.add(tpidRuleBuilder.build()); |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1128 | .fromApp(fwd.appId()) |
| 1129 | .withPriority(fwd.priority()) |
| 1130 | .forDevice(deviceId) |
| 1131 | .withSelector(sb.build()) |
| 1132 | .withTreatment(tb.build()) |
| 1133 | .makePermanent() |
| 1134 | .forTable(EGRESS_VLAN_FLOW_TABLE); |
| 1135 | rules.add(ruleBuilder.build()); |
| 1136 | return rules; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1140 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 1141 | * ACL table. |
| 1142 | * @param fwd the forwarding objective of type 'versatile' |
| 1143 | * @return a collection of flow rules to be sent to the switch. An empty |
| 1144 | * collection may be returned if there is a problem in processing |
| 1145 | * the flow rule |
| 1146 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1147 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1148 | log.debug("Processing versatile forwarding objective:{} in dev:{}", |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1149 | fwd.id(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1150 | |
| 1151 | EthTypeCriterion ethType = |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1152 | (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1153 | if (ethType == null) { |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1154 | log.error("Versatile forwarding objective:{} must include ethType", |
| 1155 | fwd.id()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1156 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1157 | return Collections.emptySet(); |
| 1158 | } |
| 1159 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 1160 | log.error("Forwarding objective {} from {} must contain " |
| 1161 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
Zsolt Haraszti | 9faab75 | 2016-02-17 15:55:20 -0800 | [diff] [blame] | 1162 | fail(fwd, ObjectiveError.BADPARAMS); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1163 | return Collections.emptySet(); |
| 1164 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1165 | |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1166 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1167 | fwd.selector().criteria().forEach(criterion -> { |
| 1168 | if (criterion instanceof VlanIdCriterion) { |
| 1169 | VlanId vlanId = ((VlanIdCriterion) criterion).vlanId(); |
| 1170 | // ensure that match does not include vlan = NONE as OF-DPA does not |
| 1171 | // match untagged packets this way in the ACL table. |
| 1172 | if (vlanId.equals(VlanId.NONE)) { |
| 1173 | return; |
| 1174 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1175 | if (requireVlanExtensions()) { |
| 1176 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanId); |
| 1177 | sbuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1178 | } else { |
| 1179 | sbuilder.matchVlanId(vlanId); |
| 1180 | } |
Charles Chan | 09bf269 | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1181 | } else if (criterion instanceof Icmpv6TypeCriterion) { |
| 1182 | byte icmpv6Type = (byte) ((Icmpv6TypeCriterion) criterion).icmpv6Type(); |
| 1183 | sbuilder.matchIcmpv6Type(icmpv6Type); |
| 1184 | } else if (criterion instanceof Icmpv6CodeCriterion) { |
| 1185 | byte icmpv6Code = (byte) ((Icmpv6CodeCriterion) criterion).icmpv6Code(); |
| 1186 | sbuilder.matchIcmpv6Type(icmpv6Code); |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1187 | } else if (criterion instanceof TcpPortCriterion || criterion instanceof UdpPortCriterion) { |
| 1188 | // FIXME: QMX switches do not support L4 dst port matching in ACL table. |
| 1189 | // Currently L4 dst port matching is only used by DHCP relay feature |
| 1190 | // and therefore is safe to be replaced with L4 src port matching. |
| 1191 | // We need to revisit this if L4 dst port is used for other purpose in the future. |
| 1192 | if (!supportIpv6L4Dst() && isIpv6(fwd.selector())) { |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1193 | switch (criterion.type()) { |
| 1194 | case UDP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1195 | case UDP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1196 | case TCP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1197 | case TCP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | default: |
| 1200 | sbuilder.add(criterion); |
| 1201 | } |
| 1202 | } else { |
| 1203 | sbuilder.add(criterion); |
| 1204 | } |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1205 | } else { |
| 1206 | sbuilder.add(criterion); |
| 1207 | } |
| 1208 | }); |
| 1209 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1210 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 1211 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1212 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 1213 | if (fwd.treatment() != null) { |
| 1214 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 1215 | if (ins instanceof OutputInstruction) { |
| 1216 | OutputInstruction o = (OutputInstruction) ins; |
Ray Milkey | fe0e085 | 2018-01-18 11:14:05 -0800 | [diff] [blame] | 1217 | if (PortNumber.CONTROLLER.equals(o.port())) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1218 | ttBuilder.add(o); |
| 1219 | } else { |
| 1220 | log.warn("Only allowed treatments in versatile forwarding " |
| 1221 | + "objectives are punts to the controller"); |
| 1222 | } |
| 1223 | } else { |
| 1224 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 1225 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1226 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 1227 | if (fwd.treatment().clearedDeferred()) { |
| 1228 | ttBuilder.wipeDeferred(); |
| 1229 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1230 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1231 | if (fwd.nextId() != null) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1232 | // overide case |
| 1233 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 1234 | if (next == null) { |
| 1235 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1236 | return Collections.emptySet(); |
| 1237 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1238 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1239 | // we only need the top level group's key to point the flow to it |
| 1240 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1241 | if (group == null) { |
| 1242 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1243 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1244 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1245 | return Collections.emptySet(); |
| 1246 | } |
| 1247 | ttBuilder.deferred().group(group.id()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1248 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1249 | |
| 1250 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1251 | .fromApp(fwd.appId()) |
| 1252 | .withPriority(fwd.priority()) |
| 1253 | .forDevice(deviceId) |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1254 | .withSelector(sbuilder.build()) |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1255 | .withTreatment(ttBuilder.build()) |
| 1256 | .makePermanent() |
| 1257 | .forTable(ACL_TABLE); |
| 1258 | return Collections.singletonList(ruleBuilder.build()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * In the OF-DPA 2.0 pipeline, specific forwarding refers to the IP table |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1263 | * (unicast or multicast) or the L2 table (mac + vlan) or the MPLS table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1264 | * |
| 1265 | * @param fwd the forwarding objective of type 'specific' |
| 1266 | * @return a collection of flow rules. Typically there will be only one |
| 1267 | * for this type of forwarding objective. An empty set may be |
| 1268 | * returned if there is an issue in processing the objective. |
| 1269 | */ |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1270 | private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1271 | log.debug("Processing specific fwd objective:{} in dev:{} with next:{}", |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1272 | fwd.id(), deviceId, fwd.nextId()); |
| 1273 | boolean isEthTypeObj = isSupportedEthTypeObjective(fwd); |
| 1274 | boolean isEthDstObj = isSupportedEthDstObjective(fwd); |
| 1275 | |
| 1276 | if (isEthTypeObj) { |
| 1277 | return processEthTypeSpecific(fwd); |
| 1278 | } else if (isEthDstObj) { |
| 1279 | return processEthDstSpecific(fwd); |
| 1280 | } else { |
| 1281 | log.warn("processSpecific: Unsupported forwarding objective " |
| 1282 | + "criteria fwd:{} in dev:{}", fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1283 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 1284 | return Collections.emptySet(); |
| 1285 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1288 | /** |
| 1289 | * Handles forwarding rules to the IP and MPLS tables. |
| 1290 | * |
| 1291 | * @param fwd the forwarding objective |
| 1292 | * @return A collection of flow rules, or an empty set |
| 1293 | */ |
| 1294 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1295 | return processEthTypeSpecificInternal(fwd, false, ACL_TABLE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Internal implementation of processEthTypeSpecific. |
| 1300 | * <p> |
| 1301 | * Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break |
| 1302 | * the rule into 0.0.0.0/1 and 128.0.0.0/1. |
| 1303 | * The allowDefaultRoute must be set to false for OFDPA i12. |
| 1304 | * </p> |
| 1305 | * |
| 1306 | * @param fwd the forwarding objective |
| 1307 | * @param allowDefaultRoute allow wildcarded IPv4_DST or not |
Ray Milkey | 0bb1e10 | 2016-11-10 14:51:27 -0800 | [diff] [blame] | 1308 | * @param mplsNextTable next MPLS table |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1309 | * @return A collection of flow rules, or an empty set |
| 1310 | */ |
| 1311 | protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd, |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1312 | boolean allowDefaultRoute, |
| 1313 | int mplsNextTable) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1314 | TrafficSelector selector = fwd.selector(); |
| 1315 | EthTypeCriterion ethType = |
| 1316 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1317 | boolean emptyGroup = false; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1318 | int forTableId; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1319 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1320 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1321 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1322 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1323 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1324 | if (buildIpv4Selector(filteredSelector, complementarySelector, fwd, allowDefaultRoute) < 0) { |
| 1325 | return Collections.emptyList(); |
| 1326 | } |
| 1327 | // We need to set properly the next table |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1328 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1329 | if (ipv4Dst.isMulticast()) { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1330 | forTableId = MULTICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1331 | } else { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1332 | forTableId = UNICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1333 | } |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1334 | |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1335 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1336 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1337 | // if (fwd.treatment() != null) { |
| 1338 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1339 | // if (instr instanceof L3ModificationInstruction && |
| 1340 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1341 | // tb.deferred().add(instr); |
| 1342 | // } |
| 1343 | // } |
| 1344 | // } |
| 1345 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1346 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
| 1347 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 1348 | return Collections.emptyList(); |
| 1349 | } |
Kalhee Kim | 3d26bf0 | 2017-10-04 14:59:11 +0000 | [diff] [blame] | 1350 | //We need to set the proper next table |
| 1351 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1352 | if (ipv6Dst.isMulticast()) { |
| 1353 | forTableId = MULTICAST_ROUTING_TABLE; |
| 1354 | } else { |
| 1355 | forTableId = UNICAST_ROUTING_TABLE; |
| 1356 | } |
| 1357 | |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1358 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1359 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 236653d | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1360 | // if (fwd.treatment() != null) { |
| 1361 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1362 | // if (instr instanceof L3ModificationInstruction && |
| 1363 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1364 | // tb.deferred().add(instr); |
| 1365 | // } |
| 1366 | // } |
| 1367 | // } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1368 | } else { |
| 1369 | filteredSelector |
| 1370 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 1371 | .matchMplsLabel(((MplsCriterion) |
| 1372 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 1373 | MplsBosCriterion bos = (MplsBosCriterion) selector |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1374 | .getCriterion(MPLS_BOS); |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1375 | if (bos != null && requireMplsBosMatch()) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1376 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 1377 | } |
| 1378 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1379 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 1380 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1381 | |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1382 | if (fwd.treatment() != null) { |
| 1383 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1384 | if (instr instanceof L2ModificationInstruction && |
| 1385 | ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1386 | // OF-DPA does not pop in MPLS table in some cases. For the L3 VPN, it requires |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1387 | // setting the MPLS_TYPE so pop can happen down the pipeline |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1388 | if (requireMplsPop()) { |
| 1389 | if (mplsNextTable == MPLS_TYPE_TABLE && isNotMplsBos(selector)) { |
| 1390 | tb.immediate().popMpls(); |
| 1391 | } |
| 1392 | } else { |
| 1393 | // Skip mpls pop action for mpls_unicast label |
| 1394 | if (instr instanceof ModMplsHeaderInstruction && |
| 1395 | !((ModMplsHeaderInstruction) instr).ethernetType() |
| 1396 | .equals(EtherType.MPLS_UNICAST.ethType())) { |
| 1397 | tb.immediate().add(instr); |
| 1398 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1399 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1400 | } |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1401 | |
| 1402 | if (requireMplsTtlModification()) { |
| 1403 | if (instr instanceof L3ModificationInstruction && |
| 1404 | ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1405 | // FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction |
| 1406 | tb.immediate().decMplsTtl(); |
| 1407 | } |
| 1408 | if (instr instanceof L3ModificationInstruction && |
| 1409 | ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) { |
| 1410 | tb.immediate().add(instr); |
| 1411 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1412 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1416 | |
| 1417 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1418 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1419 | if (next != null) { |
| 1420 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1421 | // we only need the top level group's key to point the flow to it |
| 1422 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1423 | if (group == null) { |
| 1424 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1425 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1426 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1427 | return Collections.emptySet(); |
| 1428 | } |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1429 | if (isNotMplsBos(selector) && group.type().equals(SELECT)) { |
| 1430 | log.warn("SR CONTINUE case cannot be handled as MPLS ECMP " |
| 1431 | + "is not implemented in OF-DPA yet. Aborting flow {} -> next:{} " |
| 1432 | + "in this device {}", fwd.id(), fwd.nextId(), deviceId); |
| 1433 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1434 | return Collections.emptySet(); |
| 1435 | } |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1436 | tb.deferred().group(group.id()); |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1437 | // retrying flows may be necessary due to bug CORD-554 |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1438 | if (gkeys.size() == 1 && gkeys.get(0).size() == 1) { |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1439 | if (shouldRetry()) { |
| 1440 | log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}", |
| 1441 | Integer.toHexString(group.id().id()), deviceId, |
| 1442 | fwd.id()); |
| 1443 | emptyGroup = true; |
| 1444 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1445 | } |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1446 | } else { |
| 1447 | log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", |
| 1448 | fwd.nextId(), deviceId, fwd.id()); |
| 1449 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1450 | return Collections.emptySet(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1451 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1452 | } |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1453 | |
| 1454 | if (forTableId == MPLS_TABLE_1) { |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1455 | if (mplsNextTable == MPLS_L3_TYPE_TABLE) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1456 | Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP); |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1457 | // set mpls type as apply_action |
| 1458 | tb.immediate().extension(setMplsType, deviceId); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1459 | } |
| 1460 | tb.transition(mplsNextTable); |
| 1461 | } else { |
| 1462 | tb.transition(ACL_TABLE); |
| 1463 | } |
| 1464 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1465 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1466 | .fromApp(fwd.appId()) |
| 1467 | .withPriority(fwd.priority()) |
| 1468 | .forDevice(deviceId) |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1469 | .withSelector(filteredSelector.build()) |
| 1470 | .withTreatment(tb.build()) |
| 1471 | .forTable(forTableId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1472 | |
| 1473 | if (fwd.permanent()) { |
| 1474 | ruleBuilder.makePermanent(); |
| 1475 | } else { |
| 1476 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 1477 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1478 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 1479 | flowRuleCollection.add(ruleBuilder.build()); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1480 | if (!allowDefaultRoute) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1481 | flowRuleCollection.add( |
| 1482 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 1483 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1484 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 1485 | } |
Saurav Das | c568c34 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1486 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1487 | if (emptyGroup) { |
| 1488 | executorService.schedule(new RetryFlows(fwd, flowRuleCollection), |
| 1489 | RETRY_MS, TimeUnit.MILLISECONDS); |
| 1490 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1491 | return flowRuleCollection; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1494 | private int buildIpv4Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1495 | TrafficSelector.Builder extBuilder, |
| 1496 | ForwardingObjective fwd, |
| 1497 | boolean allowDefaultRoute) { |
| 1498 | TrafficSelector selector = fwd.selector(); |
| 1499 | |
| 1500 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
| 1501 | if (ipv4Dst.isMulticast()) { |
| 1502 | if (ipv4Dst.prefixLength() != 32) { |
| 1503 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 1504 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1505 | return -1; |
| 1506 | } |
| 1507 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1508 | if (assignedVlan == null) { |
| 1509 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1510 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1511 | return -1; |
| 1512 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1513 | if (requireVlanExtensions()) { |
| 1514 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1515 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1516 | } else { |
| 1517 | builderToUpdate.matchVlanId(assignedVlan); |
| 1518 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1519 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1520 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 1521 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1522 | } else { |
| 1523 | if (ipv4Dst.prefixLength() == 0) { |
| 1524 | if (allowDefaultRoute) { |
| 1525 | // The entire IPV4_DST field is wildcarded intentionally |
| 1526 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4); |
| 1527 | } else { |
| 1528 | // NOTE: The switch does not support matching 0.0.0.0/0 |
| 1529 | // Split it into 0.0.0.0/1 and 128.0.0.0/1 |
| 1530 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4) |
| 1531 | .matchIPDst(IpPrefix.valueOf("0.0.0.0/1")); |
| 1532 | extBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 1533 | .matchIPDst(IpPrefix.valueOf("128.0.0.0/1")); |
| 1534 | } |
| 1535 | } else { |
| 1536 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1537 | } |
| 1538 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 1539 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1540 | } |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | /** |
| 1545 | * Helper method to build Ipv6 selector using the selector provided by |
| 1546 | * a forwarding objective. |
| 1547 | * |
| 1548 | * @param builderToUpdate the builder to update |
| 1549 | * @param fwd the selector to read |
| 1550 | * @return 0 if the update ends correctly. -1 if the matches |
| 1551 | * are not yet supported |
| 1552 | */ |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1553 | int buildIpv6Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1554 | ForwardingObjective fwd) { |
| 1555 | |
| 1556 | TrafficSelector selector = fwd.selector(); |
| 1557 | |
| 1558 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1559 | if (ipv6Dst.isMulticast()) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1560 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 1561 | log.warn("Multicast specific forwarding objective can only be /128"); |
| 1562 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1563 | return -1; |
| 1564 | } |
| 1565 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1566 | if (assignedVlan == null) { |
| 1567 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1568 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1569 | return -1; |
| 1570 | } |
| 1571 | if (requireVlanExtensions()) { |
| 1572 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1573 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1574 | } else { |
| 1575 | builderToUpdate.matchVlanId(assignedVlan); |
| 1576 | } |
| 1577 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 1578 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 1579 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1580 | } else { |
| 1581 | if (ipv6Dst.prefixLength() != 0) { |
| 1582 | builderToUpdate.matchIPv6Dst(ipv6Dst); |
| 1583 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1584 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6); |
| 1585 | log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}" |
| 1586 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1587 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1588 | return 0; |
| 1589 | } |
| 1590 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1591 | FlowRule defaultRoute(ForwardingObjective fwd, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1592 | TrafficSelector.Builder complementarySelector, |
| 1593 | int forTableId, |
| 1594 | TrafficTreatment.Builder tb) { |
| 1595 | FlowRule.Builder rule = DefaultFlowRule.builder() |
| 1596 | .fromApp(fwd.appId()) |
| 1597 | .withPriority(fwd.priority()) |
| 1598 | .forDevice(deviceId) |
| 1599 | .withSelector(complementarySelector.build()) |
| 1600 | .withTreatment(tb.build()) |
| 1601 | .forTable(forTableId); |
| 1602 | if (fwd.permanent()) { |
| 1603 | rule.makePermanent(); |
| 1604 | } else { |
| 1605 | rule.makeTemporary(fwd.timeout()); |
| 1606 | } |
| 1607 | return rule.build(); |
| 1608 | } |
| 1609 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1610 | /** |
| 1611 | * Handles forwarding rules to the L2 bridging table. Flow actions are not |
| 1612 | * allowed in the bridging table - instead we use L2 Interface group or |
| 1613 | * L2 flood group |
| 1614 | * |
| 1615 | * @param fwd the forwarding objective |
| 1616 | * @return A collection of flow rules, or an empty set |
| 1617 | */ |
| 1618 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 1619 | List<FlowRule> rules = new ArrayList<>(); |
| 1620 | |
| 1621 | // Build filtered selector |
| 1622 | TrafficSelector selector = fwd.selector(); |
| 1623 | EthCriterion ethCriterion = (EthCriterion) selector |
| 1624 | .getCriterion(Criterion.Type.ETH_DST); |
| 1625 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
| 1626 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1627 | |
| 1628 | if (vlanIdCriterion == null) { |
| 1629 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 1630 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 1631 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1632 | return Collections.emptySet(); |
| 1633 | } |
| 1634 | |
| 1635 | TrafficSelector.Builder filteredSelectorBuilder = |
| 1636 | DefaultTrafficSelector.builder(); |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1637 | |
| 1638 | if (!ethCriterion.mac().equals(NONE) && |
| 1639 | !ethCriterion.mac().equals(BROADCAST)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1640 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 1641 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 1642 | fwd.id(), fwd.nextId(), deviceId); |
| 1643 | } else { |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1644 | // Use wildcard DST_MAC if the MacAddress is None or Broadcast |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1645 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 1646 | + "in dev:{} for vlan:{}", |
| 1647 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 1648 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1649 | if (requireVlanExtensions()) { |
| 1650 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId()); |
| 1651 | filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1652 | } else { |
| 1653 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 1654 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1655 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 1656 | |
| 1657 | if (fwd.treatment() != null) { |
| 1658 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 1659 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 1660 | } |
| 1661 | |
| 1662 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1663 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1664 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1665 | if (next != null) { |
| 1666 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1667 | // we only need the top level group's key to point the flow to it |
| 1668 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1669 | if (group != null) { |
| 1670 | treatmentBuilder.deferred().group(group.id()); |
| 1671 | } else { |
| 1672 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1673 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1674 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1675 | return Collections.emptySet(); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 1680 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 1681 | |
| 1682 | // Build bridging table entries |
| 1683 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 1684 | flowRuleBuilder.fromApp(fwd.appId()) |
| 1685 | .withPriority(fwd.priority()) |
| 1686 | .forDevice(deviceId) |
| 1687 | .withSelector(filteredSelector) |
| 1688 | .withTreatment(filteredTreatment) |
| 1689 | .forTable(BRIDGING_TABLE); |
| 1690 | if (fwd.permanent()) { |
| 1691 | flowRuleBuilder.makePermanent(); |
| 1692 | } else { |
| 1693 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 1694 | } |
| 1695 | rules.add(flowRuleBuilder.build()); |
| 1696 | return rules; |
| 1697 | } |
| 1698 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1699 | ////////////////////////////////////// |
| 1700 | // Helper Methods and Classes |
| 1701 | ////////////////////////////////////// |
| 1702 | |
| 1703 | private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { |
| 1704 | TrafficSelector selector = fwd.selector(); |
| 1705 | EthTypeCriterion ethType = (EthTypeCriterion) selector |
| 1706 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 1707 | return !((ethType == null) || |
| 1708 | ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1709 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) && |
| 1710 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | private boolean isSupportedEthDstObjective(ForwardingObjective fwd) { |
| 1714 | TrafficSelector selector = fwd.selector(); |
| 1715 | EthCriterion ethDst = (EthCriterion) selector |
| 1716 | .getCriterion(Criterion.Type.ETH_DST); |
| 1717 | VlanIdCriterion vlanId = (VlanIdCriterion) selector |
| 1718 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1719 | return !(ethDst == null && vlanId == null); |
| 1720 | } |
| 1721 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1722 | NextGroup getGroupForNextObjective(Integer nextId) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1723 | NextGroup next = flowObjectiveStore.getNextGroup(nextId); |
| 1724 | if (next != null) { |
| 1725 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1726 | if (gkeys != null && !gkeys.isEmpty()) { |
| 1727 | return next; |
| 1728 | } else { |
| 1729 | log.warn("Empty next group found in FlowObjective store for " |
| 1730 | + "next-id:{} in dev:{}", nextId, deviceId); |
| 1731 | } |
| 1732 | } else { |
| 1733 | log.warn("next-id {} not found in Flow objective store for dev:{}", |
| 1734 | nextId, deviceId); |
| 1735 | } |
| 1736 | return null; |
| 1737 | } |
| 1738 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1739 | protected static void pass(Objective obj) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 1740 | obj.context().ifPresent(context -> context.onSuccess(obj)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1743 | protected static void fail(Objective obj, ObjectiveError error) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 1744 | obj.context().ifPresent(context -> context.onError(obj, error)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1745 | } |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1746 | |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1747 | @Override |
| 1748 | public List<String> getNextMappings(NextGroup nextGroup) { |
| 1749 | List<String> mappings = new ArrayList<>(); |
| 1750 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(nextGroup.data()); |
| 1751 | for (Deque<GroupKey> gkd : gkeys) { |
| 1752 | Group lastGroup = null; |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1753 | StringBuilder gchain = new StringBuilder(); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1754 | for (GroupKey gk : gkd) { |
| 1755 | Group g = groupService.getGroup(deviceId, gk); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1756 | if (g == null) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1757 | gchain.append(" NoGrp").append(" -->"); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1758 | continue; |
| 1759 | } |
| 1760 | gchain.append(" 0x").append(Integer.toHexString(g.id().id())) |
| 1761 | .append(" -->"); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1762 | lastGroup = g; |
| 1763 | } |
| 1764 | // add port information for last group in group-chain |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1765 | List<Instruction> lastGroupIns = new ArrayList<>(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1766 | if (lastGroup != null && !lastGroup.buckets().buckets().isEmpty()) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1767 | lastGroupIns = lastGroup.buckets().buckets().get(0) |
| 1768 | .treatment().allInstructions(); |
| 1769 | } |
| 1770 | for (Instruction i: lastGroupIns) { |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1771 | if (i instanceof OutputInstruction) { |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1772 | gchain.append(" port:").append(((OutputInstruction) i).port()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1773 | } |
| 1774 | } |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1775 | mappings.add(gchain.toString()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1776 | } |
| 1777 | return mappings; |
| 1778 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1779 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1780 | /** |
| 1781 | * Returns true iff the given selector matches on BOS==true, indicating that |
| 1782 | * the selector is trying to match on a label that is bottom-of-stack. |
| 1783 | * |
| 1784 | * @param selector the given match |
| 1785 | * @return true iff BoS==true; false if BOS==false, or BOS matching is not |
| 1786 | * expressed in the given selector |
| 1787 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1788 | static boolean isMplsBos(TrafficSelector selector) { |
| 1789 | MplsBosCriterion bosCriterion = (MplsBosCriterion) selector.getCriterion(MPLS_BOS); |
| 1790 | return bosCriterion != null && bosCriterion.mplsBos(); |
| 1791 | } |
| 1792 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1793 | /** |
| 1794 | * Returns true iff the given selector matches on BOS==false, indicating |
| 1795 | * that the selector is trying to match on a label that is not the |
| 1796 | * bottom-of-stack label. |
| 1797 | * |
| 1798 | * @param selector the given match |
| 1799 | * @return true iff BoS==false; |
| 1800 | * false if BOS==true, or BOS matching is not expressed in the given selector |
| 1801 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1802 | static boolean isNotMplsBos(TrafficSelector selector) { |
| 1803 | MplsBosCriterion bosCriterion = (MplsBosCriterion) selector.getCriterion(MPLS_BOS); |
| 1804 | return bosCriterion != null && !bosCriterion.mplsBos(); |
| 1805 | } |
| 1806 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1807 | /** |
| 1808 | * Returns true iff the forwarding objective includes a treatment to pop the |
| 1809 | * MPLS label. |
| 1810 | * |
| 1811 | * @param fwd the given forwarding objective |
| 1812 | * @return true iff mpls pop treatment exists |
| 1813 | */ |
| 1814 | static boolean isMplsPop(ForwardingObjective fwd) { |
| 1815 | if (fwd.treatment() != null) { |
| 1816 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1817 | if (instr instanceof L2ModificationInstruction |
| 1818 | && ((L2ModificationInstruction) instr) |
| 1819 | .subtype() == L2SubType.MPLS_POP) { |
| 1820 | return true; |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | return false; |
| 1825 | } |
| 1826 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1827 | private static boolean isIpv6(TrafficSelector selector) { |
| 1828 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) selector.getCriterion(ETH_TYPE); |
| 1829 | return ethTypeCriterion != null && ethTypeCriterion.ethType().toShort() == Ethernet.TYPE_IPV6; |
| 1830 | } |
| 1831 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1832 | static VlanId readVlanFromSelector(TrafficSelector selector) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1833 | if (selector == null) { |
| 1834 | return null; |
| 1835 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1836 | Criterion criterion = selector.getCriterion(Criterion.Type.VLAN_VID); |
| 1837 | return (criterion == null) |
| 1838 | ? null : ((VlanIdCriterion) criterion).vlanId(); |
| 1839 | } |
| 1840 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1841 | static IpPrefix readIpDstFromSelector(TrafficSelector selector) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1842 | if (selector == null) { |
| 1843 | return null; |
| 1844 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1845 | Criterion criterion = selector.getCriterion(Criterion.Type.IPV4_DST); |
| 1846 | return (criterion == null) ? null : ((IPCriterion) criterion).ip(); |
| 1847 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1848 | |
| 1849 | private static VlanId readVlanFromTreatment(TrafficTreatment treatment) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1850 | if (treatment == null) { |
| 1851 | return null; |
| 1852 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1853 | for (Instruction i : treatment.allInstructions()) { |
| 1854 | if (i instanceof ModVlanIdInstruction) { |
| 1855 | return ((ModVlanIdInstruction) i).vlanId(); |
| 1856 | } |
| 1857 | } |
| 1858 | return null; |
| 1859 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1860 | |
Jonghwan Hyun | a76bf03 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1861 | protected static MacAddress readEthDstFromTreatment(TrafficTreatment treatment) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1862 | if (treatment == null) { |
| 1863 | return null; |
| 1864 | } |
| 1865 | for (Instruction i : treatment.allInstructions()) { |
| 1866 | if (i instanceof ModEtherInstruction) { |
| 1867 | ModEtherInstruction modEtherInstruction = (ModEtherInstruction) i; |
| 1868 | if (modEtherInstruction.subtype() == L2SubType.ETH_DST) { |
| 1869 | return modEtherInstruction.mac(); |
| 1870 | } |
| 1871 | } |
| 1872 | } |
| 1873 | return null; |
| 1874 | } |
| 1875 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1876 | /** |
| 1877 | * Utility class that retries sending flows a fixed number of times, even if |
| 1878 | * some of the attempts are successful. Used only for forwarding objectives. |
| 1879 | */ |
Alex Yashchuk | 4caa8e8 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1880 | public final class RetryFlows implements Runnable { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1881 | int attempts = MAX_RETRY_ATTEMPTS; |
| 1882 | private Collection<FlowRule> retryFlows; |
| 1883 | private ForwardingObjective fwd; |
| 1884 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1885 | RetryFlows(ForwardingObjective fwd, Collection<FlowRule> retryFlows) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1886 | this.fwd = fwd; |
| 1887 | this.retryFlows = retryFlows; |
| 1888 | } |
| 1889 | |
| 1890 | @Override |
| 1891 | public void run() { |
| 1892 | log.info("RETRY FLOWS ATTEMPT# {} for fwd:{} rules:{}", |
| 1893 | MAX_RETRY_ATTEMPTS - attempts, fwd.id(), retryFlows.size()); |
| 1894 | sendForward(fwd, retryFlows); |
| 1895 | if (--attempts > 0) { |
| 1896 | executorService.schedule(this, RETRY_MS, TimeUnit.MILLISECONDS); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1901 | } |