blob: 66383b3c763f514ceefc814f36ba08dfd100b676 [file] [log] [blame]
Carmelo Cascone13c3c5a2020-12-03 20:01:40 -08001/*
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
17package org.onosproject.net.pi.impl;
18
19import com.google.common.collect.Maps;
20import org.onosproject.net.group.Group;
21import org.onosproject.net.pi.model.PiPipeconf;
22import org.onosproject.net.pi.runtime.PiActionProfileGroup;
23import org.onosproject.net.pi.runtime.PiHandle;
24import org.onosproject.net.pi.service.PiGroupTranslator;
25import org.onosproject.net.pi.service.PiTranslatedEntity;
26import org.onosproject.net.pi.service.PiTranslationException;
27
28import java.util.Map;
29import java.util.Optional;
30
31/**
32 * Adapter implementation of PiGroupTranslator.
33 */
34public class PiGroupTranslatorAdapter implements PiGroupTranslator {
35
36 private final Map<PiHandle, PiTranslatedEntity<Group, PiActionProfileGroup>> store = Maps.newHashMap();
37
38 @Override
39 public PiActionProfileGroup translate(Group original, PiPipeconf pipeconf) throws PiTranslationException {
40 // NOTE Passing device equals to null is meant only for testing purposes
41 return PiGroupTranslatorImpl.translate(original, pipeconf, null);
42 }
43
44 @Override
45 public void learn(PiHandle handle, PiTranslatedEntity<Group, PiActionProfileGroup> entity) {
46 store.put(handle, entity);
47 }
48
49 @Override
50 public Optional<PiTranslatedEntity<Group, PiActionProfileGroup>> 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}