2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.translate.v3po.interfaces.acl.common;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import com.google.common.annotations.VisibleForTesting;
22 import com.google.common.base.Optional;
23 import io.fd.honeycomb.translate.MappingContext;
24 import javax.annotation.Nonnull;
25 import javax.annotation.concurrent.ThreadSafe;
26 import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.AclMappingEntryCtxAugmentation;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.AclMappingEntryContext;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.MappingTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.MappingTableKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntry;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.context.rev161214.mapping.entry.context.attributes.acl.mapping.entry.context.mapping.table.MappingEntryKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 public class AclTableContextManagerImpl implements AclTableContextManager {
38 private MappingTable.Direction direction;
40 public AclTableContextManagerImpl(@Nonnull final MappingTable.Direction direction) {
41 this.direction = checkNotNull(direction, "direction should not be null");
46 public synchronized Optional<MappingEntry> getEntry(final int swIfIndex, @Nonnull final MappingContext mappingContext) {
47 return mappingContext.read(getId(swIfIndex));
51 public synchronized void addEntry(@Nonnull final MappingEntry entry, @Nonnull final MappingContext mappingContext) {
52 mappingContext.put(getId(entry.getIndex()), entry);
56 public synchronized void removeEntry(final int swIfIndex, @Nonnull final MappingContext mappingContext) {
57 mappingContext.delete(getId(swIfIndex));
61 protected InstanceIdentifier<MappingEntry> getId(final int index) {
62 return InstanceIdentifier.create(Contexts.class)
63 .augmentation(AclMappingEntryCtxAugmentation.class)
64 .child(AclMappingEntryContext.class)
65 .child(MappingTable.class, new MappingTableKey(direction))
66 .child(MappingEntry.class, new MappingEntryKey(index));