Carmelo Cascone | 13c3c5a | 2020-12-03 20:01:40 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020-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.net.pi.impl; |
| 18 | |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.onosproject.net.group.Group; |
| 21 | import org.onosproject.net.pi.model.PiPipeconf; |
| 22 | import org.onosproject.net.pi.runtime.PiHandle; |
| 23 | import org.onosproject.net.pi.runtime.PiPreEntry; |
| 24 | import org.onosproject.net.pi.service.PiReplicationGroupTranslator; |
| 25 | import org.onosproject.net.pi.service.PiTranslatedEntity; |
| 26 | import org.onosproject.net.pi.service.PiTranslationException; |
| 27 | |
| 28 | import java.util.Map; |
| 29 | import java.util.Optional; |
| 30 | |
| 31 | /** |
| 32 | * Adapter implementation of PiGroupTranslator. |
| 33 | */ |
| 34 | public class PiReplicationGroupTranslatorAdapter implements PiReplicationGroupTranslator { |
| 35 | |
| 36 | private final Map<PiHandle, PiTranslatedEntity<Group, PiPreEntry>> store = Maps.newHashMap(); |
| 37 | |
| 38 | @Override |
| 39 | public PiPreEntry translate(Group original, PiPipeconf pipeconf) throws PiTranslationException { |
| 40 | // NOTE Passing device equals to null is meant only for testing purposes |
| 41 | return PiReplicationGroupTranslatorImpl.translate(original, pipeconf, null); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void learn(PiHandle handle, PiTranslatedEntity<Group, PiPreEntry> entity) { |
| 46 | store.put(handle, entity); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Optional<PiTranslatedEntity<Group, PiPreEntry>> lookup(PiHandle handle) { |
| 51 | return Optional.ofNullable(store.get(handle)); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void forget(PiHandle handle) { |
| 56 | store.remove(handle); |
| 57 | } |
| 58 | } |