use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ExternalRoutersListener method remove.
@Override
public void remove(InstanceIdentifier<Routers> identifier, Routers router) {
if (natMode != NatMode.Controller) {
return;
}
LOG.trace("remove : Router delete method");
if (identifier == null || router == null) {
LOG.error("remove : returning without processing since routers is null");
return;
}
String routerName = router.getRouterName();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.info("remove : Removing default NAT route from FIB on all dpns part of router {} ", routerName);
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("remove : Remove external router event - Invalid routerId for routerName {}", routerName);
return;
}
Uint32 bgpVpnId = NatConstants.INVALID_ID;
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
if (bgpVpnUuid != null) {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, false, tx);
Uuid networkUuid = router.getNetworkId();
Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (primarySwitchId == null || primarySwitchId.equals(Uint64.ZERO)) {
// No NAPT switch for external router, probably because the router is not attached to
// any
// internal networks
LOG.debug("No NAPT switch for router {}, check if router is attached to any internal " + "network", routerName);
return;
} else {
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkUuid);
handleDisableSnat(router, networkUuid, externalIps, true, vpnName, primarySwitchId, routerId, tx);
}
if (NatUtil.releaseId(idManager, NatConstants.ODL_VNI_POOL_NAME, routerName) == NatConstants.INVALID_ID) {
LOG.error("remove: Unable to release VNI for router - {}", routerName);
}
})), NatConstants.NAT_DJC_MAX_RETRIES);
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method disassociateExternalNetworkFromVPN.
private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
if (network.getRouterIds() != null) {
for (Uuid routerId : network.getRouterIds()) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = Optional.empty();
try {
optRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("disassociateExternalNetworkFromVPN: Exception while reading RouterPorts DS for the " + "router {} network {} vpn {}", routerId, network.getId().getValue(), vpnName, e);
}
if (!optRouterPorts.isPresent()) {
LOG.debug("disassociateExternalNetworkFromVPN : Could not read Router Ports data object with id: {} " + "to handle disassociate 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("disassociateExternalNetworkFromVPN : DPN not found for {}," + "skip handling of ext nw {} disassociation", portName, network.getId());
continue;
}
for (InternalToExternalPortMap intExtPortMap : port.nonnullInternalToExternalPortMap().values()) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + intExtPortMap.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(), intExtPortMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
}
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class FloatingIPListener method getAssociatedDpnWithExternalInterface.
private Uint64 getAssociatedDpnWithExternalInterface(final String routerName, Uuid extNwId, Uint64 dpnId, String interfaceName) {
// Get the DPN on which this interface resides
if (dpnId == null) {
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = NatUtil.getInterfaceStateFromOperDS(dataBroker, interfaceName);
if (interfaceState != null) {
dpnId = NatUtil.getDpIdFromInterface(interfaceState);
}
}
Uint64 updatedDpnId = dpnId;
if (updatedDpnId != null && updatedDpnId.equals(Uint64.ZERO)) {
LOG.debug("getAssociatedDpnWithExternalInterface : The interface {} is not associated with any dpn", interfaceName);
return updatedDpnId;
}
ProviderTypes providerType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
if (providerType == null) {
LOG.warn("getAssociatedDpnWithExternalInterface : Provider Network Type for router {} and" + " externalNetwork {} is missing.", routerName, extNwId);
return updatedDpnId;
}
// mappings) and then sent out on the external Network.
if (providerType == ProviderTypes.FLAT || providerType == ProviderTypes.VLAN) {
String providerNet = NatUtil.getElanInstancePhysicalNetwok(extNwId.getValue(), dataBroker);
boolean isDpnConnected = natSwitchCache.isSwitchConnectedToExternal(updatedDpnId, providerNet);
if (!isDpnConnected) {
updatedDpnId = centralizedSwitchScheduler.getCentralizedSwitch(routerName);
}
}
return updatedDpnId;
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class SnatNodeEventListener method remove.
@Override
public void remove(Node dataObjectModification) {
NodeKey nodeKey = dataObjectModification.key();
Uint64 dpnId = MDSALUtil.getDpnIdFromNodeName(nodeKey.getId());
LOG.info("Dpn removed {}", dpnId);
centralizedSwitchCache.removeSwitch(dpnId);
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class AbstractSnatService method addSnatMissEntry.
protected void addSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId, Uint32 routerId, String routerName, Uint64 primarySwitchId) {
LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
String ifNamePrimary = NatUtil.getTunnelInterfaceName(dpnId, primarySwitchId, itmManager);
List<BucketInfo> listBucketInfo = new ArrayList<>();
if (ifNamePrimary != null) {
LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
listActionInfoPrimary = NatUtil.getEgressActionsForInterface(odlInterfaceRpcService, itmManager, interfaceManager, ifNamePrimary, routerId, true);
}
BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
listBucketInfo.add(0, bucketPrimary);
LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
// Install the select group
Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, getGroupIdKey(routerName));
if (groupId != NatConstants.INVALID_ID) {
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId.longValue(), routerName, GroupTypes.GroupAll, listBucketInfo);
LOG.debug("installing the PSNAT to NAPTSwitch GroupEntity:{} with GroupId: {}", groupEntity, groupId);
mdsalManager.addGroup(confTx, groupEntity);
// Add the flow to send the packet to the group only after group is available in Config datastore
eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION, NatUtil.getGroupInstanceId(dpnId, groupId), (unused, newGroupId) -> {
LOG.info("group {} is created in the config", groupId);
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> addSnatMissFlowForGroup(innerConfTx, dpnId, routerId, groupId)), LOG, "Error adding flow for the group {}", groupId);
return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
}, Duration.ofSeconds(5), iid -> LOG.error("groupId {} not found in config datastore", groupId));
} else {
LOG.error("installSnatMissEntry: Unable to get groupId for routerName:{}", routerName);
}
}
Aggregations