2 * Copyright (c) 2015 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.lisp.translate.write;
19 import static com.google.common.base.Preconditions.checkState;
21 import com.google.common.base.Optional;
22 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
23 import io.fd.honeycomb.translate.util.RWUtils;
25 import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
37 * This customizer serves only as a check if user is not trying to define VniTable <br>
38 * without mapping to vrf/bd
40 public class VniTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<VniTable, VniTableKey> {
42 private static final Logger LOG = LoggerFactory.getLogger(VniTableCustomizer.class);
44 public VniTableCustomizer(FutureJVppCore futureJvpp) {
49 public void writeCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataAfter, WriteContext writeContext)
50 throws WriteFailedException {
51 checkAtLeastOnChildExists(id, writeContext, false);
55 public void updateCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, VniTable dataAfter,
56 WriteContext writeContext) throws WriteFailedException {
57 throw new UnsupportedOperationException("Operation not supported");
61 public void deleteCurrentAttributes(InstanceIdentifier<VniTable> id, VniTable dataBefore, WriteContext writeContext)
62 throws WriteFailedException {
63 checkAtLeastOnChildExists(id, writeContext, true);
66 private void checkAtLeastOnChildExists(final InstanceIdentifier<VniTable> id, final WriteContext writeContext,
67 final boolean before) {
69 Optional<VniTable> optData;
70 final InstanceIdentifier<VniTable> trimmedId = RWUtils.cutId(id, InstanceIdentifier.create(VniTable.class));
72 optData = writeContext.readBefore(trimmedId);
74 optData = writeContext.readAfter(trimmedId);
77 checkState(optData.isPresent(), "Illegal after-write state");
79 final VniTable dataAfter = optData.get();
80 checkState(dataAfter.getVrfSubtable() != null || dataAfter.getBridgeDomainSubtable() != null,
81 "At least one of VrfSubtable/BridgeDomainSubtable must be defined");