BUG-5844: Fix ComplexRouteEntry creation
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / spi / RouteEntryUtil.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.protocol.bgp.mode.spi;
10
11 import org.opendaylight.protocol.bgp.mode.api.BestPath;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
17
18 final public class RouteEntryUtil {
19     public static MapEntryNode createSimpleRouteValue(final PathArgument routeId, final BestPath path) {
20         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = Builders.mapEntryBuilder();
21         b.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
22         b.addChild(path.getAttributes());
23         return b.build();
24     }
25
26     public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path, final MapEntryNode mapValues) {
27         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder();
28         mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
29         mapEntryBuilder.addChild(path.getAttributes());
30         mapValues.getValue().forEach(mapEntryBuilder::addChild);
31         return mapEntryBuilder.build();
32     }
33 }