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() { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 35 | fabricToPdrUplink(TestUpfConstants.UPLINK_PDR, TestUpfConstants.FABRIC_UPLINK_PDR); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | @Test |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 39 | public void fabricEntryToUplinkQosPdrTest() { |
| 40 | fabricToPdrUplink(TestUpfConstants.UPLINK_QOS_PDR, TestUpfConstants.FABRIC_UPLINK_QOS_PDR); |
| 41 | fabricToPdrUplink(TestUpfConstants.UPLINK_QOS_4G_PDR, TestUpfConstants.FABRIC_UPLINK_QOS_4G_PDR); |
| 42 | } |
| 43 | |
| 44 | private void fabricToPdrUplink(PacketDetectionRule expected, FlowRule fabricFlow) { |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 45 | PacketDetectionRule translatedPdr; |
| 46 | try { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 47 | translatedPdr = upfTranslator.fabricEntryToPdr(fabricFlow); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 48 | } catch (UpfProgrammableException e) { |
| 49 | assertThat("Fabric uplink PDR should translate to abstract PDR without error.", false); |
| 50 | return; |
| 51 | } |
| 52 | assertThat("Translated PDR should be uplink.", translatedPdr.matchesEncapped()); |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 53 | assertThat(translatedPdr, equalTo(expected)); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void fabricEntryToDownlinkPdrTest() { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 58 | fabricToPdrDownlink(TestUpfConstants.DOWNLINK_PDR, TestUpfConstants.FABRIC_DOWNLINK_PDR); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Test |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 62 | public void fabricEntryToDownlinkQosPdrTest() { |
| 63 | fabricToPdrDownlink(TestUpfConstants.DOWNLINK_QOS_PDR, TestUpfConstants.FABRIC_DOWNLINK_QOS_PDR); |
| 64 | fabricToPdrDownlink(TestUpfConstants.DOWNLINK_QOS_4G_PDR, TestUpfConstants.FABRIC_DOWNLINK_QOS_4G_PDR); |
| 65 | } |
| 66 | |
| 67 | private void fabricToPdrDownlink(PacketDetectionRule expected, FlowRule fabricFlow) { |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 68 | PacketDetectionRule translatedPdr; |
| 69 | try { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 70 | translatedPdr = upfTranslator.fabricEntryToPdr(fabricFlow); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 71 | } catch (UpfProgrammableException e) { |
| 72 | assertThat("Fabric downlink PDR should translate to abstract PDR without error.", false); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | assertThat("Translated PDR should be downlink.", translatedPdr.matchesUnencapped()); |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 77 | assertThat(translatedPdr, equalTo(expected)); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void fabricEntryToUplinkFarTest() { |
| 82 | ForwardingActionRule translatedFar; |
| 83 | ForwardingActionRule expectedFar = TestUpfConstants.UPLINK_FAR; |
| 84 | try { |
| 85 | translatedFar = upfTranslator.fabricEntryToFar(TestUpfConstants.FABRIC_UPLINK_FAR); |
| 86 | } catch (UpfProgrammableException e) { |
| 87 | assertThat("Fabric uplink FAR should correctly translate to abstract FAR without error", |
| 88 | false); |
| 89 | return; |
| 90 | } |
| 91 | assertThat("Translated FAR should be uplink.", translatedFar.forwards()); |
| 92 | assertThat(translatedFar, equalTo(expectedFar)); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void fabricEntryToDownlinkFarTest() { |
| 97 | ForwardingActionRule translatedFar; |
| 98 | ForwardingActionRule expectedFar = TestUpfConstants.DOWNLINK_FAR; |
| 99 | try { |
| 100 | translatedFar = upfTranslator.fabricEntryToFar(TestUpfConstants.FABRIC_DOWNLINK_FAR); |
| 101 | } catch (UpfProgrammableException e) { |
| 102 | assertThat("Fabric downlink FAR should correctly translate to abstract FAR without error", |
| 103 | false); |
| 104 | return; |
| 105 | } |
| 106 | assertThat("Translated FAR should be downlink.", translatedFar.encaps()); |
| 107 | assertThat(translatedFar, equalTo(expectedFar)); |
| 108 | } |
| 109 | |
| 110 | @Test |
| 111 | public void fabricEntryToUplinkInterfaceTest() { |
| 112 | UpfInterface translatedInterface; |
| 113 | UpfInterface expectedInterface = TestUpfConstants.UPLINK_INTERFACE; |
| 114 | try { |
| 115 | translatedInterface = upfTranslator.fabricEntryToInterface(TestUpfConstants.FABRIC_UPLINK_INTERFACE); |
| 116 | } catch (UpfProgrammableException e) { |
| 117 | assertThat("Fabric uplink interface should correctly translate to abstract interface without error", |
| 118 | false); |
| 119 | return; |
| 120 | } |
| 121 | assertThat("Translated interface should be uplink.", translatedInterface.isAccess()); |
| 122 | assertThat(translatedInterface, equalTo(expectedInterface)); |
| 123 | } |
| 124 | |
| 125 | @Test |
| 126 | public void fabricEntryToDownlinkInterfaceTest() { |
| 127 | UpfInterface translatedInterface; |
| 128 | UpfInterface expectedInterface = TestUpfConstants.DOWNLINK_INTERFACE; |
| 129 | try { |
| 130 | translatedInterface = upfTranslator.fabricEntryToInterface(TestUpfConstants.FABRIC_DOWNLINK_INTERFACE); |
| 131 | } catch (UpfProgrammableException e) { |
| 132 | assertThat("Fabric downlink interface should correctly translate to abstract interface without error", |
| 133 | false); |
| 134 | return; |
| 135 | } |
| 136 | assertThat("Translated interface should be downlink.", translatedInterface.isCore()); |
| 137 | assertThat(translatedInterface, equalTo(expectedInterface)); |
| 138 | } |
| 139 | |
| 140 | @Test |
| 141 | public void uplinkInterfaceToFabricEntryTest() { |
| 142 | FlowRule translatedRule; |
| 143 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_INTERFACE; |
| 144 | try { |
| 145 | translatedRule = upfTranslator.interfaceToFabricEntry(TestUpfConstants.UPLINK_INTERFACE, |
| 146 | TestUpfConstants.DEVICE_ID, |
| 147 | TestUpfConstants.APP_ID, |
| 148 | TestUpfConstants.DEFAULT_PRIORITY); |
| 149 | } catch (UpfProgrammableException e) { |
| 150 | assertThat("Abstract uplink interface should correctly translate to Fabric interface without error", |
| 151 | false); |
| 152 | return; |
| 153 | } |
| 154 | assertThat(translatedRule, equalTo(expectedRule)); |
| 155 | } |
| 156 | |
| 157 | @Test |
| 158 | public void downlinkInterfaceToFabricEntryTest() { |
| 159 | FlowRule translatedRule; |
| 160 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_INTERFACE; |
| 161 | try { |
| 162 | translatedRule = upfTranslator.interfaceToFabricEntry(TestUpfConstants.DOWNLINK_INTERFACE, |
| 163 | TestUpfConstants.DEVICE_ID, |
| 164 | TestUpfConstants.APP_ID, |
| 165 | TestUpfConstants.DEFAULT_PRIORITY); |
| 166 | } catch (UpfProgrammableException e) { |
| 167 | assertThat("Abstract downlink interface should correctly translate to Fabric interface without error", |
| 168 | false); |
| 169 | return; |
| 170 | } |
| 171 | assertThat(translatedRule, equalTo(expectedRule)); |
| 172 | } |
| 173 | |
| 174 | @Test |
| 175 | public void downlinkPdrToFabricEntryTest() { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 176 | pdrToFabricDownlink(TestUpfConstants.FABRIC_DOWNLINK_PDR, TestUpfConstants.DOWNLINK_PDR); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Test |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 180 | public void downlinkPdrToFabricQosEntryTest() { |
| 181 | pdrToFabricDownlink(TestUpfConstants.FABRIC_DOWNLINK_QOS_PDR, TestUpfConstants.DOWNLINK_QOS_PDR); |
| 182 | pdrToFabricDownlink(TestUpfConstants.FABRIC_DOWNLINK_QOS_4G_PDR, TestUpfConstants.DOWNLINK_QOS_4G_PDR); |
| 183 | } |
| 184 | |
| 185 | private void pdrToFabricDownlink(FlowRule expected, PacketDetectionRule pdr) { |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 186 | FlowRule translatedRule; |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 187 | try { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 188 | translatedRule = upfTranslator.pdrToFabricEntry(pdr, |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 189 | TestUpfConstants.DEVICE_ID, |
| 190 | TestUpfConstants.APP_ID, |
| 191 | TestUpfConstants.DEFAULT_PRIORITY); |
| 192 | } catch (UpfProgrammableException e) { |
| 193 | assertThat("Abstract downlink PDR should correctly translate to Fabric PDR without error", |
| 194 | false); |
| 195 | return; |
| 196 | } |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 197 | assertThat(translatedRule, equalTo(expected)); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Test |
| 201 | public void uplinkFarToFabricEntryTest() { |
| 202 | FlowRule translatedRule; |
| 203 | FlowRule expectedRule = TestUpfConstants.FABRIC_UPLINK_FAR; |
| 204 | try { |
| 205 | translatedRule = upfTranslator.farToFabricEntry(TestUpfConstants.UPLINK_FAR, |
| 206 | TestUpfConstants.DEVICE_ID, |
| 207 | TestUpfConstants.APP_ID, |
| 208 | TestUpfConstants.DEFAULT_PRIORITY); |
| 209 | } catch (UpfProgrammableException e) { |
| 210 | assertThat("Abstract uplink FAR should correctly translate to Fabric FAR without error", |
| 211 | false); |
| 212 | return; |
| 213 | } |
| 214 | assertThat(translatedRule, equalTo(expectedRule)); |
| 215 | } |
| 216 | |
| 217 | @Test |
| 218 | public void uplinkPdrToFabricEntryTest() { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 219 | pdrToFabricUplink(TestUpfConstants.FABRIC_UPLINK_PDR, TestUpfConstants.UPLINK_PDR); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Test |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 223 | public void uplinkQosPdrToFabricEntryTest() { |
| 224 | pdrToFabricUplink(TestUpfConstants.FABRIC_UPLINK_QOS_PDR, TestUpfConstants.UPLINK_QOS_PDR); |
| 225 | pdrToFabricUplink(TestUpfConstants.FABRIC_UPLINK_QOS_4G_PDR, TestUpfConstants.UPLINK_QOS_4G_PDR); |
| 226 | } |
| 227 | |
| 228 | private void pdrToFabricUplink(FlowRule expected, PacketDetectionRule pdr) { |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 229 | FlowRule translatedRule; |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 230 | try { |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 231 | translatedRule = upfTranslator.pdrToFabricEntry(pdr, |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 232 | TestUpfConstants.DEVICE_ID, |
| 233 | TestUpfConstants.APP_ID, |
| 234 | TestUpfConstants.DEFAULT_PRIORITY); |
| 235 | } catch (UpfProgrammableException e) { |
| 236 | assertThat("Abstract uplink PDR should correctly translate to Fabric PDR without error", |
| 237 | false); |
| 238 | return; |
| 239 | } |
Daniele Moro | 08c9e7f | 2021-07-28 18:53:34 +0200 | [diff] [blame^] | 240 | assertThat(translatedRule, equalTo(expected)); |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Test |
| 244 | public void downlinkFarToFabricEntryTest() { |
| 245 | FlowRule translatedRule; |
| 246 | FlowRule expectedRule = TestUpfConstants.FABRIC_DOWNLINK_FAR; |
| 247 | try { |
| 248 | translatedRule = upfTranslator.farToFabricEntry(TestUpfConstants.DOWNLINK_FAR, |
| 249 | TestUpfConstants.DEVICE_ID, |
| 250 | TestUpfConstants.APP_ID, |
| 251 | TestUpfConstants.DEFAULT_PRIORITY); |
| 252 | } catch (UpfProgrammableException e) { |
| 253 | assertThat("Abstract downlink FAR should correctly translate to Fabric FAR without error", |
| 254 | false); |
| 255 | return; |
| 256 | } |
| 257 | assertThat(translatedRule, equalTo(expectedRule)); |
| 258 | } |
| 259 | } |