use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkCacheImpl method initialFeed.
@PostConstruct
public void initialFeed() {
// Read all InterVpnLinks and InterVpnLinkStates from MD-SAL.
InstanceIdentifier<InterVpnLinks> interVpnLinksIid = InstanceIdentifier.builder(InterVpnLinks.class).build();
Optional<InterVpnLinks> optIVpnLinksOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, interVpnLinksIid);
if (!optIVpnLinksOpData.isPresent()) {
// Nothing to be added to cache
return;
}
InterVpnLinks interVpnLinks = optIVpnLinksOpData.get();
for (InterVpnLink interVpnLink : interVpnLinks.getInterVpnLink()) {
addInterVpnLinkToCaches(interVpnLink);
}
// Now the States
InstanceIdentifier<InterVpnLinkStates> interVpnLinkStateIid = InstanceIdentifier.builder(InterVpnLinkStates.class).build();
Optional<InterVpnLinkStates> optIVpnLinkStateOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, interVpnLinkStateIid);
if (!optIVpnLinkStateOpData.isPresent()) {
return;
}
InterVpnLinkStates interVpnLinkStates = optIVpnLinkStateOpData.get();
for (InterVpnLinkState interVpnLinkState : interVpnLinkStates.getInterVpnLinkState()) {
addInterVpnLinkStateToCaches(interVpnLinkState);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState 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.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState 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.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkNodeAddTask method updateInterVpnLinkState.
private ListenableFuture<Void> updateInterVpnLinkState(InterVpnLinkState interVpnLinkState, List<BigInteger> firstDpnList, List<BigInteger> secondDpnList) {
FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder(interVpnLinkState.getFirstEndpointState()).setDpId(firstDpnList).build();
SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder(interVpnLinkState.getSecondEndpointState()).setDpId(secondDpnList).build();
InterVpnLinkState newInterVpnLinkState = new InterVpnLinkStateBuilder(interVpnLinkState).setState(InterVpnLinkState.State.Active).setFirstEndpointState(firstEndPointState).setSecondEndpointState(secondEndPointState).build();
WriteTransaction tx = broker.newWriteOnlyTransaction();
tx.merge(LogicalDatastoreType.CONFIGURATION, InterVpnLinkUtil.getInterVpnLinkStateIid(interVpnLinkState.getInterVpnLinkName()), newInterVpnLinkState, true);
return tx.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkTestCatalog method updateEndpointDpns.
static void updateEndpointDpns(InterVpnLinkDataComposite ivl, boolean is1stEndpoint, List<BigInteger> newDpns) {
Optional<FirstEndpointState> new1stEpState = (is1stEndpoint) ? Optional.of(InterVpnLinkUtil.buildFirstEndpointState(ivl.getInterVpnLinkState().getFirstEndpointState(), Optional.of(newDpns), Optional.absent())) : Optional.absent();
Optional<SecondEndpointState> new2ndEpState = (is1stEndpoint) ? Optional.absent() : Optional.of(InterVpnLinkUtil.buildSecondEndpointState(ivl.getInterVpnLinkState().getSecondEndpointState(), Optional.of(newDpns), Optional.absent()));
InterVpnLinkState newIvlState = InterVpnLinkUtil.buildIvlStateFromOriginal(ivl.getInterVpnLinkState(), new1stEpState, new2ndEpState, /*errMsg*/
Optional.absent());
ivl.setInterVpnLinkState(newIvlState);
}
Aggregations