2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.lisp.translate.initializers;
20 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.HONEYCOMB_INITIALIZER;
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;
34 * Initializes vpp node in config data tree based on operational state
36 public class LispInitializer extends AbstractDataTreeConverter<LispState, Lisp> {
38 private static final Logger LOG = LoggerFactory.getLogger(LispInitializer.class);
41 public LispInitializer(@Named(HONEYCOMB_INITIALIZER) final DataBroker bindingDataBroker) {
42 super(bindingDataBroker, InstanceIdentifier.create(LispState.class), InstanceIdentifier.create(Lisp.class));
46 protected Lisp convert(final LispState operationalData) {
47 LOG.debug("LispInitializer started");
48 final LispBuilder lispBuilder = new LispBuilder();
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
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)
60 return lispBuilder.setEnable(operationalData.isEnable())
61 .setLispFeatureData(operationalData.getLispFeatureData())