use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.
the class RouterDpnChangeListener method handleSNATForDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void handleSNATForDPN(BigInteger dpnId, String routerName, long routerId, Long routerVpnId, WriteTransaction writeFlowInvTx, WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
// Check if primary and secondary switch are selected, If not select the role
// Install select group to NAPT switch
// Install default miss entry to NAPT switch
BigInteger naptSwitch;
try {
BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptSwitchHA.getSwitchStatus(naptId)) {
LOG.debug("handleSNATForDPN : No NaptSwitch is selected for router {}", routerName);
naptSwitch = dpnId;
boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
if (!naptstatus) {
LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
return;
}
LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
// When NAPT switch is elected during first VM comes up for the given Router
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
}
Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
if (extRouters != null) {
NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
}
naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, writeFlowInvTx);
// Install miss entry (table 26) pointing to table 46
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
// Removing primary flows from old napt switch
if (naptId != null && !naptId.equals(BigInteger.ZERO)) {
LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptId, null, removeFlowInvTx);
}
} else if (naptId.equals(dpnId)) {
LOG.debug("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
} else {
naptSwitch = naptId;
LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
// installing group
List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
// Install miss entry (table 26) pointing to group
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {} groupId {}", routerName, dpnId, groupId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
}
} catch (Exception ex) {
LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.
the class ExternalNetworkGroupInstaller method removeExtNetGroupEntries.
public void removeExtNetGroupEntries(Subnetmap subnetMap) {
if (subnetMap == null) {
return;
}
String subnetName = subnetMap.getId().getValue();
Uuid networkId = subnetMap.getNetworkId();
if (networkId == null) {
LOG.error("removeExtNetGroupEntries : No external network associated subnet id {}", subnetName);
return;
}
Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
if (extInterfaces == null || extInterfaces.isEmpty()) {
LOG.debug("removeExtNetGroupEntries : No external ELAN interfaces attached to network {} subnet {}", networkId, subnetName);
return;
}
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
for (String extInterface : extInterfaces) {
GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId, extInterface);
if (groupEntity != null) {
LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}", groupId, subnetName);
NatServiceCounters.remove_external_network_group.inc();
mdsalManager.syncRemoveGroup(groupEntity);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.
the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.
private void installExtNetGroupEntries(Subnetmap subnetMap, String macAddress) {
String subnetName = subnetMap.getId().getValue();
Uuid networkId = subnetMap.getNetworkId();
if (networkId == null) {
LOG.error("installExtNetGroupEntries : No network associated subnet id {}", subnetName);
return;
}
Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
if (extInterfaces == null || extInterfaces.isEmpty()) {
LOG.trace("installExtNetGroupEntries : No external ELAN interfaces attached to network:{},subnet {}", networkId, subnetName);
return;
}
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
LOG.info("installExtNetGroupEntries : Installing ext-net group {} entry for subnet {} with macAddress {} " + "(extInterfaces: {})", groupId, subnetName, macAddress, Arrays.toString(extInterfaces.toArray()));
for (String extInterface : extInterfaces) {
BigInteger dpId = NatUtil.getDpnForInterface(interfaceManager, extInterface);
if (BigInteger.ZERO.equals(dpId)) {
LOG.info("installExtNetGroupEntries: No DPN for interface {}. NAT ext-net flow will not be installed " + "for subnet {}", extInterface, subnetName);
return;
}
installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpId);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.
the class FibUtil method updateLbGroupInfo.
public static void updateLbGroupInfo(BigInteger dpnId, String destinationIp, String groupIdKey, String groupId, WriteTransaction tx) {
InstanceIdentifier<DpnLbNexthops> id = getDpnLbNexthopsIdentifier(dpnId, destinationIp);
DpnLbNexthops dpnToLbNextHop = buildDpnLbNextHops(dpnId, destinationIp, groupIdKey);
tx.merge(LogicalDatastoreType.OPERATIONAL, id, dpnToLbNextHop);
InstanceIdentifier<Nexthops> nextHopsId = getNextHopsIdentifier(groupIdKey);
Nexthops nextHopsToGroupId = buildNextHops(dpnId, groupIdKey, groupId);
tx.merge(LogicalDatastoreType.OPERATIONAL, nextHopsId, nextHopsToGroupId);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId in project netvirt by opendaylight.
the class NexthopManager method updateDcGwLoadBalancingGroup.
/**
* This method is invoked when the tunnel status is updated.
* The bucket is directly removed/added based on the operational status of the tunnel.
*/
public void updateDcGwLoadBalancingGroup(List<String> availableDcGws, BigInteger dpnId, String destinationIp, boolean isTunnelUp) {
Preconditions.checkNotNull(availableDcGws, "There are no dc-gws present");
WriteTransaction configTx = dataBroker.newWriteOnlyTransaction();
// TODO : Place the logic to construct all possible DC-GW combination here.
int bucketId = availableDcGws.indexOf(destinationIp);
Optional<DpnLbNexthops> dpnLbNextHops = fibUtil.getDpnLbNexthops(dpnId, destinationIp);
if (!dpnLbNextHops.isPresent()) {
return;
}
List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
nextHopKeys.forEach(nextHopKey -> {
Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
if (!optionalNextHops.isPresent()) {
return;
}
Nexthops nexthops = optionalNextHops.get();
final String groupId = nexthops.getGroupId();
final long groupIdValue = Long.parseLong(groupId);
if (isTunnelUp) {
Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId);
LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
mdsalApiManager.addBucketToTx(dpnId, groupIdValue, bucket, configTx);
} else {
LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
mdsalApiManager.removeBucketToTx(dpnId, groupIdValue, bucketId, configTx);
}
});
configTx.submit();
return;
}
Aggregations