use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsBuilder in project netvirt by opendaylight.
the class ExternalRoutersListener method changeLocalVpnIdToBgpVpnId.
/**
* router association to vpn.
*
* @param routerName - Name of router
* @param routerId - router id
* @param bgpVpnName BGP VPN name
*/
public void changeLocalVpnIdToBgpVpnId(String routerName, Uint32 routerId, String extNetwork, String bgpVpnName, TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
Uint32 bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeLocalVpnIdToBgpVpnId : BGP VPN ID value {} ", bgpVpnId);
if (bgpVpnId != NatConstants.INVALID_ID) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Populate the router-id-name container with the " + "mapping BGP VPN-ID {} -> BGP VPN-NAME {}", bgpVpnId, bgpVpnName);
RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(bgpVpnId)).setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getRoutersIdentifier(bgpVpnId), rtrs);
// Get the allocated Primary NAPT Switch for this router
LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ", routerId, bgpVpnId);
addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, writeFlowInvTx);
// Get the group ID
Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, new Uuid(extNetwork), true, writeFlowInvTx, extNwProvType);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnMaps.
protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId, @Nullable List<Uuid> networks) {
VpnMapBuilder builder;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
try {
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
builder = new VpnMapBuilder(optionalVpnMap.get());
} else {
builder = new VpnMapBuilder().withKey(new VpnMapKey(vpnId)).setVpnId(vpnId);
}
if (name != null) {
builder.setName(name);
}
if (tenantId != null) {
builder.setTenantId(tenantId);
}
if (router != null) {
RouterIds vpnRouterId = new RouterIdsBuilder().setRouterId(router).build();
List<RouterIds> rtrIds = builder.getRouterIds() != null ? new ArrayList<>(builder.getRouterIds().values()) : null;
if (rtrIds == null) {
rtrIds = Collections.singletonList(vpnRouterId);
} else {
// Add vpnRouterId to rtrIds list only if update routerId is not existing in the VpnMap already
for (RouterIds routerId : rtrIds) {
if (!Objects.equals(routerId, vpnRouterId)) {
rtrIds.add(vpnRouterId);
}
}
}
builder.setRouterIds(rtrIds);
}
if (networks != null) {
List<Uuid> nwList = builder.getNetworkIds() != null ? new ArrayList<>(builder.getNetworkIds()) : new ArrayList<>();
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("Creating/Updating vpnMaps node: {} ", vpnId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, builder.build());
LOG.debug("VPNMaps DS updated for VPN {} ", vpnId.getValue());
}
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException e) {
LOG.error("UpdateVpnMaps failed for node: {} ", vpnId.getValue());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method clearFromVpnMaps.
private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(vpnId)).build();
Optional<VpnMap> optionalVpnMap;
try {
optionalVpnMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (ExecutionException | InterruptedException e) {
LOG.error("Error reading the VPN map for {}", vpnMapIdentifier, e);
return;
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
List<RouterIds> rtrIds = new ArrayList<>(vpnMap.nonnullRouterIds().values());
if (rtrIds == null) {
rtrIds = new ArrayList<>();
}
if (routerId != null) {
if (vpnMap.getNetworkIds() == null && routerId.equals(vpnMap.getVpnId())) {
rtrIds.add(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("removing vpnMaps node: {} ", vpnId);
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Deletion of vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
return;
} else if (vpnMap.getNetworkIds() == null && !routerId.equals(vpnMap.getVpnId())) {
rtrIds.remove(new RouterIdsBuilder().setRouterId(routerId).build());
vpnMapBuilder.setRouterIds(rtrIds);
LOG.debug("Removing routerId {} in vpnMaps for the vpn {}", routerId, vpnId.getValue());
}
}
if (networkIds != null) {
List<Uuid> vpnNw = vpnMap.getNetworkIds() != null ? new ArrayList<>(vpnMap.getNetworkIds()) : new ArrayList<>();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
vpnMapBuilder.setNetworkIds(null);
} else {
vpnMapBuilder.setNetworkIds(vpnNw);
}
}
try (AcquireResult lock = tryVpnLock(vpnId)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(vpnId);
}
LOG.debug("clearing from vpnMaps node: {} ", vpnId.getValue());
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier, vpnMapBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("Clearing from vpnMaps node failed for vpn {}", vpnId.getValue());
}
}
} else {
LOG.error("VPN : {} not found", vpnId.getValue());
}
LOG.debug("Clear from VPNMaps DS successful for VPN {} ", vpnId.getValue());
}
Aggregations