use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State in project netvirt by opendaylight.
the class NexthopManager method removeOrUpdateDcGwLoadBalancingGroup.
/**
* This method is invoked when the tunnel state is removed from DS.
* If the there is just one DC-GW left in configuration then the LB groups can be deleted.
* Otherwise, the groups are just updated.
*/
public void removeOrUpdateDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp) {
Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
WriteTransaction operationalTx = dataBroker.newWriteOnlyTransaction();
int noOfDcGws = availableDcGws.size();
// If availableDcGws does not contain the destination Ip it means this is a configuration delete.
if (!availableDcGws.contains(destinationIp)) {
availableDcGws.add(destinationIp);
Collections.sort(availableDcGws);
}
// TODO : Place the logic to construct all possible DC-GW combination here.
int bucketId = availableDcGws.indexOf(destinationIp);
Optional<DpnLbNexthops> dpnLbNextHops = fibUtil.getDpnLbNexthops(dpnId, destinationIp);
if (!dpnLbNextHops.isPresent()) {
return;
}
List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
nextHopKeys.forEach(nextHopKey -> {
Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
if (!optionalNextHops.isPresent()) {
return;
}
Nexthops nexthops = optionalNextHops.get();
final String groupId = nexthops.getGroupId();
final long groupIdValue = Long.parseLong(groupId);
if (noOfDcGws > 1) {
mdsalApiManager.removeBucketToTx(dpnId, groupIdValue, bucketId, configTx);
} else {
Group group = MDSALUtil.buildGroup(groupIdValue, nextHopKey, GroupTypes.GroupSelect, MDSALUtil.buildBucketLists(Collections.emptyList()));
LOG.trace("Removed LB group {} on dpn {}", group, dpnId);
mdsalApiManager.removeGroupToTx(dpnId, group, configTx);
removeNextHopPointer(nextHopKey);
}
// When the DC-GW is removed from configuration.
if (noOfDcGws != availableDcGws.size()) {
FibUtil.removeOrUpdateNextHopInfo(dpnId, nextHopKey, groupId, nexthops, operationalTx);
}
});
FibUtil.removeDpnIdToNextHopInfo(destinationIp, dpnId, operationalTx);
configTx.submit();
operationalTx.submit();
return;
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State in project netvirt by opendaylight.
the class InterVpnLinkListener method add.
@Override
protected void add(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink add) {
String ivpnLinkName = add.getName();
LOG.debug("Reacting to IVpnLink {} creation. Vpn1=[name={} EndpointIp={}] Vpn2=[name={} endpointIP={}]", ivpnLinkName, add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(), add.getSecondEndpoint().getVpnUuid(), add.getSecondEndpoint().getIpAddress());
// Create VpnLink state
InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLinkName);
InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkState);
InterVpnLinkKey key = add.getKey();
Uuid vpn1Uuid = add.getFirstEndpoint().getVpnUuid();
String vpn1Name = vpn1Uuid.getValue();
Uuid vpn2Uuid = add.getSecondEndpoint().getVpnUuid();
String vpn2Name = vpn2Uuid.getValue();
String vpn1PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
String vpn2PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
if (!VpnUtil.isVpnPendingDelete(dataBroker, vpn1PrimaryRd) && !VpnUtil.isVpnPendingDelete(dataBroker, vpn2PrimaryRd)) {
if (VpnUtil.getVpnInstance(this.dataBroker, vpn1Name) == null) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 1st endpoint Vpn " + vpn1Name;
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
if (!checkVpnAvailability(key, vpn1Name)) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn1Name + " is already associated to an inter-vpn-link ";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
// Second VPN
if (VpnUtil.getVpnInstance(this.dataBroker, vpn2Name) == null) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 2nd endpoint Vpn " + vpn2Name;
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
if (!checkVpnAvailability(key, vpn2Name)) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn2Name + " is already associated with an inter-vpn-link";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
interVpnLinkCache.addInterVpnLinkToCaches(add);
// Wait for VPN Operational data ready
long vpn1Id = VpnUtil.getVpnId(dataBroker, vpn1Name);
if (vpn1Id == VpnConstants.INVALID_ID) {
boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn1Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
if (!vpn1Ready) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn1Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
}
long vpn2Id = VpnUtil.getVpnId(dataBroker, vpn2Name);
if (vpn2Id == VpnConstants.INVALID_ID) {
boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn2Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
if (!vpn1Ready) {
String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn2Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
setInError(vpnLinkStateIid, vpnLinkState, errMsg);
return;
}
}
List<BigInteger> firstDpnList = ivpnLinkLocator.selectSuitableDpns(add);
if (firstDpnList != null && !firstDpnList.isEmpty()) {
List<BigInteger> secondDpnList = firstDpnList;
Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setDpId(firstDpnList).setLportTag(firstVpnLportTag).build();
SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setDpId(secondDpnList).setLportTag(secondVpnLportTag).build();
InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Active, firstEndPointState, secondEndPointState, interVpnLinkCache);
// Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, firstDpnList, vpn2Name, secondVpnLportTag);
InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, secondDpnList, vpn1Name, firstVpnLportTag);
// Update the VPN -> DPNs Map.
// Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2.
// Why? because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how
// to reach to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these
// DPNs even if Vpn2 is not physically present there.
InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn2Name, vpn2PrimaryRd, firstDpnList);
InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn1Name, vpn1PrimaryRd, secondDpnList);
// Program static routes if needed
Optional<InterVpnLinkDataComposite> interVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
ivpnLinkService.handleStaticRoutes(interVpnLink.get());
// Now, if the corresponding flags are activated, there will be some routes exchange
ivpnLinkService.exchangeRoutes(interVpnLink.get());
} else {
// If there is no connection to DPNs, the InterVpnLink is created and the InterVpnLinkState is also
// created with the corresponding LPortTags but no DPN is assigned since there is no DPN operative.
Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setLportTag(firstVpnLportTag).setDpId(Collections.emptyList()).build();
SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setLportTag(secondVpnLportTag).setDpId(Collections.emptyList()).build();
InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Error, firstEndPointState, secondEndPointState, interVpnLinkCache);
}
}
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State in project netvirt by opendaylight.
the class InterVpnLinkListener method setInError.
protected void setInError(final InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid, final InterVpnLinkState vpnLinkState, String errorMsg) {
LOG.error("Setting InterVpnLink {} in error. Reason: {}", vpnLinkState.getInterVpnLinkName(), errorMsg);
// Setting InterVPNLink in error state in MDSAL
InterVpnLinkState vpnLinkErrorState = new InterVpnLinkStateBuilder(vpnLinkState).setState(InterVpnLinkState.State.Error).setErrorDescription(errorMsg).build();
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkErrorState, WriteTransaction.CREATE_MISSING_PARENTS);
tx.submit();
// Sending out an error Notification
InterVpnLinkCreationErrorMessage errMsg = new InterVpnLinkCreationErrorMessageBuilder().setErrorMessage(errorMsg).build();
InterVpnLinkCreationError notif = new InterVpnLinkCreationErrorBuilder().setInterVpnLinkCreationErrorMessage(errMsg).build();
final ListenableFuture<?> eventFuture = this.notificationsService.offerNotification(notif);
Futures.addCallback(eventFuture, new FutureCallback<Object>() {
@Override
public void onFailure(Throwable error) {
LOG.warn("Error when sending notification about InterVpnLink creation issue. InterVpnLink name={} " + "state={}.", vpnLinkState.getInterVpnLinkName(), vpnLinkState, error);
}
@Override
public void onSuccess(Object arg) {
LOG.trace("Error notification for InterVpnLink successfully sent. VpnLinkName={} state={}", vpnLinkState.getInterVpnLinkName(), vpnLinkState);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State in project netvirt by opendaylight.
the class InterVpnLinkTestCatalog method build.
static InterVpnLinkDataComposite build(String ivpnLinkName, String vpn1Name, String vpn1IpAddr, String vpn2Name, String vpn2IpAddr, boolean bgpFlag, boolean staticFlag, boolean connectedFlag, List<BigInteger> vpn1Dpns, long vpn1LportTag, List<BigInteger> vpn2Dpns, long vpn2LportTag, InterVpnLinkState.State state, Optional<String> errMsg) {
FirstEndpoint firstEndpoint = new FirstEndpointBuilder().setVpnUuid(new Uuid(vpn1Name)).setIpAddress(new Ipv4Address(vpn1IpAddr)).build();
SecondEndpoint secondEndpoint = new SecondEndpointBuilder().setVpnUuid(new Uuid(vpn2Name)).setIpAddress(new Ipv4Address(vpn2IpAddr)).build();
InterVpnLink ivpnLinkCfg = new InterVpnLinkBuilder().setName(ivpnLinkName).setFirstEndpoint(firstEndpoint).setSecondEndpoint(secondEndpoint).setBgpRoutesLeaking(bgpFlag).setStaticRoutesLeaking(staticFlag).setConnectedRoutesLeaking(connectedFlag).build();
FirstEndpointState firstEndpointState = new FirstEndpointStateBuilder().setVpnUuid(new Uuid(vpn1Name)).setLportTag(vpn1LportTag).setDpId(vpn1Dpns).build();
SecondEndpointState secondEndpointState = new SecondEndpointStateBuilder().setVpnUuid(new Uuid(vpn2Name)).setLportTag(vpn2LportTag).setDpId(vpn2Dpns).build();
InterVpnLinkState ivpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).setState(state).setErrorDescription(errMsg.or("")).setFirstEndpointState(firstEndpointState).setSecondEndpointState(secondEndpointState).build();
return new InterVpnLinkDataComposite(ivpnLinkCfg, ivpnLinkState);
}
use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State 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);
}
}
Aggregations