use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.
the class NatUtil method getExternalIpsLabelForRouter.
@Nonnull
public static Map<String, Long> getExternalIpsLabelForRouter(DataBroker dataBroker, Long routerId) {
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMappingOptional = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getIpMappingBuilder(routerId));
Map<String, Long> externalIpsLabel = new HashMap<>();
if (ipMappingOptional.isPresent()) {
List<IpMap> ipMaps = ipMappingOptional.get().getIpMap();
for (IpMap ipMap : ipMaps) {
externalIpsLabel.put(ipMap.getExternalIp(), ipMap.getLabel());
}
}
return externalIpsLabel;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.
the class NatUtil method getExternalIpPortMap.
public static IpPortExternal getExternalIpPortMap(DataBroker broker, Long routerId, String internalIpAddress, String internalPort, NAPTEntryEvent.Protocol protocol) {
ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
InstanceIdentifier<IpPortMap> ipPortMapId = buildIpToPortMapIdentifier(routerId, internalIpAddress, internalPort, protocolType);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, ipPortMapId).toJavaUtil().map(IpPortMap::getIpPortExternal).orElse(null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.
the class RouterDpnChangeListener method removeSNATFromDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid extNetworkId, WriteTransaction removeFlowInvTx) {
// irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
// remove miss entry to NAPT switch
// if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
if (extNwProvType == null) {
return;
}
// Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
Map<String, Long> externalIpLabel;
if (extNwProvType == ProviderTypes.VXLAN) {
externalIpLabel = null;
} else {
externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
}
BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
return;
}
try {
boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, removeFlowInvTx);
if (!naptStatus) {
LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}", dpnId, routerName);
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} " + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// remove group
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}", dpnId, routerName);
} else {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch, externalIpLabel, removeFlowInvTx);
// remove table 26 flow ppointing to table46
FlowEntity flowEntity = null;
try {
flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.DEL_FLOW);
if (flowEntity == null) {
LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with " + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
// best effort to check IntExt model
naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, removeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.
the class RouterToVpnListener method onRouterDisassociatedFromVpn.
/**
* router disassociation from vpn.
*/
@Override
public void onRouterDisassociatedFromVpn(RouterDisassociatedFromVpn notification) {
String routerName = notification.getRouterId().getValue();
String vpnName = notification.getVpnId().getValue();
WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
// check router is associated to external network
String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
if (extNetwork != null) {
LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
if (extNetworkUuid == null) {
LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}", routerName);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
if (extNwProvType == null) {
LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
return;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, writeFlowInvTx, extNwProvType);
} else {
LOG.debug("onRouterDisassociatedFromVpn : Ignoring the Router {} association with VPN {} " + "since it is not external router", routerName, vpnName);
}
NatUtil.waitForTransactionToComplete(writeFlowInvTx);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.
the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.
private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId, WriteTransaction tx, boolean create) {
Boolean wrTxPresent = true;
if (tx == null) {
wrTxPresent = false;
tx = dataBroker.newWriteOnlyTransaction();
}
// Check if the router to bgp-vpn association is present
long associatedVpnId = NatConstants.INVALID_ID;
Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
if (associatedVpn != null) {
associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
}
if (create) {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, tx);
}
} else {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, associatedVpnId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, tx);
}
}
if (!wrTxPresent) {
tx.submit();
}
}
Aggregations