blob: a07826d6b74f66457150cb11fee0c178074cf499 [file] [log] [blame]
Daniele Moro8d630f12021-06-15 20:53:22 +02001/*
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
17package org.onosproject.pipelines.fabric.impl.behaviour.upf;
18
19import org.junit.Test;
20import org.onosproject.net.behaviour.upf.ForwardingActionRule;
21import org.onosproject.net.behaviour.upf.PacketDetectionRule;
22import org.onosproject.net.behaviour.upf.UpfInterface;
23import org.onosproject.net.behaviour.upf.UpfProgrammableException;
24import org.onosproject.net.flow.FlowRule;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.equalTo;
28
29public class FabricUpfTranslatorTest {
30
31 private final FabricUpfTranslator upfTranslator = new FabricUpfTranslator(TestDistributedFabricUpfStore.build());
32
33 @Test
34 public void fabricEntryToUplinkPdrTest() {
Daniele Moro08c9e7f2021-07-28 18:53:34 +020035 fabricToPdrUplink(TestUpfConstants.UPLINK_PDR, TestUpfConstants.FABRIC_UPLINK_PDR);
Daniele Moro8d630f12021-06-15 20:53:22 +020036 }
37
38 @Test
Daniele Moro08c9e7f2021-07-28 18:53:34 +020039 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 Moro8d630f12021-06-15 20:53:22 +020045 PacketDetectionRule translatedPdr;
46 try {
Daniele Moro08c9e7f2021-07-28 18:53:34 +020047 translatedPdr = upfTranslator.fabricEntryToPdr(fabricFlow);
Daniele Moro8d630f12021-06-15 20:53:22 +020048 } 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 Moro08c9e7f2021-07-28 18:53:34 +020053 assertThat(translatedPdr, equalTo(expected));
Daniele Moro8d630f12021-06-15 20:53:22 +020054 }
55
56 @Test
57 public void fabricEntryToDownlinkPdrTest() {
Daniele Moro08c9e7f2021-07-28 18:53:34 +020058 fabricToPdrDownlink(TestUpfConstants.DOWNLINK_PDR, TestUpfConstants.FABRIC_DOWNLINK_PDR);
Daniele Moro8d630f12021-06-15 20:53:22 +020059 }
60
61 @Test
Daniele Moro08c9e7f2021-07-28 18:53:34 +020062 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 Moro8d630f12021-06-15 20:53:22 +020068 PacketDetectionRule translatedPdr;
69 try {
Daniele Moro08c9e7f2021-07-28 18:53:34 +020070 translatedPdr = upfTranslator.fabricEntryToPdr(fabricFlow);
Daniele Moro8d630f12021-06-15 20:53:22 +020071 } 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 Moro08c9e7f2021-07-28 18:53:34 +020077 assertThat(translatedPdr, equalTo(expected));
Daniele Moro8d630f12021-06-15 20:53:22 +020078 }
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 Moro08c9e7f2021-07-28 18:53:34 +0200176 pdrToFabricDownlink(TestUpfConstants.FABRIC_DOWNLINK_PDR, TestUpfConstants.DOWNLINK_PDR);
Daniele Moro8d630f12021-06-15 20:53:22 +0200177 }
178
179 @Test
Daniele Moro08c9e7f2021-07-28 18:53:34 +0200180 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 Moro8d630f12021-06-15 20:53:22 +0200186 FlowRule translatedRule;
Daniele Moro8d630f12021-06-15 20:53:22 +0200187 try {
Daniele Moro08c9e7f2021-07-28 18:53:34 +0200188 translatedRule = upfTranslator.pdrToFabricEntry(pdr,
Daniele Moro8d630f12021-06-15 20:53:22 +0200189 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 Moro08c9e7f2021-07-28 18:53:34 +0200197 assertThat(translatedRule, equalTo(expected));
Daniele Moro8d630f12021-06-15 20:53:22 +0200198 }
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 Moro08c9e7f2021-07-28 18:53:34 +0200219 pdrToFabricUplink(TestUpfConstants.FABRIC_UPLINK_PDR, TestUpfConstants.UPLINK_PDR);
Daniele Moro8d630f12021-06-15 20:53:22 +0200220 }
221
222 @Test
Daniele Moro08c9e7f2021-07-28 18:53:34 +0200223 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 Moro8d630f12021-06-15 20:53:22 +0200229 FlowRule translatedRule;
Daniele Moro8d630f12021-06-15 20:53:22 +0200230 try {
Daniele Moro08c9e7f2021-07-28 18:53:34 +0200231 translatedRule = upfTranslator.pdrToFabricEntry(pdr,
Daniele Moro8d630f12021-06-15 20:53:22 +0200232 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 Moro08c9e7f2021-07-28 18:53:34 +0200240 assertThat(translatedRule, equalTo(expected));
Daniele Moro8d630f12021-06-15 20:53:22 +0200241 }
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}