use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method leakExtraRoutesToVpnEndpoint.
/*
* Checks if there are static routes in Vpn1 whose nexthop is Vpn2's endpoint.
* Those routes must be leaked to Vpn1.
*
* @param vpnLink
* @param vpn1Uuid
* @param vpn2Uuid
*/
private void leakExtraRoutesToVpnEndpoint(InterVpnLinkDataComposite vpnLink, String vpn1Uuid, String vpn2Uuid) {
String vpn1Rd = VpnUtil.getVpnRd(dataBroker, vpn1Uuid);
String vpn2Endpoint = vpnLink.getOtherEndpointIpAddr(vpn2Uuid);
List<VrfEntry> allVpnVrfEntries = VpnUtil.getAllVrfEntries(dataBroker, vpn1Rd);
for (VrfEntry vrfEntry : allVpnVrfEntries) {
vrfEntry.getRoutePaths().stream().filter(routePath -> routePath.getNexthopAddress().equals(vpn2Endpoint)).forEach(routePath -> {
// Vpn1 has a route pointing to Vpn2's endpoint. Forcing the leaking of the route will update
// the BGP accordingly
long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpn1Rd, vrfEntry.getDestPrefix()));
if (label == VpnConstants.INVALID_LABEL) {
LOG.error("Unable to fetch label from Id Manager. Bailing out of leaking extra routes for " + "InterVpnLink {} rd {} prefix {}", vpnLink.getInterVpnLinkName(), vpn1Rd, vrfEntry.getDestPrefix());
} else {
leakRoute(vpnLink, vpn2Uuid, vpn1Uuid, vrfEntry.getDestPrefix(), label, RouteOrigin.value(vrfEntry.getOrigin()));
}
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop in project netvirt by opendaylight.
the class IVpnLinkServiceImpl method handleStaticRoute.
/*
* Takes care of an static route to see if flows related to interVpnLink
* must be installed in tables 20 and 17
*
* @param vpnId Vpn to which the route belongs
* @param route Route to handle. Will only be considered if its nexthop is the VPN's endpoint IpAddress
* at the other side of the InterVpnLink
* @param iVpnLink
*/
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleStaticRoute(String vpnId, Routes route, InterVpnLinkDataComposite ivpnLink) {
IpAddress nhIpAddr = route.getNexthop();
String routeNextHop = nhIpAddr.getIpv4Address() != null ? nhIpAddr.getIpv4Address().getValue() : nhIpAddr.getIpv6Address().getValue();
String destination = String.valueOf(route.getDestination().getValue());
// is nexthop the other endpoint's IP
String otherEndpoint = ivpnLink.getOtherEndpoint(vpnId);
if (!routeNextHop.equals(otherEndpoint)) {
LOG.debug("VPN {}: Route to {} nexthop={} points to an InterVpnLink endpoint, but its not " + "the other endpoint. Other endpoint is {}", vpnId, destination, routeNextHop, otherEndpoint);
return;
}
// Lets work: 1) write Fibentry, 2) advertise to BGP and 3) check if it must be leaked
String vpnRd = VpnUtil.getVpnRd(dataBroker, vpnId);
if (vpnRd == null) {
LOG.warn("Could not find Route-Distinguisher for VpnName {}", vpnId);
return;
}
int label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnId, destination));
try {
InterVpnLinkUtil.handleStaticRoute(ivpnLink, vpnId, destination, routeNextHop, label, dataBroker, fibManager, bgpManager);
} catch (Exception e) {
LOG.error("Exception while advertising prefix for intervpn link, {}", e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop in project netvirt by opendaylight.
the class VpnManagerImpl method addExtraRoute.
@Override
public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID, int label, RouteOrigin origin) {
LOG.info("Adding extra route with destination {}, nextHop {}, label{} and origin {}", destination, nextHop, label, origin);
VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
addExtraRoute(vpnName, destination, nextHop, rd, routerID, vpnOpEntry.getL3vni(), origin, /*intfName*/
null, null, /*Adjacency*/
encapType, null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onPortAddedToSubnet.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onPortAddedToSubnet(Subnetmap subnetmap, Uuid portId) {
Uuid subnetId = subnetmap.getId();
LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.info("{} onPortAddedToSubnet: Port {} is part of a subnet {} that is not in VPN, ignoring", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
return;
}
String vpnName = optionalSubs.get().getVpnName();
String subnetIp = optionalSubs.get().getSubnetCidr();
String rd = optionalSubs.get().getVrfId();
String routeAdvState = optionalSubs.get().getRouteAdvState().toString();
LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {} subnetIp {} vpnName {} rd {} " + "TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, null);
Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, portId.getValue());
if (intfState == null) {
// Interface State not yet available
return;
}
final BigInteger dpnId;
try {
dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
} catch (Exception e) {
LOG.error("{} onPortAddedToSubnet: Unable to obtain dpnId for interface {}. subnetroute inclusion" + " for this interface failed for subnet {} subnetIp {} vpn {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, e);
return;
}
if (dpnId.equals(BigInteger.ZERO)) {
LOG.error("{} onPortAddedToSubnet: Port {} is not assigned DPN yet, ignoring subnetRoute " + "inclusion for the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
return;
}
subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, dpnId);
if (intfState.getOperStatus() != OperStatus.Up) {
LOG.error("{} onPortAddedToSubnet: Port {} is not UP yet, ignoring subnetRoute inclusion for " + "the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
return;
}
LOG.debug("{} onPortAddedToSubnet: Port {} added. Updating the SubnetOpDataEntry node for subnet {} " + "subnetIp {} vpnName {} rd {} TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
SubnetToDpn subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, portId.getValue());
if (subDpn == null) {
LOG.error("{} onPortAddedToSubnet: subnet-to-dpn list is null for subnetId {}. portId {}, " + "vpnName {}, rd {}, subnetIp {}", LOGGING_PREFIX, subnetId.getValue(), portId.getValue(), vpnName, rd, subnetIp);
return;
}
SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
subDpnList.add(subDpn);
subOpBuilder.setSubnetToDpn(subDpnList);
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
if (subOpBuilder.getNhDpnId() == null) {
// No nexthop selected yet, elect one now
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, subnetmap.getNetworkId(), true);
} else if (!VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue())) {
// Already nexthop has been selected, only publishing to bgp required, so publish to bgp
getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
}
}
SubnetOpDataEntry subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} onPortAddedToSubnet: Updated subnetopdataentry to OP Datastore for port {} subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpBuilder.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (Exception ex) {
LOG.error("{} onPortAddedToSubnet: Updation of subnetOpEntry for port {} subnet {} falied", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (Exception e) {
LOG.error("{} onPortAddedToSubnet: Unable to handle port {} added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method updateSubnetRouteOnTunnelUpEvent.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateSubnetRouteOnTunnelUpEvent(Uuid subnetId, BigInteger dpnId) {
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString());
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: SubnetOpDataEntry for subnet {} is not available", LOGGING_PREFIX, subnetId.getValue());
return;
}
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} subnetIp {} vpnName {} rd {} TaskState {}" + " lastTaskState {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState(), optionalSubs.get().getLastAdvState(), dpnId.toString());
SubnetOpDataEntry subOpEntry = optionalSubs.get();
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subOpEntry);
boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subOpEntry.getVpnName(), subnetId.getValue());
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
if (subOpBuilder.getNhDpnId() == null) {
// No nexthop selected yet, elect one now
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, null, /*networkId*/
!isExternalSubnetVpn);
} else if (!isExternalSubnetVpn) {
// Already nexthop has been selected, only publishing to bgp required, so publish to bgp
getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
}
}
subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Updated subnetopdataentry to OP Datastore tunnel up" + " on dpn {} for subnet {} subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, dpnId.toString(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpEntry.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (RuntimeException ex) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: updating subnetRoute for subnet {} on dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (RuntimeException e) {
LOG.error("{} updateSubnetRouteOnTunnelUpEvent: Unable to handle tunnel up event for subnetId {} dpnId {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), e);
}
}
Aggregations