Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.pipelines.fabric.pipeliner; |
| 18 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 19 | import org.junit.Before; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.Ethernet; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onlab.util.ImmutableByteSequence; |
| 25 | import org.onosproject.net.PortNumber; |
| 26 | import org.onosproject.net.flow.DefaultFlowRule; |
| 27 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 29 | import org.onosproject.net.flow.FlowRule; |
| 30 | import org.onosproject.net.flow.TableId; |
| 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
| 33 | import org.onosproject.net.flow.criteria.Criteria; |
| 34 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 35 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 36 | import org.onosproject.net.flowobjective.ObjectiveError; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 37 | import org.onosproject.net.pi.runtime.PiAction; |
| 38 | import org.onosproject.net.pi.runtime.PiActionParam; |
| 39 | import org.onosproject.pipelines.fabric.FabricConstants; |
| 40 | |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 41 | import static org.junit.Assert.assertEquals; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Test cases for fabric.p4 pipeline filtering control block. |
| 45 | */ |
| 46 | public class FabricFilteringPipelinerTest extends FabricPipelinerTest { |
| 47 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 48 | private FilteringObjectiveTranslator translator; |
| 49 | |
| 50 | @Before |
| 51 | public void setup() { |
| 52 | super.doSetup(); |
| 53 | translator = new FilteringObjectiveTranslator(DEVICE_ID, capabilitiesHashed); |
| 54 | } |
| 55 | |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Creates one rule for ingress_port_vlan table and 3 rules for |
| 58 | * fwd_classifier table (IPv4, IPv6 and MPLS unicast) when |
| 59 | * the condition is VLAN + MAC. |
| 60 | */ |
| 61 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 62 | public void testRouterMacAndVlanFilter() throws FabricPipelinerException { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 63 | FilteringObjective filteringObjective = buildFilteringObjective(ROUTER_MAC); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 64 | ObjectiveTranslation actualTranslation = translator.translate(filteringObjective); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 65 | |
| 66 | // in port vlan flow rule |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 67 | FlowRule inportFlowRuleExpected = |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 68 | buildExpectedVlanInPortRule(PORT_1, |
| 69 | VlanId.NONE, |
| 70 | VLAN_100, |
| 71 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 72 | |
| 73 | // forwarding classifier ipv4 |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 74 | FlowRule classifierV4FlowRuleExpected = buildExpectedFwdClassifierRule(PORT_1, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 75 | ROUTER_MAC, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 76 | null, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 77 | Ethernet.TYPE_IPV4, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 78 | FilteringObjectiveTranslator.FWD_IPV4_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 79 | |
| 80 | // forwarding classifier ipv6 |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 81 | FlowRule classifierV6FlowRuleExpected = buildExpectedFwdClassifierRule(PORT_1, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 82 | ROUTER_MAC, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 83 | null, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 84 | Ethernet.TYPE_IPV6, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 85 | FilteringObjectiveTranslator.FWD_IPV6_ROUTING); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 86 | |
| 87 | // forwarding classifier mpls |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 88 | FlowRule classifierMplsFlowRuleExpected = buildExpectedFwdClassifierRule(PORT_1, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 89 | ROUTER_MAC, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 90 | null, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 91 | Ethernet.MPLS_UNICAST, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 92 | FilteringObjectiveTranslator.FWD_MPLS); |
| 93 | |
| 94 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder() |
| 95 | .addFlowRule(inportFlowRuleExpected) |
| 96 | .addFlowRule(classifierV4FlowRuleExpected) |
| 97 | .addFlowRule(classifierV6FlowRuleExpected) |
| 98 | .addFlowRule(classifierMplsFlowRuleExpected) |
| 99 | .build(); |
| 100 | |
| 101 | assertEquals(expectedTranslation, actualTranslation); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Creates one rule for ingress_port_vlan table and one rule for |
| 106 | * fwd_classifier table (IPv4 multicast) when the condition is ipv4 |
| 107 | * multicast mac address. |
| 108 | */ |
| 109 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 110 | public void testIpv4MulticastFwdClass() throws FabricPipelinerException { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 111 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 112 | .pushVlan() |
| 113 | .setVlanId(VLAN_100) |
| 114 | .build(); |
| 115 | FilteringObjective filteringObjective = DefaultFilteringObjective.builder() |
| 116 | .permit() |
| 117 | .withPriority(PRIORITY) |
| 118 | .withKey(Criteria.matchInPort(PORT_1)) |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 119 | .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, MacAddress.IPV4_MULTICAST_MASK)) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 120 | .addCondition(Criteria.matchVlanId(VlanId.NONE)) |
| 121 | .withMeta(treatment) |
| 122 | .fromApp(APP_ID) |
| 123 | .makePermanent() |
| 124 | .add(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 125 | ObjectiveTranslation actualTranslation = translator.translate(filteringObjective); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 126 | |
| 127 | // in port vlan flow rule |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 128 | FlowRule inportFlowRuleExpected = |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 129 | buildExpectedVlanInPortRule(PORT_1, |
| 130 | VlanId.NONE, |
| 131 | VLAN_100, |
| 132 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 133 | |
| 134 | // forwarding classifier |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 135 | FlowRule classifierFlowRuleExpected = buildExpectedFwdClassifierRule(PORT_1, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 136 | MacAddress.IPV4_MULTICAST, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 137 | MacAddress.IPV4_MULTICAST_MASK, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 138 | Ethernet.TYPE_IPV4, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 139 | FilteringObjectiveTranslator.FWD_IPV4_ROUTING); |
| 140 | |
| 141 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder() |
| 142 | .addFlowRule(inportFlowRuleExpected) |
| 143 | .addFlowRule(classifierFlowRuleExpected) |
| 144 | .build(); |
| 145 | |
| 146 | assertEquals(expectedTranslation, actualTranslation); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Creates one rule for ingress_port_vlan table and one rule for |
| 151 | * fwd_classifier table (IPv6 multicast) when the condition is ipv6 |
| 152 | * multicast mac address. |
| 153 | */ |
| 154 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 155 | public void testIpv6MulticastFwdClass() throws FabricPipelinerException { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 156 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 157 | .pushVlan() |
| 158 | .setVlanId(VLAN_100) |
| 159 | .build(); |
| 160 | FilteringObjective filteringObjective = DefaultFilteringObjective.builder() |
| 161 | .permit() |
| 162 | .withPriority(PRIORITY) |
| 163 | .withKey(Criteria.matchInPort(PORT_1)) |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 164 | .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV6_MULTICAST, MacAddress.IPV6_MULTICAST_MASK)) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 165 | .addCondition(Criteria.matchVlanId(VlanId.NONE)) |
| 166 | .withMeta(treatment) |
| 167 | .fromApp(APP_ID) |
| 168 | .makePermanent() |
| 169 | .add(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 170 | ObjectiveTranslation actualTranslation = translator.translate(filteringObjective); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 171 | |
| 172 | // in port vlan flow rule |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 173 | FlowRule inportFlowRuleExpected = |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 174 | buildExpectedVlanInPortRule(PORT_1, |
| 175 | VlanId.NONE, |
| 176 | VLAN_100, |
| 177 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 178 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 179 | FlowRule classifierFlowRuleExpected = buildExpectedFwdClassifierRule(PORT_1, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 180 | MacAddress.IPV6_MULTICAST, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 181 | MacAddress.IPV6_MULTICAST_MASK, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 182 | Ethernet.TYPE_IPV6, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 183 | FilteringObjectiveTranslator.FWD_IPV6_ROUTING); |
| 184 | |
| 185 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder() |
| 186 | .addFlowRule(inportFlowRuleExpected) |
| 187 | .addFlowRule(classifierFlowRuleExpected) |
| 188 | .build(); |
| 189 | |
| 190 | assertEquals(expectedTranslation, actualTranslation); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Creates only one rule for ingress_port_vlan table if there is no condition |
| 195 | * of destination mac address. |
| 196 | * The packet will be handled by bridging table by default. |
| 197 | */ |
| 198 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 199 | public void testFwdBridging() throws Exception { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 200 | FilteringObjective filteringObjective = buildFilteringObjective(null); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 201 | ObjectiveTranslation actualTranslation = translator.translate(filteringObjective); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 202 | |
| 203 | // in port vlan flow rule |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 204 | FlowRule flowRuleExpected = |
| 205 | buildExpectedVlanInPortRule(PORT_1, |
| 206 | VlanId.NONE, |
| 207 | VLAN_100, |
| 208 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 209 | |
| 210 | // No rules in forwarding classifier, will do default action: set fwd type to bridging |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 211 | |
| 212 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder() |
| 213 | .addFlowRule(flowRuleExpected) |
| 214 | .build(); |
| 215 | |
| 216 | assertEquals(expectedTranslation, actualTranslation); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 220 | * Test DENY objective. |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 221 | */ |
| 222 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 223 | public void testDenyObjective() throws FabricPipelinerException { |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 224 | FilteringObjective filteringObjective = DefaultFilteringObjective.builder() |
| 225 | .deny() |
| 226 | .withKey(Criteria.matchInPort(PORT_1)) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 227 | .addCondition(Criteria.matchVlanId(VlanId.NONE)) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 228 | .fromApp(APP_ID) |
| 229 | .makePermanent() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 230 | .withPriority(PRIORITY) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 231 | .add(); |
| 232 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 233 | ObjectiveTranslation actualTranslation = translator.translate(filteringObjective); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 234 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 235 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 236 | .matchInPort(PORT_1) |
| 237 | .matchPi(VLAN_INVALID); |
| 238 | PiAction piAction = PiAction.builder() |
| 239 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_DENY) |
| 240 | .build(); |
| 241 | FlowRule expectedFlowRule = DefaultFlowRule.builder() |
| 242 | .withPriority(PRIORITY) |
| 243 | .withSelector(selector.build()) |
| 244 | .withTreatment(DefaultTrafficTreatment.builder() |
| 245 | .piTableAction(piAction).build()) |
| 246 | .fromApp(APP_ID) |
| 247 | .forDevice(DEVICE_ID) |
| 248 | .makePermanent() |
| 249 | .forTable(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN) |
| 250 | .build(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 251 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 252 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder() |
| 253 | .addFlowRule(expectedFlowRule) |
| 254 | .build(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 255 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 256 | assertEquals(expectedTranslation, actualTranslation); |
| 257 | |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Incorrect filtering key or filtering conditions test. |
| 262 | */ |
| 263 | @Test |
| 264 | public void badParamTest() { |
| 265 | // Filtering objective should contains filtering key |
| 266 | FilteringObjective filteringObjective = DefaultFilteringObjective.builder() |
| 267 | .permit() |
| 268 | .addCondition(Criteria.matchVlanId(VLAN_100)) |
| 269 | .fromApp(APP_ID) |
| 270 | .makePermanent() |
| 271 | .add(); |
| 272 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 273 | ObjectiveTranslation result1 = translator.translate(filteringObjective); |
| 274 | assertError(ObjectiveError.BADPARAMS, result1); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 275 | |
| 276 | // Filtering objective should use in_port as key |
| 277 | filteringObjective = DefaultFilteringObjective.builder() |
| 278 | .permit() |
| 279 | .withKey(Criteria.matchEthDst(ROUTER_MAC)) |
| 280 | .addCondition(Criteria.matchVlanId(VLAN_100)) |
| 281 | .withMeta(DefaultTrafficTreatment.emptyTreatment()) |
| 282 | .fromApp(APP_ID) |
| 283 | .makePermanent() |
| 284 | .add(); |
| 285 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 286 | ObjectiveTranslation result2 = translator.translate(filteringObjective); |
| 287 | assertError(ObjectiveError.BADPARAMS, result2); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* Utilities */ |
| 291 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 292 | private void assertError(ObjectiveError error, ObjectiveTranslation actualTranslation) { |
| 293 | ObjectiveTranslation expectedTranslation = ObjectiveTranslation.ofError(error); |
| 294 | assertEquals(expectedTranslation, actualTranslation); |
| 295 | } |
| 296 | |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 297 | private FilteringObjective buildFilteringObjective(MacAddress dstMac) { |
| 298 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 299 | .pushVlan() |
| 300 | .setVlanId(VLAN_100) |
| 301 | .build(); |
| 302 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder() |
| 303 | .permit() |
| 304 | .withPriority(PRIORITY) |
| 305 | .withKey(Criteria.matchInPort(PORT_1)); |
| 306 | if (dstMac != null) { |
| 307 | builder.addCondition(Criteria.matchEthDst(dstMac)); |
| 308 | } |
| 309 | |
| 310 | builder.addCondition(Criteria.matchVlanId(VlanId.NONE)) |
| 311 | .withMeta(treatment) |
| 312 | .fromApp(APP_ID) |
| 313 | .makePermanent(); |
| 314 | return builder.add(); |
| 315 | } |
| 316 | |
| 317 | private FlowRule buildExpectedVlanInPortRule(PortNumber inPort, VlanId vlanId, |
| 318 | VlanId internalVlan, |
| 319 | TableId tableId) { |
| 320 | |
| 321 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 322 | .matchInPort(inPort); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 323 | PiAction piAction; |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 324 | if (vlanId == null || vlanId.equals(VlanId.NONE)) { |
| 325 | selector.matchPi(VLAN_INVALID); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 326 | piAction = PiAction.builder() |
| 327 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN) |
| 328 | .withParameter(new PiActionParam( |
| 329 | FabricConstants.VLAN_ID, internalVlan.toShort())) |
| 330 | .build(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 331 | } else { |
| 332 | selector.matchPi(VLAN_VALID); |
| 333 | selector.matchVlanId(vlanId); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 334 | piAction = PiAction.builder() |
| 335 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) |
| 336 | .build(); |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return DefaultFlowRule.builder() |
| 340 | .withPriority(PRIORITY) |
| 341 | .withSelector(selector.build()) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 342 | .withTreatment(DefaultTrafficTreatment.builder() |
| 343 | .piTableAction(piAction).build()) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 344 | .fromApp(APP_ID) |
| 345 | .forDevice(DEVICE_ID) |
| 346 | .makePermanent() |
| 347 | .forTable(tableId) |
| 348 | .build(); |
| 349 | } |
| 350 | |
| 351 | private FlowRule buildExpectedFwdClassifierRule(PortNumber inPort, |
| 352 | MacAddress dstMac, |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 353 | MacAddress dstMacMask, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 354 | short ethType, |
| 355 | byte fwdClass) { |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 356 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 357 | .matchInPort(inPort) |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 358 | .matchEthType(ethType); |
| 359 | if (dstMacMask != null) { |
| 360 | sbuilder.matchEthDstMasked(dstMac, dstMacMask); |
| 361 | } else { |
| 362 | sbuilder.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK); |
| 363 | } |
| 364 | TrafficSelector selector = sbuilder.build(); |
| 365 | |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 366 | PiActionParam classParam = new PiActionParam(FabricConstants.FWD_TYPE, |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 367 | ImmutableByteSequence.copyFrom(fwdClass)); |
| 368 | PiAction fwdClassifierAction = PiAction.builder() |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 369 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 370 | .withParameter(classParam) |
| 371 | .build(); |
| 372 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 373 | .piTableAction(fwdClassifierAction) |
| 374 | .build(); |
| 375 | |
| 376 | return DefaultFlowRule.builder() |
| 377 | .withPriority(PRIORITY) |
| 378 | .withSelector(selector) |
| 379 | .withTreatment(treatment) |
| 380 | .fromApp(APP_ID) |
| 381 | .forDevice(DEVICE_ID) |
| 382 | .makePermanent() |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 383 | .forTable(FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER) |
Yi Tseng | 0b80972 | 2017-11-03 10:23:26 -0700 | [diff] [blame] | 384 | .build(); |
| 385 | } |
| 386 | } |