Fix physical information management on node removal
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / manager / VppNodeManager.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.manager;
10
11 import static org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus.Connected;
12 import static org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus.Connecting;
13 import static org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus.UnableToConnect;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Objects;
21 import java.util.concurrent.Callable;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.ExecutorService;
24 import java.util.concurrent.Executors;
25 import java.util.concurrent.Future;
26 import java.util.stream.Collectors;
27
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
30
31 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
32 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
33 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
34 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
35 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
36 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
37 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
38 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
39 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
40 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
41 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.HostRelatedInfoContainer;
42 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
43 import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatUtil;
44 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
45 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppRendererProcessingException;
46 import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererNodes;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNodeKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VppInterfaceAugmentation;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VppInterfaceAugmentationBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterfaceBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterfaceKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
71 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74
75 import com.google.common.base.Optional;
76 import com.google.common.base.Preconditions;
77 import com.google.common.base.Splitter;
78 import com.google.common.base.Strings;
79 import com.google.common.collect.Lists;
80 import com.google.common.collect.Sets;
81 import com.google.common.util.concurrent.CheckedFuture;
82 import com.google.common.util.concurrent.FutureCallback;
83 import com.google.common.util.concurrent.Futures;
84 import com.google.common.util.concurrent.ListenableFuture;
85
86 public class VppNodeManager {
87
88     private static final short DURATION = 3000;
89     private static final TopologyId TOPOLOGY_ID = new TopologyId("topology-netconf");
90     private static final Logger LOG = LoggerFactory.getLogger(VppNodeManager.class);
91     private static final String V3PO_CAPABILITY = "(urn:opendaylight:params:xml:ns:yang:v3po?revision=2017-06-07)v3po";
92     private static final String INTERFACES_CAPABILITY = "(urn:ietf:params:xml:ns:yang:ietf-interfaces?revision=2014-05-08)ietf-interfaces";
93     private static final NodeId CONTROLLER_CONFIG_NODE = new NodeId("controller-config");
94     private static final String NO_PUBLIC_INT_SPECIFIED = "unspecified";
95     private static final String PUBLIC_INTERFACE = "public-interface";
96     private final Map<NodeId, PhysicalInterfaceKey> extInterfaces = new HashMap<>();
97     private final DataBroker dataBroker;
98     private final List<String> requiredCapabilities;
99     private final MountPointService mountService;
100     private final HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
101
102     public VppNodeManager(@Nonnull final DataBroker dataBroker,
103             @Nonnull final BindingAwareBroker.ProviderContext session, @Nullable String physicalInterfaces) {
104         this.dataBroker = Preconditions.checkNotNull(dataBroker);
105         this.mountService = Preconditions.checkNotNull(session.getSALService(MountPointService.class));
106         requiredCapabilities = initializeRequiredCapabilities();
107         if (!Strings.isNullOrEmpty(physicalInterfaces) && !Objects.equals(physicalInterfaces, NO_PUBLIC_INT_SPECIFIED)) {
108             loadPhysicalInterfaces(physicalInterfaces);
109         }
110     }
111
112     /**
113      * Caches list of physical interfaces.
114      */
115     private void loadPhysicalInterfaces(@Nonnull String physicalInterfaces) {
116         for (String intfOnNode : Sets.newConcurrentHashSet(Splitter.on(",").split(physicalInterfaces))) {
117             List<String> entries = Lists.newArrayList(Splitter.on(":").split(intfOnNode));
118             if (entries.size() != 2) {
119                 LOG.warn("Cannot resolve {} initial configuration for physical interfaces.", intfOnNode);
120                 continue;
121             }
122             NodeId nodeId = new NodeId(entries.get(0));
123             PhysicalInterfaceKey infaceKey = new PhysicalInterfaceKey(entries.get(1));
124             LOG.info("Interface %s on node %swill be considered as external", infaceKey, nodeId);
125             extInterfaces.put(nodeId, infaceKey);
126         }
127     }
128
129     /**
130      * Synchronizes nodes to DataStore based on their modification state which results in
131      * create/update/remove of Node.
132      */
133     public void syncNodes(final Node dataAfter, final Node dataBefore) {
134         if (isControllerConfigNode(dataAfter, dataBefore)) {
135             LOG.trace("{} is ignored by VPP-renderer", CONTROLLER_CONFIG_NODE);
136             return;
137         }
138         ListenableFuture<String> syncFuture = Futures.immediateFuture(null);
139         // New node
140         if (dataBefore == null && dataAfter != null) {
141             syncFuture = createNode(dataAfter);
142         }
143         // Connected/disconnected node
144         else if (dataBefore != null && dataAfter != null) {
145             syncFuture = updateNode(dataAfter);
146         }
147         // Removed node
148         else if (dataBefore != null) {
149             syncFuture = removeNode(dataBefore);
150         }
151         Futures.addCallback(syncFuture, new FutureCallback<String>() {
152             @Override
153             public void onSuccess(@Nullable String message) {
154                 LOG.info("Node synchronization completed. {} ", message);
155             }
156
157             @Override
158             public void onFailure(@Nonnull Throwable t) {
159                 LOG.warn("Node synchronization failed. Data before: {} after {}", dataBefore, dataAfter);
160             }
161         });
162     }
163
164     private boolean isControllerConfigNode(final Node dataAfter, final Node dataBefore) {
165         if (dataAfter != null) {
166             return CONTROLLER_CONFIG_NODE.equals(dataAfter.getNodeId());
167         }
168         return CONTROLLER_CONFIG_NODE.equals(dataBefore.getNodeId());
169     }
170
171     private ListenableFuture<String> createNode(final Node node) {
172         final String nodeId = node.getNodeId().getValue();
173         LOG.info("Registering new node {}", nodeId);
174         final NetconfNode netconfNode = getNodeAugmentation(node);
175         if (netconfNode == null) {
176             final String message = String.format("Node %s is not an netconf node", nodeId);
177             return Futures.immediateFuture(message);
178         }
179         final NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = netconfNode.getConnectionStatus();
180         switch (connectionStatus) {
181             case Connecting: {
182                 final String message = String.format("Connecting device %s ...", nodeId);
183                 return Futures.immediateFuture(message);
184             }
185             case Connected: {
186                 return resolveConnectedNode(node, netconfNode);
187             }
188             case UnableToConnect: {
189                 final String message = String.format("Connection status is unable to connect for node %s", nodeId);
190                 return Futures.immediateFuture(message);
191             }
192             default: {
193                 final String message = String.format("Unknown connection status for node %s", nodeId);
194                 return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
195             }
196         }
197     }
198
199     private ListenableFuture<String> updateNode(final Node node) {
200         final String nodeId = node.getNodeId().getValue();
201         LOG.info("Updating node {}", nodeId);
202         final NetconfNode netconfNode = getNodeAugmentation(node);
203         if (netconfNode == null) {
204             final String message = String.format("Node %s is not an netconf node", nodeId);
205             return Futures.immediateFuture(message);
206         }
207         final NetconfNodeConnectionStatus.ConnectionStatus afterNodeStatus = netconfNode.getConnectionStatus();
208         if (Connected.equals(afterNodeStatus)) {
209             return resolveConnectedNode(node, netconfNode);
210         } else if (Connecting.equals(afterNodeStatus)) {
211             final String cause = String.format("Node %s is disconnected, removing from available nodes", nodeId);
212             return resolveDisconnectedNode(node, cause);
213         } else if (UnableToConnect.equals(afterNodeStatus)) {
214             final String cause = String.format("New node %s status is unable to connect, removing from available nodes",
215                     nodeId);
216             return resolveDisconnectedNode(node, cause);
217         } else {
218             final String cause = String.format("New node status is unknown. Node %s will be removed from available nodes",
219                     nodeId);
220             return resolveDisconnectedNode(node, cause);
221         }
222     }
223
224     private ListenableFuture<String> removeNode(final Node node) {
225         final String cause = String.format("Node %s is removed", node.getNodeId().getValue());
226         return resolveDisconnectedNode(node, cause);
227     }
228
229     private ListenableFuture<String> resolveConnectedNode(final Node node, final NetconfNode netconfNode) {
230         final String nodeId = node.getNodeId().getValue();
231         final InstanceIdentifier<Node> mountPointIid = getMountpointIid(node);
232         final RendererNode rendererNode = remapNode(mountPointIid);
233         if (!isCapableNetconfDevice(node, netconfNode)) {
234             final String message = String.format("Node %s is not connected", nodeId);
235             return Futures.immediateFuture(message);
236         }
237         final DataBroker mountpoint = getNodeMountPoint(mountPointIid);
238         if (mountpoint == null) {
239             final String message = String.format("Mountpoint not available for node %s", nodeId);
240             return Futures.immediateFuture(message);
241         }
242         final WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
243         wTx.put(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodeIid(rendererNode), rendererNode, true);
244         final boolean submit = DataStoreHelper.submitToDs(wTx);
245         if (submit) {
246             final String message = String.format("Node %s is capable and ready", nodeId);
247             syncPhysicalInterfacesInLocalDs(mountpoint, mountPointIid);
248             NatUtil.resolveOutboundNatInterface(mountpoint, mountPointIid, node.getNodeId(), extInterfaces);
249             return Futures.immediateFuture(message);
250         } else {
251             final String message = String.format("Failed to resolve connected node %s", nodeId);
252             return Futures.immediateFuture(message);
253         }
254     }
255
256     private ListenableFuture<String> resolveDisconnectedNode(final Node node, final String cause) {
257         final InstanceIdentifier<Node> mountPointIid = getMountpointIid(node);
258         final RendererNode rendererNode = remapNode(mountPointIid);
259         final WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
260         wTx.delete(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodeIid(rendererNode));
261         final CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = wTx.submit();
262         try {
263             checkedFuture.checkedGet();
264             return Futures.immediateFuture(cause);
265         } catch (TransactionCommitFailedException e) {
266             final String message = String.format("Failed to resolve disconnected node %s", node.getNodeId().getValue());
267             return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
268         }
269     }
270
271     @Nullable
272     private DataBroker getNodeMountPoint(final InstanceIdentifier<Node> mountPointIid) {
273         final Future<Optional<MountPoint>> futureOptionalObject = getMountpointFromSal(mountPointIid);
274         try {
275             final Optional<MountPoint> optionalObject = futureOptionalObject.get();
276             LOG.debug("Optional mountpoint object: {}", optionalObject);
277             MountPoint mountPoint;
278             if (optionalObject.isPresent()) {
279                 mountPoint = optionalObject.get();
280                 Optional<DataBroker> optionalDataBroker = mountPoint.getService(DataBroker.class);
281                 if (optionalDataBroker.isPresent()) {
282                     return optionalDataBroker.get();
283                 } else {
284                     LOG.warn("Cannot obtain data broker from mountpoint {}", mountPoint);
285                 }
286             } else {
287                 LOG.warn("Cannot obtain mountpoint with IID {}", mountPointIid);
288             }
289             return null;
290         } catch (ExecutionException | InterruptedException e) {
291             LOG.warn("Unable to obtain mountpoint ... {}", e);
292             return null;
293         }
294     }
295
296     private RendererNode remapNode(final InstanceIdentifier<Node> path) {
297         final RendererNodeBuilder rendererNodeBuilder = new RendererNodeBuilder();
298         rendererNodeBuilder.setKey(new RendererNodeKey(path)).setNodePath(path);
299         return rendererNodeBuilder.build();
300     }
301
302     private InstanceIdentifier<Node> getMountpointIid(final Node node) {
303         return InstanceIdentifier.builder(NetworkTopology.class)
304                 .child(Topology.class, new TopologyKey(TOPOLOGY_ID))
305                 .child(Node.class, new NodeKey(node.getNodeId()))
306                 .build();
307     }
308
309     private boolean isCapableNetconfDevice(final Node node, final NetconfNode netconfAugmentation) {
310         if (netconfAugmentation.getAvailableCapabilities() == null
311                 || netconfAugmentation.getAvailableCapabilities().getAvailableCapability() == null
312                 || netconfAugmentation.getAvailableCapabilities().getAvailableCapability().isEmpty()) {
313             LOG.warn("Node {} does not contain any capabilities", node.getNodeId().getValue());
314             return false;
315         }
316         if (!capabilityCheck(netconfAugmentation.getAvailableCapabilities().getAvailableCapability())) {
317             LOG.warn("Node {} does not contain all capabilities required by vpp-renderer", node.getNodeId().getValue());
318             return false;
319         }
320         return true;
321     }
322
323     private boolean capabilityCheck(final List<AvailableCapability> capabilities) {
324         final List<String> availableCapabilities = capabilities.stream()
325                 .map(AvailableCapability::getCapability)
326                 .collect(Collectors.toList());
327         return requiredCapabilities.stream()
328                 .allMatch(availableCapabilities::contains);
329     }
330
331     private NetconfNode getNodeAugmentation(final Node node) {
332         final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
333         if (netconfNode == null) {
334             LOG.warn("Node {} is not a netconf device", node.getNodeId().getValue());
335             return null;
336         }
337         return netconfNode;
338     }
339
340     /**
341      * Initialize all common capabilities required by VPP renderer. Any connected node is examined
342      * whether it's
343      * an appropriate device to handle configuration created by this renderer. A device must support
344      * all capabilities
345      * in list below.
346      *
347      * @return list of string representations of required capabilities
348      */
349     private List<String> initializeRequiredCapabilities() {
350         // Required device capabilities
351         String[] capabilityEntries = {V3PO_CAPABILITY, INTERFACES_CAPABILITY};
352         return Arrays.asList(capabilityEntries);
353     }
354
355     // TODO bug 7699
356     // This works as a workaround for mountpoint registration in cluster. If application is registered on different
357     // node as netconf service, it obtains mountpoint registered by SlaveSalFacade (instead of MasterSalFacade). However
358     // this service registers mountpoint a moment later then connectionStatus is set to "Connected". If NodeManager hits
359     // state where device is connected but mountpoint is not yet available, try to get it again in a while
360     private Future<Optional<MountPoint>> getMountpointFromSal(final InstanceIdentifier<Node> iid) {
361         final ExecutorService executorService = Executors.newSingleThreadExecutor();
362         final Callable<Optional<MountPoint>> task = () -> {
363             byte attempt = 0;
364             do {
365                 try {
366                     final Optional<MountPoint> optionalMountpoint = mountService.getMountPoint(iid);
367                     if (optionalMountpoint.isPresent()) {
368                         return optionalMountpoint;
369                     }
370                     LOG.warn("Mountpoint {} is not registered yet", iid);
371                     Thread.sleep(DURATION);
372                 } catch (InterruptedException e) {
373                     LOG.warn("Thread interrupted to ", e);
374                 }
375                 attempt++;
376             } while (attempt <= 3);
377             return Optional.absent();
378         };
379         return executorService.submit(task);
380     }
381
382     private void syncPhysicalInterfacesInLocalDs(DataBroker mountPointDataBroker, InstanceIdentifier<Node> nodeIid) {
383         ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
384         ReadOnlyTransaction rTx = mountPointDataBroker.newReadOnlyTransaction();
385         Optional<Interfaces> readIfaces = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,
386                 InstanceIdentifier.create(Interfaces.class), rTx);
387         if (readIfaces.isPresent()) {
388             InstanceIdentifier<RendererNode> rendererNodeIid = VppIidFactory.getRendererNodesIid()
389                 .builder()
390                 .child(RendererNode.class, new RendererNodeKey(nodeIid))
391                 .build();
392             Optional<RendererNode> optRendNode = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
393                     rendererNodeIid, rwTx);
394             NodeId nodeId = nodeIid.firstKeyOf(Node.class).getNodeId();
395             RendererNode rendNode = new RendererNodeBuilder(optRendNode.get())
396                 .addAugmentation(VppInterfaceAugmentation.class, resolveTerminationPoints(nodeId, readIfaces.get()))
397                 .build();
398             rwTx.put(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodeIid(optRendNode.get()), rendNode,
399                     true);
400         }
401         rTx.close();
402         DataStoreHelper.submitToDs(rwTx);
403     }
404
405     private VppInterfaceAugmentation resolveTerminationPoints(NodeId nodeId, Interfaces interfaces) {
406         List<PhysicalInterface> phIfaces = new ArrayList<>();
407         if (interfaces != null && interfaces.getInterface() != null) {
408             interfaces.getInterface()
409                 .stream()
410                 .filter(iface -> iface.getType().equals(EthernetCsmacd.class))
411                 .filter(iface -> iface.getAugmentation(Interface1.class) != null)
412                 .forEach(iface -> {
413                     PhysicalInterfaceBuilder phIface = new PhysicalInterfaceBuilder();
414                     phIface.setInterfaceName(iface.getName());
415                     phIface.setType(iface.getType());
416                     phIface.setAddress(resolveIpAddress(iface.getAugmentation(Interface1.class)));
417                     PhysicalInterfaces physicalInterfaces = hostRelatedInfoContainer
418                                                                         .getPhysicalInterfaceState(nodeId.getValue());
419                     if (physicalInterfaces == null) {
420                         physicalInterfaces = new PhysicalInterfaces();
421                         hostRelatedInfoContainer.setPhysicalInterfaceStateOfHost(nodeId.getValue(), physicalInterfaces);
422                     }
423
424
425                     if (extInterfaces.get(nodeId) != null
426                             && extInterfaces.get(nodeId).getInterfaceName().equals(phIface.getInterfaceName())) {
427                         phIface.setExternal(true);
428                         extInterfaces.put(nodeId, new PhysicalInterfaceKey(iface.getName()));
429                         physicalInterfaces
430                                 .addPhysicalInterfaceInfo(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC,
431                                         phIface.getInterfaceName(), phIface.getAddress().get(0));
432                         LOG.info("Interface {} is marked as public interface based on bundle configuration.",
433                                 iface.getName());
434                     }
435                     if (PUBLIC_INTERFACE.equals(iface.getDescription())) {
436                         phIface.setExternal(true);
437                         extInterfaces.put(nodeId, new PhysicalInterfaceKey(iface.getName()));
438                         physicalInterfaces
439                                 .addPhysicalInterfaceInfo(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC,
440                                         phIface.getInterfaceName(), phIface.getAddress().get(0));
441                         LOG.info("Interface {} is marked as public interface based on HC configuration.",
442                                 iface.getName());
443                     }
444                     phIfaces.add(phIface.build());
445                 });
446         }
447         return new VppInterfaceAugmentationBuilder().setPhysicalInterface(phIfaces).build();
448     }
449
450     private List<IpAddress> resolveIpAddress(Interface1 iface) {
451         if (iface.getIpv4() != null && iface.getIpv4().getAddress() != null) {
452             return iface.getIpv4().getAddress().stream().map(ipv4 ->
453                     new IpAddress(new Ipv4Address(ipv4.getIp().getValue()))).collect(Collectors.toList());
454         } else if (iface.getIpv6() != null && iface.getIpv6().getAddress() != null) {
455             return iface.getIpv6().getAddress().stream().map(ipv6 ->
456                     new IpAddress(new Ipv4Address(ipv6.getIp().getValue()))).collect(Collectors.toList());
457         }
458         return Lists.newArrayList();
459     }
460
461     public static Map<NodeId, String> resolvePublicInterfaces(ReadTransaction rTx) {
462         Map<NodeId, String> nodes = new HashMap<>();
463         Optional<RendererNodes> rendNodes =
464                 DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL, VppIidFactory.getRendererNodesIid(), rTx);
465         if (!rendNodes.isPresent()) {
466             return nodes;
467         }
468         rendNodes.get()
469             .getRendererNode()
470             .stream()
471             .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class) != null)
472             .filter(rn -> rn.getAugmentation(VppInterfaceAugmentation.class).getPhysicalInterface() != null)
473             .forEach(rn -> {
474                 java.util.Optional<PhysicalInterface> pubInt = rn.getAugmentation(VppInterfaceAugmentation.class)
475                     .getPhysicalInterface()
476                     .stream()
477                     .filter(phInt -> phInt.isExternal())
478                     .findFirst();
479                 if (pubInt.isPresent()) {
480                     nodes.put(rn.getNodePath().firstKeyOf(Node.class).getNodeId(), pubInt.get().getInterfaceName());
481                 }
482             });
483         return nodes;
484     }
485 }