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