use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createPrefix.
private void createPrefix(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
if (ippfx == null) {
LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
return;
}
final PrefixBuilder pb = new PrefixBuilder();
final PrefixKey pk = new PrefixKey(ippfx);
pb.withKey(pk);
pb.setPrefix(ippfx);
final PrefixAttributes pa;
// Very defensive lookup
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
} else {
LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
} else {
LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
SrPrefix srPrefix = null;
if (pa != null) {
if (pa.getPrefixMetric() != null) {
pb.setMetric(pa.getPrefixMetric().getValue());
}
if (pa.getSrPrefix() != null) {
srPrefix = pa.getSrPrefix();
}
}
ProtocolUtil.augmentProtocolId(value, pa, pb);
final Prefix pfx = pb.build();
LOG.debug("Created prefix {} for {}", pfx, prefixCase);
/*
* All set, but... the hosting node may not exist, we may need to fake it.
*/
final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
NodeHolder nh = this.nodes.get(node);
if (nh == null) {
nh = getNode(node);
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, false, ippfx, srPrefix);
}
putNode(trans, nh);
} else {
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, true, ippfx, srPrefix);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder in project bgpcep by opendaylight.
the class LinkstateGraphBuilder method createEdge.
/**
* Create new Connected Edge in the Connected Graph.
*
* @param value The complete Linkstate route information
* @param linkCase The Link part of the Linkstate route
* @param attributes The Link attributes
*/
private void createEdge(final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
checkArgument(checkLinkState(linkCase), "Missing mandatory information in link {}", linkCase);
final LinkAttributes la = getLinkAttributes(attributes);
if (la == null) {
LOG.warn("Missing attributes in link {} route {}, skipping it", linkCase, value);
return;
}
/* Get Source and Destination Vertex from the graph */
Uint64 srcId = getVertexId(linkCase.getLocalNodeDescriptors().getCRouterIdentifier());
Uint64 dstId = getVertexId(linkCase.getRemoteNodeDescriptors().getCRouterIdentifier());
if (srcId == Uint64.ZERO || dstId == Uint64.ZERO) {
LOG.warn("Unable to get the Source or Destination Vertex Identifier from link {}, skipping it", linkCase);
return;
}
/* Get Source and Destination Key for the corresponding Edge */
Uint64 edgeId = getEdgeId(linkCase);
if (edgeId == Uint64.ZERO) {
LOG.warn("Unable to get the Edge Identifier from link {}, skipping it", linkCase);
return;
}
/* Add associated Edge */
Edge edge = new EdgeBuilder().setEdgeId(edgeId).setLocalVertexId(srcId).setRemoteVertexId(dstId).setName(srcId + " - " + dstId).setEdgeAttributes(createEdgeAttributes(la, linkCase.getLinkDescriptors())).build();
/*
* Add corresponding Prefix for the Local Address. Remote address will be added with the remote Edge */
final var localAddress = edge.getEdgeAttributes().getLocalAddress();
PrefixBuilder prefBuilder = new PrefixBuilder().setVertexId(srcId);
if (localAddress.getIpv4Address() != null) {
prefBuilder.setPrefix(new IpPrefix(IetfInetUtil.INSTANCE.ipv4PrefixFor(localAddress.getIpv4Address())));
}
if (localAddress.getIpv6Address() != null) {
prefBuilder.setPrefix(new IpPrefix(IetfInetUtil.INSTANCE.ipv6PrefixFor(localAddress.getIpv6Address())));
}
Prefix prefix = prefBuilder.build();
/* Add the Edge in the Connected Graph */
LOG.info("Add Edge {} and associated Prefix {} in TED[{}]", edge.getName(), prefix.getPrefix(), cgraph);
cgraph.addEdge(edge);
cgraph.addPrefix(prefix);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpOpDataForFib.
protected void cleanUpOpDataForFib(Long vpnId, String primaryRd, final VrfEntry vrfEntry) {
/* Get interface info from prefix to interface mapping;
Use the interface info to get the corresponding vpn interface op DS entry,
remove the adjacency corresponding to this fib entry.
If adjacency removed is the last adjacency, clean up the following:
- vpn interface from dpntovpn list, dpn if last vpn interface on dpn
- prefix to interface entry
- vpn interface op DS
*/
LOG.debug("Cleanup of prefix {} in VPN {}", vrfEntry.getDestPrefix(), vpnId);
Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
if (prefixInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
String usedRd = usedRds.isEmpty() ? primaryRd : usedRds.get(0);
Routes extraRoute = baseVrfEntryHandler.getVpnToExtraroute(vpnId, usedRd, vrfEntry.getDestPrefix());
if (extraRoute != null) {
for (String nextHopIp : extraRoute.getNexthopIpList()) {
LOG.debug("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
if (nextHopIp != null) {
String ipPrefix;
if (isIpv4Address(nextHopIp)) {
ipPrefix = nextHopIp + NwConstants.IPV4PREFIX;
} else {
ipPrefix = nextHopIp + NwConstants.IPV6PREFIX;
}
prefixInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
if (prefixInfo == null) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
Long label = optionalLabel.get();
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
PrefixesBuilder prefixBuilder = new PrefixesBuilder();
prefixBuilder.setDpnId(lri.getDpnId());
prefixBuilder.setVpnInterfaceName(lri.getVpnInterfaceName());
prefixBuilder.setIpAddress(lri.getPrefix());
prefixInfo = prefixBuilder.build();
LOG.debug("Fetched labelRouteInfo for label {} interface {} and got dpn {}", label, prefixInfo.getVpnInterfaceName(), lri.getDpnId());
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
} else {
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, null);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder in project netvirt by opendaylight.
the class VrfEntryListener method updateVpnReferencesInLri.
private Prefixes updateVpnReferencesInLri(LabelRouteInfo lri, String vpnInstanceName, boolean isPresentInList) {
LOG.debug("updating LRI : for label {} vpninstancename {}", lri.getLabel(), vpnInstanceName);
PrefixesBuilder prefixBuilder = new PrefixesBuilder();
prefixBuilder.setDpnId(lri.getDpnId());
prefixBuilder.setVpnInterfaceName(lri.getVpnInterfaceName());
prefixBuilder.setIpAddress(lri.getPrefix());
// Increment the refCount here
InstanceIdentifier<LabelRouteInfo> lriId = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(lri.getLabel())).build();
LabelRouteInfoBuilder builder = new LabelRouteInfoBuilder(lri);
if (!isPresentInList) {
LOG.debug("vpnName {} is not present in LRI with label {}..", vpnInstanceName, lri.getLabel());
List<String> vpnInstanceNames = lri.getVpnInstanceList() != null ? new ArrayList<>(lri.getVpnInstanceList()) : new ArrayList<>();
vpnInstanceNames.add(vpnInstanceName);
builder.setVpnInstanceList(vpnInstanceNames);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId, builder.build());
} else {
LOG.debug("vpnName {} is present in LRI with label {}..", vpnInstanceName, lri.getLabel());
}
return prefixBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.PrefixBuilder in project bgpcep by opendaylight.
the class LinkstateNlriParser method serializeAdvertisedNodeDescriptor.
private static void serializeAdvertisedNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
// prefix node descriptors
final PrefixCaseBuilder prefixBuilder = new PrefixCaseBuilder();
prefixBuilder.setAdvertisingNodeDescriptors(NodeNlriParser.serializeAdvNodeDescriptors((ContainerNode) objectType.findChildByArg(ADVERTISING_NODE_DESCRIPTORS_NID).get()));
// prefix descriptors
objectType.findChildByArg(PREFIX_DESCRIPTORS_NID).ifPresent(dataContainerChild -> prefixBuilder.setPrefixDescriptors(AbstractPrefixNlriParser.serializePrefixDescriptors((ContainerNode) dataContainerChild)));
builder.setObjectType(prefixBuilder.build());
}
Aggregations