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