use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry in project netvirt by opendaylight.
the class VpnRpcServiceImpl method addStaticRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
String destination = input.getDestination();
String vpnInstanceName = input.getVpnInstanceName();
String nexthop = input.getNexthop();
Long label = input.getLabel();
LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
if (!rpcErrors.isEmpty()) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
return result;
}
if (label == null || label == 0) {
label = (long) VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
if (label == 0) {
String message = "Unable to retrieve a new Label for the new Route";
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
}
String vpnRd = VpnUtil.getVpnRd(dataBroker, input.getVpnInstanceName());
VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
if (vpnRd == null) {
String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
return result;
}
Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
if (optIVpnLink.isPresent()) {
try {
InterVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label.intValue(), dataBroker, fibManager, bgpManager);
} catch (Exception e) {
result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
return result;
}
} else {
vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
null, /*Adjacency*/
encapType, null);
}
AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
result.set(RpcResultBuilder.success(labelOutput).build());
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry in project netvirt by opendaylight.
the class L3vpnPopulator method addToLabelMapper.
public void addToLabelMapper(Long label, BigInteger dpnId, String prefix, List<String> nextHopIpList, Long vpnId, String vpnInterfaceName, Long elanTag, boolean isSubnetRoute, String rd) {
Preconditions.checkNotNull(label, "addToLabelMapper: label cannot be null or empty!");
Preconditions.checkNotNull(prefix, "addToLabelMapper: prefix cannot be null or empty!");
Preconditions.checkNotNull(vpnId, "addToLabelMapper: vpnId cannot be null or empty!");
Preconditions.checkNotNull(rd, "addToLabelMapper: rd cannot be null or empty!");
if (!isSubnetRoute) {
// NextHop must be present for non-subnetroute entries
Preconditions.checkNotNull(nextHopIpList, "addToLabelMapper: nextHopIp cannot be null or empty!");
}
synchronized (label.toString().intern()) {
addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
LOG.info("addToLabelMapper: label {} dpn {} prefix {} nexthoplist {} vpnid {} vpnIntfcName {} rd {}" + " elanTag {}", label, dpnId, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
if (dpnId != null) {
LabelRouteInfoBuilder lriBuilder = new LabelRouteInfoBuilder();
lriBuilder.setLabel(label).setDpnId(dpnId).setPrefix(prefix).setNextHopIpList(nextHopIpList).setParentVpnid(vpnId).setIsSubnetRoute(isSubnetRoute);
if (elanTag != null) {
lriBuilder.setElanTag(elanTag);
} else {
LOG.warn("addToLabelMapper: elanTag is null for label {} prefix {} rd {} vpnId {}", label, prefix, rd, vpnId);
}
if (vpnInterfaceName != null) {
lriBuilder.setVpnInterfaceName(vpnInterfaceName);
} else {
LOG.warn("addToLabelMapper: vpn interface is null for label {} prefix {} rd {} vpnId {}", label, prefix, rd, vpnId);
}
lriBuilder.setParentVpnRd(rd);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = VpnUtil.getVpnInstanceOpData(broker, rd);
if (vpnInstanceOpDataEntry != null) {
List<String> vpnInstanceNames = Collections.singletonList(vpnInstanceOpDataEntry.getVpnInstanceName());
lriBuilder.setVpnInstanceList(vpnInstanceNames);
}
LabelRouteInfo lri = lriBuilder.build();
InstanceIdentifier<LabelRouteInfo> lriIid = InstanceIdentifier.builder(LabelRouteMap.class).child(LabelRouteInfo.class, new LabelRouteInfoKey(label)).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, lriIid, lri, true);
LOG.info("addToLabelMapper: Added label route info to label {} prefix {} nextHopList {} vpnId {}" + " interface {} rd {} elantag {}", label, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
} else {
LOG.warn("addToLabelMapper: Can't add entry to label map for label {} prefix {} nextHopList {}" + " vpnId {} interface {} rd {} elantag {}, dpnId is null", label, prefix, nextHopIpList, vpnId, vpnInterfaceName, rd, elanTag);
}
}), LOG, "addToLabelMapper");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry in project netvirt by opendaylight.
the class FibEntriesListener method addLabelToVpnInstance.
private void addLabelToVpnInstance(String rd, List<RoutePaths> routePaths) {
List<Long> labels = routePaths.stream().map(RoutePaths::getLabel).distinct().collect(Collectors.toList());
VpnInstanceOpDataEntry vpnInstanceOpData = vpnInstanceListener.getVpnInstanceOpData(rd);
if (vpnInstanceOpData != null) {
List<Long> routeIds = vpnInstanceOpData.getRouteEntryId() == null ? new ArrayList<>() : vpnInstanceOpData.getRouteEntryId();
labels.forEach(label -> {
LOG.debug("Adding label to vpn info - {}", label);
if (!routeIds.contains(label)) {
routeIds.add(label);
}
});
TransactionUtil.asyncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(rd), new VpnInstanceOpDataEntryBuilder(vpnInstanceOpData).setRouteEntryId(routeIds).build(), TransactionUtil.DEFAULT_CALLBACK);
} else {
LOG.warn("No VPN Instance found for RD: {}", rd);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry in project netvirt by opendaylight.
the class BgpConfigurationManager method onUpdateWithdrawRoute.
public void onUpdateWithdrawRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress) {
long vni = 0L;
boolean macupdate = false;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
vni = vpnInstanceOpDataEntry.getL3vni();
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.debug("Got RT2 withdraw for RD {} {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), vni, nextHop, macaddress, rd);
deleteTepfromElanDS(rd, nextHop, macaddress);
LOG.debug("For rd {}. skipping fib update", rd);
macupdate = true;
}
} else {
LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
return;
}
}
if (macupdate) {
LOG.info("Removing Mac Fib entry rd {} mac{} nexthop {} ", rd, macaddress, nextHop);
fibDSWriter.removeMacEntryFromDS(rd, macaddress);
LOG.info("Removed Mac Fib entry rd {} prefix {} nexthop {} ", rd, macaddress, nextHop);
} else {
LOG.info("REMOVE: Removing Fib entry rd {} prefix {}", rd, prefix);
fibDSWriter.removeOrUpdateFibEntryFromDS(rd, prefix + "/" + plen, nextHop);
LOG.info("REMOVE: Removed Fib entry rd {} prefix {}", rd, prefix);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry in project netvirt by opendaylight.
the class BgpConfigurationManager method onUpdatePushRoute.
/* onUpdatePushRoute
* Get Stale fibDSWriter map, and compare current route/fibDSWriter entry.
* - Entry compare shall include NextHop, Label.
* - If entry matches: delete from STALE Map. NO Change to FIB Config DS.
* - If entry not found, add to FIB Config DS.
* - If entry found, but either Label/NextHop doesn't match.
* - Update FIB Config DS with modified values.
* - delete from Stale Map.
*/
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress, int label, int l2label, String routermac, af_afi afi) {
boolean addroute = false;
boolean macupdate = false;
long l3vni = 0L;
VrfEntry.EncapType encapType = VrfEntry.EncapType.Mplsgre;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
encapType = VrfEntry.EncapType.Vxlan;
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.info("Got RT2 route for RD {} l3label {} l2label {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), label, l2label, nextHop, macaddress, rd);
addTepToElanDS(rd, nextHop, macaddress, (long) l2label);
macupdate = true;
} else {
l3vni = vpnInstanceOpDataEntry.getL3vni();
}
} else {
LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
return;
}
}
if (!staledFibEntriesMap.isEmpty()) {
// restart Scenario, as MAP is not empty.
Map<String, Long> map = staledFibEntriesMap.get(rd);
if (map != null) {
String prefixNextHop = appendNextHopToPrefix(prefix + "/" + plen, nextHop);
Long labelInStaleMap = map.get(prefixNextHop);
if (null == labelInStaleMap) {
// New Entry, which happened to be added during restart.
addroute = true;
} else {
map.remove(prefixNextHop);
if (isRouteModified(label, labelInStaleMap)) {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
// Existing entry, where in Label got modified during restart
addroute = true;
}
}
} else {
LOG.debug("rd {} map is null while processing prefix {} ", rd, prefix);
addroute = true;
}
} else {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
addroute = true;
}
if (macupdate) {
LOG.info("ADD: Adding Mac Fib entry rd {} mac{} nexthop {} l2vni {}", rd, macaddress, nextHop, l2label);
fibDSWriter.addMacEntryToDS(rd, macaddress, prefix, Collections.singletonList(nextHop), encapType, l2label, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Mac Fib entry rd {} prefix {} nexthop {} label {}", rd, macaddress, nextHop, l2label);
} else if (addroute) {
LOG.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {} afi {}", rd, prefix, nextHop, label, afi);
// TODO: modify addFibEntryToDS signature
List<String> nextHopList = Collections.singletonList(nextHop);
fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
String vpnName = bgpUtil.getVpnNameFromRd(rd);
if (vpnName != null) {
vpnLinkService.leakRouteIfNeeded(vpnName, prefix, nextHopList, label, RouteOrigin.BGP, NwConstants.ADD_FLOW);
}
}
}
Aggregations