use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NaptSwitchHA method getRouterIdsForExtNetwork.
@NonNull
private List<String> getRouterIdsForExtNetwork(Uuid extNetworkId) {
List<String> routerUuidsAsString = new ArrayList<>();
InstanceIdentifier<Networks> extNetwork = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetworkId)).build();
Optional<Networks> extNetworkData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetwork);
if (extNetworkData.isPresent()) {
List<Uuid> routerUuids = extNetworkData.get().getRouterIds();
if (routerUuids != null) {
for (Uuid routerUuid : routerUuids) {
routerUuidsAsString.add(routerUuid.getValue());
}
}
}
return routerUuidsAsString;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class FloatingIPListener method createNATFlowEntries.
void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
if (!validateIpMapping(mapping)) {
LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
return;
}
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
if (extNwId == null) {
LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
return;
}
// For Overlay Networks, get the DPN on which this interface resides.
// For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, dpnId, interfaceName);
if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
return;
}
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
return;
}
// Check if the router to vpn association is present
// long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
Uint32 associatedVpnId = NatConstants.INVALID_ID;
if (associatedVpn == null) {
LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
} else {
LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
LOG.debug("createNATFlowEntries : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
// routerId = associatedVpnId;
}
Uuid vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
LOG.trace("createNATFlowEntries : vpnUuid {} for External Network {}", vpnUuid, extNwId);
if (vpnUuid == null) {
LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
if (vpnInstance == null || vpnInstance.getVpnId() == null) {
LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
return;
}
// Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
if (!isSnatEnabled) {
addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
}
// Create the DNAT and SNAT table entries
Uint32 vpnId = vpnInstance.getVpnId();
String vrfId = vpnInstance.getVrfId();
createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, confTx);
floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, vrfId, confTx);
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks 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.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateNetworks.
/**
* It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
SettableFuture<RpcResult<DissociateNetworksOutput>> result = SettableFuture.create();
LOG.debug("dissociateNetworks {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
try {
if (neutronvpnUtils.getVpnMap(vpnId) != null) {
LOG.debug("dissociateNetworks RPC: VpnId {}, networkList {}", vpnId.getValue(), input.getNetworkId());
List<Uuid> netIds = input.getNetworkId();
if (netIds != null && !netIds.isEmpty()) {
List<String> failed = dissociateNetworksFromVpn(vpnId, netIds);
if (!failed.isEmpty()) {
returnMsg.append(failed);
}
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
} else {
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
}
LOG.debug("dissociateNetworks returns..");
return result;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class NeutronvpnManager method addExternalNetworkToVpn.
private boolean addExternalNetworkToVpn(Network extNet, Uuid vpnId) {
Uuid extNetId = extNet.getUuid();
InstanceIdentifier<Networks> extNetIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
try {
Optional<Networks> optionalExtNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier);
if (!optionalExtNets.isPresent()) {
LOG.error("addExternalNetworkToVpn: Provider Network {} is not present in ConfigDS", extNetId.getValue());
return false;
}
NetworksBuilder builder = new NetworksBuilder(optionalExtNets.get());
builder.setVpnid(vpnId);
Networks networks = builder.build();
// Add Networks object to the ExternalNetworks list
LOG.trace("addExternalNetworkToVpn: Set VPN Id {} for Provider Network {}", vpnId.getValue(), extNetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, extNetIdentifier, networks);
return true;
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException ex) {
LOG.error("addExternalNetworkToVpn: Failed to set VPN Id {} to Provider Network {}: ", vpnId.getValue(), extNetId.getValue(), ex);
}
return false;
}
Aggregations