61c442e18f337085e46bbba6540cc9134366b161
[honeycomb.git] / nsh / impl / src / main / java / io / fd / honeycomb / vppnsh / impl / config / VppNshWriterFactory.java
1 /*
2  * Copyright (c) 2016 Intel 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.honeycomb.vppnsh.impl.config;
18
19 import com.google.common.collect.Sets;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
23 import io.fd.honeycomb.translate.vpp.util.NamingContext;
24 import io.fd.honeycomb.translate.write.WriterFactory;
25 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
26 import io.fd.vpp.jvpp.nsh.future.FutureJVppNsh;
27 import javax.annotation.Nonnull;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.NshMdType1Augment;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.NshMdType2Augment;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.VppNsh;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.NshEntries;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.NshMaps;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.nsh.entries.NshEntry;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nsh.rev160624.vpp.nsh.nsh.maps.NshMap;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36
37 public class VppNshWriterFactory implements WriterFactory {
38
39     @Nonnull
40     private final FutureJVppNsh jvppNsh;
41     private final NamingContext nshEntryContext;
42     private final NamingContext nshMapContext;
43     private final NamingContext interfaceContext;
44
45     @Inject
46     public VppNshWriterFactory(@Nonnull final FutureJVppNsh jvppNsh,
47                                @Named("nsh-entry-context") @Nonnull final NamingContext nshEntryContext,
48                                @Named("nsh-map-context") @Nonnull final NamingContext nshMapContext,
49                                @Named("interface-context") @Nonnull final NamingContext interfaceContext) {
50         this.jvppNsh = jvppNsh;
51         this.nshEntryContext = nshEntryContext;
52         this.nshMapContext = nshMapContext;
53         this.interfaceContext = interfaceContext;
54     }
55
56     @Override
57     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
58         // WriterFactory is intended for registering Writers into HC framework
59         // Writers handle ONLY config (config "true") data coming from upper layers and propagate them into lower layer/device
60         // they are triggered when RESTCONF PUT/POST on config is invoked or when NETCONF edit-config + commit operation is executed
61
62         // VppNsh has no handlers
63         //  NshEntries has no handlers
64         //   NshEntry =
65         final InstanceIdentifier<NshEntries> nshEntriesId = InstanceIdentifier.create(VppNsh.class).child(NshEntries.class);
66         final InstanceIdentifier<NshEntry> nshEntryId = nshEntriesId.child(NshEntry.class);
67         registry.subtreeAdd(
68                 Sets.newHashSet(
69                     InstanceIdentifier.create(NshEntry.class).augmentation(NshMdType1Augment.class),
70                     InstanceIdentifier.create(NshEntry.class).augmentation(NshMdType2Augment.class)),
71                 new GenericListWriter<>(nshEntryId, new NshEntryWriterCustomizer(jvppNsh, nshEntryContext)));
72
73         // VppNsh has no handlers
74         //  NshMaps has no handlers
75         //   NshMap =
76         final InstanceIdentifier<NshMap> nshMapId =
77               InstanceIdentifier.create(VppNsh.class).child(NshMaps.class).child(NshMap.class);
78         registry.add(new GenericListWriter<>(nshMapId, new NshMapWriterCustomizer(jvppNsh, nshMapContext, interfaceContext)));
79
80     }
81 }