690d2a91aafd1148ea9039b6448b1c68e934fe93
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / initializers / LispInitializer.java
1 /*
2  * Copyright (c) 2016 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.honeycomb.lisp.translate.initializers;
18
19
20 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.HONEYCOMB_INITIALIZER;
21
22 import com.google.inject.Inject;
23 import com.google.inject.name.Named;
24 import io.fd.honeycomb.data.init.AbstractDataTreeConverter;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispState;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * Initializes vpp node in config data tree based on operational state
35  */
36 public class LispInitializer extends AbstractDataTreeConverter<LispState, Lisp> {
37
38     private static final Logger LOG = LoggerFactory.getLogger(LispInitializer.class);
39
40     @Inject
41     public LispInitializer(@Named(HONEYCOMB_INITIALIZER) final DataBroker bindingDataBroker) {
42         super(bindingDataBroker, InstanceIdentifier.create(LispState.class), InstanceIdentifier.create(Lisp.class));
43     }
44
45     @Override
46     protected Lisp convert(final LispState operationalData) {
47         LOG.debug("LispInitializer started");
48         final LispBuilder lispBuilder = new LispBuilder();
49
50         // set everything from LispState to LispBuilder
51         // this is necessary in cases, when HC connects to a running VPP with some LISP configuration. HC needs to
52         // reconstruct configuration based on what's present in VPP in order to support subsequent configuration changes
53         // without any issues
54
55         // the other reason this should work is HC persistence, so that HC after restart only performs diff (only push
56         // configuration that is not currently in VPP, but is persisted. If they are equal skip any VPP calls)
57         // updates to VPP. If this is not fully implemented (depending on VPP implementation, restoration of persisted
58         // configuration can fail)
59
60         return lispBuilder.setEnable(operationalData.isEnable())
61                 .setLispFeatureData(operationalData.getLispFeatureData())
62                 .build();
63     }
64 }