Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -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 | |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 17 | package org.onosproject.pipelines.fabric.impl.behaviour; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.MacAddress; |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 23 | import org.onlab.packet.MplsLabel; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 24 | import org.onlab.packet.VlanId; |
| 25 | import org.onlab.util.ImmutableByteSequence; |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 30 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 31 | import org.onosproject.net.packet.OutboundPacket; |
| 32 | import org.onosproject.net.pi.model.PiPacketOperationType; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 33 | import org.onosproject.net.pi.runtime.PiAction; |
| 34 | import org.onosproject.net.pi.runtime.PiActionParam; |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 35 | import org.onosproject.net.pi.runtime.PiPacketMetadata; |
| 36 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | 2102bfb | 2020-12-04 16:54:24 -0800 | [diff] [blame] | 37 | import org.onosproject.pipelines.fabric.FabricConstants; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 38 | |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 39 | import java.nio.ByteBuffer; |
| 40 | import java.util.Collection; |
| 41 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 42 | import static org.easymock.EasyMock.createNiceMock; |
| 43 | import static org.easymock.EasyMock.expect; |
| 44 | import static org.easymock.EasyMock.replay; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 45 | import static org.junit.Assert.assertEquals; |
| 46 | |
| 47 | /** |
| 48 | * Test for fabric interpreter. |
| 49 | */ |
| 50 | public class FabricInterpreterTest { |
| 51 | private static final VlanId VLAN_100 = VlanId.vlanId("100"); |
| 52 | private static final PortNumber PORT_1 = PortNumber.portNumber(1); |
| 53 | private static final MacAddress SRC_MAC = MacAddress.valueOf("00:00:00:00:00:01"); |
| 54 | private static final MacAddress DST_MAC = MacAddress.valueOf("00:00:00:00:00:02"); |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 55 | private static final MplsLabel MPLS_10 = MplsLabel.mplsLabel(10); |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 56 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("device:1"); |
| 57 | private static final int PORT_BITWIDTH = 9; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 58 | |
| 59 | private FabricInterpreter interpreter; |
| 60 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 61 | FabricCapabilities allCapabilities; |
| 62 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 63 | @Before |
| 64 | public void setup() { |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 65 | allCapabilities = createNiceMock(FabricCapabilities.class); |
| 66 | expect(allCapabilities.hasHashedTable()).andReturn(true).anyTimes(); |
| 67 | expect(allCapabilities.supportDoubleVlanTerm()).andReturn(true).anyTimes(); |
| 68 | replay(allCapabilities); |
| 69 | interpreter = new FabricInterpreter(allCapabilities); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* Filtering control block */ |
| 73 | |
| 74 | /** |
| 75 | * Map treatment to push_internal_vlan action. |
| 76 | */ |
| 77 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 78 | public void testFilteringTreatmentPermitWithInternalVlan() throws Exception { |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 79 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 80 | .pushVlan() |
| 81 | .setVlanId(VLAN_100) |
| 82 | .build(); |
| 83 | PiAction mappedAction = interpreter.mapTreatment(treatment, |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 84 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 85 | PiActionParam param = new PiActionParam(FabricConstants.VLAN_ID, |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 86 | ImmutableByteSequence.copyFrom(VLAN_100.toShort())); |
| 87 | PiAction expectedAction = PiAction.builder() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 88 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 89 | .withParameter(param) |
| 90 | .build(); |
| 91 | |
| 92 | assertEquals(expectedAction, mappedAction); |
| 93 | } |
| 94 | |
| 95 | /** |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 96 | * Map empty treatment to permit action. |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 97 | */ |
| 98 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 99 | public void testFilteringTreatmentPermit() throws Exception { |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 100 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
| 101 | PiAction mappedAction = interpreter.mapTreatment(treatment, |
Yi Tseng | 43ee7e8 | 2018-04-12 16:37:34 +0800 | [diff] [blame] | 102 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 103 | PiAction expectedAction = PiAction.builder() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 104 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 105 | .build(); |
| 106 | |
| 107 | assertEquals(expectedAction, mappedAction); |
| 108 | } |
| 109 | |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 110 | /** |
| 111 | * Map empty treatment and wipeDeferred to permit action. |
| 112 | */ |
| 113 | @Test |
| 114 | public void testFilteringTreatmentPermit2() throws Exception { |
| 115 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 116 | .wipeDeferred() |
| 117 | .build(); |
| 118 | PiAction mappedAction = interpreter.mapTreatment(treatment, |
| 119 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
| 120 | PiAction expectedAction = PiAction.builder() |
| 121 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) |
| 122 | .build(); |
| 123 | |
| 124 | assertEquals(expectedAction, mappedAction); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Map popVlan to permit action. |
| 129 | */ |
| 130 | @Test |
| 131 | public void testFilteringTreatmentPermit3() throws Exception { |
| 132 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 133 | .popVlan() |
| 134 | .build(); |
| 135 | PiAction mappedAction = interpreter.mapTreatment(treatment, |
| 136 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); |
| 137 | PiAction expectedAction = PiAction.builder() |
| 138 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) |
| 139 | .build(); |
| 140 | |
| 141 | assertEquals(expectedAction, mappedAction); |
| 142 | } |
| 143 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 144 | /* Forwarding control block */ |
| 145 | |
| 146 | /** |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 147 | * Map empty treatment for routing v4 table. |
Yi Tseng | df3eec5 | 2018-02-15 14:56:02 -0800 | [diff] [blame] | 148 | */ |
| 149 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 150 | public void testRoutingV4TreatmentEmpty() throws Exception { |
Yi Tseng | df3eec5 | 2018-02-15 14:56:02 -0800 | [diff] [blame] | 151 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 152 | PiAction mappedAction = interpreter.mapTreatment( |
| 153 | treatment, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4); |
Charles Chan | cf696e5 | 2018-08-16 16:25:13 -0700 | [diff] [blame] | 154 | PiAction expectedAction = PiAction.builder() |
Charles Chan | cd03f07 | 2018-08-31 17:46:37 -0700 | [diff] [blame] | 155 | .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4) |
Charles Chan | cf696e5 | 2018-08-16 16:25:13 -0700 | [diff] [blame] | 156 | .build(); |
| 157 | assertEquals(expectedAction, mappedAction); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 158 | } |
Charles Chan | cf696e5 | 2018-08-16 16:25:13 -0700 | [diff] [blame] | 159 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 160 | /** |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 161 | * Map empty treatment to NOP for ACL table. |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 162 | */ |
| 163 | @Test |
| 164 | public void testAclTreatmentEmpty() throws Exception { |
| 165 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
| 166 | PiAction mappedAction = interpreter.mapTreatment( |
| 167 | treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL); |
| 168 | PiAction expectedAction = PiAction.builder() |
| 169 | .withId(FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL) |
Charles Chan | cf696e5 | 2018-08-16 16:25:13 -0700 | [diff] [blame] | 170 | .build(); |
| 171 | assertEquals(expectedAction, mappedAction); |
Yi Tseng | df3eec5 | 2018-02-15 14:56:02 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 174 | /** |
| 175 | * Map wipeDeferred treatment to DROP for ACL table. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testAclTreatmentWipeDeferred() throws Exception { |
| 179 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 180 | .wipeDeferred() |
| 181 | .build(); |
| 182 | PiAction mappedAction = interpreter.mapTreatment( |
| 183 | treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL); |
| 184 | PiAction expectedAction = PiAction.builder() |
| 185 | .withId(FabricConstants.FABRIC_INGRESS_ACL_DROP) |
| 186 | .build(); |
| 187 | assertEquals(expectedAction, mappedAction); |
| 188 | } |
| 189 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 190 | /* Next control block */ |
| 191 | |
| 192 | /** |
| 193 | * Map treatment to output action. |
| 194 | */ |
| 195 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 196 | public void testNextTreatmentSimpleOutput() throws Exception { |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 197 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 198 | .setOutput(PORT_1) |
| 199 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 200 | PiAction mappedAction = interpreter.mapTreatment( |
| 201 | treatment, FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE); |
| 202 | PiActionParam param = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong()); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 203 | PiAction expectedAction = PiAction.builder() |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 204 | .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 205 | .withParameter(param) |
| 206 | .build(); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 207 | assertEquals(expectedAction, mappedAction); |
| 208 | } |
| 209 | |
| 210 | /** |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 211 | * Map treatment for hashed table to routing v4 action. |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 212 | */ |
| 213 | @Test |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 214 | public void testNextTreatmentHashedRoutingV4() throws Exception { |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 215 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 216 | .setEthSrc(SRC_MAC) |
| 217 | .setEthDst(DST_MAC) |
| 218 | .setOutput(PORT_1) |
| 219 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 220 | PiAction mappedAction = interpreter.mapTreatment( |
| 221 | treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED); |
| 222 | PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes()); |
| 223 | PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes()); |
| 224 | PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong()); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 225 | PiAction expectedAction = PiAction.builder() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 226 | .withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 227 | .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam)) |
| 228 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 229 | assertEquals(expectedAction, mappedAction); |
| 230 | } |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 231 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 232 | /** |
| 233 | * Map treatment for hashed table to routing v4 action. |
| 234 | */ |
| 235 | @Test |
| 236 | public void testNextTreatmentHashedRoutingMpls() throws Exception { |
| 237 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 238 | .setEthSrc(SRC_MAC) |
| 239 | .setEthDst(DST_MAC) |
| 240 | .setOutput(PORT_1) |
| 241 | .pushMpls() |
| 242 | .setMpls(MPLS_10) |
| 243 | .build(); |
| 244 | PiAction mappedAction = interpreter.mapTreatment( |
| 245 | treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED); |
| 246 | PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes()); |
| 247 | PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes()); |
| 248 | PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong()); |
| 249 | PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt()); |
| 250 | PiAction expectedAction = PiAction.builder() |
| 251 | .withId(FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_HASHED) |
| 252 | .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam, mplsParam)) |
| 253 | .build(); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 254 | assertEquals(expectedAction, mappedAction); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Map treatment to set_vlan_output action. |
| 259 | */ |
| 260 | @Test |
| 261 | public void testNextTreatment3() throws Exception { |
| 262 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 263 | .setVlanId(VLAN_100) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 264 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 265 | PiAction mappedAction = interpreter.mapTreatment( |
| 266 | treatment, FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN); |
| 267 | PiActionParam vlanParam = new PiActionParam( |
| 268 | FabricConstants.VLAN_ID, VLAN_100.toShort()); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 269 | PiAction expectedAction = PiAction.builder() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 270 | .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN) |
| 271 | .withParameter(vlanParam) |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 272 | .build(); |
| 273 | assertEquals(expectedAction, mappedAction); |
| 274 | } |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 275 | |
| 276 | @Test |
| 277 | public void testMapOutboundPacketWithoutForwarding() |
| 278 | throws Exception { |
| 279 | PortNumber outputPort = PortNumber.portNumber(1); |
| 280 | TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder() |
| 281 | .setOutput(outputPort) |
| 282 | .build(); |
| 283 | ByteBuffer data = ByteBuffer.allocate(64); |
| 284 | OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data); |
| 285 | Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt); |
| 286 | assertEquals(result.size(), 1); |
| 287 | |
| 288 | ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder(); |
| 289 | builder.add(PiPacketMetadata.builder() |
| 290 | .withId(FabricConstants.EGRESS_PORT) |
| 291 | .withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()) |
| 292 | .fit(PORT_BITWIDTH)) |
| 293 | .build()); |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 294 | |
| 295 | PiPacketOperation expectedPktOp = PiPacketOperation.builder() |
| 296 | .withType(PiPacketOperationType.PACKET_OUT) |
| 297 | .withData(ImmutableByteSequence.copyFrom(data)) |
| 298 | .withMetadatas(builder.build()) |
| 299 | .build(); |
| 300 | |
| 301 | assertEquals(expectedPktOp, result.iterator().next()); |
| 302 | } |
| 303 | |
| 304 | @Test |
| 305 | public void testMapOutboundPacketWithForwarding() |
| 306 | throws Exception { |
| 307 | PortNumber outputPort = PortNumber.TABLE; |
| 308 | TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder() |
| 309 | .setOutput(outputPort) |
| 310 | .build(); |
| 311 | ByteBuffer data = ByteBuffer.allocate(64); |
| 312 | OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data); |
| 313 | Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt); |
| 314 | assertEquals(result.size(), 1); |
| 315 | |
| 316 | ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder(); |
| 317 | builder.add(PiPacketMetadata.builder() |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 318 | .withId(FabricConstants.DO_FORWARDING) |
| 319 | .withValue(ImmutableByteSequence.copyFrom(1) |
| 320 | .fit(1)) |
| 321 | .build()); |
| 322 | |
| 323 | PiPacketOperation expectedPktOp = PiPacketOperation.builder() |
| 324 | .withType(PiPacketOperationType.PACKET_OUT) |
| 325 | .withData(ImmutableByteSequence.copyFrom(data)) |
| 326 | .withMetadatas(builder.build()) |
| 327 | .build(); |
| 328 | |
| 329 | assertEquals(expectedPktOp, result.iterator().next()); |
| 330 | } |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 331 | } |