use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder in project netvirt by opendaylight.
the class NatUtil method addPrefixToInterface.
static void addPrefixToInterface(DataBroker broker, long vpnId, String interfaceName, String ipPrefix, BigInteger dpId, Uuid subnetId, Prefixes.PrefixCue prefixCue) {
InstanceIdentifier<Prefixes> prefixId = InstanceIdentifier.builder(PrefixToInterface.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.VpnIds.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.VpnIdsKey(vpnId)).child(Prefixes.class, new PrefixesKey(ipPrefix)).build();
PrefixesBuilder prefixBuilder = new PrefixesBuilder().setDpnId(dpId).setIpAddress(ipPrefix);
prefixBuilder.setVpnInterfaceName(interfaceName).setSubnetId(subnetId).setPrefixCue(prefixCue);
try {
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, prefixId, prefixBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("addPrefixToInterface : Failed to write prefxi-to-interface for {} vpn-id {} DPN {}", ipPrefix, vpnId, dpId, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder in project netvirt by opendaylight.
the class VrfEntryListener method deleteLocalFibEntry.
public List<BigInteger> deleteLocalFibEntry(Long vpnId, String rd, VrfEntry vrfEntry) {
List<BigInteger> returnLocalDpnId = new ArrayList<>();
Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
String vpnName = fibUtil.getVpnNameFromId(vpnId);
boolean isExtraroute = false;
if (localNextHopInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
if (usedRds.size() > 1) {
LOG.error("The extra route prefix {} is still present in some DPNs in vpn {} on rd {}", vrfEntry.getDestPrefix(), vpnName, rd);
return returnLocalDpnId;
}
// Is this fib route an extra route? If yes, get the nexthop which would be an adjacency
// in the vpn
Optional<Routes> extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, rd, vrfEntry.getDestPrefix());
if (extraRouteOptional.isPresent()) {
isExtraroute = true;
Routes extraRoute = extraRouteOptional.get();
String ipPrefix;
if (isIpv4Address(extraRoute.getNexthopIpList().get(0))) {
ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV4PREFIX;
} else {
ipPrefix = extraRoute.getNexthopIpList().get(0) + NwConstants.IPV6PREFIX;
}
localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
if (localNextHopInfo != null) {
String localNextHopIP = localNextHopInfo.getIpAddress();
BigInteger dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, isExtraroute, vpnId);
if (!dpnId.equals(BigInteger.ZERO)) {
LOG.trace("Deleting ECMP group for prefix {}, dpn {}", vrfEntry.getDestPrefix(), dpnId);
nextHopManager.setupLoadBalancingNextHop(vpnId, dpnId, vrfEntry.getDestPrefix(), /*listBucketInfo*/
Collections.emptyList(), /*remove*/
false);
returnLocalDpnId.add(dpnId);
}
} else {
LOG.error("localNextHopInfo unavailable while deleting prefix {} with rds {}, primary rd {} in " + "vpn {}", vrfEntry.getDestPrefix(), usedRds, rd, vpnName);
}
}
if (localNextHopInfo == null) {
/* Imported VRF entry */
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());
BigInteger dpnId = checkDeleteLocalFibEntry(prefixBuilder.build(), nextHopAddressList.get(0), vpnId, rd, vrfEntry, isExtraroute, lri.getParentVpnid());
if (!dpnId.equals(BigInteger.ZERO)) {
returnLocalDpnId.add(dpnId);
}
}
}
}
} else {
LOG.debug("Obtained prefix to interface for rd {} prefix {}", rd, vrfEntry.getDestPrefix());
String localNextHopIP = localNextHopInfo.getIpAddress();
BigInteger dpnId = checkDeleteLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, isExtraroute, vpnId);
if (!dpnId.equals(BigInteger.ZERO)) {
returnLocalDpnId.add(dpnId);
}
}
return returnLocalDpnId;
}
use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.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.setKey(pk);
pb.setPrefix(ippfx);
final PrefixAttributes pa;
// Very defensive lookup
final Attributes1 attr = attributes.getAugmentation(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;
}
if (pa != null) {
pb.setMetric(pa.getPrefixMetric().getValue());
}
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);
putNode(trans, nh);
} else {
nh.addPrefix(pfx);
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.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder in project bgpcep by opendaylight.
the class AbstractReachabilityTopologyBuilder method createObject.
@Override
protected final void createObject(final ReadWriteTransaction trans, final InstanceIdentifier<T> id, final T value) {
final NodeId ni = advertizingNode(getAttributes(value));
if (ni == null) {
return;
}
final InstanceIdentifier<IgpNodeAttributes> nii = ensureNodePresent(trans, ni);
final IpPrefix prefix = getPrefix(value);
final PrefixKey pk = new PrefixKey(prefix);
trans.put(LogicalDatastoreType.OPERATIONAL, nii.child(Prefix.class, pk), new PrefixBuilder().setKey(pk).setPrefix(prefix).build());
}
use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder in project bgpcep by opendaylight.
the class IPv4RIBSupport method extractPrefixes.
private List<Ipv4Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
final List<Ipv4Prefixes> prefs = new ArrayList<>(routes.size());
for (final MapEntryNode route : routes) {
final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue();
final Ipv4PrefixesBuilder prefixBuilder = new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix(prefix));
prefixBuilder.setPathId(PathIdUtil.buildPathId(route, routePathIdNid()));
prefs.add(prefixBuilder.build());
}
return prefs;
}
Aggregations