EvpnNlriParser.serializeNlri(Collections.singletonList(dest), buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
evpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf
= destination.getChild(routePathIdNid());
final String routeKeyValue = this.nlriParser.stringNlri(destination);
- final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), routeKeyValue, maybePathIdLeaf);
+ final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ routeKeyValue, maybePathIdLeaf);
function.apply(tx, base, routeKey, destination, attributes);
return Collections.singletonList(routeKey);
prefixes.getChild(routePathIdNid());
Preconditions.checkState(maybePrefixLeaf.isPresent());
final Object prefixValue = maybePrefixLeaf.get().getValue();
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), prefixValue, maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(), prefixValue, maybePathIdLeaf);
}
}
L3vpnMcastNlriSerializer.serializeNlri(Collections.singletonList(dest), buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
l3vpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
L3vpnMcastNlriSerializer.serializeNlri(Collections.singletonList(dest), buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
l3vpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
l3vpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
final String routeKeyValue = ByteArray.encodeBase64(buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf
= labeledUnicast.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(), routeKeyValue, maybePathIdLeaf);
}
/**
SimpleNlriTypeRegistry.getInstance().serializeNlriType(cLinkstateDestination, buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
linkstate.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
private static List<CLinkstateDestination> extractRoutes(final Collection<MapEntryNode> routes) {
Ipv4NlriHandler.serializeNlri(Collections.singletonList(dest), buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
mvpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
Ipv6NlriHandler.serializeNlri(Collections.singletonList(dest), buffer);
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
mvpn.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
.serializeRouteTargetConstrain(dest.getRouteTargetConstrainChoice()));
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
routeTarget.getChild(routePathIdNid());
- return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
- pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
+ return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
+ ByteArray.encodeBase64(buffer), maybePathIdLeaf);
}
@Override
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>util</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-common</artifactId>
package org.opendaylight.protocol.bgp.parser.spi;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
import io.netty.buffer.ByteBuf;
import java.util.Optional;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
+import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
return (Long) NormalizedNodes.findNode(data, pathNii).map(NormalizedNode::getValue).orElse(null);
}
- public static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname,
- final QName pathidQname, final Object pathId,
- final QName routeKeyQname, final Object keyObject) {
- final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, routeKeyQname, keyObject);
- return new NodeIdentifierWithPredicates(routeQname, keyValues);
- }
-
/**
* Build Path Id.
*
* Build Route Key for supporting mp.
* Key is composed by 2 elements (route-key + path Id).
*
- * @param routeQname route Qname
- * @param routeKeyQname route key Qname
- * @param pathIdQname path Id Qname
- * @param routeKeyValue route key value
- * @param maybePathIdLeaf path id container, it might me supported or not, in that case default 0 value will
- * be
- * assigned
+ * @param routeQName route QName
+ * @param routeKeyTemplate route key template
+ * @param routeKeyValue route key value
+ * @param maybePathIdLeaf path id container, it might me supported or not, in that case default 0 value will
+ * be assigned
* @return Route Key Nid
*/
- public static NodeIdentifierWithPredicates createNidKey(final QName routeQname, final QName routeKeyQname,
- final QName pathIdQname, final Object routeKeyValue,
+ public static NodeIdentifierWithPredicates createNidKey(final QName routeQName,
+ final ImmutableOffsetMapTemplate<QName> routeKeyTemplate, final Object routeKeyValue,
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf) {
// FIXME: a cache here would mean we instantiate the same identifier for each route making comparison quicker.
final Object pathId = maybePathIdLeaf.isPresent() ? maybePathIdLeaf.get().getValue() : NON_PATH_ID_VALUE;
- return createNodeIdentifierWithPredicates(routeQname, pathIdQname, pathId, routeKeyQname, routeKeyValue);
+ return new NodeIdentifierWithPredicates(routeQName,
+ routeKeyTemplate.instantiateWithValues(pathId, routeKeyValue));
}
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisherBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.CNextHop;
+import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.ChoiceIn;
import org.opendaylight.yangtools.yang.binding.DataObject;
private final Class<? extends AddressFamily> afiClass;
private final Class<? extends SubsequentAddressFamily> safiClass;
private final NodeIdentifier destinationNid;
- private final QName pathIdQname;
private final NodeIdentifier pathIdNid;
- private final QName routeKeyQname;
private final NodeIdentifier prefixTypeNid;
private final NodeIdentifier rdNid;
protected final BindingNormalizedNodeSerializer mappingService;
protected final YangInstanceIdentifier routeDefaultYii;
private final TablesKey tk;
private final ImmutableList<PathArgument> relativeRoutesPath;
+ private final ImmutableOffsetMapTemplate<QName> routeKeyTemplate;
/**
* Default constructor. Requires the QName of the container augmented under the routes choice
this.afiClass = afiClass;
this.safiClass = safiClass;
this.destinationNid = NodeIdentifier.create(destContainerQname);
- this.pathIdQname = QName.create(routeQName(), "path-id").intern();
- this.pathIdNid = NodeIdentifier.create(this.pathIdQname);
- this.routeKeyQname = QName.create(routeQName(), ROUTE_KEY).intern();
+ this.pathIdNid = NodeIdentifier.create(QName.create(routeQName(), "path-id").intern());
this.prefixTypeNid = NodeIdentifier.create(QName.create(destContainerQname, "prefix").intern());
this.rdNid = NodeIdentifier.create(QName.create(destContainerQname, "route-distinguisher").intern());
this.routeDefaultYii =
.node(this.routesListIdentifier)
.node(this.routesListIdentifier).build();
this.relativeRoutesPath = ImmutableList.of(routesContainerIdentifier, routesListIdentifier);
+ this.routeKeyTemplate = ImmutableOffsetMapTemplate.ordered(
+ ImmutableList.of(this.pathIdNid.getNodeType(), QName.create(routeQName(), ROUTE_KEY).intern()));
}
@Override
return this.pathIdNid;
}
- protected final QName pathIdQName() {
- return this.pathIdQname;
- }
-
- protected final QName routeKeyQName() {
- return this.routeKeyQname;
+ protected final ImmutableOffsetMapTemplate<QName> routeKeyTemplate() {
+ return this.routeKeyTemplate;
}
protected final String extractPrefix(final DataContainerNode<? extends PathArgument> route) {
return customizer;
}
- @Test
- public void pathIdQName() {
- assertEquals(PATH_ID_QNAME,this.ribSupportTestImp.pathIdQName());
- }
-
@Test
public void routesCaseClass() {
- assertEquals(Ipv4RoutesCase.class,this.ribSupportTestImp.routesCaseClass());
+ assertEquals(Ipv4RoutesCase.class, this.ribSupportTestImp.routesCaseClass());
}
@Test
public void routesContainerClass() {
- assertEquals(Ipv4Routes.class,this.ribSupportTestImp.routesContainerClass());
+ assertEquals(Ipv4Routes.class, this.ribSupportTestImp.routesContainerClass());
}
@Test
public void routesListClass() {
- assertEquals(Ipv4Route.class,this.ribSupportTestImp.routesListClass());
+ assertEquals(Ipv4Route.class, this.ribSupportTestImp.routesListClass());
}
@Test
public void routeQName() {
- assertEquals(Ipv4Route.QNAME,this.ribSupportTestImp.routeQName());
+ assertEquals(Ipv4Route.QNAME, this.ribSupportTestImp.routeQName());
}
@Test