use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.
the class NatUtil method createRouterIdsConfigDS.
static void createRouterIdsConfigDS(DataBroker dataBroker, Uint32 routerId, String routerName) {
if (routerId == NatConstants.INVALID_ID) {
LOG.error("createRouterIdsConfigDS : invalid routerId for routerName {}", routerName);
return;
}
RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(routerId)).setRouterId(routerId).setRouterName(routerName).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, buildRouterIdentifier(routerId), rtrs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method associateExternalNetworkWithVPN.
private void associateExternalNetworkWithVPN(Networks network) {
if (network.getRouterIds() != null) {
List<Uuid> routerIds = network.getRouterIds();
for (Uuid routerId : routerIds) {
// long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = null;
try {
optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("associateExternalNetworkWithVPN: Exception while reading RouterPorts DS for the " + "router {} network {} ", routerId, network.getId().getValue(), e);
continue;
}
if (!optRouterPorts.isPresent()) {
LOG.debug("associateExternalNetworkWithVPN : Could not read Router Ports data object with id: {} " + "to handle associate ext nw {}", routerId, network.getId());
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
for (Ports port : routerPorts.nonnullPorts().values()) {
String portName = port.getPortName();
Uint64 dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(Uint64.ZERO)) {
LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
continue;
}
for (InternalToExternalPortMap ipMap : port.nonnullInternalToExternalPortMap().values()) {
// remove all VPN related entries
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + ipMap.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
// SNAT
for (Uuid routerId : routerIds) {
LOG.debug("associateExternalNetworkWithVPN() : for routerId {}", routerId);
Uuid networkId = network.getId();
if (networkId == null) {
LOG.error("associateExternalNetworkWithVPN : networkId is null for the router ID {}", routerId);
return;
}
final String vpnName = network.getVpnid().getValue();
if (vpnName == null) {
LOG.error("associateExternalNetworkWithVPN : No VPN associated with ext nw {} for router {}", networkId, routerId);
return;
}
Uint64 dpnId = Uint64.valueOf("0");
InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
Optional<RouterToNaptSwitch> rtrToNapt = Optional.empty();
try {
rtrToNapt = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
} catch (ExecutionException | InterruptedException e) {
LOG.error("associateExternalNetworkWithVPN: Exception while reading routerToNaptSwitch DS for the " + "router {}", routerId, e);
}
if (rtrToNapt.isPresent()) {
dpnId = rtrToNapt.get().getPrimarySwitchId();
}
LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
return;
}
final Uint64 finalDpnId = dpnId;
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerId.getValue(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
Uint32 routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey(routerIdentifier));
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> id = idBuilder.build();
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
String externalIp = ipMap.getExternalIp();
LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows " + "for dpnId {},vpnName {} and externalIp {}", finalDpnId, vpnName, externalIp);
if (natMode == NatMode.Controller) {
externalRouterListener.advToBgpAndInstallFibAndTsFlows(finalDpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
confTx);
}
}
} else {
LOG.warn("associateExternalNetworkWithVPN: No ipMapping present fot the routerId {}", routerId);
}
Uint32 vpnId = NatUtil.getVpnId(dataBroker, vpnName);
// Install 47 entry to point to 21
if (natMode == NatMode.Controller) {
externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), finalDpnId, confTx);
if (vpnId.longValue() != -1) {
LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener " + "installNaptPfibEntry for dpnId {} and vpnId {}", finalDpnId, vpnId);
externalRouterListener.installNaptPfibEntry(finalDpnId, vpnId, confTx);
}
}
})), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIds 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.vpn.instance.RouterIds 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.vpn.instance.RouterIds in project netvirt by opendaylight.
the class NeutronvpnManager method associateRouter.
/**
* It handles the invocations to the neutronvpn:associateRouter RPC method.
*/
@Override
public ListenableFuture<RpcResult<AssociateRouterOutput>> associateRouter(AssociateRouterInput input) {
SettableFuture<RpcResult<AssociateRouterOutput>> result = SettableFuture.create();
LOG.debug("associateRouter {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
Map<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIdsKey, org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIds> keyRouterIdsMap = input.nonnullRouterIds();
Preconditions.checkArgument(!keyRouterIdsMap.isEmpty(), "associateRouter: RouterIds list is empty!");
Preconditions.checkNotNull(vpnId, "associateRouter; VpnId not found!");
Preconditions.checkNotNull(vpnId, "associateRouter; RouterIds not found!");
for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.associaterouter.input.RouterIds routerId : keyRouterIdsMap.values()) {
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
Router rtr = neutronvpnUtils.getNeutronRouter(routerId.getRouterId());
if (vpnMap != null) {
if (rtr != null) {
Uuid extVpnId = neutronvpnUtils.getVpnForRouter(routerId.getRouterId(), true);
if (vpnMap.getRouterIds() != null && vpnMap.getRouterIds().size() > 1) {
returnMsg.append("vpn ").append(vpnId.getValue()).append(" already associated to router ").append(routerId.getRouterId());
} else if (extVpnId != null) {
returnMsg.append("router ").append(routerId.getRouterId()).append(" already associated to " + "another VPN ").append(extVpnId.getValue());
} else {
LOG.debug("associateRouter RPC: VpnId {}, routerId {}", vpnId.getValue(), routerId.getRouterId());
associateRouterToVpn(vpnId, routerId.getRouterId());
}
} else {
returnMsg.append("router not found : ").append(routerId.getRouterId());
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
result.set(RpcResultBuilder.<AssociateRouterOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "associate router to vpn {} failed " + "due to {}", routerId.getRouterId(), returnMsg)).build());
} else {
result.set(RpcResultBuilder.success(new AssociateRouterOutputBuilder().build()).build());
}
}
LOG.debug("associateRouter returns..");
return result;
}
Aggregations