ca44208ba70bd773f98e9fc5ac95d6711772d095
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
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 io.fd.hc2vpp.v3po.read.span;
18
19
20 import io.fd.hc2vpp.common.translate.util.NamingContext;
21 import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer;
22 import io.fd.hc2vpp.v3po.util.SubInterfaceUtils;
23 import io.fd.honeycomb.translate.read.ReadContext;
24 import io.fd.honeycomb.translate.spi.read.Initialized;
25 import io.fd.honeycomb.translate.util.RWUtils;
26 import io.fd.jvpp.core.future.FutureJVppCore;
27 import java.util.Collections;
28 import java.util.Optional;
29 import java.util.stream.Collectors;
30 import javax.annotation.Nonnull;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev190527.VppSubinterfaceSpanAugmentation;
32 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev190527.interfaces._interface.sub.interfaces.sub._interface.Span;
33 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev190527.interfaces._interface.sub.interfaces.sub._interface.SpanBuilder;
34 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.MirroredInterfaces;
35 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev190527.interfaces._interface.sub.interfaces.SubInterface;
36 import org.opendaylight.yangtools.concepts.Builder;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39
40 /**
41  * Provides sub-interface-specific logic to read/init port mirroring configuration
42  */
43 public class SubInterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer {
44
45     public SubInterfaceMirroredInterfacesCustomizer(@Nonnull FutureJVppCore futureJVppCore, NamingContext ifcContext) {
46         super(futureJVppCore, ifcContext, SubInterfaceUtils::subInterfaceFullNameOperational);
47     }
48
49     @Nonnull
50     @Override
51     public Initialized<? extends DataObject> init(@Nonnull InstanceIdentifier<MirroredInterfaces> id,
52                                                   @Nonnull MirroredInterfaces readValue,
53                                                   @Nonnull ReadContext readContext) {
54         final InstanceIdentifier<org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.MirroredInterfaces>
55                 cfgId =
56                 SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class))
57                         .augmentation(VppSubinterfaceSpanAugmentation.class)
58                         .child(Span.class)
59                         .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.MirroredInterfaces.class);
60
61         final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.MirroredInterfaces
62                 cfgValue =
63                 new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.MirroredInterfacesBuilder()
64                 .setMirroredInterface(
65                         Optional.ofNullable(readValue.getMirroredInterface()).orElse(Collections.emptyList())
66                                 .stream()
67                                 .map(mirroredInterface -> new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder()
68                                         .withKey(
69                                                 new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190527.span.attributes.mirrored.interfaces.MirroredInterfaceKey(
70                                                         mirroredInterface.key().getIfaceRef()))
71                                         .setIfaceRef(mirroredInterface.getIfaceRef())
72                                         .setState(mirroredInterface.getState())
73                                         .build())
74                                 .collect(Collectors.toList()))
75                 .build();
76
77         return Initialized.create(cfgId, cfgValue);
78     }
79
80     @Override
81     public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull MirroredInterfaces mirroredInterfaces) {
82         ((SpanBuilder) builder).setMirroredInterfaces(mirroredInterfaces);
83     }
84 }