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.
16 package io.fd.honeycomb.vppioam.impl.config;
18 import static com.google.common.base.Preconditions.checkNotNull;
19 import static com.google.common.base.Preconditions.checkState;
21 import io.fd.honeycomb.translate.MappingContext;
22 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
23 import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator;
24 import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer;
25 import io.fd.honeycomb.translate.vpp.util.NamingContext;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import io.fd.honeycomb.vppioam.impl.util.FutureJVppIoamCustomizer;
30 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd;
31 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply;
32 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel;
33 import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply;
34 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace;
36 import java.util.concurrent.CompletionStage;
37 import javax.annotation.Nonnull;
38 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig;
39 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig;
40 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp;
41 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces;
42 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey;
43 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Writer customizer responsible for Ioam Trace create/delete.
51 public class IoamTraceWriterCustomizer extends FutureJVppIoamCustomizer
52 implements ListWriterCustomizer<TraceConfig, TraceConfigKey>, ByteDataTranslator, JvppReplyConsumer {
54 private static final Logger LOG = LoggerFactory.getLogger(IoamTraceWriterCustomizer.class);
56 public IoamTraceWriterCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) {
57 super(futureJVppIoam);
61 public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<TraceConfig> id,
62 @Nonnull final TraceConfig dataCurr,
63 @Nonnull final WriteContext writeContext)
64 throws WriteFailedException {
67 addTraceConfig(dataCurr, writeContext, id);
68 } catch (Exception exCreate) {
69 LOG.error("Add Trace Configuration failed", exCreate);
70 throw new WriteFailedException.CreateFailedException(id, dataCurr, exCreate);
73 LOG.debug("Trace config added iid={}, added {}", id, dataCurr);
77 public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<TraceConfig> id,
78 @Nonnull final TraceConfig dataBefore,
79 @Nonnull final TraceConfig dataAfter,
80 @Nonnull final WriteContext ctx) throws WriteFailedException {
82 deleteTraceConfig(dataBefore, id);
83 addTraceConfig(dataAfter, ctx, id);
84 } catch (Exception exUpdate) {
85 LOG.error("Update Trace Configuration failed", exUpdate);
86 throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, exUpdate);
89 LOG.debug("Trace config updated {}", dataAfter);
93 public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<TraceConfig> id,
94 @Nonnull final TraceConfig dataBefore,
95 @Nonnull final WriteContext ctx) throws WriteFailedException {
97 deleteTraceConfig(dataBefore, id);
98 } catch (Exception exDelete) {
99 LOG.error("Delete Trace Configuration failed", exDelete);
100 throw new WriteFailedException.DeleteFailedException(id, exDelete);
103 LOG.debug("Trace config deleted:iid={} dataBefore={}", id, dataBefore);
106 public TraceProfileAddReply addTraceConfig(TraceConfig traceConfig,
108 final InstanceIdentifier<TraceConfig> id) throws Exception {
110 TraceProfileAdd traceProfileAdd = new TraceProfileAdd();
111 traceProfileAdd.traceType = (byte) traceConfig.getTraceType().byteValue(); //trace type
112 traceProfileAdd.numElts = (byte) traceConfig.getTraceNumElt().byteValue(); //num of elts
113 traceProfileAdd.traceTsp = (byte) traceConfig.getTraceTsp().getIntValue(); // tsp
114 traceProfileAdd.appData = (int) traceConfig.getTraceAppData().intValue(); // appdata
115 traceProfileAdd.nodeId = (int) traceConfig.getNodeId().intValue(); // nodeid
118 final TraceProfileAddReply reply = getReplyForWrite((getFutureJVppIoam().
119 traceProfileAdd(traceProfileAdd).
120 toCompletableFuture()), id);
124 public TraceProfileDelReply deleteTraceConfig(TraceConfig dataBefore,
125 final InstanceIdentifier<TraceConfig> id) throws Exception {
126 TraceProfileDel del = new TraceProfileDel();
129 TraceProfileDelReply reply = getReplyForWrite((getFutureJVppIoam().
130 traceProfileDel(del).toCompletableFuture()), id);