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