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 com.google.common.collect.Maps; |
| 20 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 21 | import org.onosproject.net.pi.model.PiActionProfileModel; |
| 22 | import org.onosproject.net.pi.model.PiCounterId; |
| 23 | import org.onosproject.net.pi.model.PiCounterModel; |
| 24 | import org.onosproject.net.pi.model.PiMeterId; |
| 25 | import org.onosproject.net.pi.model.PiMeterModel; |
| 26 | import org.onosproject.net.pi.model.PiPacketOperationModel; |
| 27 | import org.onosproject.net.pi.model.PiPacketOperationType; |
| 28 | import org.onosproject.net.pi.model.PiPipelineModel; |
| 29 | import org.onosproject.net.pi.model.PiRegisterId; |
| 30 | import org.onosproject.net.pi.model.PiRegisterModel; |
| 31 | import org.onosproject.net.pi.model.PiTableId; |
| 32 | import org.onosproject.net.pi.model.PiTableModel; |
| 33 | |
| 34 | import java.util.Collection; |
| 35 | import java.util.List; |
| 36 | import java.util.Map; |
| 37 | import java.util.Optional; |
| 38 | |
| 39 | |
| 40 | public class MockPiPipelineModel implements PiPipelineModel { |
| 41 | |
| 42 | private final Map<PiTableId, PiTableModel> tableMap = Maps.newHashMap(); |
| 43 | |
| 44 | private final List<PiCounterModel> counters; |
| 45 | |
| 46 | public MockPiPipelineModel(Collection<PiTableModel> tables, Collection<PiCounterModel> counters) { |
| 47 | tables.forEach(tableModel -> tableMap.put(tableModel.id(), tableModel)); |
| 48 | this.counters = List.copyOf(counters); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Optional<PiTableModel> table(PiTableId tableId) { |
| 53 | return Optional.ofNullable(tableMap.getOrDefault(tableId, null)); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public Collection<PiTableModel> tables() { |
| 58 | return tableMap.values(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Optional<PiCounterModel> counter(PiCounterId counterId) { |
| 63 | return Optional.empty(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public Collection<PiCounterModel> counters() { |
| 68 | return counters; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Optional<PiMeterModel> meter(PiMeterId meterId) { |
| 73 | return Optional.empty(); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Collection<PiMeterModel> meters() { |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Optional<PiRegisterModel> register(PiRegisterId registerId) { |
| 83 | return Optional.empty(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Collection<PiRegisterModel> registers() { |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public Optional<PiActionProfileModel> actionProfiles(PiActionProfileId actionProfileId) { |
| 93 | return Optional.empty(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Collection<PiActionProfileModel> actionProfiles() { |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public Optional<PiPacketOperationModel> packetOperationModel(PiPacketOperationType type) { |
| 103 | return Optional.empty(); |
| 104 | } |
| 105 | |
| 106 | |
| 107 | } |