use of org.opendaylight.genius.mdsalutil.GroupEntity in project netvirt by opendaylight.
the class ExternalRoutersListener method installSnatMissEntry.
protected void installSnatMissEntry(BigInteger dpnId, List<BucketInfo> bucketInfo, String routerName, long routerId) {
LOG.debug("installSnatMissEntry : called for dpnId {} with primaryBucket {} ", dpnId, bucketInfo.get(0));
// Install the select group
long groupId = createGroupId(getGroupIdKey(routerName));
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.syncInstallGroup(groupEntity);
// Install miss entry pointing to group
FlowEntity flowEntity = buildSnatFlowEntity(dpnId, routerName, routerId, groupId);
if (flowEntity == null) {
LOG.error("installSnatMissEntry : Flow entity received as NULL. " + "Cannot proceed with installation of SNAT Flow in table {} which is pointing to Group " + "on Non NAPT DPN {} for router {}", NwConstants.PSNAT_TABLE, dpnId, routerName);
return;
}
mdsalManager.installFlow(flowEntity);
}
use of org.opendaylight.genius.mdsalutil.GroupEntity in project netvirt by opendaylight.
the class ExternalRoutersListener method installGroup.
long installGroup(BigInteger dpnId, String routerName, List<BucketInfo> bucketInfo) {
long groupId = createGroupId(getGroupIdKey(routerName));
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
LOG.debug("installGroup : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.syncInstallGroup(groupEntity);
return groupId;
}
use of org.opendaylight.genius.mdsalutil.GroupEntity in project netvirt by opendaylight.
the class NatTunnelInterfaceStateListener method removeSNATFromDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid networkId, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSNATFromDPN : SNAT -> Invalid routerId returned for routerName {}", routerName);
return;
}
Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
if (extNwProvType == null) {
return;
}
Map<String, Long> externalIpLabel;
if (extNwProvType == ProviderTypes.VXLAN) {
externalIpLabel = null;
} else {
externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
}
try {
final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (externalVpnName == null) {
LOG.error("removeSNATFromDPN : SNAT -> No VPN associated with ext nw {} in router {}", networkId, routerId);
return;
}
BigInteger naptSwitch = dpnId;
boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, false, writeFlowInvTx);
if (!naptStatus) {
LOG.debug("removeSNATFromDPN:SNAT->NaptSwitchDown: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 : SNAT -> Failed to populate flowentity for " + "router {} with dpnId {} groupIs {}", routerName, dpnId, groupId);
return;
}
LOG.debug("removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity {}", flowEntity);
mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN:SNAT->Removed default SNAT miss entry flow for dpnID {}, routername {}", dpnId, routerName);
// remove group
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
LOG.info("removeSNATFromDPN : SNAT->Removing NAPT GroupEntity:{} on Dpn {}", groupEntity, dpnId);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Failed to remove group entity {}", groupEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : SNAT->Removed default SNAT miss entry flow for dpnID {}, routerName {}", dpnId, routerName);
} else {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, dpnId, externalIpLabel, writeFlowInvTx);
// 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 : SNAT->Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity for " + "router {} with dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
return;
}
LOG.debug("removeSNATFromDPN : SNAT->Removed default SNAT miss entry flow for dpnID {} " + "with routername {}", dpnId, routerName);
// best effort to check IntExt model
naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, writeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("removeSNATFromDPN : SNAT->Exception while handling naptSwitch down for router {}", routerName, ex);
}
}
use of org.opendaylight.genius.mdsalutil.GroupEntity 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.genius.mdsalutil.GroupEntity in project netvirt by opendaylight.
the class VxlanGreConntrackBasedSnatService method installSnatMissEntry.
protected void installSnatMissEntry(BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId, int addOrRemove) {
LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
String ifNamePrimary = getTunnelInterfaceName(dpnId, primarySwitchId);
List<BucketInfo> listBucketInfo = new ArrayList<>();
if (ifNamePrimary != null) {
LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
}
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
long groupId = createGroupId(getGroupIdKey(routerName));
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.installGroup(groupEntity);
// Install miss entry pointing to group
LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}", dpnId, routerName, groupId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchEthernetType(0x0800L));
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfo = new ArrayList<>();
BigInteger tunnelId = BigInteger.valueOf(routerId);
if (elanManager.isOpenStackVniSemanticsEnforced()) {
tunnelId = NatOverVxlanUtil.getRouterVni(idManager, routerName, routerId);
}
actionsInfo.add(new ActionSetFieldTunnelId(tunnelId));
LOG.debug("AbstractSnatService : Setting the tunnel to the list of action infos {}", actionsInfo);
actionsInfo.add(new ActionGroup(groupId));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfo));
String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
syncFlow(dpnId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Aggregations