blob: 8500b9a3bc30ae771abcc46bbb61446f0a2f9078 [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.onlab.packet.Ip4Address;
20import org.onosproject.store.service.Serializer;
21import org.onosproject.store.service.TestConsistentMap;
22import org.onosproject.store.service.TestDistributedSet;
23
24import java.util.Set;
25
26import static org.onosproject.pipelines.fabric.impl.behaviour.upf.DistributedFabricUpfStore.BUFFER_FAR_ID_SET_NAME;
27import static org.onosproject.pipelines.fabric.impl.behaviour.upf.DistributedFabricUpfStore.FAR_ID_MAP_NAME;
28import static org.onosproject.pipelines.fabric.impl.behaviour.upf.DistributedFabricUpfStore.FAR_ID_UE_MAP_NAME;
29import static org.onosproject.pipelines.fabric.impl.behaviour.upf.DistributedFabricUpfStore.SERIALIZER;
30
31
32public final class TestDistributedFabricUpfStore {
33
34 private TestDistributedFabricUpfStore() {
35 }
36
37 public static DistributedFabricUpfStore build() {
38 var store = new DistributedFabricUpfStore();
39 TestConsistentMap.Builder<UpfRuleIdentifier, Integer> farIdMapBuilder =
40 TestConsistentMap.builder();
41 farIdMapBuilder.withName(FAR_ID_MAP_NAME)
42 .withRelaxedReadConsistency()
43 .withSerializer(Serializer.using(SERIALIZER.build()));
44 store.farIdMap = farIdMapBuilder.build();
45
46 TestDistributedSet.Builder<UpfRuleIdentifier> bufferFarIdsBuilder =
47 TestDistributedSet.builder();
48 bufferFarIdsBuilder
49 .withName(BUFFER_FAR_ID_SET_NAME)
50 .withRelaxedReadConsistency()
51 .withSerializer(Serializer.using(SERIALIZER.build()));
52 store.bufferFarIds = bufferFarIdsBuilder.build().asDistributedSet();
53
54 TestConsistentMap.Builder<UpfRuleIdentifier, Set<Ip4Address>> farIdToUeAddrsBuilder =
55 TestConsistentMap.builder();
56 farIdToUeAddrsBuilder
57 .withName(FAR_ID_UE_MAP_NAME)
58 .withRelaxedReadConsistency()
59 .withSerializer(Serializer.using(SERIALIZER.build()));
60 store.farIdToUeAddrs = farIdToUeAddrsBuilder.build();
61
62 store.activate();
63
64 // Init with some translation state.
65 store.farIdMap.put(
66 new UpfRuleIdentifier(TestUpfConstants.SESSION_ID, TestUpfConstants.UPLINK_FAR_ID),
67 TestUpfConstants.UPLINK_PHYSICAL_FAR_ID);
68 store.farIdMap.put(
69 new UpfRuleIdentifier(TestUpfConstants.SESSION_ID, TestUpfConstants.DOWNLINK_FAR_ID),
70 TestUpfConstants.DOWNLINK_PHYSICAL_FAR_ID);
71
72 return store;
73 }
74}