summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/main/java/io/fd/hc2vpp/lisp/translate/write/factory/EidTableWriterFactory.java
blob: 1e0758eec56fb7e2c328d4b6ce8f7cfa69cdfca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.hc2vpp.lisp.translate.write.factory;

import com.google.common.collect.ImmutableSet;
import io.fd.hc2vpp.lisp.translate.AbstractLispInfraFactoryBase;
import io.fd.hc2vpp.lisp.translate.write.AdjacencyCustomizer;
import io.fd.hc2vpp.lisp.translate.write.BridgeDomainSubtableCustomizer;
import io.fd.hc2vpp.lisp.translate.write.LocalMappingCustomizer;
import io.fd.hc2vpp.lisp.translate.write.RemoteMappingCustomizer;
import io.fd.hc2vpp.lisp.translate.write.VniTableCustomizer;
import io.fd.hc2vpp.lisp.translate.write.VrfSubtableCustomizer;
import io.fd.honeycomb.translate.impl.write.GenericListWriter;
import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.adjacencies.grouping.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.adjacencies.grouping.adjacencies.Adjacency;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.adjacencies.grouping.adjacencies.adjacency.LocalEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.adjacencies.grouping.adjacencies.adjacency.RemoteEid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.LocalMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.RemoteMappings;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.local.mappings.LocalMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.local.mappings.local.mapping.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.remote.mappings.RemoteMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.Rlocs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.eid.table.grouping.EidTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.eid.table.grouping.eid.table.VniTable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.eid.table.grouping.eid.table.vni.table.VrfSubtable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.hmac.key.grouping.HmacKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.lisp.feature.data.grouping.LispFeatureData;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;


/**
 * Factory for producing writers for {@code EidTable}
 */
public final class EidTableWriterFactory extends AbstractLispInfraFactoryBase implements WriterFactory {

    static final InstanceIdentifier<VniTable> VNI_TABLE_ID =
            LISP_CONFIG_IDENTIFIER.child(LispFeatureData.class).child(EidTable.class).child(VniTable.class);

    static final InstanceIdentifier<VrfSubtable> VRF_SUBTABLE_ID = VNI_TABLE_ID.child(VrfSubtable.class);

    static final InstanceIdentifier<BridgeDomainSubtable> BRIDGE_DOMAIN_SUBTABLE_ID =
            VNI_TABLE_ID.child(BridgeDomainSubtable.class);


    @Override
    public void init(final ModifiableWriterRegistryBuilder registry) {

        registry.add(new GenericListWriter<>(VNI_TABLE_ID, new VniTableCustomizer(vppApi, lispStateCheckService)));

        registry.add(new GenericWriter<>(VRF_SUBTABLE_ID, new VrfSubtableCustomizer(vppApi)));
        registry.add(new GenericWriter<>(BRIDGE_DOMAIN_SUBTABLE_ID,
                new BridgeDomainSubtableCustomizer(vppApi, bridgeDomainContext)));

        addLocalMappingSubtree(registry);
        addRemoteMappingSubtree(registry);
        addAdjacenciesSubtree(registry);
    }

    /**
     * VniTable - > VrfSubtable -> LocalMappings - > LocalMapping
     * VniTable - > BridgeDomainSubtable -> LocalMappings - > LocalMapping
     */
    private void addLocalMappingSubtree(final ModifiableWriterRegistryBuilder registry) {
        final InstanceIdentifier<LocalMapping> localMappingSubtreeId = InstanceIdentifier.create(LocalMapping.class);

        final ImmutableSet<InstanceIdentifier<?>> localMappingHandledChildren =
                ImmutableSet.of(localMappingSubtreeId.child(Eid.class), localMappingSubtreeId.child(HmacKey.class));
        registry.subtreeAdd(localMappingHandledChildren,
                new GenericListWriter<>(VRF_SUBTABLE_ID.child(LocalMappings.class).child(LocalMapping.class),
                        new LocalMappingCustomizer(vppApi, localMappingContext)));

        registry.subtreeAdd(localMappingHandledChildren,
                new GenericListWriter<>(BRIDGE_DOMAIN_SUBTABLE_ID.child(LocalMappings.class).child(LocalMapping.class),
                        new LocalMappingCustomizer(vppApi, localMappingContext)));
    }

    /**
     * VniTable - > VrfSubtable -> RemoteMappings - > RemoteMapping
     * VniTable - > BridgeDomainSubtable -> RemoteMappings - > RemoteMapping
     */
    private void addRemoteMappingSubtree(final ModifiableWriterRegistryBuilder registry) {
        final InstanceIdentifier<RemoteMapping> remoteMappingSubtreeId =
                InstanceIdentifier.create(RemoteMapping.class);
        final ImmutableSet<InstanceIdentifier<?>> remoteMappingHandledChildren =
                ImmutableSet.of(remoteMappingSubtreeId
                                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170911.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class),
                        remoteMappingSubtreeId.child(Rlocs.class),
                        remoteMappingSubtreeId.child(Rlocs.class).child(Locator.class),
                        remoteMappingSubtreeId.child(MapReply.class));

        registry.subtreeAdd(remoteMappingHandledChildren, new GenericListWriter<>(
                VRF_SUBTABLE_ID.child(RemoteMappings.class).child(RemoteMapping.class),
                new RemoteMappingCustomizer(vppApi, remoteMappingContext)));

        registry.subtreeAdd(remoteMappingHandledChildren, new GenericListWriter<>(
                BRIDGE_DOMAIN_SUBTABLE_ID.child(RemoteMappings.class).child(RemoteMapping.class),
                new RemoteMappingCustomizer(vppApi, remoteMappingContext)));
    }

    /**
     * VniTable - > VrfSubtable -> RemoteMappings - > RemoteMapping - > Adjacencies - > Adjacency
     * VniTable - > BridgeDomainSubtable -> RemoteMappings - > RemoteMapping - > Adjacencies - > Adjacency
     */
    private void addAdjacenciesSubtree(final ModifiableWriterRegistryBuilder registry) {
        final InstanceIdentifier<Adjacency> adjacencySubtreeId = InstanceIdentifier.create(Adjacency.class);

        final ImmutableSet<InstanceIdentifier<?>> adjacencyHandledChildren = ImmutableSet.of(adjacencySubtreeId
                .child(LocalEid.class), adjacencySubtreeId.child(RemoteEid.class));

        registry.subtreeAdd(adjacencyHandledChildren, new GenericListWriter<>(
                VRF_SUBTABLE_ID.child(RemoteMappings.class).child(RemoteMapping.class)
                        .child(Adjacencies.class).child(Adjacency.class),
                new AdjacencyCustomizer(vppApi, localMappingContext, remoteMappingContext,
                        adjacenciesMappingContext)));

        registry.subtreeAdd(adjacencyHandledChildren, new GenericListWriter<>(
                BRIDGE_DOMAIN_SUBTABLE_ID.child(RemoteMappings.class)
                        .child(RemoteMapping.class)
                        .child(Adjacencies.class).child(Adjacency.class),
                new AdjacencyCustomizer(vppApi, localMappingContext, remoteMappingContext,
                        adjacenciesMappingContext)));
    }
}