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 ElanServiceTest method readBgpNetworkFromDS.
public Networks readBgpNetworkFromDS(String prefix) throws ReadFailedException {
InstanceIdentifier<Networks> iid = InstanceIdentifier.create(Bgp.class).child(NetworksContainer.class).child(Networks.class, new NetworksKey(prefix, RD));
awaitForData(LogicalDatastoreType.CONFIGURATION, iid);
return singleTxdataBroker.syncRead(CONFIGURATION, iid);
}
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 ExternalNetworksChangeListener method remove.
@Override
public void remove(InstanceIdentifier<Networks> identifier, Networks networks) {
if (identifier == null || networks == null || networks.getRouterIds() == null || networks.getRouterIds().isEmpty()) {
LOG.warn("remove : returning without processing since networks/identifier is null: " + "identifier: {}, networks: {}", identifier, networks);
return;
}
for (Uuid routerId : networks.getRouterIds()) {
String routerName = routerId.toString();
InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitchInstanceIdentifier = NatUtil.buildNaptSwitchIdentifier(routerName);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, routerToNaptSwitchInstanceIdentifier);
LOG.debug("remove : successful deletion of data in napt-switches container");
}
}
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 ExternalNetworksChangeListener method removeSnatEntries.
private void removeSnatEntries(Networks original, Uuid networkUuid) {
if (original.getRouterIds() != null) {
for (Uuid routerUuid : original.getRouterIds()) {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntries : Invalid routerId returned for routerName {}", routerUuid.getValue());
return;
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
if (natMode == NatMode.Controller) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid.getValue(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId, networkUuid, externalIps, original.getVpnid().getValue(), tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
}
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 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.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.networkscontainer.Networks in project netvirt by opendaylight.
the class FloatingIPListener method getVpnUuid.
private Uuid getVpnUuid(Uuid extNwId, Uuid floatingIpExternalId) {
InstanceIdentifier<Networks> nwId = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNwId)).build();
Optional<Networks> nw = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, nwId);
if (!nw.isPresent()) {
LOG.error("getVpnId : Unable to read external network for {}", extNwId);
return null;
}
ProviderTypes providerType = nw.get().getProviderNetworkType();
if (providerType == ProviderTypes.FLAT || providerType == ProviderTypes.VLAN) {
Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpExternalId);
if (subnetId != null) {
return subnetId;
}
}
Uuid vpnUuid = nw.get().getVpnid();
if (vpnUuid == null) {
LOG.error("getVpnId : Unable to read vpn from External network: {}", extNwId);
return null;
}
return vpnUuid;
}
Aggregations