Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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.impl.behaviour.upf; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.behaviour.upf.ForwardingActionRule; |
| 21 | import org.onosproject.net.behaviour.upf.PacketDetectionRule; |
| 22 | import org.onosproject.net.behaviour.upf.UpfInterface; |
| 23 | import org.onosproject.net.behaviour.upf.UpfProgrammableException; |
| 24 | import org.onosproject.net.flow.FlowRule; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.equalTo; |
| 28 | |
| 29 | public class FabricUpfTranslatorTest { |
| 30 | |
| 31 | private final FabricUpfTranslator upfTranslator = new FabricUpfTranslator(TestDistributedFabricUpfStore.build()); |
| 32 | |
| 33 | @Test |
| 34 | public void fabricEntryToUplinkPdrTest() { |
| 35 | PacketDetectionRule expectedPdr = TestUpfConstants.UPLINK_PDR; |
| 36 | PacketDetectionRule translatedPdr; |
| 37 | try { |
| 38 | translatedPdr = upfTranslator.fabricEntryToPdr(TestUpfConstants.FABRIC_UPLINK_PDR); |
| 39 | } catch (UpfProgrammableException e) { |
| 40 | assertThat("Fabric uplink PDR should translate to abstract PDR without error.", false); |
| 41 | return; |
| 42 | } |
| 43 | assertThat("Translated PDR should be uplink.", translatedPdr.matchesEncapped()); |
| 44 | assertThat(translatedPdr, equalTo(expectedPdr)); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void fabricEntryToUplinkPriorityPdrTest() { |
| 49 | PacketDetectionRule expectedPdr = TestUpfConstants.UPLINK_PRIORITY_PDR; |
| 50 | PacketDetectionRule translatedPdr; |
| 51 | try { |
| 52 | translatedPdr = upfTranslator.fabricEntryToPdr(TestUpfConstants.FABRIC_UPLINK_PRIORITY_PDR); |
| 53 | } catch (UpfProgrammableException e) { |
| 54 | assertThat("Fabric uplink PDR should translate to abstract PDR without error.", false); |
| 55 | return; |
| 56 | } |
| 57 | assertThat("Translated PDR should be uplink.", translatedPdr.matchesEncapped()); |
| 58 | assertThat(translatedPdr, equalTo(expectedPdr)); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void fabricEntryToDownlinkPdrTest() { |
| 63 | PacketDetectionRule expectedPdr = TestUpfConstants.DOWNLINK_PDR; |
| 64 | PacketDetectionRule translatedPdr; |
| 65 | try { |
| 66 | translatedPdr = upfTranslator.fabricEntryToPdr(TestUpfConstants.FABRIC_DOWNLINK_PDR); |
| 67 | } catch (UpfProgrammableException e) { |
| 68 | assertThat("Fabric downlink PDR should translate to abstract PDR without error.", false); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | assertThat("Translated PDR should be downlink.", translatedPdr.matchesUnencapped()); |
| 73 | assertThat(translatedPdr, equalTo(expectedPdr)); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void fabricEntryToDownlinkPriorityPdrTest() { |
| 78 | PacketDetectionRule expectedPdr = TestUpfConstants.DOWNLINK_PRIORITY_PDR; |
| 79 | PacketDetectionRule translatedPdr; |
| 80 | try { |
| 81 | translatedPdr = upfTranslator.fabricEntryToPdr(TestUpfConstants.FABRIC_DOWNLINK_PRIORITY_PDR); |
| 82 | } catch (UpfProgrammableException e) { |
| 83 | assertThat("Fabric downlink PDR should translate to abstract PDR without error.", false); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | assertThat("Translated PDR should be downlink.", translatedPdr.matchesUnencapped()); |
| 88 | assertThat(translatedPdr, equalTo(expectedPdr)); |
| 89 | } |
| 90 | |
| 91 | @Test |
| 92 | public void fabricEntryToUplinkFarTest() { |
| 93 | ForwardingActionRule translatedFar; |
| 94 | ForwardingActionRule expectedFar = TestUpfConstants.UPLINK_FAR; |
| 95 | try { |
| 96 | translatedFar = upfTranslator.fabricEntryToFar(TestUpfConstants.FABRIC_UPLINK_FAR); |
| 97 | } catch (UpfProgrammableException e) { |
| 98 | assertThat("Fabric uplink FAR should correctly translate to abstract FAR without error", |
| 99 | false); |
| 100 | return; |
| 101 | } |
| 102 | assertThat("Translated FAR should be uplink.", translatedFar.forwards()); |
| 103 | assertThat(translatedFar, equalTo(expectedFar)); |
| 104 | } |
| 105 | |
| 106 | @Test |
| 107 | public void fabricEntryToDownlinkFarTest() { |
| 108 | ForwardingActionRule translatedFar; |
| 109 | ForwardingActionRule expectedFar = TestUpfConstants.DOWNLINK_FAR; |
| 110 | try { |
| 111 | translatedFar = upfTranslator.fabricEntryToFar(TestUpfConstants.FABRIC_DOWNLINK_FAR); |
| 112 | } catch (UpfProgrammableException e) { |
| 113 | assertThat("Fabric downlink FAR should correctly translate to abstract FAR without error", |
| 114 | false); |
| 115 | return; |
| 116 | } |
| 117 | assertThat("Translated FAR should be downlink.", translatedFar.encaps()); |
| 118 | assertThat(translatedFar, equalTo(expectedFar)); |
| 119 | } |
| 120 | |
| 121 | @Test |
| 122 | public void fabricEntryToUplinkInterfaceTest() { |
| 123 | UpfInterface translatedInterface; |
| 124 | UpfInterface expectedInterface = TestUpfConstants.UPLINK_INTERFACE; |
| 125 | try { |
| 126 | translatedInterface = upfTranslator.fabricEntryToInterface(TestUpfConstants.FABRIC_UPLINK_INTERFACE); |
| 127 | } catch (UpfProgrammableException e) { |
| 128 | assertThat("Fabric uplink interface should correctly translate to abstract interface without error", |
| 129 | false); |
| 130 | return; |
| 131 | } |
| 132 | assertThat("Translated interface should be uplink.", translatedInterface.isAccess()); |
| 133 | assertThat(translatedInterface, equalTo(expectedInterface)); |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void fabricEntryToDownlinkInterfaceTest() { |
| 138 | UpfInterface translatedInterface; |
| 139 | UpfInterface expectedInterface = TestUpfConstants.DOWNLINK_INTERFACE; |
| 140 | try { |
| 141 | translatedInterface = upfTranslator.fabricEntryToInterface(TestUpfConstants.FABRIC_DOWNLINK_INTERFACE); |
| 142 | } catch (UpfProgrammableException e) { |
| 143 | assertThat("Fabric downlink interface should correctly translate to abstract interface without error", |
| 144 | false); |
| 145 | return; |
| 146 | } |
| 147 | assertThat("Translated interface should be downlink.", translatedInterface.isCore()); |
| 148 | assertThat(translatedInterface, equalTo(expectedInterface)); |
| 149 | } |
| 150 | |
| 151 | @Test |
| 152 | public void uplinkInterfaceToFabricEntryTest() { |
| 153 | FlowRule translatedRule; |
| 154 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_INTERFACE; |
| 155 | try { |
| 156 | translatedRule = upfTranslator.interfaceToFabricEntry(TestUpfConstants.UPLINK_INTERFACE, |
| 157 | TestUpfConstants.DEVICE_ID, |
| 158 | TestUpfConstants.APP_ID, |
| 159 | TestUpfConstants.DEFAULT_PRIORITY); |
| 160 | } catch (UpfProgrammableException e) { |
| 161 | assertThat("Abstract uplink interface should correctly translate to Fabric interface without error", |
| 162 | false); |
| 163 | return; |
| 164 | } |
| 165 | assertThat(translatedRule, equalTo(expectedRule)); |
| 166 | } |
| 167 | |
| 168 | @Test |
| 169 | public void downlinkInterfaceToFabricEntryTest() { |
| 170 | FlowRule translatedRule; |
| 171 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_INTERFACE; |
| 172 | try { |
| 173 | translatedRule = upfTranslator.interfaceToFabricEntry(TestUpfConstants.DOWNLINK_INTERFACE, |
| 174 | TestUpfConstants.DEVICE_ID, |
| 175 | TestUpfConstants.APP_ID, |
| 176 | TestUpfConstants.DEFAULT_PRIORITY); |
| 177 | } catch (UpfProgrammableException e) { |
| 178 | assertThat("Abstract downlink interface should correctly translate to Fabric interface without error", |
| 179 | false); |
| 180 | return; |
| 181 | } |
| 182 | assertThat(translatedRule, equalTo(expectedRule)); |
| 183 | } |
| 184 | |
| 185 | @Test |
| 186 | public void downlinkPdrToFabricEntryTest() { |
| 187 | FlowRule translatedRule; |
| 188 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_PDR; |
| 189 | try { |
| 190 | translatedRule = upfTranslator.pdrToFabricEntry(TestUpfConstants.DOWNLINK_PDR, |
| 191 | TestUpfConstants.DEVICE_ID, |
| 192 | TestUpfConstants.APP_ID, |
| 193 | TestUpfConstants.DEFAULT_PRIORITY); |
| 194 | } catch (UpfProgrammableException e) { |
| 195 | assertThat("Abstract downlink PDR should correctly translate to Fabric PDR without error", |
| 196 | false); |
| 197 | return; |
| 198 | } |
| 199 | assertThat(translatedRule, equalTo(expectedRule)); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void downlinkPdrToFabricPriorityEntryTest() { |
| 204 | FlowRule translatedRule; |
| 205 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_PRIORITY_PDR; |
| 206 | try { |
| 207 | translatedRule = upfTranslator.pdrToFabricEntry(TestUpfConstants.DOWNLINK_PRIORITY_PDR, |
| 208 | TestUpfConstants.DEVICE_ID, |
| 209 | TestUpfConstants.APP_ID, |
| 210 | TestUpfConstants.DEFAULT_PRIORITY); |
| 211 | } catch (UpfProgrammableException e) { |
| 212 | assertThat("Abstract downlink PDR should correctly translate to Fabric PDR without error", |
| 213 | false); |
| 214 | return; |
| 215 | } |
| 216 | assertThat(translatedRule, equalTo(expectedRule)); |
| 217 | } |
| 218 | |
| 219 | @Test |
| 220 | public void uplinkFarToFabricEntryTest() { |
| 221 | FlowRule translatedRule; |
| 222 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_FAR; |
| 223 | try { |
| 224 | translatedRule = upfTranslator.farToFabricEntry(TestUpfConstants.UPLINK_FAR, |
| 225 | TestUpfConstants.DEVICE_ID, |
| 226 | TestUpfConstants.APP_ID, |
| 227 | TestUpfConstants.DEFAULT_PRIORITY); |
| 228 | } catch (UpfProgrammableException e) { |
| 229 | assertThat("Abstract uplink FAR should correctly translate to Fabric FAR without error", |
| 230 | false); |
| 231 | return; |
| 232 | } |
| 233 | assertThat(translatedRule, equalTo(expectedRule)); |
| 234 | } |
| 235 | |
| 236 | @Test |
| 237 | public void uplinkPdrToFabricEntryTest() { |
| 238 | FlowRule translatedRule; |
| 239 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_PDR; |
| 240 | try { |
| 241 | translatedRule = upfTranslator.pdrToFabricEntry(TestUpfConstants.UPLINK_PDR, |
| 242 | TestUpfConstants.DEVICE_ID, |
| 243 | TestUpfConstants.APP_ID, |
| 244 | TestUpfConstants.DEFAULT_PRIORITY); |
| 245 | } catch (UpfProgrammableException e) { |
| 246 | assertThat("Abstract uplink PDR should correctly translate to Fabric PDR without error", |
| 247 | false); |
| 248 | return; |
| 249 | } |
| 250 | assertThat(translatedRule, equalTo(expectedRule)); |
| 251 | } |
| 252 | |
| 253 | @Test |
| 254 | public void uplinkPriorityPdrToFabricEntryTest() { |
| 255 | FlowRule translatedRule; |
| 256 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_PRIORITY_PDR; |
| 257 | try { |
| 258 | translatedRule = upfTranslator.pdrToFabricEntry(TestUpfConstants.UPLINK_PRIORITY_PDR, |
| 259 | TestUpfConstants.DEVICE_ID, |
| 260 | TestUpfConstants.APP_ID, |
| 261 | TestUpfConstants.DEFAULT_PRIORITY); |
| 262 | } catch (UpfProgrammableException e) { |
| 263 | assertThat("Abstract uplink PDR should correctly translate to Fabric PDR without error", |
| 264 | false); |
| 265 | return; |
| 266 | } |
| 267 | assertThat(translatedRule, equalTo(expectedRule)); |
| 268 | } |
| 269 | |
| 270 | @Test |
| 271 | public void downlinkFarToFabricEntryTest() { |
| 272 | FlowRule translatedRule; |
| 273 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_FAR; |
| 274 | try { |
| 275 | translatedRule = upfTranslator.farToFabricEntry(TestUpfConstants.DOWNLINK_FAR, |
| 276 | TestUpfConstants.DEVICE_ID, |
| 277 | TestUpfConstants.APP_ID, |
| 278 | TestUpfConstants.DEFAULT_PRIORITY); |
| 279 | } catch (UpfProgrammableException e) { |
| 280 | assertThat("Abstract downlink FAR should correctly translate to Fabric FAR without error", |
| 281 | false); |
| 282 | return; |
| 283 | } |
| 284 | assertThat(translatedRule, equalTo(expectedRule)); |
| 285 | } |
| 286 | } |