6255d08ee34316c197929578b0f4d4c675578028
[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.interfaces.ip.v4.subinterface;
18
19 import io.fd.hc2vpp.common.translate.util.AddressTranslator;
20 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
21 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
22 import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
23 import io.fd.hc2vpp.common.translate.util.NamingContext;
24 import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter;
25 import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
26 import io.fd.honeycomb.translate.write.WriteContext;
27 import io.fd.honeycomb.translate.write.WriteFailedException;
28 import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel;
29 import io.fd.vpp.jvpp.core.future.FutureJVppCore;
30 import javax.annotation.Nonnull;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Neighbor;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer
38         implements ListWriterCustomizer<Neighbor, NeighborKey>, ByteDataTranslator, AddressTranslator, IpWriter,
39         JvppReplyConsumer {
40
41     private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4NeighbourCustomizer.class);
42     private final NamingContext interfaceContext;
43
44     public SubInterfaceIpv4NeighbourCustomizer(final FutureJVppCore futureJVppCore,
45                                                final NamingContext interfaceContext) {
46         super(futureJVppCore);
47         this.interfaceContext = interfaceContext;
48     }
49
50     @Override
51     public void writeCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor data,
52                                        @Nonnull WriteContext writeContext)
53             throws WriteFailedException {
54
55         LOG.debug("Processing request for Neighbour {} write", id);
56
57         addDelNeighbour(id, () -> {
58             IpNeighborAddDel request = preBindIpv4Request(true);
59
60             request.dstAddress = ipv4AddressNoZoneToArray(data.getIp());
61             request.macAddress = parseMac(data.getLinkLayerAddress().getValue());
62             request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext());
63
64             //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid
65             //request.vrfId
66             return request;
67         }, getFutureJVpp());
68         LOG.info("Neighbour {} successfully written", id);
69     }
70
71     @Override
72     public void updateCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataBefore,
73                                         @Nonnull Neighbor dataAfter,
74                                         @Nonnull WriteContext writeContext) throws WriteFailedException {
75         throw new UnsupportedOperationException("Operation not supported");
76     }
77
78     @Override
79     public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor data,
80                                         @Nonnull WriteContext writeContext)
81             throws WriteFailedException {
82
83         LOG.debug("Processing request for Neighbour {} delete", id);
84
85         addDelNeighbour(id, () -> {
86             IpNeighborAddDel request = preBindIpv4Request(false);
87
88             request.dstAddress = ipv4AddressNoZoneToArray(data.getIp());
89             request.macAddress = parseMac(data.getLinkLayerAddress().getValue());
90             request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext());
91
92             //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid
93             //request.vrfId
94             return request;
95         }, getFutureJVpp());
96         LOG.info("Neighbour {} successfully deleted", id);
97     }
98
99 }